diff options
author | David Teigland <teigland@redhat.com> | 2014-11-07 12:51:42 -0600 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2014-12-08 11:58:40 -0600 |
commit | 5371da37976fa25714dd802e15f9e5346db47482 (patch) | |
tree | 4e64f7861115d8252cb489f3b1c13dc7e00f5177 | |
parent | e0c61ed6360d655fc10c4524f2f449c90623863c (diff) | |
download | lvm2-5371da37976fa25714dd802e15f9e5346db47482.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 5612c1bd2..ccdf63a35 100644 --- a/lib/cache/lvmetad.c +++ b/lib/cache/lvmetad.c @@ -1030,3 +1030,85 @@ int lvmetad_pvscan_all_devs(struct cmd_context *cmd, activation_handler handler) return r; } +/* + * 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 2cd738ed9..81d0dc825 100644 --- a/lib/cache/lvmetad.h +++ b/lib/cache/lvmetad.h @@ -157,6 +157,8 @@ int lvmetad_pvscan_single(struct cmd_context *cmd, struct device *dev, int lvmetad_pvscan_all_devs(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) @@ -181,6 +183,7 @@ int lvmetad_pvscan_all_devs(struct cmd_context *cmd, activation_handler handler) # define lvmetad_vg_lookup(cmd, vgname, vgid) (NULL) # define lvmetad_pvscan_single(cmd, dev, handler) (0) # define lvmetad_pvscan_all_devs(cmd, handler) (0) +# define lvmetad_validate_global_cache(cmd, handler) do { } while (0) # endif /* LVMETAD_SUPPORT */ |