[Libguestfs] [nbdkit PATCH 4/7] nbd: Honor server global flags on little-endian

Eric Blake eblake at redhat.com
Tue Apr 23 00:50:23 UTC 2019


In the nbd plugin, I forgot to swap the server's global flags into
host endian order before checking which flags the server had set. As a
result, on little-endian machines, we were always replying with cflags
of 0 instead of the intended mirroring of the supported server flags,
although fortunately it made no real difference up to now (we were
never sending any option other than NBD_OPT_EXPORT_NAME, so not
mirroring NBD_FLAG_FIXED_NEWSTYLE had no effect; not mirroring
NBD_FLAG_NO_ZEROES merely means a longer handshake; and the NBD
protocol does not yet define flag 0x100 or 0x200 to confuse
us). However, once we add code for NBD_OPT_GO, it becomes essential to
get it right.

Fixes: 0e8e8eb1
Signed-off-by: Eric Blake <eblake at redhat.com>
---
 plugins/nbd/nbd.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/plugins/nbd/nbd.c b/plugins/nbd/nbd.c
index 72e833c..14e6806 100644
--- a/plugins/nbd/nbd.c
+++ b/plugins/nbd/nbd.c
@@ -512,6 +512,7 @@ nbd_open (int readonly)
       nbdkit_error ("unable to read global flags: %m");
       goto err;
     }
+    gflags = be16toh (gflags);
     cflags = htobe32(gflags & (NBD_FLAG_FIXED_NEWSTYLE | NBD_FLAG_NO_ZEROES));
     if (write_full (h->fd, &cflags, sizeof cflags)) {
       nbdkit_error ("unable to return global flags: %m");
-- 
2.20.1




More information about the Libguestfs mailing list