Blob Blame History Raw
From baf8189686402c1dc74405afd2ffe45338540031 Mon Sep 17 00:00:00 2001
From: Kotresh HR <khiremat@redhat.com>
Date: Fri, 19 Jun 2015 01:41:27 +0530
Subject: [PATCH 252/279] geo-rep: Fix fd referenced before assignment

Fix fd reference before assignment in mgmt_lock
function.

BUG: 1232216
Change-Id: I5c4a7009570e4ac18fbf417f655765f09d1bcab6
Reviewed-on: http://review.gluster.org/11318
Reviewed-on: http://review.gluster.org/11563
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Tested-by: NetBSD Build System <jenkins@build.gluster.org>
Reviewed-by: Saravanakumar Arumugam <sarumuga@redhat.com>
Reviewed-by: Milind Changire <mchangir@redhat.com>
Reviewed-by: Venky Shankar <vshankar@redhat.com>
Signed-off-by: Kotresh HR <khiremat@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/55050
Reviewed-by: Aravinda Vishwanathapura Krishna Murthy <avishwan@redhat.com>
Tested-by: Aravinda Vishwanathapura Krishna Murthy <avishwan@redhat.com>
---
 geo-replication/syncdaemon/master.py |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/geo-replication/syncdaemon/master.py b/geo-replication/syncdaemon/master.py
index 37be4fc..5b8abc5 100644
--- a/geo-replication/syncdaemon/master.py
+++ b/geo-replication/syncdaemon/master.py
@@ -442,6 +442,7 @@ class GMasterCommon(object):
 
     def mgmt_lock(self):
         """Take management volume lock """
+        fd = None
         bname = str(self.uuid) + "_" + str(gconf.slave_id) + "_subvol_" \
             + str(gconf.subvol_num) + ".lock"
         mgmt_lock_dir = os.path.join(gconf.meta_volume_mnt, "geo-rep")
@@ -455,18 +456,21 @@ class GMasterCommon(object):
                 logging.info("Creating geo-rep directory in meta volume...")
                 try:
                     os.makedirs(mgmt_lock_dir)
-                    fd = os.open(path, os.O_CREAT | os.O_RDWR)
                 except OSError:
                     ex = sys.exc_info()[1]
                     if ex.errno == EEXIST:
                         pass
                     else:
                         raise
+                fd = os.open(path, os.O_CREAT | os.O_RDWR)
+            else:
+                raise
         try:
             fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
         except:
             ex = sys.exc_info()[1]
-            os.close(fd)
+            if fd:
+                os.close(fd)
             if isinstance(ex, IOError) and ex.errno in (EACCES, EAGAIN):
                 # cannot grab, it's taken
                 logging.debug("Lock held by someother worker process")
-- 
1.7.1