diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2013-07-09 17:12:38 +0100 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2013-07-18 11:01:14 +0100 |
commit | 03e7cacfa2891b62737886692bd68b648cc74706 (patch) | |
tree | 46552d59909b7782e0c387a6c8fcf495867ae7eb /libvirt-override.c | |
parent | f8bc3a9ccc3f40d800d856a9c6d44bc225d621bd (diff) | |
download | libvirt-python-split-03e7cacfa2891b62737886692bd68b648cc74706.tar.gz libvirt-python-split-03e7cacfa2891b62737886692bd68b648cc74706.tar.xz libvirt-python-split-03e7cacfa2891b62737886692bd68b648cc74706.zip |
Introduce new domain create APIs to pass pre-opened FDs to LXC
With container based virt, it is useful to be able to pass
pre-opened file descriptors to the container init process.
This allows for containers to be auto-activated from incoming
socket connections, passing the active socket into the container.
To do this, introduce a pair of new APIs, virDomainCreateXMLWithFiles
and virDomainCreateWithFiles, which accept an array of file
descriptors. For the LXC driver, UNIX file descriptor passing
will be used to send them to libvirtd, which will them pass
them down to libvirt_lxc, which will then pass them to the container
init process.
This will only be implemented for LXC right now, but the design
is generic enough it could work with other hypervisors, hence
I suggest adding this to libvirt.so, rather than libvirt-lxc.so
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'libvirt-override.c')
-rw-r--r-- | libvirt-override.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/libvirt-override.c b/libvirt-override.c index 01c941e..0a10887 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -7025,6 +7025,93 @@ error: } +static PyObject * +libvirt_virDomainCreateWithFiles(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval = NULL; + int c_retval; + virDomainPtr domain; + PyObject *pyobj_domain; + PyObject *pyobj_files; + unsigned int flags; + unsigned int nfiles; + int *files = NULL; + size_t i; + + if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainCreateWithFiles", + &pyobj_domain, &pyobj_files, &flags)) + return NULL; + domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain); + + nfiles = PyList_Size(pyobj_files); + + if (VIR_ALLOC_N_QUIET(files, nfiles) < 0) + return PyErr_NoMemory(); + + for (i = 0; i < nfiles; i++) { + PyObject *pyfd; + int fd; + + pyfd = PyList_GetItem(pyobj_files, i); + + if (libvirt_intUnwrap(pyfd, &fd) < 0) + goto cleanup; + } + + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virDomainCreateWithFiles(domain, nfiles, files, flags); + LIBVIRT_END_ALLOW_THREADS; + py_retval = libvirt_intWrap((int) c_retval); + +cleanup: + VIR_FREE(files); + return py_retval; +} + + +static PyObject * +libvirt_virDomainCreateXMLWithFiles(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) { + PyObject *py_retval = NULL; + virDomainPtr c_retval; + virConnectPtr conn; + PyObject *pyobj_conn; + char * xmlDesc; + PyObject *pyobj_files; + unsigned int flags; + unsigned int nfiles; + int *files = NULL; + size_t i; + + if (!PyArg_ParseTuple(args, (char *)"OzOi:virDomainCreateXMLWithFiles", + &pyobj_conn, &xmlDesc, &pyobj_files, &flags)) + return NULL; + conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn); + + nfiles = PyList_Size(pyobj_files); + + if (VIR_ALLOC_N_QUIET(files, nfiles) < 0) + return PyErr_NoMemory(); + + for (i = 0; i < nfiles; i++) { + PyObject *pyfd; + int fd; + + pyfd = PyList_GetItem(pyobj_files, i); + + if (libvirt_intUnwrap(pyfd, &fd) < 0) + goto cleanup; + } + + LIBVIRT_BEGIN_ALLOW_THREADS; + c_retval = virDomainCreateXMLWithFiles(conn, xmlDesc, nfiles, files, flags); + LIBVIRT_END_ALLOW_THREADS; + py_retval = libvirt_virDomainPtrWrap((virDomainPtr) c_retval); + +cleanup: + VIR_FREE(files); + return py_retval; +} + + /************************************************************************ * * * The registration stuff * @@ -7150,6 +7237,8 @@ static PyMethodDef libvirtMethods[] = { {(char *) "virNodeGetMemoryParameters", libvirt_virNodeGetMemoryParameters, METH_VARARGS, NULL}, {(char *) "virNodeSetMemoryParameters", libvirt_virNodeSetMemoryParameters, METH_VARARGS, NULL}, {(char *) "virNodeGetCPUMap", libvirt_virNodeGetCPUMap, METH_VARARGS, NULL}, + {(char *) "virDomainCreateXMLWithFiles", libvirt_virDomainCreateXMLWithFiles, METH_VARARGS, NULL}, + {(char *) "virDomainCreateWithFiles", libvirt_virDomainCreateWithFiles, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; |