ctdb-tools/ctdb: Add ctdb detach command to detach databases
authorAmitay Isaacs <amitay@gmail.com>
Mon, 31 Mar 2014 04:45:23 +0000 (15:45 +1100)
committerMartin Schwenke <martins@samba.org>
Mon, 14 Apr 2014 01:52:39 +0000 (03:52 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/tools/ctdb.c

index 68d365bf789d13a41bc17edc7340d57c8a606ddd..ad85f084f29ec416e5739e9699267226e446345c 100644 (file)
@@ -5178,6 +5178,45 @@ static int control_attach(struct ctdb_context *ctdb, int argc, const char **argv
        return 0;
 }
 
+/*
+ * detach from a database
+ */
+static int control_detach(struct ctdb_context *ctdb, int argc,
+                         const char **argv)
+{
+       uint32_t db_id;
+       uint8_t flags;
+       int ret, i, status = 0;
+
+       if (argc < 1) {
+               usage();
+       }
+
+       assert_single_node_only();
+
+       for (i=0; i<argc; i++) {
+               if (!db_exists(ctdb, argv[i], &db_id, NULL, &flags)) {
+                       continue;
+               }
+
+               if (flags & CTDB_DB_FLAGS_PERSISTENT) {
+                       DEBUG(DEBUG_ERR, ("Persistent database '%s' "
+                                         "cannot be detached\n", argv[i]));
+                       status = -1;
+                       continue;
+               }
+
+               ret = ctdb_detach(ctdb, db_id);
+               if (ret != 0) {
+                       DEBUG(DEBUG_ERR, ("Database '%s' detach failed\n",
+                                         argv[i]));
+                       status = ret;
+               }
+       }
+
+       return status;
+}
+
 /*
   set db priority
  */
@@ -6224,6 +6263,7 @@ static const struct {
        { "getlog",          control_getlog,            true,   false,  "get the log data from the in memory ringbuffer", "[<level>] [recoverd]" },
        { "clearlog",          control_clearlog,        true,   false,  "clear the log data from the in memory ringbuffer", "[recoverd]" },
        { "attach",          control_attach,            true,   false,  "attach to a database",                 "<dbname> [persistent]" },
+       { "detach",          control_detach,            false,  false,  "detach from a database",                 "<dbname|dbid> [<dbname|dbid> ...]" },
        { "dumpmemory",      control_dumpmemory,        true,   false,  "dump memory map to stdout" },
        { "rddumpmemory",    control_rddumpmemory,      true,   false,  "dump memory map from the recovery daemon to stdout" },
        { "getpid",          control_getpid,            true,   false,  "get ctdbd process ID" },