From: Steve Muir Date: Mon, 5 Dec 2005 20:46:13 +0000 (+0000) Subject: Port rc7 changes to release branch X-Git-Tag: planetlab-3_2-rc7~1 X-Git-Url: http://git.onelab.eu/?p=util-vserver.git;a=commitdiff_plain;h=3928ff35846885e08afbe19403ffb6256dcaeef0 Port rc7 changes to release branch --- diff --git a/.cvsignore b/.cvsignore index 5797688..93b0d06 100644 --- a/.cvsignore +++ b/.cvsignore @@ -1,4 +1,4 @@ -.X_user_local_etc-up-to-date +.X_usr_local_etc-up-to-date .deps .fixups .pathconfig.h.pathsubst.stamp diff --git a/python/vserver.py b/python/vserver.py index 7132cd1..9578ad3 100644 --- a/python/vserver.py +++ b/python/vserver.py @@ -4,6 +4,7 @@ import errno import fcntl import os import re +import signal import sys import time import traceback @@ -249,13 +250,12 @@ class VServer: def __do_chcontext(self, state_file): - vserverimpl.chcontext(self.ctx, self.resources) + if state_file: + print >>state_file, "S_CONTEXT=%u" % self.ctx + print >>state_file, "S_PROFILE=" + state_file.close() - if not state_file: - return - print >>state_file, "S_CONTEXT=%d" % self.ctx - print >>state_file, "S_PROFILE=%s" % self.config.get("S_PROFILE", "") - state_file.close() + vserverimpl.chcontext(self.ctx, self.resources) def __prep(self, runlevel, log): @@ -324,7 +324,6 @@ class VServer: self.__do_chroot() log = open("/var/log/boot.log", "w", 0) os.dup2(1, 2) - # XXX - close all other fds print >>log, ("%s: starting the virtual server %s" % (time.asctime(time.gmtime()), self.name)) @@ -388,3 +387,8 @@ class VServer: (self.disk_inodes, self.disk_blocks, size) = vduimpl.vdu(self.dir) return size + + def stop(self, signal = signal.SIGKILL): + + vserverimpl.killall(self.ctx, signal) + self.vm_running = False diff --git a/python/vserverimpl.c b/python/vserverimpl.c index 9048e24..00c8980 100644 --- a/python/vserverimpl.c +++ b/python/vserverimpl.c @@ -44,6 +44,29 @@ POSSIBILITY OF SUCH DAMAGE. #include "vserver.h" #include "vserver-internal.h" +static int +get_rspec(PyObject *resources, rspec_t *rspec) +{ + PyObject *cpu_share; + + if (!PyMapping_Check(resources)) + { + PyErr_SetString(PyExc_TypeError, "invalid rspec"); + return -1; + } + if ((cpu_share = PyMapping_GetItemString(resources, "nm_cpu_share"))) + { + if (PyInt_Check(cpu_share)) + { + rspec->cpu_share = PyInt_AS_LONG(cpu_share); + return 0; + } + PyErr_SetString(PyExc_TypeError, "nm_cpu_share not an integer"); + } + + return -1; +} + /* * context create */ @@ -55,21 +78,13 @@ vserver_chcontext(PyObject *self, PyObject *args) uint32_t bcaps = ~vc_get_insecurebcaps(); rspec_t rspec = { 32, VC_VXF_SCHED_FLAGS, -1, -1 }; PyObject *resources; - PyObject *cpu_share; - if (!PyArg_ParseTuple(args, "IO|K", &ctx, &resources, &flags)) + if (!PyArg_ParseTuple(args, "IO|K", &ctx, &resources, &flags) || + get_rspec(resources, &rspec)) return NULL; - if (!PyMapping_Check(resources)) - { - PyErr_SetString(PyExc_TypeError, "invalid resources object"); - return NULL; - } - if ((cpu_share = PyMapping_GetItemString(resources, "nm_cpu_share")) && - (cpu_share = PyNumber_Int(cpu_share))) - rspec.cpu_share = PyInt_AsLong(cpu_share); if (pl_chcontext(ctx, flags, bcaps, &rspec)) - PyErr_SetFromErrno(PyExc_OSError); + return PyErr_SetFromErrno(PyExc_OSError); return Py_None; } @@ -131,21 +146,13 @@ vserver_setsched(PyObject *self, PyObject *args) xid_t ctx; rspec_t rspec = { 32, VC_VXF_SCHED_FLAGS, -1, -1 }; PyObject *resources; - PyObject *cpu_share; - if (!PyArg_ParseTuple(args, "IO", &ctx, &resources)) + if (!PyArg_ParseTuple(args, "IO", &ctx, &resources) || + get_rspec(resources, &rspec)) return NULL; - if (!PyMapping_Check(resources)) - { - PyErr_SetString(PyExc_TypeError, "invalid resources object"); - return NULL; - } - if ((cpu_share = PyMapping_GetItemString(resources, "nm_cpu_share")) && - (cpu_share = PyNumber_Int(cpu_share))) - rspec.cpu_share = PyInt_AsLong(cpu_share); if (pl_setsched(ctx, rspec.cpu_share, rspec.cpu_sched_flags)) - PyErr_SetFromErrno(PyExc_OSError); + return PyErr_SetFromErrno(PyExc_OSError); return Py_None; } @@ -233,6 +240,21 @@ vserver_unset_dlimit(PyObject *self, PyObject *args) return Py_None; } +static PyObject * +vserver_killall(PyObject *self, PyObject *args) +{ + xid_t ctx; + int sig; + + if (!PyArg_ParseTuple(args, "Ii", &ctx, &sig)) + return NULL; + + if (vc_ctx_kill(ctx, 0, sig) && errno != ESRCH) + return PyErr_SetFromErrno(PyExc_OSError); + + return Py_None; +} + static PyMethodDef methods[] = { { "chcontext", vserver_chcontext, METH_VARARGS, "chcontext to vserver with provided flags" }, @@ -248,6 +270,8 @@ 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" }, { NULL, NULL, 0, NULL } }; diff --git a/src/vsh.c b/src/vsh.c index 435ea05..5908b20 100644 --- a/src/vsh.c +++ b/src/vsh.c @@ -294,6 +294,14 @@ static int sandbox_processes(xid_t ctx, char *context) {0,0}}; get_limits(context,list); + + /* check whether the slice has been disabled */ + if (!cpu) + { + fprintf(stderr, "*** this slice has been suspended ***\n"); + exit(0); + } + (void) (sandbox_chroot(ctx)); rspec.cpu_share = cpu; diff --git a/util-vserver.spec b/util-vserver.spec index 5f7e6f5..2917a1e 100644 --- a/util-vserver.spec +++ b/util-vserver.spec @@ -17,11 +17,14 @@ %define name util-vserver %define version 0.30.208 -%define release 6.planetlab%{?date:.%{date}} +%define release 7.planetlab%{?date:.%{date}} %define _without_dietlibc 1 %define _without_xalan 1 +# don't build debuginfo RPM +%define debug_package %{nil} + Vendor: PlanetLab Packager: PlanetLab Central Distribution: PlanetLab 3.0 @@ -381,6 +384,11 @@ done %changelog +* Fri Dec 2 2005 Steve Muir +- fix bugs in python/vserverimpl.c where exceptions were not raised when + they should be and thus occured later at unexpected times +- add support for stopping a vserver + * Wed Nov 9 2005 Steve Muir - add support for removing resource limits e.g., when a slice is deleted diff --git a/util-vserver.spec.in b/util-vserver.spec.in index 2f47ef8..d69e465 100644 --- a/util-vserver.spec.in +++ b/util-vserver.spec.in @@ -17,11 +17,14 @@ %define name @PACKAGE@ %define version @VERSION@ -%define release 1.planetlab%{?date:.%{date}} +%define release 7.planetlab%{?date:.%{date}} %define _without_dietlibc 1 %define _without_xalan 1 +# don't build debuginfo RPM +%define debug_package %{nil} + Vendor: PlanetLab Packager: PlanetLab Central Distribution: PlanetLab 3.0 @@ -381,6 +384,29 @@ done %changelog +* Fri Dec 2 2005 Steve Muir +- fix bugs in python/vserverimpl.c where exceptions were not raised when + they should be and thus occured later at unexpected times +- add support for stopping a vserver + +* Wed Nov 9 2005 Steve Muir +- add support for removing resource limits e.g., when a slice is deleted + +* Mon Nov 7 2005 Steve Muir +- fix file descriptor leak in vduimpl +- clean up handling of network parameters +- don't rely upon /etc/vservers/foo.conf to initialise vserver object + +* Wed Nov 2 2005 Steve Muir +- fix Python modules to handling scheduling parameters correctly + +* Fri Oct 28 2005 Steve Muir +- raise exception about being over disk limit after setting usage values + +* Fri Oct 7 2005 Steve Muir +- create common function to be used for entering a vserver and applying + resource limits + * Thu Aug 21 2005 Mark Huang - restore build of python modules