1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

merged admin enable/disable change from ronnie

(This used to be ctdb commit df17b69dfd83a98f9c711994c7dd51ad2cc0ab8a)
This commit is contained in:
Andrew Tridgell 2007-06-07 11:15:22 +10:00
commit 9754d16d48
6 changed files with 115 additions and 11 deletions

View File

@ -1918,3 +1918,26 @@ int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb,
return 0;
}
/*
set/clear the permanent disabled bit on a remote node
*/
int ctdb_ctrl_permdisable(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t mode)
{
int ret;
TDB_DATA data;
int32_t res;
data.dsize = sizeof(uint32_t);
data.dptr = (unsigned char *)&mode;
ret = ctdb_control(ctdb, destnode, 0,
CTDB_CONTROL_PERMANENTLY_DISABLE, 0, data,
NULL, NULL, &res, &timeout, NULL);
if (ret != 0 || res != 0) {
DEBUG(0,(__location__ " ctdb_control for setpermdisable failed\n"));
return -1;
}
return 0;
}

View File

@ -288,6 +288,10 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
case CTDB_CONTROL_LIST_TUNABLES:
return ctdb_control_list_tunables(ctdb, outdata);
case CTDB_CONTROL_PERMANENTLY_DISABLE:
CHECK_CONTROL_DATA_SIZE(sizeof(uint32_t));
return ctdb_control_permdisable(ctdb, indata);
default:
DEBUG(0,(__location__ " Unknown CTDB control opcode %u\n", opcode));
return -1;

View File

@ -104,12 +104,12 @@ static void ctdb_health_callback(struct ctdb_context *ctdb, int status, void *p)
timeval_current_ofs(ctdb->tunable.monitor_interval, 0),
ctdb_check_health, ctdb);
if (status != 0 && !(node->flags & NODE_FLAGS_DISABLED)) {
if (status != 0 && !(node->flags & NODE_FLAGS_UNHEALTHY)) {
DEBUG(0,("monitor event failed - disabling node\n"));
node->flags |= NODE_FLAGS_DISABLED;
} else if (status == 0 && (node->flags & NODE_FLAGS_DISABLED)) {
node->flags |= NODE_FLAGS_UNHEALTHY;
} else if (status == 0 && (node->flags & NODE_FLAGS_UNHEALTHY)) {
DEBUG(0,("monitor event OK - node re-enabled\n"));
ctdb->nodes[ctdb->vnn]->flags &= ~NODE_FLAGS_DISABLED;
ctdb->nodes[ctdb->vnn]->flags &= ~NODE_FLAGS_UNHEALTHY;
} else {
/* no change */
return;
@ -124,6 +124,7 @@ static void ctdb_health_callback(struct ctdb_context *ctdb, int status, void *p)
/* tell the other nodes that something has changed */
ctdb_daemon_send_message(ctdb, CTDB_BROADCAST_VNNMAP,
CTDB_SRVID_NODE_FLAGS_CHANGED, data);
}
@ -181,3 +182,33 @@ void ctdb_start_monitoring(struct ctdb_context *ctdb)
ctdb_check_health, ctdb);
CTDB_NO_MEMORY_FATAL(ctdb, te);
}
/*
administratively disable/enable a node
*/
int32_t ctdb_control_permdisable(struct ctdb_context *ctdb, TDB_DATA indata)
{
uint32_t set = *(uint32_t *)indata.dptr;
TDB_DATA data;
struct ctdb_node_flag_change c;
struct ctdb_node *node = ctdb->nodes[ctdb->vnn];
if (set) {
node->flags |= NODE_FLAGS_PERMANENTLY_DISABLED;
} else {
node->flags &= ~NODE_FLAGS_PERMANENTLY_DISABLED;
}
c.vnn = ctdb->vnn;
c.flags = node->flags;
data.dptr = (uint8_t *)&c;
data.dsize = sizeof(c);
/* tell the other nodes that something has changed */
ctdb_daemon_send_message(ctdb, CTDB_BROADCAST_VNNMAP,
CTDB_SRVID_NODE_FLAGS_CHANGED, data);
return 0;
}

View File

@ -351,6 +351,9 @@ int ctdb_ctrl_list_tunables(struct ctdb_context *ctdb,
TALLOC_CTX *mem_ctx,
const char ***list, uint32_t *count);
int ctdb_ctrl_permdisable(struct ctdb_context *ctdb,
struct timeval timeout,
uint32_t destnode,
uint32_t mode);
#endif

View File

