mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
ns: Factor out namespace switching call
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
3bc0936ae7
commit
8ac80915e0
7 changed files with 23 additions and 25 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include "list.h"
|
||||
|
||||
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 netns_pre_create(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
6
ipc_ns.c
6
ipc_ns.c
|
|
@ -456,7 +456,7 @@ static int dump_ipc_data(const struct cr_imgset *imgset)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int dump_ipc_ns(int ns_pid, int ns_id)
|
||||
int dump_ipc_ns(int ns_id)
|
||||
{
|
||||
int ret;
|
||||
struct cr_imgset *imgset;
|
||||
|
|
@ -465,10 +465,6 @@ int dump_ipc_ns(int ns_pid, int ns_id)
|
|||
if (imgset == NULL)
|
||||
return -1;
|
||||
|
||||
ret = switch_ns(ns_pid, &ipc_ns_desc, NULL);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
ret = dump_ipc_data(imgset);
|
||||
if (ret < 0) {
|
||||
pr_err("Failed to write IPC namespace data\n");
|
||||
|
|
|
|||
24
namespaces.c
24
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");
|
||||
|
|
|
|||
6
net.c
6
net.c
|
|
@ -533,7 +533,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_imgset *fds;
|
||||
int ret;
|
||||
|
|
@ -542,9 +542,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)
|
||||
|
|
|
|||
6
uts_ns.c
6
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;
|
||||
struct cr_img *img;
|
||||
|
|
@ -23,10 +23,6 @@ int dump_uts_ns(int ns_pid, int ns_id)
|
|||
if (!img)
|
||||
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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue