linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fuse: Allow parallel DIO reads and check NOWAIT case for DIO writes
@ 2020-02-02  3:34 qiwuchen55
  2020-02-02 21:25 ` Bernd Schubert
  0 siblings, 1 reply; 3+ messages in thread
From: qiwuchen55 @ 2020-02-02  3:34 UTC (permalink / raw)
  To: miklos; +Cc: linux-fsdevel, linux-kernel, chenqiwu

From: chenqiwu <chenqiwu@xiaomi.com>

Earlier there was no shared lock in DIO read path. But this patch
(16c54688592ce: ext4: Allow parallel DIO reads)
simplified some of the locking mechanism while still allowing for
parallel DIO reads by adding shared lock in inode DIO read path.

Add NOWAIT check at the start of cache writes, because an aio request
with IOCB_NOWAIT could block when we call inode_lock(), which is not
allowed.

Change current rwsem code of direct write to do the trylock for the
IOCB_NOWAIT case, otherwise lock for real scheme.

Signed-off-by: chenqiwu <chenqiwu@xiaomi.com>
---
 fs/fuse/file.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index ce71538..4fcf492 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1263,6 +1263,9 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	ssize_t err;
 	loff_t endbyte = 0;
 
+	if (iocb->ki_flags & IOCB_NOWAIT)
+		return -EOPNOTSUPP;
+
 	if (get_fuse_conn(inode)->writeback_cache) {
 		/* Update size (EOF optimization) and mode (SUID clearing) */
 		err = fuse_update_attributes(mapping->host, file);
@@ -1432,11 +1435,7 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
 
 	ia->io = io;
 	if (!cuse && fuse_range_is_writeback(inode, idx_from, idx_to)) {
-		if (!write)
-			inode_lock(inode);
 		fuse_sync_writes(inode);
-		if (!write)
-			inode_unlock(inode);
 	}
 
 	io->should_dirty = !write && iter_is_iovec(iter);
@@ -1510,6 +1509,14 @@ static ssize_t __fuse_direct_read(struct fuse_io_priv *io,
 static ssize_t fuse_direct_read_iter(struct kiocb *iocb, struct iov_iter *to)
 {
 	ssize_t res;
+	struct inode *inode = file_inode(iocb->ki_filp);
+
+	if (iocb->ki_flags & IOCB_NOWAIT) {
+		if (!inode_trylock_shared(inode))
+			return -EAGAIN;
+	} else {
+		inode_lock_shared(inode);
+	}
 
 	if (!is_sync_kiocb(iocb) && iocb->ki_flags & IOCB_DIRECT) {
 		res = fuse_direct_IO(iocb, to);
@@ -1518,6 +1525,9 @@ static ssize_t fuse_direct_read_iter(struct kiocb *iocb, struct iov_iter *to)
 
 		res = __fuse_direct_read(&io, to, &iocb->ki_pos);
 	}
+	inode_unlock_shared(inode);
+
+	file_accessed(iocb->ki_filp);
 
 	return res;
 }
@@ -1529,7 +1539,13 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	ssize_t res;
 
 	/* Don't allow parallel writes to the same file */
-	inode_lock(inode);
+	if (iocb->ki_flags & IOCB_NOWAIT) {
+		if (!inode_trylock(inode))
+			return -EAGAIN;
+	} else {
+		inode_lock(inode);
+	}
+
 	res = generic_write_checks(iocb, from);
 	if (res > 0) {
 		if (!is_sync_kiocb(iocb) && iocb->ki_flags & IOCB_DIRECT) {
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fuse: Allow parallel DIO reads and check NOWAIT case for DIO writes
  2020-02-02  3:34 [PATCH] fuse: Allow parallel DIO reads and check NOWAIT case for DIO writes qiwuchen55
@ 2020-02-02 21:25 ` Bernd Schubert
  2020-02-03  4:00   ` chenqiwu
  0 siblings, 1 reply; 3+ messages in thread
From: Bernd Schubert @ 2020-02-02 21:25 UTC (permalink / raw)
  To: qiwuchen55, miklos; +Cc: linux-fsdevel, linux-kernel, chenqiwu



> @@ -1518,6 +1525,9 @@ static ssize_t fuse_direct_read_iter(struct kiocb *iocb, struct iov_iter *to)
>  
>  		res = __fuse_direct_read(&io, to, &iocb->ki_pos);
>  	}
> +	inode_unlock_shared(inode);
> +
> +	file_accessed(iocb->ki_filp);


Shouldn't the file_accessed() in different patch, with a description? It
looks totally unrelated to locking?


Thanks,
Bernd

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fuse: Allow parallel DIO reads and check NOWAIT case for DIO writes
  2020-02-02 21:25 ` Bernd Schubert
@ 2020-02-03  4:00   ` chenqiwu
  0 siblings, 0 replies; 3+ messages in thread
From: chenqiwu @ 2020-02-03  4:00 UTC (permalink / raw)
  To: Bernd Schubert; +Cc: miklos, linux-fsdevel, linux-kernel, chenqiwu

On Sun, Feb 02, 2020 at 10:25:43PM +0100, Bernd Schubert wrote:
> 
> 
> > @@ -1518,6 +1525,9 @@ static ssize_t fuse_direct_read_iter(struct kiocb *iocb, struct iov_iter *to)
> >  
> >  		res = __fuse_direct_read(&io, to, &iocb->ki_pos);
> >  	}
> > +	inode_unlock_shared(inode);
> > +
> > +	file_accessed(iocb->ki_filp);
> 
> 
> Shouldn't the file_accessed() in different patch, with a description? It
> looks totally unrelated to locking?
>
Thanks for your remind! file_accessed() is used to update atime for
every direct read, it's totally unrelated to locking. I will separate
it to another patch.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-03  4:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-02  3:34 [PATCH] fuse: Allow parallel DIO reads and check NOWAIT case for DIO writes qiwuchen55
2020-02-02 21:25 ` Bernd Schubert
2020-02-03  4:00   ` chenqiwu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).