summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2014-10-21 09:42:20 -0500
committerDavid Teigland <teigland@redhat.com>2015-06-23 16:17:14 -0500
commitc2a227a1d4a3e895fd2ed020babcb2610a684148 (patch)
tree50940e5edd3da92873848d719c2b66c9b662178a
parent024c81f981427106a9b23e20b373d48042dc08dc (diff)
downloadlvm2-dev-dct-lvmetactl.tar.gz
lvmetactl: new program to interact with lvmetaddev-dct-lvmetactl
-rw-r--r--daemons/lvmetad/Makefile.in6
-rw-r--r--daemons/lvmetad/lvmetactl.c182
2 files changed, 187 insertions, 1 deletions
diff --git a/daemons/lvmetad/Makefile.in b/daemons/lvmetad/Makefile.in
index 765128c83..090bb7649 100644
--- a/daemons/lvmetad/Makefile.in
+++ b/daemons/lvmetad/Makefile.in
@@ -18,7 +18,7 @@ top_builddir = @top_builddir@
SOURCES = lvmetad-core.c
SOURCES2 = testclient.c
-TARGETS = lvmetad
+TARGETS = lvmetad lvmetactl
.PHONY: install_lvmetad
@@ -41,6 +41,10 @@ lvmetad: $(OBJECTS) $(top_builddir)/libdaemon/client/libdaemonclient.a \
$(top_builddir)/libdaemon/server/libdaemonserver.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJECTS) $(LVMLIBS) $(LIBS)
+lvmetactl: lvmetactl.o $(top_builddir)/libdaemon/client/libdaemonclient.a \
+ $(top_builddir)/libdaemon/server/libdaemonserver.a
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ lvmetactl.o $(LVMLIBS)
+
# TODO: No idea. No idea how to test either.
#ifneq ("$(CFLOW_CMD)", "")
#CFLOW_SOURCES = $(addprefix $(srcdir)/, $(SOURCES))
diff --git a/daemons/lvmetad/lvmetactl.c b/daemons/lvmetad/lvmetactl.c
new file mode 100644
index 000000000..7f2b3c187
--- /dev/null
+++ b/daemons/lvmetad/lvmetactl.c
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ */
+
+#include "configure.h"
+#include "lvmetad-client.h"
+
+daemon_handle h;
+
+static void print_reply(daemon_reply reply)
+{
+ const char *a = daemon_reply_str(reply, "response", NULL);
+ const char *b = daemon_reply_str(reply, "status", NULL);
+ const char *c = daemon_reply_str(reply, "reason", NULL);
+
+ printf("response \"%s\" status \"%s\" reason \"%s\"\n",
+ a ? a : "", b ? b : "", c ? c : "");
+}
+
+int main(int argc, char **argv)
+{
+ daemon_reply reply;
+ char *cmd;
+ char *uuid;
+ char *name;
+ int val;
+ int ver;
+
+ if (argc < 2) {
+ printf("lvmeta dump\n");
+ printf("lvmeta pv_list\n");
+ printf("lvmeta vg_list\n");
+ printf("lvmeta vg_lookup_name <name>\n");
+ printf("lvmeta vg_lookup_uuid <uuid>\n");
+ printf("lvmeta pv_lookup_uuid <uuid>\n");
+ printf("lvmeta set_global_invalid 0|1\n");
+ printf("lvmeta get_global_invalid\n");
+ printf("lvmeta set_vg_version <uuid> <version>\n");
+ printf("lvmeta vg_lock_type <uuid>\n");
+ return -1;
+ }
+
+ cmd = argv[1];
+
+ h = lvmetad_open(NULL);
+
+ if (!strcmp(cmd, "dump")) {
+ reply = daemon_send_simple(h, "dump",
+ "token = %s", "skip",
+ NULL);
+ printf("%s\n", reply.buffer.mem);
+
+ } else if (!strcmp(cmd, "pv_list")) {
+ reply = daemon_send_simple(h, "pv_list",
+ "token = %s", "skip",
+ NULL);
+ printf("%s\n", reply.buffer.mem);
+
+ } else if (!strcmp(cmd, "vg_list")) {
+ reply = daemon_send_simple(h, "vg_list",
+ "token = %s", "skip",
+ NULL);
+ printf("%s\n", reply.buffer.mem);
+
+ } else if (!strcmp(cmd, "set_global_invalid")) {
+ if (argc < 3) {
+ printf("set_global_invalid 0|1\n");
+ return -1;
+ }
+ val = atoi(argv[2]);
+
+ reply = daemon_send_simple(h, "set_global_info",
+ "global_invalid = %d", val,
+ "token = %s", "skip",
+ NULL);
+ print_reply(reply);
+
+ } else if (!strcmp(cmd, "get_global_invalid")) {
+ reply = daemon_send_simple(h, "get_global_info",
+ "token = %s", "skip",
+ NULL);
+ printf("%s\n", reply.buffer.mem);
+
+ } else if (!strcmp(cmd, "set_vg_version")) {
+ if (argc < 4) {
+ printf("set_vg_version <uuid> <ver>\n");
+ return -1;
+ }
+ uuid = argv[2];
+ ver = atoi(argv[3]);
+
+ reply = daemon_send_simple(h, "set_vg_info",
+ "uuid = %s", uuid,
+ "version = %d", ver,
+ "token = %s", "skip",
+ NULL);
+ print_reply(reply);
+
+ } else if (!strcmp(cmd, "vg_lookup_name")) {
+ if (argc < 3) {
+ printf("vg_lookup_name <name>\n");
+ return -1;
+ }
+ name = argv[2];
+
+ reply = daemon_send_simple(h, "vg_lookup",
+ "name = %s", name,
+ "token = %s", "skip",
+ NULL);
+ printf("%s\n", reply.buffer.mem);
+
+ } else if (!strcmp(cmd, "vg_lookup_uuid")) {
+ if (argc < 3) {
+ printf("vg_lookup_uuid <uuid>\n");
+ return -1;
+ }
+ uuid = argv[2];
+
+ reply = daemon_send_simple(h, "vg_lookup",
+ "uuid = %s", uuid,
+ "token = %s", "skip",
+ NULL);
+ printf("%s\n", reply.buffer.mem);
+
+ } else if (!strcmp(cmd, "vg_lock_type")) {
+ struct dm_config_node *metadata;
+ const char *lock_type;
+
+ if (argc < 3) {
+ printf("vg_lock_type <uuid>\n");
+ return -1;
+ }
+ uuid = argv[2];
+
+ reply = daemon_send_simple(h, "vg_lookup",
+ "uuid = %s", uuid,
+ "token = %s", "skip",
+ NULL);
+ /* printf("%s\n", reply.buffer.mem); */
+
+ metadata = dm_config_find_node(reply.cft->root, "metadata");
+ if (!metadata) {
+ printf("no metadata\n");
+ goto out;
+ }
+
+ lock_type = dm_config_find_str(metadata, "metadata/lock_type", NULL);
+ if (!lock_type) {
+ printf("no lock_type\n");
+ goto out;
+ }
+ printf("lock_type %s\n", lock_type);
+
+ } else if (!strcmp(cmd, "pv_lookup_uuid")) {
+ if (argc < 3) {
+ printf("pv_lookup_uuid <uuid>\n");
+ return -1;
+ }
+ uuid = argv[2];
+
+ reply = daemon_send_simple(h, "pv_lookup",
+ "uuid = %s", uuid,
+ "token = %s", "skip",
+ NULL);
+ printf("%s\n", reply.buffer.mem);
+
+ } else {
+ printf("unknown command\n");
+ goto out_close;
+ }
+out:
+ daemon_reply_destroy(reply);
+out_close:
+ daemon_close(h);
+ return 0;
+}