mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
scan: use PV device name hint for choosing duplicate PV
Prefer a device if its name matches the PV device name hint.
This commit is contained in:
parent
4910a31f6d
commit
f836fe3836
36
lib/cache/lvmcache.c
vendored
36
lib/cache/lvmcache.c
vendored
@ -404,6 +404,23 @@ static uint64_t _get_pvsummary_size(char *pvid)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *_get_pvsummary_device_hint(char *pvid)
|
||||
{
|
||||
char pvid_s[ID_LEN + 1] __attribute__((aligned(8)));
|
||||
struct lvmcache_vginfo *vginfo;
|
||||
struct pv_list *pvl;
|
||||
|
||||
dm_list_iterate_items(vginfo, &_vginfos) {
|
||||
dm_list_iterate_items(pvl, &vginfo->pvsummaries) {
|
||||
(void) dm_strncpy(pvid_s, (char *) &pvl->pv->id, sizeof(pvid_s));
|
||||
if (!strcmp(pvid_s, pvid))
|
||||
return pvl->pv->device_hint;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if any PVs in vg->pvs have the same PVID as any
|
||||
* entries in _unused_duplicates.
|
||||
@ -502,6 +519,7 @@ static void _choose_duplicates(struct cmd_context *cmd,
|
||||
{
|
||||
char *pvid;
|
||||
const char *reason;
|
||||
const char *device_hint;
|
||||
struct dm_list altdevs;
|
||||
struct dm_list new_unused;
|
||||
struct dev_types *dt = cmd->dev_types;
|
||||
@ -515,6 +533,7 @@ static void _choose_duplicates(struct cmd_context *cmd,
|
||||
int has_fs1, has_fs2;
|
||||
int has_lv1, has_lv2;
|
||||
int same_size1, same_size2;
|
||||
int same_name1 = 0, same_name2 = 0;
|
||||
int prev_unchosen1, prev_unchosen2;
|
||||
int change;
|
||||
|
||||
@ -640,6 +659,11 @@ next:
|
||||
same_size1 = (dev1_size == pv_size);
|
||||
same_size2 = (dev2_size == pv_size);
|
||||
|
||||
if ((device_hint = _get_pvsummary_device_hint(devl->dev->pvid))) {
|
||||
same_name1 = !strcmp(device_hint, dev_name(dev1));
|
||||
same_name2 = !strcmp(device_hint, dev_name(dev2));
|
||||
}
|
||||
|
||||
has_lv1 = (dev1->flags & DEV_USED_FOR_LV) ? 1 : 0;
|
||||
has_lv2 = (dev2->flags & DEV_USED_FOR_LV) ? 1 : 0;
|
||||
|
||||
@ -652,10 +676,11 @@ next:
|
||||
has_fs1 = dm_device_has_mounted_fs(dev1_major, dev1_minor);
|
||||
has_fs2 = dm_device_has_mounted_fs(dev2_major, dev2_minor);
|
||||
|
||||
log_debug_cache("PV %s compare duplicates: %s %u:%u. %s %u:%u.",
|
||||
log_debug_cache("PV %s compare duplicates: %s %u:%u. %s %u:%u. device_hint %s.",
|
||||
devl->dev->pvid,
|
||||
dev_name(dev1), dev1_major, dev1_minor,
|
||||
dev_name(dev2), dev2_major, dev2_minor);
|
||||
dev_name(dev2), dev2_major, dev2_minor,
|
||||
device_hint ?: "none");
|
||||
|
||||
log_debug_cache("PV %s: size %llu. %s is %llu. %s is %llu.",
|
||||
devl->dev->pvid,
|
||||
@ -711,6 +736,13 @@ next:
|
||||
/* change to 2 */
|
||||
change = 1;
|
||||
reason = "device size is correct";
|
||||
} else if (same_name1 && !same_name2) {
|
||||
/* keep 1 */
|
||||
reason = "device name matches previous";
|
||||
} else if (same_name2 && !same_name1) {
|
||||
/* change to 2 */
|
||||
change = 1;
|
||||
reason = "device name matches previous";
|
||||
} else if (has_fs1 && !has_fs2) {
|
||||
/* keep 1 */
|
||||
reason = "device has fs mounted";
|
||||
|
Loading…
Reference in New Issue
Block a user