[CRIU] [PATCH 09/15] pstree: allocate fdt shared data

Pavel Emelyanov xemul at parallels.com
Thu Jan 10 06:34:37 EST 2013


On 01/10/2013 02:00 PM, Andrey Vagin wrote:

A comment about at least pid sorting should be here.
Another thing deserving description is why we decide who
will restore the fdt in a separate loop over all pstree items,
instead of dynamically tuning this info on pstree items read.

> 
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>  include/crtools.h |  9 +++++++++
>  include/pstree.h  |  8 ++++++++
>  pstree.c          | 33 +++++++++++++++++++++++++++++++++
>  3 files changed, 50 insertions(+)
> 
> diff --git a/include/crtools.h b/include/crtools.h
> index 2dc30c7..ff07ce1 100644
> --- a/include/crtools.h
> +++ b/include/crtools.h
> @@ -8,6 +8,7 @@
>  #include "list.h"
>  #include "util.h"
>  #include "image.h"
> +#include "lock.h"
>  
>  #include "../protobuf/vma.pb-c.h"
>  
> @@ -229,6 +230,12 @@ struct vma_area {
>  #define vma_area_is(vma_area, s)	vma_entry_is(&((vma_area)->vma), s)
>  #define vma_area_len(vma_area)		vma_entry_len(&((vma_area)->vma))
>  
> +struct fdt {
> +	futex_t			fdt_lock;
> +	int			nr;
> +	pid_t			pid;
> +};
> +
>  struct rst_info {
>  	struct list_head	fds;
>  	struct list_head	eventpoll;
> @@ -236,6 +243,8 @@ struct rst_info {
>  
>  	void			*premmapped_addr;
>  	unsigned long		premmapped_len;
> +
> +	struct fdt		*fdt;
>  };
>  
>  static inline int in_vma_area(struct vma_area *vma, unsigned long addr)
> diff --git a/include/pstree.h b/include/pstree.h
> index 7e1a40c..f53d1f6 100644
> --- a/include/pstree.h
> +++ b/include/pstree.h
> @@ -46,6 +46,14 @@ struct pstree_item {
>  	struct rst_info		rst[0];
>  };
>  
> +static inline int shared_fdtable(struct pstree_item *item) {
> +	return (item->parent && item->parent->state != TASK_HELPER &&
> +		item->ids &&
> +		item->parent->ids &&
> +		item->ids->files_id &&
> +		item->ids->files_id == item->parent->ids->files_id);
> +}
> +
>  extern void free_pstree(struct pstree_item *root_item);
>  extern struct pstree_item *__alloc_pstree_item(bool rst);
>  #define alloc_pstree_item() __alloc_pstree_item(false)
> diff --git a/pstree.c b/pstree.c
> index 2e2171b..7df42e3 100644
> --- a/pstree.c
> +++ b/pstree.c
> @@ -5,6 +5,7 @@
>  #include "pstree.h"
>  #include "restorer.h"
>  #include "util.h"
> +#include "lock.h"
>  
>  #include "protobuf.h"
>  #include "protobuf/pstree.pb-c.h"
> @@ -434,6 +435,38 @@ static int prepare_pstree_ids(void)
>  				helper->pid.virt, helper->pgid);
>  	}
>  
> +	for_each_pstree_item(item) {
> +		struct pstree_item *parent = item->parent;
> +		struct fdt *fdt;
> +
> +		if (item->state == TASK_HELPER)
> +			continue;
> +
> +		if (parent == NULL)
> +			continue;
> +
> +		if (!shared_fdtable(item))
> +			continue;
> +
> +		if (!parent->rst->fdt) {
> +			fdt = shmalloc(sizeof(*item->rst->fdt));
> +			if (fdt == NULL)
> +				return -1;
> +
> +			parent->rst->fdt = fdt;
> +
> +			futex_init(&fdt->fdt_lock);
> +			fdt->nr = 1;
> +			fdt->pid = parent->pid.virt;
> +		} else
> +			fdt = parent->rst->fdt;
> +
> +		item->rst->fdt = fdt;
> +		fdt->nr++;
> +		if (fdt->pid > item->pid.virt)
> +			fdt->pid = item->pid.virt;
> +	}
> +
>  	return 0;
>  }
>  
> 




More information about the CRIU mailing list