From dffca81b18d54e1ea6db1213b85e1741bd85861f Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Wed, 16 Feb 2011 12:49:03 +0000 Subject: [PATCH] Only call remount on kernels newer than 2.6.26 without BME where it's needed, as it will remount the base superblock with the options given on older kernels. git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2935 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- lib/Makefile-files | 1 + lib/getkernel.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/issupported.c | 2 ++ lib/issupportedstring.c | 2 +- lib/vserver.h | 3 +++ src/secure-mount.c | 3 ++- 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 lib/getkernel.c diff --git a/lib/Makefile-files b/lib/Makefile-files index 075c82c..e607f53 100644 --- a/lib/Makefile-files +++ b/lib/Makefile-files @@ -203,6 +203,7 @@ lib_SRCS = lib/syscall.c \ lib/val2text-v2t-uint32.c \ lib/val2text-v2t-uint64.c \ lib/parselimit.c \ + lib/getkernel.c \ $(lib_legacy_SRCS) \ $(lib_compat_SRCS) \ $(lib_management_SRCS) \ diff --git a/lib/getkernel.c b/lib/getkernel.c new file mode 100644 index 0000000..b9a36c8 --- /dev/null +++ b/lib/getkernel.c @@ -0,0 +1,58 @@ +// $Id$ --*- c++ -*-- + +// Copyright (C) 2011 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 +#include + +int +vc_get_kernel() +{ + static int linux_ver = -1; + if (linux_ver == -1) { + struct utsname uts; + char *p; + int part, n; + if (uname(&uts) == -1) + return -1; + part = 0; + n = 0; + linux_ver = 0; + for (p = uts.release; *p && part < 3; p++) { + if (*p == '.') { + if (part < 3) { + linux_ver |= n << (8 * (2 - part)); + n = 0; + part++; + } + } + else if (isdigit(*p)) { + n *= 10; + n += *p - '0'; + } + else + break; + } + if (n > 0 && part < 3) + linux_ver |= n << (8 * (2 - part)); + } + return linux_ver; +} diff --git a/lib/issupported.c b/lib/issupported.c index e1176de..6859094 100644 --- a/lib/issupported.c +++ b/lib/issupported.c @@ -28,6 +28,7 @@ vc_isSupported(vcFeatureSet feature) { int ver = vc_get_version(); vc_vci_t conf = vc_get_vci(); + int linux_ver = vc_get_kernel(); if (ver==-1) return false; if (conf==(vc_vci_t)-1) conf = 0; @@ -53,6 +54,7 @@ vc_isSupported(vcFeatureSet feature) case vcFEATURE_PIDSPACE : return false; case vcFEATURE_MEMCG : return ver >= 0x00020306 && conf & VC_VCI_MEMCG; case vcFEATURE_DYNAMIC : return ver < 0x00020300 || !(conf & VC_VCI_NO_DYNAMIC); + case vcFEATURE_BME : return linux_ver < 0x0002061a; default : assert(false); } diff --git a/lib/issupportedstring.c b/lib/issupportedstring.c index 746f5f3..03fb46c 100644 --- a/lib/issupportedstring.c +++ b/lib/issupportedstring.c @@ -36,7 +36,7 @@ static struct { DECL(VHI), DECL(VSHELPER0), DECL(VSHELPER), DECL(VWAIT), DECL(VNET), DECL(VSTAT), DECL(PPTAG), DECL(PIDSPACE), DECL(SPACES), DECL(PERSISTENT),DECL(PIVOT_ROOT),DECL(MEMCG), - DECL(DYNAMIC), + DECL(DYNAMIC), DECL(BME), }; bool diff --git a/lib/vserver.h b/lib/vserver.h index f8da611..1d553f4 100644 --- a/lib/vserver.h +++ b/lib/vserver.h @@ -392,6 +392,8 @@ extern "C" { */ vc_vci_t vc_get_vci(); + int vc_get_kernel(); + /** \brief Moves current process into a context * \ingroup syscalls * @@ -991,6 +993,7 @@ extern "C" { vcFEATURE_VNET, vcFEATURE_VSTAT, vcFEATURE_PPTAG, vcFEATURE_PIDSPACE, vcFEATURE_SPACES, vcFEATURE_PERSISTENT, vcFEATURE_PIVOT_ROOT, vcFEATURE_MEMCG, vcFEATURE_DYNAMIC, + vcFEATURE_BME, } vcFeatureSet; diff --git a/src/secure-mount.c b/src/secure-mount.c index baf2c4a..ae0650f 100644 --- a/src/secure-mount.c +++ b/src/secure-mount.c @@ -470,7 +470,8 @@ mountSingle(struct MountInfo const *mnt, struct Options *opt) opt->cur_dir_fd = Eopen(".", O_RDONLY|O_DIRECTORY, 0); Efcntl(opt->cur_dir_fd, F_SETFD, FD_CLOEXEC); } - if ((mnt->flag & MS_BIND) && + if (!vc_isSupported(vcFEATURE_BME) && + (mnt->flag & MS_BIND) && (mnt->mask & ~(MS_BIND|MS_REC))) { /* This is needed to put us in the new mountpoint */ if (!secureChdir(mnt->dst, opt)) -- 1.8.1.5