#include "config.h"
#include "vserver.h"
-#include "planetlab.h"
static inline PyObject *inc_and_ret_none(void)
{
#define PL_INSECURE_BCAPS (vc_get_insecurebcaps() | (1 << VC_CAP_NET_BIND_SERVICE))
#define PL_INSECURE_CCAPS vc_get_insecureccaps()
-/*
- * context create
- */
-static PyObject *
-vserver_chcontext(PyObject *self, PyObject *args)
-{
- int ctx_is_new;
- xid_t ctx;
- uint_least64_t bcaps = 0;
-
- if (!PyArg_ParseTuple(args, "I|K", &ctx, &bcaps))
- return NULL;
- bcaps |= ~PL_INSECURE_BCAPS;
-
- if ((ctx_is_new = pl_chcontext(ctx, bcaps, 0)) < 0)
- return PyErr_SetFromErrno(PyExc_OSError);
-
- return PyBool_FromLong(ctx_is_new);
-}
-
-static PyObject *
-vserver_setup_done(PyObject *self, PyObject *args)
-{
- xid_t ctx;
-
- if (!PyArg_ParseTuple(args, "I", &ctx))
- return NULL;
-
- if (pl_setup_done(ctx) < 0)
- return PyErr_SetFromErrno(PyExc_OSError);
-
- return NONE;
-}
-
-static PyObject *
-vserver_isrunning(PyObject *self, PyObject *args)
-{
- xid_t ctx;
- PyObject *ret;
- struct stat statbuf;
- char fname[64];
-
- if (!PyArg_ParseTuple(args, "I", &ctx))
- return NULL;
-
- sprintf(fname,"/proc/virtual/%d", ctx);
-
- if(stat(&fname[0],&statbuf)==0)
- ret = PyBool_FromLong(1);
- else
- ret = PyBool_FromLong(0);
-
- return ret;
-}
static PyObject *
__vserver_get_rlimit(xid_t xid, int resource) {
uint32_t bitmask;
xid_t xid;
int resource;
- PyObject *ret;
+ PyObject *ret = NULL;
limits.min = VC_LIM_KEEP;
limits.soft = VC_LIM_KEEP;
return ret;
}
-/*
- * setsched
- */
-static PyObject *
-vserver_setsched(PyObject *self, PyObject *args)
-{
- xid_t ctx;
- uint32_t cpu_min;
- uint32_t cpu_share;
-
- if (!PyArg_ParseTuple(args, "II|I", &ctx, &cpu_min, &cpu_share))
- return NULL;
-
- /* ESRCH indicates that there are no processes in the context */
- if (pl_setsched(ctx, cpu_min, cpu_share) &&
- errno != ESRCH)
- return PyErr_SetFromErrno(PyExc_OSError);
-
- return NONE;
-}
static PyObject *
vserver_get_dlimit(PyObject *self, PyObject *args)
return NONE;
}
-static PyObject *
-vserver_killall(PyObject *self, PyObject *args)
-{
- xid_t ctx;
- int sig;
- struct vc_ctx_flags cflags = {
- .flagword = 0,
- .mask = VC_VXF_PERSISTENT
- };
- struct vc_net_flags nflags = {
- .flagword = 0,
- .mask = VC_NXF_PERSISTENT
- };
-
- if (!PyArg_ParseTuple(args, "Ii", &ctx, &sig))
- return NULL;
-
- if (vc_ctx_kill(ctx, 0, sig) && errno != ESRCH)
- return PyErr_SetFromErrno(PyExc_OSError);
-
- if (vc_set_cflags(ctx, &cflags) && errno != ESRCH)
- return PyErr_SetFromErrno(PyExc_OSError);
-
- if (vc_set_nflags(ctx, &nflags) && errno != ESRCH)
- return PyErr_SetFromErrno(PyExc_OSError);
-
- return NONE;
-}
static PyObject *
vserver_set_bcaps(PyObject *self, PyObject *args)
return ret;
}
+
static PyMethodDef methods[] = {
- { "chcontext", vserver_chcontext, METH_VARARGS,
- "chcontext to vserver with provided flags" },
- { "setup_done", vserver_setup_done, METH_VARARGS,
- "Release vserver setup lock" },
- { "setsched", vserver_setsched, METH_VARARGS,
- "Change vserver scheduling attributes for given vserver context" },
{ "setdlimit", vserver_set_dlimit, METH_VARARGS,
"Set disk limits for given vserver context" },
{ "unsetdlimit", vserver_unset_dlimit, METH_VARARGS,
"Set resource limits for given resource of a vserver context" },
{ "getrlimit", vserver_get_rlimit, METH_VARARGS,
"Get resource limits for given resource of a vserver context" },
- { "killall", vserver_killall, METH_VARARGS,
- "Send signal to all processes in vserver context" },
- { "isrunning", vserver_isrunning, METH_VARARGS,
- "Check if vserver is running"},
{ "setbcaps", vserver_set_bcaps, METH_VARARGS,
"Set POSIX capabilities of a vserver context" },
{ "getbcaps", vserver_get_bcaps, METH_VARARGS,
/* export limit-related constants */
PyModule_AddIntConstant(mod, "DLIMIT_KEEP", (int)VC_CDLIM_KEEP);
PyModule_AddIntConstant(mod, "DLIMIT_INF", (int)VC_CDLIM_INFINITY);
+ PyModule_AddIntConstant(mod, "VC_LIM_INFINITY", (int)VC_LIM_INFINITY);
PyModule_AddIntConstant(mod, "VC_LIM_KEEP", (int)VC_LIM_KEEP);
PyModule_AddIntConstant(mod, "RLIMIT_CPU", (int)RLIMIT_CPU);