Add VCMD_{enter,set}_space_v2 support, in preparation of pivot_root.
authorDaniel Hokka Zakrisson <daniel@hozac.com>
Fri, 31 Oct 2008 04:45:26 +0000 (04:45 +0000)
committerDaniel Hokka Zakrisson <daniel@hozac.com>
Fri, 31 Oct 2008 04:45:26 +0000 (04:45 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2817 94cd875c-1c1d-0410-91d2-eb244daf1a30

17 files changed:
ensc_wrappers/wrappers-vserver.hc
kernel/space_cmd.h
lib/Makefile-files
lib/syscall_enternamespace-v13.hc
lib/syscall_enternamespace-v21.hc
lib/syscall_enternamespace-v23.hc [new file with mode: 0644]
lib/syscall_enternamespace.c
lib/syscall_getspacedefault-v23.hc
lib/syscall_getspacemask-v21.hc
lib/syscall_setnamespace-v13.hc
lib/syscall_setnamespace-v21.hc
lib/syscall_setnamespace-v23.hc [new file with mode: 0644]
lib/syscall_setnamespace.c
lib/vserver.h
python/_libvserver.c
src/vcontext.c
src/vspace.c

index d86dbcf..c134c35 100644 (file)
@@ -146,15 +146,15 @@ Evc_set_ncaps(nid_t nid, struct vc_net_caps const *caps)
 }
 
 inline static WRAPPER_DECL void
-Evc_set_namespace(xid_t xid, uint_least64_t mask)
+Evc_set_namespace(xid_t xid, uint_least64_t mask, uint32_t index)
 {
-  FatalErrnoError(vc_set_namespace(xid, mask)==-1, "vc_set_namespace()");
+  FatalErrnoError(vc_set_namespace(xid, mask, index)==-1, "vc_set_namespace()");
 }
 
 inline static WRAPPER_DECL void
-Evc_enter_namespace(xid_t xid, uint_least64_t mask)
+Evc_enter_namespace(xid_t xid, uint_least64_t mask, uint32_t index)
 {
-  FatalErrnoError(vc_enter_namespace(xid, mask)==-1, "vc_enter_namespace()");
+  FatalErrnoError(vc_enter_namespace(xid, mask, index)==-1, "vc_enter_namespace()");
 }
 
 inline static WRAPPER_DECL xid_t
index 17dcac7..0be0a58 100644 (file)
@@ -3,22 +3,29 @@
 
 
 #define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
-#define VCMD_enter_space       VC_CMD(PROCALT, 1, 1)
+#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
+#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
 
 /* XXX: This is not available in recent kernels */
 #define VCMD_cleanup_namespace VC_CMD(PROCALT, 2, 0)
 
 #define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
-#define VCMD_set_space         VC_CMD(PROCALT, 3, 1)
+#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
+#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
 
 #define VCMD_get_space_mask    VC_CMD(PROCALT, 4, 0)
 
 #define VCMD_get_space_default VC_CMD(PROCALT, 7, 0)
 
 
