return 0;
}
+/*
+ get all keys for a specific database
+ */
+int ctdb_getkeys(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, struct ctdb_key_list *keys)
+{
+ int i, ret;
+ TDB_DATA indata, outdata;
+ int32_t res;
+ unsigned char *ptr;
+
+ indata.dsize = sizeof(uint32_t);
+ indata.dptr = (unsigned char *)&dbid;
+
+ ret = ctdb_control(ctdb, destnode, 0,
+ CTDB_CONTROL_GET_KEYS, indata,
+ mem_ctx, &outdata, &res);
+ if (ret != 0 || res != 0) {
+ DEBUG(0,(__location__ " ctdb_control for getkeys failed\n"));
+ return -1;
+ }
+
+
+ keys->num= *((uint32_t *)(&outdata.dptr[0]));
+ keys->keys=talloc_array(mem_ctx, TDB_DATA, keys->num);
+ keys->headers=talloc_array(mem_ctx, struct ctdb_ltdb_header, keys->num);
+ keys->lmasters=talloc_array(mem_ctx, uint32_t, keys->num);
+ keys->data=talloc_array(mem_ctx, TDB_DATA, keys->num);
+
+ /* loop over all key/data pairs */
+ ptr=&outdata.dptr[4];
+ for(i=0;i<keys->num;i++){
+ uint32_t len;
+ TDB_DATA *key, *data;
+
+ keys->lmasters[i]= *((uint32_t *)ptr);
+ ptr+=4;
+
+ key=&keys->keys[i];
+ key->dsize= *((uint32_t *)ptr);
+ ptr+=4;
+ key->dptr=talloc_size(mem_ctx, key->dsize);
+ memcpy(key->dptr, ptr, key->dsize);
+ len = (key->dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
+ ptr+=len;
+
+ memcpy(&keys->headers[i], ptr, sizeof(struct ctdb_ltdb_header));
+ len = (sizeof(struct ctdb_ltdb_header)+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
+ ptr+=len;
+
+ data=&keys->data[i];
+ data->dsize= *((uint32_t *)ptr);
+ ptr+=4;
+ data->dptr=talloc_size(mem_ctx, data->dsize);
+ memcpy(data->dptr, ptr, data->dsize);
+ len = (data->dsize+CTDB_DS_ALIGNMENT-1)& ~(CTDB_DS_ALIGNMENT-1);
+ ptr+=len;
+
+ }
+
+ return 0;
+}
+
+/*
+ change dmaster for all keys in the database to the new value
+ */
+int ctdb_setdmaster(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster)
+{
+ int ret;
+ TDB_DATA indata, outdata;
+ int32_t res;
+
+ indata.dsize = 2*sizeof(uint32_t);
+ indata.dptr = (unsigned char *)talloc_array(mem_ctx, uint32_t, 2);
+
+ ((uint32_t *)(&indata.dptr[0]))[0] = dbid;
+ ((uint32_t *)(&indata.dptr[0]))[1] = dmaster;
+
+ ret = ctdb_control(ctdb, destnode, 0,
+ CTDB_CONTROL_SET_DMASTER, indata,
+ mem_ctx, &outdata, &res);
+ if (ret != 0 || res != 0) {
+ DEBUG(0,(__location__ " ctdb_control for setdmaster failed\n"));
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ delete all records from a tdb
+ */
+int ctdb_cleardb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid)
+{
+ int ret;
+ TDB_DATA indata, outdata;
+ int32_t res;
+
+ indata.dsize = sizeof(uint32_t);
+ indata.dptr = (unsigned char *)talloc_array(mem_ctx, uint32_t, 1);
+
+ ((uint32_t *)(&indata.dptr[0]))[0] = dbid;
+
+ ret = ctdb_control(ctdb, destnode, 0,
+ CTDB_CONTROL_CLEAR_DB, indata,
+ mem_ctx, &outdata, &res);
+ if (ret != 0 || res != 0) {
+ DEBUG(0,(__location__ " ctdb_control for cleardb failed\n"));
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ pull a db from a remote node
+ */
+int ctdb_pulldb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t from_vnn)
+{
+ int ret;
+ TDB_DATA indata, outdata;
+ int32_t res;
+
+ indata.dsize = 2*sizeof(uint32_t);
+ indata.dptr = (unsigned char *)talloc_array(mem_ctx, uint32_t, 2);
+
+ ((uint32_t *)(&indata.dptr[0]))[0] = dbid;
+ ((uint32_t *)(&indata.dptr[0]))[1] = from_vnn;
+
+ ret = ctdb_control(ctdb, destnode, 0,
+ CTDB_CONTROL_PULL_DB, indata,
+ mem_ctx, &outdata, &res);
+ if (ret != 0 || res != 0) {
+ DEBUG(0,(__location__ " ctdb_control for pulldb failed\n"));
+ return -1;
+ }
+
+ return 0;
+}
+
/*
- ping a node
+ ping a node, return number of clients connected
*/
int ctdb_ping(struct ctdb_context *ctdb, uint32_t destnode)
{
uint32_t num;
struct ctdb_node_and_flags *nodes;
};
- int ctdb_getnodemap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_node_map *nodemap);
+ int ctdb_getnodemap(struct ctdb_context *ctdb, uint32_t destnode,
+ TALLOC_CTX *mem_ctx, struct ctdb_node_map *nodemap);
+struct ctdb_key_list {
+ uint32_t num;
+ TDB_DATA *keys;
+ struct ctdb_ltdb_header *headers;
+ uint32_t *lmasters;
+ TDB_DATA *data;
+};
+int ctdb_getkeys(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, struct ctdb_key_list *keys);
+
int ctdb_getdbpath(struct ctdb_context *ctdb, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **path);
int ctdb_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
int ctdb_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *level);
int ctdb_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint32_t level);
+/*
+ change dmaster for all keys in the database to the new value
+ */
+int ctdb_setdmaster(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster);
+
+/*
+ delete all records from a tdb
+ */
+int ctdb_cleardb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid);
+
+/*
+ pull a db from a remote node
+ */
+int ctdb_pulldb(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t from_vnn);
+
+
+#define CTDB_RECOVERY_NORMAL 0
+#define CTDB_RECOVERY_ACTIVE 1
+/*
+ get the recovery mode of a remote node
+ */
+int ctdb_getrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *recmode);
+/*
+ set the recovery mode of a remote node
+ */
+int ctdb_setrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t recmode);
+
+ uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
+ uint32_t *num_nodes);
+
+ int ctdb_status_reset(struct ctdb_context *ctdb, uint32_t destnode);
+
#endif