[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Nbd] gznbd endian fix



Hello all,

after many years of seeing a mysterious "Network Block Device" option
under kernel config I saw mention of it in an LWN comment and got curious
enough to investigate. I remember seeing that gznbd is considered
"experimental" but it's a nice simple example of a userspace program
talking to the nbd module. PPC being my platform of choice, I noticed an
endian problem because WORDS_BIGENDIAN wasn't getting defined like it was
in the main nbd server & client. My simple fix is just to use the common
headers that were set up for the right endianness by the configure script;
patch with this fix follows.

With this patch applied, gznbd seems to work ok, though I can definitely
see why it is deemed experimental... the gznbd.c comment "ro is important,
since writes will fail horribly" is no exaggeration; forgetting the ro
option in the mount results in failure & a kernel oops when attempting to
unmount the device. On the other hand, it's likely a problem in kernel
error recovery rather than a user-space bug, since gznbd returned a
read-only-filesystem error as seems appropriate.

BTW, let me know if patches are not welcome on this list. I did see a
patch submission thing at sourceforge, but it did not play well with my
browser of choice (lynx). At least this patch is tiny, so hopefully it
shouldn't offend anyone too badly...

--SJLC

--- gznbd.c.orig	2005-01-16 18:36:31.000000000 +0000
+++ gznbd.c	2005-01-22 11:11:29.363458552 +0000
@@ -52,30 +52,15 @@
 #define u32 __u32
 #define u64 __u64

-#include <linux/nbd.h>
+/* these headers take care of endianness */
+#include "../config.h"
+#include "../cliserv.h"

 #define BLOCK 1024

 /* don't ask me why this value, I only copied it */
 #define CHUNK BLOCK*20

-/* taken litterally from the original nbd */
-#ifdef WORDS_BIGENDIAN
-u64 ntohll(u64 a)
-{
-  return a;
-}
-#else
-u64 ntohll(u64 a)
-{
-  u32 lo = a & 0xffffffff;
-  u32 hi = a >> 32U;
-  lo = ntohl(lo);
-  hi = ntohl(hi);
-  return ((u64) lo) << 32U | hi;
-}
-#endif
-

 int main(int argc, char **argv)
 {



Reply to: