On Sat, Jul 15, 2023 at 18:37:10 +0200, Benedek Major wrote: > The XML-Schema specifies two tags vendor and product for the disk type. But they only apply to the SCSI bus, > even though the QEMU driver ide-hd and ide-cd have support for the command line argument -model. > The model corresponds to words 27-46 of the IDENTIFY PACKET DEVICE response from the ATAPI spec. > Words 27-46 is a 40 Char space for the model number of the device. The model number is built by > combining the vendor and the product fields with a single space as separator in the middle. If there are any formatting requirements (e.g. from this description it seems that 'vendor' must not contain any space in order to work, then you'll need to add code enforcing them. > Therefore I would say, that vendor and product pretty much correlate to the model field in QEMU, This feels very subjective. Could you please add a better justification? E.g. show how qemu formats the default vendor and product name? > so the ide disk should also have the possibility of adding vendor and product to it. > The tests got changed to incorporate the new error message which now contains that the ide and > sata bus also supports vendor and product. Also the xml to command line tests got updated, to > have both fields present for testing. > The command generator reordered a bit too, to only include disk->vendor and disk->product into the > json generation, when the scsi bus is selected. The same logic applies to the ide and sata bus. This bit above can be dropped > Signed-off-by: Benedek Major <benedek@xxxxxxxxx> > --- > src/qemu/qemu_command.c | 21 ++++++++++++++++--- > src/qemu/qemu_validate.c | 6 ++++-- > .../disk-sata-device.x86_64-latest.args | 2 +- > tests/qemuxml2argvdata/disk-sata-device.xml | 2 ++ > ...csi-disk-vpd-build-error.x86_64-latest.err | 2 +- > .../disk-sata-device.x86_64-latest.xml | 2 ++ > 6 files changed, 28 insertions(+), 7 deletions(-) > > diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c > index ad224571f3..903872091f 100644 > --- a/src/qemu/qemu_command.c > +++ b/src/qemu/qemu_command.c > @@ -1943,8 +1943,6 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, > "p:physical_block_size", physical_block_size, > "A:wwn", &wwn, > "p:rotation_rate", disk->rotation_rate, > - "S:vendor", disk->vendor, > - "S:product", disk->product, > "T:removable", removable, > "S:write-cache", qemuOnOffAuto(writeCache), > "p:cyls", disk->geometry.cylinders, > @@ -1956,7 +1954,24 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, > "S:rerror", rpolicy, > NULL) < 0) > return NULL; > - > + if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) { > + /* add vendor and product in SCSI section, since only SCSI supports > + * vendor and product tag*/ > + if (virJSONValueObjectAdd(&props, > + "S:vendor", disk->vendor, > + "S:product", disk->product, Please make your changes conform to the code formatting we use. E.g. the line above should align all arguments below &props. Ideally, to prevent code movement, use local variables to extract vendor/product only if appropriate and initialize them to NULL > + NULL) < 0) > + return NULL; > + } > + if (disk->bus == VIR_DOMAIN_DISK_BUS_IDE || disk->bus == VIR_DOMAIN_DISK_BUS_SATA) { > + /* Repurpose vendor and product, since IDE-Disk only supports model, > + * which per ATAPI spec is the combination of vendor and product > + * separated by a single space*/ > + if (virJSONValueObjectAdd(&props, > + "S:model", g_strconcat(disk->vendor, " ", disk->product, NULL), g_strconcat allocates a new string, but the "S:" json building modifier does NOT consume it, thus memory is leaked here. You'll need a temporary variable. This aligns pretty well with the above non-movement of the code where you can simply add a "S:model", modelstr, into the original formatter and fill it conditionally. Additionally the above ine would be misformatted otherwise. > + NULL) < 0) > + return NULL; This also looks misformatted as it's returning if virJSONValueObjectAdd fails. > + } > return g_steal_pointer(&props); > } > > diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c > index 7e09e2c52f..e7312bf789 100644 > --- a/src/qemu/qemu_validate.c > +++ b/src/qemu/qemu_validate.c > @@ -2871,9 +2871,11 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk, > } > > if (disk->vendor || disk->product) { > - if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI) { > + if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI > + && disk->bus != VIR_DOMAIN_DISK_BUS_IDE > + && disk->bus != VIR_DOMAIN_DISK_BUS_SATA) { Please follow our coding style, we format logic operators at the end of the line rather than at the start of the next one. > virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", > - _("Only scsi disk supports vendor and product")); > + _("Only scsi, sata and ide disk supports vendor and product")); > return -1; > }