1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-12-01 08:23:47 +03:00
Commit Graph

314 Commits

Author SHA1 Message Date
w00506750
b47727460e iothread: fix memory access out of bounds
When the 'pcpu' is larger then the last 'iothr->cpumap' bits,
set the list element to False to avoid out of bounds access
'iothr->cpumap'.

Signed-off-by: suruifeng <suruifeng@huawei.com>
Reviewed-by: Hogan Wang <hogan.wang@huawei.com>
2021-05-27 13:23:16 +00:00
renlei4
fd069ac85c Fix wrong type for BlockThreshold Callback
type of threshold and excess are unsigned long long,
but PyObject_CallMethod incorrectly set it to int.

if threshold or excess greater than 0x7FFFFFFF(max int),
those variables will overflow.

Signed-off-by: Ren Lei <ren.lei4@zte.com.cn>
2021-03-01 16:51:40 +08:00
Daniel P. Berrangé
75c053e49e Add impl override for virDomainGetMessages
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-02-15 16:02:21 +00:00
Daniel P. Berrangé
9b942039ca Avoid signed/unsigned warnings in loop over SSH keys
libvirt-override.c: In function ‘libvirt_virDomainAuthorizedSSHKeysGet’:
libvirt-override.c:10455:19: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
10455 |     for (i = 0; i < nkeys; i++)
      |                   ^

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-12-03 11:57:25 +00:00
Michal Privoznik
767bf23ba6 Implement virDomainAuthorizedSSHKeys{Get,Set}
Both APIs work with string lists (the getter returns it, the
setter gets keys to set from it) -> represent that as a python
list. The rest is kept as is in C.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2020-11-19 18:12:33 +01:00
Daniel P. Berrangé
417b39049e Add support for memory failure event callbacks
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-11-12 14:51:56 +00:00
Daniel P. Berrangé
ae219e3480 Replace deprecated PyEval_CallObject with PyObject_Call
The former is deprecated since Python 3.9, and the latter has existed
for all 3.x and probably before.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-11-12 14:31:54 +00:00
Philipp Hahn
a14161f01c debug: Fix bit-rot in debug output
Let the compiler optimize out the printf() call instead of doing it with the
pre-processor as the later does not catch format string errors or the following
case, where NULLSTR() is used but not defined:

> libvirt-qemu-override.c: In function ‘libvirt_qemu_virConnectDomainQemuMonitorEventRegister’:
> libvirt-qemu-override.c:271:34: warning: implicit declaration of function ‘NULLSTR’; did you mean ‘NULL’? [-Wimplicit-function-declaration]
>   271 |           pyobj_conn, pyobj_dom, NULLSTR(event), pyobj_cbData, flags);
>       |                                  ^~~~~~~
> libvirt-qemu-override.c:39:28: note: in definition of macro ‘DEBUG’
>    39 |     while (0) {printf(fmt, __VA_ARGS__);}
>       |                            ^~~~~~~~~~~
> libvirt-qemu-override.c:270:11: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘int’ [-Wformat=]
>   270 |     DEBUG("libvirt_qemu_virConnectDomainQemuMonitorEventRegister(%p %p %s %p %x) called\n",
>       |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   271 |           pyobj_conn, pyobj_dom, NULLSTR(event), pyobj_cbData, flags);
>       |                                  ~~~~~~~~~~~~~~
>       |                                  |
>       |                                  int
> libvirt-qemu-override.c:39:23: note: in definition of macro ‘DEBUG’
>    39 |     while (0) {printf(fmt, __VA_ARGS__);}
>       |                       ^~~
> libvirt-qemu-override.c:270:73: note: format string is defined here
>   270 |     DEBUG("libvirt_qemu_virConnectDomainQemuMonitorEventRegister(%p %p %s %p %x) called\n",
>       |                                                                        ~^
>       |                                                                         |
>       |                                                                         char *
>       |                                                                        %d

Copy the definition of NULLSTR from libvirt/src/internal.h to typewrappers.h

Signed-off-by: Philipp Hahn <hahn@univention.de>
2020-07-27 13:24:36 +02:00
Cole Robinson
c1b9384759 Fix PY_SSIZE_T_CLEAN deprecation warning
Seen running on fedora 32:

DeprecationWarning: PY_SSIZE_T_CLEAN will be required for '#' formats
  ret = libvirtmod.virDomainLookupByUUID(self._o, uuid)

This comes from here: https://bugs.python.org/issue36381
See the section about PY_SSIZE_T_CLEAN here:
https://docs.python.org/3/c-api/arg.html#strings-and-buffers

Solution is to use Py_ssize_t instead of int for unpacked '#' values,
combined with defined PY_SSIZE_T_CLEAN before importing Python.h. The
latter turns these deprecation warnings into runtime segfaults though
if we missed an instance.

I verified the virt-manager's test suite works fine after this change

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2020-07-06 11:01:01 +00:00
Daniel P. Berrangé
56afc9b33f Add overrides for network port UUID getter/lookup methods
The generator creates broken code for all these methods.

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-01-03 11:32:57 +00:00
Daniel P. Berrangé
b22e4f2441 Drop support for python 2
python2 will be end of life by the time of the next
libvirt release. All our supported build targets, including
CentOS7, have a python3 build available.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-12-04 12:14:51 +00:00
Pavel Hrdina
ebd352515d virDomainMigrate3Params: add missing parallel connections param
Introduced in libvirt 5.2.0 by commit <d3ea986af24>.

Reported-by: Liping Cheng <lcheng@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-23 13:58:37 +02:00
Pavel Hrdina
1c20685831 virDomainMigrate3Params: add missing bandwidth postcopy param
Introduced in libvirt 5.1.0 by commit <c830187a015>.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-23 13:58:27 +02:00
Daniel P. Berrangé
873e0ca7db Custom impl for virConnectSetIdentity which can't be generated
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-20 13:51:20 +01:00
Pavel Hrdina
d76c27e385 virDomainMemoryStats: include hugetlb pgalloc and pgfail
Introduced in libvirt 5.4.0 by commit <a699b19f6c3>.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1683516

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-20 12:58:35 +02:00
Pavel Hrdina
b0a7747ddd virDomainMemoryStats: include disk caches
Introduced in libvirt 4.6.0 by commit <aee04655089>.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1683516

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-09-20 12:58:30 +02:00
Cole Robinson
5fe311f1f3 Fix -Wsign-compare warnings
libvirt-override.c: In function ‘libvirt_virConnectBaselineHypervisorCPU’:
libvirt-override.c:9946:23: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
libvirt-override.c:9961:19: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]

