diff options
author | David Teigland <teigland@redhat.com> | 2015-11-30 11:46:55 -0600 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2015-11-30 11:46:55 -0600 |
commit | 05ac8367980afb0b660fc312b228337e256a38e8 (patch) | |
tree | 4a4065d39375e5a71d2ac79d8e68af8f8970add9 | |
parent | d3ca18e489d48cc7c7b2a877b95b5a9a324e8e30 (diff) | |
download | lvm2-05ac8367980afb0b660fc312b228337e256a38e8.tar.gz |
system_id: refactor check for allowed system_id
Refactor the code that checks for an allowable system_id
so that it can be used from other places.
-rw-r--r-- | lib/metadata/metadata-exported.h | 2 | ||||
-rw-r--r-- | lib/metadata/metadata.c | 49 |
2 files changed, 34 insertions, 17 deletions
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index f00968763..8242db17d 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -1238,4 +1238,6 @@ int validate_vg_rename_params(struct cmd_context *cmd, int is_lockd_type(const char *lock_type); +int is_system_id_allowed(struct cmd_context *cmd, const char *system_id); + #endif diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 7ee928da4..bf030d37f 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -4854,39 +4854,53 @@ static int _access_vg_lock_type(struct cmd_context *cmd, struct volume_group *vg return 1; } -static int _access_vg_systemid(struct cmd_context *cmd, struct volume_group *vg) +int is_system_id_allowed(struct cmd_context *cmd, const char *system_id) { /* - * LVM1 VGs must not be accessed if a new-style LVM2 system ID is set. + * A VG without a system_id can be accessed by anyone. */ - if (cmd->system_id && systemid_on_pvs(vg)) { - log_error("Cannot access VG %s with LVM1 system ID %s when host system ID is set.", - vg->name, vg->lvm1_system_id); - return 0; - } + if (!system_id || !system_id[0]) + return 1; /* - * A VG without a system_id can be accessed by anyone. + * Allowed if the host and VG system_id's match. */ - if (!vg->system_id || !vg->system_id[0]) + if (cmd->system_id && !strcmp(cmd->system_id, system_id)) return 1; /* - * A few commands allow read-only access to foreign VGs. + * Allowed if a host's extra system_id matches. */ - if (cmd->include_foreign_vgs) + if (cmd->system_id && _allow_extra_system_id(cmd, system_id)) return 1; /* - * A host can access a VG with a matching system_id. + * Not allowed if the host does not have a system_id + * and the VG does, or if the host and VG's system_id's + * do not match. */ - if (cmd->system_id && !strcmp(vg->system_id, cmd->system_id)) - return 1; + return 0; +} + +static int _access_vg_systemid(struct cmd_context *cmd, struct volume_group *vg) +{ /* - * A host can access a VG if the VG's system_id is in extra_system_ids list. + * LVM1 VGs must not be accessed if a new-style LVM2 system ID is set. */ - if (cmd->system_id && _allow_extra_system_id(cmd, vg->system_id)) + if (cmd->system_id && systemid_on_pvs(vg)) { + log_error("Cannot access VG %s with LVM1 system ID %s when host system ID is set.", + vg->name, vg->lvm1_system_id); + return 0; + } + + /* + * A few commands allow read-only access to foreign VGs. + */ + if (cmd->include_foreign_vgs) + return 1; + + if (is_system_id_allowed(cmd, vg->system_id)) return 1; /* @@ -4901,7 +4915,8 @@ static int _access_vg_systemid(struct cmd_context *cmd, struct volume_group *vg) } /* - * A host without a system_id cannot access a VG with a system_id. + * Print an error when reading a VG that has a system_id + * and the host system_id is unknown. */ if (!cmd->system_id || cmd->unknown_system_id) { log_error("Cannot access VG %s with system ID %s with unknown local system ID.", |