[pve-devel] [PATCH qemu 2/3] add sub for local disks check

Tim Marx t.marx at proxmox.com
Wed May 22 15:25:35 CEST 2019


Signed-off-by: Tim Marx <t.marx at proxmox.com>
---
 PVE/API2/Qemu.pm | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index a771a1a..fa4ff63 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -3141,6 +3141,51 @@ __PACKAGE__->register_method({
 	return PVE::QemuConfig->lock_config($vmid, $updatefn);
     }});
 
+my $check_vm_disks_local = sub {
+    my ($storecfg, $vmconf, $vmid) = @_;
+
+    my $local_disks = {};
+
+    my @sids = PVE::Storage::storage_ids($storecfg);
+
+    # check each storage for disks, even if they aren't referenced in VM config
+    foreach my $storeid (@sids) {
+	my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+	next if $scfg->{shared};
+	next if !PVE::Storage::storage_check_enabled($storecfg, $storeid, undef, 1);
+
+	# get list from PVE::Storage (for unused volumes)
+	my $dl = PVE::Storage::vdisk_list($storecfg, $storeid, $vmid);
+	next if @{$dl->{$storeid}} == 0;
+
+	PVE::Storage::foreach_volid($dl, sub {
+	    my ($volid, $sid, $volname) = @_;
+	    $local_disks->{$volid} = $volname;
+	});
+    }
+
+    # add some more information to the disks e.g. cdrom
+    PVE::QemuServer::foreach_volid($vmconf, sub {
+	my ($volid, $attr) = @_;
+
+	my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
+	if ($storeid) {
+	    my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+	    return if $scfg->{shared};
+	}
+	# The shared attr here is just a special case where the vdisk
+	# is marked as shared manually
+	return if $attr->{shared};
+	return if $attr->{cdrom} and $volid eq "none";
+
+	if (exists $local_disks->{$volid}) {
+	    @{$local_disks->{$volid}}{keys %$attr} = values %$attr
+	} else {
+	    $local_disks->{$volid} = $attr;
+	    # ensure volid is present in case it's needed
+	    $local_disks->{$volid}->{volid} = $volid;
+	}
+    });
 __PACKAGE__->register_method({
     name => 'migrate_vm',
     path => '{vmid}/migrate',
-- 
2.11.0




More information about the pve-devel mailing list