Skip to content

Commit 6528013

Browse files
committed
Merge tag 'qga-pull-2025-01-06' of https://github.com/kostyanf14/qemu into staging
qga-pull-2025-01-06 # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCAAdFiEEwsLBCepDxjwUI+uE711egWG6hOcFAmd7vqMACgkQ711egWG6 # hOffRxAAotgBsE+o8fsZ2tfOKNPekW0hlw/hceDMJRA2UwOSPfw1fXfw59w4Pnfr # 4xwMC6O8Lu9ohBCBWHUvh3261gJgXQkLASbbzmF2oewfXZyvPXQI8nz78Ol3LBTG # gL8lwaBci3YuFtc+2/55VdQsWUqtrRMvBW9WSXTEC+0dQJv+VzblXlEF7hQkKppT # oGiHQL7pEA1UP7bRo4TyaoDnc8a+xz1J+vtEZUZghtreT7I3ELai/PFdo0U99fkf # HZfjyj2sHCZto+tAokjBcqf2RXDRqUVRsn3GgC1MQbh1LRdfShmhCTbgYYk/1MmD # 0xwiqAsw814W25299LM3xP2LHPm1jKtkZyCyuSXme9QtN9mC3F0TipR+HMRErAj0 # GQTBOJ0LinZsx5U/+ih4/qPj7RRov+SFzpVxBV3NUkpneVFp5FQgOo4n8l+h57ap # fmkZ6/hb8itn2oux7S9v/LkcmWE3FqThKO6qMXOhBhQDCKpICz8liYO/tPdB4x1Q # /HHQ9oon0A2eQw/53AYqz0SoazOqNtadg/hsQ11OHDExUjdp4M6hyxtmrJEQz4Et # AFvIby98lJZCZ1u65dv/Prb+gW0E8AQ5Ib0jJllAm7tL/GjVyhbRlUl8S9R2uTcZ # Gsb6e3DMBOny/lR9+2M4rCyCqXM58gTohuqtcXvAe8l2a3h23B4= # =uk2Q # -----END PGP SIGNATURE----- # gpg: Signature made Mon 06 Jan 2025 06:29:39 EST # gpg: using RSA key C2C2C109EA43C63C1423EB84EF5D5E8161BA84E7 # gpg: Good signature from "Kostiantyn Kostiuk (Upstream PR sign) <[email protected]>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: C2C2 C109 EA43 C63C 1423 EB84 EF5D 5E81 61BA 84E7 * tag 'qga-pull-2025-01-06' of https://github.com/kostyanf14/qemu: qemu-ga: Optimize freeze-hook script logic of logging error qga: implement a 'guest-get-load' command Signed-off-by: Stefan Hajnoczi <[email protected]>
2 parents 9ee90cf + 85978df commit 6528013

File tree

4 files changed

+90
-4
lines changed

4 files changed

+90
-4
lines changed

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,6 +2646,7 @@ config_host_data.set('CONFIG_SETNS', cc.has_function('setns') and cc.has_functio
26462646
config_host_data.set('CONFIG_SYNCFS', cc.has_function('syncfs'))
26472647
config_host_data.set('CONFIG_SYNC_FILE_RANGE', cc.has_function('sync_file_range'))
26482648
config_host_data.set('CONFIG_TIMERFD', cc.has_function('timerfd_create'))
2649+
config_host_data.set('CONFIG_GETLOADAVG', cc.has_function('getloadavg'))
26492650
config_host_data.set('HAVE_COPY_FILE_RANGE', cc.has_function('copy_file_range'))
26502651
config_host_data.set('HAVE_GETIFADDRS', cc.has_function('getifaddrs'))
26512652
config_host_data.set('HAVE_GLIB_WITH_SLICE_ALLOCATOR', glib_has_gslice)

qga/commands-posix.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,3 +1368,23 @@ char *qga_get_host_name(Error **errp)
13681368

13691369
return g_steal_pointer(&hostname);
13701370
}
1371+
1372+
#ifdef CONFIG_GETLOADAVG
1373+
GuestLoadAverage *qmp_guest_get_load(Error **errp)
1374+
{
1375+
double loadavg[3];
1376+
GuestLoadAverage *ret = NULL;
1377+
1378+
if (getloadavg(loadavg, G_N_ELEMENTS(loadavg)) < 0) {
1379+
error_setg_errno(errp, errno,
1380+
"cannot query load average");
1381+
return NULL;
1382+
}
1383+
1384+
ret = g_new0(GuestLoadAverage, 1);
1385+
ret->load1m = loadavg[0];
1386+
ret->load5m = loadavg[1];
1387+
ret->load15m = loadavg[2];
1388+
return ret;
1389+
}
1390+
#endif

