From e68b5e30297718b262945d60b08da6fd892a7732 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 13 Nov 2001 17:53:06 +0000 Subject: [PATCH] o lvdisplay now shows LE / PV map o fix LE allocation when first PV is full o reduce VG free_count when removing PVs from VG --- lib/display/display.c | 166 ++++++++++++++++++++++++---------------- lib/metadata/metadata.h | 4 +- lib/metadata/pv_map.c | 11 ++- tools/lvcreate.c | 12 +-- tools/vgreduce.c | 2 + 5 files changed, 113 insertions(+), 82 deletions(-) diff --git a/lib/display/display.c b/lib/display/display.c index 3aca44ffd..4065976a9 100644 --- a/lib/display/display.c +++ b/lib/display/display.c @@ -65,7 +65,8 @@ char *display_size(unsigned long long size, size_len_t sl) * creates a new uuid string with -'s in it. It would be better if * the destination was passed in as well. EJT */ -char *display_uuid(char *uuidstr) { +char *display_uuid(char *uuidstr) +{ int i, j; char *uuid; @@ -103,33 +104,30 @@ void pvdisplay_colons(struct physical_volume *pv) uuid = display_uuid(pv->id.uuid); log_print("%s:%s:%llu:-1:%u:%u:-1:%llu:%u:%u:%u:%s", - dev_name(pv->dev), - pv->vg_name, - pv->size, - /* FIXME pv->pv_number, Derive or remove? */ - pv->status, /* FIXME Support old or new format here? */ - pv->status & ALLOCATED_PV, /* FIXME Remove? */ - /* FIXME pv->lv_cur, Remove? */ - pv->pe_size / 2, - pv->pe_count, - pv->pe_count - pv->pe_allocated, - pv->pe_allocated, - *uuid ? uuid : "none"); + dev_name(pv->dev), pv->vg_name, pv->size, + /* FIXME pv->pv_number, Derive or remove? */ + pv->status, /* FIXME Support old or new format here? */ + pv->status & ALLOCATED_PV, /* FIXME Remove? */ + /* FIXME pv->lv_cur, Remove? */ + pv->pe_size / 2, + pv->pe_count, + pv->pe_count - pv->pe_allocated, + pv->pe_allocated, *uuid ? uuid : "none"); dbg_free(uuid); return; } -void pvdisplay_full(struct physical_volume * pv) +void pvdisplay_full(struct physical_volume *pv) { - char *uuid; - char *size, *size1; /*, *size2; */ + char *uuid; + char *size, *size1; /*, *size2; */ uint64_t pe_free; - if (!pv) - return; + if (!pv) + return; uuid = display_uuid(pv->id.uuid); @@ -139,16 +137,15 @@ void pvdisplay_full(struct physical_volume * pv) size = display_size(pv->size / 2, SIZE_SHORT); if (pv->pe_size && pv->pe_count) { - size1 = display_size((pv->size - pv->pe_count * pv->pe_size) - / 2, SIZE_SHORT); + size1 = display_size((pv->size - pv->pe_count * pv->pe_size) + / 2, SIZE_SHORT); /******** FIXME display LVM on-disk data size size2 = display_size(pv->size / 2, SIZE_SHORT); ********/ - log_print("PV Size %s" - " / not usable %s", /* [LVM: %s]", */ - size, size1); /* , size2); */ + log_print("PV Size %s" " / not usable %s", /* [LVM: %s]", */ + size, size1); /* , size2); */ dbg_free(size1); /* dbg_free(size2); */ @@ -161,7 +158,7 @@ void pvdisplay_full(struct physical_volume * pv) **********/ log_print("PV Status %savailable", - (pv->status & ACTIVE) ? "" : "NOT "); + (pv->status & ACTIVE) ? "" : "NOT "); pe_free = pv->pe_count - pv->pe_allocated; if (pv->pe_count && (pv->status & ALLOCATED_PV)) @@ -192,16 +189,16 @@ void pvdisplay_full(struct physical_volume * pv) void pv_display_short(struct physical_volume *pv) { - if (!pv) + if (!pv) return; log_print("PV Name %s ", dev_name(pv->dev)); /* FIXME pv->pv_number); */ log_print("PV Status %savailable / %sallocatable", - (pv->status & ACTIVE) ? "" : "NOT ", - (pv->status & ALLOCATED_PV) ? "" : "NOT "); + (pv->status & ACTIVE) ? "" : "NOT ", + (pv->status & ALLOCATED_PV) ? "" : "NOT "); log_print("Total PE / Free PE %u / %u", - pv->pe_count, pv->pe_count - pv->pe_allocated); + pv->pe_count, pv->pe_count - pv->pe_allocated); return; } @@ -211,24 +208,17 @@ void lvdisplay_colons(struct logical_volume *lv) log_print("%s/%s:%s:%d:%d:-1:%d:%llu:%d:-1:%d:%d:-1:-1", /* FIXME Prefix - attach to struct volume_group? */ lv->vg->name, - lv->name, - lv->vg->name, - (lv->status & (LVM_READ | LVM_WRITE)) >> 8, - lv->status & ACTIVE, - /* FIXME lv->lv_number, */ - lvs_in_vg_opened(lv->vg), - lv->size, - lv->le_count, - /* FIXME num allocated? */ - (lv->status & (ALLOC_STRICT | ALLOC_CONTIGUOUS)) >> 12, - lv->read_ahead - /* FIXME device num MAJOR(lv->lv_dev), MINOR(lv->lv_dev) */ - ); - return; -} - -void lvdisplay_extents(struct logical_volume *lv) -{ + lv->name, + lv->vg->name, + (lv->status & (LVM_READ | LVM_WRITE)) >> 8, + lv->status & ACTIVE, + /* FIXME lv->lv_number, */ + lvs_in_vg_opened(lv->vg), lv->size, lv->le_count, + /* FIXME Add num allocated to struct! lv->lv_allocated_le, */ + ((lv->status & ALLOC_STRICT) + + (lv->status & ALLOC_CONTIGUOUS) * 2), lv->read_ahead + /* FIXME device num MAJOR(lv->lv_dev), MINOR(lv->lv_dev) */ + ); return; } @@ -237,14 +227,14 @@ void lvdisplay_full(struct logical_volume *lv) char *size; uint32_t alloc; - log_print("--- Logical volume ---"); + log_print("--- Logical volume ---"); /* FIXME prefix */ log_print("LV Name %s/%s", lv->vg->name, lv->name); - log_print("VG Name %s", lv->vg->name); + log_print("VG Name %s", lv->vg->name); - log_print("LV Write Access %s", - (lv->status & LVM_WRITE) ? "read/write" : "read only"); + log_print("LV Write Access %s", + (lv->status & LVM_WRITE) ? "read/write" : "read only"); /******* FIXME Snapshot if (lv->status & (LVM_SNAPSHOT_ORG | LVM_SNAPSHOT)) { @@ -291,8 +281,8 @@ void lvdisplay_full(struct logical_volume *lv) } ***********/ - log_print("LV Status %savailable", - (lv->status & ACTIVE) ? "" : "NOT "); + log_print("LV Status %savailable", + (lv->status & ACTIVE) ? "" : "NOT "); /********* FIXME lv_number log_print("LV # %u", lv->lv_number + 1); @@ -313,12 +303,11 @@ void lvdisplay_full(struct logical_volume *lv) #endif ********/ - size = display_size(lv->size / 2, SIZE_SHORT); - log_print("LV Size %s", size); - dbg_free(size); + log_print("LV Size %s", size); + dbg_free(size); - log_print("Current LE %u", lv->le_count); + log_print("Current LE %u", lv->le_count); /********** FIXME allocation log_print("Allocated LE %u", lv->allocated_le); @@ -356,13 +345,12 @@ void lvdisplay_full(struct logical_volume *lv) } ******************/ - if (lv->stripes > 1) { - log_print("Stripes %u", lv->stripes); + if (lv->stripes > 1) { + log_print("Stripes %u", lv->stripes); /*********** FIXME stripesize log_print("Stripe size (KByte) %u", lv->stripesize / 2); ***********/ - } - + } /************** #ifdef LVM_FUTURE @@ -374,15 +362,17 @@ void lvdisplay_full(struct logical_volume *lv) #endif ***************/ + /* FIXME next free == ALLOC_SIMPLE */ alloc = lv->status & (ALLOC_STRICT | ALLOC_CONTIGUOUS); - log_print("Allocation %s%s%s%s", - !(alloc & (ALLOC_STRICT | ALLOC_CONTIGUOUS)) ? "next free" : "", - (alloc == ALLOC_STRICT) ? "strict" : "", - (alloc == ALLOC_CONTIGUOUS) ? "contiguous" : "", - (alloc == (ALLOC_STRICT | ALLOC_CONTIGUOUS)) ? "strict/contiguous" : "" - ); + log_print("Allocation %s%s%s%s", + !(alloc & (ALLOC_STRICT | ALLOC_CONTIGUOUS)) ? "next free" : + "", (alloc == ALLOC_STRICT) ? "strict" : "", + (alloc == ALLOC_CONTIGUOUS) ? "contiguous" : "", + (alloc == + (ALLOC_STRICT | ALLOC_CONTIGUOUS)) ? "strict/contiguous" : + ""); - log_print("Read ahead sectors %u\n", lv->read_ahead); + log_print("Read ahead sectors %u\n", lv->read_ahead); /**************** #ifdef LVM_FUTURE @@ -399,6 +389,46 @@ void lvdisplay_full(struct logical_volume *lv) MAJOR(lv->lv_dev), MINOR(lv->lv_dev)); *************/ - return; + return; } + +void lvdisplay_extents(struct logical_volume *lv) +{ + int le; + struct list *pvh; + struct physical_volume *pv; + + log_verbose("--- Distribution of logical volume on physical " + "volumes ---"); + log_verbose("PV Name PE on PV "); + + list_iterate(pvh, &lv->vg->pvs) { + int count = 0; + pv = &list_item(pvh, struct pv_list)->pv; + for (le = 0; le < lv->le_count; le++) + if (lv->map[le].pv->dev == pv->dev) + count++; + if (count) + log_verbose("%-25s %d", dev_name(pv->dev), count); + } + +/********* FIXME "reads writes" + + + printf("\n --- logical volume i/o statistic ---\n" + " %d reads %d writes\n", sum_reads, sum_writes); + +******* */ + + log_verbose(" "); + log_verbose("--- Logical extents ---"); + log_verbose("LE PV PE"); + + for (le = 0; le < lv->le_count; le++) { + log_verbose("%05d %-25s %05u ", le, + dev_name(lv->map[le].pv->dev), lv->map[le].pe); + } + + return; +} diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index 113d853c7..a87054618 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -35,9 +35,9 @@ /* FIXME: This should be an enum rather than a bitset, remove from status - EJT */ -#define ALLOC_SIMPLE 0x00001000 /* LV */ +#define ALLOC_SIMPLE 0x00001000 /* LV */ #define ALLOC_STRICT 0x00002000 /* LV */ -#define ALLOC_CONTIGUOUS 0x00004000 /* LV */ +#define ALLOC_CONTIGUOUS 0x00004000 /* LV */ #define SNAPSHOT 0x00010000 /* LV */ #define SNAPSHOT_ORG 0x00020000 /* LV */ diff --git a/lib/metadata/pv_map.c b/lib/metadata/pv_map.c index 7e3702e4e..5a3a8de00 100644 --- a/lib/metadata/pv_map.c +++ b/lib/metadata/pv_map.c @@ -7,7 +7,6 @@ #include "pv_map.h" #include "log.h" - static int _create_maps(struct pool *mem, struct list *pvs, struct list *maps) { struct list *tmp; @@ -29,6 +28,8 @@ static int _create_maps(struct pool *mem, struct list *pvs, struct list *maps) return 0; } + list_init(&pvm->areas); + list_add(maps, &pvm->list); } @@ -97,7 +98,6 @@ static int _create_single_area(struct pool *mem, struct pv_map *pvm, return 0; } - list_init(&pvm->areas); pva->start = b; pva->count = e - b; list_add(&pvm->areas, &pva->list); @@ -136,7 +136,7 @@ static int _create_all_areas(struct pool *mem, struct list *maps) return 1; } -struct list *create_pv_maps(struct pool *mem, struct volume_group *vg, +struct list *create_pv_maps(struct pool *mem, struct volume_group *vg, struct list *pvs) { struct list *maps = pool_zalloc(mem, sizeof(*maps)); @@ -149,7 +149,7 @@ struct list *create_pv_maps(struct pool *mem, struct volume_group *vg, list_init(maps); if (!_create_maps(mem, pvs, maps)) { - log_error("Couldn't create physical volume maps in %s", + log_error("Couldn't create physical volume maps in %s", vg->name); goto bad; } @@ -167,8 +167,7 @@ struct list *create_pv_maps(struct pool *mem, struct volume_group *vg, return maps; - bad: + bad: pool_free(mem, maps); return NULL; } - diff --git a/tools/lvcreate.c b/tools/lvcreate.c index 04d77c243..f9a1f4dd1 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -133,7 +133,7 @@ int lvcreate(int argc, char **argv) if (argc) { /* Build up list of PVs */ - if (!(pvh = pool_alloc(fid->cmd->mem, sizeof (struct list)))) { + if (!(pvh = pool_alloc(fid->cmd->mem, sizeof(struct list)))) { log_error("pvh list allocation failed"); return ECMD_FAILED; } @@ -147,8 +147,8 @@ int lvcreate(int argc, char **argv) } if (list_item(pvl, struct pv_list)->pv.pe_count == list_item(pvl, struct pv_list)->pv.pe_allocated) { - log_error("No free extents on physical volume" - " %s", argv[opt]); + log_error("No free extents on physical volume" + " %s", argv[opt]); continue; /* FIXME But check not null at end! */ } @@ -207,7 +207,7 @@ int lvcreate(int argc, char **argv) extents += vg->extent_size - extents % vg->extent_size; log_print("Rounding up size to full physical extent %s", - (s1 = display_size(extents / 2, SIZE_SHORT))); + (s1 = display_size(extents / 2, SIZE_SHORT))); dbg_free(s1); } @@ -248,13 +248,13 @@ int lvcreate(int argc, char **argv) /* FIXME 2 blocks */ char buf[4096]; - memset(buf, 0, sizeof (buf)); + memset(buf, 0, sizeof(buf)); log_verbose("Zeroing start of logical volume %s", lv_name); /* FIXME get dev = dev_cache_get(lv_name, fid->cmd->filter); */ /* FIXME Add fsync! */ - if (!(dev_write(dev, 0, sizeof (buf), &buf) == sizeof (buf))) { + if (!(dev_write(dev, 0, sizeof(buf), &buf) == sizeof(buf))) { log_error("Initialisation of %s failed", dev_name(dev)); return ECMD_FAILED; } diff --git a/tools/vgreduce.c b/tools/vgreduce.c index 468cff1b1..3223615ab 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -113,6 +113,8 @@ static int vgreduce_single(struct volume_group *vg, struct physical_volume *pv) list_del(pvh); *pv->vg_name = '\0'; vg->pv_count--; + vg->free_count -= pv->pe_count - pv->pe_allocated; + vg->extent_count -= pv->pe_count; if (!(fid->ops->vg_write(fid, vg))) { log_error("Removal of physical volume %s from %s failed", -- 2.43.5