This includes hacking the test client to send NBD_CMD_CACHE to the
server, and that all layers are visited in the correct order.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
tests/test-layers-filter.c | 22 +++++++++++++++++++++-
tests/test-layers-plugin.c | 17 +++++++++++++++++
tests/test-layers.c | 36 ++++++++++++++++++++++++++++++++++++
3 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/tests/test-layers-filter.c b/tests/test-layers-filter.c
index a8f4723..bd063bd 100644
--- a/tests/test-layers-filter.c
+++ b/tests/test-layers-filter.c
@@ -1,5 +1,5 @@
/* nbdkit
- * Copyright (C) 2018 Red Hat Inc.
+ * Copyright (C) 2018-2019 Red Hat Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -184,6 +184,15 @@ test_layers_filter_can_extents (struct nbdkit_next_ops *next_ops,
return next_ops->can_extents (nxdata);
}
+static int
+test_layers_filter_can_cache (struct nbdkit_next_ops *next_ops,
+ void *nxdata,
+ void *handle)
+{
+ DEBUG_FUNCTION;
+ return next_ops->can_cache (nxdata);
+}
+
static int
test_layers_filter_pread (struct nbdkit_next_ops *next_ops, void *nxdata,
void *handle, void *buf,
@@ -241,6 +250,15 @@ test_layers_filter_extents (struct nbdkit_next_ops *next_ops, void
*nxdata,
return next_ops->extents (nxdata, count, offset, flags, extents, err);
}
+static int
+test_layers_filter_cache (struct nbdkit_next_ops *next_ops, void *nxdata,
+ void *handle, uint32_t count, uint64_t offset,
+ uint32_t flags, int *err)
+{
+ DEBUG_FUNCTION;
+ return next_ops->cache (nxdata, count, offset, flags, err);
+}
+
static struct nbdkit_filter filter = {
.name = "testlayers" layer,
.version = PACKAGE_VERSION,
@@ -262,12 +280,14 @@ static struct nbdkit_filter filter = {
.can_fua = test_layers_filter_can_fua,
.can_multi_conn = test_layers_filter_can_multi_conn,
.can_extents = test_layers_filter_can_extents,
+ .can_cache = test_layers_filter_can_cache,
.pread = test_layers_filter_pread,
.pwrite = test_layers_filter_pwrite,
.flush = test_layers_filter_flush,
.trim = test_layers_filter_trim,
.zero = test_layers_filter_zero,
.extents = test_layers_filter_extents,
+ .cache = test_layers_filter_cache,
};
NBDKIT_REGISTER_FILTER(filter)
diff --git a/tests/test-layers-plugin.c b/tests/test-layers-plugin.c
index f9b2014..e9ffd3b 100644
--- a/tests/test-layers-plugin.c
+++ b/tests/test-layers-plugin.c
@@ -143,6 +143,13 @@ test_layers_plugin_can_multi_conn (void *handle)
return 1;
}
+static int
+test_layers_plugin_can_cache (void *handle)
+{
+ DEBUG_FUNCTION;
+ return NBDKIT_CACHE_NATIVE;
+}
+
static int
test_layers_plugin_can_extents (void *handle)
{
@@ -201,6 +208,14 @@ test_layers_plugin_extents (void *handle,
return nbdkit_add_extent (extents, offset, count, 0);
}
+static int
+test_layers_plugin_cache (void *handle,
+ uint32_t count, uint64_t offset, uint32_t flags)
+{
+ DEBUG_FUNCTION;
+ return 0;
+}
+
static struct nbdkit_plugin plugin = {
.name = "testlayersplugin",
.version = PACKAGE_VERSION,
@@ -220,12 +235,14 @@ static struct nbdkit_plugin plugin = {
.can_fua = test_layers_plugin_can_fua,
.can_multi_conn = test_layers_plugin_can_multi_conn,
.can_extents = test_layers_plugin_can_extents,
+ .can_cache = test_layers_plugin_can_cache,
.pread = test_layers_plugin_pread,
.pwrite = test_layers_plugin_pwrite,
.flush = test_layers_plugin_flush,
.trim = test_layers_plugin_trim,
.zero = test_layers_plugin_zero,
.extents = test_layers_plugin_extents,
+ .cache = test_layers_plugin_cache,
/* In this plugin, errno is preserved properly along error return
* paths from failed system calls.
*/
diff --git a/tests/test-layers.c b/tests/test-layers.c
index 627e4ec..a820ba5 100644
--- a/tests/test-layers.c
+++ b/tests/test-layers.c
@@ -361,6 +361,12 @@ main (int argc, char *argv[])
"filter1: test_layers_filter_can_extents",
"test_layers_plugin_can_extents",
NULL);
+ log_verify_seen_in_order
+ ("filter3: test_layers_filter_can_cache",
+ "filter2: test_layers_filter_can_cache",
+ "filter1: test_layers_filter_can_cache",
+ "test_layers_plugin_can_cache",
+ NULL);
fprintf (stderr, "%s: protocol connected\n", program_name);
@@ -526,6 +532,36 @@ main (int argc, char *argv[])
"test_layers_plugin_zero",
NULL);
+ request.type = htobe16 (NBD_CMD_CACHE);
+ request.offset = htobe64 (0);
+ request.count = htobe32 (512);
+ request.flags = htobe16 (0);
+ if (send (sock, &request, sizeof request, 0) != sizeof request) {
+ perror ("send: NBD_CMD_CACHE");
+ exit (EXIT_FAILURE);
+ }
+ if (recv (sock, &reply, sizeof reply, MSG_WAITALL) != sizeof reply) {
+ perror ("recv: NBD_CMD_CACHE");
+ exit (EXIT_FAILURE);
+ }
+ if (reply.error != NBD_SUCCESS) {
+ fprintf (stderr, "%s: NBD_CMD_CACHE failed with %d\n",
+ program_name, reply.error);
+ exit (EXIT_FAILURE);
+ }
+
+ sleep (1);
+ log_verify_seen_in_order
+ ("testlayersfilter3: cache count=512 offset=0 flags=0x0",
+ "filter3: test_layers_filter_cache",
+ "testlayersfilter2: cache count=512 offset=0 flags=0x0",
+ "filter2: test_layers_filter_cache",
+ "testlayersfilter1: cache count=512 offset=0 flags=0x0",
+ "filter1: test_layers_filter_cache",
+ "testlayersplugin: debug: cache count=512 offset=0",
+ "test_layers_plugin_cache",
+ NULL);
+
/* XXX We should test NBD_CMD_BLOCK_STATUS here. However it
* requires that we negotiate structured replies and base:allocation
* in the handshake, and the format of the reply is more complex
--
2.20.1