diff --git a/WHATS_NEW b/WHATS_NEW index 921eeed9e..dd0330e7d 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.34 - =================================== + Divide up internal orphan volume group by format type. Update usage message for clvmd. Fix clvmd man page printing
, clarified debug options. Fix lvresize to support /dev/mapper prefix in the lvname diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c index 3bb7b63e7..5fbad184c 100644 --- a/lib/cache/lvmcache.c +++ b/lib/cache/lvmcache.c @@ -208,9 +208,6 @@ const char *vgname_from_vgid(struct dm_pool *mem, const char *vgid) struct lvmcache_vginfo *vginfo; const char *vgname = NULL; - if (!*vgid) - vgname = ORPHAN; - if ((vginfo = vginfo_from_vgid(vgid))) vgname = vginfo->vgname; @@ -530,8 +527,10 @@ static int _lvmcache_update_vgid(struct lvmcache_info *info, const char *vgid) return 0; } - log_debug("lvmcache: %s: setting %s VGID to %s", dev_name(info->dev), - info->vginfo->vgname, info->vginfo->vgid); + if (!is_orphan_vg(info->vginfo->vgname)) + log_debug("lvmcache: %s: setting %s VGID to %s", + dev_name(info->dev), info->vginfo->vgname, + info->vginfo->vgid); return 1; } @@ -627,15 +626,6 @@ static int _lvmcache_update_vgname(struct lvmcache_info *info, struct lvmcache_vginfo *vginfo, *primary_vginfo; // struct lvmcache_vginfo *old_vginfo, *next; - /* If vgname is NULL and we don't already have a vgname, - * assume ORPHAN - we want every entry to have a vginfo - * attached for scanning reasons. - */ - if (!vgname && !info->vginfo) { - vgname = ORPHAN; - vgid = ORPHAN; - } - if (!vgname || (info->vginfo && !strcmp(info->vginfo->vgname, vgname))) return 1; @@ -716,9 +706,8 @@ static int _lvmcache_update_vgname(struct lvmcache_info *info, /* FIXME Check consistency of list! */ vginfo->fmt = info->fmt; - log_debug("lvmcache: %s: now %s%s%s%s%s", dev_name(info->dev), - !is_orphan_vg(vgname) ? "in VG " : "orphaned", vgname, - vginfo->vgid[0] ? " (" : "", + log_debug("lvmcache: %s: now in VG %s%s%s%s", dev_name(info->dev), + vgname, vginfo->vgid[0] ? " (" : "", vginfo->vgid[0] ? vginfo->vgid : "", vginfo->vgid[0] ? ")" : ""); @@ -764,6 +753,12 @@ int lvmcache_update_vgname_and_id(struct lvmcache_info *info, const char *vgname, const char *vgid, uint32_t vgstatus, const char *creation_host) { + if (!vgname && !info->vginfo) { + log_error("Internal error: NULL vgname handed to cache"); + /* FIXME Remove this */ + vgname = info->fmt->orphan_vg_name; + vgid = vgname; + } if (!_lvmcache_update_vgname(info, vgname, vgid, vgstatus, creation_host) || !_lvmcache_update_vgid(info, vgid) || diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h index bdda2f0a4..3be620ab4 100644 --- a/lib/cache/lvmcache.h +++ b/lib/cache/lvmcache.h @@ -20,7 +20,8 @@ #include "uuid.h" #include "label.h" -#define ORPHAN "" +#define ORPHAN_PREFIX "#" +#define ORPHAN_VG_NAME(fmt) ORPHAN_PREFIX "orphans_" fmt #define CACHE_INVALID 0x00000001 #define CACHE_LOCKED 0x00000002 diff --git a/lib/display/display.c b/lib/display/display.c index 9e5751a53..90e9b6854 100644 --- a/lib/display/display.c +++ b/lib/display/display.c @@ -307,7 +307,8 @@ void pvdisplay_full(const struct cmd_context *cmd, log_print("--- %sPhysical volume ---", pv->pe_size ? "" : "NEW "); log_print("PV Name %s", pv_dev_name(pv)); - log_print("VG Name %s%s", pv->vg_name, + log_print("VG Name %s%s", + is_orphan(pv) ? "" : pv->vg_name, pv->status & EXPORTED_VG ? " (exported)" : ""); data_size = (uint64_t) pv->pe_count * pv->pe_size; diff --git a/lib/format1/disk-rep.c b/lib/format1/disk-rep.c index 9db2cf35b..2379cf2d9 100644 --- a/lib/format1/disk-rep.c +++ b/lib/format1/disk-rep.c @@ -326,10 +326,11 @@ static void __update_lvmcache(const struct format_type *fmt, unsigned exported) { struct lvmcache_info *info; + const char *vgname = *((char *)dl->pvd.vg_name) ? + (char *)dl->pvd.vg_name : fmt->orphan_vg_name; if (!(info = lvmcache_add(fmt->labeller, (char *)dl->pvd.pv_uuid, dev, - (char *)dl->pvd.vg_name, vgid, - exported ? EXPORTED_VG : 0))) { + vgname, vgid, exported ? EXPORTED_VG : 0))) { stack; return; } @@ -363,20 +364,20 @@ static struct disk_list *__read_disk(const struct format_type *fmt, if (!*dl->pvd.vg_name) { log_very_verbose("%s is not a member of any format1 VG", name); - __update_lvmcache(fmt, dl, dev, NULL, 0); + __update_lvmcache(fmt, dl, dev, fmt->orphan_vg_name, 0); return (vg_name) ? NULL : dl; } if (!read_vgd(dl->dev, &dl->vgd, &dl->pvd)) { log_error("Failed to read VG data from PV (%s)", name); - __update_lvmcache(fmt, dl, dev, NULL, 0); + __update_lvmcache(fmt, dl, dev, fmt->orphan_vg_name, 0); goto bad; } if (vg_name && strcmp(vg_name, (char *)dl->pvd.vg_name)) { log_very_verbose("%s is not a member of the VG %s", name, vg_name); - __update_lvmcache(fmt, dl, dev, NULL, 0); + __update_lvmcache(fmt, dl, dev, fmt->orphan_vg_name, 0); goto bad; } diff --git a/lib/format1/format1.c b/lib/format1/format1.c index 5e3f24fe5..4db74f0e4 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -18,13 +18,10 @@ #include "limits.h" #include "display.h" #include "toolcontext.h" -#include "lvmcache.h" #include "lvm1-label.h" #include "format1.h" #include "segtype.h" -#define FMT_LVM1_NAME "lvm1" - /* VG consistency checks */ static int _check_vgs(struct list *pvs, int *partial) { @@ -523,6 +520,7 @@ struct format_type *init_format(struct cmd_context *cmd) fmt->ops = &_format1_ops; fmt->name = FMT_LVM1_NAME; fmt->alias = NULL; + fmt->orphan_vg_name = FMT_LVM1_ORPHAN_VG_NAME; fmt->features = FMT_RESTRICTED_LVIDS | FMT_ORPHAN_ALLOCATABLE | FMT_RESTRICTED_READAHEAD; fmt->private = NULL; diff --git a/lib/format1/format1.h b/lib/format1/format1.h index 4a3c12a9f..c76ba6200 100644 --- a/lib/format1/format1.h +++ b/lib/format1/format1.h @@ -17,6 +17,10 @@ #define _LVM_FORMAT1_H #include "metadata.h" +#include "lvmcache.h" + +#define FMT_LVM1_NAME "lvm1" +#define FMT_LVM1_ORPHAN_VG_NAME ORPHAN_VG_NAME(FMT_LVM1_NAME) #ifdef LVM1_INTERNAL struct format_type *init_lvm1_format(struct cmd_context *cmd); diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c index fc78bbb8a..a0de3628a 100644 --- a/lib/format1/import-export.c +++ b/lib/format1/import-export.c @@ -26,6 +26,7 @@ #include "pv_alloc.h" #include "display.h" #include "lvmcache.h" +#include "metadata.h" #include @@ -61,7 +62,7 @@ int import_pv(const struct format_type *fmt, struct dm_pool *mem, pv->dev = dev; if (!*pvd->vg_name) - pv->vg_name = ORPHAN; + pv->vg_name = fmt->orphan_vg_name; else if (!(pv->vg_name = dm_pool_strdup(mem, (char *)pvd->vg_name))) { log_error("Volume Group name allocation failed."); return 0; @@ -147,7 +148,7 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem __attribute((unused)) memcpy(pvd->pv_uuid, pv->id.uuid, ID_LEN); - if (pv->vg_name) { + if (pv->vg_name && !is_orphan(pv)) { if (!_check_vg_name(pv->vg_name)) return_0; strncpy((char *)pvd->vg_name, pv->vg_name, sizeof(pvd->vg_name)); diff --git a/lib/format1/lvm1-label.c b/lib/format1/lvm1-label.c index dd8443d1a..ffd215187 100644 --- a/lib/format1/lvm1-label.c +++ b/lib/format1/lvm1-label.c @@ -19,7 +19,7 @@ #include "label.h" #include "metadata.h" #include "xlate.h" -#include "lvmcache.h" +#include "format1.h" #include #include @@ -60,17 +60,21 @@ static int _lvm1_read(struct labeller *l, struct device *dev, void *buf, struct pv_disk *pvd = (struct pv_disk *) buf; struct vg_disk vgd; struct lvmcache_info *info; - const char *vgid = NULL; + const char *vgid = FMT_LVM1_ORPHAN_VG_NAME; + const char *vgname = FMT_LVM1_ORPHAN_VG_NAME; unsigned exported = 0; munge_pvd(dev, pvd); - if (*pvd->vg_name && read_vgd(dev, &vgd, pvd)) { + if (*pvd->vg_name) { + if (!read_vgd(dev, &vgd, pvd)) + return_0; vgid = (char *) vgd.vg_uuid; + vgname = (char *) pvd->vg_name; exported = pvd->pv_status & VG_EXPORTED; } - if (!(info = lvmcache_add(l, (char *)pvd->pv_uuid, dev, (char *)pvd->vg_name, vgid, + if (!(info = lvmcache_add(l, (char *)pvd->pv_uuid, dev, vgname, vgid, exported))) return_0; *label = info->label; diff --git a/lib/format_pool/format_pool.c b/lib/format_pool/format_pool.c index 5c09b78cb..9cd8f5d42 100644 --- a/lib/format_pool/format_pool.c +++ b/lib/format_pool/format_pool.c @@ -316,6 +316,7 @@ struct format_type *init_format(struct cmd_context *cmd) fmt->ops = &_format_pool_ops; fmt->name = FMT_POOL_NAME; fmt->alias = NULL; + fmt->orphan_vg_name = ORPHAN_VG_NAME(FMT_POOL_NAME); fmt->features = 0; fmt->private = NULL; diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c index 2235f0591..4becae206 100644 --- a/lib/format_text/format-text.c +++ b/lib/format_text/format-text.c @@ -36,9 +36,6 @@ #include #include -#define FMT_TEXT_NAME "lvm2" -#define FMT_TEXT_ALIAS "text" - static struct mda_header *_raw_read_mda_header(const struct format_type *fmt, struct device_area *dev_area); @@ -387,7 +384,8 @@ static struct raw_locn *_find_vg_rlocn(struct device_area *dev_area, bad: if ((info = info_from_pvid(dev_area->dev->pvid, 0))) - lvmcache_update_vgname_and_id(info, ORPHAN, ORPHAN, 0, NULL); + lvmcache_update_vgname_and_id(info, FMT_TEXT_ORPHAN_VG_NAME, + FMT_TEXT_ORPHAN_VG_NAME, 0, NULL); return NULL; } @@ -1293,7 +1291,7 @@ static int _text_pv_write(const struct format_type *fmt, struct physical_volume /* FIXME Test mode don't update cache? */ if (!(info = lvmcache_add(fmt->labeller, (char *) &pv->id, pv->dev, - ORPHAN, NULL, 0))) + FMT_TEXT_ORPHAN_VG_NAME, NULL, 0))) return_0; label = info->label; @@ -1438,7 +1436,7 @@ static int _text_pv_read(const struct format_type *fmt, const char *pv_name, pv->dev = info->dev; pv->fmt = info->fmt; pv->size = info->device_size >> SECTOR_SHIFT; - pv->vg_name = ORPHAN; + pv->vg_name = FMT_TEXT_ORPHAN_VG_NAME; memcpy(&pv->id, &info->dev->pvid, sizeof(pv->id)); /* Currently only support exactly one data area */ @@ -1887,6 +1885,7 @@ struct format_type *create_text_format(struct cmd_context *cmd) fmt->ops = &_text_handler; fmt->name = FMT_TEXT_NAME; fmt->alias = FMT_TEXT_ALIAS; + fmt->orphan_vg_name = ORPHAN_VG_NAME(FMT_TEXT_NAME); fmt->features = FMT_SEGMENTS | FMT_MDAS | FMT_TAGS | FMT_PRECOMMIT | FMT_UNLIMITED_VOLS | FMT_RESIZE_PV | FMT_UNLIMITED_STRIPESIZE; diff --git a/lib/format_text/format-text.h b/lib/format_text/format-text.h index 9d7f86233..4efcdaa0f 100644 --- a/lib/format_text/format-text.h +++ b/lib/format_text/format-text.h @@ -19,6 +19,10 @@ #include "lvm-types.h" #include "metadata.h" +#define FMT_TEXT_NAME "lvm2" +#define FMT_TEXT_ALIAS "text" +#define FMT_TEXT_ORPHAN_VG_NAME ORPHAN_VG_NAME(FMT_TEXT_NAME) + /* * Archives a vg config. 'retain_days' is the minimum number of * days that an archive file must be held for. 'min_archives' is diff --git a/lib/format_text/text_label.c b/lib/format_text/text_label.c index 8fa64f648..60550f2b1 100644 --- a/lib/format_text/text_label.c +++ b/lib/format_text/text_label.c @@ -207,7 +207,9 @@ static int _text_read(struct labeller *l, struct device *dev, void *buf, pvhdr = (struct pv_header *) ((void *) buf + xlate32(lh->offset_xl)); - if (!(info = lvmcache_add(l, (char *)pvhdr->pv_uuid, dev, NULL, NULL, 0))) + if (!(info = lvmcache_add(l, (char *)pvhdr->pv_uuid, dev, + FMT_TEXT_ORPHAN_VG_NAME, + FMT_TEXT_ORPHAN_VG_NAME, 0))) return_0; *label = info->label; diff --git a/lib/label/label.c b/lib/label/label.c index a0608c068..934fe6805 100644 --- a/lib/label/label.c +++ b/lib/label/label.c @@ -178,7 +178,8 @@ static struct labeller *_find_labeller(struct device *dev, char *buf, out: if (!found) { if ((info = info_from_pvid(dev->pvid, 0))) - lvmcache_update_vgname_and_id(info, ORPHAN, ORPHAN, + lvmcache_update_vgname_and_id(info, info->fmt->orphan_vg_name, + info->fmt->orphan_vg_name, 0, NULL); log_very_verbose("%s: No label detected", dev_name(dev)); } @@ -275,7 +276,8 @@ int label_read(struct device *dev, struct label **result, stack; if ((info = info_from_pvid(dev->pvid, 0))) - lvmcache_update_vgname_and_id(info, ORPHAN, ORPHAN, + lvmcache_update_vgname_and_id(info, info->fmt->orphan_vg_name, + info->fmt->orphan_vg_name, 0, NULL); return r; @@ -351,7 +353,8 @@ int label_verify(struct device *dev) if (!dev_open(dev)) { if ((info = info_from_pvid(dev->pvid, 0))) - lvmcache_update_vgname_and_id(info, ORPHAN, ORPHAN, + lvmcache_update_vgname_and_id(info, info->fmt->orphan_vg_name, + info->fmt->orphan_vg_name, 0, NULL); return_0; diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h index e7c9741bc..f98c47219 100644 --- a/lib/metadata/metadata-exported.h +++ b/lib/metadata/metadata-exported.h @@ -133,6 +133,7 @@ struct format_type { struct labeller *labeller; const char *name; const char *alias; + const char *orphan_vg_name; uint32_t features; void *library; void *private; diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index bde628ef1..92c282c2e 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -356,7 +356,7 @@ int vg_remove_single(struct cmd_context *cmd, const char *vg_name, pv = pvl->pv; log_verbose("Removing physical volume \"%s\" from " "volume group \"%s\"", pv_dev_name(pv), vg_name); - pv->vg_name = ORPHAN; + pv->vg_name = vg->fid->fmt->orphan_vg_name; pv->status = ALLOCATABLE_PV; if (!dev_get_size(pv_dev(pv), &pv->size)) { @@ -833,6 +833,7 @@ static struct physical_volume *_pv_create(const struct format_type *fmt, } pv->fmt = fmt; + pv->vg_name = fmt->orphan_vg_name; if (!fmt->ops->pv_setup(fmt, pe_start, existing_extent_count, existing_extent_size, @@ -1324,7 +1325,8 @@ int vg_revert(struct volume_group *vg) } /* Make orphan PVs look like a VG */ -static struct volume_group *_vg_read_orphans(struct cmd_context *cmd) +static struct volume_group *_vg_read_orphans(struct cmd_context *cmd, + const char *orphan_vgname) { struct lvmcache_vginfo *vginfo; struct lvmcache_info *info; @@ -1332,7 +1334,7 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd) struct volume_group *vg; struct physical_volume *pv; - if (!(vginfo = vginfo_from_vgname(ORPHAN, NULL))) + if (!(vginfo = vginfo_from_vgname(orphan_vgname, NULL))) return_NULL; if (!(vg = dm_pool_zalloc(cmd->mem, sizeof(*vg)))) { @@ -1343,7 +1345,7 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd) list_init(&vg->lvs); list_init(&vg->tags); vg->cmd = cmd; - if (!(vg->name = dm_pool_strdup(cmd->mem, ORPHAN))) { + if (!(vg->name = dm_pool_strdup(cmd->mem, orphan_vgname))) { log_error("vg name allocation failed"); return NULL; } @@ -1421,7 +1423,7 @@ static struct volume_group *_vg_read(struct cmd_context *cmd, return NULL; } *consistent = 1; - return _vg_read_orphans(cmd); + return _vg_read_orphans(cmd, vgname); } /* Find the vgname in the cache */ @@ -1942,7 +1944,7 @@ int pv_write_orphan(struct cmd_context *cmd, struct physical_volume *pv) { const char *old_vg_name = pv->vg_name; - pv->vg_name = ORPHAN; + pv->vg_name = cmd->fmt->orphan_vg_name; pv->status = ALLOCATABLE_PV; if (!dev_get_size(pv->dev, &pv->size)) { @@ -1966,7 +1968,7 @@ int pv_write_orphan(struct cmd_context *cmd, struct physical_volume *pv) */ int is_orphan_vg(const char *vg_name) { - return (!strcmp(vg_name, ORPHAN) ? 1 : 0); + return (vg_name && vg_name[0] == ORPHAN_PREFIX[0]) ? 1 : 0; } /** diff --git a/lib/report/report.c b/lib/report/report.c index 7e1b67969..3279ad9fd 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -1004,7 +1004,7 @@ static int _copypercent_disp(struct dm_report *rh __attribute((unused)), struct /* necessary for displaying something for PVs not belonging to VG */ static struct volume_group _dummy_vg = { - .name = (char *) ORPHAN, + .name = (char *) "", }; static void *_obj_get_vg(void *obj) diff --git a/tools/pvchange.c b/tools/pvchange.c index 1783bad80..c7a0ee714 100644 --- a/tools/pvchange.c +++ b/tools/pvchange.c @@ -171,7 +171,7 @@ static int _pvchange_single(struct cmd_context *cmd, struct physical_volume *pv, if (!is_orphan(pv)) { orig_vg_name = pv_vg_name(pv); orig_pe_alloc_count = pv_pe_alloc_count(pv); - pv->vg_name = ORPHAN; + pv->vg_name = pv->fmt->orphan_vg_name; pv->pe_alloc_count = 0; if (!(pv_write(cmd, pv, NULL, INT64_C(-1)))) { log_error("pv_write with new uuid failed " diff --git a/tools/vgreduce.c b/tools/vgreduce.c index 4b4dea48d..ccda5d96c 100644 --- a/tools/vgreduce.c +++ b/tools/vgreduce.c @@ -376,7 +376,7 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg, if (pvl) list_del(&pvl->list); - pv->vg_name = ORPHAN; + pv->vg_name = vg->fid->fmt->orphan_vg_name; pv->status = ALLOCATABLE_PV; if (!dev_get_size(pv_dev(pv), &pv->size)) {