mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 14:25:49 +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:
@@ -7,5 +7,6 @@ int dump_namespaces(struct pid *pid, unsigned int ns_flags);
|
||||
int prepare_namespace(int pid, unsigned long clone_flags);
|
||||
struct cr_options;
|
||||
int try_show_namespaces(int pid, struct cr_options *);
|
||||
int switch_ns(int pid, int type, char *ns);
|
||||
int switch_ns(int pid, int type, char *ns, int *rst);
|
||||
int restore_ns(int rst, int type);
|
||||
#endif
|
||||
|
2
ipc_ns.c
2
ipc_ns.c
@@ -456,7 +456,7 @@ int dump_ipc_ns(int ns_pid, const struct cr_fdset *fdset)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = switch_ns(ns_pid, CLONE_NEWIPC, "ipc");
|
||||
ret = switch_ns(ns_pid, CLONE_NEWIPC, "ipc", NULL);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
|
37
namespaces.c
37
namespaces.c
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user