summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2012-11-10 15:03:35 +0100
committerMichael Adam <obnox@samba.org>2012-11-29 18:00:02 +0100
commit850d5de96702b8c4bd8a285b4bd44a15350dfca8 (patch)
treef80cfbb5049c31d1dc088f6e82f55fc379eedee1 /source3/lib
parenta742b6edd5dc23378ec1926777af67ad54e75e10 (diff)
downloadsamba-850d5de96702b8c4bd8a285b4bd44a15350dfca8.tar.gz
samba-850d5de96702b8c4bd8a285b4bd44a15350dfca8.tar.bz2
samba-850d5de96702b8c4bd8a285b4bd44a15350dfca8.zip
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 <obnox@samba.org>
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/dbwrap/dbwrap_ctdb.c69
1 files changed, 21 insertions, 48 deletions
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; i<buf->count; 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;