From 99d33f6844e093ed5119203557a606ce60f83de5 Mon Sep 17 00:00:00 2001 From: Daniel Hokka Zakrisson Date: Thu, 11 Oct 2007 20:37:56 +0000 Subject: [PATCH] Add support for vc_unset_mapping introduced in 2.3.0.27. git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2615 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- kernel/device_cmd.h | 1 + lib/Makefile-files | 2 ++ lib/syscall_unsetmapping-v21.hc | 33 +++++++++++++++++++++++++++++++++ lib/syscall_unsetmapping.c | 38 ++++++++++++++++++++++++++++++++++++++ lib/vserver.h | 1 + scripts/vserver.functions | 2 +- src/vdevmap.c | 25 +++++++++++++++++++++---- 7 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 lib/syscall_unsetmapping-v21.hc create mode 100644 lib/syscall_unsetmapping.c diff --git a/kernel/device_cmd.h b/kernel/device_cmd.h index 5ebf825..506e21b 100644 --- a/kernel/device_cmd.h +++ b/kernel/device_cmd.h @@ -5,6 +5,7 @@ /* device vserver commands */ #define VCMD_set_mapping VC_CMD(DEVICE, 1, 0) +#define VCMD_unset_mapping VC_CMD(DEVICE, 2, 0) struct vcmd_set_mapping_v0 { const char *device; diff --git a/lib/Makefile-files b/lib/Makefile-files index e33f1d5..de7dfe6 100644 --- a/lib/Makefile-files +++ b/lib/Makefile-files @@ -130,6 +130,8 @@ lib_v21_SRCS = lib/syscall_setccaps-v21.hc \ lib/syscall_ctxmigrate-v21.hc \ lib/syscall_setmapping.c \ lib/syscall_setmapping-v21.hc \ + lib/syscall_unsetmapping.c \ + lib/syscall_unsetmapping-v21.hc \ lib/syscall_schedinfo.c \ lib/syscall_schedinfo-v21.hc \ lib/syscall_getccaps-v21.hc \ diff --git a/lib/syscall_unsetmapping-v21.hc b/lib/syscall_unsetmapping-v21.hc new file mode 100644 index 0000000..322805b --- /dev/null +++ b/lib/syscall_unsetmapping-v21.hc @@ -0,0 +1,33 @@ +// $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 + +static inline ALWAYSINLINE int +vc_unset_mapping_v21(xid_t xid, const char *device, const char *target, uint32_t flags) +{ + struct vcmd_set_mapping_v0 data = { + .device = device, + .target = target, + .flags = flags + }; + return vserver(VCMD_unset_mapping, xid, &data); +} diff --git a/lib/syscall_unsetmapping.c b/lib/syscall_unsetmapping.c new file mode 100644 index 0000000..4608006 --- /dev/null +++ b/lib/syscall_unsetmapping.c @@ -0,0 +1,38 @@ +// $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" +#include "vserver-internal.h" +#include "virtual.h" + +#if defined(VC_ENABLE_API_V21) +# include "syscall_unsetmapping-v21.hc" +#endif + +#if defined(VC_ENABLE_API_V21) +int +vc_unset_mapping(xid_t xid, const char *device, const char *target, uint32_t flags) +{ + CALL_VC(CALL_VC_V21(vc_unset_mapping, xid, device, target, flags)); +} +#endif diff --git a/lib/vserver.h b/lib/vserver.h index d403677..bbc8049 100644 --- a/lib/vserver.h +++ b/lib/vserver.h @@ -813,6 +813,7 @@ extern "C" { /* misc. syscalls */ int vc_set_mapping(xid_t xid, const char *device, const char *target, uint32_t flags); + int vc_unset_mapping(xid_t xid, const char *device, const char *target, uint32_t flags); /** \brief Information about parsing errors diff --git a/scripts/vserver.functions b/scripts/vserver.functions index e2372f7..0918cc0 100644 --- a/scripts/vserver.functions +++ b/scripts/vserver.functions @@ -1275,6 +1275,6 @@ function loadDeviceMap vdevmap_opts=( "${vdevmap_opts[@]}" ${flags:+--flags "$flags"} \ ${device:+--device "$device"} ${target:+--target "$target"} ) - $_VDEVMAP --xid "$xid" "${vdevmap_opts[@]}" || return $? + $_VDEVMAP --xid "$xid" --set "${vdevmap_opts[@]}" || return $? done } diff --git a/src/vdevmap.c b/src/vdevmap.c index 1a9c9a4..fc08edd 100644 --- a/src/vdevmap.c +++ b/src/vdevmap.c @@ -43,6 +43,8 @@ CMDLINE_OPTIONS[] = { { "help", no_argument, 0, CMD_HELP }, { "version", no_argument, 0, CMD_VERSION }, { "xid", required_argument, 0, 'x' }, + { "set", no_argument, 0, 's' }, + { "unset", no_argument, 0, 'u' }, { "open", no_argument, 0, 'o' }, { "create", no_argument, 0, 'c' }, { "remap", no_argument, 0, 'r' }, @@ -58,7 +60,15 @@ showHelp(int fd, char const *cmd) WRITE_MSG(fd, "Usage: "); WRITE_STR(fd, cmd); WRITE_MSG(fd, - " --xid [--flags ] [--open] [--create] [--remap] [--device ] [--target ]\n" + " --xid {--set|--unset} [--flags ] [--open] [--create]\n" + " [--device ] [--remap --target ]\n" + "\n" + " --flags Set the specified flags\n" + " --open Allow opening of the device\n" + " --create If SECURE_MKNOD is given, allow mknod(2)\n" + " --device Device to apply the command to\n" + " --remap Remap the device to the target\n" + " --target Target for --remap\n" "\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); @@ -85,10 +95,11 @@ int main(int argc, char *argv[]) uint32_t flags = 0; char *device = NULL; char *target = NULL; + bool set = true; unsigned long tmp = 0; while (1) { - int c = getopt_long(argc, argv, "+x:ocrf:d:t:", CMDLINE_OPTIONS, 0); + int c = getopt_long(argc, argv, "+x:suocrf:d:t:", CMDLINE_OPTIONS, 0); if (c==-1) break; switch (c) { @@ -100,6 +111,8 @@ int main(int argc, char *argv[]) case 'r' : do_remap = true; break; case 'd' : device = optarg; break; case 't' : target = optarg; break; + case 's' : set = 1; break; + case 'u' : set = 0; break; case 'f' : if (!isNumberUnsigned(optarg, &tmp, false)) { WRITE_MSG(2, "Invalid flags argument: '"); @@ -123,12 +136,16 @@ int main(int argc, char *argv[]) if (allow_create) flags |= VC_DATTR_CREATE; if (do_remap) flags |= VC_DATTR_REMAP; - if (xid==VC_NOCTX) + if (target && !do_remap) + WRITE_MSG(2, "Target specified without --remap; try '--help' for more information\n"); + else if (xid==VC_NOCTX) WRITE_MSG(2, "No xid specified; try '--help' for more information\n"); else if (optind!=argc) WRITE_MSG(2, "Unused argument(s); try '--help' for more information\n"); - else if (vc_set_mapping(xid, device, target, flags)==-1) + else if (set && vc_set_mapping(xid, device, target, flags)==-1) perror("vc_set_mapping()"); + else if (!set && vc_unset_mapping(xid, device, target, flags)==-1) + perror("vc_unset_mapping()"); else return EXIT_SUCCESS; -- 1.8.1.5