Commit 9eb9abb6 authored by Andy Tucker's avatar Andy Tucker Committed by Andrei Vagin

files: Fail dump if dump_one_file() fails

When dumping a process with a large number of open files,
dump_task_files_seized() processes the fds in batches. If
dump_one_file() results in an error, processing of the current batch is
stopped but the next batch (if any) will still be fetched and the error
value is overwritten. The result is a corrupt dump image (the fdinfo
file is missing a bunch of fds) which results in restore failure.

Also close all received fds after an error (previously the skipped ones
were left open).
Signed-off-by: 's avatarAndy Tucker <agtucker@google.com>
Reviewed-by: 's avatarDmitry Safonov <0x7f454c46@gmail.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 3e86fb12
...@@ -606,7 +606,7 @@ int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item, ...@@ -606,7 +606,7 @@ int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
goto err; goto err;
ret = 0; /* Don't fail if nr_fds == 0 */ ret = 0; /* Don't fail if nr_fds == 0 */
for (off = 0; off < dfds->nr_fds; off += nr_fds) { for (off = 0; ret == 0 && off < dfds->nr_fds; off += nr_fds) {
if (nr_fds + off > dfds->nr_fds) if (nr_fds + off > dfds->nr_fds)
nr_fds = dfds->nr_fds - off; nr_fds = dfds->nr_fds - off;
...@@ -620,7 +620,6 @@ int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item, ...@@ -620,7 +620,6 @@ int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
ret = dump_one_file(item->pid, dfds->fds[i + off], ret = dump_one_file(item->pid, dfds->fds[i + off],
lfds[i], opts + i, ctl, &e); lfds[i], opts + i, ctl, &e);
close(lfds[i]);
if (ret) if (ret)
break; break;
...@@ -628,6 +627,9 @@ int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item, ...@@ -628,6 +627,9 @@ int dump_task_files_seized(struct parasite_ctl *ctl, struct pstree_item *item,
if (ret) if (ret)
break; break;
} }
for (i = 0; i < nr_fds; i++)
close(lfds[i]);
} }
pr_info("----------------------------------------\n"); pr_info("----------------------------------------\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment