9p: v9fs_fid_add() can't fail now
[linux-3.10.git] / fs / 9p / fid.c
index 85b67ff..73ca550 100644 (file)
  *
  */
 
-int v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid)
+void v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid)
 {
-       struct v9fs_dentry *dent;
-
-       P9_DPRINTK(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;
-
-               spin_lock_init(&dent->lock);
-               INIT_LIST_HEAD(&dent->fidlist);
-               dentry->d_fsdata = dent;
-       }
-
-       spin_lock(&dent->lock);
-       list_add(&fid->dlist, &dent->fidlist);
-       spin_unlock(&dent->lock);
-
-       return 0;
+       spin_lock(&dentry->d_lock);
+       hlist_add_head(&fid->dlist, (struct hlist_head *)&dentry->d_fsdata);
+       spin_unlock(&dentry->d_lock);
 }
 
 /**
@@ -74,24 +56,26 @@ int v9fs_fid_add(struct dentry *dentry, struct p9_fid *fid)
  *
  */
 
-static struct p9_fid *v9fs_fid_find(struct dentry *dentry, u32 uid, int any)
+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_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p) uid %d any %d\n",
-               dentry->d_name.name, dentry, uid, any);
-       dent = (struct v9fs_dentry *) dentry->d_fsdata;
+       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);
        ret = NULL;
-       if (dent) {
-               spin_lock(&dent->lock);
-               list_for_each_entry(fid, &dent->fidlist, dlist) {
-                       if (any || fid->uid == uid) {
+       /* 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, h, dlist) {
+                       if (any || uid_eq(fid->uid, uid)) {
                                ret = fid;
                                break;
                        }
                }
-               spin_unlock(&dent->lock);
+               spin_unlock(&dentry->d_lock);
        }
 
        return ret;
@@ -126,7 +110,7 @@ err_out:
 }
 
 static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry,
-                                              uid_t uid, int any)
+                                              kuid_t uid, int any)
 {
        struct dentry *ds;
        char **wnames, *uname;
@@ -233,7 +217,7 @@ err_out:
 
 struct p9_fid *v9fs_fid_lookup(struct dentry *dentry)
 {
-       uid_t uid;
+       kuid_t uid;
        int  any, access;
        struct v9fs_session_info *v9ses;
 
@@ -253,7 +237,7 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry)
                break;
 
        default:
-               uid = ~0;
+               uid = INVALID_UID;
                any = 0;
                break;
        }
@@ -272,7 +256,7 @@ struct p9_fid *v9fs_fid_clone(struct dentry *dentry)
        return ret;
 }
 
-static struct p9_fid *v9fs_fid_clone_with_uid(struct dentry *dentry, uid_t uid)
+static struct p9_fid *v9fs_fid_clone_with_uid(struct dentry *dentry, kuid_t uid)
 {
        struct p9_fid *fid, *ret;
 
@@ -289,7 +273,7 @@ struct p9_fid *v9fs_writeback_fid(struct dentry *dentry)
        int err;
        struct p9_fid *fid;
 
-       fid = v9fs_fid_clone_with_uid(dentry, 0);
+       fid = v9fs_fid_clone_with_uid(dentry, GLOBAL_ROOT_UID);
        if (IS_ERR(fid))
                goto error_out;
        /*