diff options
author | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2011-07-20 15:31:44 +1000 |
---|---|---|
committer | Ronnie Sahlberg <ronniesahlberg@gmail.com> | 2011-08-23 10:33:17 +1000 |
commit | 1bbd4cbf35518ece7076d8219f17cdda12017cd6 (patch) | |
tree | c15a022f06db900b6db8ef582c669783605481dd | |
parent | 38e89649107b5c2258b38a6c2dd3faade74d6591 (diff) | |
download | samba-1bbd4cbf35518ece7076d8219f17cdda12017cd6.tar.gz samba-1bbd4cbf35518ece7076d8219f17cdda12017cd6.tar.xz samba-1bbd4cbf35518ece7076d8219f17cdda12017cd6.zip |
ReadOnly: Add a ctdb_ltdb_fetch_readonly() helper function
(This used to be ctdb commit 8551420fb331dd2a897f4619278a981fcefb96e8)
-rw-r--r-- | ctdb/common/ctdb_ltdb.c | 34 | ||||
-rw-r--r-- | ctdb/include/ctdb_private.h | 3 |
2 files changed, 37 insertions, 0 deletions
diff --git a/ctdb/common/ctdb_ltdb.c b/ctdb/common/ctdb_ltdb.c index bc17b47e6a..76274ceafb 100644 --- a/ctdb/common/ctdb_ltdb.c +++ b/ctdb/common/ctdb_ltdb.c @@ -119,6 +119,40 @@ int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db, return 0; } +/* + fetch a record from the ltdb, separating out the header information + and returning the body of the record. + if the record does not exist, *header will be NULL + and data = {0, NULL} +*/ +int ctdb_ltdb_fetch_readonly(struct ctdb_db_context *ctdb_db, + TDB_DATA key, struct ctdb_ltdb_header *header, + TALLOC_CTX *mem_ctx, TDB_DATA *data) +{ + TDB_DATA rec; + + rec = tdb_fetch(ctdb_db->ltdb->tdb, key); + if (rec.dsize < sizeof(*header)) { + free(rec.dptr); + + data->dsize = 0; + data->dptr = NULL; + return -1; + } + + *header = *(struct ctdb_ltdb_header *)rec.dptr; + if (data) { + data->dsize = rec.dsize - sizeof(struct ctdb_ltdb_header); + data->dptr = talloc_memdup(mem_ctx, + sizeof(struct ctdb_ltdb_header)+rec.dptr, + data->dsize); + } + + free(rec.dptr); + + return 0; +} + /* write a record to a normal database diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 93ac28e416..4937bc8762 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -669,6 +669,9 @@ int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db, int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key, struct ctdb_ltdb_header *header, TDB_DATA data); int ctdb_ltdb_delete(struct ctdb_db_context *ctdb_db, TDB_DATA key); +int ctdb_ltdb_fetch_readonly(struct ctdb_db_context *ctdb_db, + TDB_DATA key, struct ctdb_ltdb_header *header, + TALLOC_CTX *mem_ctx, TDB_DATA *data); int32_t ctdb_control_start_persistent_update(struct ctdb_context *ctdb, struct ctdb_req_control *c, TDB_DATA recdata); |