Whamcloud - gitweb
LU-8371 llite: optimize atomic_open of negative dentry. 61/21161/4
authorOleg Drokin <oleg.drokin@intel.com>
Wed, 6 Jul 2016 00:35:30 +0000 (20:35 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 11 Aug 2016 05:52:17 +0000 (05:52 +0000)
No point in talking to MDS in that case if we are not creating,
just return -ENOENT.

Change-Id: I15c00fdc841e5e9d4d1923b2353f7fdc5910d67b
Signed-off-by: Oleg Drokin <oleg.drokin@intel.com>
Reviewed-on: http://review.whamcloud.com/21161
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
lustre/llite/namei.c

index 89624e6..b78ad91 100644 (file)
@@ -466,6 +466,7 @@ static int ll_lookup_it_finish(struct ptlrpc_request *request,
        struct inode             *inode = NULL;
        __u64                     bits = 0;
        int                       rc;
+       struct dentry *alias;
        ENTRY;
 
        /* NB 1 request reference will be taken away by ll_intent_lock()
@@ -492,21 +493,11 @@ static int ll_lookup_it_finish(struct ptlrpc_request *request,
        /* Only hash *de if it is unhashed (new dentry).
         * Atoimc_open may passin hashed dentries for open.
         */
-       if (d_unhashed(*de)) {
-               struct dentry *alias;
-
-               alias = ll_splice_alias(inode, *de);
-               if (IS_ERR(alias))
-                       GOTO(out, rc = PTR_ERR(alias));
-
-               *de = alias;
-       } else if (!it_disposition(it, DISP_LOOKUP_NEG)  &&
-                  !it_disposition(it, DISP_OPEN_CREATE)) {
-               /* With DISP_OPEN_CREATE dentry will
-                  instantiated in ll_create_it. */
-               LASSERT((*de)->d_inode == NULL);
-               d_instantiate(*de, inode);
-       }
+       alias = ll_splice_alias(inode, *de);
+       if (IS_ERR(alias))
+               GOTO(out, rc = PTR_ERR(alias));
+
+       *de = alias;
 
        if (!it_disposition(it, DISP_LOOKUP_NEG)) {
                /* we have lookup look - unhide dentry */
@@ -708,6 +699,24 @@ static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
               dentry->d_name.len, dentry->d_name.name,
               PFID(ll_inode2fid(dir)), dir, file, open_flags, mode, *opened);
 
+       /* Only negative dentries enter here */
+       LASSERT(dentry->d_inode == NULL);
+
+       if (!d_unhashed(dentry)) {
+               /* A valid negative dentry that just passed revalidation,
+                * there's little point to try and open it server-side,
+                * even though there's a minuscule chance it might succeed.
+                * Either way it's a valid race to just return -ENOENT here.
+                */
+               if (!(open_flags & O_CREAT))
+                       return -ENOENT;
+
+               /* Otherwise we just unhash it to be rehashed afresh via
+                * lookup if necessary
+                */
+               d_drop(dentry);
+       }
+
        OBD_ALLOC(it, sizeof(*it));
        if (!it)
                RETURN(-ENOMEM);