[Patch v2 2/4] veth: implement io_alloc()

Thomas Graf tgraf at suug.ch
Tue Apr 1 07:54:31 EDT 2014


On 03/31/14 at 04:49pm, Cong Wang wrote:
> On Mon, Mar 31, 2014 at 12:11 PM, Cong Wang <xiyou.wangcong at gmail.com> wrote:
> > On Mon, Mar 31, 2014 at 4:04 AM, Thomas Graf <tgraf at suug.ch> wrote:
> >> On 03/28/14 at 06:08pm, Cong Wang wrote:
> >>> +             return -NLE_NOMEM;
> >>> +     }
> >>> +
> >>> +     peer->l_info = link;
> >>
> >> You need to acquire a refcnt to link to make sure link is
> >> not freed while you hold that reference.
> >>
> >> nl_object_get(OBJ_CAST(link));
> >> peer->l_info = link;
> >>
> >> And then release it again in io_free
> >>
> >
> > Yeah, will do.
> 
> 
> Hmm, thinking a bit more, I think we probably we don't need
> a hold a reference here, because no matter we free link from
> either link or its peer, it will free the ->l_info struct together.
> IOW, they share the same life time thus their refcounts are
> always same.
> 
> I tried to grab a reference here, but it's hard to make it working
> correctly.
> 
> What do you think?

The case that I wanted to have covered is:

1. create veth X
2. peer Y gets created automatically
3. acquire new ref on Y and push it into a cache or something
4. original user releases ref on X
5. at this point X will get freed if Y doesn't hold a ref



More information about the libnl mailing list