public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH v4 qemu-server 0/4] fix #4957: add vendor and product information passthrough for SCSI-Disks
@ 2023-11-17 11:53 Hannes Duerr
  2023-11-17 11:53 ` [pve-devel] [PATCH v4 qemu-server 1/4] Move path_is_scsi to QemuServer/Drive.pm Hannes Duerr
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Hannes Duerr @ 2023-11-17 11:53 UTC (permalink / raw)
  To: pve-devel

changes in v2:
- when calling the API to create/update a VM, check whether the devices
are "scsi-hd" or "scsi-cd" devices,where there is the option to add
vendor and product information, if not error out
- change the format in product_fmt and vendor_fmt to a pattern that only
allows 40 characters consisting of upper and lower case letters, numbers and '-' and '_'.

changes in v3:
- splitup into preparation and fix patch
- move get_scsi_devicetype into QemuServer/Drive.pm
- refactor check_scsi_feature_compatibility to assert_scsi_feature_compatibility
- assert_scsi_feature_compatibility before creating the device
- handle 'local-lvm:' syntax in get_scsi_devicetype
- fix style issues

changes in v4:
- create assert_scsi_feature_compatibility() in API2/Qemu.pm
- divide the preparation into smaller steps
- remove or harden brittle regex
- fix wrong storagename assumption

Hannes Duerr (4):
  Move path_is_scsi to QemuServer/Drive.pm
  Move NEW_DISK_RE to QemuServer/Drive.pm
  drive: Create get_scsi_devicetype
  fix #4957: add vendor and product information passthrough for
    SCSI-Disks

 PVE/API2/Qemu.pm        |  49 +++++++++++++++--
 PVE/QemuServer.pm       | 100 +++++----------------------------
 PVE/QemuServer/Drive.pm | 119 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 177 insertions(+), 91 deletions(-)

-- 
2.39.2





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pve-devel] [PATCH v4 qemu-server 1/4] Move path_is_scsi to QemuServer/Drive.pm
  2023-11-17 11:53 [pve-devel] [PATCH v4 qemu-server 0/4] fix #4957: add vendor and product information passthrough for SCSI-Disks Hannes Duerr
@ 2023-11-17 11:53 ` Hannes Duerr
  2023-11-17 11:53 ` [pve-devel] [PATCH v4 qemu-server 2/4] Move NEW_DISK_RE " Hannes Duerr
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Hannes Duerr @ 2023-11-17 11:53 UTC (permalink / raw)
  To: pve-devel

Prepare for introduction of new helper

Signed-off-by: Hannes Duerr <h.duerr@proxmox.com>
---
 PVE/QemuServer.pm       | 62 +----------------------------------------
 PVE/QemuServer/Drive.pm | 61 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 61 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index c465fb6..294702d 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -53,7 +53,7 @@ use PVE::QemuServer::Helpers qw(config_aware_timeout min_version windows_version
 use PVE::QemuServer::Cloudinit;
 use PVE::QemuServer::CGroup;
 use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options);
-use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit drive_is_cdrom drive_is_read_only parse_drive print_drive);
+use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit drive_is_cdrom drive_is_read_only parse_drive print_drive path_is_scsi);
 use PVE::QemuServer::Machine;
 use PVE::QemuServer::Memory qw(get_current_memory);
 use PVE::QemuServer::Monitor qw(mon_cmd);
@@ -1342,66 +1342,6 @@ sub pve_verify_hotplug_features {
     die "unable to parse hotplug option\n";
 }
 
-sub scsi_inquiry {
-    my($fh, $noerr) = @_;
-
-    my $SG_IO = 0x2285;
-    my $SG_GET_VERSION_NUM = 0x2282;
-
-    my $versionbuf = "\x00" x 8;
-    my $ret = ioctl($fh, $SG_GET_VERSION_NUM, $versionbuf);
-    if (!$ret) {
-	die "scsi ioctl SG_GET_VERSION_NUM failoed - $!\n" if !$noerr;
-	return;
-    }
-    my $version = unpack("I", $versionbuf);
-    if ($version < 30000) {
-	die "scsi generic interface too old\n"  if !$noerr;
-	return;
-    }
-
-    my $buf = "\x00" x 36;
-    my $sensebuf = "\x00" x 8;
-    my $cmd = pack("C x3 C x1", 0x12, 36);
-
-    # see /usr/include/scsi/sg.h
-    my $sg_io_hdr_t = "i i C C s I P P P I I i P C C C C S S i I I";
-
-    my $packet = pack(
-	$sg_io_hdr_t, ord('S'), -3, length($cmd), length($sensebuf), 0, length($buf), $buf, $cmd, $sensebuf, 6000
-    );
-
-    $ret = ioctl($fh, $SG_IO, $packet);
-    if (!$ret) {
-	die "scsi ioctl SG_IO failed - $!\n" if !$noerr;
-	return;
-    }
-
-    my @res = unpack($sg_io_hdr_t, $packet);
-    if ($res[17] || $res[18]) {
-	die "scsi ioctl SG_IO status error - $!\n" if !$noerr;
-	return;
-    }
-
-    my $res = {};
-    $res->@{qw(type removable vendor product revision)} = unpack("C C x6 A8 A16 A4", $buf);
-
-    $res->{removable} = $res->{removable} & 128 ? 1 : 0;
-    $res->{type} &= 0x1F;
-
-    return $res;
-}
-
-sub path_is_scsi {
-    my ($path) = @_;
-
-    my $fh = IO::File->new("+<$path") || return;
-    my $res = scsi_inquiry($fh, 1);
-    close($fh);
-
-    return $res;
-}
-
 sub print_tabletdevice_full {
     my ($conf, $arch) = @_;
 
diff --git a/PVE/QemuServer/Drive.pm b/PVE/QemuServer/Drive.pm
index e24ba12..dce1398 100644
--- a/PVE/QemuServer/Drive.pm
+++ b/PVE/QemuServer/Drive.pm
@@ -17,6 +17,7 @@ drive_is_cdrom
 drive_is_read_only
 parse_drive
 print_drive
+path_is_scsi
 );
 
 our $QEMU_FORMAT_RE = qr/raw|cow|qcow|qcow2|qed|vmdk|cloop/;
@@ -760,4 +761,64 @@ sub resolve_first_disk {
     return;
 }
 
+sub scsi_inquiry {
+    my($fh, $noerr) = @_;
+
+    my $SG_IO = 0x2285;
+    my $SG_GET_VERSION_NUM = 0x2282;
+
+    my $versionbuf = "\x00" x 8;
+    my $ret = ioctl($fh, $SG_GET_VERSION_NUM, $versionbuf);
+    if (!$ret) {
+	die "scsi ioctl SG_GET_VERSION_NUM failoed - $!\n" if !$noerr;
+	return;
+    }
+    my $version = unpack("I", $versionbuf);
+    if ($version < 30000) {
+	die "scsi generic interface too old\n"  if !$noerr;
+	return;
+    }
+
+    my $buf = "\x00" x 36;
+    my $sensebuf = "\x00" x 8;
+    my $cmd = pack("C x3 C x1", 0x12, 36);
+
+    # see /usr/include/scsi/sg.h
+    my $sg_io_hdr_t = "i i C C s I P P P I I i P C C C C S S i I I";
+
+    my $packet = pack(
+	$sg_io_hdr_t, ord('S'), -3, length($cmd), length($sensebuf), 0, length($buf), $buf, $cmd, $sensebuf, 6000
+    );
+
+    $ret = ioctl($fh, $SG_IO, $packet);
+    if (!$ret) {
+	die "scsi ioctl SG_IO failed - $!\n" if !$noerr;
+	return;
+    }
+
+    my @res = unpack($sg_io_hdr_t, $packet);
+    if ($res[17] || $res[18]) {
+	die "scsi ioctl SG_IO status error - $!\n" if !$noerr;
+	return;
+    }
+
+    my $res = {};
+    $res->@{qw(type removable vendor product revision)} = unpack("C C x6 A8 A16 A4", $buf);
+
+    $res->{removable} = $res->{removable} & 128 ? 1 : 0;
+    $res->{type} &= 0x1F;
+
+    return $res;
+}
+
+sub path_is_scsi {
+    my ($path) = @_;
+
+    my $fh = IO::File->new("+<$path") || return;
+    my $res = scsi_inquiry($fh, 1);
+    close($fh);
+
+    return $res;
+}
+
 1;
-- 
2.39.2





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pve-devel] [PATCH v4 qemu-server 2/4] Move NEW_DISK_RE to QemuServer/Drive.pm
  2023-11-17 11:53 [pve-devel] [PATCH v4 qemu-server 0/4] fix #4957: add vendor and product information passthrough for SCSI-Disks Hannes Duerr
  2023-11-17 11:53 ` [pve-devel] [PATCH v4 qemu-server 1/4] Move path_is_scsi to QemuServer/Drive.pm Hannes Duerr
