Misc QGA patches for 2025-01-06
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
[PULL 2/2] qemu-ga: Optimize freeze-hook script logic of logging error
From: Dehan Meng <[email protected]>
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
Message-ID: <[email protected]>
--- scripts/qemu-guest-agent/fsfreeze-hook | 36 +++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-)
scripts/qemu-guest-agent/fsfreeze-hook +32 -4
@@ -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
Signature · 1 line
2.47.1
[PULL 1/2] qga: implement a 'guest-get-load' command
In reply to Konstantin KostiukFrom: Daniel P. Berrangé <[email protected]>
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.
Message-ID: <[email protected]>
--- meson.build | 1 + qga/commands-posix.c | 20 ++++++++++++++++++++ qga/qapi-schema.json | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+)
meson.build +1 -0
@@ -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)
qga/commands-posix.c +20 -0
@@ -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
qga/qapi-schema.json +37 -0
@@ -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: #
Signature · 1 line
2.47.1
Stefan Hajnoczi
AppliedApplied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/10.0 for any user-visible changes.