X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fvsched.c;h=215f879edc434a3cccf6237d64c1f99623c2946b;hb=HEAD;hp=358d139b298bfb1dcf869272ae63f09a0dd09b2b;hpb=bd9b1a68c9b4855e2dab03fc2b84e174446cbef5;p=util-vserver.git diff --git a/src/vsched.c b/src/vsched.c index 358d139..215f879 100644 --- a/src/vsched.c +++ b/src/vsched.c @@ -1,6 +1,7 @@ // $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 @@ -30,6 +31,7 @@ #include #include #include +#include #define ENSC_WRAPPERS_PREFIX "vsched: " #define ENSC_WRAPPERS_VSERVER 1 @@ -96,13 +98,13 @@ struct sched_opt { }; #define FOPT(NAME,MASK,FIELD) { #NAME, MASK, offsetof(struct vc_set_sched, FIELD) } static struct sched_opt FILE_OPTIONS[] = { - FOPT(fill-rate, VC_VXSM_FILL_RATE, fill_rate), - FOPT(interval, VC_VXSM_INTERVAL, interval), - FOPT(tokens, VC_VXSM_TOKENS, tokens), - FOPT(tokens-min, VC_VXSM_TOKENS_MIN, tokens_min), - FOPT(tokens-max, VC_VXSM_TOKENS_MAX, tokens_max), - FOPT(prio-bias, VC_VXSM_PRIO_BIAS, priority_bias), - FOPT(priority-bias, VC_VXSM_PRIO_BIAS, priority_bias), + FOPT(fill-rate, VC_VXSM_FILL_RATE, fill_rate), + FOPT(interval, VC_VXSM_INTERVAL, interval), + FOPT(tokens, VC_VXSM_TOKENS, tokens), + FOPT(tokens-min, VC_VXSM_TOKENS_MIN, tokens_min), + FOPT(tokens-max, VC_VXSM_TOKENS_MAX, tokens_max), + FOPT(prio-bias, VC_VXSM_PRIO_BIAS, priority_bias), + FOPT(priority-bias, VC_VXSM_PRIO_BIAS, priority_bias), FOPT(fill-rate2, VC_VXSM_FILL_RATE2|VC_VXSM_IDLE_TIME, fill_rate2), FOPT(interval2, VC_VXSM_INTERVAL2|VC_VXSM_IDLE_TIME, interval2), FOPT(cpu-id, VC_VXSM_CPU_ID, cpu_id), @@ -119,9 +121,25 @@ showHelp(int fd, char const *cmd, int res) WRITE_MSG(fd, "Usage:\n "); WRITE_STR(fd, cmd); WRITE_MSG(fd, - " [--xid ] [--fill-rate ] [--interval ] [--tokens ] [--tokens-min ] [--tokens-max ] [--prio-bias ] [--] [ *]\n" + " [--xid ] * [--dir ] [--] [ *]\n" "\n" - "Please report bugs to " PACKAGE_BUGREPORT "\n"); + "Options:\n" + " --fill-rate \n" + " --interval \n" + " --tokens \n" + " --tokens-min \n" + " --tokens-max \n" + " --prio-bias \n" + " --fill-rate2 \n" + " --interval2 \n" + " --cpu-id \n" + " --bucket-id \n" + " --idle-time ... set the idle time flag; this is required for\n" + " all updates to the scheduler to keep it enabled\n" + " --force ... force update of all per-CPU schedulers now\n" + " --dir ... read settings from \n" + " --missingok ... do not fail when does not exist\n" + "\nPlease report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); } @@ -133,40 +151,44 @@ showVersion() "vsched " VERSION " -- modifies scheduling parameters\n" "This program is part of " PACKAGE_STRING "\n\n" "Copyright (C) 2003,2004 Enrico Scholz\n" + "Copyright (C) 2006 Daniel Hokka Zakrisson\n" VERSION_COPYRIGHT_DISCLAIMER); exit(0); } static void do_dir_entry(struct vc_set_sched *sched, const char *name) { - int fd; - char buf[128]; - signed long val; struct sched_opt *opt; - ssize_t len; - char *newline; for (opt = FILE_OPTIONS; opt->name != 0; opt++) { if (strcmp(name, opt->name) == 0) break; } + if (opt->name == 0) + return; + + if (opt->offset != offsetof(struct vc_set_sched, set_mask)) { + int fd; + char buf[128], *newline; + signed long val; + ssize_t len; + + fd = Eopen(name, O_RDONLY, 0); + len = Eread(fd, buf, sizeof(buf)-1); + Eclose(fd); + buf[len] = '\0'; + if ((newline=strchr(buf, '\n')) != NULL) + *newline = '\0'; + + if (!isNumber(buf, &val, true)) { + WRITE_MSG(2, ENSC_WRAPPERS_PREFIX); + WRITE_STR(2, name); + WRITE_MSG(2, ": is not an integer\n"); + exit(1); + } - fd = Eopen(name, O_RDONLY, 0); - len = Eread(fd, buf, sizeof(buf)-1); - Eclose(fd); - buf[len] = '\0'; - if ((newline=strchr(buf, '\n')) != NULL) - *newline = '\0'; - - if (!isNumber(buf, &val, true)) { - WRITE_MSG(2, ENSC_WRAPPERS_PREFIX); - WRITE_STR(2, name); - WRITE_MSG(2, ": is not a number\n"); - exit(1); - } - - if (opt->offset != offsetof(struct vc_set_sched, set_mask)) *(int_least32_t *)(((char *)sched)+opt->offset) = (int_least32_t) val; + } sched->set_mask |= opt->mask; } @@ -222,7 +244,7 @@ static void do_dir(xid_t xid, struct vc_set_sched *sched, const char *dir, int m #define SETVAL(ATTR,MASK) \ if (!isNumber(optarg, &tmp, false)) { \ - WRITE_MSG(2, ENSC_WRAPPERS_PREFIX "non-numeric value specified for '--" #ATTR "'\n"); \ + WRITE_MSG(2, ENSC_WRAPPERS_PREFIX "non-integer value specified for '--" #ATTR "'\n"); \ exit(wrapper_exit_code); \ } \ else { \ @@ -291,7 +313,8 @@ int main(int argc, char *argv[]) do_dir(xid, &sched, dir, missing_ok, 0); } else { - if (sched.set_mask!=0 && vc_set_sched(xid, &sched)==-1) { + if (sched.set_mask!=0 && sched.set_mask!=VC_VXSM_FORCE && + vc_set_sched(xid, &sched)==-1) { perror("vc_set_sched()"); exit(255); }