qga/qapi-schema.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,43 @@
18431843
'if': 'CONFIG_LINUX'
18441844
}
18451845

1846+
1847+
##
1848+
# @GuestLoadAverage:
1849+
#
1850+
# Statistics about process load information
1851+
#
1852+
# @load1m: 1-minute load avage
1853+
#
1854+
# @load5m: 5-minute load avage
1855+
#
1856+
# @load15m: 15-minute load avage
1857+
#
1858+
# Since: 10.0
1859+
##
1860+
{ 'struct': 'GuestLoadAverage',
1861+
'data': {
1862+
'load1m': 'number',
1863+
'load5m': 'number',
1864+
'load15m': 'number'
1865+
},
1866+
'if': 'CONFIG_GETLOADAVG'
1867+
}
1868+
1869+
##
1870+
# @guest-get-load:
1871+
#
1872+
# Retrieve CPU process load information
1873+
#
1874+
# Returns: load information
1875+
#
1876+
# Since: 10.0
1877+
##
1878+
{ 'command': 'guest-get-load',
1879+
'returns': 'GuestLoadAverage',
1880+
'if': 'CONFIG_GETLOADAVG'
1881+
}
1882+
18461883
##
18471884
# @GuestNetworkRoute:
18481885
#

scripts/qemu-guest-agent/fsfreeze-hook

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,43 @@ is_ignored_file() {
1919
return 1
2020
}
2121

22+
USE_SYSLOG=0
23+
# if log file is not writable, fallback to syslog
24+
[ ! -w "$LOGFILE" ] && USE_SYSLOG=1
25+
# try to update log file and fallback to syslog if it fails
26+
touch "$LOGFILE" &>/dev/null || USE_SYSLOG=1
27+
28+
# Ensure the log file is writable, fallback to syslog if not
29+
log_message() {
30+
local message="$1"
31+
if [ "$USE_SYSLOG" -eq 0 ]; then
32+
printf "%s: %s\n" "$(date)" "$message" >>"$LOGFILE"
33+
else
34+
logger -t qemu-ga-freeze-hook "$message"
35+
fi
36+
}
37+
2238
# Iterate executables in directory "fsfreeze-hook.d" with the specified args
2339
[ ! -d "$FSFREEZE_D" ] && exit 0
40+
2441
for file in "$FSFREEZE_D"/* ; do
2542
is_ignored_file "$file" && continue
2643
[ -x "$file" ] || continue
27-
printf "$(date): execute $file $@\n" >>$LOGFILE
28-
"$file" "$@" >>$LOGFILE 2>&1
29-
STATUS=$?
30-
printf "$(date): $file finished with status=$STATUS\n" >>$LOGFILE
44+
45+
log_message "Executing $file $@"
46+
if [ "$USE_SYSLOG" -eq 0 ]; then
47+
"$file" "$@" >>"$LOGFILE" 2>&1
48+
STATUS=$?
49+
else
50+
"$file" "$@" 2>&1 | logger -t qemu-ga-freeze-hook
51+
STATUS=${PIPESTATUS[0]}
52+
fi
53+
54+
if [ $STATUS -ne 0 ]; then
55+
log_message "Error: $file finished with status=$STATUS"
56+
else
57+
log_message "$file finished successfully"
58+
fi
3159
done
3260

3361
exit 0

0 commit comments

Comments
 (0)