]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
separate the wire format and internal format for the vnn_map
authorAndrew Tridgell <tridge@samba.org>
Wed, 9 May 2007 22:13:19 +0000 (08:13 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 9 May 2007 22:13:19 +0000 (08:13 +1000)
(This used to be ctdb commit 9a71718d87c5162f1423d85c2e86a01f6771925e)

ctdb/common/ctdb.c
ctdb/common/ctdb_client.c
ctdb/common/ctdb_recover.c
ctdb/include/ctdb_private.h
ctdb/tests/ctdbd.sh

index a7084d1a34cedc76c35dd4f367b976d6c82677dd..cf4e757898501ae250229a381ee6acb05a543e78 100644 (file)
@@ -161,15 +161,16 @@ XXX Once we have recovery working we should initialize this always to
 XXX generation==0 (==invalid) and let the recovery tool populate this 
 XXX table for the daemons. 
 */
-       ctdb->vnn_map = talloc_zero_size(ctdb, offsetof(struct ctdb_vnn_map, map) + 4*ctdb->num_nodes);
-       if (ctdb->vnn_map == NULL) {
-               DEBUG(0,(__location__ " Unable to allocate vnn_map structure\n"));
-               exit(1);
-       }
+       ctdb->vnn_map = talloc(ctdb, struct ctdb_vnn_map);
+       CTDB_NO_MEMORY(ctdb, ctdb->vnn_map);
+
        ctdb->vnn_map->generation = 1;
        ctdb->vnn_map->size = ctdb->num_nodes;
-       for(i=0;i<ctdb->vnn_map->size;i++){
-               ctdb->vnn_map->map[i] = i%ctdb->num_nodes;
+       ctdb->vnn_map->map = talloc_array(ctdb->vnn_map, uint32_t, ctdb->vnn_map->size);
+       CTDB_NO_MEMORY(ctdb, ctdb->vnn_map->map);
+
+       for(i=0;i<ctdb->vnn_map->size;i++) {
+               ctdb->vnn_map->map[i] = i;
        }
        
        talloc_free(lines);
index 02ad4c2d0e2e37fb1cf5cd6cc8e8698ee31bb3ed..eeff60d405ff5517af4401207089144803a15aa9 100644 (file)
@@ -808,6 +808,7 @@ int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, struct timeval timeout, uint3
        int ret;
        TDB_DATA data, outdata;
        int32_t res;
+       struct ctdb_vnn_map_wire *map;
 
        ZERO_STRUCT(data);
        ret = ctdb_control(ctdb, destnode, 0, 
@@ -817,8 +818,22 @@ int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, struct timeval timeout, uint3
                DEBUG(0,(__location__ " ctdb_control for getvnnmap failed\n"));
                return -1;
        }
+       
+       map = (struct ctdb_vnn_map_wire *)outdata.dptr;
+       if (outdata.dsize < offsetof(struct ctdb_vnn_map_wire, map) ||
+           outdata.dsize != map->size*sizeof(uint32_t) + offsetof(struct ctdb_vnn_map_wire, map)) {
+               DEBUG(0,("Bad vnn map size received in ctdb_ctrl_getvnnmap\n"));
+               return -1;
+       }
+
+       (*vnnmap) = talloc(mem_ctx, struct ctdb_vnn_map);
+       CTDB_NO_MEMORY(ctdb, *vnnmap);
+       (*vnnmap)->generation = map->generation;
+       (*vnnmap)->size       = map->size;
+       (*vnnmap)->map        = talloc_array(*vnnmap, uint32_t, map->size);
 
-       *vnnmap = (struct ctdb_vnn_map *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
+       CTDB_NO_MEMORY(ctdb, (*vnnmap)->map);
+       memcpy((*vnnmap)->map, map->map, sizeof(uint32_t)*map->size);
                    
        return 0;
 }
index a45180d94ef392f3372877688e21b16ec3952abf..fd63667dbec335ca3a6c666a17399e5c220934f0 100644 (file)
@@ -32,9 +32,19 @@ int
 ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata)
 {
        CHECK_CONTROL_DATA_SIZE(0);
+       struct ctdb_vnn_map_wire *map;
+       size_t len;
 
-       outdata->dsize = offsetof(struct ctdb_vnn_map, map) + 4*ctdb->vnn_map->size;
-       outdata->dptr  = (unsigned char *)ctdb->vnn_map;
+       len = offsetof(struct ctdb_vnn_map_wire, map) + sizeof(uint32_t)*ctdb->vnn_map->size;
+       map = talloc_size(outdata, len);
+       CTDB_NO_MEMORY_VOID(ctdb, map);
+
+       map->generation = ctdb->vnn_map->generation;
+       map->size = ctdb->vnn_map->size;
+       memcpy(map->map, ctdb->vnn_map->map, sizeof(uint32_t)*map->size);
+
+       outdata->dsize = len;
+       outdata->dptr  = (uint8_t *)map;
 
        return 0;
 }
index 3ade8e714b2632fb1da7bbb16745c23ec417b5b1..0b627458106a201e41e7fc7a37cb29d5d39da85d 100644 (file)
@@ -190,6 +190,15 @@ struct ctdb_status {
 /* table that contains the mapping between a hash value and lmaster
  */
 struct ctdb_vnn_map {
+       uint32_t generation;
+       uint32_t size;
+       uint32_t *map;
+};
+
+/* 
+   a wire representation of the vnn map
+ */
+struct ctdb_vnn_map_wire {
        uint32_t generation;
        uint32_t size;
        uint32_t map[1];
index 1664a68d639aa13032448283f82cb70066c32fb0..104bb71787711be83d7d801f16eb4bdf5abd2a2c 100755 (executable)
@@ -31,4 +31,6 @@ $VALGRIND bin/ctdb_control attach test2.tdb || exit 1
 echo "Testing getdbmap"
 $VALGRIND bin/ctdb_control getdbmap 0 || exit 1
 
+echo "All done"
+
 killall -q ctdbd