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