From: Hannes Duerr <h.duerr@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v6 qemu-server 4/4] fix #4957: add vendor and product information passthrough for SCSI-Disks
Date: Wed, 6 Dec 2023 08:47:45 +0100 [thread overview]
Message-ID: <20231206074745.18832-5-h.duerr@proxmox.com> (raw)
In-Reply-To: <20231206074745.18832-1-h.duerr@proxmox.com>
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 | 38 ++++++++++++++++++++++++++++++++++++++
PVE/QemuServer.pm | 13 ++++++++++++-
PVE/QemuServer/Drive.pm | 24 ++++++++++++++++++++++++
3 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 9e3cfb5..e0fbb3c 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 => '',
@@ -1013,6 +1040,12 @@ __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 +1866,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 b3e651e..3a4c30d 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1218,7 +1218,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)
@@ -1427,6 +1428,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 5747356..82d117e 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]{,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\-_\s]{,40}',
+ format_description => 'vendor',
+ description => "The drive's vendor name, up to 40 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
next prev parent reply other threads:[~2023-12-06 7:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-06 7:47 [pve-devel] [PATCH v6 qemu-server 0/4] " Hannes Duerr
2023-12-06 7:47 ` [pve-devel] [PATCH v6 qemu-server 1/4] Move path_is_scsi to QemuServer/Drive.pm Hannes Duerr
2023-12-06 7:47 ` [pve-devel] [PATCH v6 qemu-server 2/4] Move NEW_DISK_RE " Hannes Duerr
2023-12-06 7:47 ` [pve-devel] [PATCH v6 qemu-server 3/4] drive: Create get_scsi_devicetype Hannes Duerr
2023-12-06 7:47 ` Hannes Duerr [this message]
2024-01-05 16:00 ` [pve-devel] [PATCH v6 qemu-server 4/4] fix #4957: add vendor and product information passthrough for SCSI-Disks Fiona Ebner
2024-01-05 16:00 ` [pve-devel] partially-applied: [PATCH v6 qemu-server 0/4] " Fiona Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231206074745.18832-5-h.duerr@proxmox.com \
--to=h.duerr@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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