diff options
author | Amitay Isaacs <amitay@gmail.com> | 2014-08-12 23:54:39 +1000 |
---|---|---|
committer | Martin Schwenke <martins@samba.org> | 2014-08-13 08:57:11 +0200 |
commit | f96f395d853e0181d9ee031c3e3f1d31f5cff35c (patch) | |
tree | ecc167d4a26c116dfa73b1c5dcaf59ee3279d2c9 | |
parent | b8e9f6b015811d7fb162634f85721b5d27ab503b (diff) | |
download | samba-f96f395d853e0181d9ee031c3e3f1d31f5cff35c.tar.gz samba-f96f395d853e0181d9ee031c3e3f1d31f5cff35c.tar.xz samba-f96f395d853e0181d9ee031c3e3f1d31f5cff35c.zip |
ctdb-readonly: Add an early return to simplify code
This patch makes the subsequent logic change small and easier to
understand.
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
-rw-r--r-- | ctdb/server/ctdb_call.c | 73 |
1 files changed, 37 insertions, 36 deletions
diff --git a/ctdb/server/ctdb_call.c b/ctdb/server/ctdb_call.c index 1830b4a7c5..7affe44a79 100644 --- a/ctdb/server/ctdb_call.c +++ b/ctdb/server/ctdb_call.c @@ -1540,6 +1540,8 @@ static int ctdb_revoke_all_delegations(struct ctdb_context *ctdb, struct ctdb_db { struct ctdb_revoke_state *state = talloc_zero(ctdb, struct ctdb_revoke_state); int status; + struct ctdb_ltdb_header new_header; + TDB_DATA new_data; state->ctdb_db = ctdb_db; state->key = key; @@ -1555,45 +1557,44 @@ static int ctdb_revoke_all_delegations(struct ctdb_context *ctdb, struct ctdb_db } status = state->status; + if (status != 0) { + talloc_free(state); + return staus; + } - if (status == 0) { - struct ctdb_ltdb_header new_header; - TDB_DATA new_data; - - if (ctdb_ltdb_lock(ctdb_db, key) != 0) { - DEBUG(DEBUG_ERR,("Failed to chainlock the database in revokechild\n")); - talloc_free(state); - return -1; - } - if (ctdb_ltdb_fetch(ctdb_db, key, &new_header, state, &new_data) != 0) { - ctdb_ltdb_unlock(ctdb_db, key); - DEBUG(DEBUG_ERR,("Failed for fetch tdb record in revokechild\n")); - talloc_free(state); - return -1; - } - header->rsn++; - if (new_header.rsn > header->rsn) { - ctdb_ltdb_unlock(ctdb_db, key); - DEBUG(DEBUG_ERR,("RSN too high in tdb record in revokechild\n")); - talloc_free(state); - return -1; - } - if ( (new_header.flags & (CTDB_REC_RO_REVOKING_READONLY|CTDB_REC_RO_HAVE_DELEGATIONS)) != (CTDB_REC_RO_REVOKING_READONLY|CTDB_REC_RO_HAVE_DELEGATIONS) ) { - ctdb_ltdb_unlock(ctdb_db, key); - DEBUG(DEBUG_ERR,("Flags are wrong in tdb record in revokechild\n")); - talloc_free(state); - return -1; - } - new_header.rsn++; - new_header.flags |= CTDB_REC_RO_REVOKE_COMPLETE; - if (ctdb_ltdb_store(ctdb_db, key, &new_header, new_data) != 0) { - ctdb_ltdb_unlock(ctdb_db, key); - DEBUG(DEBUG_ERR,("Failed to write new record in revokechild\n")); - talloc_free(state); - return -1; - } + if (ctdb_ltdb_lock(ctdb_db, key) != 0) { + DEBUG(DEBUG_ERR,("Failed to chainlock the database in revokechild\n")); + talloc_free(state); + return -1; + } + if (ctdb_ltdb_fetch(ctdb_db, key, &new_header, state, &new_data) != 0) { ctdb_ltdb_unlock(ctdb_db, key); + DEBUG(DEBUG_ERR,("Failed for fetch tdb record in revokechild\n")); + talloc_free(state); + return -1; + } + header->rsn++; + if (new_header.rsn > header->rsn) { + ctdb_ltdb_unlock(ctdb_db, key); + DEBUG(DEBUG_ERR,("RSN too high in tdb record in revokechild\n")); + talloc_free(state); + return -1; + } + if ( (new_header.flags & (CTDB_REC_RO_REVOKING_READONLY|CTDB_REC_RO_HAVE_DELEGATIONS)) != (CTDB_REC_RO_REVOKING_READONLY|CTDB_REC_RO_HAVE_DELEGATIONS) ) { + ctdb_ltdb_unlock(ctdb_db, key); + DEBUG(DEBUG_ERR,("Flags are wrong in tdb record in revokechild\n")); + talloc_free(state); + return -1; + } + new_header.rsn++; + new_header.flags |= CTDB_REC_RO_REVOKE_COMPLETE; + if (ctdb_ltdb_store(ctdb_db, key, &new_header, new_data) != 0) { + ctdb_ltdb_unlock(ctdb_db, key); + DEBUG(DEBUG_ERR,("Failed to write new record in revokechild\n")); + talloc_free(state); + return -1; } + ctdb_ltdb_unlock(ctdb_db, key); talloc_free(state); return status; |