-struct vcmd_space_mask {
+struct vcmd_space_mask_v1 {
        uint64_t mask;
 };
 
+struct vcmd_space_mask_v2 {
+       uint64_t mask;
+       uint32_t index;
+};
+
 
 #endif /* _VX_SPACE_CMD_H */
index b42adce..0f906f4 100644 (file)
@@ -159,7 +159,9 @@ lib_v23_SRCS =                      lib/syscall_tagmigrate-v23.hc \
                                lib/syscall_setbadness.c \
                                lib/syscall_setbadness-v23.hc \
                                lib/syscall_getspacedefault.c \
-                               lib/syscall_getspacedefault-v23.hc
+                               lib/syscall_getspacedefault-v23.hc \
+                               lib/syscall_setnamespace-v23.hc \
+                               lib/syscall_enternamespace-v23.hc
 
 if ENSC_HAVE_C99_COMPILER
 lib_v13_SRCS +=                        lib/syscall_adddlimit-v13.hc \
index e4dc1cf..cbdaede 100644 (file)
 #include "vserver.h"
 
 static inline ALWAYSINLINE int
-vc_enter_namespace_v13(xid_t xid, uint_least64_t mask)
+vc_enter_namespace_v13(xid_t xid, uint_least64_t mask, uint32_t index)
 {
   if ((mask & (CLONE_NEWNS|CLONE_FS)) == 0)
     return 0;
+  if (index != 0) {
+    errno = EINVAL;
+    return -1;
+  }
   return vserver(VCMD_enter_space_v0, CTX_USER2KERNEL(xid), 0);
 }
index 0106984..c17179c 100644 (file)
 #include "vserver.h"
 
 static inline ALWAYSINLINE int
-vc_enter_namespace_spaces(xid_t xid, uint_least64_t mask)
+vc_enter_namespace_spaces(xid_t xid, uint_least64_t mask, uint32_t index)
 {
-  struct vcmd_space_mask data = { .mask = mask };
-  return vserver(VCMD_enter_space, CTX_USER2KERNEL(xid), &data);
+  struct vcmd_space_mask_v1 data = { .mask = mask };
+  if (index != 0) {
+    errno = EINVAL;
+    return -1;
+  }
+  return vserver(VCMD_enter_space_v1, CTX_USER2KERNEL(xid), &data);
 }
diff --git a/lib/syscall_enternamespace-v23.hc b/lib/syscall_enternamespace-v23.hc
new file mode 100644 (file)
index 0000000..0625623
--- /dev/null
@@ -0,0 +1,31 @@
+// $Id$    --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+// Copyright (C) 2006 Daniel Hokka Zakrisson
+//  
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//  
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//  
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "vserver.h"
+
+static inline ALWAYSINLINE int
+vc_enter_namespace_v23(xid_t xid, uint_least64_t mask, uint32_t index)
+{
+  struct vcmd_space_mask_v2 data = { .mask = mask, .index = index };
+  return vserver(VCMD_enter_space, CTX_USER2KERNEL(xid), &data);
+}
index 4eaeae1..1603b34 100644 (file)
@@ -23,9 +23,7 @@
 #include "vserver.h"
 #include "virtual.h"
 
-#if defined(VC_ENABLE_API_V13) && defined(VC_ENABLE_API_V21)
-#  define VC_MULTIVERSION_SYSCALL 1
-#endif
+#define VC_MULTIVERSION_SYSCALL 1
 #include "vserver-internal.h"
 
 #ifdef VC_ENABLE_API_V13
 #  include "syscall_enternamespace-v21.hc"
 #endif
 
+#ifdef VC_ENABLE_API_V23
+#  include "syscall_enternamespace-v23.hc"
+#endif
+
 #if defined(VC_ENABLE_API_V13) || defined(VC_ENABLE_API_V21)
 int
-vc_enter_namespace(xid_t xid, uint_least64_t mask)
+vc_enter_namespace(xid_t xid, uint_least64_t mask, uint32_t index)
 {
-  CALL_VC(CALL_VC_SPACES(vc_enter_namespace, xid, mask),
-         CALL_VC_V13   (vc_enter_namespace, xid, mask));
+  CALL_VC(CALL_VC_V23P  (vc_enter_namespace, xid, mask, index),
+         CALL_VC_SPACES(vc_enter_namespace, xid, mask, index),
+         CALL_VC_V13   (vc_enter_namespace, xid, mask, index));
 }
 #endif
index 766a5e6..8be0635 100644 (file)
@@ -23,7 +23,7 @@
 static inline ALWAYSINLINE uint_least64_t
 vc_get_space_default_v23(int UNUSED tmp)
 {
-  struct vcmd_space_mask data = { .mask = 0 };
+  struct vcmd_space_mask_v1 data = { .mask = 0 };
   int ret = vserver(VCMD_get_space_default, 0, &data);
   if (ret)
     return ret;
index 1896bef..1511b9d 100644 (file)
@@ -24,7 +24,7 @@
 static inline ALWAYSINLINE uint_least64_t
 vc_get_space_mask_spaces(int UNUSED tmp)
 {
-  struct vcmd_space_mask data = { .mask = 0 };
+  struct vcmd_space_mask_v1 data = { .mask = 0 };
   int ret = vserver(VCMD_get_space_mask, 0, &data);
   if (ret)
     return ret;
index 915d67d..dd1bf88 100644 (file)
 #include "vserver.h"
 
 static inline ALWAYSINLINE int
-vc_set_namespace_v13(xid_t xid, uint_least64_t mask)
+vc_set_namespace_v13(xid_t xid, uint_least64_t mask, uint32_t index)
 {
   if ((mask & (CLONE_NEWNS|CLONE_FS)) == 0)
     return 0;
+  if (index != 0) {
+    errno = EINVAL;
+    return -1;
+  }
   return vserver(VCMD_set_space_v0, CTX_USER2KERNEL(xid), 0);
 }
index 160a124..5a719de 100644 (file)
 #include "vserver.h"
 
 static inline ALWAYSINLINE int
-vc_set_namespace_spaces(xid_t xid, uint_least64_t mask)
+vc_set_namespace_spaces(xid_t xid, uint_least64_t mask, uint32_t index)
 {
-  struct vcmd_space_mask data = { .mask = mask };
-  return vserver(VCMD_set_space, CTX_USER2KERNEL(xid), &data);
+  struct vcmd_space_mask_v1 data = { .mask = mask };
+  if (index != 0) {
+    errno = EINVAL;
+    return -1;
+  }
+  return vserver(VCMD_set_space_v1, CTX_USER2KERNEL(xid), &data);
 }
diff --git a/lib/syscall_setnamespace-v23.hc b/lib/syscall_setnamespace-v23.hc
new file mode 100644 (file)
index 0000000..922c25d
--- /dev/null
@@ -0,0 +1,31 @@
+// $Id$    --*- c -*--
+
+// Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+// Copyright (C) 2006 Daniel Hokka Zakrisson
+//  
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//  
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//  
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include "vserver.h"
+
+static inline ALWAYSINLINE int
+vc_set_namespace_v23(xid_t xid, uint_least64_t mask, uint32_t index)
+{
+  struct vcmd_space_mask_v2 data = { .mask = mask, .index = index };
+  return vserver(VCMD_set_space, CTX_USER2KERNEL(xid), &data);
+}
index 0e4d4a2..42c1847 100644 (file)
@@ -23,9 +23,7 @@
 #include "vserver.h"
 #include "virtual.h"
 
-#if defined(VC_ENABLE_API_V13) && defined(VC_ENABLE_API_V21)
-#  define VC_MULTIVERSION_SYSCALL 1
-#endif
+#define VC_MULTIVERSION_SYSCALL 1
 #include "vserver-internal.h"
 
 #ifdef VC_ENABLE_API_V13
 #  include "syscall_setnamespace-v21.hc"
 #endif
 
-#if defined(VC_ENABLE_API_V13) || defined(VC_ENABLE_API_V21)
+#ifdef VC_ENABLE_API_V23
+#  include "syscall_setnamespace-v23.hc"
+#endif
+
+#if defined(VC_ENABLE_API_V13) || defined(VC_ENABLE_API_V21) || defined(VC_ENABLE_API_V23)
 int
-vc_set_namespace(xid_t xid, uint_least64_t mask)
+vc_set_namespace(xid_t xid, uint_least64_t mask, uint32_t index)
 {
-  CALL_VC(CALL_VC_SPACES(vc_set_namespace, xid, mask),
-         CALL_VC_V13   (vc_set_namespace, xid, mask));
+  CALL_VC(CALL_VC_V23P  (vc_set_namespace, xid, mask, index),
+         CALL_VC_SPACES(vc_set_namespace, xid, mask, index),
+         CALL_VC_V13   (vc_set_namespace, xid, mask, index));
 }
 #endif
index 488aa50..4d92b29 100644 (file)
@@ -764,8 +764,8 @@ extern "C" {
                                char *val, size_t len)       VC_ATTR_NONNULL((3));
 
     /* namespace related functions */
-  int          vc_enter_namespace(xid_t xid, uint_least64_t mask);
-  int          vc_set_namespace(xid_t xid, uint_least64_t mask);
+  int          vc_enter_namespace(xid_t xid, uint_least64_t mask, uint32_t index);
+  int          vc_set_namespace(xid_t xid, uint_least64_t mask, uint32_t index);
   int          vc_cleanup_namespace(void);
   uint_least64_t vc_get_space_mask(void);
   uint_least64_t vc_get_space_default(void);
index dfba4e6..b1eb86a 100644 (file)
@@ -607,11 +607,12 @@ pyvserver_enter_namespace(PyObject UNUSED *self, PyObject *args)
 {
   xid_t xid;
   uint_least64_t mask;
+  uint32_t index;
 
-  if (!PyArg_ParseTuple(args, "IK", &xid, &mask))
+  if (!PyArg_ParseTuple(args, "IKI", &xid, &mask, &index))
     return NULL;
 
-  if (vc_enter_namespace(xid, mask) == -1)
+  if (vc_enter_namespace(xid, mask, index) == -1)
     return PyErr_SetFromErrno(PyExc_OSError);
 
   return NONE();
@@ -622,11 +623,12 @@ pyvserver_set_namespace(PyObject UNUSED *self, PyObject *args)
 {
   xid_t xid;
   uint_least64_t mask;
+  uint32_t index;
 
-  if (!PyArg_ParseTuple(args, "IK", &xid, &mask))
+  if (!PyArg_ParseTuple(args, "IKI", &xid, &mask, &index))
     return NULL;
 
-  if (vc_set_namespace(xid, mask) == -1)
+  if (vc_set_namespace(xid, mask, index) == -1)
     return PyErr_SetFromErrno(PyExc_OSError);
 
   return NONE();
index a42a82e..9768041 100644 (file)
@@ -274,8 +274,8 @@ doit(struct Arguments const *args, int argc, char *argv[])
     if (args->do_chroot) {
       Echroot(".");
       if (args->set_namespace) {
-       if (args->do_migrateself)  Evc_set_namespace(xid, CLONE_NEWNS|CLONE_FS);
-       else if (args->do_migrate) Evc_enter_namespace(xid, CLONE_NEWNS|CLONE_FS);
+       if (args->do_migrateself)  Evc_set_namespace(xid, CLONE_NEWNS|CLONE_FS, 0);
+       else if (args->do_migrate) Evc_enter_namespace(xid, CLONE_NEWNS|CLONE_FS, 0);
       }
     }
 
index a6aeb83..fdcedb3 100644 (file)
@@ -49,6 +49,7 @@ CMDLINE_OPTIONS[] = {
   { "new",        no_argument,       0, 'n' },
   { "enter",      required_argument, 0, 'e' },
   { "set",        no_argument,       0, 's' },
+  { "index",      required_argument, 0, 'i' },
   { "mask",       required_argument, 0, 'm' },
   { "default",    no_argument,       0, 'd' },
   { "~default",   no_argument,       0, 'd' | 0x10000 },
@@ -142,18 +143,18 @@ newSpaces(uint_least64_t mask)
 }
 
 static void
-enterSpaces(xid_t xid, uint_least64_t mask)
+enterSpaces(xid_t xid, uint_least64_t mask, uint32_t index)
 {
-  if (vc_enter_namespace(xid, mask)==-1) {
+  if (vc_enter_namespace(xid, mask, index)==-1) {
     perror(ENSC_WRAPPERS_PREFIX "vc_enter_namespace()");
     exit(wrapper_exit_code);
   }
 }
 
 static void
-setSpaces(xid_t xid, uint_least64_t mask)
+setSpaces(xid_t xid, uint_least64_t mask, uint32_t index)
 {
-  if (vc_set_namespace(xid, mask)==-1) {
+  if (vc_set_namespace(xid, mask, index)==-1) {
     perror(ENSC_WRAPPERS_PREFIX "vc_set_namespace()");
     exit(wrapper_exit_code);
   }
@@ -165,6 +166,7 @@ int main(int argc, char *argv[])
   bool                 do_enter   = false;
   bool                 do_set     = false;
   uint_least64_t       mask       = 0;
+  uint32_t             index      = 0;
   xid_t                        xid        = VC_NOCTX;
   int                  sum        = 0;
   
@@ -182,6 +184,17 @@ int main(int argc, char *argv[])
        do_enter = true;
        xid      = Evc_xidopt2xid(optarg,true);
        break;
+      case 'i'         :  {
+       unsigned long   index_l;
+       if (!isNumberUnsigned(optarg, &index_l, true)) {
+         WRITE_MSG(2, "Invalid index '");
+         WRITE_STR(2, optarg);
+         WRITE_MSG(2, "'; try '--help' for more information\n");
+         return wrapper_exit_code;
+       }
+       index = (uint32_t)index_l;
+       break;
+      }
       case 'm'         :  {
        unsigned long   mask_l;
        if (!isNumberUnsigned(optarg, &mask_l, true)) {
@@ -234,8 +247,8 @@ int main(int argc, char *argv[])
     WRITE_MSG(2, "No command specified; try '--help' for more information\n");
   else {
     if      (do_new)     newSpaces(mask);
-    else if (do_set)     setSpaces(VC_SAMECTX, mask);
-    else if (do_enter)   enterSpaces(xid, mask);
+    else if (do_set)     setSpaces(VC_SAMECTX, mask, index);
+    else if (do_enter)   enterSpaces(xid, mask, index);
 
     if (optind<argc)
       EexecvpD(argv[optind], argv+optind);