Whamcloud - gitweb
b=22342 more sanity check for same dentry.
[fs/lustre-release.git] / lustre / llite / namei.c
index 187cfea..9eecc1f 100644 (file)
@@ -154,7 +154,7 @@ static void ll_drop_negative_dentry(struct inode *dir)
 {
         struct dentry *dentry, *tmp_alias, *tmp_subdir;
 
-        spin_lock(&ll_lookup_lock);
+        cfs_spin_lock(&ll_lookup_lock);
         spin_lock(&dcache_lock);
 restart:
         list_for_each_entry_safe(dentry, tmp_alias,
@@ -175,7 +175,7 @@ restart:
                 }
         }
         spin_unlock(&dcache_lock);
-        spin_unlock(&ll_lookup_lock);
+        cfs_spin_unlock(&ll_lookup_lock);
 }
 
 
@@ -270,7 +270,7 @@ int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
 
 __u32 ll_i2suppgid(struct inode *i)
 {
-        if (in_group_p(i->i_gid))
+        if (cfs_curproc_is_in_groups(i->i_gid))
                 return (__u32)i->i_gid;
         else
                 return (__u32)(-1);
@@ -350,7 +350,7 @@ static struct dentry *ll_find_alias(struct inode *inode, struct dentry *de)
         struct dentry *dentry;
         struct dentry *last_discon = NULL;
 
-        spin_lock(&ll_lookup_lock);
+        cfs_spin_lock(&ll_lookup_lock);
         spin_lock(&dcache_lock);
         list_for_each(tmp, &inode->i_dentry) {
                 dentry = list_entry(tmp, struct dentry, d_alias);
@@ -387,7 +387,7 @@ static struct dentry *ll_find_alias(struct inode *inode, struct dentry *de)
                 ll_dops_init(dentry, 0);
                 d_rehash_cond(dentry, 0); /* avoid taking dcache_lock inside */
                 spin_unlock(&dcache_lock);
-                spin_unlock(&ll_lookup_lock);
+                cfs_spin_unlock(&ll_lookup_lock);
                 iput(inode);
                 CDEBUG(D_DENTRY, "alias dentry %.*s (%p) parent %p inode %p "
                        "refc %d\n", de->d_name.len, de->d_name.name, de,
@@ -404,24 +404,54 @@ static struct dentry *ll_find_alias(struct inode *inode, struct dentry *de)
                 last_discon->d_flags |= DCACHE_LUSTRE_INVALID;
                 unlock_dentry(last_discon);
                 spin_unlock(&dcache_lock);
-                spin_unlock(&ll_lookup_lock);
+                cfs_spin_unlock(&ll_lookup_lock);
                 ll_dops_init(last_discon, 1);
                 d_rehash(de);
                 d_move(last_discon, de);
                 iput(inode);
                 return last_discon;
         }
+        lock_dentry(de);
         de->d_flags |= DCACHE_LUSTRE_INVALID;
+        unlock_dentry(de);
         ll_d_add(de, inode);
 
         spin_unlock(&dcache_lock);
-        spin_unlock(&ll_lookup_lock);
+        cfs_spin_unlock(&ll_lookup_lock);
 
         return de;
 }
 
+void ll_lookup_it_alias(struct dentry **de, struct inode *inode, __u32 bits)
+{
+        struct dentry *save = *de;
+        ENTRY;
+
+        ll_dops_init(*de, 1);
+        *de = ll_find_alias(inode, *de);
+        if (*de != save) {
+                struct ll_dentry_data *lld = ll_d2d(*de);
+
+                /* just make sure the ll_dentry_data is ready */
+                if (unlikely(lld == NULL)) {
+                        ll_set_dd(*de);
+                        lld = ll_d2d(*de);
+                        if (likely(lld != NULL))
+                                lld->lld_sa_generation = 0;
+                }
+        }
+        /* we have lookup look - unhide dentry */
+        if (bits & MDS_INODELOCK_LOOKUP) {
+                lock_dentry(*de);
+                (*de)->d_flags &= ~DCACHE_LUSTRE_INVALID;
+                unlock_dentry(*de);
+        }
+        EXIT;
+}
+
 int ll_lookup_it_finish(struct ptlrpc_request *request,
-                        struct lookup_intent *it, void *data)
+                        struct lookup_intent *it, void *data,
+                        struct inode **alias)
 {
         struct it_cb_data *icbd = data;
         struct dentry **de = icbd->icbd_childp;
@@ -434,7 +464,6 @@ int ll_lookup_it_finish(struct ptlrpc_request *request,
         /* NB 1 request reference will be taken away by ll_intent_lock()
          * when I return */
         if (!it_disposition(it, DISP_LOOKUP_NEG)) {
-                struct dentry *save = *de;
                 __u32 bits;
 
                 rc = ll_prep_inode(&inode, request, (*de)->d_sb);
@@ -446,6 +475,11 @@ int ll_lookup_it_finish(struct ptlrpc_request *request,
                 md_set_lock_data(sbi->ll_md_exp,
                                  &it->d.lustre.it_lock_handle, inode, &bits);
 
+                if (alias != NULL) {
+                        *alias = inode;
+                        RETURN(0);
+                }
+
                 /* We used to query real size from OSTs here, but actually
                    this is not needed. For stat() calls size would be updated
                    from subsequent do_revalidate()->ll_inode_revalidate_it() in
@@ -454,26 +488,7 @@ int ll_lookup_it_finish(struct ptlrpc_request *request,
                    Everybody else who needs correct file size would call
                    cl_glimpse_size or some equivalent themselves anyway.
                    Also see bug 7198. */
-
-                ll_dops_init(*de, 1);
-                *de = ll_find_alias(inode, *de);
-                if (*de != save) {
-                        struct ll_dentry_data *lld = ll_d2d(*de);
-
-                        /* just make sure the ll_dentry_data is ready */
-                        if (unlikely(lld == NULL)) {
-                                ll_set_dd(*de);
-                                lld = ll_d2d(*de);
-                                if (likely(lld != NULL))
-                                        lld->lld_sa_generation = 0;
-                        }
-                }
-                /* we have lookup look - unhide dentry */
-                if (bits & MDS_INODELOCK_LOOKUP) {
-                        lock_dentry(*de);
-                        (*de)->d_flags &= ~(DCACHE_LUSTRE_INVALID);
-                        unlock_dentry(*de);
-                }
+                ll_lookup_it_alias(de, inode, bits);
         } else {
                 ll_dops_init(*de, 1);
                 /* Check that parent has UPDATE lock. If there is none, we
@@ -569,7 +584,7 @@ static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
         if (rc < 0)
                 GOTO(out, retval = ERR_PTR(rc));
 
-        rc = ll_lookup_it_finish(req, it, &icbd);
+        rc = ll_lookup_it_finish(req, it, &icbd, NULL);
         if (rc != 0) {
                 ll_intent_release(it);
                 GOTO(out, retval = ERR_PTR(rc));
@@ -861,7 +876,7 @@ static int ll_new_node(struct inode *dir, struct qstr *name,
                 GOTO(err_exit, err = PTR_ERR(op_data));
 
         err = md_create(sbi->ll_md_exp, op_data, tgt, tgt_len, mode,
-                        current->fsuid, current->fsgid,
+                        cfs_curproc_fsuid(), cfs_curproc_fsgid(),
                         cfs_curproc_cap_pack(), rdev, &request);
         ll_finish_md_op_data(op_data);
         if (err)