diff options
author | David Teigland <teigland@redhat.com> | 2014-11-07 12:51:42 -0600 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2015-03-03 15:40:58 -0600 |
commit | 7f9d9db20895bce498fabd8e4beaf65d066dc77b (patch) | |
tree | 4ea3944d74772d2175208c81ef442a5a3e366ef0 | |
parent | 8620702bdb0cba07debdbf1e4889403d126f25ca (diff) | |
download | lvm2-7f9d9db20895bce498fabd8e4beaf65d066dc77b.tar.gz |
lvmcache: add function to validate and update global cache
Will be used in later patches to check and update the
local lvmetad global cache when needed.
-rw-r--r-- | lib/cache/lvmetad.c | 82 | ||||
-rw-r--r-- | lib/cache/lvmetad.h | 3 |
2 files changed, 85 insertions, 0 deletions
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c index aad442351..126c51f4a 100644 --- a/lib/cache/lvmetad.c +++ b/lib/cache/lvmetad.c @@ -1039,3 +1039,85 @@ int lvmetad_pvscan_foreign_vgs(struct cmd_context *cmd, activation_handler handl { return lvmetad_pvscan_all_devs(cmd, handler); } + +/* + * Before this command was run, some external entity may have + * invalidated lvmetad's cache of global information, e.g. lvmlockd. + * + * The global information includes things like a new VG, a + * VG that was removed, the assignment of a PV to a VG; + * any change that is not isolated within a single VG. + * + * The external entity, like a lock manager, would invalidate + * the lvmetad global cache if it detected that the global + * information had been changed on disk by something other + * than a local lvm command, e.g. an lvm command on another + * host with access to the same devices. (How it detects + * the change is specific to lock manager or other entity.) + * + * The effect is that metadata on disk is newer than the metadata + * in the local lvmetad daemon, and the local lvmetad's cache + * should be updated from disk before this command uses it. + * + * So, using this function, a command checks if lvmetad's global + * cache is valid. If so, it does nothing. If not, it rescans + * devices to update the lvmetad cache, then it notifies lvmetad + * that it's cache is valid again (consistent with what's on disk.) + * This command can then go ahead and use the newly refreshed metadata. + * + * 1. Check if the lvmetad global cache is invalid. + * 2. If so, reread metadata from all devices and update the lvmetad cache. + * 3. Tell lvmetad that the global cache is now valid. + */ + +void lvmetad_validate_global_cache(struct cmd_context *cmd, int force) +{ + daemon_reply reply; + int global_invalid; + + if (force) + goto do_scan; + + reply = daemon_send_simple(_lvmetad, "get_global_info", + "token = %s", "skip", + NULL); + + if (reply.error) { + log_error("lvmetad_validate_global_cache get_global_info error %d", reply.error); + goto do_scan; + } + + if (strcmp(daemon_reply_str(reply, "response", ""), "OK")) { + log_error("lvmetad_validate_global_cache get_global_info not ok"); + goto do_scan; + } + + global_invalid = daemon_reply_int(reply, "global_invalid", -1); + + daemon_reply_destroy(reply); + + if (!global_invalid) { + /* cache is valid */ + return; + } + + do_scan: + lvmetad_pvscan_all_devs(cmd, NULL); + + /* Clear the global_invalid flag in lvmetad. */ + + reply = daemon_send_simple(_lvmetad, "set_global_info", + "token = %s", "skip", + "global_invalid = %d", 0, + NULL); + + if (reply.error) + log_error("lvmetad_validate_global_cache set_global_info error %d", reply.error); + + if (strcmp(daemon_reply_str(reply, "response", ""), "OK")) + log_error("lvmetad_validate_global_cache set_global_info not ok"); + + daemon_reply_destroy(reply); + + lvmcache_seed_infos_from_lvmetad(cmd); +} diff --git a/lib/cache/lvmetad.h b/lib/cache/lvmetad.h index 4d6f107eb..1e9b42f08 100644 --- a/lib/cache/lvmetad.h +++ b/lib/cache/lvmetad.h @@ -158,6 +158,8 @@ int lvmetad_pvscan_single(struct cmd_context *cmd, struct device *dev, int lvmetad_pvscan_all_devs(struct cmd_context *cmd, activation_handler handler); int lvmetad_pvscan_foreign_vgs(struct cmd_context *cmd, activation_handler handler); +void lvmetad_validate_global_cache(struct cmd_context *cmd, int force); + # else /* LVMETAD_SUPPORT */ # define lvmetad_init(cmd) do { } while (0) @@ -183,6 +185,7 @@ int lvmetad_pvscan_foreign_vgs(struct cmd_context *cmd, activation_handler handl # define lvmetad_pvscan_single(cmd, dev, handler) (0) # define lvmetad_pvscan_all_devs(cmd, handler) (0) # define lvmetad_pvscan_foreign_vgs(cmd, handler) (0) +# define lvmetad_validate_global_cache(cmd, handler) do { } while (0) # endif /* LVMETAD_SUPPORT */ |