master - improve reading and repairing vg metadata
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ba7ff96faff052c6145c71222ea5047a6bcee33b Commit: ba7ff96faff052c6145c71222ea5047a6bcee33b Parent: 015b906069a989552c09f61d7230b000d0a1f0f0 Author: David Teigland <[email protected]> AuthorDate: Fri May 24 12:04:37 2019 -0500 Committer: David Teigland <[email protected]> CommitterDate: Fri Jun 7 15:54:04 2019 -0500
improve reading and repairing vg metadata
The fact that vg repair is implemented as a part of vg read has led to a messy and complicated implementation of vg_read, and limited and uncontrolled repair capability. This splits read and repair apart.
Summary
-------
- take all kinds of various repairs out of vg_read
- vg_read no longer writes anything
- vg_read now simply reads and returns vg metadata
- vg_read ignores bad or old copies of metadata
- vg_read proceeds with a single good copy of metadata
- improve error checks and handling when reading
- keep track of bad (corrupt) copies of metadata in lvmcache
- keep track of old (seqno) copies of metadata in lvmcache
- keep track of outdated PVs in lvmcache
- vg_write will do basic repairs
- new command vgck --updatemetdata will do all repairs
Details
-------
- In scan, do not delete dev from lvmcache if reading/processing fails; the dev is still present, and removing it makes it look like the dev is not there. Records are now kept about the problems with each PV so they be fixed/repaired in the appropriate places.
- In scan, record a bad mda on failure, and delete the mda from mda in use list so it will not be used by vg_read or vg_write, only by repair.
- In scan, succeed if any good mda on a device is found, instead of failing if any is bad. The bad/old copies of metadata should not interfere with normal usage while good copies can be used.
- In scan, add a record of old mdas in lvmcache for later, do not repair them while reading, and do not let them prevent us from finding and using a good copy of metadata from elsewhere. One result is that "inconsistent metadata" is no longer a read error, but instead a record in lvmcache that can be addressed separate from the read.
- Treat a dev with no good mdas like a dev with no mdas, which is an existing case we already handle.
- Don't use a fake vg "handle" for returning an error from vg_read, or the vg_read_error function for getting that error number; just return null if the vg cannot be read or used, and an error_flags arg with flags set for the specific kind of error (which can be used later for determining the kind of repair.)
- Saving an original copy of the vg metadata, for purposes of reverting a write, is now done explicitly in vg_read instead of being hidden in the vg_make_handle function.
- When a vg is not accessible due to "access restrictions" but is otherwise fine, return the vg through the new error_vg arg so that process_each_pv can skip the PVs in the VG while processing. (This is a temporary accomodation for the way process_each_pv tracks which devs have been looked at, and can be dropped later when process_each_pv implementation dev tracking is changed.)
- vg_read does not try to fix or recover a vg, but now just reads the metadata, checks access restrictions and returns it. (Checking access restrictions might be better done outside of vg_read, but this is a later improvement.)
- _vg_read now simply makes one attempt to read metadata from each mda, and uses the most recent copy to return to the caller in the form of a 'vg' struct.
(bad mdas were excluded during the scan and are not retried) (old mdas were not excluded during scan and are retried here)
- vg_read uses _vg_read to get the latest copy of metadata from mdas, and then makes various checks against it to produce warnings, and to check if VG access is allowed (access restrictions include:
writable, foreign, shared, clustered, missing pvs).
- Things that were previously silently/automatically written by vg_read that are now done by vg_write, based on the records made in lvmcache during the scan and read:
. clearing the missing flag
. updating old copies of metadata
. clearing outdated pvs
. updating pv header flags
- Bad/corrupt metadata are now repaired; they were not before.
Test changes
------------
- A read command no longer writes the VG to repair it, so add a write command to do a repair.
(inconsistent-metadata, unlost-pv)
- When a missing PV is removed from a VG, and then the device is enabled again, vgck --updatemetadata is needed to clear the outdated PV before it can be used again, where it wasn't before. (lvconvert-repair-policy, lvconvert-repair-raid, lvconvert-repair, mirror-vgreduce-removemissing, pv-ext-flags, unlost-pv)
Reading bad/old metadata
------------------------
- "bad metadata": the mda_header or metadata text has invalid fields or can't be parsed by lvm. This is a form of corruption that would not be caused by known failure scenarios. A checksum error is typically included among the errors reported.
- "old metadata": a valid copy of the metadata that has a smaller seqno than other copies of the metadata. This can happen if the device failed, or io failed, or lvm failed while commiting new metadata to all the metadata areas. Old metadata on a PV that has been removed from the VG is the "outdated" case below.
When a VG has some PVs with bad/old metadata, lvm can simply ignore the bad/old copies, and use a good copy. This is why there are multiple copies of the metadata -- so it's available even when some of the copies cannot be used. The bad/old copies do not have to be repaired before the VG can be used (the repair can happen later.)
A PV with no good copies of the metadata simply falls back to being treated like a PV with no mdas; a common and harmless configuration.
When bad/old metadata exists, lvm warns the user about it, and suggests repairing it using a new metadata repair command. Bad metadata in particular is something that users will want to investigate and repair themselves, since it should not happen and may indicate some other problem that needs to be fixed.
PVs with bad/old metadata are not the same as missing devices. Missing devices will block various kinds of VG modification or activation, but bad/old metadata will not.
Previously, lvm would attempt to repair bad/old metadata whenever it was read. This was unnecessary since lvm does not require every copy of the metadata to be used. It would also hide potential problems that should be investigated by the user. It was also dangerous in cases where the VG was on shared storage. The user is now allowed to investigate potential problems and decide how and when to repair them.
Repairing bad/old metadata
--------------------------
When label scan sees bad metadata in an mda, that mda is removed from the lvmcache info->mdas list. This means that vg_read will skip it, and not attempt to read/process it again. If it was the only in-use mda on a PV, that PV is treated like a PV with no mdas. It also means that vg_write will also skip the bad mda, and not attempt to write new metadata to it. The only way to repair bad metadata is with the metadata repair command.
When label scan sees old metadata in an mda, that mda is kept in the lvmcache info->mdas list. This means that vg_read will read/process it again, and likely see the same mismatch with the other copies of the metadata. Like the label_scan, the vg_read will simply ignore the old copy of the metadata and use the latest copy. If the command is modifying the vg (e.g. lvcreate), then vg_write, which writes new metadata to every mda on info->mdas, will write the new metadata to the mda that had the old version. If successful, this will resolve the old metadata problem (without needing to run a metadata repair command.)
Outdated PVs
------------
An outdated PV is a PV that has an old copy of VG metadata that shows it is a member of the VG, but the latest copy of the VG metadata does not include this PV. This happens if the PV is disconnected, vgreduce --removemissing is run to remove the PV from the VG, then the PV is reconnected. In this case, the outdated PV needs have its outdated metadata removed and the PV used flag needs to be cleared. This repair will be done by the subsequent repair command. It is also done if vgremove is run on the VG.
MISSING PVs
-----------
When a device is missing, most commands will refuse to modify the VG. This is the simple case. More complicated is when a command is allowed to modify the VG while it is missing a device.
When a VG is written while a device is missing for one of it's PVs, the VG metadata is written to disk with the MISSING flag on the PV with the missing device. When the VG is next used, it is treated as if the PV with the MISSING flag still has a missing device, even if that device has reappeared.
If all LVs that were using a PV with the MISSING flag are removed or repaired so that the MISSING PV is no longer used, then the next time the VG metadata is written, the MISSING flag will be dropped.
Alternative methods of clearing the MISSING flag are:
vgreduce --removemissing will remove PVs with missing devices, or PVs with the MISSING flag where the device has reappeared.
vgextend --restoremissing will clear the MISSING flag on PVs where the device has reappeared, allowing the VG to be used normally. This must be done with caution since the reappeared device may have old data that is inconsistent with data on other PVs.
Bad mda repair
--------------
The new command:
vgck --updatemetadata VG
first uses vg_write to repair old metadata, and other basic issues mentioned above (old metadata, outdated PVs, pv_header flags, MISSING_PV flags). It will also go further and repair bad metadata:
. text metadata that has a bad checksum
. text metadata that is not parsable
. corrupt mda_header checksum and version fields
(To keep a clean diff, #if 0 is added around functions that are replaced by new code. These commented functions are removed by the following commit.)
--- lib/cache/lvmcache.c | 8 + lib/format_text/format-text.c | 7 +- lib/format_text/import.c | 6 +- lib/format_text/text_label.c | 207 +++++++-- lib/label/label.c | 4 - lib/metadata/metadata-exported.h | 30 +- lib/metadata/metadata.c | 628 +++++++++++++++++++++++++- lib/metadata/pv.h | 1 + lib/metadata/vg.c | 6 +- lib/metadata/vg.h | 5 - test/shell/inconsistent-metadata.sh | 49 +-- test/shell/lvconvert-repair-cache.sh | 3 + test/shell/lvconvert-repair-policy.sh | 2 + test/shell/lvconvert-repair-raid.sh | 7 + test/shell/lvconvert-repair.sh | 6 + test/shell/lvmcache-exercise.sh | 10 +- test/shell/mirror-vgreduce-removemissing.sh | 8 + test/shell/pv-ext-flags.sh | 34 +- test/shell/unlost-pv.sh | 52 ++- test/shell/vgck.sh | 4 +- tools/polldaemon.c | 17 +- tools/toollib.c | 73 ++-- tools/vgcfgbackup.c | 8 +- tools/vgextend.c | 19 +- tools/vgsplit.c | 7 +- 25 files changed, 965 insertions(+), 236 deletions(-)
lib/cache/lvmcache.c +8 -0
@@ -2122,6 +2122,14 @@ int lvmcache_fid_add_mdas_pv(struct lvmcache_info *info, struct format_instancereturn lvmcache_fid_add_mdas (info, fid, info->dev->pvid,ID_LEN ); } +/* +* This is the linkage where information is passed from +* the label_scan to vg_read. +* +* Called by create_text_instance in vg_read to copy the +* mda's found during label_scan and saved in info->mdas, +* to fid->metadata_areas_in_use which is used by vg_read. +*/ int lvmcache_fid_add_mdas_vg (struct lvmcache_vginfo *vginfo,struct format_instance *fid) {struct lvmcache_info *info;
lib/format_text/format-text.c +4 -3
@@ -1357,7 +1357,7 @@ int read_metadata_location_summary(const struct format_type *fmt,* valid vg name. */ if (!validate_name (namebuf)) { -log_error ("Metadata location on %s at %llu begins with invalid VG name." , +log_warn ("WARNING: Metadata location on %s at %llu begins with invalid VG name." ,dev_name (dev_area->dev), (unsigned long long )(dev_area->start + rlocn->offset));return 0 ;
@@ -1423,7 +1423,7 @@ int read_metadata_location_summary(const struct format_type *fmt, (off_t) (dev_area->start + MDA_HEADER_SIZE), wrap, calc_crc, vgsummary->vgname ? 1 : 0, vgsummary)) { -log_error ("Metadata location on %s at %llu has invalid summary for VG." , +log_warn ("WARNING: metadata on %s at %llu has invalid summary for VG." ,dev_name (dev_area->dev), (unsigned long long )(dev_area->start + rlocn->offset));return 0 ;
@@ -1431,7 +1431,7 @@ int read_metadata_location_summary(const struct format_type *fmt,/* Ignore this entry if the characters aren't permissible */ if (!validate_name (vgsummary->vgname)) { -log_error ("Metadata location on %s at %llu has invalid VG name." , +log_warn ("WARNING: metadata on %s at %llu has invalid VG name." ,dev_name (dev_area->dev), (unsigned long long )(dev_area->start + rlocn->offset));return 0 ;
@@ -2508,3 +2508,4 @@ int text_wipe_outdated_pv_mda(struct cmd_context *cmd, struct device *dev,return 1 ; } +
lib/format_text/import.c +3 -3
@@ -61,13 +61,13 @@ int text_read_metadata_summary(const struct format_type *fmt, offset2, size2, checksum_fn, vgsummary->mda_checksum, checksum_only, 1)) { -/* FIXME: handle errors */ -log_error ("Couldn't read volume group metadata from %s." ,dev_name (dev)); +log_warn ("WARNING: invalid metadata text from %s at %llu." , +dev_name (dev), (unsigned long long )offset); goto out; } }else {if (!config_file_read (cft)) { -log_error ("Couldn't read volume group metadata from file." ); +log_warn ("WARNING: invalid metadata text from file." ); goto out; } }
lib/format_text/text_label.c +161 -46
286 lines not on this page · raw message
lib/label/label.c +0 -4
@@ -432,9 +432,6 @@ static int _process_block(struct cmd_context *cmd, struct dev_filter *f, ret = labeller->ops->read (labeller, dev, label_buf, sector, &is_duplicate);if (!ret) { -/* FIXME: handle errors */ -lvmcache_del_dev (dev); -if (is_duplicate) {/* * _text_read() called lvmcache_add() which found an
@@ -720,7 +717,6 @@ static int _scan_list(struct cmd_context *cmd, struct dev_filter *f, scan_failed =1 ; scan_process_errors++; scan_failed_count++; -lvmcache_del_dev (devl->dev); } }
lib/metadata/metadata-exported.h +10 -20
@@ -181,15 +181,14 @@#define MIRROR_SKIP_INIT_SYNC 0x00000010U/* skip initial sync */ /* vg_read and vg_read_for_update flags */ -#define READ_ALLOW_INCONSISTENT 0x00010000U#define READ_ALLOW_EXPORTED 0x00020000U#define READ_OK_NOTFOUND 0x00040000U#define READ_WARN_INCONSISTENT 0x00080000U#define READ_FOR_UPDATE 0x00100000U/* A meta-flag, useful with toollib for_each_* functions. */ #define PROCESS_SKIP_SCAN 0x00200000U/* skip lvmcache_label_scan in process_each_pv */ -/* vg's "read_status" field */ -#define FAILED_INCONSISTENT 0x00000001U +/* vg_read returns these in error_flags */ +#define FAILED_NOT_ENABLED 0x00000001U#define FAILED_LOCKING 0x00000002U#define FAILED_NOTFOUND 0x00000004U#define FAILED_READ_ONLY 0x00000008U
@@ -202,6 +201,7 @@#define FAILED_SYSTEMID 0x00000400U#define FAILED_LOCK_TYPE 0x00000800U#define FAILED_LOCK_MODE 0x00001000U +#define FAILED_INTERNAL_ERROR 0x00002000U#define SUCCESS 0x00000000U#define VGMETADATACOPIES_ALL UINT32_MAX
@@ -717,24 +717,14 @@ int lv_resize(struct logical_volume *lv,struct lvresize_params *lp, struct dm_list *pvh); -/* -* Return a handle to VG metadata. -*/ -struct volume_group *vg_read_internal (struct cmd_context *cmd, -const char *vgname,const char *vgid, -uint32_t lockd_state,uint32_t warn_flags, -int enable_repair, -int *mdas_consistent); -struct volume_group *vg_read (struct cmd_context *cmd,const char *vg_name, -const char *vgid,uint32_t read_flags,uint32_t lockd_state); +struct volume_group *vg_read (struct cmd_context *cmd,const char *vg_name,const char *vgid, +uint32_t read_flags,uint32_t lockd_state, +uint32_t *error_flags,struct volume_group **error_vg);struct volume_group *vg_read_for_update (struct cmd_context *cmd,const char *vg_name,const char *vgid,uint32_t read_flags,uint32_t lockd_state); -struct volume_group *vg_read_orphans (struct cmd_context *cmd, -uint32_t warn_flags, -const char *orphan_vgname); -/* -* Test validity of a VG handle. -*/ +struct volume_group *vg_read_orphans (struct cmd_context *cmd,const char *orphan_vgname); + +/* this is historical and being removed, don't use */ uint32_t vg_read_error (struct volume_group *vg_handle);/* pe_start and pe_end relate to any existing data so that new metadata
@@ -757,7 +747,7 @@ uint32_t pv_list_extents_free(const struct dm_list *pvh);int validate_new_vg_name (struct cmd_context *cmd,const char *vg_name);int vg_validate (struct volume_group *vg);struct volume_group *vg_create (struct cmd_context *cmd,const char *vg_name); -struct volume_group *vg_lock_and_create (struct cmd_context *cmd,const char *vg_name); +struct volume_group *vg_lock_and_create (struct cmd_context *cmd,const char *vg_name,int *exists);int vg_remove_mdas (struct volume_group *vg);int vg_remove_check (struct volume_group *vg);void vg_remove_pvs (struct volume_group *vg);
lib/metadata/metadata.c +603 -25
809 lines not on this page · raw message
lib/metadata/pv.h +1 -0
@@ -59,6 +59,7 @@ struct physical_volume {/* This is true whenever the represented PV has a label associated. */ uint64_t is_labelled:1; + uint64_t unused_missing_cleared:1;/* NB. label_sector is valid whenever is_labelled is true */ uint64_t label_sector;
lib/metadata/vg.c +3 -3
@@ -84,7 +84,7 @@ static void _free_vg(struct volume_group *vg)void release_vg (struct volume_group *vg) { -if (!vg || (vg->fid && vg == vg->fid->fmt->orphan_vg)) +if (!vg ||is_orphan_vg (vg->name))return ;release_vg (vg->vg_committed);
@@ -711,9 +711,9 @@ int vgreduce_single(struct cmd_context *cmd, struct volume_group *vg, vg->extent_count -=pv_pe_count (pv);/* FIXME: we don't need to vg_read the orphan vg here */ - orphan_vg =vg_read_orphans (cmd,0 , vg->fid->fmt->orphan_vg_name); + orphan_vg =vg_read_orphans (cmd, vg->fid->fmt->orphan_vg_name); -if (vg_read_error (orphan_vg)) +if (!orphan_vg) goto bad;if (!vg_split_mdas (cmd, vg, orphan_vg) || !vg->pv_count) {
lib/metadata/vg.h +0 -5
@@ -122,11 +122,6 @@ struct volume_group {struct dm_list removed_pvs;uint32_t open_mode;/* FIXME: read or write - check lock type? */ -/* -* Store result of the last vg_read(). -* 0 for success else appropriate FAILURE_* bits set. -*/ -uint32_t read_status;uint32_t mda_copies;/* target number of mdas for this VG */ struct dm_hash_table *hostnames;/* map of creation hostnames */
test/shell/inconsistent-metadata.sh +22 -27
75 lines not on this page · raw message
test/shell/lvconvert-repair-cache.sh +3 -0
@@ -93,6 +93,9 @@ lvconvert --yes --uncache $vg/$lv1 aux enable_dev "$dev2" +# vg was changed while dev was missing +vgextend --restoremissing $vg "$dev2" + # FIXME: temporary workaround lvcreate -L1 -n $lv5 $vg lvremove -ff $vg
test/shell/lvconvert-repair-policy.sh +2 -0
@@ -24,6 +24,8 @@ aux lvmconf 'allocation/maximise_cling = 0' \ cleanup_() { vgreduce --removemissing $vg for d in "$@"; do aux enable_dev "$d"; done + # clear the outdated metadata on enabled devs before we can reuse them + vgck --updatemetadata $vg for d in "$@"; do vgextend $vg "$d"; done lvremove -ff $vg/mirror lvcreate -aey --type mirror -m 1 --ignoremonitoring -l 2 -n mirror $vg "$dev1" "$dev2" "$dev3:0"
test/shell/lvconvert-repair-raid.sh +7 -0
@@ -65,6 +65,7 @@ aux disable_dev "$dev2" lvconvert -y --repair $vg/$lv1 vgreduce --removemissing $vg aux enable_dev "$dev2" +vgck --updatemetadata $vg vgextend $vg "$dev2" lvremove -ff $vg/$lv1
@@ -80,6 +81,7 @@ aux wait_for_sync $vg $lv1 lvconvert -y --repair $vg/$lv1 vgreduce --removemissing $vg aux enable_dev "$dev2" "$dev3" +vgck --updatemetadata $vg vgextend $vg "$dev2" "$dev3" lvremove -ff $vg/$lv1
@@ -96,6 +98,7 @@ aux disable_dev "$dev3" vgreduce --removemissing -f $vg lvconvert -y --repair $vg/$lv1 aux enable_dev "$dev3" +vgck --updatemetadata $vg pvcreate -yff "$dev3" vgextend $vg "$dev3" lvremove -ff $vg/$lv1
@@ -114,6 +117,7 @@ aux wait_for_sync $vg $lv1 lvconvert -y --repair $vg/$lv1 vgreduce --removemissing $vg aux enable_dev "$dev3" +vgck --updatemetadata $vg vgextend $vg "$dev3" lvremove -ff $vg/$lv1
@@ -128,6 +132,7 @@ aux disable_dev "$dev4" "$dev5" lvconvert -y --repair $vg/$lv1 vgreduce --removemissing $vg aux enable_dev "$dev4" "$dev5" +vgck --updatemetadata $vg vgextend $vg "$dev4" "$dev5" lvremove -ff $vg/$lv1
@@ -145,6 +150,7 @@ aux wait_for_sync $vg $lv1 lvconvert -y --repair $vg/$lv1 vgreduce --removemissing $vg aux enable_dev "$dev4" +vgck --updatemetadata $vg vgextend $vg "$dev4" lvremove -ff $vg/$lv1
@@ -163,6 +169,7 @@ aux wait_for_sync $vg $lv1 lvconvert -y --repair $vg/$lv1 vgreduce --removemissing $vg aux enable_dev "$dev4" +vgck --updatemetadata $vg vgextend $vg "$dev4" lvremove -ff $vg/$lv1
test/shell/lvconvert-repair.sh +6 -0
@@ -106,17 +106,23 @@ lvconvert -y --repair $vg/mirror vgreduce --removemissing $vg aux enable_dev "$dev1" +# clear the outdated dev before we can reuse it +vgck --updatemetadata $vg vgextend $vg "$dev1" aux disable_dev "$dev2" lvconvert -y --repair $vg/mirror vgreduce --removemissing $vg aux enable_dev "$dev2" +# clear the outdated dev before we can reuse it +vgck --updatemetadata $vg vgextend $vg "$dev2" aux disable_dev "$dev3" lvconvert -y --repair $vg/mirror vgreduce --removemissing $vg aux enable_dev "$dev3" +# clear the outdated dev before we can reuse it +vgck --updatemetadata $vg vgextend $vg "$dev3" vgremove -ff $vg
test/shell/lvmcache-exercise.sh +6 -4
@@ -43,14 +43,16 @@ pvs "$dev1" lvcreate -aey -m2 --type mirror -l4 --alloc anywhere --corelog -n $lv1 $vg2 aux disable_dev "$dev3" + +pvs 2>&1| tee out +grep "is missing PV" out + lvconvert --yes --repair $vg2/$lv1 -aux enable_dev "$dev3" -# here it should fix any reappeared devices -lvs +aux enable_dev "$dev3" lvs -a $vg2 -o+devices 2>&1 | tee out -not grep reappeared out +not grep "is missing PV" out # This removes the first "vg1" using its uuid vgremove -ff -S vg_uuid=$UUID1
test/shell/mirror-vgreduce-removemissing.sh +8 -0
@@ -123,8 +123,16 @@ check_and_cleanup_lvs_() recover_vg_() { aux enable_dev "$@" + + # clear outdated metadata on PVs so they can be used again + vgck --updatemetadata $vg + + pvscan --cache + pvcreate -ff "$@" + # wipefs -a "$@" vgextend $vg "$@" + check_and_cleanup_lvs_ }
test/shell/pv-ext-flags.sh +10 -24
@@ -39,7 +39,6 @@ check pv_field "$dev2" pv_in_use "used" # disable $dev2 and dev1 with 0 MDAs remains, but still # marked as used, so pvcreate/vgcreate/pvremove should fail aux disable_dev "$dev2" -pvscan --cache check pv_field "$dev1" pv_in_use "used" not pvcreate "$dev1" 2>err
@@ -71,20 +70,14 @@ vgcreate $vg1 "$dev1" "$dev2" # disable $dev1, then repair the VG - $dev1 is removed from VG aux disable_dev "$dev1" vgreduce --removemissing $vg1 -# now, enable $dev1, automatic repair will happen on pvs call -# (or any other lvm command that does vg_read with repair inside) -aux enable_dev "$dev1" -# FIXME: once persistent cache does not cause races with timestamps -# causing LVM tools to not see the VG inconsistency and once -# VG repair is always done, delete this line which removes -# persistent .cache as a workaround -rm -f "$TESTDIR/etc/.cache" +# now, enable $dev1 and clear the old metadata from it +aux enable_dev "$dev1" +vgck --updatemetadata $vg1 vgck $vg1 -# check $dev1 does not contain the PV_EXT_FLAG anymore - it -# should be removed as part of the repaid during vg_read since -# $dev1 is not part of $vg1 anymore + +# check $dev1 does not contain the PV_EXT_FLAG anymore check pv_field "$dev1" pv_in_use "" #############################################
@@ -105,7 +98,6 @@ check pv_field "$dev2" pv_in_use "used" pvchange --metadataignore y "$dev1" aux disable_dev "$dev2" -pvscan --cache check pv_field "$dev1" pv_in_use "used" not pvcreate "$dev1" 2>err
@@ -136,20 +128,14 @@ vgcreate $vg1 "$dev1" "$dev2" # disable $dev1, then repair the VG - $dev1 is removed from VG aux disable_dev "$dev1" vgreduce --removemissing $vg1 -# now, enable $dev1, automatic repair will happen on pvs call -# (or any other lvm command that does vg_read with repair inside) -aux enable_dev "$dev1" -# FIXME: once persistent cache does not cause races with timestamps -# causing LVM tools to not see the VG inconsistency and once -# VG repair is always done, delete this line which removes -# persistent .cache as a workaround -rm -f "$TESTDIR/etc/.cache" +# now, enable $dev1 and clear the old metadata from it +aux enable_dev "$dev1" +vgck --updatemetadata $vg1 vgck $vg1 -# check $dev1 does not contain the PV_EXT_FLAG anymore - it -# should be removed as part of the repaid during vg_read since -# $dev1 is not part of $vg1 anymore + +# check $dev1 does not contain the PV_EXT_FLAG anymore check pv_field "$dev1" pv_in_use "" ###########################
test/shell/unlost-pv.sh +32 -20
79 lines not on this page · raw message
test/shell/vgck.sh +2 -2
@@ -24,11 +24,11 @@ dd if=/dev/urandom bs=512 seek=2 count=32 of="$dev2" vgscan 2>&1 | tee vgscan.out || true -grep "Failed" vgscan.out +grep "checksum" vgscan.out dd if=/dev/urandom bs=512 seek=2 count=32 of="$dev2" vgck $vg 2>&1 | tee vgck.out || true -grep Incorrect vgck.out +grep "checksum" vgck.out vgremove -ff $vg
tools/polldaemon.c +8 -9
@@ -148,6 +148,7 @@ int wait_for_single_lv(struct cmd_context *cmd, struct poll_operation_id *id,struct logical_volume *lv;int finished =0 ;uint32_t lockd_state =0 ; +uint32_t error_flags =0 ;int ret;if (!parms->wait_before_testing)
@@ -168,12 +169,10 @@ int wait_for_single_lv(struct cmd_context *cmd, struct poll_operation_id *id, }/* Locks the (possibly renamed) VG again */ - vg =vg_read (cmd, id->vg_name,NULL ,READ_FOR_UPDATE , lockd_state); -if (vg_read_error (vg)) { + vg =vg_read (cmd, id->vg_name,NULL ,READ_FOR_UPDATE , lockd_state, &error_flags,NULL ); +if (!vg) {/* What more could we do here? */ -log_error ("ABORTING: Can't reread VG for %s." , id->display_name); -release_vg (vg); - vg =NULL ; +log_error ("ABORTING: Can't reread VG for %s error flags %x." , id->display_name, error_flags); ret =0 ; goto out; }
@@ -395,6 +394,7 @@ static int _report_progress(struct cmd_context *cmd, struct poll_operation_id *istruct volume_group *vg;struct logical_volume *lv;uint32_t lockd_state =0 ; +uint32_t error_flags =0 ;int ret;/*
@@ -407,10 +407,9 @@ static int _report_progress(struct cmd_context *cmd, struct poll_operation_id *i* change done locally. */ - vg =vg_read (cmd, id->vg_name,NULL ,0 , lockd_state); -if (vg_read_error (vg)) { -release_vg (vg); -log_error ("Can't reread VG for %s" , id->display_name); + vg =vg_read (cmd, id->vg_name,NULL ,0 , lockd_state, &error_flags,NULL ); +if (!vg) { +log_error ("Can't reread VG for %s error flags %x" , id->display_name, error_flags); ret =0 ; goto out_ret; }
tools/toollib.c +47 -26
192 lines not on this page · raw message
tools/vgcfgbackup.c +1 -7
@@ -67,12 +67,6 @@ static int _vg_backup_single(struct cmd_context *cmd, const char *vg_name,if (!backup_to_file (filename, vg->cmd->cmd_line, vg)) return_ECMD_FAILED; }else { -if (vg_read_error (vg) ==FAILED_INCONSISTENT ) { -log_error ("No backup taken: specify filename with -f " -"to backup an inconsistent VG" ); -return ECMD_FAILED ; - } -if (vg_missing_pv_count (vg)) {log_error ("No backup taken: specify filename with -f to backup with missing PVs." );return ECMD_FAILED ;
@@ -116,7 +110,7 @@ int vgcfgbackup(struct cmd_context *cmd, int argc, char **argv)init_pvmove (1 ); - ret =process_each_vg (cmd, argc, argv,NULL ,NULL ,READ_ALLOW_INCONSISTENT ,0 , + ret =process_each_vg (cmd, argc, argv,NULL ,NULL ,0 ,0 , handle, &_vg_backup_single);free (last_filename);
tools/vgextend.c +14 -5
@@ -28,16 +28,25 @@ static int _restore_pv(struct volume_group *vg, const char *pv_name)return 0 ; } -if (!(pvl->pv->status &MISSING_PV )) { -log_warn ("WARNING: PV %s was not missing in VG %s" , pv_name, vg->name); -return 0 ; - } -if (!pvl->pv->dev) {log_warn ("WARNING: The PV %s is still missing." , pv_name);return 0 ; } +if (pvl->pv->status &MISSING_PV ) + goto clear_flag; + +/* +* when the PV has no used PE's vg_read clears the MISSING_PV flag +* and sets this so we know. +*/ +if (pvl->pv->unused_missing_cleared) + goto clear_flag; + +log_warn ("WARNING: PV %s was not missing in VG %s" , pv_name, vg->name); +return 0 ; + +clear_flag: pvl->pv->status &= ~MISSING_PV ;return 1 ; }
tools/vgsplit.c +4 -3
@@ -456,6 +456,7 @@ static struct volume_group *_vgsplit_to(struct cmd_context *cmd, int *existing_vg) {struct volume_group *vg_to =NULL ; +int exists =0 ;log_verbose ("Checking for new volume group \"%s\"" , vg_name_to);/*
@@ -468,13 +469,13 @@ static struct volume_group *_vgsplit_to(struct cmd_context *cmd,* we obtained a WRITE lock and could not find the vgname in the * system. Thus, the split will be into a new VG. */ - vg_to =vg_lock_and_create (cmd, vg_name_to); -if (vg_read_error (vg_to) ==FAILED_LOCKING ) { + vg_to =vg_lock_and_create (cmd, vg_name_to, &exists); +if (!vg_to && !exists) {log_error ("Can't get lock for %s" , vg_name_to);release_vg (vg_to);return NULL ; } -if (vg_read_error (vg_to) ==FAILED_EXIST ) { +if (!vg_to && exists) { *existing_vg =1 ;release_vg (vg_to); vg_to =vg_read_for_update (cmd, vg_name_to,NULL ,0 ,0 );