[CRIU] [PATCH] ns: Factor out namespace switching call
Pavel
arsbum at mail.ru
Mon Sep 22 05:27:18 PDT 2014
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
include/ipc_ns.h | 2 +-
include/net.h | 2 +-
include/uts_ns.h | 2 +-
ipc_ns.c | 6 +-----
namespaces.c | 24 ++++++++++++++++--------
net.c | 6 ++----
uts_ns.c | 6 +-----
7 files changed, 23 insertions(+), 25 deletions(-)
diff --git a/include/ipc_ns.h b/include/ipc_ns.h
index a50281f..c890989 100644
--- a/include/ipc_ns.h
+++ b/include/ipc_ns.h
@@ -1,7 +1,7 @@
#ifndef __CR_IPC_NS_H__
#define __CR_IPC_NS_H__
-extern int dump_ipc_ns(int ns_pid, int ns_id);
+extern int dump_ipc_ns(int ns_id);
extern int prepare_ipc_ns(int pid);
extern struct ns_desc ipc_ns_desc;
diff --git a/include/net.h b/include/net.h
index a9f0d46..11fddf6 100644
--- a/include/net.h
+++ b/include/net.h
@@ -4,7 +4,7 @@
#include "list.h"
struct cr_fdset;
-extern int dump_net_ns(int pid, int ns_id);
+extern int dump_net_ns(int ns_id);
extern int prepare_net_ns(int pid);
extern int netns_pre_create(void);
diff --git a/include/uts_ns.h b/include/uts_ns.h
index ff499ac..ab054ff 100644
--- a/include/uts_ns.h
+++ b/include/uts_ns.h
@@ -1,7 +1,7 @@
#ifndef __CR_UTS_NS_H__
#define __CR_UTS_NS_H__
-extern int dump_uts_ns(int ns_pid, int ns_id);
+extern int dump_uts_ns(int ns_id);
extern int prepare_utsns(int pid);
extern struct ns_desc uts_ns_desc;
diff --git a/ipc_ns.c b/ipc_ns.c
index 7dc4cbd..1687776 100644
--- a/ipc_ns.c
+++ b/ipc_ns.c
@@ -456,7 +456,7 @@ static int dump_ipc_data(const struct cr_fdset *fdset)
return 0;
}
-int dump_ipc_ns(int ns_pid, int ns_id)
+int dump_ipc_ns(int ns_id)
{
int ret;
struct cr_fdset *fdset;
@@ -465,10 +465,6 @@ int dump_ipc_ns(int ns_pid, int ns_id)
if (fdset == NULL)
return -1;
- ret = switch_ns(ns_pid, &ipc_ns_desc, NULL);
- if (ret < 0)
- goto err;
-
ret = dump_ipc_data(fdset);
if (ret < 0) {
pr_err("Failed to write IPC namespace data\n");
diff --git a/namespaces.c b/namespaces.c
index 6be030f..e73760c 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -424,27 +424,27 @@ int gen_predump_ns_mask(void)
static int do_dump_namespaces(struct ns_id *ns)
{
- int ret = -1;
+ int ret;
+
+ ret = switch_ns(ns->pid, ns->nd, NULL);
+ if (ret)
+ return ret;
switch (ns->nd->cflag) {
- case CLONE_NEWPID:
- case CLONE_NEWNS:
- ret = 0;
- break;
case CLONE_NEWUTS:
pr_info("Dump UTS namespace %d via %d\n",
ns->id, ns->pid);
- ret = dump_uts_ns(ns->pid, ns->id);
+ ret = dump_uts_ns(ns->id);
break;
case CLONE_NEWIPC:
pr_info("Dump IPC namespace %d via %d\n",
ns->id, ns->pid);
- ret = dump_ipc_ns(ns->pid, ns->id);
+ ret = dump_ipc_ns(ns->id);
break;
case CLONE_NEWNET:
pr_info("Dump NET namespace info %d via %d\n",
ns->id, ns->pid);
- ret = dump_net_ns(ns->pid, ns->id);
+ ret = dump_net_ns(ns->id);
break;
default:
pr_err("Unknown namespace flag %x", ns->nd->cflag);
@@ -485,6 +485,14 @@ int dump_namespaces(struct pstree_item *item, unsigned int ns_flags)
if (ns->pid == getpid())
continue;
+ switch (ns->nd->cflag) {
+ /* No data for pid namespaces to dump */
+ case CLONE_NEWPID:
+ /* Dumped explicitly with dump_mnt_namespaces() */
+ case CLONE_NEWNS:
+ continue;
+ }
+
pid = fork();
if (pid < 0) {
pr_perror("Can't fork ns dumper");
diff --git a/net.c b/net.c
index 543f24c..b0bf5a5 100644
--- a/net.c
+++ b/net.c
@@ -527,7 +527,7 @@ static int mount_ns_sysfs(void)
return ns_sysfs_fd >= 0 ? 0 : -1;
}
-int dump_net_ns(int pid, int ns_id)
+int dump_net_ns(int ns_id)
{
struct cr_fdset *fds;
int ret;
@@ -536,9 +536,7 @@ int dump_net_ns(int pid, int ns_id)
if (fds == NULL)
return -1;
- ret = switch_ns(pid, &net_ns_desc, NULL);
- if (!ret)
- ret = mount_ns_sysfs();
+ ret = mount_ns_sysfs();
if (!ret)
ret = dump_links(fds);
if (!ret)
diff --git a/uts_ns.c b/uts_ns.c
index b495bbb..7f1fda0 100644
--- a/uts_ns.c
+++ b/uts_ns.c
@@ -12,7 +12,7 @@
#include "protobuf.h"
#include "protobuf/utsns.pb-c.h"
-int dump_uts_ns(int ns_pid, int ns_id)
+int dump_uts_ns(int ns_id)
{
int ret, img_fd;
struct utsname ubuf;
@@ -22,10 +22,6 @@ int dump_uts_ns(int ns_pid, int ns_id)
if (img_fd < 0)
return -1;
- ret = switch_ns(ns_pid, &uts_ns_desc, NULL);
- if (ret < 0)
- goto err;
-
ret = uname(&ubuf);
if (ret < 0) {
pr_perror("Error calling uname");
--
1.8.4.2
More information about the CRIU
mailing list