From 91cec69dc44c4a25c6ed53b874da4de35b6812b8 Mon Sep 17 00:00:00 2001 From: Marc Fiuczynski Date: Tue, 20 Sep 2005 21:58:27 +0000 Subject: [PATCH 1/1] more fixes --- python/vserver.py | 25 +++++++++++-------- python/vserverimpl.c | 57 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 60 insertions(+), 22 deletions(-) diff --git a/python/vserver.py b/python/vserver.py index 8618088..b2fe876 100644 --- a/python/vserver.py +++ b/python/vserver.py @@ -46,6 +46,8 @@ FLAGS_NAMESPACE = 128 # default values for new vserver scheduler SCHED_TOKENS_MIN = 50 SCHED_TOKENS_MAX = 100 +SCHED_TOKENS = 100 +SCHED_INTERVAL = 1000 class VServer: @@ -110,7 +112,7 @@ class VServer: return blocktotal - def set_sched(self, shares, besteffort = True): + def set_sched(self, shares = 32, besteffort = True): # for the old CKRM scheduler if cpulimit.checkckrm() is True: cpulimit.cpuinit() @@ -124,21 +126,20 @@ class VServer: # for the new vserver scheduler else: - global SCHED_TOKENS_MIN, SCHED_TOKENS_MAX + global SCHED_TOKENS_MIN, SCHED_TOKENS_MAX, SCHED_TOKENS, SCHED_INTERVAL tokensmin = SCHED_TOKENS_MIN tokensmax = SCHED_TOKENS_MAX + tokens = SCHED_TOKENS + interval = SCHED_INTERVAL + fillrate = shares if besteffort is True: - # magic "interval" value for Andy's scheduler to denote besteffort - interval = 1000 - fillrate = shares + cpuguaranteed = 0 else: - interval = 1001 - fillrate = shares + cpuguaranteed = 1 try: - cpuguaranteed = 0 # need to set this from the conf file - vserverimpl.setsched(self.ctx,fillrate,interval,tokensmin,tokensmax,cpuguaranteed) + vserverimpl.setsched(self.ctx,fillrate,interval,tokens,tokensmin,tokensmax,cpuguaranteed) except OSError, ex: if ex.errno == 22: print "kernel does not support vserver scheduler" @@ -238,7 +239,11 @@ class VServer: def __do_chcontext(self, state_file = None): - vserverimpl.chcontext(self.ctx) + vserverimpl.create(self.ctx) + vserverimpl.flags(self.ctx) + self.set_sched() + vserverimpl.enter(self.ctx) + if not state_file: return print >>state_file, "S_CONTEXT=%d" % self.ctx diff --git a/python/vserverimpl.c b/python/vserverimpl.c index 09e3782..4136525 100644 --- a/python/vserverimpl.c +++ b/python/vserverimpl.c @@ -53,14 +53,32 @@ POSSIBILITY OF SUCH DAMAGE. #include "virtual.h" /* - * chcontext + * context create */ static PyObject * -vserver_chcontext(PyObject *self, PyObject *args) +vserver_create(PyObject *self, PyObject *args) +{ + xid_t ctx, xid; + + if (!PyArg_ParseTuple(args, "I", &ctx)) + return NULL; + + xid = vc_ctx_create(ctx); + if (xid == VC_NOCTX && errno != EEXIST) { + return PyErr_SetFromErrno(PyExc_OSError); + } + return Py_None; +} + +/* + * set flags + */ +static PyObject * +vserver_flags(PyObject *self, PyObject *args) { struct vc_ctx_caps caps; struct vc_ctx_flags flags; - xid_t ctx, xid; + xid_t ctx; caps.ccaps = ~vc_get_insecureccaps(); caps.cmask = ~0ull; @@ -73,24 +91,34 @@ vserver_chcontext(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "I", &ctx)) return NULL; - xid = vc_ctx_create(ctx); - if (xid == VC_NOCTX && errno != EEXIST) { + if (vc_set_ccaps(ctx, &caps) == -1) { return PyErr_SetFromErrno(PyExc_OSError); } - if (vc_set_ccaps(ctx, &caps) == -1) { + if (vc_set_cflags(ctx, &flags) == -1) { return PyErr_SetFromErrno(PyExc_OSError); } + return Py_None; +} - if (vc_set_cflags(ctx, &flags) == -1) { +/* + * enter + */ +static PyObject * +vserver_enter(PyObject *self, PyObject *args) +{ + xid_t ctx, xid; + if (!PyArg_ParseTuple(args, "I", &ctx)) + return NULL; + + xid = vc_ctx_create(ctx); + if (xid == VC_NOCTX && errno != EEXIST) { return PyErr_SetFromErrno(PyExc_OSError); } - /* context already exists, migrate to it */ if (xid == VC_NOCTX && vc_ctx_migrate(ctx) == -1) { return PyErr_SetFromErrno(PyExc_OSError); } - return Py_None; } @@ -156,9 +184,10 @@ vserver_setsched(PyObject *self, PyObject *args) VC_VXSM_TOKENS_MIN | VC_VXSM_TOKENS_MAX); - if (!PyArg_ParseTuple(args, "I|I|I|I|I|I", &xid, + if (!PyArg_ParseTuple(args, "I|I|I|I|I|I|I", &xid, &sched.fill_rate, &sched.interval, + &sched.tokens, &sched.tokens_min, &sched.tokens_max, &cpuguaranteed)) @@ -265,8 +294,12 @@ vserver_set_dlimit(PyObject *self, PyObject *args) } static PyMethodDef methods[] = { - { "chcontext", vserver_chcontext, METH_VARARGS, - "Change to the given vserver context" }, + { "create", vserver_create, METH_VARARGS, + "Create a new vserver context" }, + { "flags", vserver_flags, METH_VARARGS, + "Set the default flags and caps" }, + { "enter", vserver_flags, METH_VARARGS, + "Enter the vserver context" }, { "setsched", vserver_setsched, METH_VARARGS, "Change vserver scheduling attributes for given vserver context" }, { "setdlimit", vserver_set_dlimit, METH_VARARGS, -- 2.43.0