diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index 48c0bf20d..5a53d22b1 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -538,7 +538,7 @@ static int _emit_target(struct dm_task *dmt, struct stripe_segment *seg) } for (s = 0; s < stripes; s++, w += tw) { - if (!seg->area[s].pv) + if (!seg->area[s].pv || !seg->area[s].pv->dev) tw = lvm_snprintf(params + w, sizeof(params) - w, "%s 0%s", filler, s == (stripes - 1) ? "" : " "); diff --git a/lib/device/device.h b/lib/device/device.h index 6d165e963..66846bc3e 100644 --- a/lib/device/device.h +++ b/lib/device/device.h @@ -47,7 +47,8 @@ int dev_zero(struct device *dev, uint64_t offset, int64_t len); static inline const char *dev_name(struct device *dev) { - return list_item(dev->aliases.n, struct str_list)->str; + return (dev) ? list_item(dev->aliases.n, struct str_list)->str : + "unknown device"; } /* Return a valid device name from the alias list; NULL otherwise */ diff --git a/lib/format1/format1.c b/lib/format1/format1.c index 89365b380..b09daa029 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -238,12 +238,6 @@ static int _vg_write(struct format_instance *fid, struct volume_group *vg, return 0; } - if (vg->status & PARTIAL_VG) { - log_error("Cannot change metadata for partial volume group %s", - vg->name); - return 0; - } - list_init(&pvds); r = (_flatten_vg(fid, mem, vg, &pvds, fid->fmt->cmd->dev_dir, diff --git a/lib/format_text/import.c b/lib/format_text/import.c index a8b28fa7a..c596118c0 100644 --- a/lib/format_text/import.c +++ b/lib/format_text/import.c @@ -91,13 +91,15 @@ static int _read_pv(struct format_instance *fid, struct pool *mem, if (!(pv->dev = uuid_map_lookup(um, &pv->id))) { char buffer[64]; - if (!id_write_format(&pv->id, buffer, sizeof(buffer))) { + if (!id_write_format(&pv->id, buffer, sizeof(buffer))) log_err("Couldn't find device."); - return 0; - } + else + log_err("Couldn't find device with uuid '%s'.", buffer); - log_err("Couldn't find device with uuid '%s'.", buffer); - return 0; + if (partial_mode()) + vg->status |= PARTIAL_VG; + else + return 0; } if (!(pv->vg_name = pool_strdup(mem, vg->name))) { @@ -610,6 +612,11 @@ static struct volume_group *_read_vg(struct format_instance *fid, hash_destroy(pv_hash); + if (vg->status & PARTIAL_VG) { + vg->status &= ~LVM_WRITE; + vg->status |= LVM_READ; + } + /* * Finished. */ diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index aa5616fcd..00a3e7dee 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -362,6 +362,12 @@ int vg_write(struct volume_group *vg) struct list *mdah; void *mdl; + if (vg->status & PARTIAL_VG) { + log_error("Cannot change metadata for partial volume group %s", + vg->name); + return 0; + } + vg->seqno++; /* Write to each copy of the metadata area */ diff --git a/tools/commands.h b/tools/commands.h index 5a940edbd..de61b96b5 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -226,10 +226,11 @@ xx(lvscan, "\t[-d|--debug] " "\n" "\t[-D|--disk]" "\n" "\t[-h|--help] " "\n" + "\t[-P|--partial] " "\n" "\t[-v|--verbose] " "\n" "\t[--version]\n", - blockdevice_ARG, disk_ARG) + blockdevice_ARG, disk_ARG, partial_ARG) xx(pvchange, "Change attributes of physical volume(s)", @@ -327,12 +328,13 @@ xx(pvscan, "\t[-d|--debug] " "\n" "\t{-e|--exported | -n/--novolumegroup} " "\n" "\t[-h|--help]" "\n" + "\t[-P|--partial] " "\n" "\t[-s|--short] " "\n" "\t[-u|--uuid] " "\n" "\t[-v|--verbose] " "\n" "\t[--version]\n", - exported_ARG, novolumegroup_ARG, short_ARG, uuid_ARG) + exported_ARG, novolumegroup_ARG, partial_ARG, short_ARG, uuid_ARG) xx(vgcfgbackup, "Backup volume group configuration(s)", @@ -520,7 +522,9 @@ xx(vgscan, "vgscan " "\t[-d/--debug]\n" "\t[-h/-?/--help]\n" - "\t[-v/--verbose]\n" ) + "\t[-P/--partial] " "\n" + "\t[-v/--verbose]\n" , + partial_ARG) xx(vgsplit, "Move physical volumes into a new volume group",