From: Adam Julis Date: Sat, 18 Jan 2025 10:30:20 +0000 (+0100) Subject: Support IDE/SATA disk 'product' parameter X-Git-Tag: v11.1.0-rc1~160 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fce24e433b5daa051c9aad0964003cb78bdc268c;p=thirdparty%2Flibvirt.git Support IDE/SATA disk 'product' parameter Since we supported 'product' parameter for SCSI, just expanded existing solution makes IDE/SATA parameter works too. QEMU requires parameter 'model' in case of IDE/SATA (instead of 'product'), so the process of making JSON object is slightly modified. Length of the 'product' parameter is different in SCSI (16 chars) and ATA/SATA (40 chars). Resolves: https://gitlab.com/libvirt/libvirt/-/issues/697 Signed-off-by: Adam Julis Reviewed-by: Peter Krempa --- diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 785b51bb4e..83aeaa32c2 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3570,12 +3570,13 @@ paravirtualized driver is specified via the ``disk`` element. :since:`Since 0.10.1` ``vendor`` If present, this element specifies the vendor of a virtual hard disk or - CD-ROM device. It must not be longer than 8 printable characters. - :since:`Since 1.0.1` + CD-ROM device. It must not be longer than 8 printable characters. Only for + 'scsi' ``bus``.:since:`Since 1.0.1` ``product`` If present, this element specifies the product of a virtual hard disk or - CD-ROM device. It must not be longer than 16 printable characters. - :since:`Since 1.0.1` + CD-ROM device. It must not be longer than 16 printable characters for 'scsi' + (:since:`Since 1.0.1`). For 'sata' or 'ide' not longer than 40 printable + characters (:since:`Since 11.1.0`). Other ``bus`` is not supported. ``address`` If present, the ``address`` element ties the disk to a given slot of a controller (the actual ```` device can often be inferred by diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 6aed74dd8d..eb5e764c02 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -603,8 +603,8 @@ virDomainDiskDefValidateSource(const virStorageSource *src) #define VENDOR_LEN 8 -#define PRODUCT_LEN 16 - +#define PRODUCT_SCSI_LEN 16 +#define PRODUCT_ATA_SATA_LEN 40 /** * virDomainDiskDefSourceLUNValidate: @@ -874,16 +874,21 @@ virDomainDiskDefValidate(const virDomainDef *def, } if (disk->product) { + size_t len = PRODUCT_ATA_SATA_LEN; + + if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) + len = PRODUCT_SCSI_LEN; + if (!virStringIsPrintable(disk->product)) { virReportError(VIR_ERR_XML_ERROR, "%s", _("disk product is not printable string")); return -1; } - if (strlen(disk->product) > PRODUCT_LEN) { + if (strlen(disk->product) > len) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("disk product is more than %1$d characters"), - PRODUCT_LEN); + _("disk product is more than %1$zu characters"), + len); return -1; } } diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng index 5848d3eaaf..96cedb85e8 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -1669,7 +1669,7 @@ - [ -~]{0,16} + [ -~]{0,40} diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 1f20189e89..9e96c59bad 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1619,6 +1619,8 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, const char *biosCHSTrans = NULL; const char *wpolicy = NULL; const char *rpolicy = NULL; + const char *model = NULL; + const char *product = NULL; switch (disk->bus) { case VIR_DOMAIN_DISK_BUS_IDE: @@ -1628,6 +1630,8 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, else driver = "ide-hd"; + model = disk->product; + break; case VIR_DOMAIN_DISK_BUS_SCSI: @@ -1654,6 +1658,8 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, } } + product = disk->product; + break; case VIR_DOMAIN_DISK_BUS_VIRTIO: { @@ -1803,7 +1809,8 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, "A:wwn", &wwn, "p:rotation_rate", disk->rotation_rate, "S:vendor", disk->vendor, - "S:product", disk->product, + "S:product", product, + "S:model", model, "T:removable", removable, "S:write-cache", qemuOnOffAuto(writeCache), "p:cyls", disk->geometry.cylinders, diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 07a505d106..c8ea8b63d2 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2962,10 +2962,20 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk, } } - if (disk->vendor || disk->product) { + if (disk->vendor) { if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Only scsi disk supports vendor and product")); + _("Only scsi disk supports 'vendor'")); + return -1; + } + } + + if (disk->product) { + if ((disk->bus != VIR_DOMAIN_DISK_BUS_IDE) && + (disk->bus != VIR_DOMAIN_DISK_BUS_SATA) && + (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Only ide, sata and scsi disk supports 'product'")); return -1; } } diff --git a/tests/qemuxmlconfdata/disk-sata-product.x86_64-latest.args b/tests/qemuxmlconfdata/disk-sata-product.x86_64-latest.args new file mode 100644 index 0000000000..a171f5c447 --- /dev/null +++ b/tests/qemuxmlconfdata/disk-sata-product.x86_64-latest.args @@ -0,0 +1,36 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/var/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=off,dump-guest-core=off,memory-backend=pc.ram,acpi=off \ +-accel tcg \ +-cpu qemu64 \ +-m size=219136k \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-boot strict=on \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \ +-device '{"driver":"ahci","id":"sata0","bus":"pci.0","addr":"0x2"}' \ +-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUG uest1","node-name":"libvirt-1-storage","read-only":false}' \ +-device '{"driver":"ide-hd","bus":"sata0.0","drive":"libvirt-1-storage","id":"sata0-0-0","bootindex":1,"model":"WD10EZEX-00BN5A0"}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x3"}' \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxmlconfdata/disk-sata-product.x86_64-latest.xml b/tests/qemuxmlconfdata/disk-sata-product.x86_64-latest.xml new file mode 100644 index 0000000000..7a75731146 --- /dev/null +++ b/tests/qemuxmlconfdata/disk-sata-product.x86_64-latest.xml @@ -0,0 +1,41 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + qemu64 + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + + + WD10EZEX-00BN5A0 +
+ + +
+ + +
+ + + + +