From mboxrd@z Thu Jan 1 00:00:00 1970 From: Konrad Rzeszutek Wilk Subject: Re: [PATCH v3 07/11] tmem: Make the uint64_t oid[3] a proper structure: tmem_oid Date: Tue, 1 Sep 2015 11:53:35 -0400 Message-ID: <20150901155335.GA824@l.oracle.com> References: <1440788000-32635-1-git-send-email-konrad.wilk@oracle.com> <1440788000-32635-8-git-send-email-konrad.wilk@oracle.com> <55E458E5020000780009E574@prv-mh.provo.novell.com> <20150831153720.GA9931@l.oracle.com> <55E4874702000078000D7A72@prv-mh.provo.novell.com> <20150831161416.GA7982@l.oracle.com> <20150901151843.GC11425@l.oracle.com> <55E5E26C020000780009EB1B@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZWnsX-0001KY-HB for xen-devel@lists.xenproject.org; Tue, 01 Sep 2015 15:53:45 +0000 Content-Disposition: inline In-Reply-To: <55E5E26C020000780009EB1B@prv-mh.provo.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich Cc: andrew.cooper3@citrix.com, wei.liu2@citrix.com, xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org On Tue, Sep 01, 2015 at 09:37:48AM -0600, Jan Beulich wrote: > >>> On 01.09.15 at 17:18, wrote: > > On Mon, Aug 31, 2015 at 12:14:16PM -0400, Konrad Rzeszutek Wilk wrote: > >> > >And the 'container_of' macro looks to require only one level of > >> > >nesting. > >> > > >> > I'm pretty sure the macro can deal with both. > >> > >> OK, let me experiement with it as at the first blush it does not work for > > me. > > > > I can't get it to work. > > > > My understanding (and the test case - see attached) seem to agree that > > the 'container_of' is to be used when you have the pointer to the nested > > member (oid) and want the pointer to the structure in which it is > > embedded in (op). We have the opposite case - we have the pointer to the > > structure in which it was embedded (op): > > > > struct tmem_op *op; > > > > oidp = (struct tmem_oid *)&op.u.gen.oid[0]; > > > > Hence using the container_of macro won't work. > > All of these work and behave the same for me: > > struct tmem_oid *test1(struct tmem_op *op) { > return (struct tmem_oid *)&op->u.gen.oid[0]; > } > > struct tmem_oid *test2(struct tmem_op *op) { > return container_of(&op->u.gen.oid[0], struct tmem_oid, oid[0]); > } > > struct tmem_oid *test3(struct tmem_op *op) { > return container_of(op->u.gen.oid, struct tmem_oid, oid[0]); > } Woot! That will definitly work. Thank you! > > Jan >