Setting tag util-vserver-pl-0.4-29
[util-vserver-pl.git] / python / vserverimpl.c
index b9a06aa..8c2818c 100644 (file)
@@ -49,7 +49,6 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #include "config.h"
 #include "vserver.h"
-#include "planetlab.h"
 
 static inline PyObject *inc_and_ret_none(void)
 {
@@ -62,60 +61,6 @@ 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) {
@@ -152,7 +97,7 @@ vserver_set_rlimit(PyObject *self, PyObject *args) {
   uint32_t bitmask;
   xid_t xid;
   int resource;
-  PyObject *ret;
+  PyObject *ret = NULL;
 
   limits.min = VC_LIM_KEEP;
   limits.soft = VC_LIM_KEEP;
@@ -177,26 +122,6 @@ vserver_set_rlimit(PyObject *self, PyObject *args) {
   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)
@@ -266,34 +191,6 @@ vserver_unset_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)
@@ -492,7 +389,7 @@ get_mask(struct vc_net_addr *addr)
     offset = offsetof(struct sockaddr_in6, sin6_addr.s6_addr);
     ip = addr->vna_v6_ip.s6_addr;
     len = 16;
-    addr->vna_v6_mask.s6_addr32[9] = addr->vna_v6_mask.s6_addr32[1] = 0xffffffff;
+    addr->vna_v6_mask.s6_addr32[0] = addr->vna_v6_mask.s6_addr32[1] = 0xffffffff;
     addr->vna_v6_mask.s6_addr32[2] = addr->vna_v6_mask.s6_addr32[3] = 0x00000000;
     addr->vna_prefix = 64;
     break;
@@ -504,7 +401,7 @@ get_mask(struct vc_net_addr *addr)
   if (getifaddrs(&head) == -1)
     return -1;
   for (ifa = head; ifa; ifa = ifa->ifa_next) {
-    if (ifa->ifa_addr->sa_family == family &&
+    if (ifa->ifa_addr && ifa->ifa_addr->sa_family == family &&
         memcmp((char *) ifa->ifa_addr + offset, ip, len) == 0) {
       switch (addr->vna_type) {
       case VC_NXA_TYPE_IPV4:
@@ -775,13 +672,8 @@ vserver_get_name(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,
@@ -792,10 +684,6 @@ static PyMethodDef  methods[] = {
     "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,
@@ -845,6 +733,7 @@ initvserverimpl(void)
   /* 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);