Network namespace support in configuration file?

30 views
Skip to first unread message

Guan Xin

unread,
Apr 30, 2021, 2:53:34 AM4/30/21
to beegfs-user

Hi,

It would be more helpful if a network namespace option can be used in conjunction with the NUMA binding option in BeeGFS server configuration files.
We find it very efficient in both cost an rackspace to split a 2-way or 4-way general purpose server of 2U height into respective numbers of lightweight virtual machines, each VM connecting to 6 or 8 Optane DCPMMs and an Infiniband port associated with an IP address in the same network section, and serving as metadata servers.

Network namespace, in this use case, prevents ARP flux.

Therefore, I'd suggest something like the following:
---------------------------------------- >8 ----------------------------------------
diff -pru v7-7.2.1/meta/build/dist/etc/beegfs-meta.conf v7-7.2.1_netns/meta/build/dist/etc/beegfs-meta.conf
--- v7-7.2.1/meta/build/dist/etc/beegfs-meta.conf       2021-02-23 08:40:49.000000000 +0000
+++ v7-7.2.1_netns/meta/build/dist/etc/beegfs-meta.conf 2021-03-21 14:54:44.951909938 +0000
@@ -27,6 +27,7 @@ storeAllowFirstRunInit       = true
 connAuthFile                 =
 connBacklogTCP               = 128
 connFallbackExpirationSecs   = 900
+connNetNS                    =
 connInterfacesFile           =
 connMaxInternodeNum          = 32
 
diff -pru v7-7.2.1/meta/source/app/App.cpp v7-7.2.1_netns/meta/source/app/App.cpp
--- v7-7.2.1/meta/source/app/App.cpp    2021-02-23 08:40:49.000000000 +0000
+++ v7-7.2.1_netns/meta/source/app/App.cpp      2021-03-21 14:49:40.466160770 +0000
@@ -24,6 +24,13 @@
 #include <syslog.h>
 #include <sys/resource.h>
 #include <sys/statfs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif // _GNU_SOURCE
+#include <sched.h>
 
 // this magic number is not available on all supported platforms. specifically, rhel5 does not have
 // linux/magic.h (which is where this constant is found).
@@ -427,6 +434,31 @@ void App::initBasicNetwork()
    if(!cfg->getSysMgmtdHost().length() )
       throw InvalidConfigException("Management host undefined");
 
+   // enter the specified network namespace now                                                                                                             
+   if(cfg->getConnNetNS().length() )                                                                                                                        
+   {
+       const std::string path_netns = "/run/netns/" + cfg->getConnNetNS();
+       int fd = open(path_netns.c_str(), O_RDONLY | O_CLOEXEC);
+
+       if(fd == -1)
+       {
+           throw InvalidConfigException("Unable to open network namespace at \""
+              + path_netns + "\": " + strerror(errno));
+       }
+       else
+       {
+           const int setns_retval = setns(fd, CLONE_NEWNET);
+           const int setns_errno = errno;
+
+           close(fd);
+           if(setns_retval == -1)
+           {
+              throw InvalidConfigException("Unable to enter network namespace \""
+                 + cfg->getConnNetNS() + "\": " + strerror(setns_errno));
+           }
+       }
+   }
+
    // prepare filter for outgoing packets/connections
    this->netFilter = new NetFilter(cfg->getConnNetFilterFile() );
    this->tcpOnlyFilter = new NetFilter(cfg->getConnTcpOnlyFilterFile() );
diff -pru v7-7.2.1/meta/source/app/config/Config.cpp v7-7.2.1_netns/meta/source/app/config/Config.cpp
--- v7-7.2.1/meta/source/app/config/Config.cpp  2021-02-23 08:40:49.000000000 +0000
+++ v7-7.2.1_netns/meta/source/app/config/Config.cpp    2021-03-21 14:12:01.476391765 +0000
@@ -40,6 +40,7 @@ void Config::loadDefaults(bool addDashes
    configMapRedefine("connMaxInternodeNum",        "16");
 
    // own definitions
+   configMapRedefine("connNetNS",                  "");
    configMapRedefine("connInterfacesFile",         "");
    configMapRedefine("connInterfacesList",         "");
 
@@ -114,6 +115,8 @@ void Config::applyConfigMap(bool enableE
             throw InvalidConfigException("The value of config argument logType is invalid.");
          }
       }
+      else if (iter->first == std::string("connNetNS"))
+         connNetNS = iter->second;
       else if (iter->first == std::string("connInterfacesFile"))
          connInterfacesFile = iter->second;
       else if (iter->first == std::string("connInterfacesList"))
diff -pru v7-7.2.1/meta/source/app/config/Config.h v7-7.2.1_netns/meta/source/app/config/Config.h
--- v7-7.2.1/meta/source/app/config/Config.h    2021-02-23 08:40:49.000000000 +0000
+++ v7-7.2.1_netns/meta/source/app/config/Config.h      2021-03-21 14:10:17.231817303 +0000
@@ -25,6 +25,7 @@ class Config : public AbstractConfig
 
       // configurables
 
+      std::string       connNetNS; // run in this network namespace
       std::string       connInterfacesFile; // implicitly generates connInterfacesList
       std::string       connInterfacesList; // comma-separated list
 
@@ -90,6 +91,11 @@ class Config : public AbstractConfig
 
    public:
       // getters & setters
+      const std::string& getConnNetNS() const
+      {
+         return connNetNS;
+      }
+
       const std::string& getConnInterfacesList() const
       {
          return connInterfacesList;
---------------------------------------- >8 ----------------------------------------
Regards,
Guan
beegfs-v7-7.2.1_netns.patch
Reply all
Reply to author
Forward
0 new messages