[CRIU] Re: [PATCH 07/12] dump: Use parasite file descriptors draining

Pavel Emelyanov xemul at parallels.com
Tue Mar 27 08:55:31 EDT 2012


> -static int reg_files_fd = -1;
> +static int collect_fds(pid_t pid, int *fd, int *nr_fd)
> +{
> +	struct dirent *d;
> +	DIR *dir;
> +	int n;
> +
> +	pr_info("\n");
> +	pr_info("Collecting fds (pid: %d)\n", pid);
> +	pr_info("----------------------------------------\n");
> +
> +	dir = opendir_proc(pid, "fd");
> +	if (!dir)
> +		return -1;
> +
> +	n = 0;
> +	while ((d = readdir(dir))) {
> +		if (d->d_name[0] == '.')
> +			continue;

This is wrong.

> +		if (n > *nr_fd - 1)
> +			return -ENOMEM;
> +		fd[n++] = atoi(d->d_name);
> +	}
> +
> +	*nr_fd = n;
> +	pr_info("Found %d file descriptors\n", n);
> +
> +	pr_info("----------------------------------------\n");
> +	return 0;
> +}

> @@ -289,68 +321,47 @@ err:
>  	return ret;
>  }
>  
> -static int read_fd_params(pid_t pid, const char *fd, struct fd_parms *p)
> +static void fill_fd_params(pid_t pid, int fd, int lfd, struct fd_parms *p)
>  {
> -	FILE *file;
> -	int ret;
> +	p->fd_name	= fd;
> +	p->pos		= lseek(lfd, 0, SEEK_CUR);
> +	p->flags	= fcntl(lfd, F_GETFL);
> +	p->pid		= pid;
> +	p->id		= FD_ID_INVALID;

Stop reformatting the code in one patch with writing new functionality.

> -	file = fopen_proc(pid, "fdinfo/%s", fd);
> -	if (!file)
> -		return -1;
> -
> -	p->fd_name = atoi(fd);
> -	ret = fscanf(file, "pos:\t%li\nflags:\t%o\n", &p->pos, &p->flags);
> -	fclose(file);
> -
> -	if (ret != 2) {
> -		pr_err("Bad format of fdinfo file (%d items, want 2)\n", ret);
> -		return -1;
> -	}
> -
> -	pr_info("%d fdinfo %s: pos: %16lx flags: %16o\n",
> +	pr_info("%d fdinfo %d: pos: %16lx flags: %16o\n",
>  		pid, fd, p->pos, p->flags);
> -
> -	p->pid	= pid;
> -	p->id	= FD_ID_INVALID;
> -
> -	return 0;
>  }

> @@ -1290,6 +1292,9 @@ static int dump_one_task(const struct pstree_item *item, struct cr_fdset *cr_fds
>  	struct parasite_dump_misc misc;
>  	struct sk_queue sk_queue = { };
>  
> +	int nr_fds = PARASITE_MAX_FDS;
> +	int fds[nr_fds];

I wouldn't allocate that much space on stack.

> +
>  	pr_info("========================================\n");
>  	pr_info("Dumping task (pid: %d)\n", pid);
>  	pr_info("========================================\n");


More information about the CRIU mailing list