all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH qemu-server v7 0/1] fix #4957: add vendor and product information passthrough for SCSI-Disks
@ 2024-01-10 12:45 Hannes Duerr
  2024-01-10 12:45 ` [pve-devel] [PATCH qemu-server v7 1/1] " Hannes Duerr
  2024-01-26 10:19 ` [pve-devel] applied: [PATCH qemu-server v7 0/1] " Fiona Ebner
  0 siblings, 2 replies; 3+ messages in thread
From: Hannes Duerr @ 2024-01-10 12:45 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

changes in v5:
- fix copy/paste mistake

changes in v6:
- add whitespace to allowed characters for vendor and product
  information
- fix undefined subroutine errors
- fix nits

changes in v7:
- use PVE::QemuServer::Machine::extract_version() to avoid making the helper
public
- since the properties cannot be hotplugged, skip the properties during hotplugg
- reduce the amount of allowed characters due to restrictions in qemu

qemu-server:

Hannes Duerr (1):
  fix #4957: add vendor and product information passthrough for
    SCSI-Disks

 PVE/API2/Qemu.pm        | 39 +++++++++++++++++++++++++++++++++++++++
 PVE/QemuServer.pm       | 12 ++++++++++++
 PVE/QemuServer/Drive.pm | 24 ++++++++++++++++++++++++
 3 files changed, 75 insertions(+)


Summary over all repositories:
  3 files changed, 75 insertions(+), 0 deletions(-)

-- 
Generated by git-murpp 0.5.0




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

* [pve-devel] [PATCH qemu-server v7 1/1] fix #4957: add vendor and product information passthrough for SCSI-Disks
  2024-01-10 12:45 [pve-devel] [PATCH qemu-server v7 0/1] fix #4957: add vendor and product information passthrough for SCSI-Disks Hannes Duerr
@ 2024-01-10 12:45 ` Hannes Duerr
  2024-01-26 10:19 ` [pve-devel] applied: [PATCH qemu-server v7 0/1] " Fiona Ebner
  1 sibling, 0 replies; 3+ messages in thread
From: Hannes Duerr @ 2024-01-10 12:45 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       | 12 ++++++++++++
 PVE/QemuServer/Drive.pm | 24 ++++++++++++++++++++++++
 3 files changed, 75 insertions(+)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 9e3cfb5..8808ac5 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::Machine::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 => '',
@@ -1013,6 +1040,13 @@ __PACKAGE__->register_method({
 		my $conf = $param;
 		my $arch = PVE::QemuServer::get_vm_arch($conf);
 
+
+		for my $opt (sort keys $param->%*) {
+		    next if $opt !~ m/^scsi\d+$/;
+		    assert_scsi_feature_compatibility(
+			$opt, $conf, $storecfg, $param->{$opt});
+		}
+
 		$conf->{meta} = PVE::QemuServer::new_meta_info_string();
 
 		my $vollist = [];
@@ -1833,6 +1867,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+$/) {
+			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 a6a118b..9ec4591 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1427,6 +1427,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);
@@ -5359,8 +5369,10 @@ sub vmconfig_update_disk {
 		    safe_string_ne($drive->{discard}, $old_drive->{discard}) ||
 		    safe_string_ne($drive->{iothread}, $old_drive->{iothread}) ||
 		    safe_string_ne($drive->{queues}, $old_drive->{queues}) ||
+		    safe_string_ne($drive->{product}, $old_drive->{product}) ||
 		    safe_string_ne($drive->{cache}, $old_drive->{cache}) ||
 		    safe_string_ne($drive->{ssd}, $old_drive->{ssd}) ||
+		    safe_string_ne($drive->{vendor}, $old_drive->{vendor}) ||
 		    safe_string_ne($drive->{ro}, $old_drive->{ro})) {
 		    die "skip\n";
 		}
diff --git a/PVE/QemuServer/Drive.pm b/PVE/QemuServer/Drive.pm
index 5747356..6064bea 100644
--- a/PVE/QemuServer/Drive.pm
+++ b/PVE/QemuServer/Drive.pm
@@ -163,6 +163,26 @@ my %iothread_fmt = ( iothread => {
 	optional => 1,
 });
 
+my %product_fmt = (
+    product => {
+	type => 'string',
+	pattern => '[A-Za-z0-9\-_\s]{,16}',
+	format_description => 'product',
+	description => "The drive's product name, up to 16 bytes long.",
+	optional => 1,
+    },
+);
+
+my %vendor_fmt = (
+    vendor => {
+	type => 'string',
+	pattern => '[A-Za-z0-9\-_\s]{,8}',
+	format_description => 'vendor',
+	description => "The drive's vendor name, up to 8 bytes long.",
+	optional => 1,
+    },
+);
+
 my %model_fmt = (
     model => {
 	type => 'string',
@@ -280,10 +300,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 = {
@@ -404,10 +426,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] 3+ messages in thread

* [pve-devel] applied: [PATCH qemu-server v7 0/1] fix #4957: add vendor and product information passthrough for SCSI-Disks
  2024-01-10 12:45 [pve-devel] [PATCH qemu-server v7 0/1] fix #4957: add vendor and product information passthrough for SCSI-Disks Hannes Duerr
  2024-01-10 12:45 ` [pve-devel] [PATCH qemu-server v7 1/1] " Hannes Duerr
@ 2024-01-26 10:19 ` Fiona Ebner
  1 sibling, 0 replies; 3+ messages in thread
From: Fiona Ebner @ 2024-01-26 10:19 UTC (permalink / raw)
  To: Proxmox VE development discussion, Hannes Duerr

Am 10.01.24 um 13:45 schrieb Hannes Duerr:
> qemu-server:
> 
> Hannes Duerr (1):
>   fix #4957: add vendor and product information passthrough for
>     SCSI-Disks
> 
>  PVE/API2/Qemu.pm        | 39 +++++++++++++++++++++++++++++++++++++++
>  PVE/QemuServer.pm       | 12 ++++++++++++
>  PVE/QemuServer/Drive.pm | 24 ++++++++++++++++++++++++
>  3 files changed, 75 insertions(+)
> 
> 
> Summary over all repositories:
>   3 files changed, 75 insertions(+), 0 deletions(-)
> 

applied, thanks!

Squashed in a few style changes that didn't warrant a new version IMHO:
- You can use up to 100 characters per line, no need to split function
calls early, if they can fit that limit
- The exception message should be for raised for the config option, not
the sub-option, e.g. 'scsi0' instead of 'product'
- Also fixed the style for the exception (missing trailing comma,
indentation, message missing a space):

> -               product => "Passing of product information is only supported for".
> -               "'scsi-hd' and 'scsi-cd' devices (e.g. not pass-through)."
> +               $opt => "Passing of product information is only supported for 'scsi-hd' and "
> +                   ."'scsi-cd' devices (e.g. not pass-through).",




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

end of thread, other threads:[~2024-01-26 10:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-10 12:45 [pve-devel] [PATCH qemu-server v7 0/1] fix #4957: add vendor and product information passthrough for SCSI-Disks Hannes Duerr
2024-01-10 12:45 ` [pve-devel] [PATCH qemu-server v7 1/1] " Hannes Duerr
2024-01-26 10:19 ` [pve-devel] applied: [PATCH qemu-server v7 0/1] " Fiona Ebner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal