Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 39733
b: refs/heads/master
c: d2a8516
h: refs/heads/master
i:
  39731: ae5e8b5
v: v3
  • Loading branch information
Miklos Szeredi authored and Linus Torvalds committed Oct 17, 2006
1 parent f064d1b commit 4a0f65f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 28 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 265126ba9e1f8e217e61d1017c6609f76828aa7a
refs/heads/master: d2a85164aaa8d514ef5efbf5d05746e85dd13ddd
70 changes: 44 additions & 26 deletions trunk/fs/fuse/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,6 @@ static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd)
return 1;
}

/*
* Check if there's already a hashed alias of this directory inode.
* If yes, then lookup and mkdir must not create a new alias.
*/
static int dir_alias(struct inode *inode)
{
if (S_ISDIR(inode->i_mode)) {
struct dentry *alias = d_find_alias(inode);
if (alias) {
dput(alias);
return 1;
}
}
return 0;
}

static int invalid_nodeid(u64 nodeid)
{
return !nodeid || nodeid == FUSE_ROOT_ID;
Expand All @@ -208,6 +192,24 @@ static int valid_mode(int m)
S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m);
}

/*
* Add a directory inode to a dentry, ensuring that no other dentry
* refers to this inode. Called with fc->inst_mutex.
*/
static int fuse_d_add_directory(struct dentry *entry, struct inode *inode)
{
struct dentry *alias = d_find_alias(inode);
if (alias) {
/* This tries to shrink the subtree below alias */
fuse_invalidate_entry(alias);
dput(alias);
if (!list_empty(&inode->i_dentry))
return -EBUSY;
}
d_add(entry, inode);
return 0;
}

static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
struct nameidata *nd)
{
Expand Down Expand Up @@ -243,11 +245,17 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
if (err && err != -ENOENT)
return ERR_PTR(err);

if (inode && dir_alias(inode)) {
iput(inode);
return ERR_PTR(-EIO);
}
d_add(entry, inode);
if (inode && S_ISDIR(inode->i_mode)) {
mutex_lock(&fc->inst_mutex);
err = fuse_d_add_directory(entry, inode);
mutex_unlock(&fc->inst_mutex);
if (err) {
iput(inode);
return ERR_PTR(err);
}
} else
d_add(entry, inode);

entry->d_op = &fuse_dentry_operations;
if (!err)
fuse_change_timeout(entry, &outarg);
Expand Down Expand Up @@ -403,12 +411,22 @@ static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
}
fuse_put_request(fc, req);

if (dir_alias(inode)) {
iput(inode);
return -EIO;
}
if (S_ISDIR(inode->i_mode)) {
struct dentry *alias;
mutex_lock(&fc->inst_mutex);
alias = d_find_alias(inode);
if (alias) {
/* New directory must have moved since mkdir */
mutex_unlock(&fc->inst_mutex);
dput(alias);
iput(inode);
return -EBUSY;
}
d_instantiate(entry, inode);
mutex_unlock(&fc->inst_mutex);
} else
d_instantiate(entry, inode);

d_instantiate(entry, inode);
fuse_change_timeout(entry, &outarg);
fuse_invalidate_attr(dir);
return 0;
Expand Down
3 changes: 3 additions & 0 deletions trunk/fs/fuse/fuse_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ struct fuse_conn {
/** Lock protecting accessess to members of this structure */
spinlock_t lock;

/** Mutex protecting against directory alias creation */
struct mutex inst_mutex;

/** Refcount */
atomic_t count;

Expand Down
5 changes: 4 additions & 1 deletion trunk/fs/fuse/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ static struct fuse_conn *new_conn(void)
fc = kzalloc(sizeof(*fc), GFP_KERNEL);
if (fc) {
spin_lock_init(&fc->lock);
mutex_init(&fc->inst_mutex);
atomic_set(&fc->count, 1);
init_waitqueue_head(&fc->waitq);
init_waitqueue_head(&fc->blocked_waitq);
Expand All @@ -398,8 +399,10 @@ static struct fuse_conn *new_conn(void)

void fuse_conn_put(struct fuse_conn *fc)
{
if (atomic_dec_and_test(&fc->count))
if (atomic_dec_and_test(&fc->count)) {
mutex_destroy(&fc->inst_mutex);
kfree(fc);
}
}

struct fuse_conn *fuse_conn_get(struct fuse_conn *fc)
Expand Down

0 comments on commit 4a0f65f

Please sign in to comment.