common/ctdb_io.o common/util.o common/ctdb_util.o \
common/ctdb_call.o common/ctdb_ltdb.o common/ctdb_lockwait.o \
common/ctdb_message.o common/cmdline.o common/ctdb_control.o \
- lib/util/debug.o
+ lib/util/debug.o common/ctdb_recover.o
CTDB_TCP_OBJ = tcp/tcp_connect.o tcp/tcp_io.o tcp/tcp_init.o
XXX generation==0 (==invalid) and let the recovery tool populate this
XXX table for the daemons.
*/
- ctdb->vnn_map = talloc_zero(ctdb, struct ctdb_vnn_map);
+ 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->generation = 1;
ctdb->vnn_map->size = ctdb->num_nodes;
- ctdb->vnn_map->map = talloc_array(ctdb->vnn_map, uint32_t, ctdb->vnn_map->size);
- if (ctdb->vnn_map->map == NULL) {
- DEBUG(0,(__location__ " Unable to allocate vnn_map->map structure\n"));
- exit(1);
- }
for(i=0;i<ctdb->vnn_map->size;i++){
ctdb->vnn_map->map[i] = i%ctdb->num_nodes;
}
/*
get vnn map from a remote node
*/
-int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn_map *vnnmap)
+int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, struct ctdb_vnn_map **vnnmap)
{
int ret;
TDB_DATA data, outdata;
- int32_t i, res;
+ int32_t res;
ZERO_STRUCT(data);
ret = ctdb_control(ctdb, destnode, 0,
return -1;
}
- vnnmap->generation = ((uint32_t *)outdata.dptr)[0];
- vnnmap->size = ((uint32_t *)outdata.dptr)[1];
- if (vnnmap->map) {
- talloc_free(vnnmap->map);
- vnnmap->map = NULL;
- }
- vnnmap->map = talloc_array(vnnmap, uint32_t, vnnmap->size);
- for (i=0;i<vnnmap->size;i++) {
- vnnmap->map[i] = ((uint32_t *)outdata.dptr)[i+2];
+ if (*vnnmap) {
+ talloc_free(*vnnmap);
+ *vnnmap=NULL;
}
+ *vnnmap = (struct ctdb_vnn_map *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize);
return 0;
}
int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, struct ctdb_vnn_map *vnnmap)
{
int ret;
- TDB_DATA *data, outdata;
- int32_t i, res;
-
- data = talloc_zero(mem_ctx, TDB_DATA);
- data->dsize = (vnnmap->size+2)*sizeof(uint32_t);
- data->dptr = (unsigned char *)talloc_array(data, uint32_t, vnnmap->size+2);
+ TDB_DATA data, outdata;
+ int32_t res;
- ((uint32_t *)&data->dptr[0])[0] = vnnmap->generation;
- ((uint32_t *)&data->dptr[0])[1] = vnnmap->size;
- for (i=0;i<vnnmap->size;i++) {
- ((uint32_t *)&data->dptr[0])[i+2] = vnnmap->map[i];
- }
+ data.dsize = offsetof(struct ctdb_vnn_map, map) + 4*vnnmap->size;
+ data.dptr = (unsigned char *)vnnmap;
ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_SETVNNMAP, 0, *data,
+ CTDB_CONTROL_SETVNNMAP, 0, data,
ctdb, &outdata, &res);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for setvnnmap failed\n"));
return -1;
}
- talloc_free(data);
return 0;
}
void *private_data;
};
-#define CHECK_CONTROL_DATA_SIZE(size) do { \
- if (indata.dsize != size) { \
- DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
- opcode, indata.dsize, size)); \
- return -1; \
- } \
- } while (0)
-
static int traverse_cleardb(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *p)
{
int ret;
return 0;
}
- case CTDB_CONTROL_GETVNNMAP: {
- uint32_t i, len;
- CHECK_CONTROL_DATA_SIZE(0);
- len = 2+ctdb->vnn_map->size;
- outdata->dsize = 4*len;
- outdata->dptr = (unsigned char *)talloc_array(outdata, uint32_t, len);
-
- ((uint32_t *)outdata->dptr)[0] = ctdb->vnn_map->generation;
- ((uint32_t *)outdata->dptr)[1] = ctdb->vnn_map->size;
- for (i=0;i<ctdb->vnn_map->size;i++) {
- ((uint32_t *)outdata->dptr)[i+2] = ctdb->vnn_map->map[i];
- }
-
- return 0;
- }
+ case CTDB_CONTROL_GETVNNMAP:
+ return ctdb_control_getvnnmap(ctdb, opcode, indata, outdata);
case CTDB_CONTROL_GET_DBMAP: {
uint32_t i, len;
return 0;
}
- case CTDB_CONTROL_SETVNNMAP: {
- uint32_t *ptr, i;
-
- ptr = (uint32_t *)(&indata.dptr[0]);
- ctdb->vnn_map->generation = ptr[0];
- ctdb->vnn_map->size = ptr[1];
- if (ctdb->vnn_map->map) {
- talloc_free(ctdb->vnn_map->map);
- ctdb->vnn_map->map = NULL;
- }
- ctdb->vnn_map->map = talloc_array(ctdb->vnn_map, uint32_t, ctdb->vnn_map->size);
- if (ctdb->vnn_map->map == NULL) {
- DEBUG(0,(__location__ " Unable to allocate vnn_map->map structure\n"));
- exit(1);
- }
- for (i=0;i<ctdb->vnn_map->size;i++) {
- ctdb->vnn_map->map[i] = ptr[i+2];
- }
- return 0;
- }
+ case CTDB_CONTROL_SETVNNMAP:
+ return ctdb_control_setvnnmap(ctdb, opcode, indata, outdata);
case CTDB_CONTROL_PULL_DB: {
uint32_t dbid, lmaster;
--- /dev/null
+/*
+ ctdb_control protocol code
+
+ Copyright (C) Andrew Tridgell 2007
+ Copyright (C) Ronnie Sahlberg 2007
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+#include "includes.h"
+#include "lib/events/events.h"
+#include "lib/tdb/include/tdb.h"
+#include "system/network.h"
+#include "system/filesys.h"
+#include "system/wait.h"
+#include "../include/ctdb_private.h"
+#include "lib/util/dlinklist.h"
+#include "db_wrap.h"
+
+int
+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;
+
+ return 0;
+}
+
+int
+ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata)
+{
+ if (ctdb->vnn_map) {
+ talloc_free(ctdb->vnn_map);
+ ctdb->vnn_map = NULL;
+ }
+
+ ctdb->vnn_map = (struct ctdb_vnn_map *)talloc_memdup(ctdb, indata.dptr, indata.dsize);
+
+ return 0;
+}
+
int ctdb_ctrl_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status *status);
struct ctdb_vnn_map;
-int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn_map *vnnmap);
+int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, struct ctdb_vnn_map **vnnmap);
int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, struct ctdb_vnn_map *vnnmap);
/* table that contains a list of all dbids on a node
struct ctdb_vnn_map {
uint32_t generation;
uint32_t size;
- uint32_t *map;
+ uint32_t map[1];
};
/* main state of the ctdb daemon */
uint32_t opcode, uint32_t flags, TDB_DATA data,
TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status);
+
+
+
+#define CHECK_CONTROL_DATA_SIZE(size) do { \
+ if (indata.dsize != size) { \
+ DEBUG(0,(__location__ " Invalid data size in opcode %u. Got %u expected %u\n", \
+ opcode, indata.dsize, size)); \
+ return -1; \
+ } \
+ } while (0)
+
+int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
+int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata);
+
#endif
static int control_recover(struct ctdb_context *ctdb, int argc, const char **argv)
{
uint32_t vnn, num_nodes, generation, dmaster;
- struct ctdb_vnn_map vnnmap;
+ struct ctdb_vnn_map *vnnmap;
struct ctdb_node_map nodemap;
int i, j, ret;
struct ctdb_dbid_map dbmap;
/* 8: build a new vnn map */
printf("\n8: build a new vnn map with a new generation id\n");
+
+ vnnmap = talloc_zero_size(ctdb, offsetof(struct ctdb_vnn_map, map) + 4*num_nodes);
+ if (vnnmap == NULL) {
+ DEBUG(0,(__location__ " Unable to allocate vnn_map structure\n"));
+ exit(1);
+ }
generation = random();
- vnnmap.generation = generation;
- vnnmap.size = num_nodes;
- vnnmap.map = talloc_array(ctdb, uint32_t, num_nodes);
+ vnnmap->generation = generation;
+ vnnmap->size = num_nodes;
for (i=j=0;i<nodemap.num;i++) {
if (nodemap.nodes[i].flags&NODE_FLAGS_CONNECTED) {
- vnnmap.map[j++]=nodemap.nodes[i].vnn;
+ vnnmap->map[j++]=nodemap.nodes[i].vnn;
}
}
- printf("Generation:%d\n",vnnmap.generation);
- printf("Size:%d\n",vnnmap.size);
- for(i=0;i<vnnmap.size;i++){
- printf("hash:%d lmaster:%d\n",i,vnnmap.map[i]);
+ printf("Generation:%d\n",vnnmap->generation);
+ printf("Size:%d\n",vnnmap->size);
+ for(i=0;i<vnnmap->size;i++){
+ printf("hash:%d lmaster:%d\n",i,vnnmap->map[i]);
}
/* 9: push the new vnn map out to all the nodes */
}
printf("setting new vnn map on node %d\n",nodemap.nodes[j].vnn);
- ret = ctdb_ctrl_setvnnmap(ctdb, nodemap.nodes[j].vnn, ctdb, &vnnmap);
+ ret = ctdb_ctrl_setvnnmap(ctdb, nodemap.nodes[j].vnn, ctdb, vnnmap);
if (ret != 0) {
printf("Unable to set vnnmap for node %u\n", vnn);
return ret;
{
uint32_t vnn;
int i, ret;
- struct ctdb_vnn_map *vnnmap;
+ struct ctdb_vnn_map *vnnmap=NULL;
if (argc < 1) {
usage();
}
vnn = strtoul(argv[0], NULL, 0);
- vnnmap = talloc_zero(ctdb, struct ctdb_vnn_map);
- ret = ctdb_ctrl_getvnnmap(ctdb, vnn, vnnmap);
+ ret = ctdb_ctrl_getvnnmap(ctdb, vnn, ctdb, &vnnmap);
if (ret != 0) {
printf("Unable to get vnnmap from node %u\n", vnn);
return ret;
*/
static int control_setvnnmap(struct ctdb_context *ctdb, int argc, const char **argv)
{
- uint32_t vnn;
+ uint32_t vnn, num_nodes, generation;
struct ctdb_vnn_map *vnnmap;
int i, ret;
if (argc < 3) {
usage();
}
- vnn = strtoul(argv[0], NULL, 0);
+ vnn = strtoul(argv[0], NULL, 0);
+ generation = strtoul(argv[1], NULL, 0);
+ num_nodes = strtoul(argv[2], NULL, 0);
- vnnmap = talloc_zero(ctdb, struct ctdb_vnn_map);
- vnnmap->generation = strtoul(argv[1], NULL, 0);
- vnnmap->size = strtoul(argv[2], NULL, 0);
- vnnmap->map = talloc_array(vnnmap, uint32_t, vnnmap->size);
+ vnnmap = talloc_zero_size(ctdb, offsetof(struct ctdb_vnn_map, map) + 4*num_nodes);
+ if (vnnmap == NULL) {
+ DEBUG(0,(__location__ " Unable to allocate vnn_map structure\n"));
+ exit(1);
+ }
+ vnnmap->generation = generation;
+ vnnmap->size = num_nodes;
for (i=0;i<vnnmap->size;i++) {
vnnmap->map[i] = strtoul(argv[3+i], NULL, 0);
}