From fd4ff5d201226dba471d3d24f9017d5aa313a977 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Mon, 5 Nov 2007 01:47:49 +0000 Subject: [PATCH] Show 'not usable' space when PV is too large for device in pvdisplay. Ignore and fix up any excessive device size found in metadata. --- WHATS_NEW | 2 ++ lib/display/display.c | 26 ++++++++++++++------------ lib/format1/import-export.c | 4 ++-- lib/format_text/import_vsn1.c | 4 ++-- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index b87e7d6ab..d74443c41 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,6 +1,8 @@ Version 2.02.29 - ================================== Add LVM2 version to 'Generated by' comment in metadata. + Show 'not usable' space when PV is too large for device in pvdisplay. + Ignore and fix up any excessive device size found in metadata. Fix error message when fixing up PV size in lvm2 metadata (2.02.11). Fix orphan-related locking in pvdisplay and pvs. Fix missing VG unlocks in some pvchange error paths. diff --git a/lib/display/display.c b/lib/display/display.c index d71f97802..05cbad351 100644 --- a/lib/display/display.c +++ b/lib/display/display.c @@ -295,6 +295,7 @@ void pvdisplay_full(const struct cmd_context *cmd, const char *size; uint32_t pe_free; + uint64_t used_size, pvsize, unusable; if (!pv) return; @@ -309,19 +310,20 @@ void pvdisplay_full(const struct cmd_context *cmd, log_print("VG Name %s%s", pv->vg_name, pv->status & EXPORTED_VG ? " (exported)" : ""); - size = display_size(cmd, (uint64_t) pv->size); - if (pv->pe_size && pv->pe_count) { - -/******** FIXME display LVM on-disk data size - size2 = display_size(cmd, pv->size); -********/ - - log_print("PV Size %s" " / not usable %s", /* [LVM: %s]", */ - size, - display_size(cmd, (pv->size - - (uint64_t) pv->pe_count * pv->pe_size))); + used_size = (uint64_t) pv->pe_count * pv->pe_size; + if (pv->size > used_size) { + pvsize = pv->size; + unusable = pvsize - used_size; + } else { + pvsize = used_size; + unusable = used_size - pv->size; + } - } else + size = display_size(cmd, pvsize); + if (used_size) + log_print("PV Size %s / not usable %s", /* [LVM: %s]", */ + size, display_size(cmd, unusable)); + else log_print("PV Size %s", size); /* PV number not part of LVM2 design diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c index e6b799264..94d5cc80b 100644 --- a/lib/format1/import-export.c +++ b/lib/format1/import-export.c @@ -95,8 +95,8 @@ int import_pv(const struct format_type *fmt, struct dm_pool *mem, pv->pe_count = pvd->pe_total; pv->pe_alloc_count = 0; - /* Fix up pv size if missing */ - if (!pv->size) { + /* Fix up pv size if missing or impossibly large */ + if (!pv->size || pv->size > (1ULL << 62)) { if (!dev_get_size(dev, &pv->size)) { log_error("%s: Couldn't get size.", pv_dev_name(pv)); return 0; diff --git a/lib/format_text/import_vsn1.c b/lib/format_text/import_vsn1.c index a733ae689..0f2fd697e 100644 --- a/lib/format_text/import_vsn1.c +++ b/lib/format_text/import_vsn1.c @@ -215,8 +215,8 @@ static int _read_pv(struct format_instance *fid, struct dm_pool *mem, pv->pe_alloc_count = 0; pv->fmt = fid->fmt; - /* Fix up pv size if missing */ - if (!pv->size && pv->dev) { + /* Fix up pv size if missing or impossibly large */ + if ((!pv->size || pv->size > (1ULL << 62)) && pv->dev) { if (!dev_get_size(pv->dev, &pv->size)) { log_error("%s: Couldn't get size.", pv_dev_name(pv)); return 0; -- 2.43.5