Use ssize_t as was similarly done in 75ec2acb61

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2019-09-05 14:04:17 -04:00
Michal Privoznik
17937cc337 Implement virDomainGetGuestInfo
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-08-29 12:04:56 +02:00
Eric Blake
358a8640fa Add virDomainCheckpoint APIs
Copies heavily from existing virDomainSnapshot handling, regarding
what special cases the generator has to be taught and what overrides
need to be written.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2019-07-29 13:39:39 -05:00
Daniel P. Berrangé
204d3c061b Add missing impl of virNetworkListAllPorts
This API needs manual impl as the generator cannot cope

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-06-20 14:21:06 +01:00
Daniel P. Berrangé
a57c86593e Fix syntax error with missing ; and too many )
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-06-20 12:48:07 +01:00
Daniel P. Berrangé
a4de6e2ed8 Add support for virNetworkPort object & APIs
Define the various rules in the generator to wire up methods into the
virNetwork class and create the new virNetworkPort class.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2019-06-20 12:11:59 +01:00
Nir Soffer
5d6228d417 Fix handling of optional params in blockCopy()
Commit 2b4bd07e0a (Add check for params, nparams being a dictionary)
changed the way the optional params argument is treated. If
libvirt.virDomain.blockCopy() is called without specifying params,
params is None, and the call will fail with:

    TypeError: block params must be a dictionary

This is wrong as params is defined as kwarg, breaking existing libvirt
users like oVirt. Add a check for Py_None, so we accept either a dict or
None and fail with TypeError with anything else.

