mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-22 17:35:59 +03:00
vgimportclone: fix when duplicates are both in the devices file
Fix case where duplicate PVs are created (e.g. with dd) from devices that are both already in the devices file.
This commit is contained in:
parent
8b72313936
commit
72af1cb085
@ -43,9 +43,23 @@ vgimport $vg1
|
|||||||
fail vgimport $vg1
|
fail vgimport $vg1
|
||||||
vgchange -ay $vg1
|
vgchange -ay $vg1
|
||||||
|
|
||||||
|
# Since the devices file is using devnames as ids,
|
||||||
|
# it will not automatically know that dev2 is a
|
||||||
|
# duplicate after the dd, so we need to remove dev2
|
||||||
|
# from df, then add it again after the dd.
|
||||||
|
if lvmdevices; then
|
||||||
|
lvmdevices --deldev "$dev2"
|
||||||
|
fi
|
||||||
|
|
||||||
# Clone the LUN
|
# Clone the LUN
|
||||||
dd if="$dev1" of="$dev2" bs=256K count=1
|
dd if="$dev1" of="$dev2" bs=256K count=1
|
||||||
|
|
||||||
|
# Requires -y to confirm prompt about adding
|
||||||
|
# a duplicate pvid.
|
||||||
|
if lvmdevices; then
|
||||||
|
lvmdevices -y --adddev "$dev2"
|
||||||
|
fi
|
||||||
|
|
||||||
# Verify pvs works on each device to give us vgname
|
# Verify pvs works on each device to give us vgname
|
||||||
aux hide_dev "$dev2"
|
aux hide_dev "$dev2"
|
||||||
check pv_field "$dev1" vg_name $vg1
|
check pv_field "$dev1" vg_name $vg1
|
||||||
@ -55,9 +69,16 @@ aux hide_dev "$dev1"
|
|||||||
check pv_field "$dev2" vg_name $vg1
|
check pv_field "$dev2" vg_name $vg1
|
||||||
aux unhide_dev "$dev1"
|
aux unhide_dev "$dev1"
|
||||||
|
|
||||||
|
lvmdevices || true
|
||||||
|
pvs -a -o+uuid
|
||||||
|
|
||||||
# Import the cloned PV to a new VG
|
# Import the cloned PV to a new VG
|
||||||
vgimportclone --basevgname $vg2 "$dev2"
|
vgimportclone --basevgname $vg2 "$dev2"
|
||||||
|
|
||||||
|
lvmdevices || true
|
||||||
|
pvs -a -o+uuid
|
||||||
|
vgs
|
||||||
|
|
||||||
# Verify we can activate / deactivate the LV from both VGs
|
# Verify we can activate / deactivate the LV from both VGs
|
||||||
lvchange -ay $vg1/$lv1 $vg2/$lv1
|
lvchange -ay $vg1/$lv1 $vg2/$lv1
|
||||||
vgchange -an $vg1 $vg2
|
vgchange -an $vg1 $vg2
|
||||||
|
@ -160,7 +160,7 @@ static int _update_vg(struct cmd_context *cmd, struct volume_group *vg,
|
|||||||
* will be included in the metadata. The device file is written
|
* will be included in the metadata. The device file is written
|
||||||
* (with these additions) at the end of the command.
|
* (with these additions) at the end of the command.
|
||||||
*/
|
*/
|
||||||
if (vp->import_devices) {
|
if (vp->import_devices || cmd->enable_devices_file) {
|
||||||
dm_list_iterate_items(devl, &vp->new_devs) {
|
dm_list_iterate_items(devl, &vp->new_devs) {
|
||||||
if (!device_id_add(cmd, devl->dev, devl->dev->pvid, NULL, NULL)) {
|
if (!device_id_add(cmd, devl->dev, devl->dev->pvid, NULL, NULL)) {
|
||||||
log_error("Failed to add device id for %s.", dev_name(devl->dev));
|
log_error("Failed to add device id for %s.", dev_name(devl->dev));
|
||||||
@ -506,7 +506,7 @@ retry_name:
|
|||||||
* Should we be using device_ids_validate to check/fix other
|
* Should we be using device_ids_validate to check/fix other
|
||||||
* devs in the devices file?
|
* devs in the devices file?
|
||||||
*/
|
*/
|
||||||
if (vp.import_devices) {
|
if (vp.import_devices || cmd->enable_devices_file) {
|
||||||
if (!device_ids_write(cmd)) {
|
if (!device_ids_write(cmd)) {
|
||||||
log_error("Failed to write devices file.");
|
log_error("Failed to write devices file.");
|
||||||
goto out;
|
goto out;
|
||||||
|
Loading…
Reference in New Issue
Block a user