[pve-devel] [PATCH qemu-server] remove pve-qm-drive

Wolfgang Bumiller w.bumiller at proxmox.com
Thu May 19 11:44:30 CEST 2016


Let 'cdrom' use the pve-qm-ide format, as it's supposed to
be an alias to ide2.
We're not using the 'alias' schema property (yet) since
there's still a parse function in qemu-server which does not
deal with them.

This also brings back support for old-style filenames for
the drive options other than 'cdrom' (which is most likely
only found in very very old backup files).
---
 PVE/QemuServer.pm | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index fe19d7f..7b40f62 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -434,7 +434,7 @@ EODESCR
     },
     cdrom => {
 	optional => 1,
-	type => 'string', format => 'pve-qm-drive',
+	type => 'string', format => 'pve-qm-ide',
 	typetext => 'volume',
 	description => "This is an alias for option -ide2",
     },
@@ -662,6 +662,13 @@ sub verify_volume_id_or_qm_path {
 	return $volid;
     }
 
+    # parse_vm_config special-cases old-style file names and converts them, so
+    # allow them, too. filename_to_volume_id() uses the same cases as we have
+    # above plus the following:
+    if ($volid !~ /^[^:]+:.+$/) {
+	return $volid;
+    }
+
     # if its neither 'none' nor 'cdrom' nor a path, check if its a volume-id
     $volid = eval { PVE::JSONSchema::check_format('pve-volume-id', $volid, '') };
     if ($@) {
@@ -848,6 +855,7 @@ my $idedesc = {
     description => "Use volume as IDE hard disk or CD-ROM (n is 0 to " .($MAX_IDE_DISKS -1) . ").",
 };
 PVE::JSONSchema::register_standard_option("pve-qm-ide", $idedesc);
+PVE::JSONSchema::register_format("pve-qm-ide", $ide_fmt);
 
 my $scsi_fmt = {
     %drivedesc_base,
@@ -1941,12 +1949,6 @@ sub check_type {
         die "type check ('number') failed - got '$value'\n";
     } elsif ($type eq 'string') {
 	if (my $fmt = $confdesc->{$key}->{format}) {
-	    if ($fmt eq 'pve-qm-drive') {
-		# special case - we need to pass $key to parse_drive()
-		my $drive = parse_drive($key, $value);
-		return $value if $drive;
-		die "unable to parse drive options\n";
-	    }
 	    PVE::JSONSchema::check_format($fmt, $value);
 	    return $value;
 	}
@@ -2094,8 +2096,9 @@ sub parse_vm_config {
 	    if ($@) {
 		warn "vm $vmid - unable to parse value of '$key' - $@";
 	    } else {
+		$key = 'ide2' if $key eq 'cdrom';
 		my $fmt = $confdesc->{$key}->{format};
-		if ($fmt && $fmt eq 'pve-qm-drive') {
+		if ($fmt && $fmt =~ /^pve-qm-(?:ide|scsi|virtio|sata)$/) {
 		    my $v = parse_drive($key, $value);
 		    if (my $volid = filename_to_volume_id($vmid, $v->{file}, $v->{media})) {
 			$v->{file} = $volid;
@@ -2106,11 +2109,7 @@ sub parse_vm_config {
 		    }
 		}
 
-		if ($key eq 'cdrom') {
-		    $conf->{ide2} = $value;
-		} else {
-		    $conf->{$key} = $value;
-		}
+		$conf->{$key} = $value;
 	    }
 	}
     }
-- 
2.1.4





More information about the pve-devel mailing list