From 634095dab2a2001844fc8b26673c0cb14a766cdf Mon Sep 17 00:00:00 2001 From: Al Viro Date: Wed, 27 Feb 2013 22:37:21 -0500 Subject: 9p: don't bother with private lock in ->d_fsdata; dentry->d_lock will do just fine Signed-off-by: Al Viro --- fs/9p/fid.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'fs/9p/fid.c') diff --git a/fs/9p/fid.c b/fs/9p/fid.c index afd4724b2d92..71bc36a03e72 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c @@ -54,14 +54,13 @@ int v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid) if (!dent) return -ENOMEM; - spin_lock_init(&dent->lock); INIT_LIST_HEAD(&dent->fidlist); dentry->d_fsdata = dent; } - spin_lock(&dent->lock); + spin_lock(&dentry->d_lock); list_add(&fid->dlist, &dent->fidlist); - spin_unlock(&dent->lock); + spin_unlock(&dentry->d_lock); return 0; } @@ -85,14 +84,14 @@ static struct p9_fid *v9fs_fid_find(struct dentry *dentry, kuid_t uid, int any) dent = (struct v9fs_dentry *) dentry->d_fsdata; ret = NULL; if (dent) { - spin_lock(&dent->lock); + spin_lock(&dentry->d_lock); list_for_each_entry(fid, &dent->fidlist, dlist) { if (any || uid_eq(fid->uid, uid)) { ret = fid; break; } } - spin_unlock(&dent->lock); + spin_unlock(&dentry->d_lock); } return ret; -- cgit v1.2.3 From c4d30967f3020cda9df9ee22af79cd1f2c284244 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Wed, 27 Feb 2013 22:51:08 -0500 Subject: 9p: turn fid->dlist into hlist Signed-off-by: Al Viro --- fs/9p/fid.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'fs/9p/fid.c') diff --git a/fs/9p/fid.c b/fs/9p/fid.c index 71bc36a03e72..49de4264db9a 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c @@ -54,12 +54,12 @@ int v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid) if (!dent) return -ENOMEM; - INIT_LIST_HEAD(&dent->fidlist); + INIT_HLIST_HEAD(&dent->fidlist); dentry->d_fsdata = dent; } spin_lock(&dentry->d_lock); - list_add(&fid->dlist, &dent->fidlist); + hlist_add_head(&fid->dlist, &dent->fidlist); spin_unlock(&dentry->d_lock); return 0; @@ -84,8 +84,9 @@ static struct p9_fid *v9fs_fid_find(struct dentry *dentry, kuid_t uid, int any) dent = (struct v9fs_dentry *) dentry->d_fsdata; ret = NULL; if (dent) { + struct hlist_node *n; spin_lock(&dentry->d_lock); - list_for_each_entry(fid, &dent->fidlist, dlist) { + hlist_for_each_entry(fid, n, &dent->fidlist, dlist) { if (any || uid_eq(fid->uid, uid)) { ret = fid; break; -- cgit v1.2.3 From aaeb7ecfb48ad4c8942a26874322d8918524a04f Mon Sep 17 00:00:00 2001 From: Al Viro Date: Thu, 28 Feb 2013 01:13:19 -0500 Subject: v9fs: get rid of v9fs_dentry ->d_fsdata can act as hlist_head... Signed-off-by: Al Viro --- fs/9p/fid.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'fs/9p/fid.c') diff --git a/fs/9p/fid.c b/fs/9p/fid.c index 49de4264db9a..ddf618936d8a 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c @@ -43,25 +43,9 @@ int v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid) { - struct v9fs_dentry *dent; - - p9_debug(P9_DEBUG_VFS, "fid %d dentry %s\n", - fid->fid, dentry->d_name.name); - - dent = dentry->d_fsdata; - if (!dent) { - dent = kmalloc(sizeof(struct v9fs_dentry), GFP_KERNEL); - if (!dent) - return -ENOMEM; - - INIT_HLIST_HEAD(&dent->fidlist); - dentry->d_fsdata = dent; - } - spin_lock(&dentry->d_lock); - hlist_add_head(&fid->dlist, &dent->fidlist); + hlist_add_head(&fid->dlist, (struct hlist_head *)&dentry->d_fsdata); spin_unlock(&dentry->d_lock); - return 0; } @@ -75,18 +59,18 @@ int v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid) static struct p9_fid *v9fs_fid_find(struct dentry *dentry, kuid_t uid, int any) { - struct v9fs_dentry *dent; struct p9_fid *fid, *ret; p9_debug(P9_DEBUG_VFS, " dentry: %s (%p) uid %d any %d\n", dentry->d_name.name, dentry, from_kuid(&init_user_ns, uid), any); - dent = (struct v9fs_dentry *) dentry->d_fsdata; ret = NULL; - if (dent) { + /* we'll recheck under lock if there's anything to look in */ + if (dentry->d_fsdata) { + struct hlist_head *h = (struct hlist_head *)&dentry->d_fsdata; struct hlist_node *n; spin_lock(&dentry->d_lock); - hlist_for_each_entry(fid, n, &dent->fidlist, dlist) { + hlist_for_each_entry(fid, n, h, dlist) { if (any || uid_eq(fid->uid, uid)) { ret = fid; break; -- cgit v1.2.3 From 2ea03e1d62d56c37737e43550c360b43a5e40a32 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Thu, 28 Feb 2013 01:18:14 -0500 Subject: 9p: v9fs_fid_add() can't fail now Signed-off-by: Al Viro --- fs/9p/fid.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'fs/9p/fid.c') diff --git a/fs/9p/fid.c b/fs/9p/fid.c index ddf618936d8a..73ca55042cb0 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c @@ -41,12 +41,11 @@ * */ -int v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid) +void v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid) { spin_lock(&dentry->d_lock); hlist_add_head(&fid->dlist, (struct hlist_head *)&dentry->d_fsdata); spin_unlock(&dentry->d_lock); - return 0; } /** -- cgit v1.2.3 From 5e608671dfbfd6a9556c31df65a4f147439eed59 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Thu, 28 Feb 2013 01:50:20 -0500 Subject: 9p: if v9fs_fid_lookup() gets to asking server, it'd better have hashed dentry ... otherwise the path we'd built isn't worth much. Don't accept such fids obtained from paths unless dentry is still alived by the end of the work. Signed-off-by: Al Viro --- fs/9p/fid.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'fs/9p/fid.c') diff --git a/fs/9p/fid.c b/fs/9p/fid.c index 73ca55042cb0..616abaf1c6cd 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c @@ -41,10 +41,15 @@ * */ +static inline void __add_fid(struct dentry *dentry, struct p9_fid *fid) +{ + hlist_add_head(&fid->dlist, (struct hlist_head *)&dentry->d_fsdata); +} + void v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid) { spin_lock(&dentry->d_lock); - hlist_add_head(&fid->dlist, (struct hlist_head *)&dentry->d_fsdata); + __add_fid(dentry, fid); spin_unlock(&dentry->d_lock); } @@ -198,8 +203,17 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry, } kfree(wnames); fid_out: - if (!IS_ERR(fid)) - v9fs_fid_add(dentry, fid); + if (!IS_ERR(fid)) { + spin_lock(&dentry->d_lock); + if (d_unhashed(dentry)) { + spin_unlock(&dentry->d_lock); + p9_client_clunk(fid); + fid = ERR_PTR(-ENOENT); + } else { + __add_fid(dentry, fid); + spin_unlock(&dentry->d_lock); + } + } err_out: up_read(&v9ses->rename_sem); return fid; -- cgit v1.2.3