summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2016-01-29 14:33:46 -0600
committerDavid Teigland <teigland@redhat.com>2016-03-31 09:51:33 -0500
commit54ad66efc74f5760485a3633040a5e31dcf3c7ee (patch)
treeda902ad72fb33562b1c0e781ca860ec317d69bfb
parent282f98b3fe482021e19e400e225930d9afd05c42 (diff)
downloadlvm2-54ad66efc74f5760485a3633040a5e31dcf3c7ee.tar.gz
pvscan: repopulate and reenable disabled lvmetad
Other commands ignore lvmetad when it's disabled, but pvscan --cache is an exception since it is populating the lvmetad cache, not using the lvmetad cache. Have 'pvscan --cache' clear the disabled flag in lvmetad if, after scanning all devices, it found no lvm1 metadata and found no duplicate PVs.
-rw-r--r--lib/cache/lvmetad.c37
-rw-r--r--lib/cache/lvmetad.h2
-rw-r--r--tools/lvmcmdline.c9
3 files changed, 47 insertions, 1 deletions
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index 45b591193..c1ccdc340 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -35,6 +35,8 @@ static char *_lvmetad_token = NULL;
static const char *_lvmetad_socket = NULL;
static struct cmd_context *_lvmetad_cmd = NULL;
+static int _found_lvm1_metadata = 0;
+
static struct volume_group *lvmetad_pvscan_vg(struct cmd_context *cmd, struct volume_group *vg);
static int _log_debug_inequality(const char *name, struct dm_config_node *a, struct dm_config_node *b)
@@ -1381,6 +1383,7 @@ static struct volume_group *lvmetad_pvscan_vg(struct cmd_context *cmd, struct vo
lvmcache_fmt(info)->ops->destroy_instance(baton.fid);
log_warn("WARNING: Disabling lvmetad cache which does not support obsolete metadata.");
lvmetad_set_disabled(cmd, "LVM1");
+ _found_lvm1_metadata = 1;
return NULL;
}
@@ -1497,6 +1500,7 @@ int lvmetad_pvscan_single(struct cmd_context *cmd, struct device *dev,
log_warn("WARNING: Disabling lvmetad cache which does not support obsolete metadata.");
lvmetad_set_disabled(cmd, "LVM1");
+ _found_lvm1_metadata = 1;
if (ignore_obsolete)
return 1;
@@ -1551,6 +1555,7 @@ static int _lvmetad_pvscan_all_devs(struct cmd_context *cmd, activation_handler
daemon_reply reply;
int r = 1;
char *future_token;
+ const char *reason;
int was_silent;
if (!lvmetad_active()) {
@@ -1600,6 +1605,16 @@ static int _lvmetad_pvscan_all_devs(struct cmd_context *cmd, activation_handler
if (!_token_update())
return 0;
+ /*
+ * If lvmetad is disabled, and no lvm1 metadata was seen and no
+ * duplicate PVs were seen, then re-enable lvmetad.
+ */
+ if (lvmetad_is_disabled(cmd, &reason) &&
+ !lvmcache_found_duplicate_pvs() && !_found_lvm1_metadata) {
+ log_debug_lvmetad("Enabling lvmetad which was previously disabled.");
+ lvmetad_clear_disabled(cmd);
+ }
+
return r;
}
@@ -1996,6 +2011,28 @@ void lvmetad_set_disabled(struct cmd_context *cmd, const char *reason)
daemon_reply_destroy(reply);
}
+void lvmetad_clear_disabled(struct cmd_context *cmd)
+{
+ daemon_reply reply;
+
+ if (!_lvmetad_use)
+ return;
+
+ log_debug_lvmetad("lvmetad send disabled 0");
+
+ reply = daemon_send_simple(_lvmetad, "set_global_info",
+ "token = %s", "skip",
+ "global_disable = " FMTd64, (int64_t)0,
+ NULL);
+ if (reply.error)
+ log_error("Failed to send message to lvmetad %d", reply.error);
+
+ if (strcmp(daemon_reply_str(reply, "response", ""), "OK"))
+ log_error("Failed response from lvmetad.");
+
+ daemon_reply_destroy(reply);
+}
+
int lvmetad_is_disabled(struct cmd_context *cmd, const char **reason)
{
daemon_reply reply;
diff --git a/lib/cache/lvmetad.h b/lib/cache/lvmetad.h
index 6345d9551..9e0f51a6f 100644
--- a/lib/cache/lvmetad.h
+++ b/lib/cache/lvmetad.h
@@ -180,6 +180,7 @@ int lvmetad_vg_is_foreign(struct cmd_context *cmd, const char *vgname, const cha
int lvmetad_is_disabled(struct cmd_context *cmd, const char **reason);
void lvmetad_set_disabled(struct cmd_context *cmd, const char *reason);
+void lvmetad_clear_disabled(struct cmd_context *cmd);
# else /* LVMETAD_SUPPORT */
@@ -214,6 +215,7 @@ void lvmetad_set_disabled(struct cmd_context *cmd, const char *reason);
# define lvmetad_is_connected() (0)
# define lvmetad_is_disabled(cmd, reason) (0)
# define lvmetad_set_disabled(cmd, reason) do { } while (0)
+# define lvmetad_clear_disabled(cmd) do { } while (0)
# endif /* LVMETAD_SUPPORT */
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index d3d99f940..d21c4cf17 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1643,7 +1643,14 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
goto_out;
}
- if (lvmetad_is_connected() && lvmetad_is_disabled(cmd, &reason)) {
+ /*
+ * If lvmetad is disabled, don't use it and revert to scanning.
+ * The exception is pvscan which is explicitly repopulating
+ * lvmetad, and may be able to clear the disabled setting.
+ */
+ if (lvmetad_is_connected() &&
+ !(cmd->command->flags & DISABLE_BUILTIN_PVSCAN) &&
+ lvmetad_is_disabled(cmd, &reason)) {
log_warn("WARNING: Disabling use of lvmetad because %s.", reason);
lvmetad_set_active(cmd, 0);
}