From 850d5de96702b8c4bd8a285b4bd44a15350dfca8 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 10 Nov 2012 15:03:35 +0100 Subject: s3: reduce db_ctdb_marshall_loop_next to specialized db_ctdb_marshall_buf_parse now that the db_ctdb_marshall_loop_next_key has been factored out. Reviewed-by: Michael Adam --- source3/lib/dbwrap/dbwrap_ctdb.c | 69 ++++++++++++---------------------------- 1 file changed, 21 insertions(+), 48 deletions(-) (limited to 'source3/lib/dbwrap/dbwrap_ctdb.c') diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c index dea3dc281c..642053875f 100644 --- a/source3/lib/dbwrap/dbwrap_ctdb.c +++ b/source3/lib/dbwrap/dbwrap_ctdb.c @@ -338,43 +338,22 @@ static struct ctdb_rec_data *db_ctdb_marshall_loop_next_key( return r; } -/* - 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(struct ctdb_marshall_buffer *m, struct ctdb_rec_data *r, - uint32_t *reqid, - struct ctdb_ltdb_header *header, - TDB_DATA *key, TDB_DATA *data) +static bool db_ctdb_marshall_buf_parse( + struct ctdb_rec_data *r, uint32_t *reqid, + struct ctdb_ltdb_header **header, TDB_DATA *data) { - r = db_ctdb_marshall_loop_next_key(m, r, key); - if (r == NULL) { - return NULL; + if (r->datalen < sizeof(struct ctdb_ltdb_header)) { + return false; } - if (reqid != NULL) { - *reqid = r->reqid; - } + *reqid = r->reqid; - if (data != NULL) { - data->dptr = &r->data[r->keylen]; - data->dsize = r->datalen; - if (header != NULL) { - data->dptr += sizeof(*header); - data->dsize -= sizeof(*header); - } - } + data->dptr = &r->data[r->keylen] + sizeof(struct ctdb_ltdb_header); + data->dsize = r->datalen - sizeof(struct ctdb_ltdb_header); - if (header != NULL) { - if (r->datalen < sizeof(*header)) { - return NULL; - } - *header = *(struct ctdb_ltdb_header *)&r->data[r->keylen]; - } + *header = (struct ctdb_ltdb_header *)&r->data[r->keylen]; - return r; + return true; } /** @@ -460,8 +439,7 @@ static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf, TDB_DATA *pdata) { struct ctdb_rec_data *rec = NULL; - struct ctdb_ltdb_header h; - bool found = false; + struct ctdb_ltdb_header *h = NULL; TDB_DATA data; int i; @@ -469,9 +447,6 @@ static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf, return false; } - ZERO_STRUCT(h); - ZERO_STRUCT(data); - /* * Walk the list of records written during this * transaction. If we want to read one we have already @@ -481,26 +456,24 @@ static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf, */ for (i=0; icount; i++) { - TDB_DATA tkey, tdata; + TDB_DATA tkey; uint32_t reqid; - struct ctdb_ltdb_header hdr; - - ZERO_STRUCT(hdr); - rec = db_ctdb_marshall_loop_next(buf, rec, &reqid, &hdr, &tkey, - &tdata); + rec = db_ctdb_marshall_loop_next_key(buf, rec, &tkey); if (rec == NULL) { return false; } - if (tdb_data_equal(key, tkey)) { - found = true; - data = tdata; - h = hdr; + if (!tdb_data_equal(key, tkey)) { + continue; + } + + if (!db_ctdb_marshall_buf_parse(rec, &reqid, &h, &data)) { + return false; } } - if (!found) { + if (h == NULL) { return false; } @@ -514,7 +487,7 @@ static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf, } if (pheader != NULL) { - *pheader = h; + *pheader = *h; } return true; -- cgit