When nbdcopy was first written (commit 48d1e206 is in v1.7.2),
nbd_can_meta_context() could not fail. Likewise for nbdinfo --map
(earlier than commit 8f30c47 in v1.7.12). But more recently, v1.15.3
made it possible to return an error, and our return conversion of -1
to bool then behaves as if the meta context is available. More
specifically, when talking to a source server that has structured
replies but lacks meta context support (nbd-server 3.25), this causes
nbdcopy to then fail with an odd error message (possibly displayed
more than once, depending on how fast multi-threading tackles the
problem):
nbd://localhost:10811: nbd_block_status_64: did not negotiate any metadata contexts,
either you did not call nbd_add_meta_context before connecting or the server does not
support it: Operation not supported
With this patch, nbdcopy now works on nbd-server as source; meanwhile,
nbdinfo --map still gives an error, but it is now more legible:
/home/eblake/libnbd/info/.libs/nbdinfo: --map: server does not support metadata context
"base:allocation"
An audit of other in-tree clients, such as nbddump, found that they
were already correctly checking for failures.
The next patch will fix the regression in nbd_can_meta_context()
behavior for returning an error in the first place; but the later
testsuite addition can be shuffled around in the patch series to show
that this change in isolation makes nbdcopy more robust despite the
API regression.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
copy/nbd-ops.c | 2 +-
info/map.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/copy/nbd-ops.c b/copy/nbd-ops.c
index 71ee0a3b..fd42fd19 100644
--- a/copy/nbd-ops.c
+++ b/copy/nbd-ops.c
@@ -236,7 +236,7 @@ nbd_ops_can_extents (struct rw *rw)
struct rw_nbd *rwn = (struct rw_nbd *)rw;
if (rwn->handles.len > 0)
- return nbd_can_meta_context (rwn->handles.ptr[0], "base:allocation");
+ return nbd_can_meta_context (rwn->handles.ptr[0], "base:allocation")
> 0;
else
return false;
}
diff --git a/info/map.c b/info/map.c
index 399e0355..d17cdd06 100644
--- a/info/map.c
+++ b/info/map.c
@@ -62,7 +62,7 @@ do_map (void)
}
/* Did we get the requested map? */
- if (!nbd_can_meta_context (nbd, map)) {
+ if (nbd_can_meta_context (nbd, map) <= 0) {
fprintf (stderr,
"%s: --map: server does not support metadata context
\"%s\"\n",
progname, map);
--
2.43.2