s3: Factor out db_ctdb_marshall_loop_next_key from db_ctdb_marshall_loop_next
authorVolker Lendecke <vl@samba.org>
Sat, 10 Nov 2012 13:46:10 +0000 (14:46 +0100)
committerMichael Adam <obnox@samba.org>
Thu, 29 Nov 2012 16:55:19 +0000 (17:55 +0100)
Reviewed-by: Michael Adam <obnox@samba.org>
source3/lib/dbwrap/dbwrap_ctdb.c

index 43b4b28..dea3dc2 100644 (file)
@@ -318,6 +318,26 @@ static TDB_DATA db_ctdb_marshall_finish(struct ctdb_marshall_buffer *m)
        return data;
 }
 
+/*
+   loop over a marshalling buffer
+
+     - pass r==NULL to start
+     - loop the number of times indicated by m->count
+*/
+static struct ctdb_rec_data *db_ctdb_marshall_loop_next_key(
+       struct ctdb_marshall_buffer *m, struct ctdb_rec_data *r, TDB_DATA *key)
+{
+       if (r == NULL) {
+               r = (struct ctdb_rec_data *)&m->data[0];
+       } else {
+               r = (struct ctdb_rec_data *)(r->length + (uint8_t *)r);
+       }
+
+       key->dptr   = &r->data[0];
+       key->dsize  = r->keylen;
+       return r;
+}
+
 /*
    loop over a marshalling buffer
 
@@ -329,19 +349,15 @@ static struct ctdb_rec_data *db_ctdb_marshall_loop_next(struct ctdb_marshall_buf
                                                     struct ctdb_ltdb_header *header,
                                                     TDB_DATA *key, TDB_DATA *data)
 {
+       r = db_ctdb_marshall_loop_next_key(m, r, key);
        if (r == NULL) {
-               r = (struct ctdb_rec_data *)&m->data[0];
-       } else {
-               r = (struct ctdb_rec_data *)(r->length + (uint8_t *)r);
+               return NULL;
        }
 
        if (reqid != NULL) {
                *reqid = r->reqid;
        }
 
-       key->dptr   = &r->data[0];
-       key->dsize  = r->keylen;
-
        if (data != NULL) {
                data->dptr  = &r->data[r->keylen];
                data->dsize = r->datalen;
@@ -1438,9 +1454,8 @@ static int db_ctdb_traverse(struct db_context *db,
 
                        for (i=0; i<mbuf->count; i++) {
                                TDB_DATA key;
-                               rec =db_ctdb_marshall_loop_next(mbuf, rec,
-                                                               NULL, NULL,
-                                                               &key, NULL);
+                               rec = db_ctdb_marshall_loop_next_key(
+                                       mbuf, rec, &key);
                                SMB_ASSERT(rec != NULL);
 
                                if (!tdb_exists(ltdb, key)) {