Skip to content

Commit c59d323

Browse files
committed
override: domain: Implement override for virDomainFDAssociate
The bindings generator can't generate proper bindings for FD passing so the bindings need to be implemented manually both the python wrapper and the C backend. Signed-off-by: Peter Krempa <[email protected]>
1 parent d75be36 commit c59d323

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

generator.py

+1
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ def enum(type: str, name: str, value: EnumValue) -> None:
484484
'virConnectListAllSecrets', # overridden in virConnect.py
485485
'virConnectGetAllDomainStats', # overridden in virConnect.py
486486
'virDomainListGetStats', # overridden in virConnect.py
487+
'virDomainFDAssociate', # overridden in virDomain.py
487488

488489
'virStreamRecvAll', # Pure python libvirt-override-virStream.py
489490
'virStreamSendAll', # Pure python libvirt-override-virStream.py

libvirt-override-virDomain.py

+28
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,31 @@ def setTime(self, time: int = None, flags: int = 0) -> int:
8080
if ret == -1:
8181
raise libvirtError('virDomainSetTime() failed')
8282
return ret
83+
84+
def FDAssociate(self, name: str, files: List[int], flags: int = 0) -> int:
85+
"""Associate the array of FDs passed as @fds with the domain object
86+
under @name. The FDs are associated as long as the connection used to
87+
associated exists and are disposed of afterwards. FD may still be kept
88+
open by the hypervisor for as long as it's needed.
89+
90+
Security labelling (e.g. via the selinux) may be applied on the passed
91+
FDs when requiredg for usage by the VM. By default libvirt does not
92+
restore the seclabels on the FDs afterwards to avoid keeping it open
93+
unnecessarily.
94+
95+
Restoring of the security label can be requested by passing either
96+
VIR_DOMAIN_FD_ASSOCIATE_SECLABEL_RESTORE for a best-effort attempt to
97+
restore the security label after use. Requesting the restore of
98+
security label will require that the file descriptors are kept open for
99+
the whole time they are used by the hypervisor, or other additional
100+
overhead.
101+
102+
In certain cases usage of the fd group would imply read-only access.
103+
Passing VIR_DOMAIN_FD_ASSOCIATE_SECLABEL_WRITABLE in @flags ensures
104+
that a writable security label is picked in case when the file
105+
represented by the fds may be used in write mode. """
106+
ret = libvirtmod.virDomainFDAssociate(self._o, name, files, flags)
107+
if ret == -1:
108+
raise libvirtError('virDomainFDAssociate() failed')
109+
return ret
110+

libvirt-override.c

+56
Original file line numberDiff line numberDiff line change
@@ -10789,6 +10789,59 @@ libvirt_virDomainRestoreParams(PyObject *self ATTRIBUTE_UNUSED,
1078910789
}
1079010790
#endif /* LIBVIR_CHECK_VERSION(8, 4, 0) */
1079110791

10792+
10793+
#if LIBVIR_CHECK_VERSION(9, 0, 0)
10794+
static PyObject *
10795+
libvirt_virDomainFDAssociate(PyObject *self ATTRIBUTE_UNUSED,
10796+
PyObject *args)
10797+
{
10798+
PyObject *py_retval = NULL;
10799+
int c_retval;
10800+
virDomainPtr domain;
10801+
PyObject *pyobj_domain;
10802+
PyObject *pyobj_files;
10803+
const char *name = NULL;
10804+
unsigned int flags;
10805+
unsigned int nfiles;
10806+
int *files = NULL;
10807+
ssize_t i;
10808+
10809+
if (!PyArg_ParseTuple(args, (char *)"OsOI:virDomainFDAssociate",
10810+
&pyobj_domain, &name, &pyobj_files, &flags))
10811+
return NULL;
10812+
domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
10813+
10814+
nfiles = PyList_Size(pyobj_files);
10815+
10816+
if (VIR_ALLOC_N(files, nfiles) < 0)
10817+
return PyErr_NoMemory();
10818+
10819+
for (i = 0; i < nfiles; i++) {
10820+
PyObject *pyfd;
10821+
int fd;
10822+
10823+
pyfd = PyList_GetItem(pyobj_files, i);
10824+
10825+
if (libvirt_intUnwrap(pyfd, &fd) < 0)
10826+
goto cleanup;
10827+
10828+
files[i] = fd;
10829+
}
10830+
10831+
LIBVIRT_BEGIN_ALLOW_THREADS;
10832+
c_retval = virDomainFDAssociate(domain, name, nfiles, files, flags);
10833+
LIBVIRT_END_ALLOW_THREADS;
10834+
10835+
py_retval = libvirt_intWrap((int) c_retval);
10836+
10837+
cleanup:
10838+
VIR_FREE(files);
10839+
return py_retval;
10840+
}
10841+
#endif /* LIBVIR_CHECK_VERSION(9, 0, 0) */
10842+
10843+
10844+
1079210845
/************************************************************************
1079310846
* *
1079410847
* The registration stuff *
@@ -11070,6 +11123,9 @@ static PyMethodDef libvirtMethods[] = {
1107011123
{(char *) "virDomainSaveParams", libvirt_virDomainSaveParams, METH_VARARGS, NULL},
1107111124
{(char *) "virDomainRestoreParams", libvirt_virDomainRestoreParams, METH_VARARGS, NULL},
1107211125
#endif /* LIBVIR_CHECK_VERSION(8, 4, 0) */
11126+
#if LIBVIR_CHECK_VERSION(9, 0, 0)
11127+
{(char *) "virDomainFDAssociate", libvirt_virDomainFDAssociate, METH_VARARGS, NULL},
11128+
#endif /* LIBVIR_CHECK_VERSION(9, 0, 0) */
1107311129
{NULL, NULL, 0, NULL}
1107411130
};
1107511131

0 commit comments

Comments
 (0)