Commit eac46292 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

restore: add mount id-s in the ns_ids list (v4)

Currently ns_ids list is filled only on dump. Soon we'll need this
list for mount namespaces on restore, e.g. to know which tasks share
the namespaces.

v2: merge the patch "namespace: add a function to search an ns_id
item by id" into this one.
v3: add prefix rst_ to add_ns_id
v4: look up namespace by two values -- type AND ID
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 0989d3fd
...@@ -42,6 +42,9 @@ extern int switch_ns(int pid, struct ns_desc *nd, int *rst); ...@@ -42,6 +42,9 @@ extern int switch_ns(int pid, struct ns_desc *nd, int *rst);
extern int restore_ns(int rst, struct ns_desc *nd); extern int restore_ns(int rst, struct ns_desc *nd);
extern int dump_task_ns_ids(struct pstree_item *); extern int dump_task_ns_ids(struct pstree_item *);
extern int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd);
extern struct ns_id *lookup_ns_by_id(unsigned int id, struct ns_desc *nd);
extern int gen_predump_ns_mask(void); extern int gen_predump_ns_mask(void);
#endif /* __CR_NS_H__ */ #endif /* __CR_NS_H__ */
...@@ -117,6 +117,34 @@ struct ns_id *ns_ids = NULL; ...@@ -117,6 +117,34 @@ struct ns_id *ns_ids = NULL;
static unsigned int ns_next_id = 1; static unsigned int ns_next_id = 1;
unsigned long current_ns_mask = 0; unsigned long current_ns_mask = 0;
int rst_add_ns_id(unsigned int id, pid_t pid, struct ns_desc *nd)
{
struct ns_id *nsid;
for (nsid = ns_ids; nsid != NULL; nsid = nsid->next) {
if (nsid->id == id) {
if (pid_rst_prio(pid, nsid->pid))
nsid->pid = pid;
return 0;
}
}
nsid = shmalloc(sizeof(struct ns_id));
if (nsid == NULL)
return -1;
nsid->nd = nd;
nsid->id = id;
nsid->pid = pid;
nsid->next = ns_ids;
ns_ids = nsid;
pr_info("Add namespace %d pid %d\n", nsid->id, nsid->pid);
return 0;
}
static unsigned int lookup_ns_id(unsigned int kid, struct ns_desc *nd) static unsigned int lookup_ns_id(unsigned int kid, struct ns_desc *nd)
{ {
struct ns_id *nsid; struct ns_id *nsid;
...@@ -128,6 +156,17 @@ static unsigned int lookup_ns_id(unsigned int kid, struct ns_desc *nd) ...@@ -128,6 +156,17 @@ static unsigned int lookup_ns_id(unsigned int kid, struct ns_desc *nd)
return 0; return 0;
} }
struct ns_id *lookup_ns_by_id(unsigned int id, struct ns_desc *nd)
{
struct ns_id *nsid;
for (nsid = ns_ids; nsid != NULL; nsid = nsid->next)
if (nsid->id == id && nsid->nd == nd)
return nsid;
return NULL;
}
static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd) static unsigned int generate_ns_id(int pid, unsigned int kid, struct ns_desc *nd)
{ {
unsigned int id; unsigned int id;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "namespaces.h" #include "namespaces.h"
#include "files.h" #include "files.h"
#include "tty.h" #include "tty.h"
#include "mount.h"
#include "asm/dump.h" #include "asm/dump.h"
#include "protobuf.h" #include "protobuf.h"
...@@ -413,6 +414,10 @@ static int read_pstree_image(void) ...@@ -413,6 +414,10 @@ static int read_pstree_image(void)
if (ret != 1) if (ret != 1)
goto err; goto err;
if (pi->ids->has_mnt_ns_id) {
if (rst_add_ns_id(pi->ids->mnt_ns_id, pi->pid.virt, &mnt_ns_desc))
goto err;
}
} }
err: err:
close(ps_fd); close(ps_fd);
......
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