Commit 8ac80915 authored by Pavel's avatar Pavel Committed by Pavel Emelyanov

ns: Factor out namespace switching call

Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 3bc0936a
#ifndef __CR_IPC_NS_H__ #ifndef __CR_IPC_NS_H__
#define __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 int prepare_ipc_ns(int pid);
extern struct ns_desc ipc_ns_desc; extern struct ns_desc ipc_ns_desc;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "list.h" #include "list.h"
struct cr_imgset; struct cr_imgset;
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 prepare_net_ns(int pid);
extern int netns_pre_create(void); extern int netns_pre_create(void);
......
#ifndef __CR_UTS_NS_H__ #ifndef __CR_UTS_NS_H__
#define __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 int prepare_utsns(int pid);
extern struct ns_desc uts_ns_desc; extern struct ns_desc uts_ns_desc;
......
...@@ -456,7 +456,7 @@ static int dump_ipc_data(const struct cr_imgset *imgset) ...@@ -456,7 +456,7 @@ static int dump_ipc_data(const struct cr_imgset *imgset)
return 0; return 0;
} }
int dump_ipc_ns(int ns_pid, int ns_id) int dump_ipc_ns(int ns_id)
{ {
int ret; int ret;
struct cr_imgset *imgset; struct cr_imgset *imgset;
...@@ -465,10 +465,6 @@ int dump_ipc_ns(int ns_pid, int ns_id) ...@@ -465,10 +465,6 @@ int dump_ipc_ns(int ns_pid, int ns_id)
if (imgset == NULL) if (imgset == NULL)
return -1; return -1;
ret = switch_ns(ns_pid, &ipc_ns_desc, NULL);
if (ret < 0)
goto err;
ret = dump_ipc_data(imgset); ret = dump_ipc_data(imgset);
if (ret < 0) { if (ret < 0) {
pr_err("Failed to write IPC namespace data\n"); pr_err("Failed to write IPC namespace data\n");
......
...@@ -424,27 +424,27 @@ int gen_predump_ns_mask(void) ...@@ -424,27 +424,27 @@ int gen_predump_ns_mask(void)
static int do_dump_namespaces(struct ns_id *ns) 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) { switch (ns->nd->cflag) {
case CLONE_NEWPID:
case CLONE_NEWNS:
ret = 0;
break;
case CLONE_NEWUTS: case CLONE_NEWUTS:
pr_info("Dump UTS namespace %d via %d\n", pr_info("Dump UTS namespace %d via %d\n",
ns->id, ns->pid); ns->id, ns->pid);
ret = dump_uts_ns(ns->pid, ns->id); ret = dump_uts_ns(ns->id);
break; break;
case CLONE_NEWIPC: case CLONE_NEWIPC:
pr_info("Dump IPC namespace %d via %d\n", pr_info("Dump IPC namespace %d via %d\n",
ns->id, ns->pid); ns->id, ns->pid);
ret = dump_ipc_ns(ns->pid, ns->id); ret = dump_ipc_ns(ns->id);
break; break;
case CLONE_NEWNET: case CLONE_NEWNET:
pr_info("Dump NET namespace info %d via %d\n", pr_info("Dump NET namespace info %d via %d\n",
ns->id, ns->pid); ns->id, ns->pid);
ret = dump_net_ns(ns->pid, ns->id); ret = dump_net_ns(ns->id);
break; break;
default: default:
pr_err("Unknown namespace flag %x", ns->nd->cflag); pr_err("Unknown namespace flag %x", ns->nd->cflag);
...@@ -485,6 +485,14 @@ int dump_namespaces(struct pstree_item *item, unsigned int ns_flags) ...@@ -485,6 +485,14 @@ int dump_namespaces(struct pstree_item *item, unsigned int ns_flags)
if (ns->pid == getpid()) if (ns->pid == getpid())
continue; 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(); pid = fork();
if (pid < 0) { if (pid < 0) {
pr_perror("Can't fork ns dumper"); pr_perror("Can't fork ns dumper");
......
...@@ -533,7 +533,7 @@ static int mount_ns_sysfs(void) ...@@ -533,7 +533,7 @@ static int mount_ns_sysfs(void)
return ns_sysfs_fd >= 0 ? 0 : -1; 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_imgset *fds; struct cr_imgset *fds;
int ret; int ret;
...@@ -542,9 +542,7 @@ int dump_net_ns(int pid, int ns_id) ...@@ -542,9 +542,7 @@ int dump_net_ns(int pid, int ns_id)
if (fds == NULL) if (fds == NULL)
return -1; return -1;
ret = switch_ns(pid, &net_ns_desc, NULL); ret = mount_ns_sysfs();
if (!ret)
ret = mount_ns_sysfs();
if (!ret) if (!ret)
ret = dump_links(fds); ret = dump_links(fds);
if (!ret) if (!ret)
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "protobuf.h" #include "protobuf.h"
#include "protobuf/utsns.pb-c.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; int ret;
struct cr_img *img; struct cr_img *img;
...@@ -23,10 +23,6 @@ int dump_uts_ns(int ns_pid, int ns_id) ...@@ -23,10 +23,6 @@ int dump_uts_ns(int ns_pid, int ns_id)
if (!img) if (!img)
return -1; return -1;
ret = switch_ns(ns_pid, &uts_ns_desc, NULL);
if (ret < 0)
goto err;
ret = uname(&ubuf); ret = uname(&ubuf);
if (ret < 0) { if (ret < 0) {
pr_perror("Error calling uname"); pr_perror("Error calling uname");
......
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