Correct definition of NBD_CMD_FLAG_FUA
PATCH 2/2 Correct definition of NBD_CMD_FLAG_FUA
NBD_CMD_FLAG_FUA is defined as 1<<0 in the documentation, but 1<<16 in nbd.h. It is not used anywhere within the code. 1<<16 cannot work as the flags word is only 16 bits long. It is doubtful whether anyone is using NBD_CMD_FLAG_FUA at the moment in any case.
--- nbd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
nbd.h +1 -1
@@ -38,7 +38,7 @@ enum { };#define NBD_CMD_MASK_COMMAND 0x0000ffff -#define NBD_CMD_FLAG_FUA (1<<16) +#define NBD_CMD_FLAG_FUA (1 << 0)/* values for flags field */ #define NBD_FLAG_HAS_FLAGS (1 << 0)/* Flags are there */
Signature · 1 line
1.9.1
Quoted 2 lines · Alex Bligh
It is doubtful whether anyone is using
NBD_CMD_FLAG_FUAat the moment in any case.
Drat. I spoke too soon. Qemu uses it, but presumably from its own .h file.
However, it's now nonsensical having it defined as 1<<16 in a 16 bit flags variable.
Should we produce a new name for it (and future command flags) that aren't shifted left 16 places, and just maintain the current value for compatibility?
Signature · 1 line
Alex Bligh
Quoted 8 lines · Alex Bligh
Quoted 2 lines · Alex Bligh
It is doubtful whether anyone is using
NBD_CMD_FLAG_FUAat the moment in any case.Drat. I spoke too soon. Qemu uses it, but presumably from its own .h file.
Yes, qemu has its own nbd.h, which still has nbd_request with a single uint32_type that holds both flags and command type. It wouldn't be too hard to rework that to more closely match upstream NBD.
Quoted 3 lines
However, it's now nonsensical having it defined as 1<<16 in a 16 bit flags variable.
I don't see any problem with your patch on the NBD project side of things; it's not like 'make install' is dumping a header into /usr/include for client programs to reuse (which is _why_ qemu is using its own nbd.h), because no one has really churned out an NBD-client library for embedding in larger programs.
Quoted 4 lines
Should we produce a new name for it (and future command flags) that aren't shifted left 16 places, and just maintain the current value for compatibility?
I don't see the point. Your fix looks correct.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 7 lines · Eric Blake
Quoted 5 lines
Should we produce a new name for it (and future command flags) that aren't shifted left 16 places, and just maintain the current value for compatibility?
I don't see the point. Your fix looks correct.
OK. And the wrongness hasn't yet got into /usr/include/linux/nbd.h or include/uapi/linux/nbd.h ; these have no reference to FUA at all, even though it does have NBD_FLAG_SEND_FLUSH, which is odd as I added both flags at the same time.
So I'm guessing it's safe.
--
Alex Bligh
Quoted 5 lines · Alex Bligh
Quoted 2 lines · Eric Blake
Quoted 2 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Should we produce a new name for it (and future command flags) that aren't shifted left 16 places, and just maintain the current value for compatibility?
I don't see the point. Your fix looks correct.
OK. And the wrongness hasn't yet got into
/usr/include/linux/nbd.h
Still using the older '__be32 type;' instead of the newer '__be16 flags; __be16 type;', changing that one will be ABI compatible, but not API compatible. I don't know what people want to do there, :(
Quoted 1 line
or
include/uapi/linux/nbd.h; these have no reference to FUA at all,
I'm not finding that file on my system; not sure what it contains, or where it is maintained.
Quoted 11 lines
even though it does have
NBD_FLAG_SEND_FLUSH, which is odd as I added both flags at the same time.So I'm guessing it's safe.
--
Alex Bligh
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 5 lines · Eric Blake
Quoted 2 lines
or
include/uapi/linux/nbd.h; these have no reference to FUA at all,I'm not finding that file on my system; not sure what it contains, or where it is maintained.
files have moved around in the kernel, and the userspace api file now lives in include/uapi/linux/nbd.h e.g:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/nbd.h
include/linux/nbd.h has gone from the kernel, and previously included internal structs (now in nbd.c I think)
Disclaimer: it's a while since I looked at nbd kernel side.
--
Alex Bligh
Quoted 2 lines · Alex Bligh
NBD_CMD_FLAG_FUAis defined as 1<<0 in the documentation, but 1<<16 innbd.h. It is not used anywhere within the code.
Yes it is:
wouter@gangtai:~/code/c/nbd$ grep -rl CMD_FLAG_FUA * doc/proto.md make-integrityhuge.c nbd.h nbd-server.c nbd-trdump.c tests/run/nbd-tester-client.c wouter@gangtai:~/code/c/nbd$
I don't mind bringing the code in sync with what the documentation says, but it should not change behaviour ;-)
Signature · 4 lines
< ron> I mean, the main *practical* problem with C++, is there's like a dozen
people in the world who think they really understand all of its rules,
and pretty much all of them are just lying to themselves too.
-- #debian-devel, OFTC, 2016-02-12Quoted 15 lines · Wouter Verhelst
Quoted 2 lines · Alex Bligh
NBD_CMD_FLAG_FUAis defined as 1<<0 in the documentation, but 1<<16 innbd.h. It is not used anywhere within the code.Yes it is:
wouter@gangtai:~/code/c/nbd$ grep -rl CMD_FLAG_FUA * doc/proto.md make-integrityhuge.c nbd.h nbd-server.c nbd-trdump.c tests/run/nbd-tester-client.c wouter@gangtai:~/code/c/nbd$
Quoted 2 lines
I don't mind bringing the code in sync with what the documentation says, but it should not change behaviour ;-)
Sorry - I think I must have done 'git grep' in the wrong directory or something. Ignore this patch and I'll redo it.
I think probably the easiest fix is (beware, manually generated untested patch) as follows, which at least shows the reason for the discrepancy.
nbd.h +0 -0
@@ -38,7 +38,9 @@ enum {
};
#define NBD_CMD_MASK_COMMAND 0x0000ffff -#define NBD_CMD_FLAG_FUA (1<<16)
+#define NBD_CMD_SHIFT (16)
+#define NBD_CMD_FLAG_FUA ((1 << 0) << NBD_CMD_SHIFT)
/* values for flags field */
#define NBD_FLAG_HAS_FLAGS (1 << 0) /* Flags are there */
Signature · 1 line
Alex Bligh
Review
Quoted 4 lines · Alex Bligh
#define
NBD_CMD_MASK_COMMAND0x0000ffff(quoted diff) +2
-1-#define NBD_CMD_FLAG_FUA (1<<16) +#define NBD_CMD_SHIFT (16) +#define NBD_CMD_FLAG_FUA ((1 << 0) << NBD_CMD_SHIFT)
That works too, I suppose.
However, like I said, I need to clean this up anyway. I thought your "will you take a patch" was going to do that, but if not, I'll get around to doing it myself at some point...
Signature · 4 lines
< ron> I mean, the main *practical* problem with C++, is there's like a dozen
people in the world who think they really understand all of its rules,
and pretty much all of them are just lying to themselves too.
-- #debian-devel, OFTC, 2016-02-12Quoted 11 lines · Wouter Verhelst
Review
Quoted 4 lines · Alex Bligh
#define
NBD_CMD_MASK_COMMAND0x0000ffff(quoted diff) +2
-1-#define NBD_CMD_FLAG_FUA (1<<16) +#define NBD_CMD_SHIFT (16) +#define NBD_CMD_FLAG_FUA ((1 << 0) << NBD_CMD_SHIFT)That works too, I suppose.
However, like I said, I need to clean this up anyway. I thought your "will you take a patch" was going to do that, but if not, I'll get around to doing it myself at some point...
How about you take that one for now and one of us will get do doing it properly in due course. The proper solution is obviously to use two 16 bit fields.
Signature · 1 line
Alex Bligh