提交 8cbdf1e6 编写于 作者: M Miklos Szeredi 提交者: Linus Torvalds

[PATCH] fuse: support caching negative dentries

Add support for caching negative dentries.

Up till now, ->d_revalidate() always forced a new lookup on these.  Now let
the lookup method return a zero node ID (not used for anything else) meaning a
negative entry, but with a positive cache timeout.  The old way of signaling
negative entry (replying ENOENT) still works.

Userspace should check the ABI minor version to see whether sending a zero ID
is allowed by the kernel or not.
Signed-off-by: NMiklos Szeredi <miklos@szeredi.hu>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 de5f1202
...@@ -23,9 +23,26 @@ static inline unsigned long time_to_jiffies(unsigned long sec, ...@@ -23,9 +23,26 @@ static inline unsigned long time_to_jiffies(unsigned long sec,
static void fuse_change_timeout(struct dentry *entry, struct fuse_entry_out *o) static void fuse_change_timeout(struct dentry *entry, struct fuse_entry_out *o)
{ {
struct fuse_inode *fi = get_fuse_inode(entry->d_inode);
entry->d_time = time_to_jiffies(o->entry_valid, o->entry_valid_nsec); entry->d_time = time_to_jiffies(o->entry_valid, o->entry_valid_nsec);
fi->i_time = time_to_jiffies(o->attr_valid, o->attr_valid_nsec); if (entry->d_inode)
get_fuse_inode(entry->d_inode)->i_time =
time_to_jiffies(o->attr_valid, o->attr_valid_nsec);
}
void fuse_invalidate_attr(struct inode *inode)
{
get_fuse_inode(inode)->i_time = jiffies - 1;
}
static void fuse_invalidate_entry_cache(struct dentry *entry)
{
entry->d_time = jiffies - 1;
}
static void fuse_invalidate_entry(struct dentry *entry)
{
d_invalidate(entry);
fuse_invalidate_entry_cache(entry);
} }
static void fuse_lookup_init(struct fuse_req *req, struct inode *dir, static void fuse_lookup_init(struct fuse_req *req, struct inode *dir,
...@@ -45,15 +62,22 @@ static void fuse_lookup_init(struct fuse_req *req, struct inode *dir, ...@@ -45,15 +62,22 @@ static void fuse_lookup_init(struct fuse_req *req, struct inode *dir,
static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd) static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd)
{ {
if (!entry->d_inode || is_bad_inode(entry->d_inode)) struct inode *inode = entry->d_inode;
if (inode && is_bad_inode(inode))
return 0; return 0;
else if (time_after(jiffies, entry->d_time)) { else if (time_after(jiffies, entry->d_time)) {
int err; int err;
struct fuse_entry_out outarg; struct fuse_entry_out outarg;
struct inode *inode = entry->d_inode; struct fuse_conn *fc;
struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_req *req;
struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_req *req = fuse_get_request(fc); fuse_invalidate_entry_cache(entry);
if (!inode)
return 0;
fc = get_fuse_conn(inode);
req = fuse_get_request(fc);
if (!req) if (!req)
return 0; return 0;
...@@ -61,6 +85,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd) ...@@ -61,6 +85,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd)
request_send(fc, req); request_send(fc, req);
err = req->out.h.error; err = req->out.h.error;
if (!err) { if (!err) {
struct fuse_inode *fi = get_fuse_inode(inode);
if (outarg.nodeid != get_node_id(inode)) { if (outarg.nodeid != get_node_id(inode)) {
fuse_send_forget(fc, req, outarg.nodeid, 1); fuse_send_forget(fc, req, outarg.nodeid, 1);
return 0; return 0;
...@@ -118,9 +143,9 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, ...@@ -118,9 +143,9 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
fuse_lookup_init(req, dir, entry, &outarg); fuse_lookup_init(req, dir, entry, &outarg);
request_send(fc, req); request_send(fc, req);
err = req->out.h.error; err = req->out.h.error;
if (!err && invalid_nodeid(outarg.nodeid)) if (!err && outarg.nodeid && invalid_nodeid(outarg.nodeid))
err = -EIO; err = -EIO;
if (!err) { if (!err && outarg.nodeid) {
inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation, inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
&outarg.attr); &outarg.attr);
if (!inode) { if (!inode) {
...@@ -138,22 +163,13 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, ...@@ -138,22 +163,13 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
} }
d_add(entry, inode); d_add(entry, inode);
entry->d_op = &fuse_dentry_operations; entry->d_op = &fuse_dentry_operations;
if (inode) if (!err)
fuse_change_timeout(entry, &outarg); fuse_change_timeout(entry, &outarg);
else
fuse_invalidate_entry_cache(entry);
return NULL; return NULL;
} }
void fuse_invalidate_attr(struct inode *inode)
{
get_fuse_inode(inode)->i_time = jiffies - 1;
}
static void fuse_invalidate_entry(struct dentry *entry)
{
d_invalidate(entry);
entry->d_time = jiffies - 1;
}
static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode, static int fuse_create_open(struct inode *dir, struct dentry *entry, int mode,
struct nameidata *nd) struct nameidata *nd)
{ {
...@@ -387,6 +403,7 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry) ...@@ -387,6 +403,7 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry)
inode->i_nlink = 0; inode->i_nlink = 0;
fuse_invalidate_attr(inode); fuse_invalidate_attr(inode);
fuse_invalidate_attr(dir); fuse_invalidate_attr(dir);
fuse_invalidate_entry_cache(entry);
} else if (err == -EINTR) } else if (err == -EINTR)
fuse_invalidate_entry(entry); fuse_invalidate_entry(entry);
return err; return err;
...@@ -412,6 +429,7 @@ static int fuse_rmdir(struct inode *dir, struct dentry *entry) ...@@ -412,6 +429,7 @@ static int fuse_rmdir(struct inode *dir, struct dentry *entry)
if (!err) { if (!err) {
entry->d_inode->i_nlink = 0; entry->d_inode->i_nlink = 0;
fuse_invalidate_attr(dir); fuse_invalidate_attr(dir);
fuse_invalidate_entry_cache(entry);
} else if (err == -EINTR) } else if (err == -EINTR)
fuse_invalidate_entry(entry); fuse_invalidate_entry(entry);
return err; return err;
...@@ -447,6 +465,10 @@ static int fuse_rename(struct inode *olddir, struct dentry *oldent, ...@@ -447,6 +465,10 @@ static int fuse_rename(struct inode *olddir, struct dentry *oldent,
fuse_invalidate_attr(olddir); fuse_invalidate_attr(olddir);
if (olddir != newdir) if (olddir != newdir)
fuse_invalidate_attr(newdir); fuse_invalidate_attr(newdir);
/* newent will end up negative */
if (newent->d_inode)
fuse_invalidate_entry_cache(newent);
} else if (err == -EINTR) { } else if (err == -EINTR) {
/* If request was interrupted, DEITY only knows if the /* If request was interrupted, DEITY only knows if the
rename actually took place. If the invalidation rename actually took place. If the invalidation
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册