@ 2023-11-17 11:53 ` Hannes Duerr
  2023-11-17 11:53 ` [pve-devel] [PATCH v4 qemu-server 3/4] drive: Create get_scsi_devicetype Hannes Duerr
  2023-11-17 11:53 ` [pve-devel] [PATCH v4 qemu-server 4/4] fix #4957: add vendor and product information passthrough for SCSI-Disks Hannes Duerr
  3 siblings, 0 replies; 6+ messages in thread
From: Hannes Duerr @ 2023-11-17 11:53 UTC (permalink / raw)
  To: pve-devel

Move it due to better context and preparation of fix

Signed-off-by: Hannes Duerr <h.duerr@proxmox.com>
---
 PVE/API2/Qemu.pm        | 10 ++++------
 PVE/QemuServer/Drive.pm |  1 +
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 38bdaab..b9c8f20 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -86,8 +86,6 @@ my $foreach_volume_with_alloc = sub {
     }
 };
 
-my $NEW_DISK_RE = qr!^(([^/:\s]+):)?(\d+(\.\d+)?)$!;
-
 my $check_drive_param = sub {
     my ($param, $storecfg, $extra_checks) = @_;
 
@@ -98,7 +96,7 @@ my $check_drive_param = sub {
 	raise_param_exc({ $opt => "unable to parse drive options" }) if !$drive;
 
 	if ($drive->{'import-from'}) {
-	    if ($drive->{file} !~ $NEW_DISK_RE || $3 != 0) {
+	    if ($drive->{file} !~ $PVE::QemuServer::Drive::NEW_DISK_RE || $3 != 0) {
 		raise_param_exc({
 		    $opt => "'import-from' requires special syntax - ".
 			"use <storage ID>:0,import-from=<source>",
@@ -142,7 +140,7 @@ my $check_storage_access = sub {
 	    # nothing to check
 	} elsif ($isCDROM && ($volid eq 'cdrom')) {
 	    $rpcenv->check($authuser, "/", ['Sys.Console']);
-	} elsif (!$isCDROM && ($volid =~ $NEW_DISK_RE)) {
+	} elsif (!$isCDROM && ($volid =~ $PVE::QemuServer::Drive::NEW_DISK_RE)) {
 	    my ($storeid, $size) = ($2 || $default_storage, $3);
 	    die "no storage ID specified (and no default storage)\n" if !$storeid;
 	    $rpcenv->check($authuser, "/storage/$storeid", ['Datastore.AllocateSpace']);
@@ -365,7 +363,7 @@ my $create_disks = sub {
 	    delete $disk->{format}; # no longer needed
 	    $res->{$ds} = PVE::QemuServer::print_drive($disk);
 	    print "$ds: successfully created disk '$res->{$ds}'\n";
-	} elsif ($volid =~ $NEW_DISK_RE) {
+	} elsif ($volid =~ $PVE::QemuServer::Drive::NEW_DISK_RE) {
 	    my ($storeid, $size) = ($2 || $default_storage, $3);
 	    die "no storage ID specified (and no default storage)\n" if !$storeid;
 
@@ -1626,7 +1624,7 @@ my $update_vm_api  = sub {
 	return if defined($volname) && $volname eq 'cloudinit';
 
 	my $format;
-	if ($volid =~ $NEW_DISK_RE) {
+	if ($volid =~ $PVE::QemuServer::Drive::NEW_DISK_RE) {
 	    $storeid = $2;
 	    $format = $drive->{format} || PVE::Storage::storage_default_format($storecfg, $storeid);
 	} else {
diff --git a/PVE/QemuServer/Drive.pm b/PVE/QemuServer/Drive.pm
index dce1398..6d94a2f 100644
--- a/PVE/QemuServer/Drive.pm
+++ b/PVE/QemuServer/Drive.pm
@@ -34,6 +34,7 @@ my $MAX_SCSI_DISKS = 31;
 my $MAX_VIRTIO_DISKS = 16;
 our $MAX_SATA_DISKS = 6;
 our $MAX_UNUSED_DISKS = 256;
+our $NEW_DISK_RE = qr!^(([^/:\s]+):)?(\d+(\.\d+)?)$!;
 
 our $drivedesc_hash;
 # Schema when disk allocation is possible.
-- 
2.39.2





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pve-devel] [PATCH v4 qemu-server 3/4] drive: Create get_scsi_devicetype
  2023-11-17 11:53 [pve-devel] [PATCH v4 qemu-server 0/4] fix #4957: add vendor and product information passthrough for SCSI-Disks Hannes Duerr
  2023-11-17 11:53 ` [pve-devel] [PATCH v4 qemu-server 1/4] Move path_is_scsi to QemuServer/Drive.pm Hannes Duerr
  2023-11-17 11:53 ` [pve-devel] [PATCH v4 qemu-server 2/4] Move NEW_DISK_RE " Hannes Duerr
@ 2023-11-17 11:53 ` Hannes Duerr
  2023-11-17 11:53 ` [pve-devel] [PATCH v4 qemu-server 4/4] fix #4957: add vendor and product information passthrough for SCSI-Disks Hannes Duerr
  3 siblings, 0 replies; 6+ messages in thread
From: Hannes Duerr @ 2023-11-17 11:53 UTC (permalink / raw)
  To: pve-devel

Encapsulation of the functionality for determining the scsi device type in a new function
for reusability in QemuServer/Drive.pm

Signed-off-by: Hannes Duerr <h.duerr@proxmox.com>
---
 PVE/QemuServer.pm       | 29 ++++-------------------------
 PVE/QemuServer/Drive.pm | 35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 38 insertions(+), 26 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 294702d..6090f91 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -53,7 +53,7 @@ use PVE::QemuServer::Helpers qw(config_aware_timeout min_version windows_version
 use PVE::QemuServer::Cloudinit;
 use PVE::QemuServer::CGroup;
 use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options);
-use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit drive_is_cdrom drive_is_read_only parse_drive print_drive path_is_scsi);
+use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit drive_is_cdrom drive_is_read_only parse_drive print_drive);
 use PVE::QemuServer::Machine;
 use PVE::QemuServer::Memory qw(get_current_memory);
 use PVE::QemuServer::Monitor qw(mon_cmd);
@@ -1386,31 +1386,10 @@ sub print_drivedevice_full {
 
 	my ($maxdev, $controller, $controller_prefix) = scsihw_infos($conf, $drive);
 	my $unit = $drive->{index} % $maxdev;
-	my $devicetype = 'hd';
-	my $path = '';
-	if (drive_is_cdrom($drive)) {
-	    $devicetype = 'cd';
-	} else {
-	    if ($drive->{file} =~ m|^/|) {
-		$path = $drive->{file};
-		if (my $info = path_is_scsi($path)) {
-		    if ($info->{type} == 0 && $drive->{scsiblock}) {
-			$devicetype = 'block';
-		    } elsif ($info->{type} == 1) { # tape
-			$devicetype = 'generic';
-		    }
-		}
-	    } else {
-		 $path = PVE::Storage::path($storecfg, $drive->{file});
-	    }
 
-	    # for compatibility only, we prefer scsi-hd (#2408, #2355, #2380)
-	    my $version = extract_version($machine_type, kvm_user_version());
-	    if ($path =~ m/^iscsi\:\/\// &&
-	       !min_version($version, 4, 1)) {
-		$devicetype = 'generic';
-	    }
-	}
+	my $machine_version = extract_version($machine_type, kvm_user_version());
+	my $devicetype  = PVE::QemuServer::Drive::get_scsi_devicetype(
+	    $drive, $storecfg, $machine_version);
 
 	if (!$conf->{scsihw} || $conf->{scsihw} =~ m/^lsi/ || $conf->{scsihw} eq 'pvscsi') {
 	    $device = "scsi-$devicetype,bus=$controller_prefix$controller.0,scsi-id=$unit";
diff --git a/PVE/QemuServer/Drive.pm b/PVE/QemuServer/Drive.pm
index 6d94a2f..de62d43 100644
--- a/PVE/QemuServer/Drive.pm
+++ b/PVE/QemuServer/Drive.pm
@@ -15,9 +15,9 @@ is_valid_drivename
 drive_is_cloudinit
 drive_is_cdrom
 drive_is_read_only
+get_scsi_devicetype
 parse_drive
 print_drive
-path_is_scsi
 );
 
 our $QEMU_FORMAT_RE = qr/raw|cow|qcow|qcow2|qed|vmdk|cloop/;
@@ -822,4 +822,37 @@ sub path_is_scsi {
     return $res;
 }
 
+sub get_scsi_devicetype {
+    my ($drive, $storecfg, $machine_version) = @_;
+
+    my $devicetype = 'hd';
+    my $path = '';
+    if (drive_is_cdrom($drive)) {
+	$devicetype = 'cd';
+    } else {
+	if ($drive->{file} =~ m|^/|) {
+	    $path = $drive->{file};
+	    if (my $info = path_is_scsi($path)) {
+		if ($info->{type} == 0 && $drive->{scsiblock}) {
+		    $devicetype = 'block';
+		} elsif ($info->{type} == 1) { # tape
+		    $devicetype = 'generic';
+		}
+	    }
+	} elsif ($drive->{file} =~ $NEW_DISK_RE){
+	    # special syntax cannot be parsed to path
+	    return $devicetype;
+	} else {
+	    $path = PVE::Storage::path($storecfg, $drive->{file});
+	}
+
+	# for compatibility only, we prefer scsi-hd (#2408, #2355, #2380)
+	if ($path =~ m/^iscsi\:\/\// &&
+	   !min_version($machine_version, 4, 1)) {
+	    $devicetype = 'generic';
+	}
+    }
+
+    return $devicetype;
+}
 1;
-- 
2.39.2





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pve-devel] [PATCH v4 qemu-server 4/4] fix #4957: add vendor and product information passthrough for SCSI-Disks
  2023-11-17 11:53 [pve-devel] [PATCH v4 qemu-server 0/4] fix #4957: add vendor and product information passthrough for SCSI-Disks Hannes Duerr
                   ` (2 preceding siblings ...)
  2023-11-17 11:53 ` [pve-devel] [PATCH v4 qemu-server 3/4] drive: Create get_scsi_devicetype Hannes Duerr
@ 2023-11-17 11:53 ` Hannes Duerr
  2023-11-17 12:24   ` Hannes Dürr
  3 siblings, 1 reply; 6+ messages in thread
From: Hannes Duerr @ 2023-11-17 11:53 UTC (permalink / raw)
  To: pve-devel

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@proxmox.com>
---
 PVE/API2/Qemu.pm        | 39 +++++++++++++++++++++++++++++++++++++++
 PVE/QemuServer.pm       | 13 ++++++++++++-
 PVE/QemuServer/Drive.pm | 24 ++++++++++++++++++++++++
 3 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index b9c8f20..fc8c876 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -696,6 +696,33 @@ my $check_vm_modify_config_perm = sub {
     return 1;
 };
 
+sub assert_scsi_feature_compatibility {
+    my ($opt, $conf, $storecfg, $drive_attributes) = @_;
+
+    my $drive = PVE::QemuServer::Drive::parse_drive($opt, $drive_attributes);
+
+    my $machine_type = PVE::QemuServer::get_vm_machine($conf, undef, $conf->{arch});
+    my $machine_version = PVE::QemuServer::extract_version(
+	$machine_type, PVE::QemuServer::kvm_user_version());
+    my $drivetype = PVE::QemuServer::Drive::get_scsi_devicetype(
+	$drive, $storecfg, $machine_version);
+
+    if ($drivetype ne 'hd' && $drivetype ne 'cd') {
+	if ($drive->{product}) {
+	    raise_param_exc({
+		product => "Passing of product information is only supported for".
+		"'scsi-hd' and 'scsi-cd' devices (e.g. not pass-through)."
+	    });
+	}
+	if ($drive->{vendor}) {
+	    raise_param_exc({
+		vendor => "Passing of vendor information is only supported for".
+		"'scsi-hd' and 'scsi-cd' devices (e.g. not pass-through)."
+	    });
+	}
+    }
+}
+
 __PACKAGE__->register_method({
     name => 'vmlist',
     path => '',
@@ -1011,6 +1038,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(\d)+$/) {
+			assert_scsi_feature_compatibility(
+			    $opt, $conf, $storecfg, $param->{$opt});
+		    }
+		}
+
 		$conf->{meta} = PVE::QemuServer::new_meta_info_string();
 
 		my $vollist = [];
@@ -1826,6 +1860,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(\d)+$/) {
+			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 6090f91..4fbb9b2 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1210,7 +1210,8 @@ sub kvm_user_version {
     return $kvm_user_version->{$binary};
 
 }
-my sub extract_version {
+
+our sub extract_version {
     my ($machine_type, $version) = @_;
     $version = kvm_user_version() if !defined($version);
     return PVE::QemuServer::Machine::extract_version($machine_type, $version)
@@ -1404,6 +1405,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 de62d43..4e1646d 100644
--- a/PVE/QemuServer/Drive.pm
+++ b/PVE/QemuServer/Drive.pm
@@ -161,6 +161,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',
@@ -278,10 +298,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 = {
@@ -402,10 +424,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





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [pve-devel] [PATCH v4 qemu-server 4/4] fix #4957: add vendor and product information passthrough for SCSI-Disks
  2023-11-17 11:53 ` [pve-devel] [PATCH v4 qemu-server 4/4] fix #4957: add vendor and product information passthrough for SCSI-Disks Hannes Duerr
