]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/QemuServer.pm
remove $vmid param from print_drive
[qemu-server.git] / PVE / QemuServer.pm
index 5cf04e6ae6be9cdb6934c5982cc5b97efa5a58b5..e10461f11ae1f5cb39fc04ed4922deec7858a811 100644 (file)
@@ -1751,7 +1751,7 @@ sub parse_drive {
 }
 
 sub print_drive {
-    my ($vmid, $drive) = @_;
+    my ($drive) = @_;
     my $data = { %$drive };
     delete $data->{$_} for qw(index interface);
     return PVE::JSONSchema::print_property_string($data, $alldrive_fmt);
@@ -2246,13 +2246,9 @@ sub parse_hostpci {
     my @idlist = split(/;/, $res->{host});
     delete $res->{host};
     foreach my $id (@idlist) {
-       if ($id =~ m/\./) { # full id 00:00.1
-           push @{$res->{pciid}}, {
-               id => $id,
-           };
-       } else { # partial id 00:00
-           $res->{pciid} = PVE::SysFSTools::lspci($id);
-       }
+       my $devs = PVE::SysFSTools::lspci($id);
+       die "no PCI device found for '$id'\n" if !scalar(@$devs);
+       push @{$res->{pciid}}, @$devs;
     }
     return $res;
 }
@@ -2667,7 +2663,7 @@ sub parse_vm_config {
                    my $v = parse_drive($key, $value);
                    if (my $volid = filename_to_volume_id($vmid, $v->{file}, $v->{media})) {
                        $v->{file} = $volid;
-                       $value = print_drive($vmid, $v);
+                       $value = print_drive($v);
                    } else {
                        warn "vm $vmid - unable to parse value of '$key'\n";
                        next;
@@ -5267,7 +5263,7 @@ sub vm_start {
                my $newdrive = $drive;
                $newdrive->{format} = $format;
                $newdrive->{file} = $newvolid;
-               my $drivestr = PVE::QemuServer::print_drive($vmid, $newdrive);
+               my $drivestr = print_drive($newdrive);
                $local_volumes->{$opt} = $drivestr;
                #pass drive to conf for command line
                $conf->{$opt} = $drivestr;
@@ -5369,7 +5365,6 @@ sub vm_start {
          my $pcidevices = $d->{pciid};
          foreach my $pcidevice (@$pcidevices) {
                my $pciid = $pcidevice->{id};
-               $pciid = "0000:$pciid" if $pciid !~ m/^[0-9a-f]{4}:/;
 
                my $info = PVE::SysFSTools::pci_device_info("$pciid");
                die "IOMMU not present\n" if !PVE::SysFSTools::check_iommu_support();
@@ -5506,11 +5501,13 @@ sub vm_start {
                    property => "guest-stats-polling-interval",
                    value => 2) if (!defined($conf->{balloon}) || $conf->{balloon});
 
-       if ($is_suspended && (my $vmstate = $conf->{vmstate})) {
+       if ($is_suspended) {
            print "Resumed VM, removing state\n";
+           if (my $vmstate = $conf->{vmstate}) {
+               PVE::Storage::deactivate_volumes($storecfg, [$vmstate]);
+               PVE::Storage::vdisk_free($storecfg, $vmstate);
+           }
            delete $conf->@{qw(lock vmstate runningmachine)};
-           PVE::Storage::deactivate_volumes($storecfg, [$vmstate]);
-           PVE::Storage::vdisk_free($storecfg, $vmstate);
            PVE::QemuConfig->write_config($vmid, $conf);
        }
 
@@ -5974,7 +5971,7 @@ sub restore_update_config_line {
        } elsif ($map->{$virtdev}) {
            delete $di->{format}; # format can change on restore
            $di->{file} = $map->{$virtdev};
-           $value = print_drive($vmid, $di);
+           $value = print_drive($di);
            print $outfd "$virtdev: $value\n";
        } else {
            print $outfd $line;
@@ -6088,7 +6085,7 @@ sub update_disksize {
            next if !$volid_hash->{$volid};
 
            $drive->{size} = $volid_hash->{$volid}->{size};
-           my $new = print_drive($vmid, $drive);
+           my $new = print_drive($drive);
            if ($new ne $conf->{$opt}) {
                $changes = 1;
                $conf->{$opt} = $new;
@@ -6686,7 +6683,7 @@ sub template_create {
 
        my $voliddst = PVE::Storage::vdisk_create_base($storecfg, $volid);
        $drive->{file} = $voliddst;
-       $conf->{$ds} = print_drive($vmid, $drive);
+       $conf->{$ds} = print_drive($drive);
        PVE::QemuConfig->write_config($vmid, $conf);
     });
 }
@@ -6720,7 +6717,7 @@ sub qemu_img_convert {
     my $cachemode;
     my $src_path;
     my $src_is_iscsi = 0;
-    my $src_format = 'raw';
+    my $src_format;
 
     if ($src_storeid) {
        PVE::Storage::activate_volumes($storecfg, [$src_volid], $snapname);
@@ -6745,14 +6742,15 @@ sub qemu_img_convert {
 
     my $cmd = [];
     push @$cmd, '/usr/bin/qemu-img', 'convert', '-p', '-n';
-    push @$cmd, '-l', "snapshot.name=$snapname" if($snapname && $src_format eq "qcow2");
+    push @$cmd, '-l', "snapshot.name=$snapname"
+       if $snapname && $src_format && $src_format eq "qcow2";
     push @$cmd, '-t', 'none' if $dst_scfg->{type} eq 'zfspool';
     push @$cmd, '-T', $cachemode if defined($cachemode);
 
     if ($src_is_iscsi) {
        push @$cmd, '--image-opts';
        $src_path = convert_iscsi_path($src_path);
-    } else {
+    } elsif ($src_format) {
        push @$cmd, '-f', $src_format;
     }
 
@@ -7076,8 +7074,9 @@ sub create_efidisk($$$$$) {
     PVE::Storage::activate_volumes($storecfg, [$volid]);
 
     qemu_img_convert($ovmf_vars, $volid, $vars_size_b, undef, 0);
+    my ($size) = PVE::Storage::volume_size_info($storecfg, $volid, 3);
 
-    return ($volid, $vars_size);
+    return ($volid, $size/1024);
 }
 
 sub vm_iothreads_list {