1 /* Copyright 2005 Princeton University
3 Redistribution and use in source and binary forms, with or without
4 modification, are permitted provided that the following conditions
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above
11 copyright notice, this list of conditions and the following
12 disclaimer in the documentation and/or other materials provided
13 with the distribution.
15 * Neither the name of the copyright holder nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PRINCETON
23 UNIVERSITY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
29 WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
43 #include <sys/ioctl.h>
44 #include <sys/types.h>
51 #include "vserver-internal.h"
52 #include "sched_cmd.h"
59 vserver_chcontext(PyObject *self, PyObject *args)
62 unsigned caps_remove = 0;
64 if (!PyArg_ParseTuple(args, "I|I", &xid, &caps_remove))
67 if (vc_new_s_context(xid, caps_remove, 0) < 0)
68 return PyErr_SetFromErrno(PyExc_OSError);
74 vserver_set_rlimit(PyObject *self, PyObject *args) {
75 struct vc_rlimit limits;
79 limits.min = VC_LIM_KEEP;
80 limits.soft = VC_LIM_KEEP;
81 limits.hard = VC_LIM_KEEP;
83 if (!PyArg_ParseTuple(args, "iiL", &xid, &resource, &limits.hard))
87 if (vc_set_rlimit(xid, resource, &limits))
88 ret = PyErr_SetFromErrno(PyExc_OSError);
89 else if (vc_get_rlimit(xid, resource, &limits)==-1)
90 ret = PyErr_SetFromErrno(PyExc_OSError);
92 ret = Py_BuildValue("L",limits.hard);
98 vserver_get_rlimit(PyObject *self, PyObject *args) {
99 struct vc_rlimit limits;
103 limits.min = VC_LIM_KEEP;
104 limits.soft = VC_LIM_KEEP;
105 limits.hard = VC_LIM_KEEP;
107 if (!PyArg_ParseTuple(args, "ii", &xid, &resource))
111 if (vc_get_rlimit(xid, resource, &limits)==-1)
112 ret = PyErr_SetFromErrno(PyExc_OSError);
114 ret = Py_BuildValue("L",limits.hard);
123 vserver_setsched(PyObject *self, PyObject *args)
126 struct vc_set_sched sched;
128 sched.set_mask = (VC_VXSM_FILL_RATE |
133 if (!PyArg_ParseTuple(args, "I|I|I|I|I", &xid,
140 if (vc_set_sched(xid, &sched) == -1)
141 return PyErr_SetFromErrno(PyExc_OSError);
150 /* inode vserver commands */
151 #define VCMD_add_dlimit VC_CMD(DLIMIT, 1, 0)
152 #define VCMD_rem_dlimit VC_CMD(DLIMIT, 2, 0)
153 #define VCMD_set_dlimit VC_CMD(DLIMIT, 5, 0)
154 #define VCMD_get_dlimit VC_CMD(DLIMIT, 6, 0)
156 #define CDLIM_UNSET (0ULL)
157 #define CDLIM_INFINITY (~0ULL)
158 #define CDLIM_KEEP (~1ULL)
161 vserver_get_dlimit(PyObject *self, PyObject *args)
166 struct vcmd_ctx_dlimit_v0 data;
169 if (!PyArg_ParseTuple(args, "si", &path,&xid))
172 memset(&data, 0, sizeof(data));
175 r = vserver(VCMD_get_dlimit, xid, &data);
177 res = Py_BuildValue("(i,i,i,i,i)",
184 res = PyErr_SetFromErrno(PyExc_OSError);
192 vserver_set_dlimit(PyObject *self, PyObject *args)
196 struct vcmd_ctx_dlimit_base_v0 init;
197 struct vcmd_ctx_dlimit_v0 data;
200 memset(&data,0,sizeof(data));
201 if (!PyArg_ParseTuple(args, "siiiiii", &path,
213 memset(&init, 0, sizeof(init));
217 r = vserver(VCMD_rem_dlimit, xid, &init);
219 r = vserver(VCMD_add_dlimit, xid, &init);
221 r = vserver(VCMD_set_dlimit, xid, &data);
226 static PyMethodDef methods[] = {
227 { "chcontext", vserver_chcontext, METH_VARARGS,
228 "Change to the given vserver context" },
229 { "setsched", vserver_setsched, METH_VARARGS,
230 "Change vserver scheduling attributes for given vserver context" },
231 { "setdlimit", vserver_set_dlimit, METH_VARARGS,
232 "Set disk limits for given vserver context" },
233 { "getdlimit", vserver_get_dlimit, METH_VARARGS,
234 "Get disk limits for given vserver context" },
235 { "setrlimit", vserver_set_rlimit, METH_VARARGS,
236 "Set resource limits for given resource of a vserver context" },
237 { "getrlimit", vserver_get_rlimit, METH_VARARGS,
238 "Get resource limits for given resource of a vserver context" },
239 { NULL, NULL, 0, NULL }
243 initvserverimpl(void)
245 Py_InitModule("vserverimpl", methods);