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