📄 ctdb_client.c
字号:
ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_GET_PID, 0, tdb_null, NULL, NULL, &res, &timeout, NULL); if (ret != 0) { DEBUG(0,(__location__ " ctdb_control for getpid failed\n")); return -1; } *pid = res; return 0;}/* freeze a node */int ctdb_ctrl_freeze(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode){ int ret; int32_t res; ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_FREEZE, 0, tdb_null, NULL, NULL, &res, &timeout, NULL); if (ret != 0 || res != 0) { DEBUG(0,(__location__ " ctdb_control freeze failed\n")); return -1; } return 0;}/* thaw a node */int ctdb_ctrl_thaw(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode){ int ret; int32_t res; ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_THAW, 0, tdb_null, NULL, NULL, &res, &timeout, NULL); if (ret != 0 || res != 0) { DEBUG(0,(__location__ " ctdb_control thaw failed\n")); return -1; } return 0;}/* get vnn of a node, or -1 */int ctdb_ctrl_getvnn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode){ int ret; int32_t res; ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_GET_VNN, 0, tdb_null, NULL, NULL, &res, &timeout, NULL); if (ret != 0) { DEBUG(0,(__location__ " ctdb_control for getvnn failed\n")); return -1; } return res;}/* set the monitoring mode of a remote node */int ctdb_ctrl_setmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t monmode){ int ret; TDB_DATA data; int32_t res; data.dsize = sizeof(uint32_t); data.dptr = (uint8_t *)&monmode; ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_SET_MONMODE, 0, data, NULL, NULL, &res, &timeout, NULL); if (ret != 0 || res != 0) { DEBUG(0,(__location__ " ctdb_control for setmonmode failed\n")); return -1; } return 0;}/* get the monitoring mode of a remote node */int ctdb_ctrl_getmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *monmode){ int ret; int32_t res; ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_GET_MONMODE, 0, tdb_null, NULL, NULL, &res, &timeout, NULL); if (ret != 0) { DEBUG(0,(__location__ " ctdb_control for getrecmode failed\n")); return -1; } *monmode = res; return 0;}/* get maximum rsn for a db on a node */int ctdb_ctrl_get_max_rsn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t db_id, uint64_t *max_rsn){ TDB_DATA data, outdata; int ret; int32_t res; data.dptr = (uint8_t *)&db_id; data.dsize = sizeof(db_id); ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_MAX_RSN, 0, data, ctdb, &outdata, &res, &timeout, NULL); if (ret != 0 || res != 0 || outdata.dsize != sizeof(uint64_t)) { DEBUG(0,(__location__ " ctdb_control for get_max_rsn failed\n")); return -1; } *max_rsn = *(uint64_t *)outdata.dptr; talloc_free(outdata.dptr); return 0; }/* set the rsn on non-empty records to the given rsn */int ctdb_ctrl_set_rsn_nonempty(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t db_id, uint64_t rsn){ TDB_DATA data; int ret; int32_t res; struct ctdb_control_set_rsn_nonempty p; p.db_id = db_id; p.rsn = rsn; data.dptr = (uint8_t *)&p; data.dsize = sizeof(p); ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_SET_RSN_NONEMPTY, 0, data, NULL, NULL, &res, &timeout, NULL); if (ret != 0 || res != 0) { DEBUG(0,(__location__ " ctdb_control for set_rsn_nonempty failed\n")); return -1; } return 0; }/* delete records which have a rsn below the given rsn */int ctdb_ctrl_delete_low_rsn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t db_id, uint64_t rsn){ TDB_DATA data; int ret; int32_t res; struct ctdb_control_delete_low_rsn p; p.db_id = db_id; p.rsn = rsn; data.dptr = (uint8_t *)&p; data.dsize = sizeof(p); ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_DELETE_LOW_RSN, 0, data, NULL, NULL, &res, &timeout, NULL); if (ret != 0 || res != 0) { DEBUG(0,(__location__ " ctdb_control for delete_low_rsn failed\n")); return -1; } return 0; }/* sent to a node to make it take over an ip address*/int ctdb_ctrl_takeover_ip(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, struct ctdb_public_ip *ip){ TDB_DATA data; int ret; int32_t res; data.dsize = sizeof(*ip); data.dptr = (uint8_t *)ip; ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_TAKEOVER_IP, 0, data, NULL, NULL, &res, &timeout, NULL); if (ret != 0 || res != 0) { DEBUG(0,(__location__ " ctdb_control for takeover_ip failed\n")); return -1; } return 0; }/* sent to a node to make it release an ip address*/int ctdb_ctrl_release_ip(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, struct ctdb_public_ip *ip){ TDB_DATA data; int ret; int32_t res; data.dsize = sizeof(*ip); data.dptr = (uint8_t *)ip; ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_RELEASE_IP, 0, data, NULL, NULL, &res, &timeout, NULL); if (ret != 0 || res != 0) { DEBUG(0,(__location__ " ctdb_control for release_ip failed\n")); return -1; } return 0; }/* get a tunable */int ctdb_ctrl_get_tunable(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, const char *name, uint32_t *value){ struct ctdb_control_get_tunable *t; TDB_DATA data, outdata; int32_t res; int ret; data.dsize = offsetof(struct ctdb_control_get_tunable, name) + strlen(name) + 1; data.dptr = (unsigned char *)talloc_size(ctdb, data.dsize); CTDB_NO_MEMORY(ctdb, data.dptr); t = (struct ctdb_control_get_tunable *)data.dptr; t->length = strlen(name)+1; memcpy(t->name, name, t->length); ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_GET_TUNABLE, 0, data, ctdb, &outdata, &res, &timeout, NULL); talloc_free(data.dptr); if (ret != 0 || res != 0) { DEBUG(0,(__location__ " ctdb_control for get_tunable failed\n")); return -1; } if (outdata.dsize != sizeof(uint32_t)) { DEBUG(0,("Invalid return data in get_tunable\n")); talloc_free(outdata.dptr); return -1; } *value = *(uint32_t *)outdata.dptr; talloc_free(outdata.dptr); return 0;}/* set a tunable */int ctdb_ctrl_set_tunable(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, const char *name, uint32_t value){ struct ctdb_control_set_tunable *t; TDB_DATA data; int32_t res; int ret; data.dsize = offsetof(struct ctdb_control_set_tunable, name) + strlen(name) + 1; data.dptr = talloc_array(ctdb, unsigned char, data.dsize); CTDB_NO_MEMORY(ctdb, data.dptr); t = (struct ctdb_control_set_tunable *)data.dptr; t->length = strlen(name)+1; memcpy(t->name, name, t->length); t->value = value; ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_SET_TUNABLE, 0, data, NULL, NULL, &res, &timeout, NULL); talloc_free(data.dptr); if (ret != 0 || res != 0) { DEBUG(0,(__location__ " ctdb_control for set_tunable failed\n")); return -1; } return 0;}/* list tunables */int ctdb_ctrl_list_tunables(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, const char ***list, uint32_t *count){ TDB_DATA outdata; int32_t res; int ret; struct ctdb_control_list_tunable *t; char *p, *s, *ptr; ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_LIST_TUNABLES, 0, tdb_null, mem_ctx, &outdata, &res, &timeout, NULL); if (ret != 0 || res != 0) { DEBUG(0,(__location__ " ctdb_control for list_tunables failed\n")); return -1; } t = (struct ctdb_control_list_tunable *)outdata.dptr; if (outdata.dsize < offsetof(struct ctdb_control_list_tunable, data) || t->length > outdata.dsize-offsetof(struct ctdb_control_list_tunable, data)) { DEBUG(0,("Invalid data in list_tunables reply\n")); talloc_free(outdata.dptr); return -1; } p = talloc_strndup(mem_ctx, (char *)t->data, t->length); CTDB_NO_MEMORY(ctdb, p); talloc_free(outdata.dptr); (*list) = NULL; (*count) = 0; for (s=strtok_r(p, ":", &ptr); s; s=strtok_r(NULL, ":", &ptr)) { (*list) = talloc_realloc(mem_ctx, *list, const char *, 1+(*count)); CTDB_NO_MEMORY(ctdb, *list); (*list)[*count] = talloc_strdup(*list, s); CTDB_NO_MEMORY(ctdb, (*list)[*count]); (*count)++; } talloc_free(p); return 0;}int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, struct ctdb_all_public_ips **ips){ int ret; TDB_DATA outdata; int32_t res; ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_GET_PUBLIC_IPS, 0, tdb_null, mem_ctx, &outdata, &res, &timeout, NULL); if (ret != 0 || res != 0) { DEBUG(0,(__location__ " ctdb_control for getpublicips failed\n")); return -1; } *ips = (struct ctdb_all_public_ips *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize); talloc_free(outdata.dptr); return 0;}/* set/clear the permanent disabled bit on a remote node */int ctdb_ctrl_modflags(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t set, uint32_t clear){ int ret; TDB_DATA data; struct ctdb_node_modflags m; int32_t res; m.set = set; m.clear = clear; data.dsize = sizeof(m); data.dptr = (unsigned char *)&m; ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_MODIFY_FLAGS, 0, data, NULL, NULL, &res, &timeout, NULL); if (ret != 0 || res != 0) { DEBUG(0,(__location__ " ctdb_control for modflags failed\n")); return -1; } return 0;}/* get all tunables */int ctdb_ctrl_get_all_tunables(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, struct ctdb_tunable *tunables){ TDB_DATA outdata; int ret; int32_t res; ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_GET_ALL_TUNABLES, 0, tdb_null, ctdb, &outdata, &res, &timeout, NULL); if (ret != 0 || res != 0) { DEBUG(0,(__location__ " ctdb_control for get all tunables failed\n")); return -1; } if (outdata.dsize != sizeof(*tunables)) { DEBUG(0,(__location__ " bad data size %u in ctdb_ctrl_get_all_tunables should be %u\n", (unsigned)outdata.dsize, (unsigned)sizeof(*tunables))); return -1; } *tunables = *(struct ctdb_tunable *)outdata.dptr; talloc_free(outdata.dptr); return 0;}/* kill a tcp connection */int ctdb_ctrl_killtcp(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, struct ctdb_control_killtcp *killtcp){ TDB_DATA data; int32_t res; int ret; data.dsize = sizeof(struct ctdb_control_killtcp); data.dptr = (unsigned char *)killtcp; ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_KILL_TCP, 0, data, NULL, NULL, &res, &timeout, NULL); if (ret != 0 || res != 0) { DEBUG(0,(__location__ " ctdb_control for killtcp failed\n")); return -1; } return 0;}/* get a list of all tcp tickles that a node knows about for a particular vnn */int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t vnn, struct ctdb_control_tcp_tickle_list **list){ int ret; TDB_DATA data, outdata; int32_t status; data.dptr = (uint8_t*)&vnn; data.dsize = sizeof(vnn); ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_GET_TCP_TICKLE_LIST, 0, data, mem_ctx, &outdata, &status, NULL, NULL); if (ret != 0) { DEBUG(0,(__location__ " ctdb_control for get tcp tickles failed\n")); return -1; } *list = (struct ctdb_control_tcp_tickle_list *)outdata.dptr; return status;}/* initialise the ctdb daemon for client applications NOTE: In current code the daemon does not fork. This is for testing purposes only and to simplify the code.*/struct ctdb_context *ctdb_init(struct event_context *ev){ struct ctdb_context *ctdb; ctdb = talloc_zero(ev, struct ctdb_context); ctdb->ev = ev; ctdb->idr = idr_init(ctdb); CTDB_NO_MEMORY_NULL(ctdb, ctdb->idr); ctdb_set_socketname(ctdb, CTDB_PATH); return ctdb;}/* set some ctdb flags*/void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags){ ctdb->flags |= flags;}/* setup the local socket name*/int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname){ ctdb->daemon.name = talloc_strdup(ctdb, socketname); return 0;}/* return the vnn of this node*/uint32_t ctdb_get_vnn(struct ctdb_context *ctdb){ return ctdb->vnn;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -