e7a346
From 8c9028b560b1f0fd816e7d2a9e0bec70cc526c1a Mon Sep 17 00:00:00 2001
e7a346
From: Kotresh HR <khiremat@redhat.com>
e7a346
Date: Sat, 7 Jul 2018 08:58:08 -0400
e7a346
Subject: [PATCH 317/325] geo-rep/scheduler: Fix EBUSY trace back
e7a346
e7a346
Fix the trace back during temporary mount
e7a346
cleanup. Temporary mount is done to touch
e7a346
the root required for checkpoint to complete.
e7a346
e7a346
Backport of
e7a346
 > Patch: https://review.gluster.org/#/c/20476/
e7a346
 > BUG: 1598977
e7a346
 > Change-Id: I97fea538e92c4ef0747747e981ef98499504e336
e7a346
 > Signed-off-by: Kotresh HR <khiremat@redhat.com>
e7a346
e7a346
BUG: 1568896
e7a346
Change-Id: I97fea538e92c4ef0747747e981ef98499504e336
e7a346
Signed-off-by: Kotresh HR <khiremat@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/143949
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
e7a346
---
e7a346
 extras/geo-rep/schedule_georep.py.in | 25 ++++++++++++++++++++-----
e7a346
 1 file changed, 20 insertions(+), 5 deletions(-)
e7a346
e7a346
diff --git a/extras/geo-rep/schedule_georep.py.in b/extras/geo-rep/schedule_georep.py.in
e7a346
index 4e1a071..3797fff 100644
e7a346
--- a/extras/geo-rep/schedule_georep.py.in
e7a346
+++ b/extras/geo-rep/schedule_georep.py.in
e7a346
@@ -43,7 +43,7 @@ SESSION_MOUNT_LOG_FILE = ("/var/log/glusterfs/geo-replication"
e7a346
                           "/schedule_georep.mount.log")
e7a346
 
e7a346
 USE_CLI_COLOR = True
e7a346
-
e7a346
+mnt_list = []
e7a346
 
e7a346
 class GlusterBadXmlFormat(Exception):
e7a346
     """
e7a346
@@ -90,6 +90,8 @@ def execute(cmd, success_msg="", failure_msg="", exitcode=-1):
e7a346
             output_ok(success_msg)
e7a346
         return out
e7a346
     else:
e7a346
+        if exitcode == 0:
e7a346
+            return
e7a346
         err_msg = err if err else out
e7a346
         output_notok(failure_msg, err=err_msg, exitcode=exitcode)
e7a346
 
e7a346
@@ -112,12 +114,12 @@ def cleanup(hostname, volname, mnt):
e7a346
     """
e7a346
     Unmount the Volume and Remove the temporary directory
e7a346
     """
e7a346
-    execute(["umount", mnt],
e7a346
+    execute(["umount", "-l", mnt],
e7a346
             failure_msg="Unable to Unmount Gluster Volume "
e7a346
             "{0}:{1}(Mounted at {2})".format(hostname, volname, mnt))
e7a346
     execute(["rmdir", mnt],
e7a346
             failure_msg="Unable to Remove temp directory "
e7a346
-            "{0}".format(mnt))
e7a346
+            "{0}".format(mnt), exitcode=0)
e7a346
 
e7a346
 
e7a346
 @contextmanager
e7a346
@@ -130,6 +132,7 @@ def glustermount(hostname, volname):
e7a346
     Automatically unmounts it in case of Exceptions/out of context
e7a346
     """
e7a346
     mnt = tempfile.mkdtemp(prefix="georepsetup_")
e7a346
+    mnt_list.append(mnt)
e7a346
     execute(["@SBIN_DIR@/glusterfs",
e7a346
              "--volfile-server", hostname,
e7a346
              "--volfile-id", volname,
e7a346
@@ -378,14 +381,14 @@ def main(args):
e7a346
     output_ok("Started Geo-replication and watching Status for "
e7a346
               "Checkpoint completion")
e7a346
 
e7a346
-    touch_mount_root(args.mastervol)
e7a346
-
e7a346
     start_time = int(time.time())
e7a346
     duration = 0
e7a346
 
e7a346
     # Sleep till Geo-rep initializes
e7a346
     time.sleep(60)
e7a346
 
e7a346
+    touch_mount_root(args.mastervol)
e7a346
+
e7a346
     slave_url = "{0}::{1}".format(args.slave, args.slavevol)
e7a346
 
e7a346
     # Loop to Check the Geo-replication Status and Checkpoint
e7a346
@@ -446,6 +449,11 @@ def main(args):
e7a346
 
e7a346
         time.sleep(args.interval)
e7a346
 
e7a346
+    for mnt in mnt_list:
e7a346
+        execute(["rmdir", mnt],
e7a346
+                failure_msg="Unable to Remove temp directory "
e7a346
+                "{0}".format(mnt), exitcode=0)
e7a346
+
e7a346
 if __name__ == "__main__":
e7a346
     parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter,
e7a346
                             description=__doc__)
e7a346
@@ -474,4 +482,11 @@ if __name__ == "__main__":
e7a346
         execute(cmd)
e7a346
         main(args)
e7a346
     except KeyboardInterrupt:
e7a346
+        for mnt in mnt_list:
e7a346
+            execute(["umount", "-l", mnt],
e7a346
+                    failure_msg="Unable to Unmount Gluster Volume "
e7a346
+                    "Mounted at {0}".format(mnt), exitcode=0)
e7a346
+            execute(["rmdir", mnt],
e7a346
+                    failure_msg="Unable to Remove temp directory "
e7a346
+                    "{0}".format(mnt), exitcode=0)
e7a346
         output_notok("Exiting...")
e7a346
-- 
e7a346
1.8.3.1
e7a346