QGA patches
From: Marc-André Lureau <[email protected]>
The following changes since commit 2e3408b3cc7de4e87a9adafc8c19bfce3abec947:
Merge tag 'misc-pull-request' of gitlab.com:marcandre.lureau/qemu into staging (2022-05-03 09:13:17 -0700)
are available in the Git repository at:
[email protected]:marcandre.lureau/qemu.git tags/qga-pull-request
for you to fetch changes up to 22668881f3def13e9ffcf16840e5fde974a55b1e:
qga: Introduce disk smart (2022-05-04 13:03:19 +0400)
----------------------------------------------------------------
QGA Pull request
----------------------------------------------------------------
Andrew Deason (5):
qga/commands-posix: Use getifaddrs when available qga/commands-posix: Fix iface hw address detection qga/commands-posix: Fix listing ifaces for Solaris qga/commands-posix: Log all net stats failures qga/commands-posix: 'guest-shutdown' for Solaris
Zhenwei Pi (2):
qga: Introduce NVMe disk bus type
qga: Introduce disk smart
meson.build | 1 + qga/qapi-schema.json | 56 +++- qga/commands-posix.c | 591 ++++++++++++++++++++++++++----------------- 3 files changed, 413 insertions(+), 235 deletions(-)
Signature · 1 line
2.36.0.44.g0f828332d5ac
[PULL 2/7] qga/commands-posix: Fix iface hw address detection
From: Andrew Deason <[email protected]>
Since its introduction in commit 3424fc9f16a1 ("qemu-ga: add guest-network-get-interfaces command"), guest-network-get-interfaces seems to check if a given interface has a hardware address by checking 'ifa->ifa_flags & SIOCGIFHWADDR'. But ifa_flags is a field for IFF_* flags (IFF_UP, IFF_LOOPBACK, etc), and comparing it to an ioctl like SIOCGIFHWADDR doesn't make sense.
On Linux, this isn't a big deal, since SIOCGIFHWADDR has so many bits set (0x8927), 'ifa->ifa_flags & SIOCGIFHWADDR' will usually have a nonzero result for any 'normal'-looking interfaces: anything with IFF_UP (0x1) or IFF_BROADCAST (0x2) set, as well as several less-common flags. This means we'll try to get the hardware address for most/all interfaces, even those that don't really have one (like the loopback device). For those interfaces, Linux just returns a hardware address of all zeroes.
On Solaris, however, trying to get the hardware address for a loopback device returns an EADDRNOTAVAIL error. This causes us to return an error and the entire guest-network-get-interfaces call fails.
Change this logic to always try to get the hardware address for each interface, and don't return an error if we fail to get it. Instead, just don't include the 'hardware-address' field in the result if we can't get the hardware address.
Message-Id: <[email protected]>
--- qga/commands-posix.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-)
qga/commands-posix.c +24 -15
@@ -2861,7 +2861,7 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)QAPI_LIST_APPEND (tail, info); } -if (!info->has_hardware_address && ifa->ifa_flags &SIOCGIFHWADDR ) { +if (!info->has_hardware_address) {/* we haven't obtained HW address yet */ sock =socket (PF_INET ,SOCK_STREAM ,0 );if (sock ==-1 ) {
@@ -2872,23 +2872,32 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)memset (&ifr,0 ,sizeof (ifr));pstrcpy (ifr.ifr_name,IF_NAMESIZE , info->name);if (ioctl (sock,SIOCGIFHWADDR , &ifr) ==-1 ) { -error_setg_errno (errp, errno, -"failed to get MAC address of %s" , - ifa->ifa_name); -close (sock); - goto error; - } +/* +* We can't get the hw addr of this interface, but that's not a +* fatal error. Don't set info->hardware_address, but keep +* going. +*/ +if (errno ==EADDRNOTAVAIL ) { +/* The interface doesn't have a hw addr (e.g. loopback). */ +g_debug ("failed to get MAC address of %s: %s" , + ifa->ifa_name,strerror (errno)); + }else { +g_warning ("failed to get MAC address of %s: %s" , + ifa->ifa_name,strerror (errno)); + } -close (sock); - mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data; + }else { + mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data; - info->hardware_address = -g_strdup_printf ("%02x:%02x:%02x:%02x:%02x:%02x" , - (int ) mac_addr[0 ], (int ) mac_addr[1 ], - (int ) mac_addr[2 ], (int ) mac_addr[3 ], - (int ) mac_addr[4 ], (int ) mac_addr[5 ]); + info->hardware_address = +g_strdup_printf ("%02x:%02x:%02x:%02x:%02x:%02x" , + (int ) mac_addr[0 ], (int ) mac_addr[1 ], + (int ) mac_addr[2 ], (int ) mac_addr[3 ], + (int ) mac_addr[4 ], (int ) mac_addr[5 ]); - info->has_hardware_address = true; + info->has_hardware_address = true; + } +close (sock); } if (ifa->ifa_addr &&
Signature · 1 line
2.36.0.44.g0f828332d5ac
[PULL 4/7] qga/commands-posix: Log all net stats failures
In reply to [email protected]From: Andrew Deason <[email protected]>
guest_get_network_stats can silently fail in a couple of ways. Add debug messages to these cases, so we're never completely silent on failure.
Message-Id: <[email protected]>
--- qga/commands-posix.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
qga/commands-posix.c +5 -1
@@ -2775,6 +2775,8 @@ static int guest_get_network_stats(const char *name,size_t n =0 ; fp =fopen (devinfo,"r" );if (!fp) { +g_debug ("failed to open network stats %s: %s" , devinfo, +g_strerror (errno));return -1 ; } name_len =strlen (name);
@@ -2823,7 +2825,9 @@ static int guest_get_network_stats(const char *name,fclose (fp);g_free (line);g_debug ("/proc/net/dev: Interface '%s' not found" , name); -#endif /* CONFIG_LINUX */ +#else /* !CONFIG_LINUX */ +g_debug ("Network stats reporting available only for Linux" ); +#endif /* !CONFIG_LINUX */ return -1 ; }
Signature · 1 line
2.36.0.44.g0f828332d5ac
[PULL 7/7] qga: Introduce disk smart
In reply to [email protected]From: zhenwei pi <[email protected]>
After assigning a NVMe/SCSI controller to guest by VFIO, we lose everything on the host side. A guest uses these devices exclusively, we usually don't care the actions on these devices. But there is a low probability that hitting physical hardware warning, we need a chance to get the basic smart log info.
Introduce disk smart, and implement NVMe smart on linux.
Thanks to Keith and Marc-André.
Message-Id: <[email protected]>
--- qga/qapi-schema.json | 53 +++++++++++++++++++++++++++++++- qga/commands-posix.c | 73 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-)
qga/qapi-schema.json +52 -1
@@ -888,6 +888,55 @@ '*serial': 'str', '*dev': 'str', '*ccw-address': 'GuestCCWAddress'} } +## +# @GuestNVMeSmart: +# +# NVMe smart informations, based on NVMe specification, +# section <SMART / Health Information (Log Identifier 02h)> +# +# Since: 7.1 +## +{ 'struct': 'GuestNVMeSmart', + 'data': {'critical-warning': 'int', + 'temperature': 'int', + 'available-spare': 'int', + 'available-spare-threshold': 'int', + 'percentage-used': 'int', + 'data-units-read-lo': 'uint64', + 'data-units-read-hi': 'uint64', + 'data-units-written-lo': 'uint64', + 'data-units-written-hi': 'uint64', + 'host-read-commands-lo': 'uint64', + 'host-read-commands-hi': 'uint64', + 'host-write-commands-lo': 'uint64', + 'host-write-commands-hi': 'uint64', + 'controller-busy-time-lo': 'uint64', + 'controller-busy-time-hi': 'uint64', + 'power-cycles-lo': 'uint64', + 'power-cycles-hi': 'uint64', + 'power-on-hours-lo': 'uint64', + 'power-on-hours-hi': 'uint64', + 'unsafe-shutdowns-lo': 'uint64', + 'unsafe-shutdowns-hi': 'uint64', + 'media-errors-lo': 'uint64', + 'media-errors-hi': 'uint64', + 'number-of-error-log-entries-lo': 'uint64', + 'number-of-error-log-entries-hi': 'uint64' } } + +## +# @GuestDiskSmart: +# +# Disk type related smart information. +# +# - @nvme: NVMe disk smart +# +# Since: 7.1 +## +{ 'union': 'GuestDiskSmart', + 'base': { 'type': 'GuestDiskBusType' }, + 'discriminator': 'type', + 'data': { 'nvme': 'GuestNVMeSmart' } } + ## # @GuestDiskInfo: #
@@ -899,12 +948,14 @@ # @address: disk address information (only for non-virtual devices) # @alias: optional alias assigned to the disk, on Linux this is a name assigned # by device mapper +# @smart: disk smart information (Since 7.1) # # Since 5.2 ## { 'struct': 'GuestDiskInfo', 'data': {'name': 'str', 'partition': 'bool', '*dependencies': ['str'], - '*address': 'GuestDiskAddress', '*alias': 'str'} } + '*address': 'GuestDiskAddress', '*alias': 'str', + '*smart': 'GuestDiskSmart'} } ## # @guest-get-disks:
qga/commands-posix.c +73 -0
97 lines not on this page · raw message
Signature · 1 line
2.36.0.44.g0f828332d5ac
[PULL 5/7] qga/commands-posix: 'guest-shutdown' for Solaris
In reply to [email protected]From: Andrew Deason <[email protected]>
On Solaris, instead of the -P, -H, and -r flags, we need to provide the target init state to the 'shutdown' command: state 5 is poweroff, 0 is halt, and 6 is reboot. We also need to pass -g0 to avoid the default 60-second delay, and -y to avoid a confirmation prompt.
Implement this logic under an #ifdef CONFIG_SOLARIS, so the 'guest-shutdown' command works properly on Solaris.
Message-Id: <[email protected]>
--- qga/commands-posix.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
qga/commands-posix.c +18 -3
@@ -85,13 +85,23 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)pid_t pid;int status; +#ifdef CONFIG_SOLARIS +const char *powerdown_flag ="-i5" ; +const char *halt_flag ="-i0" ; +const char *reboot_flag ="-i6" ; +#else +const char *powerdown_flag ="-P" ; +const char *halt_flag ="-H" ; +const char *reboot_flag ="-r" ; +#endif +slog ("guest-shutdown called, mode: %s" , mode);if (!has_mode ||strcmp (mode,"powerdown" ) ==0 ) { - shutdown_flag ="-P" ; + shutdown_flag = powerdown_flag; }else if (strcmp (mode,"halt" ) ==0 ) { - shutdown_flag ="-H" ; + shutdown_flag = halt_flag; }else if (strcmp (mode,"reboot" ) ==0 ) { - shutdown_flag ="-r" ; + shutdown_flag = reboot_flag; }else {error_setg (errp,"mode is invalid (valid values are: halt|powerdown|reboot" );
@@ -106,8 +116,13 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)reopen_fd_to_null (1 );reopen_fd_to_null (2 ); +#ifdef CONFIG_SOLARIS +execl ("/sbin/shutdown" ,"shutdown" , shutdown_flag,"-g0" ,"-y" , +"hypervisor initiated shutdown" , (char *)NULL ); +#else execl ("/sbin/shutdown" ,"shutdown" ,"-h" , shutdown_flag,"+0" ,"hypervisor initiated shutdown" , (char *)NULL ); +#endif _exit (EXIT_FAILURE ); }else if (pid <0 ) {error_setg_errno (errp, errno,"failed to create child process" );
Signature · 1 line
2.36.0.44.g0f828332d5ac
[PULL 1/7] qga/commands-posix: Use getifaddrs when available
In reply to [email protected]From: Andrew Deason <[email protected]>
Currently, commands-posix.c assumes that getifaddrs() is only available on Linux, and so the related guest agent command guest-network-get-interfaces is only implemented for #ifdef __linux__. This function does exist on other platforms, though, such as Solaris. So, add a meson check for getifaddrs(), and move the code for guest-network-get-interfaces to be built whenever getifaddrs() is available.
The implementation for guest-network-get-interfaces still has some Linux-specific code, which is not fixed in this commit. This commit moves the relevant big chunks of code around without changing them, so a future commit can change the code in place.
Message-Id: <[email protected]>
--- meson.build | 1 + qga/commands-posix.c | 474 ++++++++++++++++++++++--------------------- 2 files changed, 246 insertions(+), 229 deletions(-)
meson.build +1 -0
@@ -1687,6 +1687,7 @@ 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('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_OPENPTY', cc.has_function('openpty', dependencies: util)) config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul')) config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', prefix: '#include <stdlib.h>'))
qga/commands-posix.c +245 -229
516 lines not on this page · raw message
Signature · 1 line
2.36.0.44.g0f828332d5ac
[PULL 3/7] qga/commands-posix: Fix listing ifaces for Solaris
In reply to [email protected]From: Andrew Deason <[email protected]>
The code for guest-network-get-interfaces needs a couple of small adjustments for Solaris:
- The results from SIOCGIFHWADDR are documented as being in ifr_addr, not ifr_hwaddr (ifr_hwaddr doesn't exist on Solaris).
- The implementation of guest_get_network_stats is Linux-specific, so hide it under #ifdef CONFIG_LINUX. On non-Linux, we just won't provide network interface stats.
Message-Id: <[email protected]>
--- qga/commands-posix.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
qga/commands-posix.c +6 -1
@@ -2767,6 +2767,7 @@ guest_find_interface(GuestNetworkInterfaceList *head,static int guest_get_network_stats (const char *name,GuestNetworkInterfaceStat *stats) { +#ifdef CONFIG_LINUX int name_len;char const *devinfo ="/proc/net/dev" ;FILE *fp;
@@ -2822,6 +2823,7 @@ static int guest_get_network_stats(const char *name,fclose (fp);g_free (line);g_debug ("/proc/net/dev: Interface '%s' not found" , name); +#endif /* CONFIG_LINUX */ return -1 ; }
@@ -2887,8 +2889,11 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) } }else { +#ifdef CONFIG_SOLARIS + mac_addr = (unsigned char *) &ifr.ifr_addr.sa_data; +#else mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data; - +#endif info->hardware_address = g_strdup_printf("%02x:%02x:%02x:%02x:%02x:%02x", (int) mac_addr[0], (int) mac_addr[1],
Signature · 1 line
2.36.0.44.g0f828332d5ac
[PULL 6/7] qga: Introduce NVMe disk bus type
In reply to [email protected]From: zhenwei pi <[email protected]>
Assigning a NVMe disk by VFIO or emulating a NVMe controller by QEMU, a NVMe disk get exposed in guest side. Support NVMe disk bus type and implement posix version.
Test PCI passthrough case:
~#virsh qemu-agent-command buster '{"execute":"guest-get-disks"}' | jq
...
{
"name": "/dev/nvme0n1",
"dependencies": [],
"partition": false,
"address": {
"serial": "SAMSUNG MZQL23T8HCLS-00A07_S64HNE0N500076",
"bus-type": "nvme",
"bus": 0,
"unit": 0,
"pci-controller": {
"bus": 0,
"slot": 22,
"domain": 0,
"function": 0
},
"dev": "/dev/nvme0n1",
"target": 0
}...
Message-Id: <[email protected]>
--- qga/qapi-schema.json | 3 ++- qga/commands-posix.c | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-)
qga/qapi-schema.json +2 -1
@@ -827,13 +827,14 @@ # @mmc: Win multimedia card (MMC) bus type # @virtual: Win virtual bus type # @file-backed-virtual: Win file-backed bus type +# @nvme: NVMe disks (since 7.1) # # Since: 2.2; 'Unknown' and all entries below since 2.4 ## { 'enum': 'GuestDiskBusType', 'data': [ 'ide', 'fdc', 'scsi', 'virtio', 'xen', 'usb', 'uml', 'sata', 'sd', 'unknown', 'ieee1394', 'ssa', 'fibre', 'raid', 'iscsi', - 'sas', 'mmc', 'virtual', 'file-backed-virtual' ] } + 'sas', 'mmc', 'virtual', 'file-backed-virtual', 'nvme' ] } ##
qga/commands-posix.c +4 -1
@@ -890,7 +890,8 @@ static bool build_guest_fsinfo_for_pci_dev(char const *syspath,if (driver && (g_str_equal (driver,"ata_piix" ) ||g_str_equal (driver,"sym53c8xx" ) ||g_str_equal (driver,"virtio-pci" ) || -g_str_equal (driver,"ahci" ))) { +g_str_equal (driver,"ahci" ) || +g_str_equal (driver,"nvme" ))) {break ; }
@@ -985,6 +986,8 @@ static bool build_guest_fsinfo_for_pci_dev(char const *syspath,g_debug ("no host for '%s' (driver '%s')" , syspath, driver); goto cleanup; } + }else if (strcmp (driver,"nvme" ) ==0 ) { + disk->bus_type =GUEST_DISK_BUS_TYPE_NVME ; }else {g_debug ("unknown driver '%s' (sysfs path '%s')" , driver, syspath); goto cleanup;
Signature · 1 line
2.36.0.44.g0f828332d5ac
Richard Henderson
AppliedQuoted 8 lines · On 5/4/22 03:00, [email protected] wrote:
From: Marc-André Lureau <[email protected]>
The following changes since commit
2e3408b3cc7de4e87a9adafc8c19bfce3abec947:Merge tag 'misc-pull-request' of gitlab.com:marcandre.lureau/qemu into staging (2022-05-03 09:13:17 -0700)are available in the Git repository at:
Quoted 8 lines
[email protected]:marcandre.lureau/qemu.git tags/qga-pull-request
for you to fetch changes up to
22668881f3def13e9ffcf16840e5fde974a55b1e:qga: Introduce disk smart (2022-05-04 13:03:19 +0400)----------------------------------------------------------------
QGA Pull request
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/7.1 as appropriate.
r~
Quoted 19 lines
----------------------------------------------------------------
Andrew Deason (5):
qga/commands-posix: Use getifaddrs when available qga/commands-posix: Fix iface hw address detection qga/commands-posix: Fix listing ifaces for Solaris qga/commands-posix: Log all net stats failures qga/commands-posix: 'guest-shutdown' for SolarisZhenwei Pi (2):
qga: Introduce NVMe disk bus type
qga: Introduce disk smartmeson.build | 1 + qga/qapi-schema.json | 56 +++- qga/commands-posix.c | 591 ++++++++++++++++++++++++++----------------- 3 files changed, 413 insertions(+), 235 deletions(-)