]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
cleanup the control "write record"
authorRonnie Sahlberg <sahlberg@ronnie>
Thu, 3 May 2007 06:18:03 +0000 (16:18 +1000)
committerRonnie Sahlberg <sahlberg@ronnie>
Thu, 3 May 2007 06:18:03 +0000 (16:18 +1000)
(This used to be ctdb commit 4dd5c26a21a5dc2b2f76eb23cfeb4df82ba4e956)

ctdb/common/ctdb_client.c
ctdb/common/ctdb_control.c
ctdb/common/ctdb_recover.c
ctdb/include/ctdb_private.h

index 520a7a143f7b3b394600086d60a2b391e6525d68..159949fbfc8cadc221e30b4552cd0005051e6812 100644 (file)
@@ -1074,32 +1074,22 @@ int ctdb_ctrl_cleardb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *
 
 int ctdb_ctrl_write_record(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, TDB_DATA key, TDB_DATA data)
 {
-       int ret, len;
+       struct ctdb_write_record *wr;
        TDB_DATA indata, outdata;
        int32_t res;
-       unsigned char *ptr;
+       int ret, len;
+
+       len = offsetof(struct ctdb_write_record, blob)+key.dsize+data.dsize;
+       wr = (struct ctdb_write_record *)talloc_zero_size(mem_ctx, len);
+       wr->dbid    = dbid;
+       wr->keylen  = key.dsize;
+       wr->datalen = data.dsize;
+       memcpy(&wr->blob[0], &key.dptr[0], key.dsize);
+       memcpy(&wr->blob[key.dsize], &data.dptr[0], data.dsize);
 
-       len =  4; /* dbid */
-       len += 4; /* keylen */
-       len += (key.dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
-       len += 4; /* datalen */
-       len += (data.dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
 
        indata.dsize = len;
-       indata.dptr = (unsigned char *)talloc_array(mem_ctx, uint8_t, len);
-       ptr = indata.dptr;
-       *((uint32_t *)ptr) = dbid;
-       ptr += 4;
-
-       *((uint32_t *)ptr) = key.dsize;
-       ptr += 4;
-       memcpy(ptr, key.dptr, key.dsize);
-       ptr += (key.dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
-
-       *((uint32_t *)ptr) = data.dsize;
-       ptr += 4;
-       memcpy(ptr, data.dptr, data.dsize);
-       ptr += (data.dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
+       indata.dptr = (unsigned char *)wr;
 
        ret = ctdb_control(ctdb, destnode, 0, 
                           CTDB_CONTROL_WRITE_RECORD, 0, indata, 
index ef6ba6f0b144e2b3e047009ae6a46bb9ea4d2a3a..1e9b2e288faeac6ed08c337d3d201fe6b776c1c1 100644 (file)
@@ -326,59 +326,8 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return 0;
        }
 
-       case CTDB_CONTROL_WRITE_RECORD: {
-               uint32_t dbid;
-               struct ctdb_db_context *ctdb_db;
-               unsigned char *ptr;
-               TDB_DATA key, data;
-               struct ctdb_ltdb_header header;
-               int ret;
-
-               outdata->dsize = 0;
-               outdata->dptr = NULL;
-
-               dbid = ((uint32_t *)(&indata.dptr[0]))[0];
-               ctdb_db = find_ctdb_db(ctdb, dbid);
-               if (!ctdb_db) {
-                       DEBUG(0,(__location__ " Unknown db 0x%08x\n",dbid));
-                       return -1;
-               }
-
-               ptr = &indata.dptr[4];
-
-               key.dsize = *((uint32_t *)(ptr));
-               ptr += 4;
-               key.dptr = ptr;
-               ptr += (key.dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
-
-               data.dsize = *((uint32_t *)(ptr));
-               ptr += 4;
-               data.dptr = ptr;
-               ptr += (data.dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
-
-               ret = ctdb_ltdb_lock(ctdb_db, key);
-               if (ret != 0) {
-                       DEBUG(0, (__location__ "Unable to lock db\n"));
-                       return -1;
-               }
-               ret = ctdb_ltdb_fetch(ctdb_db, key, &header, outdata, NULL);
-               if (ret != 0) {
-                       DEBUG(0, (__location__ "Unable to fetch record\n"));
-                       ctdb_ltdb_unlock(ctdb_db, key);
-                       return -1;
-               }
-               header.rsn++;
-
-               ret = ctdb_ltdb_store(ctdb_db, key, &header, data);
-               if (ret != 0) {
-                       DEBUG(0, (__location__ "Unable to store record\n"));
-                       ctdb_ltdb_unlock(ctdb_db, key);
-                       return -1;
-               }
-               ctdb_ltdb_unlock(ctdb_db, key);
-
-               return 0;
-       }
+       case CTDB_CONTROL_WRITE_RECORD:
+               return ctdb_control_writerecord(ctdb, opcode, indata, outdata);
 
        case CTDB_CONTROL_SET_RECMODE: {
                ctdb->recovery_mode = ((uint32_t *)(&indata.dptr[0]))[0];
index 2dcba26a858c9903364678b8016849fc8e606b18..a45180d94ef392f3372877688e21b16ec3952abf 100644 (file)
@@ -109,3 +109,54 @@ ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA ind
 
        return 0;
 }
+
+int 
+ctdb_control_writerecord(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata)
+{
+       struct ctdb_write_record *wr;
+       struct ctdb_db_context *ctdb_db;
+       struct ctdb_ltdb_header header;
+       TDB_DATA key, data;
+       int ret;
+
+       outdata->dsize = 0;
+       outdata->dptr = NULL;
+
+       wr = (struct ctdb_write_record *)indata.dptr;
+
+       ctdb_db = find_ctdb_db(ctdb, wr->dbid);
+       if (!ctdb_db) {
+               DEBUG(0,(__location__ " Unknown db 0x%08x\n", wr->dbid));
+               return -1;
+       }
+
+       key.dsize  = wr->keylen;
+       key.dptr   = (unsigned char *)talloc_memdup(outdata, &wr->blob[0], wr->keylen);
+
+       data.dsize = wr->datalen;
+       data.dptr  = (unsigned char *)talloc_memdup(outdata, &wr->blob[wr->keylen], wr->datalen);
+
+
+       ret = ctdb_ltdb_lock(ctdb_db, key);
+       if (ret != 0) {
+               DEBUG(0, (__location__ "Unable to lock db\n"));
+               return -1;
+       }
+       ret = ctdb_ltdb_fetch(ctdb_db, key, &header, outdata, NULL);
+       if (ret != 0) {
+               DEBUG(0, (__location__ "Unable to fetch record\n"));
+               ctdb_ltdb_unlock(ctdb_db, key);
+               return -1;
+       }
+       header.rsn++;
+
+       ret = ctdb_ltdb_store(ctdb_db, key, &header, data);
+       if (ret != 0) {
+               DEBUG(0, (__location__ "Unable to store record\n"));
+               ctdb_ltdb_unlock(ctdb_db, key);
+               return -1;
+       }
+       ctdb_ltdb_unlock(ctdb_db, key);
+
+       return 0;
+}
index df09ca1218bf9b09938dbcba37790665ba7979fb..2c40cc8eb272c078f76db5a86e780cb5a45aa0ac 100644 (file)
@@ -173,6 +173,16 @@ struct ctdb_vnn_map {
        uint32_t map[1];
 };
 
+/* a structure that contains the elements required for the write record
+   control
+*/
+struct ctdb_write_record {
+       uint32_t dbid;
+       uint32_t keylen;
+       uint32_t datalen;
+       unsigned char blob[1];
+};
+       
 /* main state of the ctdb daemon */
 struct ctdb_context {
        struct event_context *ev;
@@ -645,5 +655,6 @@ int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA
 int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
 int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
 int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
+int ctdb_control_writerecord(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
 
 #endif