Patchwork [BUG:1756,3/3] nfs3: Prevent second lookup on a fresh entry lookup

login
register
Submitter Shehjar Tikoo
Date 2010-11-25 09:41:11
Message ID <1290678071-14424-3-git-send-email-shehjart@gluster.com>
Download mbox | patch
Permalink /patch/5784/
State Accepted
Headers show

Comments

Shehjar Tikoo - 2010-11-25 09:41:11
From: Shehjar Tikoo <shehjart@gluster.com>


Signed-off-by: Shehjar Tikoo <shehjart@gluster.com>
---
 xlators/nfs/server/src/nfs3-helpers.c |    9 +++++++--
 xlators/nfs/server/src/nfs3.c         |    4 +++-
 xlators/nfs/server/src/nfs3.h         |    1 +
 3 files changed, 11 insertions(+), 3 deletions(-)

Patch

diff --git a/xlators/nfs/server/src/nfs3-helpers.c b/xlators/nfs/server/src/nfs3-helpers.c
index 8d7c66f..f64f049 100644
--- a/xlators/nfs/server/src/nfs3-helpers.c
+++ b/xlators/nfs/server/src/nfs3-helpers.c
@@ -3027,8 +3027,13 @@  nfs3_fh_resolve_entry_hard (nfs3_call_state_t *cs)
         if (ret == -2) {
                 gf_log (GF_NFS3, GF_LOG_TRACE, "Entry needs lookup: %s",
                         cs->resolvedloc.path);
-                nfs_lookup (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
-                            nfs3_fh_resolve_entry_lookup_cbk, cs);
+                if (nfs3_lookup_op (cs)) {
+                        cs->lookuptype = GF_NFS3_FRESH;
+                        cs->resolve_ret = 0;
+                        nfs3_call_resume (cs);
+                } else
+                        nfs_lookup (cs->nfsx, cs->vol, &nfu, &cs->resolvedloc,
+                                    nfs3_fh_resolve_entry_lookup_cbk, cs);
                 ret = 0;
         } else if (ret == -1) {
                 gf_log (GF_NFS3, GF_LOG_TRACE, "Entry needs parent lookup: %s",
diff --git a/xlators/nfs/server/src/nfs3.c b/xlators/nfs/server/src/nfs3.c
index 73293ed..4c2b470 100644
--- a/xlators/nfs/server/src/nfs3.c
+++ b/xlators/nfs/server/src/nfs3.c
@@ -1055,6 +1055,7 @@  nfs3svc_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
         struct nfs3_fh                  newfh = {{0}, };
         nfsstat3                        status = NFS3_OK;
         nfs3_call_state_t               *cs = NULL;
+        inode_t                         *oldinode = NULL;
 
         cs = frame->local;
         if (op_ret == -1) {
@@ -1063,7 +1064,8 @@  nfs3svc_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
         }
 
         nfs3_fh_build_child_fh (&cs->parent, buf, &newfh);
-
+        oldinode = inode_link (inode, cs->resolvedloc.parent, cs->resolvedloc.name, buf);
+        inode_unref (oldinode);
 xmit_res:
         /* Only send fresh lookup if it was a revalidate that failed. */
         if ((op_ret ==  -1) && (nfs3_is_revalidate_lookup (cs))) {
diff --git a/xlators/nfs/server/src/nfs3.h b/xlators/nfs/server/src/nfs3.h
index be57080..7301fe0 100644
--- a/xlators/nfs/server/src/nfs3.h
+++ b/xlators/nfs/server/src/nfs3.h
@@ -205,6 +205,7 @@  struct nfs3_local {
 };
 
 #define nfs3_is_revalidate_lookup(cst) ((cst)->lookuptype == GF_NFS3_REVALIDATE)
+#define nfs3_lookup_op(cst) (nfs_rpcsvc_request_procnum(cst->req) == NFS3_LOOKUP)
 typedef struct nfs3_local nfs3_call_state_t;
 
 /* Queue of ops waiting for open fop to return. */