diff options
author | Martin Schwenke <martin@meltin.net> | 2014-12-09 14:07:20 +1100 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2015-02-13 07:19:07 +0100 |
commit | db32a2bce54b9618fe247b33d6de81bd5f7a3b62 (patch) | |
tree | 9875192a2817ada00c79a30670d647a0611e9f92 | |
parent | 72701be663ddb265320a022a22130a3437bbf6bc (diff) | |
download | samba-db32a2bce54b9618fe247b33d6de81bd5f7a3b62.tar.gz samba-db32a2bce54b9618fe247b33d6de81bd5f7a3b62.tar.xz samba-db32a2bce54b9618fe247b33d6de81bd5f7a3b62.zip |
ctdb-recoverd: New function ctdb_recovery_unlock()
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>
-rw-r--r-- | ctdb/include/ctdb_private.h | 1 | ||||
-rw-r--r-- | ctdb/server/ctdb_recover.c | 9 | ||||
-rw-r--r-- | ctdb/server/ctdb_recoverd.c | 24 |
3 files changed, 15 insertions, 19 deletions
diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 03130d6602..19fab572a3 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -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); diff --git a/ctdb/server/ctdb_recover.c b/ctdb/server/ctdb_recover.c index 1f1e50aa29..a4d84fd1a7 100644 --- a/ctdb/server/ctdb_recover.c +++ b/ctdb/server/ctdb_recover.c @@ -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 diff --git a/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c index 3d7c43240a..ba42663a57 100644 --- a/ctdb/server/ctdb_recoverd.c +++ b/ctdb/server/ctdb_recoverd.c @@ -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); |