ctdb-recoverd: New function ctdb_recovery_unlock()
authorMartin Schwenke <martin@meltin.net>
Tue, 9 Dec 2014 03:07:20 +0000 (14:07 +1100)
committerAmitay Isaacs <amitay@samba.org>
Fri, 13 Feb 2015 06:19:07 +0000 (07:19 +0100)
Unlock the recovery lock file.  This way knowledge of the file
descriptor isn't sprinkled throughout the code.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/include/ctdb_private.h
ctdb/server/ctdb_recover.c
ctdb/server/ctdb_recoverd.c

index 03130d660294b63551268f78913293a954b8b38a..19fab572a3bfc71ed830068238e8bf8238a3c8bf 100644 (file)
@@ -1261,6 +1261,7 @@ void set_close_on_exec(int fd);
 
 bool ctdb_recovery_have_lock(struct ctdb_context *ctdb);
 bool ctdb_recovery_lock(struct ctdb_context *ctdb, bool keep);
+void ctdb_recovery_unlock(struct ctdb_context *ctdb);
 
 int ctdb_set_recovery_lock_file(struct ctdb_context *ctdb, const char *file);
 
index 1f1e50aa29293e70f6e13583a6ca52407ca43a29..a4d84fd1a753a22cfb8a7e623c9dc09bc6392b9e 100644 (file)
@@ -784,6 +784,15 @@ bool ctdb_recovery_lock(struct ctdb_context *ctdb, bool keep)
        return true;
 }
 
+void ctdb_recovery_unlock(struct ctdb_context *ctdb)
+{
+       if (ctdb->recovery_lock_fd != -1) {
+               DEBUG(DEBUG_NOTICE, ("Releasing recovery lock\n"));
+               close(ctdb->recovery_lock_fd);
+               ctdb->recovery_lock_fd = -1;
+       }
+}
+
 /*
   delete a record as part of the vacuum process
   only delete if we are not lmaster or dmaster, and our rsn is <= the provided rsn
index 3d7c43240adfd44cc086e1b63418c5b06bb98576..ba42663a576dde3c097d48c9f984f84b96468db9 100644 (file)
@@ -2688,9 +2688,7 @@ static void election_handler(struct ctdb_context *ctdb, uint64_t srvid,
                /* Release the recovery lock file */
                if (em->pnn != ctdb->pnn &&
                    ctdb_recovery_have_lock(ctdb)) {
-                       DEBUG(DEBUG_NOTICE, ("Release the recovery lock\n"));
-                       close(ctdb->recovery_lock_fd);
-                       ctdb->recovery_lock_fd = -1;
+                       ctdb_recovery_unlock(ctdb);
                        unban_all_nodes(ctdb);
                }
        }
@@ -3478,10 +3476,7 @@ static int update_recovery_lock_file(struct ctdb_context *ctdb)
                        DEBUG(DEBUG_ERR,("Reclock file disabled\n"));
                        talloc_free(ctdb->recovery_lock_file);
                        ctdb->recovery_lock_file = NULL;
-                       if (ctdb->recovery_lock_fd != -1) {
-                               close(ctdb->recovery_lock_fd);
-                               ctdb->recovery_lock_fd = -1;
-                       }
+                       ctdb_recovery_unlock(ctdb);
                }
                talloc_free(tmp_ctx);
                return 0;
@@ -3489,10 +3484,7 @@ static int update_recovery_lock_file(struct ctdb_context *ctdb)
 
        if (ctdb->recovery_lock_file == NULL) {
                ctdb->recovery_lock_file = talloc_strdup(ctdb, reclockfile);
-               if (ctdb->recovery_lock_fd != -1) {
-                       close(ctdb->recovery_lock_fd);
-                       ctdb->recovery_lock_fd = -1;
-               }
+               ctdb_recovery_unlock(ctdb);
                talloc_free(tmp_ctx);
                return 0;
        }
@@ -3505,10 +3497,7 @@ static int update_recovery_lock_file(struct ctdb_context *ctdb)
 
        talloc_free(ctdb->recovery_lock_file);
        ctdb->recovery_lock_file = talloc_strdup(ctdb, reclockfile);
-       if (ctdb->recovery_lock_fd != -1) {
-               close(ctdb->recovery_lock_fd);
-               ctdb->recovery_lock_fd = -1;
-       }
+       ctdb_recovery_unlock(ctdb);
 
        talloc_free(tmp_ctx);
        return 0;
@@ -3575,10 +3564,7 @@ static void main_loop(struct ctdb_context *ctdb, struct ctdb_recoverd *rec,
           we close the file
        */
         if (ctdb->recovery_lock_file == NULL) {
-               if (ctdb->recovery_lock_fd != -1) {
-                       close(ctdb->recovery_lock_fd);
-                       ctdb->recovery_lock_fd = -1;
-               }
+               ctdb_recovery_unlock(ctdb);
        }
 
        pnn = ctdb_get_pnn(ctdb);