@ 2023-11-17 12:24   ` Hannes Dürr
  0 siblings, 0 replies; 6+ messages in thread
From: Hannes Dürr @ 2023-11-17 12:24 UTC (permalink / raw)
  To: pve-devel

New Version can be found here:
https://lists.proxmox.com/pipermail/pve-devel/2023-November/060429.html

On 11/17/23 12:53, Hannes Duerr wrote:
> 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@proxmox.com>
> ---
>   PVE/API2/Qemu.pm        | 39 +++++++++++++++++++++++++++++++++++++++
>   PVE/QemuServer.pm       | 13 ++++++++++++-
>   PVE/QemuServer/Drive.pm | 24 ++++++++++++++++++++++++
>   3 files changed, 75 insertions(+), 1 deletion(-)
>
>   __PACKAGE__->register_method({
>       name => 'vmlist',
>       path => '',
> @@ -1011,6 +1038,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(\d)+$/) {
> +			assert_scsi_feature_compatibility(
> +			    $opt, $conf, $storecfg, $param->{$opt});
> +		    }
> +		}
> +
>   		$conf->{meta} = PVE::QemuServer::new_meta_info_string();
>   
>   		my $vollist = [];
> @@ -1826,6 +1860,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(\d)+$/) {
> +			PVE::QemuServer::assert_scsi_feature_compatibility(
> +			    $opt, $conf, $storecfg, $param->{$opt});
^ copy paste error
> +		    }
> +
>   		    my (undef, $created_opts) = $create_disks->(
>   			$rpcenv,
>   			$authuser,




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-11-17 12:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-17 11:53 [pve-devel] [PATCH v4 qemu-server 0/4] fix #4957: add vendor and product information passthrough for SCSI-Disks Hannes Duerr
2023-11-17 11:53 ` [pve-devel] [PATCH v4 qemu-server 1/4] Move path_is_scsi to QemuServer/Drive.pm Hannes Duerr
2023-11-17 11:53 ` [pve-devel] [PATCH v4 qemu-server 2/4] Move NEW_DISK_RE " Hannes Duerr
2023-11-17 11:53 ` [pve-devel] [PATCH v4 qemu-server 3/4] drive: Create get_scsi_devicetype Hannes Duerr
2023-11-17 11:53 ` [pve-devel] [PATCH v4 qemu-server 4/4] fix #4957: add vendor and product information passthrough for SCSI-Disks Hannes Duerr
2023-11-17 12:24   ` Hannes Dürr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal