From 7ae5a778d56e9f8269ba55701745cf24ec34d389 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Wed, 30 Jan 2002 15:33:12 +0000 Subject: [PATCH] Basic support for (read-only) partial activation if any PVs are missing from a VG. (Linear targets use the device-mapper 'error' target which returns ioerror; striped targets use '/dev/ioerror' for now - which must already exist e.g. as a sufficiently large block device version of /dev/zero). --- VERSION | 2 +- lib/activate/activate.c | 64 ++++++++++++++++++++---------------- lib/display/display.c | 8 ++--- lib/format1/import-extents.c | 4 +-- lib/format_text/export.c | 4 ++- tools/commands.h | 8 +++-- 6 files changed, 51 insertions(+), 39 deletions(-) diff --git a/VERSION b/VERSION index f63e4e530..d5491bfec 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.95.02-cvs (2002-01-29) +0.95.03-cvs (2002-01-30) diff --git a/lib/activate/activate.c b/lib/activate/activate.c index 87fba63c7..9a852463d 100644 --- a/lib/activate/activate.c +++ b/lib/activate/activate.c @@ -191,11 +191,23 @@ static int _emit_target(struct dm_task *dmt, struct stripe_segment *seg) char params[1024]; uint64_t esize = seg->lv->vg->extent_size; uint32_t s, stripes = seg->stripes; - int w = 0, tw = 0; + int w = 0, tw = 0, error = 0; const char *no_space = "Insufficient space to write target parameters."; + char *filler = "/dev/ioerror"; + char *target; + + if (stripes == 1) { + if (!seg->area[0].pv) { + target = "error"; + error = 1; + } + else + target = "linear"; + } if (stripes > 1) { + target = "striped"; tw = lvm_snprintf(params, sizeof(params), "%u %u ", stripes, seg->stripe_size); @@ -207,39 +219,35 @@ static int _emit_target(struct dm_task *dmt, struct stripe_segment *seg) w = tw; } - - for (s = 0; s < stripes; s++, w += tw) { -/****** - log_debug("stripes: %d", stripes); - log_debug("dev_name(seg->area[s].pv->dev): %s", - dev_name(seg->area[s].pv->dev)); - log_debug("esize: %" PRIu64, esize); - log_debug("seg->area[s].pe: %" PRIu64, seg->area[s].pe); - log_debug("seg->area[s].pv->pe_start: %" PRIu64, - seg->area[s].pv->pe_start); -*******/ - - tw = lvm_snprintf(params + w, sizeof(params) - w, - "%s %" PRIu64 "%s", - dev_name(seg->area[s].pv->dev), - (seg->area[s].pv->pe_start + - (esize * seg->area[s].pe)), - s == (stripes - 1) ? "" : " "); - - if (tw < 0) { - log_err(no_space); - return 0; + if (!error) { + for (s = 0; s < stripes; s++, w += tw) { + if (!seg->area[s].pv) + tw = lvm_snprintf( + params + w, sizeof(params) - w, + "%s 0%s", filler, + s == (stripes - 1) ? "" : " "); + else + tw = lvm_snprintf( + params + w, sizeof(params) - w, + "%s %" PRIu64 "%s", + dev_name(seg->area[s].pv->dev), + (seg->area[s].pv->pe_start + + (esize * seg->area[s].pe)), + s == (stripes - 1) ? "" : " "); + + if (tw < 0) { + log_err(no_space); + return 0; + } } } - log_debug("Adding target: %" PRIu64 " %" PRIu64 " %s %s", + log_very_verbose("Adding target: %" PRIu64 " %" PRIu64 " %s %s", esize * seg->le, esize * seg->len, - stripes == 1 ? "linear" : "striped", - params); + target, params); if (!dm_task_add_target(dmt, esize * seg->le, esize * seg->len, - stripes == 1 ? "linear" : "striped", - params)) { + target, params)) { stack; return 0; } diff --git a/lib/display/display.c b/lib/display/display.c index bde656a28..8fed0140b 100644 --- a/lib/display/display.c +++ b/lib/display/display.c @@ -377,11 +377,11 @@ void _display_stripe(struct stripe_segment *seg, int s, const char *pre) uint32_t len = seg->len / seg->stripes; log_print("%sphysical volume\t%s", pre, - dev_name(seg->area[s].pv->dev)); + seg->area[s].pv ? dev_name(seg->area[s].pv->dev) : "Missing"); - log_print("%sphysical extents\t%d to %d", - pre, - seg->area[s].pe, seg->area[s].pe + len - 1); + if (seg->area[s].pv) + log_print("%sphysical extents\t%d to %d", pre, + seg->area[s].pe, seg->area[s].pe + len - 1); } int lvdisplay_segments(struct logical_volume *lv) diff --git a/lib/format1/import-extents.c b/lib/format1/import-extents.c index e520c5b3f..9e56e95a2 100644 --- a/lib/format1/import-extents.c +++ b/lib/format1/import-extents.c @@ -164,6 +164,7 @@ static int _fill_maps(struct hash_table *maps, struct volume_group *vg, static int _check_single_map(struct lv_map *lvm) { uint32_t i; + for (i = 0; i < lvm->lv->le_count; i++) { if (!lvm->map[i].pv) { log_err("Logical volume (%s) contains an incomplete " @@ -349,8 +350,7 @@ int import_extents(struct pool *mem, struct volume_group *vg, struct list *pvds) goto out; } - /* FIXME Support partial activation if (vg->status & PARTIAL_VG) */ - if (!_check_maps_are_complete(maps)) { + if (!_check_maps_are_complete(maps) && !(vg->status & PARTIAL_VG)) { stack; goto out; } diff --git a/lib/format_text/export.c b/lib/format_text/export.c index 9eb570888..45bff0666 100644 --- a/lib/format_text/export.c +++ b/lib/format_text/export.c @@ -217,7 +217,9 @@ static int _print_vg(struct formatter *f, struct volume_group *vg) static inline const char * _get_pv_name(struct formatter *f, struct physical_volume *pv) { - return (const char *) hash_lookup(f->pv_names, dev_name(pv->dev)); + return (pv) ? (const char *) + hash_lookup(f->pv_names, dev_name(pv->dev)) : + "Missing"; } static int _print_pvs(struct formatter *f, struct volume_group *vg) diff --git a/tools/commands.h b/tools/commands.h index cc0903c75..4a1bb84d1 100644 --- a/tools/commands.h +++ b/tools/commands.h @@ -108,10 +108,11 @@ xx(lvdisplay, "\t[-D/--disk]\n" "\t[-h/-?/--help]\n" "\t[-m/--maps]\n" + "\t[-P/--partial] " "\n" "\t[-v/--verbose]\n" "\tLogicalVolume[Path] [LogicalVolume[Path]...]\n", - colon_ARG, disk_ARG, maps_ARG) + colon_ARG, disk_ARG, maps_ARG, partial_ARG) xx(lvextend, "Add space to a logical volume", @@ -405,11 +406,12 @@ xx(vgdisplay, "\t[-c|--colon | -s|--short | -v|--verbose]" "\n" "\t[-d|--debug] " "\n" "\t[-h|--help] " "\n" - "\t[--version]" "\n" + "\t[-P|--partial] " "\n" "\t[-A|--activevolumegroups | [-D|--disk]" "\n" + "\t[--version]" "\n" "\t[VolumeGroupName...] ]\n", - activevolumegroups_ARG, colon_ARG, disk_ARG, short_ARG) + activevolumegroups_ARG, colon_ARG, disk_ARG, short_ARG, partial_ARG) xx(vgexport, "Unregister volume group(s) from the system", -- 2.43.5