[CRIU] [PATCH v2 4/5] net: Dump tun device net id in img
Kirill Tkhai
ktkhai at virtuozzo.com
Fri Mar 2 15:46:45 MSK 2018
From: Andrew Vagin <avagin at virtuozzo.com>
This adds new tunfile_entry::ns_id field and populates
it in standard socket way. Restore uses this ns_id
to choose correct namespace. Note, we could completelly
skip set_netns() on restore in case of !has_ns_id, but
using top_net_ns invents some definite behaviour.
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
ktkhai: comment written/code movings
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
criu/tun.c | 9 ++++++++-
images/tun.proto | 1 +
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/criu/tun.c b/criu/tun.c
index a6cd372d3..742816afc 100644
--- a/criu/tun.c
+++ b/criu/tun.c
@@ -20,6 +20,7 @@
#include "namespaces.h"
#include "xmalloc.h"
#include "kerndat.h"
+#include "sockets.h"
#include "images/tun.pb-c.h"
@@ -304,6 +305,8 @@ static int dump_tunfile(int lfd, u32 id, const struct fd_parms *p)
pr_err("No net_ns for tun device\n");
return -1;
}
+ tfe.has_ns_id = true;
+ tfe.ns_id = ns->id;
}
if (dump_one_reg_file(lfd, id, p))
@@ -356,7 +359,7 @@ struct tunfile_info {
static int tunfile_open(struct file_desc *d, int *new_fd)
{
- int fd;
+ int fd, ns_id;
struct tunfile_info *ti;
struct ifreq ifr;
struct tun_link *tl;
@@ -366,6 +369,10 @@ static int tunfile_open(struct file_desc *d, int *new_fd)
if (fd < 0)
return -1;
+ ns_id = ti->tfe->has_ns_id ? ti->tfe->ns_id : top_net_ns->id;
+ if (set_netns(ns_id))
+ return -1;
+
if (!ti->tfe->netdev)
/* just-opened tun file */
goto ok;;
diff --git a/images/tun.proto b/images/tun.proto
index 796e1f5d9..b70c9ed67 100644
--- a/images/tun.proto
+++ b/images/tun.proto
@@ -6,6 +6,7 @@ message tunfile_entry {
required uint32 id = 1;
optional string netdev = 2;
optional bool detached = 3;
+ optional uint32 ns_id = 4;
};
message tun_link_entry {
More information about the CRIU
mailing list