master - lvmcache: process duplicate PVs directly
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d3d13e134af15611c3f12107aa1627b12110a974 Commit: d3d13e134af15611c3f12107aa1627b12110a974 Parent: 8b7a78c728be3b9af698dae9344d01752c4cf615 Author: David Teigland <[email protected]> AuthorDate: Thu Feb 11 12:37:36 2016 -0600 Committer: David Teigland <[email protected]> CommitterDate: Fri May 6 09:00:00 2016 -0500
lvmcache: process duplicate PVs directly
Previously, duplicate PVs were processed as a side effect of processing the "chosen" PV in lvmcache. The duplicate PV would be hacked into lvmcache temporarily in place of the chosen PV.
In the old way, we had to always process the "chosen" PV device, even if a duplicate of it was named on the command line. This meant we were processing a different device than was asked for. This could be worked around by naming multiple duplicate devs on the command line in which case they were swapped in and out of lvmcache for processing.
Now, the duplicate devs are processed directly in their own processing loop. This means we can remove the old hacks related to processing dups as a side effect of processing the chosen device. We can now simply process the device that was named on the command line.
When the same PVID exists on two or more devices, one device is preferred and used in the VG, and the others are duplicates and are not used in the VG. The preferred device exists in lvmcache as usual. The duplicates exist in a specical list of unused duplicate devices.
The duplicate devs have the "d" attribute and the "duplicate" reporting field displays "duplicate" for them.
'pvs' warns about duplicates, but the formal output only includes the single preferred PV.
'pvs -a' has the same warnings, and the duplicate devs are included in the output.
'pvs <path>' has the same warnings, and displays the named device, whether it is preferred or a duplicate.
--- lib/cache/lvmcache.c | 41 +++++----- lib/cache/lvmcache.h | 6 +- tools/commands.h | 4 +- tools/pvchange.c | 17 ++++ tools/toollib.c | 226 ++++++++++++++++++++++++++++---------------------- tools/tools.h | 2 + 6 files changed, 172 insertions(+), 124 deletions(-)
lib/cache/lvmcache.c +20 -21
@@ -444,6 +444,21 @@ int lvmcache_found_duplicate_pvs(void)return _found_duplicate_pvs; } +int lvmcache_get_unused_duplicate_devs (struct cmd_context *cmd,struct dm_list *head) +{ +struct device_list *devl, *devl2; + + dm_list_iterate_items(devl, &_unused_duplicate_devs) { +if (!(devl2 =dm_pool_alloc (cmd->mem,sizeof (*devl2)))) { +log_error ("device_list element allocation failed" ); +return 0 ; + } + devl2->dev = devl->dev; +dm_list_add (head, &devl2->list); + } +return 1 ; +} +static void _vginfo_attach_info (struct lvmcache_vginfo *vginfo,struct lvmcache_info *info) {
@@ -683,6 +698,11 @@ struct lvmcache_info *lvmcache_info_from_pvid(const char *pvid, int valid_only)return info; } +const struct format_type *lvmcache_fmt_from_info (struct lvmcache_info *info) +{ +return info->fmt; +} +const char *lvmcache_vgname_from_info (struct lvmcache_info *info) {if (info->vginfo)
@@ -1868,27 +1888,6 @@ int lvmcache_update_vg(struct volume_group *vg, unsigned precommitted) }/* -* Replace pv->dev with dev so that dev will appear for reporting. -*/ - -void lvmcache_replace_dev (struct cmd_context *cmd,struct physical_volume *pv, -struct device *dev) -{ -struct lvmcache_info *info; - char pvid_s[ID_LEN + 1] __attribute__((aligned(8))); - -strncpy (pvid_s, (char *) &pv->id,sizeof (pvid_s) -1 ); - pvid_s[sizeof (pvid_s) -1 ] ='\0' ; - -if (!(info =lvmcache_info_from_pvid (pvid_s,0 ))) -return ; - - info->dev = dev; - info->label->dev = dev; - pv->dev = dev; -} - -/* * We can see multiple different devices with the * same pvid, i.e. duplicates. *
lib/cache/lvmcache.h +3 -3
@@ -111,6 +111,7 @@ const char *lvmcache_pvid_from_devname(struct cmd_context *cmd, const char *devname);char *lvmcache_vgname_from_pvid (struct cmd_context *cmd,const char *pvid);const char *lvmcache_vgname_from_info (struct lvmcache_info *info); +const struct format_type *lvmcache_fmt_from_info (struct lvmcache_info *info);int lvmcache_vgs_locked (void );int lvmcache_vgname_is_locked (const char *vgname);
@@ -193,11 +194,10 @@ unsigned lvmcache_mda_count(struct lvmcache_info *info);int lvmcache_vgid_is_cached (const char *vgid);uint64_t lvmcache_smallest_mda_size (struct lvmcache_info *info); -void lvmcache_replace_dev (struct cmd_context *cmd,struct physical_volume *pv, -struct device *dev); -int lvmcache_found_duplicate_pvs (void ); +int lvmcache_get_unused_duplicate_devs (struct cmd_context *cmd,struct dm_list *head); +int vg_has_duplicate_pvs (struct volume_group *vg);int lvmcache_contains_lock_type_sanlock (struct cmd_context *cmd);
tools/commands.h +2 -2
@@ -824,7 +824,7 @@ xx(pvdata,xx (pvdisplay,"Display various attributes of physical volume(s)" , -CACHE_VGMETADATA |PERMITTED_READ_ONLY |ENABLE_ALL_DEVS |LOCKD_VG_SH , +CACHE_VGMETADATA |PERMITTED_READ_ONLY |ENABLE_ALL_DEVS |ENABLE_DUPLICATE_DEVS |LOCKD_VG_SH ,"pvdisplay\n" "\t[-c|--colon]\n" "\t[--commandprofile ProfileName]\n"
@@ -933,7 +933,7 @@ xx(pvremove,xx (pvs,"Display information about physical volumes" , -CACHE_VGMETADATA |PERMITTED_READ_ONLY |ALL_VGS_IS_DEFAULT |ENABLE_ALL_DEVS |LOCKD_VG_SH , +CACHE_VGMETADATA |PERMITTED_READ_ONLY |ALL_VGS_IS_DEFAULT |ENABLE_ALL_DEVS |ENABLE_DUPLICATE_DEVS |LOCKD_VG_SH ,"pvs\n" "\t[-a|--all]\n" "\t[--aligned]\n"
tools/pvchange.c +17 -0
@@ -40,6 +40,23 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg, goto bad; } +/* +* The primary location of this check is in vg_write(), but it needs +* to be copied here to prevent the pv_write() which is called before +* the vg_write(). +*/ +if (vg &&lvmcache_found_duplicate_pvs () &&vg_has_duplicate_pvs (vg)) { +if (!find_config_tree_bool (vg->cmd, devices_allow_changes_with_duplicate_pvs_CFG,NULL )) { +log_error ("Cannot update volume group %s with duplicate PV devices." , + vg->name); + goto bad; + } +if (arg_count (cmd, uuid_ARG)) { +log_error ("Resolve duplicate PV UUIDs with vgimportclone (or filters)." ); + goto bad; + } + } +/* If in a VG, must change using volume group. */ if (!is_orphan (pv)) {if (tagargs && !(vg->fid->fmt->features &FMT_TAGS )) {
tools/toollib.c +128 -98
262 lines not on this page · raw message
tools/tools.h +2 -0
@@ -112,6 +112,8 @@ struct arg_value_group_list {#define MUST_USE_ALL_ARGS 0x00000100/* Command wants to control the device scan for lvmetad itself. */ #define NO_LVMETAD_AUTOSCAN 0x00000200 +/* Command should process unused duplicate devices. */ +#define ENABLE_DUPLICATE_DEVS 0x00000400/* a register of the lvm commands */ struct command {