[sheepdog] [PATCH 2/2] misc: check 64-bit alignment of structs for message

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Tue Mar 19 05:23:39 CET 2013


At Tue, 19 Mar 2013 13:03:47 +0900,
Hitoshi Mitake wrote:
> 
> This patch adds check of alignment of structs defined in
> internal_proto.h. check_alignment_of_structs() does that but this
> function doesn't have to becalled. The checking is done in build time.
> 
> Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
> ---
>  include/internal_proto.h |   23 +++++++++++++++++++++++
>  1 files changed, 23 insertions(+), 0 deletions(-)
> 
> diff --git a/include/internal_proto.h b/include/internal_proto.h
> index 6f1fdb3..ff61cec 100644
> --- a/include/internal_proto.h
> +++ b/include/internal_proto.h
> @@ -20,6 +20,8 @@
>  #include <stdint.h>
>  #include <netinet/in.h>
>  
> +#include "util.h"
> +
>  #define SD_SHEEP_PROTO_VER 0x07
>  
>  #define SD_DEFAULT_COPIES 3
> @@ -229,4 +231,25 @@ struct vdi_op_message {
>  	uint8_t data[0];
>  };
>  
> +static inline void check_alignment_of_structs(void)
> +{
> +	/*
> +	 * This function doesn't have to be called.
> +	 * It does only checking of size of the below structs with
> +	 * BUILD_BUG_ON(). They must be aligned with 64bit.
> +	 */
> +	BUILD_BUG_ON(sizeof(struct sd_so_req) % 8);
> +	BUILD_BUG_ON(sizeof(struct sd_so_rsp) % 8);
> +	BUILD_BUG_ON(sizeof(struct sd_list_req) % 8);
> +	BUILD_BUG_ON(sizeof(struct sd_list_rsp) % 8);
> +	BUILD_BUG_ON(sizeof(struct sd_node_req) % 8);
> +	BUILD_BUG_ON(sizeof(struct sd_node_rsp) % 8);
> +
> +	BUILD_BUG_ON(sizeof(struct node_id) % 8);
> +	BUILD_BUG_ON(sizeof(struct sd_node) % 8);
> +	BUILD_BUG_ON(sizeof(struct epoch_log) % 8);
> +	BUILD_BUG_ON(sizeof(struct join_message) % 8);
> +	BUILD_BUG_ON(sizeof(struct vdi_op_message) % 8);
> +}
> +

This doesn't check that each field offset in the structures is aligned
to 8 bytes.  Is there a way to check it simply?

If no, I wonder if we need this incomplete check.

Thanks,

Kazutaka



More information about the sheepdog mailing list