[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190626190343.22031-2-aring@mojatatu.com>
Date: Wed, 26 Jun 2019 15:03:43 -0400
From: Alexander Aring <aring@...atatu.com>
To: netdev@...r.kernel.org
Cc: linux-fsdevel@...r.kernel.org, kernel@...atatu.com,
Alexander Aring <aring@...atatu.com>
Subject: [RFC iproute2 1/1] ip: netns: add mounted state file for each netns
This patch adds a state file for each generated namespace to ensure the
namespace is mounted. There exists no way to tell another programm that
the namespace is mounted when iproute is creating one. An example
application would be an inotify watcher to use the generated namespace
when it's discovers one. In this case we cannot use the generated
namespace file in /var/run/netns in the time when it's not mounted yet.
A primitiv approach is to generate another file after the mount
systemcall was done. In my case inotify waits until the mount statefile
is generated to be sure that iproute2 did a mount bind.
Signed-off-by: Alexander Aring <aring@...atatu.com>
---
ip/ipnetns.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index a883f210..339a9ffc 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -606,6 +606,13 @@ static int on_netns_del(char *nsname, void *arg)
netns_path, strerror(errno));
return -1;
}
+ snprintf(netns_path, sizeof(netns_path), "%s/%s.mounted",
+ NETNS_RUN_DIR, nsname);
+ if (unlink(netns_path) < 0) {
+ fprintf(stderr, "Cannot remove namespace file \"%s\": %s\n",
+ netns_path, strerror(errno));
+ return -1;
+ }
return 0;
}
@@ -758,6 +765,15 @@ static int netns_add(int argc, char **argv, bool create)
}
netns_restore();
+ snprintf(netns_path, sizeof(netns_path), "%s/%s.mounted", NETNS_RUN_DIR, name);
+ fd = open(netns_path, O_RDONLY|O_CREAT|O_EXCL, 0);
+ if (fd < 0) {
+ fprintf(stderr, "Cannot create namespace file \"%s\": %s\n",
+ netns_path, strerror(errno));
+ goto out_delete;
+ }
+ close(fd);
+
return 0;
out_delete:
if (create) {
--
2.11.0
Powered by blists - more mailing lists