mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-07 21:18:59 +03:00
a4ef8fa25e
A global flag in lvmetad indicates it has been disabled. Other flags indicate the reason it was disabled. These flags can be queried using get_global_info. The lvmetactl debugging utility can set and clear the disabled flag in lvmetad. Nothing else sets the disabled flag yet. Commands will check these flags after connecting to lvmetad. If the disabled flag is set, the command will not use the lvmetad cache, but revert to disk scanning. To test this feature: $ lvmetactl get_global_info response = "OK" global_invalid = 0 global_disable = 0 disable_reason = "none" token = "filter:3041577944" $ vgs (should report VGs from lvmetad) $ lvmetactl set_global_disable 1 $ lvmetactl get_global_info response = "OK" global_invalid = 0 global_disable = 1 disable_reason = "DIRECT" token = "filter:3041577944" $ vgs WARNING: Not using lvmetad because the disable flag was set directly. (should report VGs without contacting lvmetad) $ lvmetactl set_global_disable 0 $ vgs (should report VGs from lvmetad)
224 lines
5.2 KiB
C
224 lines
5.2 KiB
C
/*
|
|
* 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 "tool.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("lvmetactl dump\n");
|
|
printf("lvmetactl pv_list\n");
|
|
printf("lvmetactl vg_list\n");
|
|
printf("lvmetactl get_global_info\n");
|
|
printf("lvmetactl vg_lookup_name <name>\n");
|
|
printf("lvmetactl vg_lookup_uuid <uuid>\n");
|
|
printf("lvmetactl pv_lookup_uuid <uuid>\n");
|
|
printf("lvmetactl set_global_invalid 0|1\n");
|
|
printf("lvmetactl set_global_disable 0|1\n");
|
|
printf("lvmetactl set_vg_version <uuid> <name> <version>\n");
|
|
printf("lvmetactl 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, "get_global_info")) {
|
|
reply = daemon_send_simple(h, "get_global_info",
|
|
"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 = " FMTd64, (int64_t) val,
|
|
"token = %s", "skip",
|
|
NULL);
|
|
print_reply(reply);
|
|
|
|
} else if (!strcmp(cmd, "set_global_disable")) {
|
|
if (argc < 3) {
|
|
printf("set_global_disable 0|1\n");
|
|
return -1;
|
|
}
|
|
val = atoi(argv[2]);
|
|
|
|
reply = daemon_send_simple(h, "set_global_info",
|
|
"global_disable = " FMTd64, (int64_t) val,
|
|
"disable_reason = %s", "DIRECT",
|
|
"token = %s", "skip",
|
|
NULL);
|
|
print_reply(reply);
|
|
|
|
} else if (!strcmp(cmd, "set_vg_version")) {
|
|
if (argc < 5) {
|
|
printf("set_vg_version <uuid> <name> <ver>\n");
|
|
return -1;
|
|
}
|
|
uuid = argv[2];
|
|
name = argv[3];
|
|
ver = atoi(argv[4]);
|
|
|
|
if ((strlen(uuid) == 1) && (uuid[0] == '-'))
|
|
uuid = NULL;
|
|
if ((strlen(name) == 1) && (name[0] == '-'))
|
|
name = NULL;
|
|
|
|
if (uuid && name) {
|
|
reply = daemon_send_simple(h, "set_vg_info",
|
|
"uuid = %s", uuid,
|
|
"name = %s", name,
|
|
"version = " FMTd64, (int64_t) ver,
|
|
"token = %s", "skip",
|
|
NULL);
|
|
} else if (uuid) {
|
|
reply = daemon_send_simple(h, "set_vg_info",
|
|
"uuid = %s", uuid,
|
|
"version = " FMTd64, (int64_t) ver,
|
|
"token = %s", "skip",
|
|
NULL);
|
|
} else if (name) {
|
|
reply = daemon_send_simple(h, "set_vg_info",
|
|
"name = %s", name,
|
|
"version = " FMTd64, (int64_t) ver,
|
|
"token = %s", "skip",
|
|
NULL);
|
|
} else {
|
|
printf("name or uuid required\n");
|
|
return -1;
|
|
}
|
|
|
|
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;
|
|
}
|