Skip to content

Commit

Permalink
remote: Use tmp file buffer when restore ip dump
Browse files Browse the repository at this point in the history
When CRIU calls the ip tool on restore, it passes the fd of remote
socket by replacing the STDIN before execvp. The stdin is used by the
ip tool to receive input. However, the ip tool calls ftell(stdin)
which fails with "Illegal seek" since UNIX sockets do not support file
positioning operations. To resolve this issue, read the received
content from the UNIX socket and store it into temporary file, then
replace STDIN with the fd of this tmp file.

 # python test/zdtm.py run -t zdtm/static/env00 --remote -f ns
 === Run 1/1 ================ zdtm/static/env00

 ========================= Run zdtm/static/env00 in ns ==========================
 Start test
 ./env00 --pidfile=env00.pid --outfile=env00.out --envname=ENV_00_TEST
 Adding image cache
 Adding image proxy
 Run criu dump
 Run criu restore
 =[log]=> dump/zdtm/static/env00/31/1/restore.log
 ------------------------ grep Error ------------------------
 RTNETLINK answers: File exists
 (00.229895)      1: do_open_remote_image RDONLY path=route-9.img snapshot_id=dump/zdtm/static/env00/31/1
 (00.230316)      1: 	Running ip route restore
 Failed to restore: ftell: Illegal seek
 (00.232757)      1: Error (criu/util.c:712): exited, status=255
 (00.232777)      1: Error (criu/net.c:1479): IP tool failed on route restore
 (00.232803)      1: Error (criu/net.c:2153): Can't create net_ns
 (00.255091) Error (criu/cr-restore.c:1177): 105 killed by signal 9: Killed
 (00.255307) Error (criu/mount.c:2960): mnt: Can't remove the directory /tmp/.criu.mntns.dTd7ak: No such file or directory
 (00.255339) Error (criu/cr-restore.c:2119): Restoring FAILED.
 ------------------------ ERROR OVER ------------------------
 ################# Test zdtm/static/env00 FAIL at CRIU restore ##################
 ##################################### FAIL #####################################

Fixes checkpoint-restore#311

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
  • Loading branch information
rst0git authored and avagin committed Jun 9, 2020
1 parent 07a9458 commit 2d88ef8
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions criu/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -2068,19 +2068,46 @@ static int dump_netns_conf(struct ns_id *ns, struct cr_imgset *fds)

static int restore_ip_dump(int type, int pid, char *cmd)
{
int ret = -1;
int ret = -1, sockfd, n, written;
FILE *tmp_file;
struct cr_img *img;
char buf[1024];

img = open_image(type, O_RSTR, pid);
if (empty_image(img)) {
close_image(img);
return 0;
}
sockfd = img_raw_fd(img);
tmp_file = tmpfile();
if (!tmp_file) {
pr_perror("Failed to open tmpfile");
return -1;
}

while ((n = read(sockfd, buf, 1024)) > 0) {
written = fwrite(buf, sizeof(char), n, tmp_file);
if (written < n) {
pr_perror("Failed to write to tmpfile "
"[written: %d; total: %d]", written, n);
return -1;
}
}

if (fseek(tmp_file, 0, SEEK_SET)) {
pr_perror("Failed to set file position to beginning of tmpfile");
return -1;
}

if (img) {
ret = run_ip_tool(cmd, "restore", NULL, NULL, img_raw_fd(img), -1, 0);
ret = run_ip_tool(cmd, "restore", NULL, NULL, fileno(tmp_file), -1, 0);
close_image(img);
}

if(fclose(tmp_file)) {
pr_perror("Failed to close tmpfile");
}

return ret;
}

Expand Down

0 comments on commit 2d88ef8

Please sign in to comment.