master - [makefile] add -laio to makefiles
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=697fa7aa1dbcc2ed8e1...
Commit: 697fa7aa1dbcc2ed8e141d9d13118cb38d609161
Parent: 93fc9374294aae679faa23aef0bd631db2e9a31a
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Feb 8 09:32:19 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:13:17 2018 -0500
[makefile] add -laio to makefiles
---
daemons/clvmd/Makefile.in | 2 +-
liblvm/Makefile.in | 2 +-
scripts/Makefile.in | 2 +-
tools/Makefile.in | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/daemons/clvmd/Makefile.in b/daemons/clvmd/Makefile.in
index 7b1b49b..83af00e 100644
--- a/daemons/clvmd/Makefile.in
+++ b/daemons/clvmd/Makefile.in
@@ -74,7 +74,7 @@ TARGETS = \
include $(top_builddir)/make.tmpl
-LIBS += $(LVMINTERNAL_LIBS) -ldevmapper $(PTHREAD_LIBS)
+LIBS += $(LVMINTERNAL_LIBS) -ldevmapper $(PTHREAD_LIBS) -laio
CFLAGS += -fno-strict-aliasing $(EXTRA_EXEC_CFLAGS)
INSTALL_TARGETS = \
diff --git a/liblvm/Makefile.in b/liblvm/Makefile.in
index 6d0325c..be3049a 100644
--- a/liblvm/Makefile.in
+++ b/liblvm/Makefile.in
@@ -43,7 +43,7 @@ LDDEPS += $(top_builddir)/lib/liblvm-internal.a
include $(top_builddir)/make.tmpl
LDFLAGS += -L$(top_builddir)/lib -L$(top_builddir)/daemons/dmeventd
-LIBS += $(LVMINTERNAL_LIBS) -ldevmapper
+LIBS += $(LVMINTERNAL_LIBS) -ldevmapper -laio
.PHONY: install_dynamic install_static install_include install_pkgconfig
diff --git a/scripts/Makefile.in b/scripts/Makefile.in
index d06766f..720ae9f 100644
--- a/scripts/Makefile.in
+++ b/scripts/Makefile.in
@@ -28,7 +28,7 @@ ifeq ("@APPLIB@", "yes")
ifeq ("@BUILD_DMEVENTD@", "yes")
LDFLAGS += -Wl,-rpath-link,$(top_builddir)/daemons/dmeventd
endif
- LVMLIBS = @LVM2APP_LIB@ -ldevmapper
+ LVMLIBS = @LVM2APP_LIB@ -ldevmapper -laio
endif
LVM_SCRIPTS = lvmdump.sh lvmconf.sh
diff --git a/tools/Makefile.in b/tools/Makefile.in
index 61c6f38..103b767 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -95,7 +95,7 @@ ifeq ("@STATIC_LINK@", "yes")
INSTALL_CMDLIB_TARGETS += install_cmdlib_static
endif
-LVMLIBS = $(LVMINTERNAL_LIBS) -ldevmapper
+LVMLIBS = $(LVMINTERNAL_LIBS) -ldevmapper -laio
LIB_VERSION = $(LIB_VERSION_LVM)
CLEAN_TARGETS = liblvm2cmd.$(LIB_SUFFIX) $(TARGETS_DM) \
6 years, 1 month
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, 1 month
master - [device/bcache] bcache_read_bytes should put blocks
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=93fc9374294aae679fa...
Commit: 93fc9374294aae679faa23aef0bd631db2e9a31a
Parent: 7be54bd687ead6aa21e04c8a85a648da369a3d88
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Feb 8 13:44:54 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:12:50 2018 -0500
[device/bcache] bcache_read_bytes should put blocks
---
lib/device/bcache.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
index 52be947..5141083 100644
--- a/lib/device/bcache.c
+++ b/lib/device/bcache.c
@@ -1009,14 +1009,17 @@ bool bcache_read_bytes(struct bcache *cache, int fd, off_t start, size_t len, vo
block_address bb, be, i;
unsigned char *udata = data;
off_t block_size = cache->block_sectors << SECTOR_SHIFT;
+ int errors = 0;
byte_range_to_block_range(cache, start, len, &bb, &be);
for (i = bb; i < be; i++)
bcache_prefetch(cache, fd, i);
for (i = bb; i < be; i++) {
- if (!bcache_get(cache, fd, i, 0, &b))
- return false;
+ if (!bcache_get(cache, fd, i, 0, &b)) {
+ errors++;
+ continue;
+ }
if (i == bb) {
off_t block_offset = start % block_size;
@@ -1030,9 +1033,11 @@ bool bcache_read_bytes(struct bcache *cache, int fd, off_t start, size_t len, vo
len -= blen;
udata += blen;
}
+
+ bcache_put(b);
}
- return true;
+ return errors ? false : true;
}
//----------------------------------------------------------------
6 years, 1 month
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, 1 month
master - [device/bcache] fix min() function
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=7be54bd687ead6aa21e...
Commit: 7be54bd687ead6aa21e04c8a85a648da369a3d88
Parent: d9e6298edb0bc6533c22f7e95e613189abe89c99
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Feb 8 11:16:19 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:12:50 2018 -0500
[device/bcache] fix min() function
---
lib/device/bcache.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
index cea4db4..52be947 100644
--- a/lib/device/bcache.c
+++ b/lib/device/bcache.c
@@ -997,7 +997,7 @@ void bcache_prefetch_bytes(struct bcache *cache, int fd, off_t start, size_t len
static off_t _min(off_t lhs, off_t rhs)
{
- if (rhs > lhs)
+ if (rhs < lhs)
return rhs;
return lhs;
6 years, 1 month
master - [device/bcache] fix missing max_io fn in bcache async engine
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d9e6298edb0bc6533c2...
Commit: d9e6298edb0bc6533c22f7e95e613189abe89c99
Parent: dc8034f5eb8d14b621c3d99ff58c95f74153c448
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Feb 8 10:10:31 2018 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:12:50 2018 -0500
[device/bcache] fix missing max_io fn in bcache async engine
---
lib/device/bcache.c | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
index dce05ef..cea4db4 100644
--- a/lib/device/bcache.c
+++ b/lib/device/bcache.c
@@ -134,6 +134,7 @@ struct async_engine {
struct io_engine e;
io_context_t aio_context;
struct cb_set *cbs;
+ unsigned max_io;
};
static struct async_engine *_to_async(struct io_engine *e)
@@ -233,6 +234,12 @@ static bool _async_wait(struct io_engine *ioe, io_complete_fn fn)
return true;
}
+static unsigned _async_max_io(struct io_engine *ioe)
+{
+ struct async_engine *e = _to_async(ioe);
+ return e->max_io;
+}
+
struct io_engine *create_async_io_engine(unsigned max_io)
{
int r;
@@ -241,9 +248,12 @@ struct io_engine *create_async_io_engine(unsigned max_io)
if (!e)
return NULL;
+ e->max_io = max_io;
+
e->e.destroy = _async_destroy;
e->e.issue = _async_issue;
e->e.wait = _async_wait;
+ e->e.max_io = _async_max_io;
e->aio_context = 0;
r = io_setup(max_io, &e->aio_context);
6 years, 1 month
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, 1 month
master - [device/bcache] more work on bcache
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=dc8034f5eb8d14b621c...
Commit: dc8034f5eb8d14b621c3d99ff58c95f74153c448
Parent: 1cde30eba0fc4404f092fb5106f7cc7fcd66795b
Author: Joe Thornber <ejt(a)redhat.com>
AuthorDate: Tue Feb 6 15:10:44 2018 +0000
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:12:50 2018 -0500
[device/bcache] more work on bcache
---
lib/device/bcache.c | 2 +-
test/unit/bcache_t.c | 152 +++++++++++++++++++++++++++++++++----------------
2 files changed, 103 insertions(+), 51 deletions(-)
diff --git a/lib/device/bcache.c b/lib/device/bcache.c
index 1d83306..dce05ef 100644
--- a/lib/device/bcache.c
+++ b/lib/device/bcache.c
@@ -365,7 +365,7 @@ static struct block *_hash_lookup(struct bcache *cache, int fd, uint64_t index)
unsigned h = _hash(cache, fd, index);
dm_list_iterate_items_gen (b, cache->buckets + h, hash)
- if (b->index == index)
+ if (b->fd == fd && b->index == index)
return b;
return NULL;
diff --git a/test/unit/bcache_t.c b/test/unit/bcache_t.c
index 5fb6789..07a45fe 100644
--- a/test/unit/bcache_t.c
+++ b/test/unit/bcache_t.c
@@ -54,6 +54,7 @@ struct mock_engine {
struct dm_list expected_calls;
struct dm_list issued_io;
unsigned max_io;
+ sector_t block_size;
};
enum method {
@@ -66,6 +67,11 @@ enum method {
struct mock_call {
struct dm_list list;
enum method m;
+
+ bool match_args;
+ enum dir d;
+ int fd;
+ block_address b;
};
struct mock_io {
@@ -97,23 +103,35 @@ static void _expect(struct mock_engine *e, enum method m)
{
struct mock_call *mc = malloc(sizeof(*mc));
mc->m = m;
+ mc->match_args = false;
dm_list_add(&e->expected_calls, &mc->list);
}
-static void _expect_read(struct mock_engine *e)
+static void _expect_read(struct mock_engine *e, int fd, block_address b)
{
- // FIXME: finish
- _expect(e, E_ISSUE);
+ struct mock_call *mc = malloc(sizeof(*mc));
+ mc->m = E_ISSUE;
+ mc->match_args = true;
+ mc->d = DIR_READ;
+ mc->fd = fd;
+ mc->b = b;
+ dm_list_add(&e->expected_calls, &mc->list);
}
-static void _expect_write(struct mock_engine *e)
+static void _expect_write(struct mock_engine *e, int fd, block_address b)
{
- // FIXME: finish
- _expect(e, E_ISSUE);
+ struct mock_call *mc = malloc(sizeof(*mc));
+ mc->m = E_ISSUE;
+ mc->match_args = true;
+ mc->d = DIR_WRITE;
+ mc->fd = fd;
+ mc->b = b;
+ dm_list_add(&e->expected_calls, &mc->list);
}
-static void _match(struct mock_engine *e, enum method m)
+static struct mock_call *_match_pop(struct mock_engine *e, enum method m)
{
+
struct mock_call *mc;
if (dm_list_empty(&e->expected_calls))
@@ -129,7 +147,12 @@ static void _match(struct mock_engine *e, enum method m)
fprintf(stderr, "%s called (expected)\n", _show_method(m));
#endif
- free(mc);
+ return mc;
+}
+
+static void _match(struct mock_engine *e, enum method m)
+{
+ free(_match_pop(e, m));
}
static void _no_outstanding_expectations(struct mock_engine *e)
@@ -163,9 +186,18 @@ static bool _mock_issue(struct io_engine *e, enum dir d, int fd,
sector_t sb, sector_t se, void *data, void *context)
{
struct mock_io *io;
+ struct mock_call *mc;
struct mock_engine *me = _to_mock(e);
- _match(me, E_ISSUE);
+ mc = _match_pop(me, E_ISSUE);
+ if (mc->match_args) {
+ T_ASSERT(d == mc->d);
+ T_ASSERT(fd == mc->fd);
+ T_ASSERT(sb == mc->b * me->block_size);
+ T_ASSERT(se == (mc->b + 1) * me->block_size);
+ }
+ free(mc);
+
io = malloc(sizeof(*io));
if (!io)
abort();
@@ -202,7 +234,7 @@ static unsigned _mock_max_io(struct io_engine *e)
return me->max_io;
}
-static struct mock_engine *_mock_create(unsigned max_io)
+static struct mock_engine *_mock_create(unsigned max_io, sector_t block_size)
{
struct mock_engine *m = malloc(sizeof(*m));
@@ -212,6 +244,7 @@ static struct mock_engine *_mock_create(unsigned max_io)
m->e.max_io = _mock_max_io;
m->max_io = max_io;
+ m->block_size = block_size;
dm_list_init(&m->expected_calls);
dm_list_init(&m->issued_io);
@@ -226,15 +259,15 @@ struct fixture {
struct bcache *cache;
};
-static struct fixture *_fixture_init(unsigned nr_cache_blocks)
+static struct fixture *_fixture_init(sector_t block_size, unsigned nr_cache_blocks)
{
struct fixture *f = malloc(sizeof(*f));
- f->me = _mock_create(16);
+ f->me = _mock_create(16, block_size);
T_ASSERT(f->me);
_expect(f->me, E_MAX_IO);
- f->cache = bcache_create(128, nr_cache_blocks, &f->me->e);
+ f->cache = bcache_create(block_size, nr_cache_blocks, &f->me->e);
T_ASSERT(f->cache);
return f;
@@ -250,7 +283,7 @@ static void _fixture_exit(struct fixture *f)
static void *_small_fixture_init(void)
{
- return _fixture_init(16);
+ return _fixture_init(128, 16);
}
static void _small_fixture_exit(void *context)
@@ -260,7 +293,7 @@ static void _small_fixture_exit(void *context)
static void *_large_fixture_init(void)
{
- return _fixture_init(1024);
+ return _fixture_init(128, 1024);
}
static void _large_fixture_exit(void *context)
@@ -277,7 +310,7 @@ static void _large_fixture_exit(void *context)
static void good_create(sector_t block_size, unsigned nr_cache_blocks)
{
struct bcache *cache;
- struct mock_engine *me = _mock_create(16);
+ struct mock_engine *me = _mock_create(16, 128);
_expect(me, E_MAX_IO);
cache = bcache_create(block_size, nr_cache_blocks, &me->e);
@@ -290,7 +323,7 @@ static void good_create(sector_t block_size, unsigned nr_cache_blocks)
static void bad_create(sector_t block_size, unsigned nr_cache_blocks)
{
struct bcache *cache;
- struct mock_engine *me = _mock_create(16);
+ struct mock_engine *me = _mock_create(16, 128);
_expect(me, E_MAX_IO);
cache = bcache_create(block_size, nr_cache_blocks, &me->e);
@@ -335,7 +368,7 @@ static void test_get_triggers_read(void *context)
int fd = 17; // arbitrary key
struct block *b;
- _expect(f->me, E_ISSUE);
+ _expect_read(f->me, fd, 0);
_expect(f->me, E_WAIT);
T_ASSERT(bcache_get(f->cache, fd, 0, 0, &b));
bcache_put(b);
@@ -349,7 +382,7 @@ static void test_repeated_reads_are_cached(void *context)
unsigned i;
struct block *b;
- _expect(f->me, E_ISSUE);
+ _expect_read(f->me, fd, 0);
_expect(f->me, E_WAIT);
for (i = 0; i < 100; i++) {
T_ASSERT(bcache_get(f->cache, fd, 0, 0, &b));
@@ -370,14 +403,14 @@ static void test_block_gets_evicted_with_many_reads(void *context)
struct block *b;
for (i = 0; i < nr_cache_blocks; i++) {
- _expect(me, E_ISSUE);
+ _expect_read(me, fd, i);
_expect(me, E_WAIT);
T_ASSERT(bcache_get(cache, fd, i, 0, &b));
bcache_put(b);
}
// Not enough cache blocks to hold this one
- _expect(me, E_ISSUE);
+ _expect_read(me, fd, nr_cache_blocks);
_expect(me, E_WAIT);
T_ASSERT(bcache_get(cache, fd, nr_cache_blocks, 0, &b));
bcache_put(b);
@@ -406,7 +439,7 @@ static void test_prefetch_issues_a_read(void *context)
for (i = 0; i < nr_cache_blocks; i++) {
// prefetch should not wait
- _expect(me, E_ISSUE);
+ _expect_read(me, fd, i);
bcache_prefetch(cache, fd, i);
}
@@ -431,7 +464,7 @@ static void test_too_many_prefetches_does_not_trigger_a_wait(void *context)
for (i = 0; i < 10 * nr_cache_blocks; i++) {
// prefetch should not wait
if (i < nr_cache_blocks)
- _expect(me, E_ISSUE);
+ _expect_read(me, fd, i);
bcache_prefetch(cache, fd, i);
}
@@ -446,19 +479,17 @@ static void test_dirty_data_gets_written_back(void *context)
struct mock_engine *me = f->me;
struct bcache *cache = f->cache;
- const unsigned nr_cache_blocks = 16;
int fd = 17; // arbitrary key
struct block *b;
- // FIXME: be specific about the IO direction
// Expect the read
- _expect(me, E_ISSUE);
+ _expect_read(me, fd, 0);
_expect(me, E_WAIT);
T_ASSERT(bcache_get(cache, fd, 0, GF_DIRTY, &b));
bcache_put(b);
// Expect the write
- _expect(me, E_ISSUE);
+ _expect_write(me, fd, 0);
_expect(me, E_WAIT);
}
@@ -468,7 +499,6 @@ static void test_zeroed_data_counts_as_dirty(void *context)
struct mock_engine *me = f->me;
struct bcache *cache = f->cache;
- const unsigned nr_cache_blocks = 16;
int fd = 17; // arbitrary key
struct block *b;
@@ -477,7 +507,7 @@ static void test_zeroed_data_counts_as_dirty(void *context)
bcache_put(b);
// Expect the write
- _expect(me, E_ISSUE);
+ _expect_write(me, fd, 0);
_expect(me, E_WAIT);
}
@@ -496,7 +526,7 @@ static void test_flush_waits_for_all_dirty(void *context)
if (i % 2) {
T_ASSERT(bcache_get(cache, fd, i, GF_ZERO, &b));
} else {
- _expect_read(me);
+ _expect_read(me, fd, i);
_expect(me, E_WAIT);
T_ASSERT(bcache_get(cache, fd, i, 0, &b));
}
@@ -505,7 +535,7 @@ static void test_flush_waits_for_all_dirty(void *context)
for (i = 0; i < count; i++) {
if (i % 2)
- _expect_write(me);
+ _expect_write(me, fd, i);
}
for (i = 0; i < count; i++) {
@@ -517,6 +547,25 @@ static void test_flush_waits_for_all_dirty(void *context)
_no_outstanding_expectations(me);
}
+static void test_multiple_files(void * context)
+{
+ static int _fds[] = {1, 128, 345, 678, 890};
+
+ struct fixture *f = context;
+ struct mock_engine *me = f->me;
+ struct bcache *cache = f->cache;
+ struct block *b;
+ unsigned i;
+
+ for (i = 0; i < DM_ARRAY_SIZE(_fds); i++) {
+ _expect_read(me, _fds[i], 0);
+ _expect(me, E_WAIT);
+
+ T_ASSERT(bcache_get(cache, _fds[i], 0, 0, &b));
+ bcache_put(b);
+ }
+}
+
// Tests to be written
// Open multiple files and prove the blocks are coming from the correct file
// show invalidate works
@@ -525,31 +574,34 @@ static void test_flush_waits_for_all_dirty(void *context)
// check zeroing
struct test_details {
- const char *name;
+ const char *path;
+ const char *desc;
void (*fn)(void *);
void *(*fixture_init)(void);
void (*fixture_exit)(void *);
};
-#define TEST(name, fn) {name, fn, NULL, NULL}
-#define TEST_S(name, fn) {name, fn, _small_fixture_init, _small_fixture_exit}
-#define TEST_L(name, fn) {name, fn, _large_fixture_init, _large_fixture_exit}
+#define PATH "device/bcache/"
+#define TEST(path, name, fn) {PATH path, name, fn, NULL, NULL}
+#define TEST_S(path, name, fn) {PATH path, name, fn, _small_fixture_init, _small_fixture_exit}
+#define TEST_L(path, name, fn) {PATH path, name, fn, _large_fixture_init, _large_fixture_exit}
int main(int argc, char **argv)
{
static struct test_details _tests[] = {
- TEST("simple create/destroy", test_create),
- TEST("nr cache blocks must be positive", test_nr_cache_blocks_must_be_positive),
- TEST("block size must be positive", test_block_size_must_be_positive),
- TEST("block size must be a multiple of page size", test_block_size_must_be_multiple_of_page_size),
- TEST_S("bcache_get() triggers read", test_get_triggers_read),
- TEST_S("repeated reads are cached", test_repeated_reads_are_cached),
- TEST_S("block get evicted with many reads", test_block_gets_evicted_with_many_reads),
- TEST_S("prefetch issues a read", test_prefetch_issues_a_read),
- TEST_S("too many prefetches does not trigger a wait", test_too_many_prefetches_does_not_trigger_a_wait),
- TEST_S("dirty data gets written back", test_dirty_data_gets_written_back),
- TEST_S("zeroed data counts as dirty", test_zeroed_data_counts_as_dirty),
- TEST_L("flush waits for all dirty", test_flush_waits_for_all_dirty),
+ TEST("create-destroy", "simple create/destroy", test_create),
+ TEST("cache-blocks-positive", "nr cache blocks must be positive", test_nr_cache_blocks_must_be_positive),
+ TEST("block-size-positive", "block size must be positive", test_block_size_must_be_positive),
+ TEST("block-size-multiple-page", "block size must be a multiple of page size", test_block_size_must_be_multiple_of_page_size),
+ TEST_S("get-reads", "bcache_get() triggers read", test_get_triggers_read),
+ TEST_S("reads-cached", "repeated reads are cached", test_repeated_reads_are_cached),
+ TEST_S("blocks-get-evicted", "block get evicted with many reads", test_block_gets_evicted_with_many_reads),
+ TEST_S("prefetch-reads", "prefetch issues a read", test_prefetch_issues_a_read),
+ TEST_S("prefetch-never-waits", "too many prefetches does not trigger a wait", test_too_many_prefetches_does_not_trigger_a_wait),
+ TEST_S("writeback-occurs", "dirty data gets written back", test_dirty_data_gets_written_back),
+ TEST_S("zero-flag-dirties", "zeroed data counts as dirty", test_zeroed_data_counts_as_dirty),
+ TEST_L("flush waits for all dirty", "flush waits for all dirty", test_flush_waits_for_all_dirty),
+ TEST_S("read-multiple-files", "read from multiple files", test_multiple_files),
};
// We have to declare these as volatile because of the setjmp()
@@ -558,10 +610,10 @@ int main(int argc, char **argv)
for (i = 0; i < DM_ARRAY_SIZE(_tests); i++) {
void *fixture;
struct test_details *t = _tests + i;
- fprintf(stderr, "[RUN ] %s\n", t->name);
+ fprintf(stderr, "[RUN ] %s\n", t->path);
if (setjmp(_test_k))
- fprintf(stderr, "[ FAIL] %s\n", t->name);
+ fprintf(stderr, "[ FAIL] %s\n", t->path);
else {
if (t->fixture_init)
fixture = t->fixture_init();
@@ -574,7 +626,7 @@ int main(int argc, char **argv)
t->fixture_exit(fixture);
passed++;
- fprintf(stderr, "[ OK] %s\n", t->name);
+ fprintf(stderr, "[ OK] %s\n", t->path);
}
}
6 years, 1 month
master - [device/bcache] More fiddling with tests
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=1cde30eba0fc4404f09...
Commit: 1cde30eba0fc4404f092fb5106f7cc7fcd66795b
Parent: 6a57ed17a28aee0e8fb9557ec3c03a02f0b2a4be
Author: Joe Thornber <ejt(a)redhat.com>
AuthorDate: Tue Feb 6 13:06:15 2018 +0000
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Apr 20 11:12:50 2018 -0500
[device/bcache] More fiddling with tests
---
test/unit/bcache_t.c | 484 ++++++++++++++++++++++----------------------------
1 files changed, 214 insertions(+), 270 deletions(-)
diff --git a/test/unit/bcache_t.c b/test/unit/bcache_t.c
index c2d2df0..5fb6789 100644
--- a/test/unit/bcache_t.c
+++ b/test/unit/bcache_t.c
@@ -219,6 +219,56 @@ static struct mock_engine *_mock_create(unsigned max_io)
}
/*----------------------------------------------------------------
+ * Fixtures
+ *--------------------------------------------------------------*/
+struct fixture {
+ struct mock_engine *me;
+ struct bcache *cache;
+};
+
+static struct fixture *_fixture_init(unsigned nr_cache_blocks)
+{
+ struct fixture *f = malloc(sizeof(*f));
+
+ f->me = _mock_create(16);
+ T_ASSERT(f->me);
+
+ _expect(f->me, E_MAX_IO);
+ f->cache = bcache_create(128, nr_cache_blocks, &f->me->e);
+ T_ASSERT(f->cache);
+
+ return f;
+}
+
+static void _fixture_exit(struct fixture *f)
+{
+ _expect(f->me, E_DESTROY);
+ bcache_destroy(f->cache);
+
+ free(f);
+}
+
+static void *_small_fixture_init(void)
+{
+ return _fixture_init(16);
+}
+
+static void _small_fixture_exit(void *context)
+{
+ _fixture_exit(context);
+}
+
+static void *_large_fixture_init(void)
+{
+ return _fixture_init(1024);
+}
+
+static void _large_fixture_exit(void *context)
+{
+ _fixture_exit(context);
+}
+
+/*----------------------------------------------------------------
* Tests
*--------------------------------------------------------------*/
#define MEG 2048
@@ -250,22 +300,22 @@ static void bad_create(sector_t block_size, unsigned nr_cache_blocks)
me->e.destroy(&me->e);
}
-static void test_create(void)
+static void test_create(void *fixture)
{
good_create(8, 16);
}
-static void test_nr_cache_blocks_must_be_positive(void)
+static void test_nr_cache_blocks_must_be_positive(void *fixture)
{
bad_create(8, 0);
}
-static void test_block_size_must_be_positive(void)
+static void test_block_size_must_be_positive(void *fixture)
{
bad_create(0, 16);
}
-static void test_block_size_must_be_multiple_of_page_size(void)
+static void test_block_size_must_be_multiple_of_page_size(void *fixture)
{
static unsigned _bad_examples[] = {3, 9, 13, 1025};
@@ -278,312 +328,195 @@ static void test_block_size_must_be_multiple_of_page_size(void)
good_create(i * 8, 16);
}
-static void test_get_triggers_read(void)
+static void test_get_triggers_read(void *context)
{
- struct bcache *cache;
- struct mock_engine *me = _mock_create(16);
+ struct fixture *f = context;
- // FIXME: use a fixture
- _expect(me, E_MAX_IO);
- cache = bcache_create(64, 16, &me->e);
- T_ASSERT(cache);
+ int fd = 17; // arbitrary key
+ struct block *b;
- {
- int fd = 17; // arbitrary key
- struct block *b;
-
- _expect(me, E_ISSUE);
- _expect(me, E_WAIT);
- T_ASSERT(bcache_get(cache, fd, 0, 0, &b));
- bcache_put(b);
- }
-
- _expect(me, E_DESTROY);
- bcache_destroy(cache);
+ _expect(f->me, E_ISSUE);
+ _expect(f->me, E_WAIT);
+ T_ASSERT(bcache_get(f->cache, fd, 0, 0, &b));
+ bcache_put(b);
}
-static void test_repeated_reads_are_cached(void)
+static void test_repeated_reads_are_cached(void *context)
{
- struct bcache *cache;
- struct mock_engine *me = _mock_create(16);
+ struct fixture *f = context;
- // FIXME: use a fixture
- _expect(me, E_MAX_IO);
- cache = bcache_create(64, 16, &me->e);
- T_ASSERT(cache);
-
- {
- int fd = 17; // arbitrary key
- unsigned i;
- struct block *b;
+ int fd = 17; // arbitrary key
+ unsigned i;
+ struct block *b;
- _expect(me, E_ISSUE);
- _expect(me, E_WAIT);
- for (i = 0; i < 100; i++) {
- T_ASSERT(bcache_get(cache, fd, 0, 0, &b));
- bcache_put(b);
- }
+ _expect(f->me, E_ISSUE);
+ _expect(f->me, E_WAIT);
+ for (i = 0; i < 100; i++) {
+ T_ASSERT(bcache_get(f->cache, fd, 0, 0, &b));
+ bcache_put(b);
}
-
- _expect(me, E_DESTROY);
- bcache_destroy(cache);
}
-static void test_block_gets_evicted_with_many_reads(void)
+static void test_block_gets_evicted_with_many_reads(void *context)
{
- const unsigned nr_cache_blocks = 16;
- struct bcache *cache;
- struct mock_engine *me = _mock_create(16);
+ struct fixture *f = context;
- // FIXME: use a fixture
- _expect(me, E_MAX_IO);
- cache = bcache_create(64, nr_cache_blocks, &me->e);
- T_ASSERT(cache);
-
- {
- int fd = 17; // arbitrary key
- unsigned i;
- struct block *b;
+ struct mock_engine *me = f->me;
+ struct bcache *cache = f->cache;
+ const unsigned nr_cache_blocks = 16;
- for (i = 0; i < nr_cache_blocks; i++) {
- _expect(me, E_ISSUE);
- _expect(me, E_WAIT);
- T_ASSERT(bcache_get(cache, fd, i, 0, &b));
- bcache_put(b);
- }
+ int fd = 17; // arbitrary key
+ unsigned i;
+ struct block *b;
- // Not enough cache blocks to hold this one
+ for (i = 0; i < nr_cache_blocks; i++) {
_expect(me, E_ISSUE);
_expect(me, E_WAIT);
- T_ASSERT(bcache_get(cache, fd, nr_cache_blocks, 0, &b));
+ T_ASSERT(bcache_get(cache, fd, i, 0, &b));
bcache_put(b);
-
- // Now if we run through we should find one block has been
- // evicted. We go backwards because the oldest is normally
- // evicted first.
- _expect(me, E_ISSUE);
- _expect(me, E_WAIT);
- for (i = nr_cache_blocks; i; i--) {
- T_ASSERT(bcache_get(cache, fd, i - 1, 0, &b));
- bcache_put(b);
- }
}
- _expect(me, E_DESTROY);
- bcache_destroy(cache);
-}
-
-static void test_prefetch_issues_a_read(void)
-{
- const unsigned nr_cache_blocks = 16;
- struct bcache *cache;
- struct mock_engine *me = _mock_create(16);
-
- // FIXME: use a fixture
- _expect(me, E_MAX_IO);
- cache = bcache_create(64, nr_cache_blocks, &me->e);
- T_ASSERT(cache);
-
- {
- int fd = 17; // arbitrary key
- unsigned i;
- struct block *b;
-
- for (i = 0; i < nr_cache_blocks; i++) {
- // prefetch should not wait
- _expect(me, E_ISSUE);
- bcache_prefetch(cache, fd, i);
- }
-
-
- for (i = 0; i < nr_cache_blocks; i++) {
- _expect(me, E_WAIT);
- T_ASSERT(bcache_get(cache, fd, i, 0, &b));
- bcache_put(b);
- }
+ // Not enough cache blocks to hold this one
+ _expect(me, E_ISSUE);
+ _expect(me, E_WAIT);
+ T_ASSERT(bcache_get(cache, fd, nr_cache_blocks, 0, &b));
+ bcache_put(b);
+
+ // Now if we run through we should find one block has been
+ // evicted. We go backwards because the oldest is normally
+ // evicted first.
+ _expect(me, E_ISSUE);
+ _expect(me, E_WAIT);
+ for (i = nr_cache_blocks; i; i--) {
+ T_ASSERT(bcache_get(cache, fd, i - 1, 0, &b));
+ bcache_put(b);
}
-
- _expect(me, E_DESTROY);
- bcache_destroy(cache);
}
-static void test_too_many_prefetches_does_not_trigger_a_wait(void)
+static void test_prefetch_issues_a_read(void *context)
{
+ struct fixture *f = context;
+ struct mock_engine *me = f->me;
+ struct bcache *cache = f->cache;
const unsigned nr_cache_blocks = 16;
- struct bcache *cache;
- struct mock_engine *me = _mock_create(16);
-
- // FIXME: use a fixture
- _expect(me, E_MAX_IO);
- cache = bcache_create(64, nr_cache_blocks, &me->e);
- T_ASSERT(cache);
-
- {
- int fd = 17; // arbitrary key
- unsigned i;
- for (i = 0; i < 10 * nr_cache_blocks; i++) {
- // prefetch should not wait
- if (i < nr_cache_blocks)
- _expect(me, E_ISSUE);
- bcache_prefetch(cache, fd, i);
- }
+ int fd = 17; // arbitrary key
+ unsigned i;
+ struct block *b;
- // Destroy will wait for any in flight IO triggered by prefetches.
- for (i = 0; i < nr_cache_blocks; i++)
- _expect(me, E_WAIT);
+ for (i = 0; i < nr_cache_blocks; i++) {
+ // prefetch should not wait
+ _expect(me, E_ISSUE);
+ bcache_prefetch(cache, fd, i);
}
- _expect(me, E_DESTROY);
- bcache_destroy(cache);
-}
-static void test_dirty_data_gets_written_back(void)
-{
- const unsigned nr_cache_blocks = 16;
- struct bcache *cache;
- struct mock_engine *me = _mock_create(16);
-
- // FIXME: use a fixture
- _expect(me, E_MAX_IO);
- cache = bcache_create(64, nr_cache_blocks, &me->e);
- T_ASSERT(cache);
-
- {
- int fd = 17; // arbitrary key
- struct block *b;
-
- // FIXME: be specific about the IO direction
- // Expect the read
- _expect(me, E_ISSUE);
+ for (i = 0; i < nr_cache_blocks; i++) {
_expect(me, E_WAIT);
- T_ASSERT(bcache_get(cache, fd, 0, GF_DIRTY, &b));
+ T_ASSERT(bcache_get(cache, fd, i, 0, &b));
bcache_put(b);
-
- // Expect the write
- _expect(me, E_ISSUE);
- _expect(me, E_WAIT);
}
-
- _expect(me, E_DESTROY);
- bcache_destroy(cache);
}
-static void test_zeroed_data_counts_as_dirty(void)
+static void test_too_many_prefetches_does_not_trigger_a_wait(void *context)
{
- const unsigned nr_cache_blocks = 16;
- struct bcache *cache;
- struct mock_engine *me = _mock_create(16);
-
- // FIXME: use a fixture
- _expect(me, E_MAX_IO);
- cache = bcache_create(64, nr_cache_blocks, &me->e);
- T_ASSERT(cache);
-
- {
- int fd = 17; // arbitrary key
- struct block *b;
+ struct fixture *f = context;
+ struct mock_engine *me = f->me;
+ struct bcache *cache = f->cache;
- // No read
- T_ASSERT(bcache_get(cache, fd, 0, GF_ZERO, &b));
- bcache_put(b);
+ const unsigned nr_cache_blocks = 16;
+ int fd = 17; // arbitrary key
+ unsigned i;
- // Expect the write
- _expect(me, E_ISSUE);
- _expect(me, E_WAIT);
+ for (i = 0; i < 10 * nr_cache_blocks; i++) {
+ // prefetch should not wait
+ if (i < nr_cache_blocks)
+ _expect(me, E_ISSUE);
+ bcache_prefetch(cache, fd, i);
}
- _expect(me, E_DESTROY);
- bcache_destroy(cache);
+ // Destroy will wait for any in flight IO triggered by prefetches.
+ for (i = 0; i < nr_cache_blocks; i++)
+ _expect(me, E_WAIT);
}
-static void test_flush_waits_for_all_dirty(void)
+static void test_dirty_data_gets_written_back(void *context)
{
- const unsigned nr_cache_blocks = 128, count = 16;
- struct bcache *cache;
- struct mock_engine *me = _mock_create(16);
+ struct fixture *f = context;
+ struct mock_engine *me = f->me;
+ struct bcache *cache = f->cache;
- // FIXME: use a fixture
- _expect(me, E_MAX_IO);
-
- // I'm using a large nr of cache blocks to avoid triggering writeback
- // early.
- cache = bcache_create(64, nr_cache_blocks, &me->e);
- T_ASSERT(cache);
-
- {
- int fd = 17; // arbitrary key
- unsigned i;
- struct block *b;
-
- for (i = 0; i < count; i++) {
- if (i % 2) {
- T_ASSERT(bcache_get(cache, fd, i, GF_ZERO, &b));
- } else {
- _expect_read(me);
- _expect(me, E_WAIT);
- T_ASSERT(bcache_get(cache, fd, i, 0, &b));
- }
- bcache_put(b);
- }
+ const unsigned nr_cache_blocks = 16;
+ int fd = 17; // arbitrary key
+ struct block *b;
+
+ // FIXME: be specific about the IO direction
+ // Expect the read
+ _expect(me, E_ISSUE);
+ _expect(me, E_WAIT);
+ T_ASSERT(bcache_get(cache, fd, 0, GF_DIRTY, &b));
+ bcache_put(b);
+
+ // Expect the write
+ _expect(me, E_ISSUE);
+ _expect(me, E_WAIT);
+}
- for (i = 0; i < count; i++) {
- if (i % 2)
- _expect_write(me);
- }
+static void test_zeroed_data_counts_as_dirty(void *context)
+{
+ struct fixture *f = context;
+ struct mock_engine *me = f->me;
+ struct bcache *cache = f->cache;
- for (i = 0; i < count; i++) {
- if (i % 2)
- _expect(me, E_WAIT);
- }
+ const unsigned nr_cache_blocks = 16;
+ int fd = 17; // arbitrary key
+ struct block *b;
- bcache_flush(cache);
- _no_outstanding_expectations(me);
- }
+ // No read
+ T_ASSERT(bcache_get(cache, fd, 0, GF_ZERO, &b));
+ bcache_put(b);
- _expect(me, E_DESTROY);
- bcache_destroy(cache);
+ // Expect the write
+ _expect(me, E_ISSUE);
+ _expect(me, E_WAIT);
}
-#if 0
-#define NR_FILES 4
-static void test_read_multiple_files(void)
+static void test_flush_waits_for_all_dirty(void *context)
{
- unsigned i;
- int fd[NR_FILES];
- char buffer[128];
-
-
- // FIXME: add fixtures.
- test_init();
- for (i = 0; i < NR_FILES; i++) {
- snprintf(buffer, sizeof(buffer), "./test%u.bin", i);
- unlink(buffer);
- _prep_file(buffer);
- fd[i] = open_file(buffer);
- CU_ASSERT(fd[i] >= 0);
- }
+ struct fixture *f = context;
+ struct mock_engine *me = f->me;
+ struct bcache *cache = f->cache;
- {
- struct block *b;
- struct bcache *cache = bcache_create(8, 16);
+ const unsigned count = 16;
+ int fd = 17; // arbitrary key
+ unsigned i;
+ struct block *b;
- for (i = 0; i < 64; i++) {
- if (!bcache_get(cache, fd[i % NR_FILES], i, 0, &b)) {
- CU_ASSERT(false);
- } else
- bcache_put(b);
+ for (i = 0; i < count; i++) {
+ if (i % 2) {
+ T_ASSERT(bcache_get(cache, fd, i, GF_ZERO, &b));
+ } else {
+ _expect_read(me);
+ _expect(me, E_WAIT);
+ T_ASSERT(bcache_get(cache, fd, i, 0, &b));
}
+ bcache_put(b);
+ }
- bcache_destroy(cache);
+ for (i = 0; i < count; i++) {
+ if (i % 2)
+ _expect_write(me);
}
- for (i = 0; i < NR_FILES; i++)
- close(fd[i]);
+ for (i = 0; i < count; i++) {
+ if (i % 2)
+ _expect(me, E_WAIT);
+ }
- test_exit();
+ bcache_flush(cache);
+ _no_outstanding_expectations(me);
}
-#endif
+
// Tests to be written
// Open multiple files and prove the blocks are coming from the correct file
// show invalidate works
@@ -593,37 +526,53 @@ static void test_read_multiple_files(void)
struct test_details {
const char *name;
- void (*fn)(void);
+ void (*fn)(void *);
+ void *(*fixture_init)(void);
+ void (*fixture_exit)(void *);
};
+#define TEST(name, fn) {name, fn, NULL, NULL}
+#define TEST_S(name, fn) {name, fn, _small_fixture_init, _small_fixture_exit}
+#define TEST_L(name, fn) {name, fn, _large_fixture_init, _large_fixture_exit}
+
int main(int argc, char **argv)
{
static struct test_details _tests[] = {
- {"simple create/destroy", test_create},
- {"nr cache blocks must be positive", test_nr_cache_blocks_must_be_positive},
- {"block size must be positive", test_block_size_must_be_positive},
- {"block size must be a multiple of page size", test_block_size_must_be_multiple_of_page_size},
- {"bcache_get() triggers read", test_get_triggers_read},
- {"repeated reads are cached", test_repeated_reads_are_cached},
- {"block get evicted with many reads", test_block_gets_evicted_with_many_reads},
- {"prefetch issues a read", test_prefetch_issues_a_read},
- {"too many prefetches does not trigger a wait", test_too_many_prefetches_does_not_trigger_a_wait},
- {"dirty data gets written back", test_dirty_data_gets_written_back},
- {"zeroed data counts as dirty", test_zeroed_data_counts_as_dirty},
- {"flush waits for all dirty", test_flush_waits_for_all_dirty},
+ TEST("simple create/destroy", test_create),
+ TEST("nr cache blocks must be positive", test_nr_cache_blocks_must_be_positive),
+ TEST("block size must be positive", test_block_size_must_be_positive),
+ TEST("block size must be a multiple of page size", test_block_size_must_be_multiple_of_page_size),
+ TEST_S("bcache_get() triggers read", test_get_triggers_read),
+ TEST_S("repeated reads are cached", test_repeated_reads_are_cached),
+ TEST_S("block get evicted with many reads", test_block_gets_evicted_with_many_reads),
+ TEST_S("prefetch issues a read", test_prefetch_issues_a_read),
+ TEST_S("too many prefetches does not trigger a wait", test_too_many_prefetches_does_not_trigger_a_wait),
+ TEST_S("dirty data gets written back", test_dirty_data_gets_written_back),
+ TEST_S("zeroed data counts as dirty", test_zeroed_data_counts_as_dirty),
+ TEST_L("flush waits for all dirty", test_flush_waits_for_all_dirty),
};
// We have to declare these as volatile because of the setjmp()
volatile unsigned i = 0, passed = 0;
for (i = 0; i < DM_ARRAY_SIZE(_tests); i++) {
+ void *fixture;
struct test_details *t = _tests + i;
fprintf(stderr, "[RUN ] %s\n", t->name);
if (setjmp(_test_k))
fprintf(stderr, "[ FAIL] %s\n", t->name);
else {
- t->fn();
+ if (t->fixture_init)
+ fixture = t->fixture_init();
+ else
+ fixture = NULL;
+
+ t->fn(fixture);
+
+ if (t->fixture_exit)
+ t->fixture_exit(fixture);
+
passed++;
fprintf(stderr, "[ OK] %s\n", t->name);
}
@@ -631,10 +580,5 @@ int main(int argc, char **argv)
fprintf(stderr, "\n%u/%lu tests passed\n", passed, DM_ARRAY_SIZE(_tests));
-#if 0
- test_prefetch_works();
- test_read_multiple_files();
-#endif
-
return 0;
}
6 years, 1 month
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, 1 month