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

add a control to create a database

(This used to be ctdb commit 74e489c6737cc79537c7812ea82daafb1b363ec2)
This commit is contained in:
Ronnie Sahlberg 2007-05-02 12:43:35 +10:00
parent 1f84807005
commit d20990c2b6
3 changed files with 40 additions and 0 deletions

View File

@ -623,4 +623,8 @@ int32_t ctdb_control_db_attach(struct ctdb_context *ctdb, TDB_DATA indata,
int ctdb_daemon_set_call(struct ctdb_context *ctdb, uint32_t db_id,
ctdb_fn_t fn, int id);
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);
#endif

View File

@ -243,6 +243,7 @@ int main(int argc, const char *argv[])
printf("DATA:\n%s\n", (char *)call.reply_data.dptr);
sleep(999999);
/* go into a wait loop to allow other nodes to complete */
ctdb_shutdown(ctdb);

View File

@ -23,6 +23,7 @@
#include "system/filesys.h"
#include "popt.h"
#include "cmdline.h"
#include "../include/ctdb.h"
#include "../include/ctdb_private.h"
@ -43,6 +44,7 @@ static void usage(void)
printf(" setvnnmap <vnn> <generation> <numslots> <lmaster>*\n");
printf(" getdbmap <vnn> lists databases on a node\n");
printf(" getnodemap <vnn> lists nodes known to a ctdb daemon\n");
printf(" createdb <vnn> <dbname> create a database\n");
printf(" catdb <vnn> <dbid> lists all keys in a remote tdb\n");
printf(" cpdb <fromvnn> <tovnn> <dbid> lists all keys in a remote tdb\n");
printf(" setdmaster <vnn> <dbid> <dmaster> sets new dmaster for all records in the database\n");
@ -710,6 +712,37 @@ static int control_cleardb(struct ctdb_context *ctdb, int argc, const char **arg
return 0;
}
/*
create a database
*/
static int control_createdb(struct ctdb_context *ctdb, int argc, const char **argv)
{
uint32_t vnn;
const char *dbname;
int ret;
int32_t res;
TDB_DATA data;
if (argc < 2) {
usage();
}
vnn = strtoul(argv[0], NULL, 0);
dbname = argv[1];
/* tell ctdb daemon to attach */
data.dptr = discard_const(dbname);
data.dsize = strlen(dbname)+1;
ret = ctdb_control(ctdb, vnn, 0, CTDB_CONTROL_DB_ATTACH,
0, data, ctdb, &data, &res);
if (ret != 0 || res != 0 || data.dsize != sizeof(uint32_t)) {
DEBUG(0,("Failed to attach to database '%s'\n", dbname));
return -1;
}
return 0;
}
/*
ping all node
*/
@ -898,6 +931,8 @@ int main(int argc, const char *argv[])
ret = control_setdmaster(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "cleardb") == 0) {
ret = control_cleardb(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "createdb") == 0) {
ret = control_createdb(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "getrecmode") == 0) {
ret = control_getrecmode(ctdb, extra_argc-1, extra_argv+1);
} else if (strcmp(control, "setrecmode") == 0) {