master - tests: vgck now exits with error for bad vg
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a01a8d71723740577e5...
Commit: a01a8d71723740577e5fe9635412940d941b5da9
Parent: a9b0aa5c178a6d8bb708ed35f833c648f7437ae3
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Mar 9 13:18:38 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:22:48 2018 -0500
tests: vgck now exits with error for bad vg
---
test/shell/vgck.sh | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/test/shell/vgck.sh b/test/shell/vgck.sh
index 2f3fba4..186704c 100644
--- a/test/shell/vgck.sh
+++ b/test/shell/vgck.sh
@@ -22,18 +22,18 @@ dd if=/dev/urandom bs=512 seek=2 count=32 of="$dev2"
# TODO: aux lvmconf "global/locking_type = 4"
-vgscan 2>&1 | tee vgscan.out
+vgscan 2>&1 | tee vgscan.out || true
if test -e LOCAL_LVMETAD; then
- not grep "Inconsistent metadata found for VG $vg" vgscan.out
+ not grep "Failed" vgscan.out
else
- grep "Inconsistent metadata found for VG $vg" vgscan.out
+ grep "Failed" vgscan.out
fi
dd if=/dev/urandom bs=512 seek=2 count=32 of="$dev2"
aux notify_lvmetad "$dev2"
-vgck $vg 2>&1 | tee vgck.out
+vgck $vg 2>&1 | tee vgck.out || true
grep Incorrect vgck.out
vgremove -ff $vg
6 years
master - lvmetad: more fixes related to bcache
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a9b0aa5c178a6d8bb70...
Commit: a9b0aa5c178a6d8bb708ed35f833c648f7437ae3
Parent: e351f8bc66d49fecaa0ab78f8413d50a4674604a
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Mar 9 11:39:12 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:22:48 2018 -0500
lvmetad: more fixes related to bcache
Need to open devs prior to bcache io.
---
lib/label/label.c | 25 +++++++++++++++++--------
lib/metadata/metadata.c | 12 ++++++++++++
2 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/lib/label/label.c b/lib/label/label.c
index 9401067..14a7e90 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -515,7 +515,7 @@ static int _scan_list(struct dm_list *devs, int *failed)
bb = NULL;
if (!bcache_get(scan_bcache, devl->dev->bcache_fd, 0, 0, &bb)) {
- log_error("Scan failed to read %s.", dev_name(devl->dev));
+ log_debug_devs("Scan failed to read %s.", dev_name(devl->dev));
scan_failed_count++;
scan_failed = 1;
lvmcache_del_dev(devl->dev);
@@ -525,7 +525,7 @@ static int _scan_list(struct dm_list *devs, int *failed)
ret = _process_block(devl->dev, bb, &is_lvm_device);
if (!ret && is_lvm_device) {
- log_error("Scan failed to process %s", dev_name(devl->dev));
+ log_debug_devs("Scan failed to process %s", dev_name(devl->dev));
scan_failed_count++;
scan_failed = 1;
lvmcache_del_dev(devl->dev);
@@ -893,8 +893,11 @@ bool dev_read_bytes(struct device *dev, off_t start, size_t len, void *data)
}
if (dev->bcache_fd <= 0) {
- log_error("dev_read_bytes %s with invalid fd %d", dev_name(dev), dev->bcache_fd);
- return false;
+ /* This is not often needed, perhaps only with lvmetad. */
+ if (!label_scan_open(dev)) {
+ log_error("dev_read_bytes %s cannot open dev", dev_name(dev));
+ return false;
+ }
}
if (!bcache_read_bytes(scan_bcache, dev->bcache_fd, start, len, data)) {
@@ -924,8 +927,11 @@ bool dev_write_bytes(struct device *dev, off_t start, size_t len, void *data)
}
if (dev->bcache_fd <= 0) {
- log_error("dev_write_bytes %s with invalid fd %d", dev_name(dev), dev->bcache_fd);
- return false;
+ /* This is not often needed, perhaps only with lvmetad. */
+ if (!label_scan_open(dev)) {
+ log_error("dev_write_bytes %s cannot open dev", dev_name(dev));
+ return false;
+ }
}
if (!bcache_write_bytes(scan_bcache, dev->bcache_fd, start, len, data)) {
@@ -954,8 +960,11 @@ bool dev_write_zeros(struct device *dev, off_t start, size_t len)
}
if (dev->bcache_fd <= 0) {
- log_error("dev_write_zeros %s with invalid fd %d", dev_name(dev), dev->bcache_fd);
- return false;
+ /* This is not often needed, perhaps only with lvmetad. */
+ if (!label_scan_open(dev)) {
+ log_error("dev_write_zeros %s cannot open dev", dev_name(dev));
+ return false;
+ }
}
if (!bcache_write_zeros(scan_bcache, dev->bcache_fd, start, len)) {
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 462c391..8cb06be 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -3809,6 +3809,18 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
release_vg(correct_vg);
return_NULL;
}
+
+ /*
+ * When a command reads the vg from lvmetad, and then
+ * writes the vg, the write path does some disk reads
+ * of the devs.
+ * FIXME: when a command is going to write the vg,
+ * we should just read the vg from disk entirely
+ * and skip reading it from lvmetad.
+ */
+ dm_list_iterate_items(pvl, &correct_vg->pvs)
+ label_scan_open(pvl->pv->dev);
+
}
return correct_vg;
6 years
master - lvmetad: need to set up bcache in another place
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e351f8bc66d49fecaa0...
Commit: e351f8bc66d49fecaa0ab78f8413d50a4674604a
Parent: 7e33bd1335ba91d6b978df3a39250987d3412116
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Mar 6 15:05:27 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:22:48 2018 -0500
lvmetad: need to set up bcache in another place
We need to find one common place to set up bcache
for the lvmetad case, instead of adding calls in
various places.
---
lib/label/label.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/lib/label/label.c b/lib/label/label.c
index 82d4bf3..9401067 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -675,6 +675,13 @@ int label_scan_devs(struct cmd_context *cmd, struct dm_list *devs)
{
struct device_list *devl;
+ /* FIXME: get rid of this, it's only needed for lvmetad in which
+ case we should be setting up bcache in one place. */
+ if (!scan_bcache) {
+ if (!_setup_bcache(0))
+ return 0;
+ }
+
dm_list_iterate_items(devl, devs) {
if (_in_bcache(devl->dev)) {
bcache_invalidate_fd(scan_bcache, devl->dev->bcache_fd);
6 years
master - clvm: fix bcache scan handling
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ddb5de7a98af5e35401...
Commit: ddb5de7a98af5e354013a07c61e46636b9ec01e6
Parent: 196579af1f7ebe25c0266043c7d966b344699d5d
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Mar 1 12:43:29 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:22:48 2018 -0500
clvm: fix bcache scan handling
We can't let clvmd keep all scanned devs open,
which prevents them from being removed. So
drop the bcache data (and close fds) affter
doing a label scan.
Also set up bcache before the clvm-specific
vg_read (which needs to rescan the vg's devs
using bcache) and destroy the bcache after.
---
daemons/clvmd/lvm-functions.c | 1 +
lib/metadata/metadata.c | 5 +++++
2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/daemons/clvmd/lvm-functions.c b/daemons/clvmd/lvm-functions.c
index c845e6d..64bdab3 100644
--- a/daemons/clvmd/lvm-functions.c
+++ b/daemons/clvmd/lvm-functions.c
@@ -665,6 +665,7 @@ int do_refresh_cache(void)
init_ignore_suspended_devices(1);
lvmcache_force_next_label_scan();
lvmcache_label_scan(cmd);
+ label_scan_destroy(cmd); /* destroys bcache (to close devs), keeps lvmcache */
dm_pool_empty(cmd->mem);
pthread_mutex_unlock(&lvm_lock);
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index b442451..462c391 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -4530,11 +4530,16 @@ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd,
consistent = 0;
+ label_scan_setup_bcache();
+
if ((vg = _vg_read(cmd, vgname, vgid, warn_flags, &consistent, precommitted))) {
/* Does it matter if consistent is 0 or 1? */
+ label_scan_destroy(cmd);
return vg;
}
+ label_scan_destroy(cmd);
+
log_debug_metadata("Reading VG by vgid %.8s not found.", vgid);
return NULL;
}
6 years
master - lvmetad: fix process_each_label
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=7e33bd1335ba91d6b97...
Commit: 7e33bd1335ba91d6b978df3a39250987d3412116
Parent: ddb5de7a98af5e354013a07c61e46636b9ec01e6
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Mar 6 11:22:18 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:22:48 2018 -0500
lvmetad: fix process_each_label
Was missing the call to populate lvmcache info from lvmetad
at the start of process_each_label.
---
tools/toollib.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index b029a0d..c8dd9d3 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1505,6 +1505,7 @@ int process_each_label(struct cmd_context *cmd, int argc, char **argv,
log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_LABEL);
lvmcache_label_scan(cmd);
+ lvmcache_seed_infos_from_lvmetad(cmd);
if (argc) {
for (; opt < argc; opt++) {
6 years
master - scan: remove lvmcache info for failed devs
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=44726ed9cb955980186...
Commit: 44726ed9cb9559801868ade5440d9e6ea6a61127
Parent: 1717d4cb178b88dc70bc14a11aba199b34931bb0
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Mar 1 12:40:37 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:22:47 2018 -0500
scan: remove lvmcache info for failed devs
When scanning a device fails, drop an lvmcache
info struct for it.
---
lib/label/label.c | 37 +++++++++++++++++++++++++------------
1 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/lib/label/label.c b/lib/label/label.c
index dd455ec..82d4bf3 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -333,7 +333,6 @@ static int _process_block(struct device *dev, struct block *bb, int *is_lvm_devi
char label_buf[LABEL_SIZE] __attribute__((aligned(8)));
struct label *label = NULL;
struct labeller *labeller;
- struct lvmcache_info *info;
uint64_t sector;
int ret = 0;
@@ -356,11 +355,7 @@ static int _process_block(struct device *dev, struct block *bb, int *is_lvm_devi
log_very_verbose("%s: No lvm label detected", dev_name(dev));
- if ((info = lvmcache_info_from_pvid(dev->pvid, dev, 0))) {
- /* FIXME: if this case is actually happening, fix it. */
- log_warn("Device %s has no label, removing PV info from lvmcache.", dev_name(dev));
- lvmcache_del(info);
- }
+ lvmcache_del_dev(dev); /* FIXME: if this is needed, fix it. */
*is_lvm_device = 0;
goto_out;
@@ -380,6 +375,7 @@ static int _process_block(struct device *dev, struct block *bb, int *is_lvm_devi
label->sector = sector;
} else {
/* FIXME: handle errors */
+ lvmcache_del_dev(dev);
}
out:
return ret;
@@ -475,6 +471,7 @@ static int _scan_list(struct dm_list *devs, int *failed)
int rem_prefetches;
int scan_failed;
int is_lvm_device;
+ int ret;
dm_list_init(&wait_devs);
dm_list_init(&done_devs);
@@ -498,7 +495,7 @@ static int _scan_list(struct dm_list *devs, int *failed)
if (!_in_bcache(devl->dev)) {
if (!_scan_dev_open(devl->dev)) {
- log_debug_devs("%s: Failed to open device.", dev_name(devl->dev));
+ log_debug_devs("Scan failed to open %s.", dev_name(devl->dev));
dm_list_del(&devl->list);
dm_list_add(&done_devs, &devl->list);
scan_failed_count++;
@@ -518,14 +515,24 @@ static int _scan_list(struct dm_list *devs, int *failed)
bb = NULL;
if (!bcache_get(scan_bcache, devl->dev->bcache_fd, 0, 0, &bb)) {
- log_debug_devs("%s: Failed to scan device.", dev_name(devl->dev));
+ log_error("Scan failed to read %s.", dev_name(devl->dev));
scan_failed_count++;
scan_failed = 1;
+ lvmcache_del_dev(devl->dev);
} else {
log_debug_devs("Processing data from device %s fd %d block %p", dev_name(devl->dev), devl->dev->bcache_fd, bb);
- _process_block(devl->dev, bb, &is_lvm_device);
- scan_lvm_count++;
- scan_failed = 0;
+
+ ret = _process_block(devl->dev, bb, &is_lvm_device);
+
+ if (!ret && is_lvm_device) {
+ log_error("Scan failed to process %s", dev_name(devl->dev));
+ scan_failed_count++;
+ scan_failed = 1;
+ lvmcache_del_dev(devl->dev);
+ } else {
+ scan_lvm_count++;
+ scan_failed = 0;
+ }
}
if (bb)
@@ -884,6 +891,8 @@ bool dev_read_bytes(struct device *dev, off_t start, size_t len, void *data)
}
if (!bcache_read_bytes(scan_bcache, dev->bcache_fd, start, len, data)) {
+ log_error("dev_read_bytes %s at %u failed invalidate fd %d",
+ dev_name(dev), (uint32_t)start, dev->bcache_fd);
label_scan_invalidate(dev);
return false;
}
@@ -913,6 +922,8 @@ bool dev_write_bytes(struct device *dev, off_t start, size_t len, void *data)
}
if (!bcache_write_bytes(scan_bcache, dev->bcache_fd, start, len, data)) {
+ log_error("dev_write_bytes %s at %u failed invalidate fd %d",
+ dev_name(dev), (uint32_t)start, dev->bcache_fd);
label_scan_invalidate(dev);
return false;
}
@@ -936,11 +947,13 @@ bool dev_write_zeros(struct device *dev, off_t start, size_t len)
}
if (dev->bcache_fd <= 0) {
- log_error("dev_write_bytes %s with invalid fd %d", dev_name(dev), dev->bcache_fd);
+ log_error("dev_write_zeros %s with invalid fd %d", dev_name(dev), dev->bcache_fd);
return false;
}
if (!bcache_write_zeros(scan_bcache, dev->bcache_fd, start, len)) {
+ log_error("dev_write_zeros %s at %u failed invalidate fd %d",
+ dev_name(dev), (uint32_t)start, dev->bcache_fd);
label_scan_invalidate(dev);
return false;
}
6 years
master - scan: check for errors in text layer
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=196579af1f7ebe25c02...
Commit: 196579af1f7ebe25c0266043c7d966b344699d5d
Parent: 44726ed9cb9559801868ade5440d9e6ea6a61127
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Mar 1 12:42:18 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:22:47 2018 -0500
scan: check for errors in text layer
The scanning code in the format_text layer
has previously ignored errors. Start checking
for and returning them.
---
lib/format_text/format-text.c | 5 ++++-
lib/format_text/text_label.c | 38 ++++++++++++++++++++++----------------
2 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index 4a9c303..4146e7c 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -536,8 +536,10 @@ static struct volume_group *_vg_read_raw_area(struct format_instance *fid,
char *desc;
uint32_t wrap = 0;
- if (!(mdah = raw_read_mda_header(fid->fmt, area, primary_mda)))
+ if (!(mdah = raw_read_mda_header(fid->fmt, area, primary_mda))) {
+ log_error("Failed to read vg %s from %s", vgname, dev_name(area->dev));
goto_out;
+ }
if (!(rlocn = _read_metadata_location_vg(area, mdah, primary_mda, vgname, &precommitted))) {
log_debug_metadata("VG %s not found on %s", vgname, dev_name(area->dev));
@@ -1213,6 +1215,7 @@ int read_metadata_location_summary(const struct format_type *fmt,
log_debug_metadata("Metadata location on %s at %llu has offset 0.",
dev_name(dev_area->dev),
(unsigned long long)(dev_area->start + rlocn->offset));
+ vgsummary->zero_offset = 1;
return 0;
}
diff --git a/lib/format_text/text_label.c b/lib/format_text/text_label.c
index 206ae3f..e65079e 100644
--- a/lib/format_text/text_label.c
+++ b/lib/format_text/text_label.c
@@ -331,16 +331,9 @@ static int _read_mda_header_and_metadata(struct metadata_area *mda, void *baton)
struct mda_header *mdah;
struct lvmcache_vgsummary vgsummary = { 0 };
- /*
- * Using the labeller struct to preserve info about
- * the last parsed vgname, vgid, creation host
- *
- * TODO: make lvmcache smarter and move this cache logic there
- */
-
if (!(mdah = raw_read_mda_header(fmt, &mdac->area, mda_is_primary(mda)))) {
- stack;
- goto close_dev;
+ log_error("Failed to read mda header from %s", dev_name(mdac->area.dev));
+ goto fail;
}
mda_set_ignored(mda, rlocn_is_ignored(mdah->raw_locns));
@@ -352,14 +345,25 @@ static int _read_mda_header_and_metadata(struct metadata_area *mda, void *baton)
return 1;
}
- if (read_metadata_location_summary(fmt, mdah, mda_is_primary(mda), &mdac->area, &vgsummary,
- &mdac->free_sectors) &&
- !lvmcache_update_vgname_and_id(p->info, &vgsummary)) {
- return_0;
+ if (!read_metadata_location_summary(fmt, mdah, mda_is_primary(mda), &mdac->area,
+ &vgsummary, &mdac->free_sectors)) {
+ if (vgsummary.zero_offset)
+ return 1;
+
+ log_error("Failed to read metadata summary from %s", dev_name(mdac->area.dev));
+ goto fail;
+ }
+
+ if (!lvmcache_update_vgname_and_id(p->info, &vgsummary)) {
+ log_error("Failed to save lvm summary for %s", dev_name(mdac->area.dev));
+ goto fail;
}
-close_dev:
return 1;
+
+fail:
+ lvmcache_del(p->info);
+ return 0;
}
static int _text_read(struct labeller *l, struct device *dev, void *label_buf,
@@ -434,10 +438,12 @@ out:
baton.info = info;
baton.label = *label;
- lvmcache_foreach_mda(info, _read_mda_header_and_metadata, &baton);
+ if (!lvmcache_foreach_mda(info, _read_mda_header_and_metadata, &baton)) {
+ log_error("Failed to scan VG from %s", dev_name(dev));
+ return 0;
+ }
lvmcache_make_valid(info);
-
return 1;
}
6 years
master - lvmcache: add shorter way to delete dev info
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=1717d4cb178b88dc70b...
Commit: 1717d4cb178b88dc70bc14a11aba199b34931bb0
Parent: 570c6239eebf18e6884d350654274d3bc8f1c4f1
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Mar 1 10:20:34 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:22:47 2018 -0500
lvmcache: add shorter way to delete dev info
Don't make the caller look up the info first.
---
lib/cache/lvmcache.c | 8 ++++++++
lib/cache/lvmcache.h | 2 ++
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index 53254f4..6479080 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -1608,6 +1608,14 @@ void lvmcache_del(struct lvmcache_info *info)
dm_free(info);
}
+void lvmcache_del_dev(struct device *dev)
+{
+ struct lvmcache_info *info;
+
+ if ((info = lvmcache_info_from_pvid((const char *)dev->pvid, dev, 0)))
+ lvmcache_del(info);
+}
+
/*
* vginfo must be info->vginfo unless info is NULL (orphans)
*/
diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h
index 3967b29..4343060 100644
--- a/lib/cache/lvmcache.h
+++ b/lib/cache/lvmcache.h
@@ -59,6 +59,7 @@ struct lvmcache_vgsummary {
const char *lock_type;
uint32_t mda_checksum;
size_t mda_size;
+ int zero_offset;
};
int lvmcache_init(void);
@@ -83,6 +84,7 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
uint32_t vgstatus);
int lvmcache_add_orphan_vginfo(const char *vgname, struct format_type *fmt);
void lvmcache_del(struct lvmcache_info *info);
+void lvmcache_del_dev(struct device *dev);
/* Update things */
int lvmcache_update_vgname_and_id(struct lvmcache_info *info,
6 years
master - bcache: fix error handling
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=570c6239eebf18e6884...
Commit: 570c6239eebf18e6884d350654274d3bc8f1c4f1
Parent: 217f3f8741c1f516ab1f039b8725ac3ce638e302
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Mar 1 10:17:32 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:22:47 2018 -0500
bcache: fix error handling
The error handling code wasn't working, but it
appears that just removing it is what we need.
The doesn't really need any different behavior
related to bcache blocks on an io error, it just
wants to know if there was an error.
---
lib/device/bcache.c | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
index 94623a8..9034776 100644
--- a/lib/device/bcache.c
+++ b/lib/device/bcache.c
@@ -539,6 +539,14 @@ static void _complete_io(void *context, int err)
dm_list_del(&b->list);
if (b->error) {
+ log_warn("bcache io error %d fd %d", b->error, b->fd);
+ memset(b->data, 0, cache->block_sectors << SECTOR_SHIFT);
+ }
+
+ /* Things don't work with this block of code, but work without it. */
+#if 0
+ if (b->error) {
+ log_warn("bcache io error %d fd %d", b->error, b->fd);
if (b->io_dir == DIR_READ) {
// We can just forget about this block, since there's
// no dirty data to be written back.
@@ -552,6 +560,9 @@ static void _complete_io(void *context, int err)
_clear_flags(b, BF_DIRTY);
_link_block(b);
}
+#endif
+ _clear_flags(b, BF_DIRTY);
+ _link_block(b);
}
/*
@@ -768,7 +779,7 @@ static struct block *_lookup_or_read_block(struct bcache *cache,
}
}
- if (b && !b->error) {
+ if (b) {
if (flags & (GF_DIRTY | GF_ZERO))
_set_flags(b, BF_DIRTY);
@@ -904,6 +915,9 @@ bool bcache_get(struct bcache *cache, int fd, block_address index,
b->ref_count++;
*result = b;
+
+ if (b->error)
+ return false;
return true;
}
6 years
master - scan: add function to drop bcache blocks
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=217f3f8741c1f516ab1...
Commit: 217f3f8741c1f516ab1f039b8725ac3ce638e302
Parent: da2b155a9da4c4c9caf502b87ad263de6e678b30
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Feb 27 16:35:47 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:22:47 2018 -0500
scan: add function to drop bcache blocks
which can be a little more efficient that destroy.
---
lib/label/label.c | 24 ++++++++++++++++--------
lib/label/label.h | 1 +
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/lib/label/label.c b/lib/label/label.c
index 0514ddf..dd455ec 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -733,20 +733,15 @@ void label_scan_invalidate_lv(struct cmd_context *cmd, struct logical_volume *lv
}
/*
- * Undo label_scan()
- *
- * Close devices that are open because bcache is holding blocks for them.
- * Destroy the bcache.
+ * Empty the bcache of all blocks and close all open fds,
+ * but keep the bcache set up.
*/
-void label_scan_destroy(struct cmd_context *cmd)
+void label_scan_drop(struct cmd_context *cmd)
{
struct dev_iter *iter;
struct device *dev;
- if (!scan_bcache)
- return;
-
if (!(iter = dev_iter_create(cmd->full_filter, 0))) {
return;
}
@@ -756,6 +751,19 @@ void label_scan_destroy(struct cmd_context *cmd)
_scan_dev_close(dev);
}
dev_iter_destroy(iter);
+}
+
+/*
+ * Close devices that are open because bcache is holding blocks for them.
+ * Destroy the bcache.
+ */
+
+void label_scan_destroy(struct cmd_context *cmd)
+{
+ if (!scan_bcache)
+ return;
+
+ label_scan_drop(cmd);
bcache_destroy(scan_bcache);
scan_bcache = NULL;
diff --git a/lib/label/label.h b/lib/label/label.h
index 8ef687b..55e92e8 100644
--- a/lib/label/label.h
+++ b/lib/label/label.h
@@ -107,6 +107,7 @@ int label_scan_devs(struct cmd_context *cmd, struct dm_list *devs);
int label_scan_devs_excl(struct dm_list *devs);
void label_scan_invalidate(struct device *dev);
void label_scan_invalidate_lv(struct cmd_context *cmd, struct logical_volume *lv);
+void label_scan_drop(struct cmd_context *cmd);
void label_scan_destroy(struct cmd_context *cmd);
int label_read(struct device *dev, struct label **labelp, uint64_t unused_sector);
int label_read_sector(struct device *dev, struct label **labelp, uint64_t scan_sector);
6 years