]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/QemuServer/Drive.pm
schema: fix description of migrate_downtime parameter
[qemu-server.git] / PVE / QemuServer / Drive.pm
index f3fbaaa5a24ddf1e107df3b43847bf87bab47b4c..6a4fafd95cf07c17c06b5d94e83ec8a30d59ab4c 100644 (file)
@@ -17,9 +17,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/;
@@ -36,6 +36,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.
@@ -162,6 +163,26 @@ my %iothread_fmt = ( iothread => {
        optional => 1,
 });
 
+my %product_fmt = (
+    product => {
+       type => 'string',
+       pattern => '[A-Za-z0-9\-_\s]{,16}', # QEMU (8.1) will quietly only use 16 bytes
+       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}', # QEMU (8.1) will quietly only use 8 bytes
+       format_description => 'vendor',
+       description => "The drive's vendor name, up to 8 bytes long.",
+       optional => 1,
+    },
+);
+
 my %model_fmt = (
     model => {
        type => 'string',
@@ -279,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 = {
@@ -403,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,
@@ -823,4 +848,37 @@ sub path_is_scsi {
     return $res;
 }
 
+sub get_scsi_device_type {
+    my ($drive, $storecfg, $machine_version) = @_;
+
+    my $devicetype = 'hd';
+    my $path = '';
+    if (drive_is_cdrom($drive) || drive_is_cloudinit($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\:\/\// &&
+           !PVE::QemuServer::Helpers::min_version($machine_version, 4, 1)) {
+           $devicetype = 'generic';
+       }
+    }
+
+    return $devicetype;
+}
 1;