# default values for new vserver scheduler
SCHED_TOKENS_MIN = 50
SCHED_TOKENS_MAX = 100
+SCHED_TOKENS = 100
+SCHED_INTERVAL = 1000
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()
# 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"
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
#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;
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;
}
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))
}
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,