[CRIU] Re: [PATCH 10/10] files: Use sys_kcmp to find file
descriptor duplicates
Pavel Emelyanov
xemul at parallels.com
Tue Feb 28 09:01:56 EST 2012
On 02/28/2012 05:10 PM, Cyrill Gorcunov wrote:
> On Tue, Feb 28, 2012 at 02:26:31PM +0400, Pavel Emelyanov wrote:
>> On 02/27/2012 07:21 PM, Cyrill Gorcunov wrote:
>>> On Mon, Feb 27, 2012 at 06:01:41PM +0400, Cyrill Gorcunov wrote:
>>>>
>>>> Yes, 0 will work as well but I would prefer to keep some predefined
>>>> value other than 0 which actually gives us a good hint in debugging
>>>> purpose.
>>>>
>>>
>>> Does this one look better?
>>
>> Almost perfect. See comments inline.
>>
>
> The final one.
No, it's not :)
> Cyrill
> +static struct fd_id_entry *alloc_fd_id_entry(u32 genid, pid_t pid, int fd)
> +{
> + struct fd_id_entry *e;
> +
> + e = xmalloc(sizeof(*e));
> + if (!e)
> + goto err;
> +
> + e->u.key.subid = fd_id_entries_subid++; /* just for the symmetry */
> + e->u.key.genid = genid;
> + e->pid = pid;
> + e->fd = fd;
> +
> + rb_init_node(&e->node);
> + rb_init_node(&e->subtree_node);
> + rb_attach_node(&e->subtree_root, &e->subtree_node);
> +err:
> + return e;
> +}
> +
> +static struct fd_id_entry *
> +lookup_alloc_subtree(struct fd_id_entry *e, u32 genid, pid_t pid, int fd)
> +{
> +
> + sub = alloc_fd_id_entry(genid, pid, fd);
> + if (!sub)
> + goto err;
> +
> + sub->u.key.subid = fd_id_entries_subid++;
It's already incremented in alloc_fd_id_entry :)
> + rb_link_and_balance(&e->subtree_root, &sub->subtree_node, parent, new);
Plus, you can merge call to rb_link_and_balance into alloc_fd_id_entry (and rename
the latter to better reflect what it's doing.
> +err:
> + return sub;
More information about the CRIU
mailing list