From 6ae7ca4f937ef9b149c4d71438cb2a86953ca012 Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Fri, 27 Feb 2004 18:46:44 +0000 Subject: [PATCH] initial checkin git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1041 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/lib/syscall_setsched-v13.hc | 36 +++++++++ util-vserver/lib/syscall_setsched.c | 36 +++++++++ util-vserver/src/vschedule.c | 124 +++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+) create mode 100644 util-vserver/lib/syscall_setsched-v13.hc create mode 100644 util-vserver/lib/syscall_setsched.c create mode 100644 util-vserver/src/vschedule.c diff --git a/util-vserver/lib/syscall_setsched-v13.hc b/util-vserver/lib/syscall_setsched-v13.hc new file mode 100644 index 0000000..e54e25c --- /dev/null +++ b/util-vserver/lib/syscall_setsched-v13.hc @@ -0,0 +1,36 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// 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_sched_v13(xid_t xid, struct vc_set_sched const *data) +{ + struct vcmd_set_sched_v1 k_data; + + k_data.fill_rate = data->fill_rate; + k_data.period = data->period; + k_data.fill_level = data->fill_level; + k_data.bucket_size = data->bucket_size; + + return vserver(VCMD_set_sched, CTX_USER2KERNEL(xid), &k_data); +} diff --git a/util-vserver/lib/syscall_setsched.c b/util-vserver/lib/syscall_setsched.c new file mode 100644 index 0000000..7149f49 --- /dev/null +++ b/util-vserver/lib/syscall_setsched.c @@ -0,0 +1,36 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// 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 "linuxvirtual.h" + +#include "vserver-internal.h" + +#ifdef VC_ENABLE_API_V13 +# include "syscall_setsched-v13.hc" +#endif + +int +vc_set_sched(xid_t xid, struct vc_set_sched const *data) +{ + CALL_VC(CALL_VC_V13(vc_set_sched,xid,data)); +} diff --git a/util-vserver/src/vschedule.c b/util-vserver/src/vschedule.c new file mode 100644 index 0000000..b0b39cc --- /dev/null +++ b/util-vserver/src/vschedule.c @@ -0,0 +1,124 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// 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 "util.h" +#include "vserver.h" + +#include +#include +#include +#include + +#define ENSC_WRAPPERS_PREFIX "vschedule: " +#define ENSC_WRAPPERS_VSERVER 1 +#define ENSC_WRAPPERS_UNISTD 1 +#include + +#define CMD_HELP 0x1000 +#define CMD_VERSION 0x1001 +#define CMD_XID 0x4000 +#define CMD_FRATE 0x4001 +#define CMD_PERIOD 0x4002 +#define CMD_FLEVEL 0x4003 +#define CMD_BSIZE 0x4004 + +int wrapper_exit_code = 255; + +struct option const +CMDLINE_OPTIONS[] = { + { "help", no_argument, 0, CMD_HELP }, + { "version", no_argument, 0, CMD_VERSION }, + { "ctx", required_argument, 0, CMD_XID }, + { "fill-rate", required_argument, 0, CMD_FRATE }, + { "period", required_argument, 0, CMD_PERIOD }, + { "fill-level", required_argument, 0, CMD_FLEVEL }, + { "bucket-size", required_argument, 0, CMD_BSIZE }, + {0,0,0,0} +}; + +static void +showHelp(int fd, char const *cmd, int res) +{ + VSERVER_DECLARE_CMD(cmd); + + WRITE_MSG(fd, "Usage:\n "); + WRITE_STR(fd, cmd); + WRITE_MSG(fd, + " [--ctx ] [--fill-rate ] [--period ] [--fill-level ] [--bucket-size ] [--] [ *]\n" + "\n" + "Please report bugs to " PACKAGE_BUGREPORT "\n"); + + exit(res); +} + +static void +showVersion() +{ + WRITE_MSG(1, + "vschedule " VERSION " -- modifies scheduling parameters\n" + "This program is part of " PACKAGE_STRING "\n\n" + "Copyright (C) 2003,2004 Enrico Scholz\n" + VERSION_COPYRIGHT_DISCLAIMER); + exit(0); +} + +int main(int argc, char *argv[]) +{ + xid_t xid = VC_NOCTX; + struct vc_set_sched sched = { 0,0,0,0 }; + + while (1) { + int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0); + if (c==-1) break; + + switch (c) { + case CMD_HELP : showHelp(1, argv[0], 0); + case CMD_VERSION : showVersion(); + case CMD_XID : xid = atoi(optarg); break; + case CMD_FRATE : sched.fill_rate = atoi(optarg); break; + case CMD_PERIOD : sched.period = atoi(optarg); break; + case CMD_FLEVEL : sched.fill_level = atoi(optarg); break; + case CMD_BSIZE : sched.bucket_size = atoi(optarg); break; + default : + WRITE_MSG(2, "Try '"); + WRITE_STR(2, argv[0]); + WRITE_MSG(2, " --help\" for more information.\n"); + return EXIT_FAILURE; + break; + } + } + + if (xid==VC_NOCTX && optind==argc) { + WRITE_MSG(2, "Neither '--xid' nor a program was specified; try '--help' for more information\n"); + exit(255); + } + + if (xid==VC_NOCTX) + xid = Evc_get_task_xid(0); + + if (vc_set_sched(xid, &sched)==-1) { + perror("vc_set_sched()"); + exit(255); + } + + EexecvpD(argv[optind],argv+optind); +} -- 1.8.1.5