mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 06:15:24 +00:00
ns: Introduce ns type
We (may) have 3 types of namespace objects in criu -- criu's one, root task's one and others. All of them sometimes make sense and we differentiate them in a weird way -- by checking the ns->pid field against getpid() or by comparing with root_item's. The proposal is to mark ns_id objects explicitly with type field. Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
@@ -9,12 +9,20 @@ struct ns_desc {
|
||||
size_t len;
|
||||
};
|
||||
|
||||
enum ns_type {
|
||||
NS_UNKNOWN = 0,
|
||||
NS_CRIU,
|
||||
NS_ROOT,
|
||||
NS_OTHER,
|
||||
};
|
||||
|
||||
struct ns_id {
|
||||
unsigned int kid;
|
||||
unsigned int id;
|
||||
pid_t pid;
|
||||
struct ns_desc *nd;
|
||||
struct ns_id *next;
|
||||
enum ns_type type;
|
||||
|
||||
/*
|
||||
* For mount namespaces on restore -- indicates that
|
||||
@@ -68,7 +76,7 @@ extern int restore_ns(int rst, struct ns_desc *nd);
|
||||
extern int dump_task_ns_ids(struct pstree_item *);
|
||||
extern int predump_task_ns_ids(struct pstree_item *);
|
||||
extern struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd);
|
||||
extern int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd);
|
||||
extern int rst_add_ns_id(unsigned int id, struct pstree_item *, struct ns_desc *nd);
|
||||
extern struct ns_id *lookup_ns_by_id(unsigned int id, struct ns_desc *nd);
|
||||
|
||||
extern int collect_user_namespaces(bool for_dump);
|
||||
|
22
namespaces.c
22
namespaces.c
@@ -135,12 +135,14 @@ static void nsid_add(struct ns_id *ns, struct ns_desc *nd, unsigned int id, pid_
|
||||
pr_info("Add %s ns %d pid %d\n", nd->str, ns->id, ns->pid);
|
||||
}
|
||||
|
||||
struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd)
|
||||
static struct ns_id *__rst_new_ns_id(unsigned int id, pid_t pid,
|
||||
struct ns_desc *nd, enum ns_type type)
|
||||
{
|
||||
struct ns_id *nsid;
|
||||
|
||||
nsid = shmalloc(sizeof(*nsid));
|
||||
if (nsid) {
|
||||
nsid->type = type;
|
||||
nsid_add(nsid, nd, id, pid);
|
||||
futex_set(&nsid->ns_created, 0);
|
||||
}
|
||||
@@ -148,8 +150,14 @@ struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd)
|
||||
return nsid;
|
||||
}
|
||||
|
||||
int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd)
|
||||
struct ns_id *rst_new_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd)
|
||||
{
|
||||
return __rst_new_ns_id(id, pid, nd, NS_CRIU);
|
||||
}
|
||||
|
||||
int rst_add_ns_id(unsigned int id, struct pstree_item *i, struct ns_desc *nd)
|
||||
{
|
||||
pid_t pid = i->pid.virt;
|
||||
struct ns_id *nsid;
|
||||
|
||||
nsid = lookup_ns_by_id(id, nd);
|
||||
@@ -159,7 +167,8 @@ int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsid = rst_new_ns_id(id, pid, nd);
|
||||
nsid = __rst_new_ns_id(id, pid, nd,
|
||||
i == root_item ? NS_ROOT : NS_OTHER);
|
||||
if (nsid == NULL)
|
||||
return -1;
|
||||
|
||||
@@ -232,27 +241,32 @@ static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd
|
||||
struct ns_id **ns_ret)
|
||||
{
|
||||
struct ns_id *nsid;
|
||||
enum ns_type type;
|
||||
|
||||
nsid = lookup_ns_by_kid(kid, nd);
|
||||
if (nsid)
|
||||
goto found;
|
||||
|
||||
if (pid != getpid()) {
|
||||
type = NS_OTHER;
|
||||
if (pid == root_item->pid.real) {
|
||||
BUG_ON(root_ns_mask & nd->cflag);
|
||||
pr_info("Will take %s namespace in the image\n", nd->str);
|
||||
root_ns_mask |= nd->cflag;
|
||||
type = NS_ROOT;
|
||||
} else if (nd->cflag & ~CLONE_SUBNS) {
|
||||
pr_err("Can't dump nested %s namespace for %d\n",
|
||||
nd->str, pid);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else
|
||||
type = NS_CRIU;
|
||||
|
||||
nsid = xmalloc(sizeof(*nsid));
|
||||
if (!nsid)
|
||||
return 0;
|
||||
|
||||
nsid->type = type;
|
||||
nsid->kid = kid;
|
||||
nsid_add(nsid, nd, ns_next_id++, pid);
|
||||
|
||||
|
Reference in New Issue
Block a user