2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00

ns: Add ability to save original ns and restoring it back while switcing

This will be required for parasite transport socket creation -- it will
have to be created in a net ns we're putting parasite in and then we'll
have to restore it back to original to go on dumping.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Pavel Emelyanov
2012-08-02 07:55:05 +04:00
parent 9eda83b74a
commit 2d56d1b056
4 changed files with 37 additions and 7 deletions

View File

@@ -9,7 +9,7 @@
#include "mount.h"
#include "namespaces.h"
int switch_ns(int pid, int type, char *ns)
int switch_ns(int pid, int type, char *ns, int *rst)
{
char buf[32];
int nsfd;
@@ -19,15 +19,44 @@ int switch_ns(int pid, int type, char *ns)
nsfd = open(buf, O_RDONLY);
if (nsfd < 0) {
pr_perror("Can't open ipcns file");
goto out;
goto err_ns;
}
if (rst) {
snprintf(buf, sizeof(buf), "/proc/self/ns/%s", ns);
*rst = open(buf, O_RDONLY);
if (*rst < 0) {
pr_perror("Can't open ns file");
goto err_rst;
}
}
ret = setns(nsfd, type);
if (ret < 0)
if (ret < 0) {
pr_perror("Can't setns %d/%s", pid, ns);
goto err_set;
}
close(nsfd);
out:
return 0;
err_set:
if (rst)
close(*rst);
err_rst:
close(nsfd);
err_ns:
return -1;
}
int restore_ns(int rst, int type)
{
int ret;
ret = setns(rst, type);
if (ret < 0)
pr_perror("Can't restore ns back");
return ret;
}