From: Feng Shuo <steve.shuo.feng@gmail.com>
To: fuse-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org
Cc: Feng Shuo <steve.shuo.feng@gmail.com>
Subject: [PATCH v3 2/2] FUSE: Adapt readdirplus to application usage patterns
Date: Tue, 15 Jan 2013 11:23:28 +0800 [thread overview]
Message-ID: <1358220208-27131-3-git-send-email-steve.shuo.feng@gmail.com> (raw)
In-Reply-To: <1358220208-27131-1-git-send-email-steve.shuo.feng@gmail.com>
Use the same adaptive readdirplus mechanism as NFS:
http://permalink.gmane.org/gmane.linux.nfs/49299
If the user space implementation wants to disable readdirplus
temporarily, it could just return ENOTSUPP. Then kernel will
recall it with readdir.
Signed-off-by: Feng Shuo <steve.shuo.feng@gmail.com>
---
fs/fuse/dir.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++----
fs/fuse/fuse_i.h | 10 ++++++++++
fs/fuse/inode.c | 3 +++
3 files changed, 59 insertions(+), 4 deletions(-)
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index dcc1e52..b9975df 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -14,6 +14,34 @@
#include <linux/namei.h>
#include <linux/slab.h>
+static bool fuse_use_readdirplus(struct inode *dir, struct file *filp)
+{
+ struct fuse_conn *fc = get_fuse_conn(dir);
+ struct fuse_inode *fi = get_fuse_inode(dir);
+
+ if (!fc->do_readdirplus)
+ return false;
+ if (test_and_clear_bit(FUSE_I_ADVISE_RDPLUS, &fi->state))
+ return true;
+ if (filp->f_pos == 0)
+ return true;
+ return false;
+}
+
+static void fuse_advise_use_readdirplus(struct inode *dir)
+{
+ struct fuse_inode *fi = get_fuse_inode(dir);
+
+ set_bit(FUSE_I_ADVISE_RDPLUS, &fi->state);
+}
+
+static void fuse_stop_use_readdirplus(struct inode *dir)
+{
+ struct fuse_inode *fi = get_fuse_inode(dir);
+
+ clear_bit(FUSE_I_ADVISE_RDPLUS, &fi->state);
+}
+
#if BITS_PER_LONG >= 64
static inline void fuse_dentry_settime(struct dentry *entry, u64 time)
{
@@ -219,6 +247,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
attr_version);
fuse_change_entry_timeout(entry, &outarg);
}
+ fuse_advise_use_readdirplus(inode);
return 1;
}
@@ -355,6 +384,7 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
else
fuse_invalidate_entry_cache(entry);
+ fuse_advise_use_readdirplus(dir);
return newent;
out_iput:
@@ -1294,7 +1324,7 @@ static int parse_dirplusfile(char *buf, size_t nbytes, struct file *file,
static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir)
{
- int err;
+ int plus, err;
size_t nbytes;
struct page *page;
struct inode *inode = file->f_path.dentry->d_inode;
@@ -1314,10 +1344,13 @@ static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir)
fuse_put_request(fc, req);
return -ENOMEM;
}
+
+ plus = fuse_use_readdirplus(inode, file);
+read_again:
req->out.argpages = 1;
req->num_pages = 1;
req->pages[0] = page;
- if (fc->do_readdirplus) {
+ if (plus) {
attr_version = fuse_get_attr_version(fc);
fuse_read_fill(req, file, file->f_pos, PAGE_SIZE,
FUSE_READDIRPLUS);
@@ -1329,8 +1362,17 @@ static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir)
nbytes = req->out.args[0].size;
err = req->out.h.error;
fuse_put_request(fc, req);
+ if ((err == -ENOTSUPP) && plus) {
+ fuse_stop_use_readdirplus(inode);
+ plus = 0;
+ req = fuse_get_req(fc);
+ if (!IS_ERR(req))
+ goto read_again;
+ err = PTR_ERR(req);
+ goto out;
+ }
if (!err) {
- if (fc->do_readdirplus) {
+ if (plus) {
err = parse_dirplusfile(page_address(page), nbytes,
file, dstbuf, filldir,
attr_version);
@@ -1339,7 +1381,7 @@ static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir)
dstbuf, filldir);
}
}
-
+out:
__free_page(page);
fuse_invalidate_attr(inode); /* atime changed */
return err;
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 5c50553..e582603 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -103,6 +103,16 @@ struct fuse_inode {
/** List of writepage requestst (pending or sent) */
struct list_head writepages;
+
+ /** Miscellaneous bits describing inode state */
+ unsigned long state;
+};
+
+/** FUSE inode state bits */
+enum {
+ /** Advise readdirplus */
+ FUSE_I_ADVISE_RDPLUS,
+ /* FUSE_I_MTIME_UPDATED, */
};
struct fuse_conn;
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 6f7d574..4ba1cf5 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -255,6 +255,9 @@ static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr)
new_decode_dev(attr->rdev));
} else
BUG();
+
+ /* The readdir_plus is disabled initially. */
+ get_fuse_inode(inode)->state = 0;
}
int fuse_inode_eq(struct inode *inode, void *_nodeidp)
--
1.7.12.4
next prev parent reply other threads:[~2013-01-15 3:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87mx1ngmip.fsf@tucsk.pomaz.szeredi.hu>
2013-01-15 3:23 ` [PATCH v3 0/2] FUSE: Adaptive NFS-like readdirplus support Feng Shuo
2013-01-15 3:23 ` [PATCH v3 1/2] fuse: implement " Feng Shuo
2013-01-15 3:23 ` Feng Shuo [this message]
[not found] ` <1358220208-27131-3-git-send-email-steve.shuo.feng-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-01-25 14:16 ` [PATCH v3 2/2] FUSE: Adapt readdirplus to application usage patterns Miklos Szeredi
2013-02-03 7:15 ` Eric Wong
2013-02-03 8:10 ` Eric Wong
2013-02-04 10:03 ` Feng Shuo
2013-02-04 10:10 ` Eric Wong
2013-02-04 12:46 ` [fuse-devel] " Miklos Szeredi
[not found] ` <CAJfpegtKM6jsegxV+Jx0QkOEP6MhO6en6nEq7bCEJHxAAfMKHw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-02-04 13:20 ` Eric Wong
2013-02-05 3:12 ` [RFC] fuse: consistently use readdirplus offsets Eric Wong
[not found] ` <20130205031202.GA9062-yBiyF41qdooeIZ0/mPfg9Q@public.gmane.org>
2013-02-06 17:55 ` Miklos Szeredi
2013-02-06 21:40 ` Eric Wong
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=1358220208-27131-3-git-send-email-steve.shuo.feng@gmail.com \
--to=steve.shuo.feng@gmail.com \
--cc=fuse-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
/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).