@ -111,8 +111,10 @@ struct ctdb_node {
const char *name; /* for debug messages */
void *private_data; /* private to transport */
uint32_t vnn;
#define NODE_FLAGS_CONNECTED 0x00000001
#define NODE_FLAGS_DISABLED 0x00000002
#define NODE_FLAGS_CONNECTED 0x00000001
#define NODE_FLAGS_UNHEALTHY 0x00000002
#define NODE_FLAGS_PERMANENTLY_DISABLED 0x00000004
#define NODE_FLAGS_DISABLED (NODE_FLAGS_UNHEALTHY|NODE_FLAGS_PERMANENTLY_DISABLED)
uint32_t flags;
/* used by the dead node monitoring */
@ -412,6 +414,7 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS = 0,
CTDB_CONTROL_GET_TUNABLE = 49,
CTDB_CONTROL_LIST_TUNABLES = 50,
CTDB_CONTROL_GET_PUBLIC_IPS = 51,
CTDB_CONTROL_PERMANENTLY_DISABLE = 52,
};
/*
@ -1007,4 +1010,6 @@ int32_t ctdb_control_list_tunables(struct ctdb_context *ctdb, TDB_DATA *outdata)
void ctdb_tunables_set_defaults(struct ctdb_context *ctdb);
int32_t ctdb_control_permdisable(struct ctdb_context *ctdb, TDB_DATA indata);
#endif

View File

@ -285,11 +285,13 @@ static int control_status(struct ctdb_context *ctdb, int argc, const char **argv
}
if(options.machinereadable){
printf(":Node:IP:Status:\n");
printf(":Node:IP:Connected:Disabled:Permanently Disabled:\n");
for(i=0;i<nodemap->num;i++){
printf(":%d:%s:%d:\n", nodemap->nodes[i].vnn,
printf(":%d:%s:%d:%d:%d:\n", nodemap->nodes[i].vnn,
inet_ntoa(nodemap->nodes[i].sin.sin_addr),
!!nodemap->nodes[i].flags&NODE_FLAGS_CONNECTED);
!!(nodemap->nodes[i].flags&NODE_FLAGS_CONNECTED),
!!(nodemap->nodes[i].flags&NODE_FLAGS_UNHEALTHY),
!!(nodemap->nodes[i].flags&NODE_FLAGS_PERMANENTLY_DISABLED));
}
return 0;
}
@ -297,8 +299,10 @@ static int control_status(struct ctdb_context *ctdb, int argc, const char **argv
printf("Number of nodes:%d\n", nodemap->num);
for(i=0;i<nodemap->num;i++){
const char *flags_str;
if (nodemap->nodes[i].flags & NODE_FLAGS_DISABLED) {
if (nodemap->nodes[i].flags & NODE_FLAGS_PERMANENTLY_DISABLED) {
flags_str = "DISABLED";
} else if (nodemap->nodes[i].flags & NODE_FLAGS_UNHEALTHY) {
flags_str = "UNHEALTHY";
} else if (nodemap->nodes[i].flags & NODE_FLAGS_CONNECTED) {
flags_str = "CONNECTED";
} else {
@ -394,6 +398,38 @@ static int control_getpid(struct ctdb_context *ctdb, int argc, const char **argv
return 0;
}
/*
disable a remote node
*/
static int control_disable(struct ctdb_context *ctdb, int argc, const char **argv)
{
int ret;
ret = ctdb_ctrl_permdisable(ctdb, TIMELIMIT(), options.vnn, NODE_FLAGS_PERMANENTLY_DISABLED);
if (ret != 0) {
printf("Unable to disable node %u\n", options.vnn);
return ret;
}
return 0;
}
/*
enable a disabled remote node
*/
static int control_enable(struct ctdb_context *ctdb, int argc, const char **argv)
{
int ret;
ret = ctdb_ctrl_permdisable(ctdb, TIMELIMIT(), options.vnn, 0);
if (ret != 0) {
printf("Unable to enable node %u\n", options.vnn);
return ret;
}
return 0;
}
/*
shutdown a daemon
*/
@ -835,6 +871,8 @@ static const struct {
{ "attach", control_attach, "attach to a database", "<dbname>" },
{ "dumpmemory", control_dumpmemory, "dump memory map to logs" },
{ "getpid", control_getpid, "get ctdbd process ID" },
{ "disable", control_disable, "disable a node" },
{ "enable", control_enable, "enable a node" },
{ "shutdown", control_shutdown, "shutdown ctdbd" },
{ "recover", control_recover, "force recovery" },
{ "freeze", control_freeze, "freeze all databases" },