Re: [PATCH 7/7] nfsd: nfs4xdr decode_stateid helper function

J. Bruce Fields
2008-08-13T19:11:56Z

On Wed, Aug 13, 2008 at 02:59:52PM -0400, Trond Myklebust wrote:
> On Wed, 2008-08-13 at 14:30 -0400, J. Bruce Fields wrote:
> > On Wed, Aug 13, 2008 at 01:59:09PM -0400, Trond Myklebust wrote:
> > > Which is a good reason for ditching the entire confusing typedef, and
> > > replacing it with a packed structure instead:
> > >
> > > struct stateid {
> > > __be32 generation;
> > > char opaque[12];
> > > } __attribute__((packed));
> >
> > So without the ((packed)), all arrays get aligned to 8-byte boundaries
> > on 64-bit machines? (What do I need to read to catch up here?)
>
> A quick google showed up:
>
> http://sig9.com/articles/gcc-packed-structures
>
> In any case, yes, the idea behind the packed attribute is to turn off
> the field alignment.

Yeah, I was more curious about how to decide when it's necessary. (Why
didn't we need it before? Is an embedded struct always aligned as if
the fields of the embedded struct were declared directly in the
containing struct? Or should we really just be using the packed
attribute *any* time we depend on that alignment, even if it seems
obvious the compiler wouldn't need to add padding?)

--b.