a3470f
From 4742c4766af4b0def0e12a2b0544c30496dfb48e Mon Sep 17 00:00:00 2001
a3470f
From: Ravishankar N <ravishankar@redhat.com>
a3470f
Date: Thu, 19 Jul 2018 12:47:38 +0530
a3470f
Subject: [PATCH 330/333] posix: check before removing stale symlink
a3470f
a3470f
Backport of https://review.gluster.org/#/c/20509/
a3470f
a3470f
BZ 1564071 complains of directories with missing gfid symlinks and
a3470f
corresponding "Found stale gfid handle" messages in the logs. Hence
a3470f
add a check to see if the symlink points to an actual directory before
a3470f
removing it.
a3470f
a3470f
Note: Removing stale symlinks was added via commit
a3470f
3e9a9c029fac359477fb26d9cc7803749ba038b2
a3470f
a3470f
Change-Id: I5d91fab8e5f3a621a9ecad4a1f9c898a3c2d346a
a3470f
BUG: 1603103
a3470f
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/144867
a3470f
Reviewed-by: Nithya Balachandran <nbalacha@redhat.com>
a3470f
Tested-by: RHGS Build Bot <nigelb@redhat.com>
a3470f
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
a3470f
---
a3470f
 xlators/storage/posix/src/posix.c | 13 +++++++++----
a3470f
 1 file changed, 9 insertions(+), 4 deletions(-)
a3470f
a3470f
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
a3470f
index ddb875c..c3b7120 100644
a3470f
--- a/xlators/storage/posix/src/posix.c
a3470f
+++ b/xlators/storage/posix/src/posix.c
a3470f
@@ -235,6 +235,7 @@ posix_lookup (call_frame_t *frame, xlator_t *this,
a3470f
         int32_t     nlink_samepgfid    = 0;
a3470f
         struct  posix_private *priv    = NULL;
a3470f
         posix_inode_ctx_t *ctx         = NULL;
a3470f
+        int         ret                = 0;
a3470f
 
a3470f
         VALIDATE_OR_GOTO (frame, out);
a3470f
         VALIDATE_OR_GOTO (this, out);
a3470f
@@ -284,20 +285,24 @@ posix_lookup (call_frame_t *frame, xlator_t *this,
a3470f
                                 "lstat on %s failed",
a3470f
                                 real_path ? real_path : "null");
a3470f
                 }
a3470f
+                entry_ret = -1;
a3470f
                 if (loc_is_nameless(loc)) {
a3470f
                         if (!op_errno)
a3470f
                                 op_errno = ESTALE;
a3470f
                         loc_gfid (loc, gfid);
a3470f
                         MAKE_HANDLE_ABSPATH (gfid_path, this, gfid);
a3470f
-                        op_ret = sys_lstat(gfid_path, &statbuf);
a3470f
-                        if (op_ret == 0 && statbuf.st_nlink == 1) {
a3470f
-                                gf_msg (this->name, GF_LOG_WARNING, ESTALE,
a3470f
+                        ret = sys_stat(gfid_path, &statbuf);
a3470f
+                        if (ret == 0 && ((statbuf.st_mode & S_IFMT) == S_IFDIR))
a3470f
+                                /*Don't unset if it was a symlink to a dir.*/
a3470f
+                                goto parent;
a3470f
+                        ret = sys_lstat(gfid_path, &statbuf);
a3470f
+                        if (ret == 0 && statbuf.st_nlink == 1) {
a3470f
+                                gf_msg (this->name, GF_LOG_WARNING, op_errno,
a3470f
                                         P_MSG_HANDLE_DELETE, "Found stale gfid "
a3470f
                                         "handle %s, removing it.", gfid_path);
a3470f
                                 posix_handle_unset (this, gfid, NULL);
a3470f
                         }
a3470f
                 }
a3470f
-                entry_ret = -1;
a3470f
                 goto parent;
a3470f
         }
a3470f
 
a3470f
-- 
a3470f
1.8.3.1
a3470f