[pve-devel] [PATCH v3 qemu-server 2/2] fix #4957: add vendor and product information passthrough for SCSI-Disks
Hannes Duerr
h.duerr at proxmox.com
Fri Nov 10 10:33:58 CET 2023
adds vendor and product information for SCSI devices to the json schema and
checks in the VM create/update API call if it is possible to add these to QEMU as a device option
Signed-off-by: Hannes Duerr <h.duerr at proxmox.com>
---
PVE/API2/Qemu.pm | 12 ++++++++++++
PVE/QemuServer.pm | 28 ++++++++++++++++++++++++++++
PVE/QemuServer/Drive.pm | 24 ++++++++++++++++++++++++
3 files changed, 64 insertions(+)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 38bdaab..9d8171a 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -1013,6 +1013,13 @@ __PACKAGE__->register_method({
my $conf = $param;
my $arch = PVE::QemuServer::get_vm_arch($conf);
+ for my $opt (sort keys $param->%*) {
+ if ($opt =~ m/scsi/) {
+ PVE::QemuServer::assert_scsi_feature_compatibility(
+ $opt, $conf, $storecfg, $param->{$opt});
+ }
+ }
+
$conf->{meta} = PVE::QemuServer::new_meta_info_string();
my $vollist = [];
@@ -1828,6 +1835,11 @@ my $update_vm_api = sub {
PVE::QemuServer::vmconfig_register_unused_drive($storecfg, $vmid, $conf, PVE::QemuServer::parse_drive($opt, $conf->{pending}->{$opt}))
if defined($conf->{pending}->{$opt});
+ if ($opt =~ m/scsi/) {
+ PVE::QemuServer::assert_scsi_feature_compatibility(
+ $opt, $conf, $storecfg, $param->{$opt});
+ }
+
my (undef, $created_opts) = $create_disks->(
$rpcenv,
$authuser,
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 9a83021..9c998d6 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1368,6 +1368,24 @@ my sub get_drive_id {
return "$drive->{interface}$drive->{index}";
}
+sub assert_scsi_feature_compatibility {
+ my ($opt, $conf, $storecfg, $drive_attributes) = @_;
+
+ my $drive = parse_drive($opt, $drive_attributes);
+
+ my $machine_type = get_vm_machine($conf, undef, $conf->{arch});
+ my $machine_version = extract_version($machine_type, kvm_user_version());
+ my $drivetype = PVE::QemuServer::Drive::get_scsi_devicetype(
+ $drive, $storecfg, $machine_version);
+
+ if ($drivetype ne 'hd' && $drivetype ne 'cd') {
+ if ($drive_attributes =~ m/vendor/ || $drive_attributes =~ m/product/) {
+ die "only 'scsi-hd' and 'scsi-cd' devices".
+ "support passing vendor and product information\n";
+ }
+ }
+}
+
sub print_drivedevice_full {
my ($storecfg, $conf, $vmid, $drive, $bridges, $arch, $machine_type) = @_;
@@ -1401,6 +1419,16 @@ sub print_drivedevice_full {
}
$device .= ",wwn=$drive->{wwn}" if $drive->{wwn};
+ # only scsi-hd and scsi-cd support passing vendor and product information
+ if ($devicetype eq 'hd' || $devicetype eq 'cd') {
+ if (my $vendor = $drive->{vendor}) {
+ $device .= ",vendor=$vendor";
+ }
+ if (my $product = $drive->{product}) {
+ $device .= ",product=$product";
+ }
+ }
+
} elsif ($drive->{interface} eq 'ide' || $drive->{interface} eq 'sata') {
my $maxdev = ($drive->{interface} eq 'sata') ? $PVE::QemuServer::Drive::MAX_SATA_DISKS : 2;
my $controller = int($drive->{index} / $maxdev);
diff --git a/PVE/QemuServer/Drive.pm b/PVE/QemuServer/Drive.pm
index 7056daa..66a4816 100644
--- a/PVE/QemuServer/Drive.pm
+++ b/PVE/QemuServer/Drive.pm
@@ -160,6 +160,26 @@ my %iothread_fmt = ( iothread => {
optional => 1,
});
+my %product_fmt = (
+ product => {
+ type => 'string',
+ pattern => '[A-Za-z0-9\-_]{,40}',
+ format_description => 'product',
+ description => "The drive's product name, up to 40 bytes long.",
+ optional => 1,
+ },
+);
+
+my %vendor_fmt = (
+ vendor => {
+ type => 'string',
+ pattern => '[A-Za-z0-9\-_]{,40}',
+ format_description => 'vendor',
+ description => "The drive's vendor name, up to 40 bytes long.",
+ optional => 1,
+ },
+);
+
my %model_fmt = (
model => {
type => 'string',
@@ -277,10 +297,12 @@ PVE::JSONSchema::register_standard_option("pve-qm-ide", $idedesc);
my $scsi_fmt = {
%drivedesc_base,
%iothread_fmt,
+ %product_fmt,
%queues_fmt,
%readonly_fmt,
%scsiblock_fmt,
%ssd_fmt,
+ %vendor_fmt,
%wwn_fmt,
};
my $scsidesc = {
@@ -401,10 +423,12 @@ my $alldrive_fmt = {
%drivedesc_base,
%iothread_fmt,
%model_fmt,
+ %product_fmt,
%queues_fmt,
%readonly_fmt,
%scsiblock_fmt,
%ssd_fmt,
+ %vendor_fmt,
%wwn_fmt,
%tpmversion_fmt,
%efitype_fmt,
--
2.39.2
More information about the pve-devel
mailing list