I'm planning to move sanity checking and per-connection caching into
common code (right now, we check and cache things at the connection
level for the final filter, but not at other layers; it would be nicer
to do this at each step through the filters). This starts the process
by extending the just-created backend.c to add wrappers for all of the
handshake and request callbacks present in a filter's next_ops. This
lets us consolidate common debugging output (which requires a tweak to
test-layers), and moves assertion checking (such as what was
duplicated in 0b8ad8c8) into a single location.
Of note: .extents no longer returns 0 for a 0-length request made by a
filter (such a request cannot be made by the client, because
protocol.c:valid_range rejects it); commit 5a1db63d showed a case
where a filter ended up doing that accidentally.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
server/internal.h | 49 +++++++
server/backend.c | 201 +++++++++++++++++++++++++++
server/filters.c | 158 +++++----------------
server/plugins.c | 48 -------
server/protocol-handshake-newstyle.c | 2 +-
server/protocol-handshake-oldstyle.c | 2 +-
server/protocol-handshake.c | 18 +--
server/protocol.c | 36 ++---
tests/test-layers.c | 50 +++----
9 files changed, 331 insertions(+), 233 deletions(-)
diff --git a/server/internal.h b/server/internal.h
index 3af6ca16..93ebeb78 100644
--- a/server/internal.h
+++ b/server/internal.h
@@ -317,6 +317,55 @@ extern void backend_set_name (struct backend *b, const char *name,
extern void backend_unload (struct backend *b, void (*unload) (void))
__attribute__((__nonnull__ (1)));
+extern int64_t backend_get_size (struct backend *b, struct connection *conn)
+ __attribute__((__nonnull__ (1, 2)));
+extern int backend_can_write (struct backend *b, struct connection *conn)
+ __attribute__((__nonnull__ (1, 2)));
+extern int backend_can_flush (struct backend *b, struct connection *conn)
+ __attribute__((__nonnull__ (1, 2)));
+extern int backend_is_rotational (struct backend *b, struct connection *conn)
+ __attribute__((__nonnull__ (1, 2)));
+extern int backend_can_trim (struct backend *b, struct connection *conn)
+ __attribute__((__nonnull__ (1, 2)));
+extern int backend_can_zero (struct backend *b, struct connection *conn)
+ __attribute__((__nonnull__ (1, 2)));
+extern int backend_can_extents (struct backend *b, struct connection *conn)
+ __attribute__((__nonnull__ (1, 2)));
+extern int backend_can_fua (struct backend *b, struct connection *conn)
+ __attribute__((__nonnull__ (1, 2)));
+extern int backend_can_multi_conn (struct backend *b, struct connection *conn)
+ __attribute__((__nonnull__ (1, 2)));
+extern int backend_can_cache (struct backend *b, struct connection *conn)
+ __attribute__((__nonnull__ (1, 2)));
+
+extern int backend_pread (struct backend *b, struct connection *conn,
+ void *buf, uint32_t count, uint64_t offset,
+ uint32_t flags, int *err)
+ __attribute__((__nonnull__ (1, 2, 3, 7)));
+extern int backend_pwrite (struct backend *b, struct connection *conn,
+ const void *buf, uint32_t count, uint64_t offset,
+ uint32_t flags, int *err)
+ __attribute__((__nonnull__ (1, 2, 3, 7)));
+extern int backend_flush (struct backend *b, struct connection *conn,
+ uint32_t flags, int *err)
+ __attribute__((__nonnull__ (1, 2, 4)));
+extern int backend_trim (struct backend *b, struct connection *conn,
+ uint32_t count, uint64_t offset, uint32_t flags,
+ int *err)
+ __attribute__((__nonnull__ (1, 2, 6)));
+extern int backend_zero (struct backend *b, struct connection *conn,
+ uint32_t count, uint64_t offset, uint32_t flags,
+ int *err)
+ __attribute__((__nonnull__ (1, 2, 6)));
+extern int backend_extents (struct backend *b, struct connection *conn,
+ uint32_t count, uint64_t offset, uint32_t flags,
+ struct nbdkit_extents *extents, int *err)
+ __attribute__((__nonnull__ (1, 2, 6, 7)));
+extern int backend_cache (struct backend *b, struct connection *conn,
+ uint32_t count, uint64_t offset,
+ uint32_t flags, int *err)
+ __attribute__((__nonnull__ (1, 2, 6)));
+
/* plugins.c */
extern struct backend *plugin_register (size_t index, const char *filename,
void *dl, struct nbdkit_plugin *(*plugin_init)
(void))
diff --git a/server/backend.c b/server/backend.c
index c7ee2d05..ce3c5e2b 100644
--- a/server/backend.c
+++ b/server/backend.c
@@ -32,8 +32,10 @@
#include <config.h>
+#include <assert.h>
#include <ctype.h>
#include <dlfcn.h>
+#include <inttypes.h>
#include <stdio.h>
#include <string.h>
@@ -119,3 +121,202 @@ backend_unload (struct backend *b, void (*unload) (void))
free (b->name);
}
+
+int64_t
+backend_get_size (struct backend *b, struct connection *conn)
+{
+ debug ("%s: get_size", b->name);
+
+ /* TODO caching */
+ return b->get_size (b, conn);
+}
+
+int
+backend_can_write (struct backend *b, struct connection *conn)
+{
+ debug ("%s: can_write", b->name);
+
+ return b->can_write (b, conn);
+}
+
+int
+backend_can_flush (struct backend *b, struct connection *conn)
+{
+ debug ("%s: can_flush", b->name);
+
+ return b->can_flush (b, conn);
+}
+
+int
+backend_is_rotational (struct backend *b, struct connection *conn)
+{
+ debug ("%s: is_rotational", b->name);
+
+ return b->is_rotational (b, conn);
+}
+
+int
+backend_can_trim (struct backend *b, struct connection *conn)
+{
+ debug ("%s: can_trim", b->name);
+
+ return b->can_trim (b, conn);
+}
+
+int
+backend_can_zero (struct backend *b, struct connection *conn)
+{
+ debug ("%s: can_zero", b->name);
+
+ return b->can_zero (b, conn);
+}
+
+int
+backend_can_extents (struct backend *b, struct connection *conn)
+{
+ debug ("%s: can_extents", b->name);
+
+ return b->can_extents (b, conn);
+}
+
+int
+backend_can_fua (struct backend *b, struct connection *conn)
+{
+ debug ("%s: can_fua", b->name);
+
+ return b->can_fua (b, conn);
+}
+
+int
+backend_can_multi_conn (struct backend *b, struct connection *conn)
+{
+ debug ("%s: can_multi_conn", b->name);
+
+ return b->can_multi_conn (b, conn);
+}
+
+int
+backend_can_cache (struct backend *b, struct connection *conn)
+{
+ debug ("%s: can_cache", b->name);
+
+ return b->can_cache (b, conn);
+}
+
+int
+backend_pread (struct backend *b, struct connection *conn,
+ void *buf, uint32_t count, uint64_t offset,
+ uint32_t flags, int *err)
+{
+ int r;
+
+ assert (flags == 0);
+ debug ("%s: pread count=%" PRIu32 " offset=%" PRIu64,
+ b->name, count, offset);
+
+ r = b->pread (b, conn, buf, count, offset, flags, err);
+ if (r == -1)
+ assert (*err);
+ return r;
+}
+
+int
+backend_pwrite (struct backend *b, struct connection *conn,
+ const void *buf, uint32_t count, uint64_t offset,
+ uint32_t flags, int *err)
+{
+ int r;
+
+ assert (!(flags & ~NBDKIT_FLAG_FUA));
+ debug ("%s: pwrite count=%" PRIu32 " offset=%" PRIu64 "
fua=%d",
+ b->name, count, offset, !!(flags & NBDKIT_FLAG_FUA));
+
+ r = b->pwrite (b, conn, buf, count, offset, flags, err);
+ if (r == -1)
+ assert (*err);
+ return r;
+}
+
+int
+backend_flush (struct backend *b, struct connection *conn,
+ uint32_t flags, int *err)
+{
+ int r;
+
+ assert (flags == 0);
+ debug ("%s: flush", b->name);
+
+ r = b->flush (b, conn, flags, err);
+ if (r == -1)
+ assert (*err);
+ return r;
+}
+
+int
+backend_trim (struct backend *b, struct connection *conn,
+ uint32_t count, uint64_t offset, uint32_t flags,
+ int *err)
+{
+ int r;
+
+ assert (flags == 0);
+ debug ("%s: trim count=%" PRIu32 " offset=%" PRIu64 "
fua=%d",
+ b->name, count, offset, !!(flags & NBDKIT_FLAG_FUA));
+
+ r = b->trim (b, conn, count, offset, flags, err);
+ if (r == -1)
+ assert (*err);
+ return r;
+}
+
+int
+backend_zero (struct backend *b, struct connection *conn,
+ uint32_t count, uint64_t offset, uint32_t flags,
+ int *err)
+{
+ int r;
+
+ assert (!(flags & ~(NBDKIT_FLAG_MAY_TRIM | NBDKIT_FLAG_FUA)));
+ debug ("%s: zero count=%" PRIu32 " offset=%" PRIu64 "
may_trim=%d fua=%d",
+ b->name, count, offset, !!(flags & NBDKIT_FLAG_MAY_TRIM),
+ !!(flags & NBDKIT_FLAG_FUA));
+
+ r = b->zero (b, conn, count, offset, flags, err);
+ if (r == -1)
+ assert (*err && *err != ENOTSUP && *err != EOPNOTSUPP);
+ return r;
+}
+
+int
+backend_extents (struct backend *b, struct connection *conn,
+ uint32_t count, uint64_t offset, uint32_t flags,
+ struct nbdkit_extents *extents, int *err)
+{
+ int r;
+
+ assert (!(flags & ~NBDKIT_FLAG_REQ_ONE));
+ debug ("%s: extents count=%" PRIu32 " offset=%" PRIu64 "
req_one=%d",
+ b->name, count, offset, !!(flags & NBDKIT_FLAG_REQ_ONE));
+
+ r = b->extents (b, conn, count, offset, flags, extents, err);
+ if (r == -1)
+ assert (*err);
+ return r;
+}
+
+int
+backend_cache (struct backend *b, struct connection *conn,
+ uint32_t count, uint64_t offset,
+ uint32_t flags, int *err)
+{
+ int r;
+
+ assert (flags == 0);
+ debug ("%s: cache count=%" PRIu32 " offset=%" PRIu64,
+ b->name, count, offset);
+
+ r = b->cache (b, conn, count, offset, flags, err);
+ if (r == -1)
+ assert (*err);
+ return r;
+}
diff --git a/server/filters.c b/server/filters.c
index 1f76bf61..acb44bda 100644
--- a/server/filters.c
+++ b/server/filters.c
@@ -244,70 +244,70 @@ static int64_t
next_get_size (void *nxdata)
{
struct b_conn *b_conn = nxdata;
- return b_conn->b->get_size (b_conn->b, b_conn->conn);
+ return backend_get_size (b_conn->b, b_conn->conn);
}
static int
next_can_write (void *nxdata)
{
struct b_conn *b_conn = nxdata;
- return b_conn->b->can_write (b_conn->b, b_conn->conn);
+ return backend_can_write (b_conn->b, b_conn->conn);
}
static int
next_can_flush (void *nxdata)
{
struct b_conn *b_conn = nxdata;
- return b_conn->b->can_flush (b_conn->b, b_conn->conn);
+ return backend_can_flush (b_conn->b, b_conn->conn);
}
static int
next_is_rotational (void *nxdata)
{
struct b_conn *b_conn = nxdata;
- return b_conn->b->is_rotational (b_conn->b, b_conn->conn);
+ return backend_is_rotational (b_conn->b, b_conn->conn);
}
static int
next_can_trim (void *nxdata)
{
struct b_conn *b_conn = nxdata;
- return b_conn->b->can_trim (b_conn->b, b_conn->conn);
+ return backend_can_trim (b_conn->b, b_conn->conn);
}
static int
next_can_zero (void *nxdata)
{
struct b_conn *b_conn = nxdata;
- return b_conn->b->can_zero (b_conn->b, b_conn->conn);
+ return backend_can_zero (b_conn->b, b_conn->conn);
}
static int
next_can_extents (void *nxdata)
{
struct b_conn *b_conn = nxdata;
- return b_conn->b->can_extents (b_conn->b, b_conn->conn);
+ return backend_can_extents (b_conn->b, b_conn->conn);
}
static int
next_can_fua (void *nxdata)
{
struct b_conn *b_conn = nxdata;
- return b_conn->b->can_fua (b_conn->b, b_conn->conn);
+ return backend_can_fua (b_conn->b, b_conn->conn);
}
static int
next_can_multi_conn (void *nxdata)
{
struct b_conn *b_conn = nxdata;
- return b_conn->b->can_multi_conn (b_conn->b, b_conn->conn);
+ return backend_can_multi_conn (b_conn->b, b_conn->conn);
}
static int
next_can_cache (void *nxdata)
{
struct b_conn *b_conn = nxdata;
- return b_conn->b->can_cache (b_conn->b, b_conn->conn);
+ return backend_can_cache (b_conn->b, b_conn->conn);
}
static int
@@ -315,13 +315,8 @@ next_pread (void *nxdata, void *buf, uint32_t count, uint64_t
offset,
uint32_t flags, int *err)
{
struct b_conn *b_conn = nxdata;
- int r;
-
- r = b_conn->b->pread (b_conn->b, b_conn->conn, buf, count, offset, flags,
+ return backend_pread (b_conn->b, b_conn->conn, buf, count, offset, flags,
err);
- if (r == -1)
- assert (*err);
- return r;
}
static int
@@ -329,25 +324,15 @@ next_pwrite (void *nxdata, const void *buf, uint32_t count, uint64_t
offset,
uint32_t flags, int *err)
{
struct b_conn *b_conn = nxdata;
- int r;
-
- r = b_conn->b->pwrite (b_conn->b, b_conn->conn, buf, count, offset, flags,
+ return backend_pwrite (b_conn->b, b_conn->conn, buf, count, offset, flags,
err);
- if (r == -1)
- assert (*err);
- return r;
}
static int
next_flush (void *nxdata, uint32_t flags, int *err)
{
struct b_conn *b_conn = nxdata;
- int r;
-
- r = b_conn->b->flush (b_conn->b, b_conn->conn, flags, err);
- if (r == -1)
- assert (*err);
- return r;
+ return backend_flush (b_conn->b, b_conn->conn, flags, err);
}
static int
@@ -355,12 +340,7 @@ next_trim (void *nxdata, uint32_t count, uint64_t offset, uint32_t
flags,
int *err)
{
struct b_conn *b_conn = nxdata;
- int r;
-
- r = b_conn->b->trim (b_conn->b, b_conn->conn, count, offset, flags, err);
- if (r == -1)
- assert (*err);
- return r;
+ return backend_trim (b_conn->b, b_conn->conn, count, offset, flags, err);
}
static int
@@ -368,12 +348,7 @@ next_zero (void *nxdata, uint32_t count, uint64_t offset, uint32_t
flags,
int *err)
{
struct b_conn *b_conn = nxdata;
- int r;
-
- r = b_conn->b->zero (b_conn->b, b_conn->conn, count, offset, flags, err);
- if (r == -1)
- assert (*err && *err != ENOTSUP && *err != EOPNOTSUPP);
- return r;
+ return backend_zero (b_conn->b, b_conn->conn, count, offset, flags, err);
}
static int
@@ -381,13 +356,8 @@ next_extents (void *nxdata, uint32_t count, uint64_t offset, uint32_t
flags,
struct nbdkit_extents *extents, int *err)
{
struct b_conn *b_conn = nxdata;
- int r;
-
- r = b_conn->b->extents (b_conn->b, b_conn->conn, count, offset, flags,
+ return backend_extents (b_conn->b, b_conn->conn, count, offset, flags,
extents, err);
- if (r == -1)
- assert (*err);
- return r;
}
static int
@@ -395,12 +365,7 @@ next_cache (void *nxdata, uint32_t count, uint64_t offset,
uint32_t flags, int *err)
{
struct b_conn *b_conn = nxdata;
- int r;
-
- r = b_conn->b->cache (b_conn->b, b_conn->conn, count, offset, flags, err);
- if (r == -1)
- assert (*err);
- return r;
+ return backend_cache (b_conn->b, b_conn->conn, count, offset, flags, err);
}
static struct nbdkit_next_ops next_ops = {
@@ -471,12 +436,10 @@ filter_get_size (struct backend *b, struct connection *conn)
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- debug ("%s: get_size", b->name);
-
if (f->filter.get_size)
return f->filter.get_size (&next_ops, &nxdata, handle);
else
- return b->next->get_size (b->next, conn);
+ return backend_get_size (b->next, conn);
}
static int
@@ -486,12 +449,10 @@ filter_can_write (struct backend *b, struct connection *conn)
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- debug ("%s: can_write", b->name);
-
if (f->filter.can_write)
return f->filter.can_write (&next_ops, &nxdata, handle);
else
- return b->next->can_write (b->next, conn);
+ return backend_can_write (b->next, conn);
}
static int
@@ -501,12 +462,10 @@ filter_can_flush (struct backend *b, struct connection *conn)
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- debug ("%s: can_flush", b->name);
-
if (f->filter.can_flush)
return f->filter.can_flush (&next_ops, &nxdata, handle);
else
- return b->next->can_flush (b->next, conn);
+ return backend_can_flush (b->next, conn);
}
static int
@@ -516,12 +475,10 @@ filter_is_rotational (struct backend *b, struct connection *conn)
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- debug ("%s: is_rotational", b->name);
-
if (f->filter.is_rotational)
return f->filter.is_rotational (&next_ops, &nxdata, handle);
else
- return b->next->is_rotational (b->next, conn);
+ return backend_is_rotational (b->next, conn);
}
static int
@@ -531,12 +488,10 @@ filter_can_trim (struct backend *b, struct connection *conn)
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- debug ("%s: can_trim", b->name);
-
if (f->filter.can_trim)
return f->filter.can_trim (&next_ops, &nxdata, handle);
else
- return b->next->can_trim (b->next, conn);
+ return backend_can_trim (b->next, conn);
}
static int
@@ -546,12 +501,10 @@ filter_can_zero (struct backend *b, struct connection *conn)
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- debug ("%s: can_zero", b->name);
-
if (f->filter.can_zero)
return f->filter.can_zero (&next_ops, &nxdata, handle);
else
- return b->next->can_zero (b->next, conn);
+ return backend_can_zero (b->next, conn);
}
static int
@@ -561,12 +514,10 @@ filter_can_extents (struct backend *b, struct connection *conn)
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- debug ("%s: can_extents", b->name);
-
if (f->filter.can_extents)
return f->filter.can_extents (&next_ops, &nxdata, handle);
else
- return b->next->can_extents (b->next, conn);
+ return backend_can_extents (b->next, conn);
}
static int
@@ -576,12 +527,10 @@ filter_can_fua (struct backend *b, struct connection *conn)
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- debug ("%s: can_fua", b->name);
-
if (f->filter.can_fua)
return f->filter.can_fua (&next_ops, &nxdata, handle);
else
- return b->next->can_fua (b->next, conn);
+ return backend_can_fua (b->next, conn);
}
static int
@@ -591,12 +540,10 @@ filter_can_multi_conn (struct backend *b, struct connection *conn)
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- debug ("%s: can_multi_conn", b->name);
-
if (f->filter.can_multi_conn)
return f->filter.can_multi_conn (&next_ops, &nxdata, handle);
else
- return b->next->can_multi_conn (b->next, conn);
+ return backend_can_multi_conn (b->next, conn);
}
static int
@@ -606,12 +553,10 @@ filter_can_cache (struct backend *b, struct connection *conn)
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- debug ("%s: can_cache", b->name);
-
if (f->filter.can_cache)
return f->filter.can_cache (&next_ops, &nxdata, handle);
else
- return b->next->can_cache (b->next, conn);
+ return backend_can_cache (b->next, conn);
}
static int
@@ -623,16 +568,11 @@ filter_pread (struct backend *b, struct connection *conn,
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- assert (flags == 0);
-
- debug ("%s: pread count=%" PRIu32 " offset=%" PRIu64 "
flags=0x%" PRIx32,
- b->name, count, offset, flags);
-
if (f->filter.pread)
return f->filter.pread (&next_ops, &nxdata, handle,
buf, count, offset, flags, err);
else
- return b->next->pread (b->next, conn, buf, count, offset, flags, err);
+ return backend_pread (b->next, conn, buf, count, offset, flags, err);
}
static int
@@ -644,16 +584,11 @@ filter_pwrite (struct backend *b, struct connection *conn,
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- assert (!(flags & ~NBDKIT_FLAG_FUA));
-
- debug ("%s: pwrite count=%" PRIu32 " offset=%" PRIu64 "
flags=0x%" PRIx32,
- b->name, count, offset, flags);
-
if (f->filter.pwrite)
return f->filter.pwrite (&next_ops, &nxdata, handle,
buf, count, offset, flags, err);
else
- return b->next->pwrite (b->next, conn, buf, count, offset, flags, err);
+ return backend_pwrite (b->next, conn, buf, count, offset, flags, err);
}
static int
@@ -664,14 +599,10 @@ filter_flush (struct backend *b, struct connection *conn, uint32_t
flags,
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- assert (flags == 0);
-
- debug ("%s: flush flags=0x%" PRIx32, b->name, flags);
-
if (f->filter.flush)
return f->filter.flush (&next_ops, &nxdata, handle, flags, err);
else
- return b->next->flush (b->next, conn, flags, err);
+ return backend_flush (b->next, conn, flags, err);
}
static int
@@ -683,16 +614,11 @@ filter_trim (struct backend *b, struct connection *conn,
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- assert (flags == 0);
-
- debug ("%s: trim count=%" PRIu32 " offset=%" PRIu64 "
flags=0x%" PRIx32,
- b->name, count, offset, flags);
-
if (f->filter.trim)
return f->filter.trim (&next_ops, &nxdata, handle, count, offset, flags,
err);
else
- return b->next->trim (b->next, conn, count, offset, flags, err);
+ return backend_trim (b->next, conn, count, offset, flags, err);
}
static int
@@ -703,16 +629,11 @@ filter_zero (struct backend *b, struct connection *conn,
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- assert (!(flags & ~(NBDKIT_FLAG_MAY_TRIM | NBDKIT_FLAG_FUA)));
-
- debug ("%s: zero count=%" PRIu32 " offset=%" PRIu64 "
flags=0x%" PRIx32,
- b->name, count, offset, flags);
-
if (f->filter.zero)
return f->filter.zero (&next_ops, &nxdata, handle,
count, offset, flags, err);
else
- return b->next->zero (b->next, conn, count, offset, flags, err);
+ return backend_zero (b->next, conn, count, offset, flags, err);
}
static int
@@ -724,18 +645,13 @@ filter_extents (struct backend *b, struct connection *conn,
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- assert (!(flags & ~NBDKIT_FLAG_REQ_ONE));
-
- debug ("%s: extents count=%" PRIu32 " offset=%" PRIu64 "
flags=0x%" PRIx32,
- b->name, count, offset, flags);
-
if (f->filter.extents)
return f->filter.extents (&next_ops, &nxdata, handle,
count, offset, flags,
extents, err);
else
- return b->next->extents (b->next, conn, count, offset, flags,
- extents, err);
+ return backend_extents (b->next, conn, count, offset, flags,
+ extents, err);
}
static int
@@ -747,16 +663,12 @@ filter_cache (struct backend *b, struct connection *conn,
void *handle = connection_get_handle (conn, b->i);
struct b_conn nxdata = { .b = b->next, .conn = conn };
- assert (flags == 0);
-
- debug ("%s: cache count=%" PRIu32 " offset=%" PRIu64 "
flags=0x%" PRIx32,
- b->name, count, offset, flags);
if (f->filter.cache)
return f->filter.cache (&next_ops, &nxdata, handle,
count, offset, flags, err);
else
- return b->next->cache (b->next, conn, count, offset, flags, err);
+ return backend_cache (b->next, conn, count, offset, flags, err);
}
static struct backend filter_functions = {
diff --git a/server/plugins.c b/server/plugins.c
index 0f70ede0..da8931a3 100644
--- a/server/plugins.c
+++ b/server/plugins.c
@@ -295,8 +295,6 @@ plugin_get_size (struct backend *b, struct connection *conn)
assert (connection_get_handle (conn, 0));
assert (p->plugin.get_size != NULL);
- debug ("get_size");
-
return p->plugin.get_size (connection_get_handle (conn, 0));
}
@@ -307,8 +305,6 @@ plugin_can_write (struct backend *b, struct connection *conn)
assert (connection_get_handle (conn, 0));
- debug ("can_write");
-
if (p->plugin.can_write)
return p->plugin.can_write (connection_get_handle (conn, 0));
else
@@ -322,8 +318,6 @@ plugin_can_flush (struct backend *b, struct connection *conn)
assert (connection_get_handle (conn, 0));
- debug ("can_flush");
-
if (p->plugin.can_flush)
return p->plugin.can_flush (connection_get_handle (conn, 0));
else
@@ -337,8 +331,6 @@ plugin_is_rotational (struct backend *b, struct connection *conn)
assert (connection_get_handle (conn, 0));
- debug ("is_rotational");
-
if (p->plugin.is_rotational)
return p->plugin.is_rotational (connection_get_handle (conn, 0));
else
@@ -352,8 +344,6 @@ plugin_can_trim (struct backend *b, struct connection *conn)
assert (connection_get_handle (conn, 0));
- debug ("can_trim");
-
if (p->plugin.can_trim)
return p->plugin.can_trim (connection_get_handle (conn, 0));
else
@@ -367,8 +357,6 @@ plugin_can_zero (struct backend *b, struct connection *conn)
assert (connection_get_handle (conn, 0));
- debug ("can_zero");
-
/* Note the special case here: the plugin's .can_zero controls only
* whether we call .zero; while the backend expects .can_zero to
* return whether to advertise zero support. Since we ALWAYS know
@@ -388,8 +376,6 @@ plugin_can_extents (struct backend *b, struct connection *conn)
assert (connection_get_handle (conn, 0));
- debug ("can_extents");
-
if (p->plugin.can_extents)
return p->plugin.can_extents (connection_get_handle (conn, 0));
else
@@ -404,8 +390,6 @@ plugin_can_fua (struct backend *b, struct connection *conn)
assert (connection_get_handle (conn, 0));
- debug ("can_fua");
-
/* The plugin must use API version 2 and have .can_fua return
NBDKIT_FUA_NATIVE before we will pass the FUA flag on. */
if (p->plugin.can_fua) {
@@ -427,8 +411,6 @@ plugin_can_multi_conn (struct backend *b, struct connection *conn)
assert (connection_get_handle (conn, 0));
- debug ("can_multi_conn");
-
if (p->plugin.can_multi_conn)
return p->plugin.can_multi_conn (connection_get_handle (conn, 0));
else
@@ -442,8 +424,6 @@ plugin_can_cache (struct backend *b, struct connection *conn)
assert (connection_get_handle (conn, 0));
- debug ("can_cache");
-
if (p->plugin.can_cache)
return p->plugin.can_cache (connection_get_handle (conn, 0));
if (p->plugin.cache)
@@ -482,9 +462,6 @@ plugin_pread (struct backend *b, struct connection *conn,
assert (connection_get_handle (conn, 0));
assert (p->plugin.pread || p->plugin._pread_old);
- assert (!flags);
-
- debug ("pread count=%" PRIu32 " offset=%" PRIu64, count, offset);
if (p->plugin.pread)
r = p->plugin.pread (connection_get_handle (conn, 0), buf, count, offset,
@@ -507,8 +484,6 @@ plugin_flush (struct backend *b, struct connection *conn, uint32_t
flags,
assert (connection_get_handle (conn, 0));
assert (!flags);
- debug ("flush");
-
if (p->plugin.flush)
r = p->plugin.flush (connection_get_handle (conn, 0), 0);
else if (p->plugin._flush_old)
@@ -533,10 +508,6 @@ plugin_pwrite (struct backend *b, struct connection *conn,
bool need_flush = false;
assert (connection_get_handle (conn, 0));
- assert (!(flags & ~NBDKIT_FLAG_FUA));
-
- debug ("pwrite count=%" PRIu32 " offset=%" PRIu64 "
fua=%d", count, offset,
- fua);
if (fua && plugin_can_fua (b, conn) != NBDKIT_FUA_NATIVE) {
flags &= ~NBDKIT_FLAG_FUA;
@@ -569,10 +540,6 @@ plugin_trim (struct backend *b, struct connection *conn,
bool need_flush = false;
assert (connection_get_handle (conn, 0));
- assert (!(flags & ~NBDKIT_FLAG_FUA));
-
- debug ("trim count=%" PRIu32 " offset=%" PRIu64 "
fua=%d", count, offset,
- fua);
if (fua && plugin_can_fua (b, conn) != NBDKIT_FUA_NATIVE) {
flags &= ~NBDKIT_FLAG_FUA;
@@ -606,10 +573,6 @@ plugin_zero (struct backend *b, struct connection *conn,
int can_zero = 1; /* TODO cache this per-connection? */
assert (connection_get_handle (conn, 0));
- assert (!(flags & ~(NBDKIT_FLAG_MAY_TRIM | NBDKIT_FLAG_FUA)));
-
- debug ("zero count=%" PRIu32 " offset=%" PRIu64 " may_trim=%d
fua=%d",
- count, offset, may_trim, fua);
if (fua && plugin_can_fua (b, conn) != NBDKIT_FUA_NATIVE) {
flags &= ~NBDKIT_FLAG_FUA;
@@ -670,21 +633,13 @@ plugin_extents (struct backend *b, struct connection *conn,
struct nbdkit_extents *extents, int *err)
{
struct backend_plugin *p = container_of (b, struct backend_plugin, backend);
- bool req_one = flags & NBDKIT_FLAG_REQ_ONE;
int r;
assert (connection_get_handle (conn, 0));
- assert (!(flags & ~NBDKIT_FLAG_REQ_ONE));
/* This should be true because plugin_can_extents checks it. */
assert (p->plugin.extents);
- debug ("extents count=%" PRIu32 " offset=%" PRIu64 "
req_one=%d",
- count, offset, req_one);
-
- if (!count)
- return 0;
-
r = p->plugin.extents (connection_get_handle (conn, 0), count, offset,
flags, extents);
if (r >= 0 && nbdkit_extents_count (extents) < 1) {
@@ -706,9 +661,6 @@ plugin_cache (struct backend *b, struct connection *conn,
int r;
assert (connection_get_handle (conn, 0));
- assert (!flags);
-
- debug ("cache count=%" PRIu32 " offset=%" PRIu64, count, offset);
/* A plugin may advertise caching but not provide .cache; in that
* case, caching is explicitly a no-op. */
diff --git a/server/protocol-handshake-newstyle.c b/server/protocol-handshake-newstyle.c
index 6ccb76f3..28817317 100644
--- a/server/protocol-handshake-newstyle.c
+++ b/server/protocol-handshake-newstyle.c
@@ -205,7 +205,7 @@ finish_newstyle_options (struct connection *conn)
{
int64_t r;
- r = backend->get_size (backend, conn);
+ r = backend_get_size (backend, conn);
if (r == -1)
return -1;
if (r < 0) {
diff --git a/server/protocol-handshake-oldstyle.c b/server/protocol-handshake-oldstyle.c
index 9fde1ca0..af3ac488 100644
--- a/server/protocol-handshake-oldstyle.c
+++ b/server/protocol-handshake-oldstyle.c
@@ -59,7 +59,7 @@ protocol_handshake_oldstyle (struct connection *conn)
return -1;
}
- r = backend->get_size (backend, conn);
+ r = backend_get_size (backend, conn);
if (r == -1)
return -1;
if (r < 0) {
diff --git a/server/protocol-handshake.c b/server/protocol-handshake.c
index 0f3bd280..4d12b3dc 100644
--- a/server/protocol-handshake.c
+++ b/server/protocol-handshake.c
@@ -52,7 +52,7 @@ protocol_compute_eflags (struct connection *conn, uint16_t *flags)
uint16_t eflags = NBD_FLAG_HAS_FLAGS;
int fl;
- fl = backend->can_write (backend, conn);
+ fl = backend_can_write (backend, conn);
if (fl == -1)
return -1;
if (readonly || !fl) {
@@ -60,7 +60,7 @@ protocol_compute_eflags (struct connection *conn, uint16_t *flags)
conn->readonly = true;
}
if (!conn->readonly) {
- fl = backend->can_zero (backend, conn);
+ fl = backend_can_zero (backend, conn);
if (fl == -1)
return -1;
if (fl) {
@@ -68,7 +68,7 @@ protocol_compute_eflags (struct connection *conn, uint16_t *flags)
conn->can_zero = true;
}
- fl = backend->can_trim (backend, conn);
+ fl = backend_can_trim (backend, conn);
if (fl == -1)
return -1;
if (fl) {
@@ -76,7 +76,7 @@ protocol_compute_eflags (struct connection *conn, uint16_t *flags)
conn->can_trim = true;
}
- fl = backend->can_fua (backend, conn);
+ fl = backend_can_fua (backend, conn);
if (fl == -1)
return -1;
if (fl) {
@@ -85,7 +85,7 @@ protocol_compute_eflags (struct connection *conn, uint16_t *flags)
}
}
- fl = backend->can_flush (backend, conn);
+ fl = backend_can_flush (backend, conn);
if (fl == -1)
return -1;
if (fl) {
@@ -93,7 +93,7 @@ protocol_compute_eflags (struct connection *conn, uint16_t *flags)
conn->can_flush = true;
}
- fl = backend->is_rotational (backend, conn);
+ fl = backend_is_rotational (backend, conn);
if (fl == -1)
return -1;
if (fl) {
@@ -104,7 +104,7 @@ protocol_compute_eflags (struct connection *conn, uint16_t *flags)
/* multi-conn is useless if parallel connections are not allowed */
if (backend->thread_model (backend) >
NBDKIT_THREAD_MODEL_SERIALIZE_CONNECTIONS) {
- fl = backend->can_multi_conn (backend, conn);
+ fl = backend_can_multi_conn (backend, conn);
if (fl == -1)
return -1;
if (fl) {
@@ -113,7 +113,7 @@ protocol_compute_eflags (struct connection *conn, uint16_t *flags)
}
}
- fl = backend->can_cache (backend, conn);
+ fl = backend_can_cache (backend, conn);
if (fl == -1)
return -1;
if (fl) {
@@ -127,7 +127,7 @@ protocol_compute_eflags (struct connection *conn, uint16_t *flags)
* per connection and store the result in the handle anyway. This
* protocol_compute_eflags function is a bit misnamed XXX.
*/
- fl = backend->can_extents (backend, conn);
+ fl = backend_can_extents (backend, conn);
if (fl == -1)
return -1;
if (fl)
diff --git a/server/protocol.c b/server/protocol.c
index 72f6f2a8..72efcaa6 100644
--- a/server/protocol.c
+++ b/server/protocol.c
@@ -240,35 +240,27 @@ handle_request (struct connection *conn,
switch (cmd) {
case NBD_CMD_READ:
- if (backend->pread (backend, conn, buf, count, offset, 0, &err) == -1) {
- assert (err);
+ if (backend_pread (backend, conn, buf, count, offset, 0, &err) == -1)
return err;
- }
break;
case NBD_CMD_WRITE:
if (fua)
f |= NBDKIT_FLAG_FUA;
- if (backend->pwrite (backend, conn, buf, count, offset, f, &err) == -1) {
- assert (err);
+ if (backend_pwrite (backend, conn, buf, count, offset, f, &err) == -1)
return err;
- }
break;
case NBD_CMD_FLUSH:
- if (backend->flush (backend, conn, 0, &err) == -1) {
- assert (err);
+ if (backend_flush (backend, conn, 0, &err) == -1)
return err;
- }
break;
case NBD_CMD_TRIM:
if (fua)
f |= NBDKIT_FLAG_FUA;
- if (backend->trim (backend, conn, count, offset, f, &err) == -1) {
- assert (err);
+ if (backend_trim (backend, conn, count, offset, f, &err) == -1)
return err;
- }
break;
case NBD_CMD_CACHE:
@@ -278,18 +270,14 @@ handle_request (struct connection *conn,
while (count) {
limit = MIN (count, sizeof buf);
- if (backend->pread (backend, conn, buf, limit, offset, flags,
- &err) == -1) {
- assert (err);
+ if (backend_pread (backend, conn, buf, limit, offset, flags,
+ &err) == -1)
return err;
- }
count -= limit;
}
}
- else if (backend->cache (backend, conn, count, offset, 0, &err) == -1) {
- assert (err);
+ else if (backend_cache (backend, conn, count, offset, 0, &err) == -1)
return err;
- }
break;
case NBD_CMD_WRITE_ZEROES:
@@ -297,10 +285,8 @@ handle_request (struct connection *conn,
f |= NBDKIT_FLAG_MAY_TRIM;
if (fua)
f |= NBDKIT_FLAG_FUA;
- if (backend->zero (backend, conn, count, offset, f, &err) == -1) {
- assert (err && err != ENOTSUP && err != EOPNOTSUPP);
+ if (backend_zero (backend, conn, count, offset, f, &err) == -1)
return err;
- }
break;
case NBD_CMD_BLOCK_STATUS:
@@ -312,11 +298,9 @@ handle_request (struct connection *conn,
if (conn->can_extents) {
if (flags & NBD_CMD_FLAG_REQ_ONE)
f |= NBDKIT_FLAG_REQ_ONE;
- if (backend->extents (backend, conn, count, offset, f,
- extents, &err) == -1) {
- assert (err);
+ if (backend_extents (backend, conn, count, offset, f,
+ extents, &err) == -1)
return err;
- }
}
else {
int r;
diff --git a/tests/test-layers.c b/tests/test-layers.c
index 6617cd73..a7184d72 100644
--- a/tests/test-layers.c
+++ b/tests/test-layers.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
@@ -400,13 +400,13 @@ main (int argc, char *argv[])
sleep (1);
log_verify_seen_in_order
- ("testlayersfilter3: pread count=512 offset=0 flags=0x0",
+ ("testlayersfilter3: pread count=512 offset=0",
"filter3: test_layers_filter_pread",
- "testlayersfilter2: pread count=512 offset=0 flags=0x0",
+ "testlayersfilter2: pread count=512 offset=0",
"filter2: test_layers_filter_pread",
- "testlayersfilter1: pread count=512 offset=0 flags=0x0",
+ "testlayersfilter1: pread count=512 offset=0",
"filter1: test_layers_filter_pread",
- "testlayersplugin: debug: pread count=512 offset=0",
+ "testlayersplugin: pread count=512 offset=0",
"test_layers_plugin_pread",
NULL);
@@ -434,13 +434,13 @@ main (int argc, char *argv[])
sleep (1);
log_verify_seen_in_order
- ("testlayersfilter3: pwrite count=512 offset=0 flags=0x0",
+ ("testlayersfilter3: pwrite count=512 offset=0 fua=0",
"filter3: test_layers_filter_pwrite",
- "testlayersfilter2: pwrite count=512 offset=0 flags=0x0",
+ "testlayersfilter2: pwrite count=512 offset=0 fua=0",
"filter2: test_layers_filter_pwrite",
- "testlayersfilter1: pwrite count=512 offset=0 flags=0x0",
+ "testlayersfilter1: pwrite count=512 offset=0 fua=0",
"filter1: test_layers_filter_pwrite",
- "testlayersplugin: debug: pwrite count=512 offset=0",
+ "testlayersplugin: pwrite count=512 offset=0 fua=0",
"test_layers_plugin_pwrite",
NULL);
@@ -464,13 +464,13 @@ main (int argc, char *argv[])
sleep (1);
log_verify_seen_in_order
- ("testlayersfilter3: flush flags=0x0",
+ ("testlayersfilter3: flush",
"filter3: test_layers_filter_flush",
- "testlayersfilter2: flush flags=0x0",
+ "testlayersfilter2: flush",
"filter2: test_layers_filter_flush",
- "testlayersfilter1: flush flags=0x0",
+ "testlayersfilter1: flush",
"filter1: test_layers_filter_flush",
- "testlayersplugin: debug: flush",
+ "testlayersplugin: flush",
"test_layers_plugin_flush",
NULL);
@@ -494,13 +494,13 @@ main (int argc, char *argv[])
sleep (1);
log_verify_seen_in_order
- ("testlayersfilter3: trim count=512 offset=0 flags=0x0",
+ ("testlayersfilter3: trim count=512 offset=0 fua=0",
"filter3: test_layers_filter_trim",
- "testlayersfilter2: trim count=512 offset=0 flags=0x0",
+ "testlayersfilter2: trim count=512 offset=0 fua=0",
"filter2: test_layers_filter_trim",
- "testlayersfilter1: trim count=512 offset=0 flags=0x0",
+ "testlayersfilter1: trim count=512 offset=0 fua=0",
"filter1: test_layers_filter_trim",
- "testlayersplugin: debug: trim count=512 offset=0",
+ "testlayersplugin: trim count=512 offset=0 fua=0",
"test_layers_plugin_trim",
NULL);
@@ -524,13 +524,13 @@ main (int argc, char *argv[])
sleep (1);
log_verify_seen_in_order
- ("testlayersfilter3: zero count=512 offset=0 flags=0x1",
+ ("testlayersfilter3: zero count=512 offset=0 may_trim=1 fua=0",
"filter3: test_layers_filter_zero",
- "testlayersfilter2: zero count=512 offset=0 flags=0x1",
+ "testlayersfilter2: zero count=512 offset=0 may_trim=1 fua=0",
"filter2: test_layers_filter_zero",
- "testlayersfilter1: zero count=512 offset=0 flags=0x1",
+ "testlayersfilter1: zero count=512 offset=0 may_trim=1 fua=0",
"filter1: test_layers_filter_zero",
- "testlayersplugin: debug: zero count=512 offset=0 may_trim=1 fua=0",
+ "testlayersplugin: zero count=512 offset=0 may_trim=1 fua=0",
"test_layers_plugin_zero",
NULL);
@@ -554,13 +554,13 @@ main (int argc, char *argv[])
sleep (1);
log_verify_seen_in_order
- ("testlayersfilter3: cache count=512 offset=0 flags=0x0",
+ ("testlayersfilter3: cache count=512 offset=0",
"filter3: test_layers_filter_cache",
- "testlayersfilter2: cache count=512 offset=0 flags=0x0",
+ "testlayersfilter2: cache count=512 offset=0",
"filter2: test_layers_filter_cache",
- "testlayersfilter1: cache count=512 offset=0 flags=0x0",
+ "testlayersfilter1: cache count=512 offset=0",
"filter1: test_layers_filter_cache",
- "testlayersplugin: debug: cache count=512 offset=0",
+ "testlayersplugin: cache count=512 offset=0",
"test_layers_plugin_cache",
NULL);
--
2.21.0