lib/syscall_virtstat.c \
lib/syscall_virtstat-v21.hc \
lib/syscall_ctxstat.c \
- lib/syscall_ctxstat-v21.hc
+ lib/syscall_ctxstat-v21.hc \
+ lib/syscall_getspacemask.c \
+ lib/syscall_getspacemask-v21.hc \
+ lib/syscall_enternamespace-v21.hc \
+ lib/syscall_setnamespace-v21.hc \
+ lib/syscall_ctxmigrate-v21.hc
if ENSC_HAVE_C99_COMPILER
lib_v13_SRCS += lib/syscall_adddlimit-v13.hc \
lib_SRCS = lib/syscall.c \
lib/checkversion.c \
+ lib/checkconfig.c \
lib/isdirectory.c \
lib/isfile.c \
lib/islink.c \
--- /dev/null
+// $Id$ --*- c++ -*--
+
+// Copyright (C) 2003 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"
+#include "vserver-internal.h"
+
+uint_least32_t
+utilvserver_checkCompatConfig()
+{
+#ifdef VC_ENABLE_API_V21
+ static uint32_t res=0;
+ static int v_errno;
+
+ if (res==0) {
+ res = vc_get_vci();
+ v_errno = errno;
+ if (res==(uint32_t)-1 && (errno==ENOSYS || errno==EINVAL)) res=0;
+ }
+
+ errno = v_errno;
+ return res;
+#else
+ return 0;
+#endif
+}
#endif
#include "vserver.h"
-#include "virtual.h"
+#include "internal.h"
vcXidType
vc_getXIDType(xid_t xid)
{
- if (xid==0) return vcTYPE_MAIN;
- if (xid==1) return vcTYPE_WATCH;
- if (xid>1 && xid<MIN_D_CONTEXT) return vcTYPE_STATIC;
- if (xid>=MIN_D_CONTEXT && xid<MAX_S_CONTEXT) return vcTYPE_DYNAMIC;
+ static xid_t MIN_D_CONTEXT = 0;
+ const xid_t MAX_S_CONTEXT = 65535;
+ if (MIN_D_CONTEXT == 0 && (utilvserver_checkCompatConfig() & VC_VCI_NO_DYNAMIC) == 0)
+ MIN_D_CONTEXT = 49152;
+ else
+ MIN_D_CONTEXT = MAX_S_CONTEXT;
+
+ if (xid==0) return vcTYPE_MAIN;
+ if (xid==1) return vcTYPE_WATCH;
+ if (xid>1 && xid<MIN_D_CONTEXT) return vcTYPE_STATIC;
+ if (xid>=MIN_D_CONTEXT && xid<MAX_S_CONTEXT) return vcTYPE_DYNAMIC;
return vcTYPE_INVALID;
}
int utilvserver_checkCompatVersion();
+uint_least32_t utilvserver_checkCompatConfig();
bool utilvserver_isDirectory(char const *path, bool follow_link);
bool utilvserver_isFile(char const *path, bool follow_link);
bool utilvserver_isLink(char const *path);
bool
vc_is_dynamic_xid(xid_t xid)
{
- return xid>=MIN_D_CONTEXT;
+ return vc_getXIDType(xid) == vcTYPE_DYNAMIC;
}
--- /dev/null
+// $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
+
+static inline ALWAYSINLINE int
+vc_ctx_migrate_spaces(xid_t xid)
+{
+ int ret;
+
+ ret = vc_enter_namespace(xid, vc_get_space_mask() & ~(CLONE_NEWNS|CLONE_FS));
+ if (ret)
+ return ret;
+
+ return vserver(VCMD_ctx_migrate_v0, CTX_USER2KERNEL(xid), NULL);
+}
#endif
#include "vserver.h"
-#include "vserver-internal.h"
#include "virtual.h"
+#if defined(VC_ENABLE_API_V13) && defined(VC_ENABLE_API_V21)
+# define VC_MULTIVERSION_SYSCALL 1
+#endif
+#include "vserver-internal.h"
+
#if defined(VC_ENABLE_API_V13)
# include "syscall_ctxmigrate-v13.hc"
#endif
-#if defined(VC_ENABLE_API_V13)
+#if defined(VC_ENABLE_API_V21)
+# include "syscall_ctxmigrate-v21.hc"
+#endif
+
+#if defined(VC_ENABLE_API_V13) || defined(VC_ENABLE_API_V21)
int
vc_ctx_migrate(xid_t xid)
{
- CALL_VC(CALL_VC_V13A(vc_ctx_migrate, xid));
+ CALL_VC(CALL_VC_SPACES(vc_ctx_migrate, xid),
+ CALL_VC_V13A (vc_ctx_migrate, xid));
}
#endif
#include "vserver.h"
static inline ALWAYSINLINE int
-vc_enter_namespace_v13(xid_t xid)
+vc_enter_namespace_v13(xid_t xid, uint_least64_t mask)
{
- return vserver(VCMD_enter_namespace, CTX_USER2KERNEL(xid), 0);
+ if ((mask & (CLONE_NEWNS|CLONE_FS)) == 0)
+ return 0;
+ return vserver(VCMD_enter_space_v0, CTX_USER2KERNEL(xid), 0);
}
--- /dev/null
+// $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_spaces(xid_t xid, uint_least64_t mask)
+{
+ struct vcmd_space_mask data = { .mask = mask };
+ return vserver(VCMD_enter_space, CTX_USER2KERNEL(xid), &data);
+}
#include "vserver.h"
#include "virtual.h"
+#if defined(VC_ENABLE_API_V13) && defined(VC_ENABLE_API_V21)
+# define VC_MULTIVERSION_SYSCALL 1
+#endif
#include "vserver-internal.h"
#ifdef VC_ENABLE_API_V13
# include "syscall_enternamespace-v13.hc"
#endif
+#ifdef VC_ENABLE_API_V21
+# include "syscall_enternamespace-v21.hc"
+#endif
+
+#if defined(VC_ENABLE_API_V13) || defined(VC_ENABLE_API_V21)
int
-vc_enter_namespace(xid_t xid)
+vc_enter_namespace(xid_t xid, uint_least64_t mask)
{
- CALL_VC(CALL_VC_V13(vc_enter_namespace, xid));
+ CALL_VC(CALL_VC_SPACES(vc_enter_namespace, xid, mask),
+ CALL_VC_V13 (vc_enter_namespace, xid, mask));
}
+#endif
--- /dev/null
+// $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
+
+static inline ALWAYSINLINE uint_least64_t
+vc_get_space_mask_spaces(int UNUSED tmp)
+{
+ struct vcmd_space_mask data = { .mask = 0 };
+ int ret = vserver(VCMD_get_space_mask, 0, &data);
+ if (ret)
+ return ret;
+ return data.mask;
+}
--- /dev/null
+// $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"
+#include "vserver-internal.h"
+#include "virtual.h"
+
+#if defined(VC_ENABLE_API_V21)
+# include "syscall_getspacemask-v21.hc"
+#endif
+
+#if defined(VC_ENABLE_API_V21)
+uint_least64_t
+vc_get_space_mask()
+{
+ CALL_VC(CALL_VC_SPACES(vc_get_space_mask, 0));
+}
+#endif
#endif
static inline ALWAYSINLINE int
-vc_get_vci_v21()
+vc_get_vci_v21(int UNUSED tmp)
{
return vserver(VCMD_get_vci, 0, 0);
}
int
vc_get_vci()
{
- CALL_VC(CALL_VC_V21(vc_get_vci));
+ CALL_VC(CALL_VC_V21(vc_get_vci, 0));
}
#endif
#include "vserver.h"
static inline ALWAYSINLINE int
-vc_set_namespace_v13(int UNUSED tmp)
+vc_set_namespace_v13(xid_t xid, uint_least64_t mask)
{
- return vserver(VCMD_set_namespace_v0, -1, 0);
+ if ((mask & (CLONE_NEWNS|CLONE_FS)) == 0)
+ return 0;
+ return vserver(VCMD_set_space_v0, CTX_USER2KERNEL(xid), 0);
}
--- /dev/null
+// $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_spaces(xid_t xid, uint_least64_t mask)
+{
+ struct vcmd_space_mask data = { .mask = mask };
+ return vserver(VCMD_set_space, CTX_USER2KERNEL(xid), &data);
+}
#include "vserver.h"
#include "virtual.h"
+#if defined(VC_ENABLE_API_V13) && defined(VC_ENABLE_API_V21)
+# define VC_MULTIVERSION_SYSCALL 1
+#endif
#include "vserver-internal.h"
#ifdef VC_ENABLE_API_V13
# include "syscall_setnamespace-v13.hc"
#endif
+#ifdef VC_ENABLE_API_V21
+# include "syscall_setnamespace-v21.hc"
+#endif
+
+#if defined(VC_ENABLE_API_V13) || defined(VC_ENABLE_API_V21)
int
-vc_set_namespace()
+vc_set_namespace(xid_t xid, uint_least64_t mask)
{
- CALL_VC(CALL_VC_V13(vc_set_namespace,0));
+ CALL_VC(CALL_VC_SPACES(vc_set_namespace, xid, mask),
+ CALL_VC_V13 (vc_set_namespace, xid, mask));
}
+#endif
#ifndef H_UTIL_VSERVER_LIB_VIRTUAL_H
#define H_UTIL_VSERVER_LIB_VIRTUAL_H
-#include <kernel/context.h>
#include <kernel/context_cmd.h>
#include <kernel/cvirt_cmd.h>
#include <kernel/cvirt_cmd.h>
-#include <kernel/dlimit.h>
#include <kernel/dlimit_cmd.h>
#include <kernel/inode_cmd.h>
#include <kernel/limit_cmd.h>
-#include <kernel/namespace_cmd.h>
+#include <kernel/space_cmd.h>
+#include <kernel/network.h>
#include <kernel/network_cmd.h>
#include <kernel/sched_cmd.h>
#include <kernel/signal_cmd.h>
-#include <kernel/network.h>
#include <kernel/legacy.h>
#endif // H_UTIL_VSERVER_LIB_VIRTUAL_H
#define CALL_VC_NOOP vc_noop0()
#define CALL_VC_GENERAL(ID, SUFFIX, FUNC, ...) \
VC_PREFIX; VC_SELECT(ID) return FUNC ## _ ## SUFFIX(__VA_ARGS__); VC_SUFFIX
+#define CALL_VC_GENERAL_CONFIG(BIT, SUFFIX, FUNC, ...) \
+ VC_PREFIX; VC_CBIT(BIT) return FUNC ## _ ## SUFFIX(__VA_ARGS__); VC_SUFFIX
#ifdef VC_MULTIVERSION_SYSCALL
# define VC_SELECT(ID) if (ver>=(ID))
+# define VC_CBIT(BIT) if ((conf&BIT) == BIT)
# define CALL_VC(...) \
do { \
int ver = utilvserver_checkCompatVersion(); \
+ int UNUSED conf = utilvserver_checkCompatConfig(); \
if (ver==-1) return -1; \
VC_SUFFIX, __VA_ARGS__, VC_PREFIX; \
errno = ENOSYS; \
} while (0)
#else
# define VC_SELECT(ID) if (1)
+# define VC_CBIT(BIT) if (1)
# define CALL_VC(...) \
do { \
if (1) {} VC_SUFFIX, __VA_ARGS__, VC_PREFIX; \
# define CALL_VC_V13OBS(F,...) CALL_VC_NOOP
#endif
-
#ifdef VC_ENABLE_API_V21
# define CALL_VC_V21(F,...) CALL_VC_GENERAL(0x00020100, v21, F, __VA_ARGS__)
#else
# define CALL_VC_V21(F,...) CALL_VC_NOOP
#endif
+#ifdef VC_ENABLE_API_V21
+# define CALL_VC_SPACES(F,...) CALL_VC_GENERAL_CONFIG(VC_VCI_SPACES, spaces, F, __VA_ARGS__)
+#else
+# define CALL_VC_SPACES(F,...) CALL_VC_NOOP
+#endif
#ifdef VC_ENABLE_API_NET
# define CALL_VC_NET(F,...) CALL_VC_GENERAL(0x00010016, net, F, __VA_ARGS__)
#include <stdlib.h>
#include <stdbool.h>
#include <sys/types.h>
+#include <sched.h>
#ifndef IS_DOXYGEN
#if defined(__GNUC__)
#define VC_VLIMIT_MAPPED 23
+// the VCI bit values
+#define VC_VCI_NO_DYNAMIC (1 << 0)
+#define VC_VCI_SPACES (1 << 10)
+
+
+#ifndef CLONE_NEWNS
+# define CLONE_NEWNS 0x00020000
+#endif
+#ifndef CLONE_NEWUTS
+# define CLONE_NEWUTS 0x04000000
+#endif
+#ifndef CLONE_NEWIPC
+# define CLONE_NEWIPC 0x08000000
+#endif
+
+
#define VC_BAD_PERSONALITY ((uint_least32_t)(-1))
/** Returns true iff \a xid is a dynamic xid */
bool vc_is_dynamic_xid(xid_t xid);
- int vc_enter_namespace(xid_t xid);
- int vc_set_namespace();
+ int vc_enter_namespace(xid_t xid, uint_least64_t mask);
+ int vc_set_namespace(xid_t xid, uint_least64_t mask);
int vc_cleanup_namespace();
+ uint_least64_t vc_get_space_mask();
/** \brief Flags of process-contexts
if (args->do_chroot) {
Echroot(".");
if (args->set_namespace) {
- if (args->do_migrateself) Evc_set_namespace();
- else if (args->do_migrate) Evc_enter_namespace(xid);
+ if (args->do_migrateself) Evc_set_namespace(xid, 0);
+ else if (args->do_migrate) Evc_enter_namespace(xid, 0);
}
}
#define ENSC_WRAPPERS_VSERVER 1
#include <wrappers.h>
-#ifndef CLONE_NEWUTS
-# define CLONE_NEWUTS 0x04000000
-#endif
-#ifndef CLONE_NEWIPC
-# define CLONE_NEWIPC 0x08000000
-#endif
-
#define CMD_HELP 0x1000
#define CMD_VERSION 0x1001
signal(SIGCHLD, SIG_DFL);
#ifdef NDEBUG
- pid = sys_clone(CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|CLONE_VFORK|SIGCHLD, 0);
+ pid = sys_clone(CLONE_NEWNS|CLONE_VFORK|SIGCHLD, 0);
#else
- pid = sys_clone(CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|SIGCHLD, 0);
+ pid = sys_clone(CLONE_NEWNS|SIGCHLD, 0);
#endif
switch (pid) {
}
static void
-enterNamespace(xid_t xid)
+enterNamespace(xid_t xid, uint_least64_t mask)
{
- if (vc_enter_namespace(xid)==-1) {
+ if (vc_enter_namespace(xid, mask)==-1) {
perror("vnamespace: vc_enter_namespace()");
exit(255);
}
}
static void
-setNamespace()
+setNamespace(xid_t xid, uint_least64_t mask)
{
- if (vc_set_namespace()==-1) {
+ if (vc_set_namespace(xid, mask)==-1) {
perror("vnamespace: vc_set_namespace()");
exit(255);
}
WRITE_MSG(2, "No command specified; try '--help' for more information\n");
else {
if (do_new) newNamespace(argv[optind]);
- else if (do_set) setNamespace();
+ else if (do_set) setNamespace(VC_SAMECTX, CLONE_NEWNS|CLONE_FS);
else if (do_cleanup) cleanupNamespace();
- else if (do_enter) enterNamespace(xid);
+ else if (do_enter) enterNamespace(xid, CLONE_NEWNS|CLONE_FS);
if (optind<argc)
EexecvpD(argv[optind], argv+optind);