summary refs log tree commit diff stats
path: root/qga/commands-linux.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* qga: Fix ubsan warningThomas Huth2025-09-011-5/+5
| | | | | | | | | | | | | | | | | When compiling QEMU with --enable-ubsan there is a undefined behavior warning when running "make check": .../qga/commands-linux.c:452:15: runtime error: applying non-zero offset 5 to null pointer #0 0x55ea7b89450c in build_guest_fsinfo_for_pci_dev ..../qga/commands-linux.c:452:15 Fix it by avoiding the additional pointer variable here and use an "offset" integer variable instead. Signed-off-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Kostiantyn Kostiuk <kkostiuk@redhat.com> Link: https://lore.kernel.org/qemu-devel/20250730072709.27077-1-thuth@redhat.com Signed-off-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
* qga: correctly write to /sys/power/state on linuxMichael Tokarev2025-08-051-6/+8
| | | | | | | | | | | | | | | | | | | | | | | Commit v9.0.0-343-g2048129625 introduced usage of g_file_set_contents() function to write to /sys/power/state. This function uses G_FILE_SET_CONTENTS_CONSISTENT flag to g_file_set_contents_full(), which is implemented by creating a temp file in the same directory and renaming it to the final destination. Which is not how sysfs works. Here, there's not a big deal to do open/write/close - it becomes almost the same as using g_file_set_contents[_full](). But it does not have surprises like this. Also, since this is linux code, it should be ok to use %m in the error reporting function. Fixes: 2048129625 "qga/commands-posix: don't do fork()/exec() when suspending via sysfs" Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3057 Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-ID: <20250801115316.6845-1-mjt@tls.msk.ru> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* qga: skip bind mounts in fs listJean-Louis Dupond2024-12-181-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The filesystem list in build_fs_mount_list should skip bind mounts. This because we end up in locking situations when doing fsFreeze. Like mentioned in [1] and [2]. Next to that, the build_fs_mount_list call did a fallback via build_fs_mount_list_from_mtab if mountinfo did not exist. There it skipped bind mounts, but this is broken for newer OS. This as mounts does not return the path of the bind mount but the underlying dev/partition, so S_ISDIR will never return true in dev_major_minor call. This patch simply checks the existing devmajor:devminor tuple in the mounts, and if it already exists, this means we have the same devices mounted again, a bind mount. So skip this. Same approach is used in open-vm-tools [3]. [1]: https://gitlab.com/qemu-project/qemu/-/issues/592 [2]: https://gitlab.com/qemu-project/qemu/-/issues/520 [3]: https://github.com/vmware/open-vm-tools/commit/d58847b497e212737007958c945af1df22a8ab58 Signed-off-by: Jean-Louis Dupond <jean-louis@dupond.be> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Link: https://lore.kernel.org/r/20241002100634.162499-2-jean-louis@dupond.be Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
* qemu-ga: Avoiding freeing line prematurelyDehan Meng2024-11-071-2/+1
| | | | | | | | | | It's now only freed at the end of the function. Signed-off-by: Dehan Meng <demeng@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Message-ID: <20241107102155.57573-4-kkostiuk@redhat.com> Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
* qemu-ga: Optimize var declaration and definitionDehan Meng2024-11-071-50/+42
| | | | | | | | | | | | Variable declarations moved to the beginning of blocks Followed the coding style of using snake_case for variable names. Proper initialization of param 'size_t n' to '0' for Signed-off-by: Dehan Meng <demeng@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Message-ID: <20241107102155.57573-3-kkostiuk@redhat.com> Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
* qemu-ga: Add 'Null' check and Redefine 'route'Dehan Meng2024-11-071-39/+44
| | | | | | | | | | | | sscanf return values are checked and add 'Null' check for mandatory parameters. And merged redundant route and networkroute variables. Signed-off-by: Dehan Meng <demeng@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Message-ID: <20241107102155.57573-2-kkostiuk@redhat.com> Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
* error: Drop superfluous #include "qapi/qmp/qerror.h"Markus Armbruster2024-10-181-1/+0
| | | | | | Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-ID: <20241010150144.986655-2-armbru@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
* qga/linux: Add new api 'guest-network-get-route'Dehan Meng2024-07-231-0/+133
| | | | | | | | | | | The Route information of the Linux VM needs to be used by administrators and users when debugging network problems and troubleshooting. Signed-off-by: Dehan Meng <demeng@redhat.com> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Message-ID: <20240613092802.346246-2-demeng@redhat.com> Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
* qga: conditionalize schema for commands requiring libudevDaniel P. Berrangé2024-07-191-8/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | Rather than creating stubs for every command that just return QERR_UNSUPPORTED, use 'if' conditions in the schema to fully exclude generation of the filesystem trimming commands on POSIX platforms lacking required APIs. The command will be rejected at QMP dispatch time instead, avoiding reimplementing rejection by blocking the stub commands. This changes the error message for affected commands from {"class": "CommandNotFound", "desc": "Command FOO has been disabled"} to {"class": "CommandNotFound", "desc": "The command FOO has not been found"} This has the additional benefit that the QGA protocol reference now documents what conditions enable use of the command. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Message-ID: <20240712132459.3974109-16-berrange@redhat.com> Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
* qga: move linux memory block command impls to commands-linux.cDaniel P. Berrangé2024-07-191-0/+308
| | | | | | | | | | | | | | | | The qmp_guest_{set,get}_{memory_blocks,block_info} command impls in commands-posix.c are surrounded by '#ifdef __linux__' so should instead live in commands-linux.c This also removes a "#ifdef CONFIG_LINUX" that was nested inside a "#ifdef __linux__". Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Message-ID: <20240712132459.3974109-7-berrange@redhat.com> Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
* qga: move linux disk/cpu stats command impls to commands-linux.cDaniel P. Berrangé2024-07-191-0/+195
| | | | | | | | | | | | | | | | The qmp_guest_{diskstats,cpustats} command impls in commands-posix.c are surrounded by '#ifdef __linux__' so should instead live in commands-linux.c This also removes a "#ifdef CONFIG_LINUX" that was nested inside a "#ifdef __linux__". Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Message-ID: <20240712132459.3974109-6-berrange@redhat.com> Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
* qga: move linux fs/disk command impls to commands-linux.cDaniel P. Berrangé2024-07-191-0/+904
| | | | | | | | | | | | | The qmp_guest_{fstrim, get_fsinfo, get_disks} command impls in commands-posix.c are surrounded by '#ifdef __linux__' so should instead live in commands-linux.c Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20240712132459.3974109-5-berrange@redhat.com> Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
* qga: move linux suspend command impls to commands-linux.cDaniel P. Berrangé2024-07-191-0/+265
| | | | | | | | | | | | | The qmp_guest_suspend_{disk,ram,hybrid} command impls in commands-posix.c are surrounded by '#ifdef __linux__' so should instead live in commands-linux.c Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20240712132459.3974109-4-berrange@redhat.com> Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
* qga: move linux vcpu command impls to commands-linux.cDaniel P. Berrangé2024-07-191-0/+141
| | | | | | | | | | | | | The qmp_guest_set_vcpus and qmp_guest_get_vcpus command impls in commands-posix.c are surrounded by '#ifdef __linux__' so should instead live in commands-linux.c Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Message-ID: <20240712132459.3974109-3-berrange@redhat.com> Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
* qga: Move Linux-specific FS freeze/thaw code to a separate fileAlexander Ivanov2022-10-261-0/+286
In the next patches we are going to add FreeBSD support for QEMU Guest Agent. In the result, code in commands-posix.c will be too cumbersome. Move Linux-specific FS freeze/thaw code to a separate file commands-linux.c keeping common POSIX code in commands-posix.c. Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com> Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>