Re: [PATCH 8/8] net: Implement socketat.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Daniel Lezcano
Date: Monday, October 4, 2010 - 3:13 am

On 10/03/2010 03:44 PM, jamal wrote:

8K ! whow ! :)



Yes, I think so.


Maybe I misunderstanding but you are trying to save some syscalls, you 
should use socketat only and keep app control namespace0 socket for it. 
The process will be in the last netns you unshared (maybe you can use 
here one setns syscall to return back to the namespace0).

     (1) socketat  :
         * pros : 1 syscall to create a socket
         * cons : a file descriptor per namespace, namespace is only 
manageable via a socket

     (2) setns :
         * pros : namespace is fully manageable with a generic code
         * cons : 2 syscall (or 3 if we want to return to the initial 
netns) to create a socket(setns + socket [ + setns ]), a file descriptor 
per namespace

     (3) setns + bind mount :
         * pros : no file descriptor need to be kept opened
         * cons : startup longer, (unshare + mount --bind), 4 syscalls 
to create a socket in the namespace (open, setns, socket, close), (may 
be 5 syscalls if we want to return to the initial netns).

Depending of the scheme you choose the startup will be for:

     (1) socketat :
          * open /proc/self/ns/net (one time to 'save' and pin the 
initial netns)
         and then

         int create_ns(void)
         {
             unshare(CLONE_NEWNET);
             return socket(...)
         }

         and,

          for (i = 0; i < 8192; i++)
                  mynsfd[i] = create_ns();

     (2) setns :
          * open /proc/self/ns/net (one time to 'save' and pin the 
initial netns)
           and then

         int create_ns(void)
         {
             unshare(CLONE_NEWNET);
             return open("/proc/self/ns/net");
         }

         and,

         for (i = 0; i < 8192; i++)
               mynsfd[i] = create_ns();

     (3) setns + mount :

          * open /proc/self/ns/net (one time to 'save' and pin the 
initial netns)
           and then

             int create_ns(const char *nspath)
             {
                unshare(CLONE_NEWNET);
                creat(nspath);
                mount("/proc/self/ns/net", nspath, MS_BIND);
             }

             for (i  = 0; i < 8192; i++)
                     create_ns(mynspath[i]);

Hope that helps.

   -- Daniel
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[ABI REVIEW][PATCH 0/8] Namespace file descriptors, Eric W. Biederman, (Thu Sep 23, 1:45 am)
[PATCH 1/8] ns: proc files for namespace naming policy., Eric W. Biederman, (Thu Sep 23, 1:46 am)
[PATCH 2/8] ns: Introduce the setns syscall, Eric W. Biederman, (Thu Sep 23, 1:46 am)
[PATCH 3/8] ns proc: Add support for the network namespace., Eric W. Biederman, (Thu Sep 23, 1:47 am)
[PATCH 4/8] ns proc: Add support for the uts namespace, Eric W. Biederman, (Thu Sep 23, 1:48 am)
[PATCH 6/8] ns proc: Add support for the mount namespace, Eric W. Biederman, (Thu Sep 23, 1:50 am)
[PATCH 7/8] net: Allow setting the network namespace by fd, Eric W. Biederman, (Thu Sep 23, 1:51 am)
[PATCH 8/8] net: Implement socketat., Eric W. Biederman, (Thu Sep 23, 1:51 am)
Re: [PATCH 8/8] net: Implement socketat., Pavel Emelyanov, (Thu Sep 23, 1:56 am)
Re: [PATCH 8/8] net: Implement socketat., jamal, (Thu Sep 23, 4:19 am)
Re: [PATCH 8/8] net: Implement socketat., Pavel Emelyanov, (Thu Sep 23, 4:33 am)
Re: [PATCH 8/8] net: Implement socketat., jamal, (Thu Sep 23, 4:40 am)
Re: [PATCH 8/8] net: Implement socketat., Pavel Emelyanov, (Thu Sep 23, 4:53 am)
Re: [PATCH 8/8] net: Implement socketat., jamal, (Thu Sep 23, 5:11 am)
Re: [PATCH 8/8] net: Implement socketat., Pavel Emelyanov, (Thu Sep 23, 5:34 am)
Re: [PATCH 8/8] net: Implement socketat., Eric W. Biederman, (Thu Sep 23, 8:00 am)
Re: [PATCH 7/8] net: Allow setting the network namespace by fd, Eric W. Biederman, (Thu Sep 23, 8:14 am)
Re: [ABI REVIEW][PATCH 0/8] Namespace file descriptors, David Lamparter, (Thu Sep 23, 8:18 am)
Re: [PATCH 3/8] ns proc: Add support for the network names ..., Eric W. Biederman, (Thu Sep 23, 9:00 am)
Re: [PATCH 7/8] net: Allow setting the network namespace by fd, Eric W. Biederman, (Thu Sep 23, 9:03 am)
Re: [PATCH 7/8] net: Allow setting the network namespace by fd, Eric W. Biederman, (Thu Sep 23, 9:16 am)
Re: [ABI REVIEW][PATCH 0/8] Namespace file descriptors, Eric W. Biederman, (Thu Sep 23, 9:32 am)
Re: [ABI REVIEW][PATCH 0/8] Namespace file descriptors, Andrew Lutomirski, (Fri Sep 24, 6:02 am)
Re: [ABI REVIEW][PATCH 0/8] Namespace file descriptors, Eric W. Biederman, (Fri Sep 24, 10:06 am)
Re: [PATCH 8/8] net: Implement socketat., Daniel Lezcano, (Sat Oct 2, 2:13 pm)
Re: [PATCH 8/8] net: Implement socketat., jamal, (Sun Oct 3, 6:44 am)
Re: [PATCH 8/8] net: Implement socketat., Daniel Lezcano, (Mon Oct 4, 3:13 am)
Re: [PATCH 8/8] net: Implement socketat., Eric W. Biederman, (Mon Oct 4, 12:07 pm)
Re: netns patches WAS( Re: [PATCH 8/8] net: Implement sock ..., Eric W. Biederman, (Tue Oct 26, 5:27 pm)