Introduce NVMe type and Smart for qga
cover Introduce NVMe type and Smart for qga
Introduce NVMe disk type for qga firstly, then support SMART in the response of command "guest-get-disks".
Originally I sent the 2 patch separately, because the second patch is dependent on the first one. So resend them in a patchset.
Zhenwei Pi (2):
qga: Introduce NVMe disk bus type
qga: Introduce disk smart
qga/commands-posix.c | 78 +++++++++++++++++++++++++++++++++++++++++++- qga/qapi-schema.json | 56 +++++++++++++++++++++++++++++-- 2 files changed, 131 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
PATCH RESEND 1/2 qga: Introduce NVMe disk bus type
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
}...
--- qga/commands-posix.c | 5 ++++- qga/qapi-schema.json | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-)
qga/commands-posix.c +4 -1
@@ -889,7 +889,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 ; }
@@ -984,6 +985,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;
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.0) # # 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' ] } ##
Signature · 1 line
2.25.1
Re: [RESEND 1/2] qga: Introduce NVMe disk bus type
Quoted 38 lines · zhenwei pi
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 }...
Signed-off-by zhenwei pi <[email protected]>--- qga/commands-posix.c | 5 ++++- qga/qapi-schema.json | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-)qga/qapi-schema.json +0
-0
qga/qapi-schema.json line 830
Quoted 4 lines
qga/qapi-schema.json +1
-0@@ -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.0)
If this patch isn't merged soon, this will need to be updated.
BTW I think I already review this patch, anyhow:
Re: Re: [RESEND 1/2] qga: Introduce NVMe disk bus type
Quoted 46 lines · Philippe Mathieu-Daudé
Quoted 38 lines · zhenwei pi
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
}
...Signed-off-by zhenwei pi <[email protected]>---
qga/commands-posix.c| 5 ++++-
qga/qapi-schema.json| 3 ++-2 files changed, 6 insertions(+), 2 deletions(-)qga/qapi-schema.json +0
-0qga/qapi-schema.json line 830
Quoted 4 lines
qga/qapi-schema.json +1
-0@@ -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.0)If this patch isn't merged soon, this will need to be updated.
Quoted 2 lines
BTW I think I already review this patch, anyhow:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Thanks a lot! I'll update the version info if this patch is deferred.
Signature · 1 line
zhenwei pi
PATCH RESEND 2/2 qga: Introduce disk smart
In reply to zhenwei piAfter 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é.
--- qga/commands-posix.c | 73 ++++++++++++++++++++++++++++++++++++++++++++ qga/qapi-schema.json | 53 +++++++++++++++++++++++++++++++- 2 files changed, 125 insertions(+), 1 deletion(-)
qga/commands-posix.c +73 -0
@@ -27,6 +27,7 @@#include "qemu/base64.h" #include "qemu/cutils.h" #include "commands-common.h" +#include "block/nvme.h" #ifdef HAVE_UTMPX #include <utmpx.h>
@@ -49,6 +50,7 @@ extern char **environ;#include <sys/socket.h> #include <net/if.h> #include <sys/statvfs.h> +#include <linux/nvme_ioctl.h> #ifdef CONFIG_LIBUDEV #include <libudev.h>
@@ -1390,6 +1392,76 @@ static GuestDiskInfoList *get_disk_partitions(return ret; } +static void get_nvme_smart (GuestDiskInfo *disk) +{ +int fd; +GuestNVMeSmart *smart; +NvmeSmartLog log = {0 }; +struct nvme_admin_cmd cmd = { + .opcode =NVME_ADM_CMD_GET_LOG_PAGE , + .nsid =NVME_NSID_BROADCAST , + .addr = (uint64_t )&log, + .data_len =sizeof (log), + .cdw10 =NVME_LOG_SMART_INFO | (1 <<15 )/* RAE bit */ + | (((sizeof (log) >>2 ) -1 ) <<16 ) + }; + + fd =qemu_open_old (disk->name,O_RDONLY ); +if (fd ==-1 ) { +g_debug ("Failed to open device: %s: %s" , disk->name,g_strerror (errno)); +return ; + } + +if (ioctl (fd,NVME_IOCTL_ADMIN_CMD , &cmd)) { +g_debug ("Failed to get smart: %s: %s" , disk->name,g_strerror (errno)); +close (fd); +return ; + } + + disk->has_smart = true; + disk->smart =g_new0 (GuestDiskSmart,1 ); + disk->smart->type =GUEST_DISK_BUS_TYPE_NVME ; + + smart = &disk->smart->u.nvme; + smart->critical_warning = log.critical_warning; + smart->temperature =lduw_le_p (&log.temperature);/* unaligned field */ + smart->available_spare = log.available_spare; + smart->available_spare_threshold = log.available_spare_threshold; + smart->percentage_used = log.percentage_used; + smart->data_units_read_lo =le64_to_cpu (log.data_units_read[0 ]); + smart->data_units_read_hi =le64_to_cpu (log.data_units_read[1 ]); + smart->data_units_written_lo =le64_to_cpu (log.data_units_written[0 ]); + smart->data_units_written_hi =le64_to_cpu (log.data_units_written[1 ]); + smart->host_read_commands_lo =le64_to_cpu (log.host_read_commands[0 ]); + smart->host_read_commands_hi =le64_to_cpu (log.host_read_commands[1 ]); + smart->host_write_commands_lo =le64_to_cpu (log.host_write_commands[0 ]); + smart->host_write_commands_hi =le64_to_cpu (log.host_write_commands[1 ]); + smart->controller_busy_time_lo =le64_to_cpu (log.controller_busy_time[0 ]); + smart->controller_busy_time_hi =le64_to_cpu (log.controller_busy_time[1 ]); + smart->power_cycles_lo =le64_to_cpu (log.power_cycles[0 ]); + smart->power_cycles_hi =le64_to_cpu (log.power_cycles[1 ]); + smart->power_on_hours_lo =le64_to_cpu (log.power_on_hours[0 ]); + smart->power_on_hours_hi =le64_to_cpu (log.power_on_hours[1 ]); + smart->unsafe_shutdowns_lo =le64_to_cpu (log.unsafe_shutdowns[0 ]); + smart->unsafe_shutdowns_hi =le64_to_cpu (log.unsafe_shutdowns[1 ]); + smart->media_errors_lo =le64_to_cpu (log.media_errors[0 ]); + smart->media_errors_hi =le64_to_cpu (log.media_errors[1 ]); + smart->number_of_error_log_entries_lo = +le64_to_cpu (log.number_of_error_log_entries[0 ]); + smart->number_of_error_log_entries_hi = +le64_to_cpu (log.number_of_error_log_entries[1 ]); + +close (fd); +} + +static void get_disk_smart (GuestDiskInfo *disk) +{ +if (disk->has_address + && (disk->address->bus_type ==GUEST_DISK_BUS_TYPE_NVME )) { +get_nvme_smart (disk); + } +} +GuestDiskInfoList *qmp_guest_get_disks (Error **errp) {GuestDiskInfoList *ret =NULL ;
@@ -1463,6 +1535,7 @@ GuestDiskInfoList *qmp_guest_get_disks(Error **errp) }get_disk_deps (disk_dir, disk); +get_disk_smart (disk); ret =get_disk_partitions (ret, de->d_name, disk_dir, dev_name); }
qga/qapi-schema.json +52 -1
70 lines not on this page · raw message
Signature · 1 line
2.25.1