ctdb-daemon: Simplify code using local variable
authorAmitay Isaacs <amitay@gmail.com>
Fri, 2 Sep 2016 07:51:36 +0000 (17:51 +1000)
committerJeremy Allison <jra@samba.org>
Thu, 27 Oct 2016 21:53:12 +0000 (23:53 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_ltdb_server.c

index 8feaff11c98a3c4846c622e6cf2c47d7ad80a078..68a839ede59947b31b8fd1a80284cd990239ba0f 100644 (file)
@@ -58,6 +58,7 @@ static int ctdb_ltdb_store_server(struct ctdb_db_context *ctdb_db,
 {
        struct ctdb_context *ctdb = ctdb_db->ctdb;
        TDB_DATA rec;
+       uint32_t hsize = sizeof(struct ctdb_ltdb_header);
        int ret;
        bool seqnum_suppressed = false;
        bool keep = false;
@@ -66,14 +67,21 @@ static int ctdb_ltdb_store_server(struct ctdb_db_context *ctdb_db,
        uint32_t lmaster;
 
        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) {
+                       free(old.dptr);
                }
-               if (rec.dptr) free(rec.dptr);
        }
 
        if (ctdb->vnn_map == NULL) {
@@ -191,14 +199,14 @@ store:
                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);
+               }
        }
 
        DEBUG(DEBUG_DEBUG, (__location__ " db[%s]: %s record: hash[0x%08x]\n",