more fixes
authorMarc Fiuczynski <mef@cs.princeton.edu>
Tue, 20 Sep 2005 21:58:27 +0000 (21:58 +0000)
committerMarc Fiuczynski <mef@cs.princeton.edu>
Tue, 20 Sep 2005 21:58:27 +0000 (21:58 +0000)
python/vserver.py
python/vserverimpl.c

index 8618088..b2fe876 100644 (file)
@@ -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
index 09e3782..4136525 100644 (file)
@@ -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,