From: "Maxim V. Patlasov" <MPatlasov@parallels.com>
To: miklos@szeredi.hu
Cc: dev@parallels.com, xemul@parallels.com,
fuse-devel@lists.sourceforge.net, bfoster@redhat.com,
linux-kernel@vger.kernel.org, devel@openvz.org
Subject: [PATCH 4/6] fuse: enable asynchronous processing direct IO
Date: Fri, 14 Dec 2012 19:21:08 +0400 [thread overview]
Message-ID: <20121214152056.27155.80931.stgit@maximpc.sw.ru> (raw)
In-Reply-To: <20121214151424.27155.45971.stgit@maximpc.sw.ru>
In case of synchronous DIO request (i.e. read(2) or write(2) for a file
opened with O_DIRECT), the patch submits fuse requests asynchronously, but
waits for their completions before return from fuse_direct_IO().
In case of asynchronous DIO request (i.e. libaio io_submit() or a file opened
with O_DIRECT), the patch submits fuse requests asynchronously and return
-EIOCBQUEUED immediately.
The only special case is async DIO extending file. Here the patch falls back
to old behaviour because we can't return -EIOCBQUEUED and update i_size later,
without i_mutex hold. And we have no method to wait on real async I/O
requests.
The patch also clean __fuse_direct_write() up: it's better to update i_size
in its callers. Thanks Brian for suggestion.
Signed-off-by: Maxim Patlasov <mpatlasov@parallels.com>
---
fs/fuse/file.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 44 insertions(+), 7 deletions(-)
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 6c2ca8a..05eed23 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1356,11 +1356,8 @@ static ssize_t __fuse_direct_write(struct fuse_io_priv *io, const struct iovec *
ssize_t res;
res = generic_write_checks(file, ppos, &count, 0);
- if (!res) {
+ if (!res)
res = fuse_direct_io(io, iov, nr_segs, count, ppos, 1);
- if (!io->async && res > 0)
- fuse_write_update_size(inode, *ppos);
- }
fuse_invalidate_attr(inode);
@@ -1381,6 +1378,8 @@ static ssize_t fuse_direct_write(struct file *file, const char __user *buf,
/* Don't allow parallel writes to the same file */
mutex_lock(&inode->i_mutex);
res = __fuse_direct_write(&io, &iov, 1, ppos);
+ if (res > 0)
+ fuse_write_update_size(inode, *ppos);
mutex_unlock(&inode->i_mutex);
return res;
@@ -2348,23 +2347,61 @@ fuse_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
ssize_t ret = 0;
struct file *file = NULL;
loff_t pos = 0;
+ struct inode *inode;
+ loff_t i_size;
+ size_t count = iov_length(iov, nr_segs);
struct fuse_io_priv *io;
file = iocb->ki_filp;
pos = offset;
+ inode = file->f_mapping->host;
+ i_size = i_size_read(inode);
- io = kzalloc(sizeof(struct fuse_io_priv), GFP_KERNEL);
+ io = kmalloc(sizeof(struct fuse_io_priv), GFP_KERNEL);
if (!io)
return -ENOMEM;
-
+ spin_lock_init(&io->lock);
+ io->reqs = 1;
+ io->bytes = -1;
+ io->size = 0;
+ io->offset = offset;
+ io->write = (rw == WRITE);
+ io->err = 0;
io->file = file;
+ /*
+ * By default, we want to optimize all I/Os with async request submission
+ * to the client filesystem.
+ */
+ io->async = 1;
+ io->iocb = iocb;
+
+ /*
+ * We cannot asynchronously extend the size of a file. We have no method
+ * to wait on real async I/O requests, so we must submit this request
+ * synchronously.
+ */
+ if (!is_sync_kiocb(iocb) && (offset + count > i_size) && rw == WRITE)
+ io->async = 0;
if (rw == WRITE)
ret = __fuse_direct_write(io, iov, nr_segs, &pos);
else
ret = __fuse_direct_read(io, iov, nr_segs, &pos);
- kfree(io);
+ if (io->async) {
+ fuse_aio_complete(io, ret == count ? 0 : -EIO, -1);
+
+ /* we have a non-extending, async request, so return */
+ if (!is_sync_kiocb(iocb))
+ return -EIOCBQUEUED;
+
+ ret = wait_on_sync_kiocb(iocb);
+ } else {
+ kfree(io);
+ }
+
+ if (rw == WRITE && ret > 0)
+ fuse_write_update_size(inode, pos);
return ret;
}
next prev parent reply other threads:[~2012-12-14 15:21 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-14 15:20 [PATCH v2 0/6] fuse: process direct IO asynchronously Maxim V. Patlasov
2012-12-14 15:20 ` [PATCH 1/6] fuse: move fuse_release_user_pages() up Maxim V. Patlasov
2012-12-14 15:20 ` [PATCH 2/6] fuse: add support of async IO Maxim V. Patlasov
2013-04-22 16:34 ` Miklos Szeredi
2013-04-23 12:21 ` Maxim V. Patlasov
2012-12-14 15:20 ` [PATCH 3/6] fuse: make fuse_direct_io() aware about AIO Maxim V. Patlasov
2012-12-14 15:21 ` Maxim V. Patlasov [this message]
2012-12-14 15:21 ` [PATCH 5/6] fuse: truncate file if async dio failed Maxim V. Patlasov
2012-12-14 20:16 ` Brian Foster
2012-12-17 14:13 ` Maxim V. Patlasov
2012-12-17 19:04 ` Brian Foster
2012-12-18 8:12 ` Maxim V. Patlasov
2013-04-17 20:42 ` Miklos Szeredi
2012-12-18 10:05 ` [PATCH] fuse: truncate file if async dio failed - v2 Maxim V. Patlasov
2012-12-14 15:21 ` [PATCH 6/6] fuse: optimize short direct reads Maxim V. Patlasov
2012-12-18 14:14 ` [PATCH v2 0/6] fuse: process direct IO asynchronously Brian Foster
2013-04-11 11:22 ` [fuse-devel] " Maxim V. Patlasov
2013-04-11 16:07 ` Miklos Szeredi
2013-04-11 16:43 ` Maxim V. Patlasov
-- strict thread matches above, loose matches on Subject: below --
2012-12-10 7:41 [PATCH " Maxim V. Patlasov
2012-12-10 7:42 ` [PATCH 4/6] fuse: enable asynchronous processing direct IO Maxim V. Patlasov
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=20121214152056.27155.80931.stgit@maximpc.sw.ru \
--to=mpatlasov@parallels.com \
--cc=bfoster@redhat.com \
--cc=dev@parallels.com \
--cc=devel@openvz.org \
--cc=fuse-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=xemul@parallels.com \
/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