[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v3 07/11] tmem: Make the uint64_t oid[3] a proper structure: tmem_oid



>>> On 01.09.15 at 17:18, <konrad.wilk@xxxxxxxxxx> 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]);
}

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.