diff options
author | David Teigland <teigland@redhat.com> | 2017-08-24 17:03:44 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2017-10-16 11:17:12 -0500 |
commit | d1cd512d9100505851287dc2a71694cac0c29a49 (patch) | |
tree | 6d7168486d3f54445d28c5d95efd81b7ef633097 | |
parent | 629fc500a89fcf655065dbbd9c6340c90910eaee (diff) | |
download | lvm2-d1cd512d9100505851287dc2a71694cac0c29a49.tar.gz |
label_scan: fix label scan for independent metadata areas
When label_scan reads metadata from independent areas, not
from the devices, set a flag on the vginfo. Use this flag
to avoid trying to rescan those devices in vg_read() since
the metadata won't be found on them, and wreck the lvmcache
data set up by the label scan.
-rw-r--r-- | lib/cache/lvmcache.c | 19 | ||||
-rw-r--r-- | lib/cache/lvmcache.h | 1 | ||||
-rw-r--r-- | lib/format_text/format-text.c | 26 |
3 files changed, 42 insertions, 4 deletions
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c index 7846ce461..4fe0dc070 100644 --- a/lib/cache/lvmcache.c +++ b/lib/cache/lvmcache.c @@ -63,6 +63,7 @@ struct lvmcache_vginfo { char *lock_type; uint32_t mda_checksum; size_t mda_size; + int independent_metadata_location; /* metadata read from independent areas */ /* * The following are not related to lvmcache or vginfo, * but are borrowing the vginfo to store the data. @@ -1169,6 +1170,16 @@ int lvmcache_label_rescan_vg(struct cmd_context *cmd, const char *vgname, const if (!(vginfo = lvmcache_vginfo_from_vgname(vgname, vgid))) return_0; + /* + * When the VG metadata is from an independent location, + * then rescanning the devices in the VG won't find the + * metadata, and will destroy the vginfo/info associations + * that were created during label scan when the + * independent locations were read. + */ + if (vginfo->independent_metadata_location) + return 1; + dm_list_iterate_items(info, &vginfo->infos) { if (!(devl = dm_malloc(sizeof(*devl)))) { log_error("device_list element allocation failed"); @@ -2620,6 +2631,14 @@ int lvmcache_vgid_is_cached(const char *vgid) { return 1; } +void lvmcache_set_independent_location(const char *vgname) +{ + struct lvmcache_vginfo *vginfo; + + if ((vginfo = lvmcache_vginfo_from_vgname(vgname, NULL))) + vginfo->independent_metadata_location = 1; +} + /* * Return true iff it is impossible to find out from this info alone whether the * PV in question is or is not an orphan. diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h index 19bafc2e2..e36284c24 100644 --- a/lib/cache/lvmcache.h +++ b/lib/cache/lvmcache.h @@ -219,4 +219,5 @@ int lvmcache_get_vg_devs(struct cmd_context *cmd, struct lvmcache_vginfo *vginfo, struct dm_list *devs); +void lvmcache_set_independent_location(const char *vgname); #endif diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c index 8bf0fca77..072c769e4 100644 --- a/lib/format_text/format-text.c +++ b/lib/format_text/format-text.c @@ -911,8 +911,10 @@ static struct volume_group *_vg_read_file_name(struct format_instance *fid, time_t when; char *desc; - if (!(vg = text_read_metadata_file(fid, read_path, &when, &desc))) - return_NULL; + if (!(vg = text_read_metadata_file(fid, read_path, &when, &desc))) { + log_error("Failed to read VG %s from %s", vgname, read_path); + return NULL; + } /* * Currently you can only have a single volume group per @@ -1138,6 +1140,9 @@ static int _scan_file(const struct format_type *fmt, const char *vgname) dir_list = &((struct mda_lists *) fmt->private)->dirs; + if (!dm_list_empty(dir_list)) + log_debug_metadata("Scanning independent files for %s", vgname ? vgname : "VGs"); + dm_list_iterate_items(dl, dir_list) { if (!(d = opendir(dl->dir))) { log_sys_error("opendir", dl->dir); @@ -1170,10 +1175,14 @@ static int _scan_file(const struct format_type *fmt, const char *vgname) stack; break; } + + log_debug_metadata("Scanning independent file %s for VG %s", path, scanned_vgname); + if ((vg = _vg_read_file_name(fid, scanned_vgname, path))) { /* FIXME Store creation host in vg */ lvmcache_update_vg(vg, 0); + lvmcache_set_independent_location(vg->name); release_vg(vg); } } @@ -1298,11 +1307,16 @@ static int _scan_raw(const struct format_type *fmt, const char *vgname __attribu raw_list = &((struct mda_lists *) fmt->private)->raws; + if (!dm_list_empty(raw_list)) + log_debug_metadata("Scanning independent raw locations for %s", vgname ? vgname : "VGs"); + fid.fmt = fmt; dm_list_init(&fid.metadata_areas_in_use); dm_list_init(&fid.metadata_areas_ignored); dm_list_iterate_items(rl, raw_list) { + log_debug_metadata("Scanning independent dev %s", dev_name(rl->dev_area.dev)); + /* FIXME We're reading mdah twice here... */ if (!dev_open_readonly(rl->dev_area.dev)) { stack; @@ -1317,8 +1331,10 @@ static int _scan_raw(const struct format_type *fmt, const char *vgname __attribu /* TODO: caching as in read_metadata_location() (trigger this code?) */ if (read_metadata_location(fmt, mdah, NULL, &rl->dev_area, &vgsummary, NULL)) { vg = _vg_read_raw_area(&fid, vgsummary.vgname, &rl->dev_area, NULL, NULL, NULL, 0); - if (vg) + if (vg) { lvmcache_update_vg(vg, 0); + lvmcache_set_independent_location(vg->name); + } } close_dev: if (!dev_close(rl->dev_area.dev)) @@ -1332,7 +1348,9 @@ static int _scan_raw(const struct format_type *fmt, const char *vgname __attribu static int _text_scan(const struct format_type *fmt, const char *vgname) { - return (_scan_file(fmt, vgname) & _scan_raw(fmt, vgname)); + _scan_file(fmt, vgname); + _scan_raw(fmt, vgname); + return 1; } struct _write_single_mda_baton { |