* [PULL 0/2] Misc QGA patches for 2025-01-06
@ 2025-01-06 11:38 Konstantin Kostiuk
2025-01-06 11:38 ` [PULL 1/2] qga: implement a 'guest-get-load' command Konstantin Kostiuk
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Konstantin Kostiuk @ 2025-01-06 11:38 UTC (permalink / raw)
To: qemu-devel, Peter Maydell, Stefan Hajnoczi
The following changes since commit 9ee90cfc25747ab25c7da31a50f167fc5122e20e:
Merge tag 'qtest-20250102-pull-request' of https://gitlab.com/farosas/qemu into staging (2025-01-03 09:14:11 -0500)
are available in the Git repository at:
https://github.com/kostyanf14/qemu.git tags/qga-pull-2025-01-06
for you to fetch changes up to 85978dfb6b1c1334ed6aa998ca06c3f45e2127e0:
qemu-ga: Optimize freeze-hook script logic of logging error (2025-01-06 12:57:13 +0200)
----------------------------------------------------------------
qga-pull-2025-01-06
----------------------------------------------------------------
Daniel P. Berrangé (1):
qga: implement a 'guest-get-load' command
Dehan Meng (1):
qemu-ga: Optimize freeze-hook script logic of logging error
meson.build | 1 +
qga/commands-posix.c | 20 ++++++++++++++++++
qga/qapi-schema.json | 37 ++++++++++++++++++++++++++++++++++
scripts/qemu-guest-agent/fsfreeze-hook | 36 +++++++++++++++++++++++++++++----
4 files changed, 90 insertions(+), 4 deletions(-)
Daniel P. Berrangé (1):
qga: implement a 'guest-get-load' command
Dehan Meng (1):
qemu-ga: Optimize freeze-hook script logic of logging error
meson.build | 1 +
qga/commands-posix.c | 20 ++++++++++++++
qga/qapi-schema.json | 37 ++++++++++++++++++++++++++
scripts/qemu-guest-agent/fsfreeze-hook | 36 ++++++++++++++++++++++---
4 files changed, 90 insertions(+), 4 deletions(-)
--
2.47.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PULL 1/2] qga: implement a 'guest-get-load' command 2025-01-06 11:38 [PULL 0/2] Misc QGA patches for 2025-01-06 Konstantin Kostiuk @ 2025-01-06 11:38 ` Konstantin Kostiuk 2025-01-06 11:38 ` [PULL 2/2] qemu-ga: Optimize freeze-hook script logic of logging error Konstantin Kostiuk 2025-01-07 14:32 ` [PULL 0/2] Misc QGA patches for 2025-01-06 Stefan Hajnoczi 2 siblings, 0 replies; 4+ messages in thread From: Konstantin Kostiuk @ 2025-01-06 11:38 UTC (permalink / raw) To: qemu-devel, Peter Maydell, Stefan Hajnoczi From: Daniel P. Berrangé <berrange@redhat.com> Provide a way to report the process load average, via a new 'guest-get-load' command. This is only implemented for POSIX platforms providing 'getloadavg'. Example illustrated with qmp-shell: (QEMU) guest-get-load { "return": { "load15m": 1.546875, "load1m": 1.669921875, "load5m": 1.9306640625 } } Windows has no native equivalent API, but it would be possible to simulate it as illustrated here (BSD-3-Clause): https://github.com/giampaolo/psutil/pull/1485 This is left as an exercise for future contributors. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Message-ID: <20241202121927.864335-1-berrange@redhat.com> Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com> --- meson.build | 1 + qga/commands-posix.c | 20 ++++++++++++++++++++ qga/qapi-schema.json | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/meson.build b/meson.build index e62251c7ca..d06f59095c 100644 --- a/meson.build +++ b/meson.build @@ -2646,6 +2646,7 @@ config_host_data.set('CONFIG_SETNS', cc.has_function('setns') and cc.has_functio config_host_data.set('CONFIG_SYNCFS', cc.has_function('syncfs')) config_host_data.set('CONFIG_SYNC_FILE_RANGE', cc.has_function('sync_file_range')) config_host_data.set('CONFIG_TIMERFD', cc.has_function('timerfd_create')) +config_host_data.set('CONFIG_GETLOADAVG', cc.has_function('getloadavg')) config_host_data.set('HAVE_COPY_FILE_RANGE', cc.has_function('copy_file_range')) config_host_data.set('HAVE_GETIFADDRS', cc.has_function('getifaddrs')) config_host_data.set('HAVE_GLIB_WITH_SLICE_ALLOCATOR', glib_has_gslice) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 636307bedf..6e3c15f539 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -1368,3 +1368,23 @@ char *qga_get_host_name(Error **errp) return g_steal_pointer(&hostname); } + +#ifdef CONFIG_GETLOADAVG +GuestLoadAverage *qmp_guest_get_load(Error **errp) +{ + double loadavg[3]; + GuestLoadAverage *ret = NULL; + + if (getloadavg(loadavg, G_N_ELEMENTS(loadavg)) < 0) { + error_setg_errno(errp, errno, + "cannot query load average"); + return NULL; + } + + ret = g_new0(GuestLoadAverage, 1); + ret->load1m = loadavg[0]; + ret->load5m = loadavg[1]; + ret->load15m = loadavg[2]; + return ret; +} +#endif diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 0537bb7886..995594aaf4 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1843,6 +1843,43 @@ 'if': 'CONFIG_LINUX' } + +## +# @GuestLoadAverage: +# +# Statistics about process load information +# +# @load1m: 1-minute load avage +# +# @load5m: 5-minute load avage +# +# @load15m: 15-minute load avage +# +# Since: 10.0 +## +{ 'struct': 'GuestLoadAverage', + 'data': { + 'load1m': 'number', + 'load5m': 'number', + 'load15m': 'number' + }, + 'if': 'CONFIG_GETLOADAVG' +} + +## +# @guest-get-load: +# +# Retrieve CPU process load information +# +# Returns: load information +# +# Since: 10.0 +## +{ 'command': 'guest-get-load', + 'returns': 'GuestLoadAverage', + 'if': 'CONFIG_GETLOADAVG' +} + ## # @GuestNetworkRoute: # -- 2.47.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PULL 2/2] qemu-ga: Optimize freeze-hook script logic of logging error 2025-01-06 11:38 [PULL 0/2] Misc QGA patches for 2025-01-06 Konstantin Kostiuk 2025-01-06 11:38 ` [PULL 1/2] qga: implement a 'guest-get-load' command Konstantin Kostiuk @ 2025-01-06 11:38 ` Konstantin Kostiuk 2025-01-07 14:32 ` [PULL 0/2] Misc QGA patches for 2025-01-06 Stefan Hajnoczi 2 siblings, 0 replies; 4+ messages in thread From: Konstantin Kostiuk @ 2025-01-06 11:38 UTC (permalink / raw) To: qemu-devel, Peter Maydell, Stefan Hajnoczi From: Dehan Meng <demeng@redhat.com> Make sure the error log of fsfreeze hooks when freeze/thaw/snapshot could be logged to system logs if the default logfile of qga can't be written or other situations Signed-off-by: Dehan Meng <demeng@redhat.com> Reviewed-by: Yan Vugenfirer <yvugenfi@redhat.com> Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com> Message-ID: <20241225083744.277374-1-demeng@redhat.com> Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com> --- scripts/qemu-guest-agent/fsfreeze-hook | 36 +++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/scripts/qemu-guest-agent/fsfreeze-hook b/scripts/qemu-guest-agent/fsfreeze-hook index 13aafd4845..c1feb6f5ce 100755 --- a/scripts/qemu-guest-agent/fsfreeze-hook +++ b/scripts/qemu-guest-agent/fsfreeze-hook @@ -19,15 +19,43 @@ is_ignored_file() { return 1 } +USE_SYSLOG=0 +# if log file is not writable, fallback to syslog +[ ! -w "$LOGFILE" ] && USE_SYSLOG=1 +# try to update log file and fallback to syslog if it fails +touch "$LOGFILE" &>/dev/null || USE_SYSLOG=1 + +# Ensure the log file is writable, fallback to syslog if not +log_message() { + local message="$1" + if [ "$USE_SYSLOG" -eq 0 ]; then + printf "%s: %s\n" "$(date)" "$message" >>"$LOGFILE" + else + logger -t qemu-ga-freeze-hook "$message" + fi +} + # Iterate executables in directory "fsfreeze-hook.d" with the specified args [ ! -d "$FSFREEZE_D" ] && exit 0 + for file in "$FSFREEZE_D"/* ; do is_ignored_file "$file" && continue [ -x "$file" ] || continue - printf "$(date): execute $file $@\n" >>$LOGFILE - "$file" "$@" >>$LOGFILE 2>&1 - STATUS=$? - printf "$(date): $file finished with status=$STATUS\n" >>$LOGFILE + + log_message "Executing $file $@" + if [ "$USE_SYSLOG" -eq 0 ]; then + "$file" "$@" >>"$LOGFILE" 2>&1 + STATUS=$? + else + "$file" "$@" 2>&1 | logger -t qemu-ga-freeze-hook + STATUS=${PIPESTATUS[0]} + fi + + if [ $STATUS -ne 0 ]; then + log_message "Error: $file finished with status=$STATUS" + else + log_message "$file finished successfully" + fi done exit 0 -- 2.47.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PULL 0/2] Misc QGA patches for 2025-01-06 2025-01-06 11:38 [PULL 0/2] Misc QGA patches for 2025-01-06 Konstantin Kostiuk 2025-01-06 11:38 ` [PULL 1/2] qga: implement a 'guest-get-load' command Konstantin Kostiuk 2025-01-06 11:38 ` [PULL 2/2] qemu-ga: Optimize freeze-hook script logic of logging error Konstantin Kostiuk @ 2025-01-07 14:32 ` Stefan Hajnoczi 2 siblings, 0 replies; 4+ messages in thread From: Stefan Hajnoczi @ 2025-01-07 14:32 UTC (permalink / raw) To: Konstantin Kostiuk; +Cc: qemu-devel, Peter Maydell, Stefan Hajnoczi [-- Attachment #1: Type: text/plain, Size: 116 bytes --] Applied, thanks. Please update the changelog at https://wiki.qemu.org/ChangeLog/10.0 for any user-visible changes. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-01-07 14:32 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-01-06 11:38 [PULL 0/2] Misc QGA patches for 2025-01-06 Konstantin Kostiuk 2025-01-06 11:38 ` [PULL 1/2] qga: implement a 'guest-get-load' command Konstantin Kostiuk 2025-01-06 11:38 ` [PULL 2/2] qemu-ga: Optimize freeze-hook script logic of logging error Konstantin Kostiuk 2025-01-07 14:32 ` [PULL 0/2] Misc QGA patches for 2025-01-06 Stefan Hajnoczi
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.