1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-08 05:57:51 +03:00

merged cleanup from ronnie

(This used to be ctdb commit 971e7f82f3e1e9bfc8d521080c86431fbb59277d)
This commit is contained in:
Andrew Tridgell 2007-05-03 11:13:01 +10:00
commit 475cfa245c
8 changed files with 115 additions and 95 deletions

View File

@ -32,7 +32,7 @@ CTDB_COMMON_OBJ = common/ctdb.o common/ctdb_daemon.o common/ctdb_client.o \
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

View File

@ -141,18 +141,13 @@ 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(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;
}

View File

@ -769,11 +769,11 @@ int ctdb_ctrl_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_s
/*
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,
@ -784,16 +784,11 @@ int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctd
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;
}
@ -915,28 +910,20 @@ int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb, uint32_t destnode,
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;
TDB_DATA data, outdata;
int32_t 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);
((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;
}

View File

@ -34,14 +34,6 @@ struct ctdb_control_state {
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;
@ -179,21 +171,8 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
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;
@ -245,26 +224,8 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
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;

View File

@ -0,0 +1,54 @@
/*
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;
}

View File

@ -201,7 +201,7 @@ struct ctdb_status;
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

View File

@ -169,7 +169,7 @@ struct ctdb_status {
struct ctdb_vnn_map {
uint32_t generation;
uint32_t size;
uint32_t *map;
uint32_t map[1];
};
/* main state of the ctdb daemon */
@ -629,4 +629,18 @@ int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
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

View File

@ -243,7 +243,7 @@ static int control_status_reset(struct ctdb_context *ctdb, int argc, const char
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;
@ -375,19 +375,24 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg
/* 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 */
@ -399,7 +404,7 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg
}
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;
@ -432,15 +437,14 @@ static int control_getvnnmap(struct ctdb_context *ctdb, int argc, const char **a
{
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;
@ -643,19 +647,24 @@ static int control_getnodemap(struct ctdb_context *ctdb, int argc, const char **
*/
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);
}