From: Daniel Hokka Zakrisson Date: Fri, 31 Oct 2008 04:45:26 +0000 (+0000) Subject: Add VCMD_{enter,set}_space_v2 support, in preparation of pivot_root. X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=adfc83d4b20c0797654b9a30b6f7699ab90d31ea;p=util-vserver.git Add VCMD_{enter,set}_space_v2 support, in preparation of pivot_root. git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2817 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- diff --git a/ensc_wrappers/wrappers-vserver.hc b/ensc_wrappers/wrappers-vserver.hc index d86dbcf..c134c35 100644 --- a/ensc_wrappers/wrappers-vserver.hc +++ b/ensc_wrappers/wrappers-vserver.hc @@ -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 diff --git a/kernel/space_cmd.h b/kernel/space_cmd.h index 17dcac7..0be0a58 100644 --- a/kernel/space_cmd.h +++ b/kernel/space_cmd.h @@ -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 */ diff --git a/lib/Makefile-files b/lib/Makefile-files index b42adce..0f906f4 100644 --- a/lib/Makefile-files +++ b/lib/Makefile-files @@ -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 \ diff --git a/lib/syscall_enternamespace-v13.hc b/lib/syscall_enternamespace-v13.hc index e4dc1cf..cbdaede 100644 --- a/lib/syscall_enternamespace-v13.hc +++ b/lib/syscall_enternamespace-v13.hc @@ -23,9 +23,13 @@ #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); } diff --git a/lib/syscall_enternamespace-v21.hc b/lib/syscall_enternamespace-v21.hc index 0106984..c17179c 100644 --- a/lib/syscall_enternamespace-v21.hc +++ b/lib/syscall_enternamespace-v21.hc @@ -24,8 +24,12 @@ #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 index 0000000..0625623 --- /dev/null +++ b/lib/syscall_enternamespace-v23.hc @@ -0,0 +1,31 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// 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 +#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); +} diff --git a/lib/syscall_enternamespace.c b/lib/syscall_enternamespace.c index 4eaeae1..1603b34 100644 --- a/lib/syscall_enternamespace.c +++ b/lib/syscall_enternamespace.c @@ -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 @@ -36,11 +34,16 @@ # 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 diff --git a/lib/syscall_getspacedefault-v23.hc b/lib/syscall_getspacedefault-v23.hc index 766a5e6..8be0635 100644 --- a/lib/syscall_getspacedefault-v23.hc +++ b/lib/syscall_getspacedefault-v23.hc @@ -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; diff --git a/lib/syscall_getspacemask-v21.hc b/lib/syscall_getspacemask-v21.hc index 1896bef..1511b9d 100644 --- a/lib/syscall_getspacemask-v21.hc +++ b/lib/syscall_getspacemask-v21.hc @@ -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; diff --git a/lib/syscall_setnamespace-v13.hc b/lib/syscall_setnamespace-v13.hc index 915d67d..dd1bf88 100644 --- a/lib/syscall_setnamespace-v13.hc +++ b/lib/syscall_setnamespace-v13.hc @@ -23,9 +23,13 @@ #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); } diff --git a/lib/syscall_setnamespace-v21.hc b/lib/syscall_setnamespace-v21.hc index 160a124..5a719de 100644 --- a/lib/syscall_setnamespace-v21.hc +++ b/lib/syscall_setnamespace-v21.hc @@ -24,8 +24,12 @@ #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 index 0000000..922c25d --- /dev/null +++ b/lib/syscall_setnamespace-v23.hc @@ -0,0 +1,31 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// 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 +#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); +} diff --git a/lib/syscall_setnamespace.c b/lib/syscall_setnamespace.c index 0e4d4a2..42c1847 100644 --- a/lib/syscall_setnamespace.c +++ b/lib/syscall_setnamespace.c @@ -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 @@ -36,11 +34,16 @@ # 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 diff --git a/lib/vserver.h b/lib/vserver.h index 488aa50..4d92b29 100644 --- a/lib/vserver.h +++ b/lib/vserver.h @@ -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); diff --git a/python/_libvserver.c b/python/_libvserver.c index dfba4e6..b1eb86a 100644 --- a/python/_libvserver.c +++ b/python/_libvserver.c @@ -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(); diff --git a/src/vcontext.c b/src/vcontext.c index a42a82e..9768041 100644 --- a/src/vcontext.c +++ b/src/vcontext.c @@ -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); } } diff --git a/src/vspace.c b/src/vspace.c index a6aeb83..fdcedb3 100644 --- a/src/vspace.c +++ b/src/vspace.c @@ -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