diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c index 6c86a40a1..985ff43a5 100644 --- a/lib/cache/lvmcache.c +++ b/lib/cache/lvmcache.c @@ -2402,3 +2402,17 @@ void lvmcache_get_max_name_lengths(struct cmd_context *cmd, } } +int lvmcache_vg_is_foreign(struct cmd_context *cmd, const char *vgname, const char *vgid) +{ + struct lvmcache_vginfo *vginfo; + int ret = 0; + + if (lvmetad_active()) + return lvmetad_vg_is_foreign(cmd, vgname, vgid); + + if ((vginfo = lvmcache_vginfo_from_vgid(vgid))) + ret = !is_system_id_allowed(cmd, vginfo->system_id); + + return ret; +} + diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h index ed1b916f3..b968a12e9 100644 --- a/lib/cache/lvmcache.h +++ b/lib/cache/lvmcache.h @@ -194,5 +194,6 @@ int lvmcache_contains_lock_type_sanlock(struct cmd_context *cmd); void lvmcache_get_max_name_lengths(struct cmd_context *cmd, unsigned *pv_max_name_len, unsigned *vg_max_name_len); +int lvmcache_vg_is_foreign(struct cmd_context *cmd, const char *vgname, const char *vgid); #endif diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c index 78844c4c6..6d9a2f7b7 100644 --- a/lib/cache/lvmetad.c +++ b/lib/cache/lvmetad.c @@ -1808,3 +1808,29 @@ void lvmetad_validate_global_cache(struct cmd_context *cmd, int force) _update_changed_pvs_in_udev(cmd, &pvc_before, &pvc_after); } } + +int lvmetad_vg_is_foreign(struct cmd_context *cmd, const char *vgname, const char *vgid) +{ + daemon_reply reply; + struct dm_config_node *top; + const char *system_id = NULL; + char uuid[64]; + int ret; + + if (!id_write_format((const struct id*)vgid, uuid, sizeof(uuid))) + return_0; + + reply = _lvmetad_send("vg_lookup", + "uuid = %s", uuid, + "name = %s", vgname, + NULL); + + if ((top = dm_config_find_node(reply.cft->root, "metadata"))) + system_id = dm_config_find_str(top, "metadata/system_id", NULL); + + ret = !is_system_id_allowed(cmd, system_id); + + daemon_reply_destroy(reply); + return ret; +} + diff --git a/lib/cache/lvmetad.h b/lib/cache/lvmetad.h index af0d562fe..2c0b13464 100644 --- a/lib/cache/lvmetad.h +++ b/lib/cache/lvmetad.h @@ -169,6 +169,8 @@ int lvmetad_pvscan_foreign_vgs(struct cmd_context *cmd, activation_handler handl int lvmetad_vg_clear_outdated_pvs(struct volume_group *vg); void lvmetad_validate_global_cache(struct cmd_context *cmd, int force); +int lvmetad_vg_is_foreign(struct cmd_context *cmd, const char *vgname, const char *vgid); + # else /* LVMETAD_SUPPORT */ # define lvmetad_init(cmd) do { } while (0) @@ -197,6 +199,7 @@ void lvmetad_validate_global_cache(struct cmd_context *cmd, int force); # define lvmetad_pvscan_foreign_vgs(cmd, handler) (0) # define lvmetad_vg_clear_outdated_pvs(vg) (1) # define lvmetad_validate_global_cache(cmd, force) do { } while (0) +# define lvmetad_vg_is_foreign(cmd, vgname, vgid) (0) # endif /* LVMETAD_SUPPORT */