Skip to content

Commit e5d9a0d

Browse files
Miklos Szereditorvalds
authored andcommitted
fuse: fix max i/o size calculation
Fix a bug that Werner Baumann reported: fuse can send a bigger write request than the maximum specified. This only affected direct_io operation. In addition set a sane minimum for the max_read and max_write tunables, so I/O always makes some progress. Signed-off-by: Miklos Szeredi <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5c5c5e5 commit e5d9a0d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

fs/fuse/file.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -966,14 +966,15 @@ static ssize_t fuse_direct_io(struct file *file, const char __user *buf,
966966

967967
while (count) {
968968
size_t nres;
969-
size_t nbytes = min(count, nmax);
970-
int err = fuse_get_user_pages(req, buf, nbytes, !write);
969+
size_t nbytes_limit = min(count, nmax);
970+
size_t nbytes;
971+
int err = fuse_get_user_pages(req, buf, nbytes_limit, !write);
971972
if (err) {
972973
res = err;
973974
break;
974975
}
975976
nbytes = (req->num_pages << PAGE_SHIFT) - req->page_offset;
976-
nbytes = min(count, nbytes);
977+
nbytes = min(nbytes_limit, nbytes);
977978
if (write)
978979
nres = fuse_send_write(req, file, inode, pos, nbytes,
979980
current->files);

fs/fuse/inode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
584584
fc->bdi.ra_pages = min(fc->bdi.ra_pages, ra_pages);
585585
fc->minor = arg->minor;
586586
fc->max_write = arg->minor < 5 ? 4096 : arg->max_write;
587+
fc->max_write = min_t(unsigned, 4096, fc->max_write);
587588
fc->conn_init = 1;
588589
}
589590
fuse_put_request(fc, req);
@@ -658,7 +659,7 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
658659
fc->flags = d.flags;
659660
fc->user_id = d.user_id;
660661
fc->group_id = d.group_id;
661-
fc->max_read = d.max_read;
662+
fc->max_read = min_t(unsigned, 4096, d.max_read);
662663

663664
/* Used by get_root_inode() */
664665
sb->s_fs_info = fc;

0 commit comments

Comments
 (0)