Resolves: https://bugzilla.redhat.com/1687114

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
2019-03-12 08:48:45 +01:00
Pavel Hrdina
878446e7f9 Fix virDomainPinIOThread typed params check
The VIR_DOMAIN_IOTHREAD_POLL_SHRINK is unsigned int.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1680546

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2019-02-25 13:04:05 +01:00
John Ferlan
8f745819c9 Fix copy paste error on the version check value
Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-11-20 13:54:52 -05:00
John Ferlan
9bc102103c Implement API binding for virDomainSetIOThreadParams
Similar to libvirt_virDomainBlockCopy (and migration API's). Create
the code for the new API.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-11-20 13:24:18 -05:00
John Ferlan
2b4bd07e0a Add check for params, nparams being a dictionary
If PyDict_Check fails, we should force an error rather than
blindly continuing on.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-11-20 13:24:13 -05:00
John Ferlan
1479577af3 Add missing virPyDictToTypedParams for libvirt_virDomainBlockCopy
Need to free params like similar API's such as libvirt_virDomainMigrate3
and libvirt_virDomainMigrateToURI3.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-11-20 11:26:37 -05:00
John Ferlan
2f3ed45cd8 Fix typos in virDomainSetSchedulerParameters name
Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2018-11-20 11:21:42 -05:00
Daniel P. Berrangé
d5aae37c61 Add support for nwfilter binding objects / apis
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-06-28 12:04:05 +01:00
Erik Skultety
6c136b8150 Add support for virNodeGetSEVInfo
This binding allows to query the AMD's SEV firmware for various platform
specific things, like a PDH certificate and a certificate chain to
establish a trusted connection with the firmware. Because the API uses
typed params, it's exempted from generation.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-14 17:23:19 +02:00
Erik Skultety
dbae262811 Add support for virDomainGetLaunchSecurityInfo
Libvirt recently introduced support for getting launch security
parameters, most notably AMD SEV VM memory measurement. This API can't
be generated as it's using typed parameters which we need to allocate.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-14 17:22:59 +02:00
Pavel Hrdina
a950b08317 libvirt_charPtrUnwrap: remove unnecessary check of returned string
Function libvirt_charPtrUnwrap() either fails or always sets the
unwrapped string so there is no need to check it explicitly.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-06-12 10:27:38 +02:00
Pavel Hrdina
0c2d0c9be9 libvirt-override: Reset exception if the error is ignored
In virConnectCredCallbackWrapper() we ignore the error case of
libvirt_charPtrUnwrap() function so we should also reset the exception.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-06-12 10:27:36 +02:00
Jiri Denemark
0f3f82e8be Add support for virConnectBaselineHypervisorCPU
The python bindings for this API cannot be generated because are
generator is not capable of handling string arrays (char **) parameters.

https://bugzilla.redhat.com/show_bug.cgi?id=1584676

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-01 08:16:48 +02:00
Daniel P. Berrangé
c99ed22847 Fix build with older libvirt versions
The libvirt python module is supposed to build with historical versions
of the API back to 0.9.1, which means all constants / methods must be
wrapped in conditionals. This was accidentally forgotten in:

  commit 314b2346df
  Author: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>
  Date:   Wed Feb 7 17:49:30 2018 +0300

    Set hints for virPyDictToTypedParams

    Predefine hints for all parameters possible to avoid wrong type
    convert.

This broke the build against any libvirt < 2.0.0

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-04-19 16:07:19 +01:00
Pavel Hrdina
b3f1a3adb0 Fix virPyDictToTypedParams type hint for block copy params
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-02-19 15:55:51 +01:00
Pavel Hrdina
7c43a863e9 Add missing virPyDictToTypedParams hint for migration params
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-02-19 15:55:48 +01:00
Pavel Hrdina
1d8852d9c4 Fix order of virPyDictToTypedParams hints
This corresponds to the order in libvirt-domain.h header file.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-02-19 15:55:45 +01:00
Pavel Hrdina
920be92397 Use static variables to store virPyDictToTypedParams hints
There is no need to have dynamic allocation every time the API
is called.  Rewrites commit <314b2346df>.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2018-02-19 15:55:28 +01:00
Edgar Kaziakhmedov
314b2346df Set hints for virPyDictToTypedParams
Predefine hints for all parameters possible to avoid wrong type
convert.

Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>
2018-02-19 13:07:07 +00:00
Peng Hao
85c371bd26 libvirt-python : PyObject memory leak
libvirt_virConnectDomainEventTunableCallback leak a PyObject.

Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn>
2017-12-11 13:32:28 +01:00
Nir Soffer
9a93051c16 Unify whitespace around *_ALLOW_THREADS macros
Most of the code treats libvirt API calls as separate block, keeping one
blank line before the LIBVIRT_BEGIN_ALLOW_THREAD, and one blank line
after LIBVIRT_END_ALLOW_THREADS. Unify the whitespace so all calls
wrapped with these macros are treated as a separate block.
2017-09-29 10:49:32 +01:00
Nir Soffer
7af7450b0a Release the GIL during virDomainGetMemoryStats & virDomainGetDiskErrors
We discovered that the entire python process get stuck for about 30
seconds when calling virDomain.getMemoryStats() if libvirt is stuck in
virConnect.getAllDomainStats() on inaccessible storage. This blocking
cause a horrible mess in oVirt.

This patches adds the standard *_ALLOW_THREADS around the call to avoid
this unwanted blocking.

Signed-off-by: Nir Soffer <nirsof@gmail.com>
2017-09-27 16:07:13 +01:00
Daniel P. Berrange
75ec2acb61 Fix comparisons between signed & unsigned integers
When python3 builds C modules, it adds the -Wsign-compare flag to GCC.
This creates lots of warnings where we compare a 'size_t' value against
an 'int' value due to signed/unsigned difference.  Change all the size_t
types to ssize_t to address this.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-09-26 11:12:18 +01:00
Daniel P. Berrange
7534c19a71 Report an error if registering an event loop twice
The C library will now ignore an attempt to register an event
loop twice. It is unable to report an error in this case though
due to the C API returning 'void'. To improve this we must
manually report an error at the python level.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-09-06 11:47:11 +01:00
Daniel P. Berrange
57a160b524 Remove unused variables for event callbacks
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-09-06 11:47:02 +01:00
John Ferlan
213ee4d7ae Implement virDomainMigrateGetMaxDowntime
Add override code for virDomainMigrateGetMaxDowntime
2017-08-26 08:59:24 -04:00
Tomáš Golembiovský
a0e8d37e66 virDomainMemoryStats: include usable memory and last update
We've forgot to include VIR_DOMAIN_MEMORY_STAT_USABLE and
VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE constants.

Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-08-02 12:46:16 +02:00
Michal Privoznik
2e4cb22122 virStream: Introduce virStreamRecvFlags
Yet again, we need a custom wrapper over virStreamRecvFlags
because our generator is not capable of generating it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-05-23 13:43:15 +02:00