Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 02c24a82 authored by Josef Bacik's avatar Josef Bacik Committed by Al Viro
Browse files

fs: push i_mutex and filemap_write_and_wait down into ->fsync() handlers



Btrfs needs to be able to control how filemap_write_and_wait_range() is called
in fsync to make it less of a painful operation, so push down taking i_mutex and
the calling of filemap_write_and_wait() down into the ->fsync() handlers.  Some
file systems can drop taking the i_mutex altogether it seems, like ext3 and
ocfs2.  For correctness sake I just pushed everything down in all cases to make
sure that we keep the current behavior the same for everybody, and then each
individual fs maintainer can make up their mind about what to do from there.
Thanks,

Acked-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 22735068
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -412,7 +412,7 @@ prototypes:
	int (*open) (struct inode *, struct file *);
	int (*flush) (struct file *);
	int (*release) (struct inode *, struct file *);
	int (*fsync) (struct file *, int datasync);
	int (*fsync) (struct file *, loff_t start, loff_t end, int datasync);
	int (*aio_fsync) (struct kiocb *, int datasync);
	int (*fasync) (int, struct file *, int);
	int (*lock) (struct file *, int, struct file_lock *);
@@ -438,9 +438,7 @@ prototypes:

locking rules:
	All may block except for ->setlease.
	No VFS locks held on entry except for ->fsync and ->setlease.

->fsync() has i_mutex on inode.
	No VFS locks held on entry except for ->setlease.

->setlease has the file_list_lock held and must not sleep.

+7 −0
Original line number Diff line number Diff line
@@ -421,3 +421,10 @@ data and there is a virtual hole at the end of the file. So if the provided
offset is less than i_size and SEEK_DATA is specified, return the same offset.
If the above is true for the offset and you are given SEEK_HOLE, return the end
of the file.  If the offset is i_size or greater return -ENXIO in either case.

[mandatory]
	If you have your own ->fsync() you must make sure to call
filemap_write_and_wait_range() so that all dirty pages are synced out properly.
You must also keep in mind that ->fsync() is not called with i_mutex held
anymore, so if you require i_mutex locking you must make sure to take it and
release it yourself.
+1 −1
Original line number Diff line number Diff line
@@ -777,7 +777,7 @@ struct file_operations {
	int (*open) (struct inode *, struct file *);
	int (*flush) (struct file *);
	int (*release) (struct inode *, struct file *);
	int (*fsync) (struct file *, int datasync);
	int (*fsync) (struct file *, loff_t, loff_t, int datasync);
	int (*aio_fsync) (struct kiocb *, int datasync);
	int (*fasync) (int, struct file *, int);
	int (*lock) (struct file *, int, struct file_lock *);
+9 −2
Original line number Diff line number Diff line
@@ -1850,9 +1850,16 @@ static int spufs_mfc_flush(struct file *file, fl_owner_t id)
	return ret;
}

static int spufs_mfc_fsync(struct file *file, int datasync)
static int spufs_mfc_fsync(struct file *file, loff_t start, loff_t end, int datasync)
{
	return spufs_mfc_flush(file, NULL);
	struct inode *inode = file->f_path.dentry->d_inode;
	int err = filemap_write_and_wait_range(inode->i_mapping, start, end);
	if (!err) {
		mutex_lock(&inode->i_mutex);
		err = spufs_mfc_flush(file, NULL);
		mutex_unlock(&inode->i_mutex);
	}
	return err;
}

static int spufs_mfc_fasync(int fd, struct file *file, int on)
+7 −2
Original line number Diff line number Diff line
@@ -309,9 +309,14 @@ static int ps3flash_flush(struct file *file, fl_owner_t id)
	return ps3flash_writeback(ps3flash_dev);
}

static int ps3flash_fsync(struct file *file, int datasync)
static int ps3flash_fsync(struct file *file, loff_t start, loff_t end, int datasync)
{
	return ps3flash_writeback(ps3flash_dev);
	struct inode *inode = file->f_path.dentry->d_inode;
	int err;
	mutex_lock(&inode->i_mutex);
	err = ps3flash_writeback(ps3flash_dev);
	mutex_unlock(&inode->i_mutex);
	return err;
}

static irqreturn_t ps3flash_interrupt(int irq, void *data)
Loading