Skip to content

Commit c928f64

Browse files
Christoph HellwigAl Viro
authored andcommitted
fs: rename pipe_buf ->steal to ->try_steal
And replace the arcane return value convention with a simple bool where true means success and false means failure. [AV: braino fix folded in] Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent b8d9e7f commit c928f64

File tree

6 files changed

+58
-60
lines changed

6 files changed

+58
-60
lines changed

drivers/char/virtio_console.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ static int pipe_to_sg(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
871871
return 0;
872872

873873
/* Try lock this page */
874-
if (pipe_buf_steal(pipe, buf) == 0) {
874+
if (pipe_buf_try_steal(pipe, buf)) {
875875
/* Get reference and unlock page for moving */
876876
get_page(buf->page);
877877
unlock_page(buf->page);

fs/fuse/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep)
805805
if (cs->len != PAGE_SIZE)
806806
goto out_fallback;
807807

808-
if (pipe_buf_steal(cs->pipe, buf) != 0)
808+
if (!pipe_buf_try_steal(cs->pipe, buf))
809809
goto out_fallback;
810810

811811
newpage = buf->page;

fs/pipe.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,20 @@ static void anon_pipe_buf_release(struct pipe_inode_info *pipe,
140140
put_page(page);
141141
}
142142

143-
static int anon_pipe_buf_steal(struct pipe_inode_info *pipe,
144-
struct pipe_buffer *buf)
143+
static bool anon_pipe_buf_try_steal(struct pipe_inode_info *pipe,
144+
struct pipe_buffer *buf)
145145
{
146146
struct page *page = buf->page;
147147

148-
if (page_count(page) == 1) {
149-
memcg_kmem_uncharge_page(page, 0);
150-
__SetPageLocked(page);
151-
return 0;
152-
}
153-
return 1;
148+
if (page_count(page) != 1)
149+
return false;
150+
memcg_kmem_uncharge_page(page, 0);
151+
__SetPageLocked(page);
152+
return true;
154153
}
155154

156155
/**
157-
* generic_pipe_buf_steal - attempt to take ownership of a &pipe_buffer
156+
* generic_pipe_buf_try_steal - attempt to take ownership of a &pipe_buffer
158157
* @pipe: the pipe that the buffer belongs to
159158
* @buf: the buffer to attempt to steal
160159
*
@@ -165,8 +164,8 @@ static int anon_pipe_buf_steal(struct pipe_inode_info *pipe,
165164
* he wishes; the typical use is insertion into a different file
166165
* page cache.
167166
*/
168-
int generic_pipe_buf_steal(struct pipe_inode_info *pipe,
169-
struct pipe_buffer *buf)
167+
bool generic_pipe_buf_try_steal(struct pipe_inode_info *pipe,
168+
struct pipe_buffer *buf)
170169
{
171170
struct page *page = buf->page;
172171

@@ -177,12 +176,11 @@ int generic_pipe_buf_steal(struct pipe_inode_info *pipe,
177176
*/
178177
if (page_count(page) == 1) {
179178
lock_page(page);
180-
return 0;
179+
return true;
181180
}
182-
183-
return 1;
181+
return false;
184182
}
185-
EXPORT_SYMBOL(generic_pipe_buf_steal);
183+
EXPORT_SYMBOL(generic_pipe_buf_try_steal);
186184

187185
/**
188186
* generic_pipe_buf_get - get a reference to a &struct pipe_buffer
@@ -216,9 +214,9 @@ void generic_pipe_buf_release(struct pipe_inode_info *pipe,
216214
EXPORT_SYMBOL(generic_pipe_buf_release);
217215

218216
static const struct pipe_buf_operations anon_pipe_buf_ops = {
219-
.release = anon_pipe_buf_release,
220-
.steal = anon_pipe_buf_steal,
221-
.get = generic_pipe_buf_get,
217+
.release = anon_pipe_buf_release,
218+
.try_steal = anon_pipe_buf_try_steal,
219+
.get = generic_pipe_buf_get,
222220
};
223221

224222
/* Done while waiting without holding the pipe lock - thus the READ_ONCE() */

fs/splice.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
* addition of remove_mapping(). If success is returned, the caller may
4545
* attempt to reuse this page for another destination.
4646
*/
47-
static int page_cache_pipe_buf_steal(struct pipe_inode_info *pipe,
48-
struct pipe_buffer *buf)
47+
static bool page_cache_pipe_buf_try_steal(struct pipe_inode_info *pipe,
48+
struct pipe_buffer *buf)
4949
{
5050
struct page *page = buf->page;
5151
struct address_space *mapping;
@@ -76,7 +76,7 @@ static int page_cache_pipe_buf_steal(struct pipe_inode_info *pipe,
7676
*/
7777
if (remove_mapping(mapping, page)) {
7878
buf->flags |= PIPE_BUF_FLAG_LRU;
79-
return 0;
79+
return true;
8080
}
8181
}
8282

@@ -86,7 +86,7 @@ static int page_cache_pipe_buf_steal(struct pipe_inode_info *pipe,
8686
*/
8787
out_unlock:
8888
unlock_page(page);
89-
return 1;
89+
return false;
9090
}
9191

9292
static void page_cache_pipe_buf_release(struct pipe_inode_info *pipe,
@@ -139,26 +139,26 @@ static int page_cache_pipe_buf_confirm(struct pipe_inode_info *pipe,
139139
}
140140

141141
const struct pipe_buf_operations page_cache_pipe_buf_ops = {
142-
.confirm = page_cache_pipe_buf_confirm,
143-
.release = page_cache_pipe_buf_release,
144-
.steal = page_cache_pipe_buf_steal,
145-
.get = generic_pipe_buf_get,
142+
.confirm = page_cache_pipe_buf_confirm,
143+
.release = page_cache_pipe_buf_release,
144+
.try_steal = page_cache_pipe_buf_try_steal,
145+
.get = generic_pipe_buf_get,
146146
};
147147

148-
static int user_page_pipe_buf_steal(struct pipe_inode_info *pipe,
149-
struct pipe_buffer *buf)
148+
static bool user_page_pipe_buf_try_steal(struct pipe_inode_info *pipe,
149+
struct pipe_buffer *buf)
150150
{
151151
if (!(buf->flags & PIPE_BUF_FLAG_GIFT))
152-
return 1;
152+
return false;
153153

154154
buf->flags |= PIPE_BUF_FLAG_LRU;
155-
return generic_pipe_buf_steal(pipe, buf);
155+
return generic_pipe_buf_try_steal(pipe, buf);
156156
}
157157

158158
static const struct pipe_buf_operations user_page_pipe_buf_ops = {
159-
.release = page_cache_pipe_buf_release,
160-
.steal = user_page_pipe_buf_steal,
161-
.get = generic_pipe_buf_get,
159+
.release = page_cache_pipe_buf_release,
160+
.try_steal = user_page_pipe_buf_try_steal,
161+
.get = generic_pipe_buf_get,
162162
};
163163

164164
static void wakeup_pipe_readers(struct pipe_inode_info *pipe)
@@ -330,15 +330,15 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
330330
EXPORT_SYMBOL(generic_file_splice_read);
331331

332332
const struct pipe_buf_operations default_pipe_buf_ops = {
333-
.release = generic_pipe_buf_release,
334-
.steal = generic_pipe_buf_steal,
335-
.get = generic_pipe_buf_get,
333+
.release = generic_pipe_buf_release,
334+
.try_steal = generic_pipe_buf_try_steal,
335+
.get = generic_pipe_buf_get,
336336
};
337337

338338
/* Pipe buffer operations for a socket and similar. */
339339
const struct pipe_buf_operations nosteal_pipe_buf_ops = {
340-
.release = generic_pipe_buf_release,
341-
.get = generic_pipe_buf_get,
340+
.release = generic_pipe_buf_release,
341+
.get = generic_pipe_buf_get,
342342
};
343343
EXPORT_SYMBOL(nosteal_pipe_buf_ops);
344344

include/linux/pipe_fs_i.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ struct pipe_inode_info {
7070
* Note on the nesting of these functions:
7171
*
7272
* ->confirm()
73-
* ->steal()
73+
* ->try_steal()
7474
*
75-
* That is, ->steal() must be called on a confirmed buffer.
76-
* See below for the meaning of each operation. Also see kerneldoc
77-
* in fs/pipe.c for the pipe and generic variants of these hooks.
75+
* That is, ->try_steal() must be called on a confirmed buffer. See below for
76+
* the meaning of each operation. Also see the kerneldoc in fs/pipe.c for the
77+
* pipe and generic variants of these hooks.
7878
*/
7979
struct pipe_buf_operations {
8080
/*
@@ -94,13 +94,13 @@ struct pipe_buf_operations {
9494

9595
/*
9696
* Attempt to take ownership of the pipe buffer and its contents.
97-
* ->steal() returns 0 for success, in which case the contents
98-
* of the pipe (the buf->page) is locked and now completely owned
99-
* by the caller. The page may then be transferred to a different
100-
* mapping, the most often used case is insertion into different
101-
* file address space cache.
97+
* ->try_steal() returns %true for success, in which case the contents
98+
* of the pipe (the buf->page) is locked and now completely owned by the
99+
* caller. The page may then be transferred to a different mapping, the
100+
* most often used case is insertion into different file address space
101+
* cache.
102102
*/
103-
int (*steal)(struct pipe_inode_info *, struct pipe_buffer *);
103+
bool (*try_steal)(struct pipe_inode_info *, struct pipe_buffer *);
104104

105105
/*
106106
* Get a reference to the pipe buffer.
@@ -201,16 +201,16 @@ static inline int pipe_buf_confirm(struct pipe_inode_info *pipe,
201201
}
202202

203203
/**
204-
* pipe_buf_steal - attempt to take ownership of a pipe_buffer
204+
* pipe_buf_try_steal - attempt to take ownership of a pipe_buffer
205205
* @pipe: the pipe that the buffer belongs to
206206
* @buf: the buffer to attempt to steal
207207
*/
208-
static inline int pipe_buf_steal(struct pipe_inode_info *pipe,
209-
struct pipe_buffer *buf)
208+
static inline bool pipe_buf_try_steal(struct pipe_inode_info *pipe,
209+
struct pipe_buffer *buf)
210210
{
211-
if (!buf->ops->steal)
212-
return 1;
213-
return buf->ops->steal(pipe, buf);
211+
if (!buf->ops->try_steal)
212+
return false;
213+
return buf->ops->try_steal(pipe, buf);
214214
}
215215

216216
/* Differs from PIPE_BUF in that PIPE_SIZE is the length of the actual
@@ -234,7 +234,7 @@ void free_pipe_info(struct pipe_inode_info *);
234234

235235
/* Generic pipe buffer ops functions */
236236
bool generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *);
237-
int generic_pipe_buf_steal(struct pipe_inode_info *, struct pipe_buffer *);
237+
bool generic_pipe_buf_try_steal(struct pipe_inode_info *, struct pipe_buffer *);
238238
void generic_pipe_buf_release(struct pipe_inode_info *, struct pipe_buffer *);
239239

240240
extern const struct pipe_buf_operations nosteal_pipe_buf_ops;

kernel/relay.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,9 +1177,9 @@ static void relay_pipe_buf_release(struct pipe_inode_info *pipe,
11771177
}
11781178

11791179
static const struct pipe_buf_operations relay_pipe_buf_ops = {
1180-
.release = relay_pipe_buf_release,
1181-
.steal = generic_pipe_buf_steal,
1182-
.get = generic_pipe_buf_get,
1180+
.release = relay_pipe_buf_release,
1181+
.try_steal = generic_pipe_buf_try_steal,
1182+
.get = generic_pipe_buf_get,
11831183
};
11841184

11851185
static void relay_page_release(struct splice_pipe_desc *spd, unsigned int i)

0 commit comments

Comments
 (0)