Rev 268: separate the wire format and internal format for the vnn_map in http://samba.org/~tridge/ctdb

tridge at samba.org tridge at samba.org
Wed May 9 22:13:21 GMT 2007


------------------------------------------------------------
revno: 268
revision-id: tridge at samba.org-20070509221319-2i6pfo0e6gudc6dz
parent: tridge at samba.org-20070509215546-6s0mhsloyilervjf
committer: Andrew Tridgell <tridge at samba.org>
branch nick: tridge
timestamp: Thu 2007-05-10 08:13:19 +1000
message:
  separate the wire format and internal format for the vnn_map
modified:
  common/ctdb.c                  ctdb.c-20061127094323-t50f58d65iaao5of-2
  common/ctdb_client.c           ctdb_client.c-20070411010216-3kd8v37k61steeya-1
  common/ctdb_recover.c          ctdb_recover.c-20070503002147-admmfgt1oj6gexfo-1
  include/ctdb_private.h         ctdb_private.h-20061117234101-o3qt14umlg9en8z0-13
  tests/ctdbd.sh                 ctdbd.sh-20070411085038-phusiewluwzyqjpc-2
=== modified file 'common/ctdb.c'
--- a/common/ctdb.c	2007-05-09 21:55:46 +0000
+++ b/common/ctdb.c	2007-05-09 22:13:19 +0000
@@ -161,15 +161,16 @@
 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);

=== modified file 'common/ctdb_client.c'
--- a/common/ctdb_client.c	2007-05-06 21:54:17 +0000
+++ b/common/ctdb_client.c	2007-05-09 22:13:19 +0000
@@ -808,6 +808,7 @@
 	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 @@
 		DEBUG(0,(__location__ " ctdb_control for getvnnmap failed\n"));
 		return -1;
 	}
-
-	*vnnmap = (struct ctdb_vnn_map *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
+	
+	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);
+
+	CTDB_NO_MEMORY(ctdb, (*vnnmap)->map);
+	memcpy((*vnnmap)->map, map->map, sizeof(uint32_t)*map->size);
 		    
 	return 0;
 }

=== modified file 'common/ctdb_recover.c'
--- a/common/ctdb_recover.c	2007-05-03 06:18:03 +0000
+++ b/common/ctdb_recover.c	2007-05-09 22:13:19 +0000
@@ -32,9 +32,19 @@
 ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata)
 {
 	CHECK_CONTROL_DATA_SIZE(0);
-
-	outdata->dsize = offsetof(struct ctdb_vnn_map, map) + 4*ctdb->vnn_map->size;
-	outdata->dptr  = (unsigned char *)ctdb->vnn_map;
+	struct ctdb_vnn_map_wire *map;
+	size_t len;
+
+	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;
 }

=== modified file 'include/ctdb_private.h'
--- a/include/ctdb_private.h	2007-05-08 11:16:29 +0000
+++ b/include/ctdb_private.h	2007-05-09 22:13:19 +0000
@@ -192,6 +192,15 @@
 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];
 };
 

=== modified file 'tests/ctdbd.sh'
--- a/tests/ctdbd.sh	2007-05-04 02:18:39 +0000
+++ b/tests/ctdbd.sh	2007-05-09 22:13:19 +0000
@@ -31,4 +31,6 @@
 echo "Testing getdbmap"
 $VALGRIND bin/ctdb_control getdbmap 0 || exit 1
 
+echo "All done"
+
 killall -q ctdbd



More information about the samba-cvs mailing list