linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maxim Patlasov <MPatlasov@parallels.com>
To: hch@lst.de
Cc: linux-fsdevel@vger.kernel.org, linux-aio@kvack.org,
	mszeredi@suse.cz, viro@zeniv.linux.org.uk
Subject: Re: [PATCH 1/5] fs: don't allow to complete sync iocbs through aio_complete
Date: Fri, 30 Jan 2015 19:01:33 -0800	[thread overview]
Message-ID: <20150131025520.12941.61643.stgit@R90AM809-1175L> (raw)
In-Reply-To: <20150128165737.GB17313@lst.de>

On 01/28/2015 08:57 AM, Christoph Hellwig wrote:
> On Wed, Jan 28, 2015 at 04:30:25PM +0100, Miklos Szeredi wrote:
>> Adding Maxim Patlasov, who did the AIO mode in fuse.
>
> FYI, I don't think fuse should be too hard, it just needs a completion
> in struct fuse_io_priv.  I just didn't bother before getting some higher
> level review for the concept.

Yes, I agree. Here is an example implementation below.

---
 fs/fuse/file.c   |   75 ++++++++++++++++++++++++++++++++++++++----------------
 fs/fuse/fuse_i.h |    1 +
 2 files changed, 54 insertions(+), 22 deletions(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index d2be147..b82207a 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -528,6 +528,18 @@ static void fuse_release_user_pages(struct fuse_req *req, int write)
 	}
 }
 
+static ssize_t fuse_get_res_by_io(struct fuse_io_priv *io)
+{
+	if (io->err)
+		return io->err;
+
+	if (io->bytes >= 0 && io->write)
+		return -EIO;
+
+	return io->bytes < 0 ? io->size : io->bytes;
+
+}
+
 /**
  * In case of short read, the caller sets 'pos' to the position of
  * actual end of fuse request in IO request. Otherwise, if bytes_requested
@@ -547,6 +559,7 @@ static void fuse_release_user_pages(struct fuse_req *req, int write)
 static void fuse_aio_complete(struct fuse_io_priv *io, int err, ssize_t pos)
 {
 	int left;
+	bool is_sync = is_sync_kiocb(io->iocb);
 
 	spin_lock(&io->lock);
 	if (err)
@@ -555,27 +568,25 @@ static void fuse_aio_complete(struct fuse_io_priv *io, int err, ssize_t pos)
 		io->bytes = pos;
 
 	left = --io->reqs;
-	spin_unlock(&io->lock);
 
-	if (!left) {
-		long res;
+	if (!left && is_sync) {
+		if (io->waiter)
+			wake_up_process(io->waiter);
+	}
 
-		if (io->err)
-			res = io->err;
-		else if (io->bytes >= 0 && io->write)
-			res = -EIO;
-		else {
-			res = io->bytes < 0 ? io->size : io->bytes;
+	spin_unlock(&io->lock);
 
-			if (!is_sync_kiocb(io->iocb)) {
-				struct inode *inode = file_inode(io->iocb->ki_filp);
-				struct fuse_conn *fc = get_fuse_conn(inode);
-				struct fuse_inode *fi = get_fuse_inode(inode);
+	if (!left && !is_sync) {
+		ssize_t res = fuse_get_res_by_io(io);
 
-				spin_lock(&fc->lock);
-				fi->attr_version = ++fc->attr_version;
-				spin_unlock(&fc->lock);
-			}
+		if (res >= 0) {
+			struct inode *inode = file_inode(io->iocb->ki_filp);
+			struct fuse_conn *fc = get_fuse_conn(inode);
+			struct fuse_inode *fi = get_fuse_inode(inode);
+
+			spin_lock(&fc->lock);
+			fi->attr_version = ++fc->attr_version;
+			spin_unlock(&fc->lock);
 		}
 
 		io->iocb->complete(io->iocb, res);
@@ -2798,6 +2809,29 @@ static inline loff_t fuse_round_up(loff_t off)
 	return round_up(off, FUSE_MAX_PAGES_PER_REQ << PAGE_SHIFT);
 }
 
+static ssize_t fuse_dio_wait(struct fuse_io_priv *io)
+{
+	ssize_t res;
+
+	spin_lock(&io->lock);
+
+	while (io->reqs) {
+		__set_current_state(TASK_UNINTERRUPTIBLE);
+		io->waiter = current;
+		spin_unlock(&io->lock);
+		io_schedule();
+		/* wake up sets us TASK_RUNNING */
+		spin_lock(&io->lock);
+		io->waiter = NULL;
+	}
+
+	spin_unlock(&io->lock);
+
+	res = fuse_get_res_by_io(io);
+	kfree(io);
+	return res;
+}
+
 static ssize_t
 fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
 			loff_t offset)
@@ -2841,10 +2875,8 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
 	/*
 	 * By default, we want to optimize all I/Os with async request
 	 * submission to the client filesystem if supported.
-	 *
-	 * XXX: need to add back support for this mode..
 	 */
-	io->async = async_dio && !is_sync_kiocb(iocb);
+ 	io->async = async_dio;
 	io->iocb = iocb;
 
 	/*
@@ -2867,8 +2899,7 @@ fuse_direct_IO(int rw, struct kiocb *iocb, struct iov_iter *iter,
 		if (!is_sync_kiocb(iocb))
 			return -EIOCBQUEUED;
 
-		// XXX: need fuse specific replacement
-//		ret = wait_on_sync_kiocb(iocb);
+		ret = fuse_dio_wait(io);
 	} else {
 		kfree(io);
 	}
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 1cdfb07..8d4872b 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -263,6 +263,7 @@ struct fuse_io_priv {
 	int err;
 	struct kiocb *iocb;
 	struct file *file;
+	struct task_struct *waiter;
 };
 
 /**

--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to majordomo@kvack.org.  For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

  reply	other threads:[~2015-01-31  3:01 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-27 17:55 [RFC] split struct kiocb Christoph Hellwig
2015-01-27 17:55 ` [PATCH 1/5] fs: don't allow to complete sync iocbs through aio_complete Christoph Hellwig
2015-01-28 15:30   ` Miklos Szeredi
2015-01-28 16:57     ` Christoph Hellwig
2015-01-31  3:01       ` Maxim Patlasov [this message]
2015-01-27 17:55 ` [PATCH 2/5] fs: saner aio_complete prototype Christoph Hellwig
2015-01-31 10:04   ` Al Viro
2015-01-27 17:55 ` [PATCH 3/5] fs: remove ki_nbytes Christoph Hellwig
2015-01-31  6:08   ` Al Viro
2015-02-02  8:07     ` Christoph Hellwig
2015-02-02  8:11       ` Al Viro
2015-02-02  8:14         ` Al Viro
2015-02-02 14:26           ` Christoph Hellwig
2015-02-04  8:34             ` Al Viro
2015-02-04 18:17               ` Alan Stern
2015-02-04 19:06                 ` Al Viro
2015-02-04 20:30                   ` Alan Stern
2015-02-04 23:07                     ` Al Viro
2015-02-05  8:24                       ` Robert Baldyga
2015-02-05  8:47                         ` Al Viro
2015-02-05  9:03                           ` Al Viro
2015-02-05  9:15                             ` Robert Baldyga
     [not found]                       ` <20150204230733.GK29656-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2015-02-05 15:29                         ` Alan Stern
2015-02-06  7:03                           ` Al Viro
     [not found]                             ` <20150206070350.GX29656-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2015-02-06  8:44                               ` Robert Baldyga
2015-02-07  5:44                           ` Al Viro
2015-02-07  5:48                             ` [PATCH 1/6] new helper: dup_iter() Al Viro
2015-02-07  5:48                             ` [PATCH 2/6] gadget/function/f_fs.c: close leaks Al Viro
2015-02-07  5:48                             ` [PATCH 3/6] gadget/function/f_fs.c: use put iov_iter into io_data Al Viro
2015-02-07  5:48                             ` [PATCH 4/6] gadget/function/f_fs.c: switch to ->{read,write}_iter() Al Viro
2015-02-07  5:48                             ` [PATCH 5/6] gadgetfs: use-after-free in ->aio_read() Al Viro
2015-02-07  5:48                             ` [PATCH 6/6] gadget: switch ep_io_operations to ->read_iter/->write_iter Al Viro
2015-02-02 14:20         ` [PATCH 3/5] fs: remove ki_nbytes Christoph Hellwig
2015-01-27 17:55 ` [PATCH 4/5] fs: split generic and aio kiocb Christoph Hellwig
2015-01-27 17:55 ` [PATCH 5/5] fs: add async read/write interfaces Christoph Hellwig
2015-01-31  6:29   ` Al Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150131025520.12941.61643.stgit@R90AM809-1175L \
    --to=mpatlasov@parallels.com \
    --cc=hch@lst.de \
    --cc=linux-aio@kvack.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mszeredi@suse.cz \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).