ctdb-daemon: Simplify code using tdb_storev
authorAmitay Isaacs <amitay@gmail.com>
Fri, 2 Sep 2016 07:53:32 +0000 (17:53 +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 68a839ede59947b31b8fd1a80284cd990239ba0f..8ff963419f15197fd0236d6bedad26fc40098b23 100644 (file)
@@ -57,7 +57,7 @@ static int ctdb_ltdb_store_server(struct ctdb_db_context *ctdb_db,
                                  TDB_DATA data)
 {
        struct ctdb_context *ctdb = ctdb_db->ctdb;
-       TDB_DATA rec;
+       TDB_DATA rec[2];
        uint32_t hsize = sizeof(struct ctdb_ltdb_header);
        int ret;
        bool seqnum_suppressed = false;
@@ -186,12 +186,11 @@ store:
         */
        header->flags &= ~CTDB_REC_FLAG_AUTOMATIC;
 
-       rec.dsize = sizeof(*header) + data.dsize;
-       rec.dptr = talloc_size(ctdb, rec.dsize);
-       CTDB_NO_MEMORY(ctdb, rec.dptr);
+       rec[0].dsize = hsize;
+       rec[0].dptr = (uint8_t *)header;
 
-       memcpy(rec.dptr, header, sizeof(*header));
-       memcpy(rec.dptr + sizeof(*header), data.dptr, data.dsize);
+       rec[1].dsize = data.dsize;
+       rec[1].dptr = data.dptr;
 
        /* Databases with seqnum updates enabled only get their seqnum
           changes when/if we modify the data */
@@ -215,7 +214,7 @@ store:
                            ctdb_hash(&key)));
 
        if (keep) {
-               ret = tdb_store(ctdb_db->ltdb->tdb, key, rec, TDB_REPLACE);
+               ret = tdb_storev(ctdb_db->ltdb->tdb, key, rec, 2, TDB_REPLACE);
        } else {
                ret = tdb_delete(ctdb_db->ltdb->tdb, key);
        }
@@ -242,8 +241,6 @@ store:
                tdb_add_flags(ctdb_db->ltdb->tdb, TDB_SEQNUM);
        }
 
-       talloc_free(rec.dptr);
-
        if (schedule_for_deletion) {
                int ret2;
                ret2 = ctdb_local_schedule_for_deletion(ctdb_db, header, key);