summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2009-10-22 16:27:45 +0200
committerMichael Adam <obnox@samba.org>2009-11-03 01:02:35 +0100
commit6a898348fa701a6d89ea939d1ba4a11da3d0c598 (patch)
tree5f406f91eb34a55cb9051d400226b8ce20fbdde7
parentd5aa7584824749ae48ede791cf1c76c8e6ab7ad2 (diff)
downloadsamba-6a898348fa701a6d89ea939d1ba4a11da3d0c598.tar.gz
samba-6a898348fa701a6d89ea939d1ba4a11da3d0c598.tar.bz2
samba-6a898348fa701a6d89ea939d1ba4a11da3d0c598.zip
s3:dbrwap_ctdb: add a function db_ctdb_ltdb_store()
and use it in db_ctdb_store() and db_ctdb_transaction_store(). Michael
-rw-r--r--source3/lib/dbwrap_ctdb.c66
1 files changed, 39 insertions, 27 deletions
diff --git a/source3/lib/dbwrap_ctdb.c b/source3/lib/dbwrap_ctdb.c
index 4dd9465c5f..1d207e7abf 100644
--- a/source3/lib/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap_ctdb.c
@@ -75,6 +75,38 @@ static NTSTATUS tdb_error_to_ntstatus(struct tdb_context *tdb)
}
+/*
+ * Store a record together with the ctdb record header
+ * in the local copy of the database.
+ */
+static NTSTATUS db_ctdb_ltdb_store(struct db_ctdb_ctx *db,
+ TDB_DATA key,
+ struct ctdb_ltdb_header *header,
+ TDB_DATA data)
+{
+ TALLOC_CTX *tmp_ctx = talloc_stackframe();
+ TDB_DATA rec;
+ int ret;
+
+ rec.dsize = data.dsize + sizeof(struct ctdb_ltdb_header);
+ rec.dptr = (uint8_t *)talloc_size(tmp_ctx, rec.dsize);
+
+ if (rec.dptr == NULL) {
+ talloc_free(tmp_ctx);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ memcpy(rec.dptr, header, sizeof(struct ctdb_ltdb_header));
+ memcpy(sizeof(struct ctdb_ltdb_header) + (uint8_t *)rec.dptr, data.dptr, data.dsize);
+
+ ret = tdb_store(db->wtdb->tdb, key, rec, TDB_REPLACE);
+
+ talloc_free(tmp_ctx);
+
+ return (ret == 0) ? NT_STATUS_OK
+ : tdb_error_to_ntstatus(db->wtdb->tdb);
+
+}
/*
form a ctdb_rec_data record from a key/data pair
@@ -472,6 +504,7 @@ static int db_ctdb_transaction_store(struct db_ctdb_transaction_handle *h,
int ret;
TDB_DATA rec;
struct ctdb_ltdb_header header;
+ NTSTATUS status;
/* we need the header so we can update the RSN */
rec = tdb_fetch(h->ctx->wtdb->tdb, key);
@@ -512,17 +545,12 @@ static int db_ctdb_transaction_store(struct db_ctdb_transaction_handle *h,
return -1;
}
- rec.dsize = data.dsize + sizeof(struct ctdb_ltdb_header);
- rec.dptr = (uint8_t *)talloc_size(tmp_ctx, rec.dsize);
- if (rec.dptr == NULL) {
- DEBUG(0,(__location__ " Failed to alloc record\n"));
- talloc_free(tmp_ctx);
- return -1;
+ status = db_ctdb_ltdb_store(h->ctx, key, &header, data);
+ if (NT_STATUS_IS_OK(status)) {
+ ret = 0;
+ } else {
+ ret = -1;
}
- memcpy(rec.dptr, &header, sizeof(struct ctdb_ltdb_header));
- memcpy(sizeof(struct ctdb_ltdb_header) + (uint8_t *)rec.dptr, data.dptr, data.dsize);
-
- ret = tdb_store(h->ctx->wtdb->tdb, key, rec, TDB_REPLACE);
talloc_free(tmp_ctx);
@@ -786,24 +814,8 @@ static NTSTATUS db_ctdb_store(struct db_record *rec, TDB_DATA data, int flag)
{
struct db_ctdb_rec *crec = talloc_get_type_abort(
rec->private_data, struct db_ctdb_rec);
- TDB_DATA cdata;
- int ret;
-
- cdata.dsize = sizeof(crec->header) + data.dsize;
-
- if (!(cdata.dptr = SMB_MALLOC_ARRAY(uint8, cdata.dsize))) {
- return NT_STATUS_NO_MEMORY;
- }
-
- memcpy(cdata.dptr, &crec->header, sizeof(crec->header));
- memcpy(cdata.dptr + sizeof(crec->header), data.dptr, data.dsize);
-
- ret = tdb_store(crec->ctdb_ctx->wtdb->tdb, rec->key, cdata, TDB_REPLACE);
- SAFE_FREE(cdata.dptr);
-
- return (ret == 0) ? NT_STATUS_OK
- : tdb_error_to_ntstatus(crec->ctdb_ctx->wtdb->tdb);
+ return db_ctdb_ltdb_store(crec->ctdb_ctx, rec->key, &(crec->header), data);
}