From: Maxim Uvarov <muvarov@ru.mvista.com>
To: Lars Ellenberg <lars.ellenberg@linbit.com>
Cc: drbd-dev@lists.linbit.com
Subject: Re: [Drbd-dev] [DRBD][PATCH] drbd_bitfild_endian.patch
Date: Mon, 26 Nov 2007 19:28:18 +0000 [thread overview]
Message-ID: <474B1E52.7090703@ru.mvista.com> (raw)
In-Reply-To: <20071126150621.GD14702@racke.local>
Lars Ellenberg wrote:
>On Mon, Nov 26, 2007 at 04:32:44PM +0000, Maxim Uvarov wrote:
>
>
>>Hello all,
>>
>>We have found that drbd state is passed incorrectly between machines
>>with different endianness.
>>Attached patch fixes this problem by converting bitfild to int.
>>
>>Replacing all bitfileds (both in kernel and userland) isn't safe way
>>(there are
>>about hundred lines to replace). Maybe adding converter from bitfield to
>>int32
>>is appropriate solution ? Then sending state we do
>>"drbd_state_to_int(state)"
>>and then receive we restore state by "int_to_drbd_state(i)". only 9 lines of
>>kernel code was changed (No need to change userspace). Additional
>>overhead is
>>neglible.
>>
>>
>
>right you are.
>but how about this instead:
>
>diff --git a/drbd/linux/drbd.h b/drbd/linux/drbd.h
>index b6ea313..ecf3a27 100644
>--- a/drbd/linux/drbd.h
>+++ b/drbd/linux/drbd.h
>@@ -28,6 +28,7 @@
> #include <linux/drbd_config.h>
>
> #include <asm/types.h>
>+#include <asm/byteorder.h>
>
> #ifdef __KERNEL__
> #include <linux/types.h>
>@@ -176,18 +177,39 @@ typedef enum {
> disk_mask=15
> } drbd_disks_t;
>
>+/* bitfields are not endian safe.
>+ * pointed out by Maxim Uvarov <muvarov@ru.mvista.com>
>+ * even though we transmit as "cpu_to_be32(state)",
>+ * the offsets of the bitfields still need to be swapped
>+ * on different endianess.
>+ */
> typedef union {
> struct {
>- unsigned role : 2 ; // 3/4 primary/secondary/unknown
>- unsigned peer : 2 ; // 3/4 primary/secondary/unknown
>- unsigned conn : 5 ; // 17/32 cstates
>- unsigned disk : 4 ; // 8/16 from Diskless to UpToDate
>- unsigned pdsk : 4 ; // 8/16 from Diskless to UpToDate
>- unsigned susp : 1 ; // 2/2 IO suspended no/yes
>- unsigned aftr_isp : 1 ; // isp .. imposed sync pause
>+#if defined(__LITTLE_ENDIAN)
>+ unsigned role : 2 ; /* 3/4 primary/secondary/unknown */
>+ unsigned peer : 2 ; /* 3/4 primary/secondary/unknown */
>+ unsigned conn : 5 ; /* 17/32 cstates */
>+ unsigned disk : 4 ; /* 8/16 from Diskless to UpToDate */
>+ unsigned pdsk : 4 ; /* 8/16 from Diskless to UpToDate */
>+ unsigned susp : 1 ; /* 2/2 IO suspended no/yes */
>+ unsigned aftr_isp : 1 ; /* isp .. imposed sync pause */
> unsigned peer_isp : 1 ;
> unsigned user_isp : 1 ;
>- unsigned _pad : 11; // 0 unused
>+ unsigned _pad : 11; /* 0 unused */
>+#elif defined(__BIG_ENDIAN)
>+ unsigned _pad : 11; /* 0 unused */
>+ unsigned user_isp : 1 ;
>+ unsigned peer_isp : 1 ;
>+ unsigned aftr_isp : 1 ; /* isp .. imposed sync pause */
>+ unsigned susp : 1 ; /* 2/2 IO suspended no/yes */
>+ unsigned pdsk : 4 ; /* 8/16 from Diskless to UpToDate */
>+ unsigned disk : 4 ; /* 8/16 from Diskless to UpToDate */
>+ unsigned conn : 5 ; /* 17/32 cstates */
>+ unsigned peer : 2 ; /* 3/4 primary/secondary/unknown */
>+ unsigned role : 2 ; /* 3/4 primary/secondary/unknown */
>+#else
>+# error "this endianess is not supported"
>+#endif
> };
> unsigned int i;
> } drbd_state_t;
>
>
>
>
Actually I did it at first time but condition was
__BIG_ENDIAN_BITFIELD. It require also changes
in default settings. And define _BITFIELD in user space. And this
version was denied by our architect with comment:
<cut>
Sending bit fields like this, unfortunately, is not portable. There is no
guarantee of bitfield layout event between compiler versions, let alone
between
different architectures even of the same endian-ness.
</cut>
So it's not good idea to depend on compiler version.
next prev parent reply other threads:[~2007-11-26 16:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-26 16:32 [Drbd-dev] [DRBD][PATCH] drbd_bitfild_endian.patch Maxim Uvarov
2007-11-26 15:06 ` Lars Ellenberg
2007-11-26 19:28 ` Maxim Uvarov [this message]
[not found] ` <474C12E0.6020306@ru.mvista.com>
2007-11-27 10:55 ` Lars Ellenberg
2007-12-03 16:52 ` Philipp Reisner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=474B1E52.7090703@ru.mvista.com \
--to=muvarov@ru.mvista.com \
--cc=drbd-dev@lists.linbit.com \
--cc=lars.ellenberg@linbit.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.