Skip to content

Commit a9c2d1e

Browse files
author
Miklos Szeredi
committed
fuse: fix fsync on directory
Commit ab2257e ("fuse: reduce size of struct fuse_inode") moved parts of fields related to writeback on regular file and to directory caching into a union. However fuse_fsync_common() called from fuse_dir_fsync() touches some writeback related fields, resulting in a crash. Move writeback related parts from fuse_fsync_common() to fuse_fysnc(). Reported-by: Brett Girton <btgirton@gmail.com> Tested-by: Brett Girton <btgirton@gmail.com> Fixes: ab2257e ("fuse: reduce size of struct fuse_inode") Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 4fc4bb7 commit a9c2d1e

3 files changed

Lines changed: 42 additions & 23 deletions

File tree

‎fs/fuse/dir.c‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,25 @@ static int fuse_dir_release(struct inode *inode, struct file *file)
12491249
static int fuse_dir_fsync(struct file *file, loff_t start, loff_t end,
12501250
int datasync)
12511251
{
1252-
return fuse_fsync_common(file, start, end, datasync, 1);
1252+
struct inode *inode = file->f_mapping->host;
1253+
struct fuse_conn *fc = get_fuse_conn(inode);
1254+
int err;
1255+
1256+
if (is_bad_inode(inode))
1257+
return -EIO;
1258+
1259+
if (fc->no_fsyncdir)
1260+
return 0;
1261+
1262+
inode_lock(inode);
1263+
err = fuse_fsync_common(file, start, end, datasync, FUSE_FSYNCDIR);
1264+
if (err == -ENOSYS) {
1265+
fc->no_fsyncdir = 1;
1266+
err = 0;
1267+
}
1268+
inode_unlock(inode);
1269+
1270+
return err;
12531271
}
12541272

12551273
static long fuse_dir_ioctl(struct file *file, unsigned int cmd,

‎fs/fuse/file.c‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -441,13 +441,30 @@ static int fuse_flush(struct file *file, fl_owner_t id)
441441
}
442442

443443
int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
444-
int datasync, int isdir)
444+
int datasync, int opcode)
445445
{
446446
struct inode *inode = file->f_mapping->host;
447447
struct fuse_conn *fc = get_fuse_conn(inode);
448448
struct fuse_file *ff = file->private_data;
449449
FUSE_ARGS(args);
450450
struct fuse_fsync_in inarg;
451+
452+
memset(&inarg, 0, sizeof(inarg));
453+
inarg.fh = ff->fh;
454+
inarg.fsync_flags = datasync ? 1 : 0;
455+
args.in.h.opcode = opcode;
456+
args.in.h.nodeid = get_node_id(inode);
457+
args.in.numargs = 1;
458+
args.in.args[0].size = sizeof(inarg);
459+
args.in.args[0].value = &inarg;
460+
return fuse_simple_request(fc, &args);
461+
}
462+
463+
static int fuse_fsync(struct file *file, loff_t start, loff_t end,
464+
int datasync)
465+
{
466+
struct inode *inode = file->f_mapping->host;
467+
struct fuse_conn *fc = get_fuse_conn(inode);
451468
int err;
452469

453470
if (is_bad_inode(inode))
@@ -479,34 +496,18 @@ int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
479496
if (err)
480497
goto out;
481498

482-
if ((!isdir && fc->no_fsync) || (isdir && fc->no_fsyncdir))
499+
if (fc->no_fsync)
483500
goto out;
484501

485-
memset(&inarg, 0, sizeof(inarg));
486-
inarg.fh = ff->fh;
487-
inarg.fsync_flags = datasync ? 1 : 0;
488-
args.in.h.opcode = isdir ? FUSE_FSYNCDIR : FUSE_FSYNC;
489-
args.in.h.nodeid = get_node_id(inode);
490-
args.in.numargs = 1;
491-
args.in.args[0].size = sizeof(inarg);
492-
args.in.args[0].value = &inarg;
493-
err = fuse_simple_request(fc, &args);
502+
err = fuse_fsync_common(file, start, end, datasync, FUSE_FSYNC);
494503
if (err == -ENOSYS) {
495-
if (isdir)
496-
fc->no_fsyncdir = 1;
497-
else
498-
fc->no_fsync = 1;
504+
fc->no_fsync = 1;
499505
err = 0;
500506
}
501507
out:
502508
inode_unlock(inode);
503-
return err;
504-
}
505509

506-
static int fuse_fsync(struct file *file, loff_t start, loff_t end,
507-
int datasync)
508-
{
509-
return fuse_fsync_common(file, start, end, datasync, 0);
510+
return err;
510511
}
511512

512513
void fuse_read_fill(struct fuse_req *req, struct file *file, loff_t pos,

‎fs/fuse/fuse_i.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ void fuse_release_common(struct file *file, int opcode);
828828
* Send FSYNC or FSYNCDIR request
829829
*/
830830
int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
831-
int datasync, int isdir);
831+
int datasync, int opcode);
832832

833833
/**
834834
* Notify poll wakeup

0 commit comments

Comments
 (0)