public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Trond Myklebust <trond.myklebust@fys.uio.no>
Cc: Benny Halevy <bhalevy@panasas.com>,
	NFS list <linux-nfs@vger.kernel.org>,
	pNFS Mailing List <pnfs@linux-nfs.org>,
	Chuck Lever <chucklever@gmail.com>
Subject: Re: [PATCH 7/7] nfsd: nfs4xdr decode_stateid helper function
Date: Wed, 13 Aug 2008 16:17:28 -0400	[thread overview]
Message-ID: <20080813201728.GJ26765@fieldses.org> (raw)
In-Reply-To: <1218656153.9042.46.camel@localhost>

On Wed, Aug 13, 2008 at 03:35:53PM -0400, Trond Myklebust wrote:
> On Wed, 2008-08-13 at 15:11 -0400, J. Bruce Fields wrote:
> > 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?)
> 
> The advantage of having it packed like the above is that you can still
> use WRITEMEM() to write out the whole structure in one fell swoop.

Right, I understand.  But the code has been doing exactly that (a
WRITEMEM of the whole thing) since the beginning, so I wondered if there
was some reason you thought the switch to the extra char opaque[12] in
particular was something that was likely to trigger the addition of
padding.

Sounds instead like your policy would be just to declare any struct
"packed" if we might depend on the absence of padding, without making
any assumptions about what compilers might do.  Which is fine.

--b.

> If you don't specify 'packed', then the C standard allows the compiler
> to add padding between the fields in order align them. I'm not sure
> that compilers will usually do that for a 'char[]' field, but they
> will definitely for the integer types.

  reply	other threads:[~2008-08-13 20:17 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-11 14:09 [PATCH 0/2] fix nfsd stateid encoding Benny Halevy
2008-08-11 14:34 ` [PATCH 1/2] nfsd: properly xdr-encode stateid4.seqid as uint32_t for cb_recall Benny Halevy
2008-08-11 14:35 ` [PATCH 2/2] nfsd: properly xdr-encode deleg stateid returned from open Benny Halevy
2008-08-11 15:58 ` [PATCH 0/2] fix nfsd stateid encoding J. Bruce Fields
2008-08-11 16:11   ` [pnfs] " Benny Halevy
2008-08-11 16:17     ` Chuck Lever
     [not found]       ` <76bd70e30808110917y5a9a1950l1d905f081bd7a819-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-08-11 16:27         ` Benny Halevy
2008-08-11 16:28         ` J. Bruce Fields
2008-08-11 17:39           ` Benny Halevy
2008-08-11 17:50             ` J. Bruce Fields
2008-08-12 17:40               ` Benny Halevy
2008-08-12 17:42                 ` [PATCH 1/7] nfsd: properly xdr-encode stateid4.seqid as uint32_t for cb_recall Benny Halevy
2008-08-12 17:43                 ` [PATCH 2/7] nfsd: properly xdr-encode deleg stateid returned from open Benny Halevy
2008-08-12 17:44                 ` [PATCH 3/7] nfsd: fix nfsd4_encode_open buffer space reservation Benny Halevy
2008-08-12 18:31                   ` J. Bruce Fields
2008-08-12 17:45                 ` [PATCH 4/7] nfsd: nfs4xdr encode_stateid helper function Benny Halevy
2008-08-12 18:39                   ` J. Bruce Fields
2008-08-13  7:27                     ` Benny Halevy
2008-08-13 15:01                       ` J. Bruce Fields
2008-08-12 17:45                 ` [PATCH 5/7] nfsd: don't declare p in ENCODE_SEQID_OP_HEAD Benny Halevy
2008-08-12 17:45                 ` [PATCH 6/7] nfsd: properly xdr-decode NFS4_OPEN_CLAIM_DELEGATE_CUR stateid Benny Halevy
2008-08-12 17:46                 ` [PATCH 7/7] nfsd: nfs4xdr decode_stateid helper function Benny Halevy
2008-08-12 19:04                   ` J. Bruce Fields
2008-08-13  7:31                     ` Benny Halevy
2008-08-13 15:03                       ` J. Bruce Fields
2008-08-13 17:59                         ` Trond Myklebust
2008-08-13 18:30                           ` J. Bruce Fields
2008-08-13 18:59                             ` Trond Myklebust
2008-08-13 19:11                               ` J. Bruce Fields
2008-08-13 19:35                                 ` Trond Myklebust
2008-08-13 20:17                                   ` J. Bruce Fields [this message]
2008-08-13 20:57                                     ` Chuck Lever
2008-08-14 10:49                                     ` Benny Halevy
2008-08-17 12:02                           ` [pnfs] " Boaz Harrosh
2008-08-19 22:44                             ` J. Bruce Fields
2008-08-12 19:14                 ` [pnfs] [PATCH 0/2] fix nfsd stateid encoding J. Bruce Fields
2008-08-11 16:27     ` J. Bruce Fields
2008-08-11 17:34       ` Benny Halevy

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=20080813201728.GJ26765@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=bhalevy@panasas.com \
    --cc=chucklever@gmail.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=pnfs@linux-nfs.org \
    --cc=trond.myklebust@fys.uio.no \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox