[CRIU] [PATCH 2/4] files: resort code about dumping file descriptors
Pavel Emelyanov
xemul at virtuozzo.com
Mon Apr 4 03:24:22 PDT 2016
> @@ -1203,20 +1168,6 @@ static int dump_one_task(struct pstree_item *item)
> goto err;
> }
>
> - if (!shared_fdtable(item)) {
> - dfds = xmalloc(sizeof(*dfds));
> - if (!dfds)
> - goto err;
> -
> - ret = collect_fds(pid, dfds);
> - if (ret) {
> - pr_err("Collect fds (pid: %d) failed with %d\n", pid, ret);
> - goto err;
> - }
> -
> - parasite_ensure_args_size(drain_fds_size(dfds));
> - }
What's wrong in collecting the descriptors early? In this place we _are_ sure
that the fds we see are those we need to dump.
> -
> ret = parse_posix_timers(pid, &proc_args);
> if (ret < 0) {
> pr_err("Can't read posix timers file (pid: %d)\n", pid);
> +int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item)
> +{
> + struct parasite_drain_fd *dfds = NULL;
> + struct fd_opts *opts = NULL;
> + struct cr_img *img = NULL;
> + pid_t pid = ctl->pid.real;
> + int *lfds = NULL;
> int i, ret = -1;
>
> pr_info("\n");
> pr_info("Dumping opened files (pid: %d)\n", ctl->pid.real);
> pr_info("----------------------------------------\n");
>
> + dfds = xmalloc(sizeof(*dfds));
> + if (!dfds)
> + goto err;
> +
> + img = open_image(CR_FD_FDINFO, O_DUMP, item->ids->files_id);
> + if (!img)
> + goto err;
> +
> + ret = collect_fds(pid, dfds, (int [2]) {ctl->ptsock, ctl->plogfd} , 2);
> + if (ret) {
> + pr_err("Collect fds (pid: %d) failed with %d\n", pid, ret);
> + goto err;
> + }
> +
> + parasite_ensure_args_size(drain_fds_size(dfds));
It's too late to ensure_args_size() here, the parasite is already injected.
> +
> lfds = xmalloc(dfds->nr_fds * sizeof(int));
> if (!lfds)
> goto err;
>
> opts = xmalloc(dfds->nr_fds * sizeof(struct fd_opts));
> if (!opts)
> - goto err1;
> + goto err;
>
> ret = parasite_drain_fds_seized(ctl, dfds, lfds, opts);
> if (ret)
> - goto err2;
> -
> - img = open_image(CR_FD_FDINFO, O_DUMP, item->ids->files_id);
> - if (!img)
> - goto err2;
> + goto err;
>
> for (i = 0; i < dfds->nr_fds; i++) {
> ret = dump_one_file(ctl, dfds->fds[i], lfds[i], opts + i, img);
More information about the CRIU
mailing list