summaryrefslogtreecommitdiff
path: root/ctdb
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2016-09-02 17:11:17 +1000
committerJeremy Allison <jra@samba.org>2016-10-27 23:53:12 +0200
commiteb1b211c9ef0a93b0f74ba763421872def36bb1c (patch)
tree5e13e7263ddd228c8159ec51276f2ce2a813b505 /ctdb
parentf7c6268c3a269a3bd4ac7e847b29b3143525787f (diff)
downloadsamba-eb1b211c9ef0a93b0f74ba763421872def36bb1c.tar.gz
ctdb-common: Simplify code using local variables
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb')
-rw-r--r--ctdb/common/ctdb_ltdb.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/ctdb/common/ctdb_ltdb.c b/ctdb/common/ctdb_ltdb.c
index 6c941d87e45..4f7811d72f9 100644
--- a/ctdb/common/ctdb_ltdb.c
+++ b/ctdb/common/ctdb_ltdb.c
@@ -171,6 +171,7 @@ int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
{
struct ctdb_context *ctdb = ctdb_db->ctdb;
TDB_DATA rec;
+ uint32_t hsize = sizeof(struct ctdb_ltdb_header);
int ret;
bool seqnum_suppressed = false;
@@ -179,14 +180,20 @@ int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
}
if (ctdb->flags & CTDB_FLAG_TORTURE) {
+ TDB_DATA old;
struct ctdb_ltdb_header *h2;
- rec = tdb_fetch(ctdb_db->ltdb->tdb, key);
- h2 = (struct ctdb_ltdb_header *)rec.dptr;
- if (rec.dptr && rec.dsize >= sizeof(h2) && h2->rsn > header->rsn) {
- DEBUG(DEBUG_CRIT,("RSN regression! %llu %llu\n",
- (unsigned long long)h2->rsn, (unsigned long long)header->rsn));
+
+ old = tdb_fetch(ctdb_db->ltdb->tdb, key);
+ h2 = (struct ctdb_ltdb_header *)old.dptr;
+ if (old.dptr != NULL && old.dsize >= hsize &&
+ h2->rsn > header->rsn) {
+ DEBUG(DEBUG_ERR,
+ ("RSN regression! %"PRIu64" %"PRIu64"\n",
+ h2->rsn, header->rsn));
+ }
+ if (old.dptr != NULL) {
+ free(old.dptr);
}
- if (rec.dptr) free(rec.dptr);
}
rec.dsize = sizeof(*header) + data.dsize;
@@ -202,14 +209,14 @@ int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
TDB_DATA old;
old = tdb_fetch(ctdb_db->ltdb->tdb, key);
- if ( (old.dsize == rec.dsize)
- && !memcmp(old.dptr+sizeof(struct ctdb_ltdb_header),
- rec.dptr+sizeof(struct ctdb_ltdb_header),
- rec.dsize-sizeof(struct ctdb_ltdb_header)) ) {
+ if ((old.dsize == hsize + data.dsize) &&
+ memcmp(old.dptr+hsize, data.dptr, data.dsize) == 0) {
tdb_remove_flags(ctdb_db->ltdb->tdb, TDB_SEQNUM);
seqnum_suppressed = true;
}
- if (old.dptr) free(old.dptr);
+ if (old.dptr != NULL) {
+ free(old.dptr);
+ }
}
ret = tdb_store(ctdb_db->ltdb->tdb, key, rec, TDB_REPLACE);
if (ret != 0) {