b74c0695d2
LVM Metadata Error: Error writing device at 4096 length 512 (bsc#1150021) + bug-1150021_01-scanning-open-devs-rw-when-rescanning-for-write.patch + bug-1150021_02-bcache-add-bcache_abort.patch + bug-1150021_03-label-Use-bcache_abort_fd-to-ensure-blocks-are-no-lo.patch + bug-1150021_04-bcache-add-unit-test.patch + bug-1150021_05-bcache-bcache_invalidate_fd-only-remove-prefixes-on.patch + bug-1150021_06-fix-dev_unset_last_byte-after-write-error.patch - Update patch, according to bug-1150021_01-scanning-xxx.patch + bug-1158861_06-fix-segfault-for-invalid-characters-in-vg-name.patch OBS-URL: https://build.opensuse.org/request/show/759060 OBS-URL: https://build.opensuse.org/package/show/Base:System/lvm2?expand=0&rev=263
122 lines
4.6 KiB
Diff
122 lines
4.6 KiB
Diff
From 13c254fc05386d05ab6bbda2806f9ca4d3358a0c Mon Sep 17 00:00:00 2001
|
|
From: Heming Zhao <heming.zhao@suse.com>
|
|
Date: Wed, 13 Nov 2019 09:15:07 -0600
|
|
Subject: [PATCH] fix dev_unset_last_byte after write error
|
|
|
|
dev_unset_last_byte() must be called while the fd is still valid.
|
|
After a write error, dev_unset_last_byte() must be called before
|
|
closing the dev and resetting the fd.
|
|
|
|
In the write error path, dev_unset_last_byte() was being called
|
|
after label_scan_invalidate() which meant that it would not unset
|
|
the last_byte values.
|
|
|
|
After a write error, dev_unset_last_byte() is now called in
|
|
dev_write_bytes() before label_scan_invalidate(), instead of by
|
|
the caller of dev_write_bytes().
|
|
|
|
In the common case of a successful write, the sequence is still:
|
|
dev_set_last_byte(); dev_write_bytes(); dev_unset_last_byte();
|
|
|
|
Signed-off-by: Zhao Heming <heming.zhao@suse.com>
|
|
---
|
|
lib/format_text/format-text.c | 3 ---
|
|
lib/label/label.c | 8 ++++----
|
|
lib/metadata/mirror.c | 1 -
|
|
3 files changed, 4 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
|
|
index 6ec47bfcef..894a71007d 100644
|
|
--- a/lib/format_text/format-text.c
|
|
+++ b/lib/format_text/format-text.c
|
|
@@ -277,7 +277,6 @@ static int _raw_write_mda_header(const struct format_type *fmt,
|
|
dev_set_last_byte(dev, start_byte + MDA_HEADER_SIZE);
|
|
|
|
if (!dev_write_bytes(dev, start_byte, MDA_HEADER_SIZE, mdah)) {
|
|
- dev_unset_last_byte(dev);
|
|
log_error("Failed to write mda header to %s fd %d", dev_name(dev), dev->bcache_fd);
|
|
return 0;
|
|
}
|
|
@@ -769,7 +768,6 @@ static int _vg_write_raw(struct format_i
|
|
if (!dev_write_bytes(mdac->area.dev, mdac->area.start + rlocn_new->offset,
|
|
(size_t) (rlocn_new->size - new_wrap), new_buf)) {
|
|
log_error("Failed to write metadata to %s fd %d", dev_name(mdac->area.dev), mdac->area.dev->bcache_fd);
|
|
- dev_unset_last_byte(mdac->area.dev);
|
|
goto out;
|
|
}
|
|
|
|
@@ -782,7 +780,6 @@ static int _vg_write_raw(struct format_i
|
|
if (!dev_write_bytes(mdac->area.dev, mdac->area.start + MDA_HEADER_SIZE,
|
|
(size_t) new_wrap, new_buf + rlocn_new->size - new_wrap)) {
|
|
log_error("Failed to write metadata wrap to %s fd %d", dev_name(mdac->area.dev), mdac->area.dev->bcache_fd);
|
|
- dev_unset_last_byte(mdac->area.dev);
|
|
goto out;
|
|
}
|
|
}
|
|
diff --git a/lib/label/label.c b/lib/label/label.c
|
|
index 7dcaf8afd5..05986cbe70 100644
|
|
--- a/lib/label/label.c
|
|
+++ b/lib/label/label.c
|
|
@@ -218,7 +218,7 @@ int label_write(struct device *dev, struct label *label)
|
|
|
|
if (!dev_write_bytes(dev, offset, LABEL_SIZE, buf)) {
|
|
log_debug_devs("Failed to write label to %s", dev_name(dev));
|
|
- r = 0;
|
|
+ return 0;
|
|
}
|
|
|
|
dev_unset_last_byte(dev);
|
|
@@ -655,7 +655,6 @@ static int _scan_list(struct cmd_context *cmd, struct dev_filter *f,
|
|
int submit_count;
|
|
int scan_failed;
|
|
int is_lvm_device;
|
|
- int error;
|
|
int ret;
|
|
|
|
dm_list_init(&wait_devs);
|
|
@@ -702,12 +701,11 @@ static int _scan_list(struct cmd_context *cmd, struct dev_filter *f,
|
|
|
|
dm_list_iterate_items_safe(devl, devl2, &wait_devs) {
|
|
bb = NULL;
|
|
- error = 0;
|
|
scan_failed = 0;
|
|
is_lvm_device = 0;
|
|
|
|
if (!bcache_get(scan_bcache, devl->dev->bcache_fd, 0, 0, &bb)) {
|
|
- log_debug_devs("Scan failed to read %s error %d.", dev_name(devl->dev), error);
|
|
+ log_debug_devs("Scan failed to read %s.", dev_name(devl->dev));
|
|
scan_failed = 1;
|
|
scan_read_errors++;
|
|
scan_failed_count++;
|
|
@@ -1451,6 +1449,7 @@ bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data)
|
|
if (!bcache_write_bytes(scan_bcache, dev->bcache_fd, start, len, data)) {
|
|
log_error("Error writing device %s at %llu length %u.",
|
|
dev_name(dev), (unsigned long long)start, (uint32_t)len);
|
|
+ dev_unset_last_byte(dev);
|
|
label_scan_invalidate(dev);
|
|
return false;
|
|
}
|
|
@@ -1458,6 +1457,7 @@ bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data)
|
|
if (!bcache_flush(scan_bcache)) {
|
|
log_error("Error writing device %s at %llu length %u.",
|
|
dev_name(dev), (unsigned long long)start, (uint32_t)len);
|
|
+ dev_unset_last_byte(dev);
|
|
label_scan_invalidate(dev);
|
|
return false;
|
|
}
|
|
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
|
|
index 01f0246b90..d8803b3e3f 100644
|
|
--- a/lib/metadata/mirror.c
|
|
+++ b/lib/metadata/mirror.c
|
|
@@ -266,7 +266,6 @@ static int _write_log_header(struct cmd_context *cmd, struct logical_volume *lv)
|
|
dev_set_last_byte(dev, sizeof(log_header));
|
|
|
|
if (!dev_write_bytes(dev, UINT64_C(0), sizeof(log_header), &log_header)) {
|
|
- dev_unset_last_byte(dev);
|
|
log_error("Failed to write log header to %s.", name);
|
|
return 0;
|
|
}
|
|
--
|
|
2.16.4
|
|
|