Skip to content

Commit cc099e0

Browse files
Christoph Hellwiggregkh
authored andcommitted
kernfs: implement ->write_iter
Switch kernfs to implement the write_iter method instead of plain old write to prepare to supporting splice and sendfile again. Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4eaad21 commit cc099e0

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

fs/kernfs/file.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,7 @@ static ssize_t kernfs_fop_read_iter(struct kiocb *iocb, struct iov_iter *iter)
242242
return kernfs_file_read_iter(iocb, iter);
243243
}
244244

245-
/**
246-
* kernfs_fop_write - kernfs vfs write callback
247-
* @file: file pointer
248-
* @user_buf: data to write
249-
* @count: number of bytes
250-
* @ppos: starting offset
251-
*
245+
/*
252246
* Copy data in from userland and pass it to the matching kernfs write
253247
* operation.
254248
*
@@ -258,20 +252,18 @@ static ssize_t kernfs_fop_read_iter(struct kiocb *iocb, struct iov_iter *iter)
258252
* modify only the the value you're changing, then write entire buffer
259253
* back.
260254
*/
261-
static ssize_t kernfs_fop_write(struct file *file, const char __user *user_buf,
262-
size_t count, loff_t *ppos)
255+
static ssize_t kernfs_fop_write_iter(struct kiocb *iocb, struct iov_iter *iter)
263256
{
264-
struct kernfs_open_file *of = kernfs_of(file);
257+
struct kernfs_open_file *of = kernfs_of(iocb->ki_filp);
258+
ssize_t len = iov_iter_count(iter);
265259
const struct kernfs_ops *ops;
266-
ssize_t len;
267260
char *buf;
268261

269262
if (of->atomic_write_len) {
270-
len = count;
271263
if (len > of->atomic_write_len)
272264
return -E2BIG;
273265
} else {
274-
len = min_t(size_t, count, PAGE_SIZE);
266+
len = min_t(size_t, len, PAGE_SIZE);
275267
}
276268

277269
buf = of->prealloc_buf;
@@ -282,7 +274,7 @@ static ssize_t kernfs_fop_write(struct file *file, const char __user *user_buf,
282274
if (!buf)
283275
return -ENOMEM;
284276

285-
if (copy_from_user(buf, user_buf, len)) {
277+
if (copy_from_iter(buf, len, iter) != len) {
286278
len = -EFAULT;
287279
goto out_free;
288280
}
@@ -301,15 +293,15 @@ static ssize_t kernfs_fop_write(struct file *file, const char __user *user_buf,
301293

302294
ops = kernfs_ops(of->kn);
303295
if (ops->write)
304-
len = ops->write(of, buf, len, *ppos);
296+
len = ops->write(of, buf, len, iocb->ki_pos);
305297
else
306298
len = -EINVAL;
307299

308300
kernfs_put_active(of->kn);
309301
mutex_unlock(&of->mutex);
310302

311303
if (len > 0)
312-
*ppos += len;
304+
iocb->ki_pos += len;
313305

314306
out_free:
315307
if (buf == of->prealloc_buf)
@@ -662,7 +654,7 @@ static int kernfs_fop_open(struct inode *inode, struct file *file)
662654

663655
/*
664656
* Write path needs to atomic_write_len outside active reference.
665-
* Cache it in open_file. See kernfs_fop_write() for details.
657+
* Cache it in open_file. See kernfs_fop_write_iter() for details.
666658
*/
667659
of->atomic_write_len = ops->atomic_write_len;
668660

@@ -950,7 +942,7 @@ EXPORT_SYMBOL_GPL(kernfs_notify);
950942

951943
const struct file_operations kernfs_file_fops = {
952944
.read_iter = kernfs_fop_read_iter,
953-
.write = kernfs_fop_write,
945+
.write_iter = kernfs_fop_write_iter,
954946
.llseek = generic_file_llseek,
955947
.mmap = kernfs_fop_mmap,
956948
.open = kernfs_fop_open,

0 commit comments

Comments
 (0)