Commit 3e4cecb9 authored by Andrei Vagin's avatar Andrei Vagin Committed by Andrei Vagin

net: read network namespace images before forking tasks

We need to know which namespaces are external to restore them properly.
Acked-by: 's avatarAdrian Reber <areber@redhat.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 3a66660e
...@@ -50,5 +50,6 @@ extern int net_get_nsid(int rtsk, int fd, int *nsid); ...@@ -50,5 +50,6 @@ extern int net_get_nsid(int rtsk, int fd, int *nsid);
extern struct ns_id *net_get_root_ns(); extern struct ns_id *net_get_root_ns();
extern int kerndat_nsid(void); extern int kerndat_nsid(void);
extern void check_has_netns_ioc(int fd, bool *kdat_val, const char *name); extern void check_has_netns_ioc(int fd, bool *kdat_val, const char *name);
extern int read_net_ns_img();
#endif /* __CR_NET_H__ */ #endif /* __CR_NET_H__ */
...@@ -1739,6 +1739,9 @@ int prepare_namespace_before_tasks(void) ...@@ -1739,6 +1739,9 @@ int prepare_namespace_before_tasks(void)
if (read_mnt_ns_img()) if (read_mnt_ns_img())
goto err_img; goto err_img;
if (read_net_ns_img())
goto err_img;
return 0; return 0;
err_img: err_img:
......
...@@ -2048,26 +2048,47 @@ out: ...@@ -2048,26 +2048,47 @@ out:
return ret; return ret;
} }
int read_net_ns_img(void)
{
struct ns_id *ns;
for (ns = ns_ids; ns != NULL; ns = ns->next) {
struct cr_img *img;
int ret;
if (ns->nd != &net_ns_desc)
continue;
img = open_image(CR_FD_NETNS, O_RSTR, ns->id);
if (!img)
return -1;
if (empty_image(img)) {
/* Backward compatibility */
close_image(img);
continue;
}
ret = pb_read_one(img, &ns->net.netns, PB_NETNS);
close_image(img);
if (ret < 0) {
pr_err("Can not read netns object\n");
return -1;
}
}
return 0;
}
static int restore_netns_conf(struct ns_id *ns) static int restore_netns_conf(struct ns_id *ns)
{ {
NetnsEntry *netns; NetnsEntry *netns = ns->net.netns;
int ret = 0; int ret = 0;
struct cr_img *img;
img = open_image(CR_FD_NETNS, O_RSTR, ns->id); if (ns->net.netns == NULL)
if (!img)
return -1;
if (empty_image(img))
/* Backward compatibility */ /* Backward compatibility */
goto out; goto out;
ret = pb_read_one(img, &netns, PB_NETNS);
if (ret < 0) {
pr_err("Can not read netns object\n");
return -1;
}
if ((netns)->def_conf4) { if ((netns)->def_conf4) {
ret = ipv4_conf_op("all", (netns)->all_conf4, (netns)->n_all_conf4, CTL_WRITE, NULL); ret = ipv4_conf_op("all", (netns)->all_conf4, (netns)->n_all_conf4, CTL_WRITE, NULL);
if (ret) if (ret)
...@@ -2094,7 +2115,6 @@ static int restore_netns_conf(struct ns_id *ns) ...@@ -2094,7 +2115,6 @@ static int restore_netns_conf(struct ns_id *ns)
ns->net.netns = netns; ns->net.netns = netns;
out: out:
close_image(img);
return ret; return ret;
} }
......
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