]> git.proxmox.com Git - qemu-server.git/commitdiff
Switch to using foreach_volume instead of foreach_drive
authorFabian Ebner <f.ebner@proxmox.com>
Wed, 8 Apr 2020 09:24:56 +0000 (11:24 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 8 Apr 2020 20:11:54 +0000 (22:11 +0200)
It was necessary to move foreach_volid back to QemuServer.pm

In VZDump/QemuServer.pm and QemuMigrate.pm the dependency on
QemuConfig.pm was already there, just the explicit "use" was missing.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/API2/Qemu.pm
PVE/QemuConfig.pm
PVE/QemuMigrate.pm
PVE/QemuServer.pm
PVE/QemuServer/Cloudinit.pm
PVE/QemuServer/Drive.pm
PVE/VZDump/QemuServer.pm

index b22093427aa2a55e948f685bcfffabf853e72174..87fbd72aaff7789d7da5f4b7569eceb9aa454078 100644 (file)
@@ -63,7 +63,7 @@ my $NEW_DISK_RE = qr!^(([^/:\s]+):)?(\d+(\.\d+)?)$!;
 my $check_storage_access = sub {
    my ($rpcenv, $authuser, $storecfg, $vmid, $settings, $default_storage) = @_;
 
-   PVE::QemuServer::foreach_drive($settings, sub {
+   PVE::QemuConfig->foreach_volume($settings, sub {
        my ($ds, $drive) = @_;
 
        my $isCDROM = PVE::QemuServer::drive_is_cdrom($drive);
@@ -96,7 +96,7 @@ my $check_storage_access_clone = sub {
 
    my $sharedvm = 1;
 
-   PVE::QemuServer::foreach_drive($conf, sub {
+   PVE::QemuConfig->foreach_volume($conf, sub {
        my ($ds, $drive) = @_;
 
        my $isCDROM = PVE::QemuServer::drive_is_cdrom($drive);
@@ -216,7 +216,7 @@ my $create_disks = sub {
        }
     };
 
-    eval { PVE::QemuServer::foreach_drive($settings, $code); };
+    eval { PVE::QemuConfig->foreach_volume($settings, $code); };
 
     # free allocated images on error
     if (my $err = $@) {
index d29b88b518cdd47c54c72525418aaff207e54938..78f5c60f6775bd03b6f82d540e9cc14031741e9a 100644 (file)
@@ -66,7 +66,7 @@ sub has_feature {
     my ($class, $feature, $conf, $storecfg, $snapname, $running, $backup_only) = @_;
 
     my $err;
-    PVE::QemuServer::foreach_drive($conf, sub {
+    $class->foreach_volume($conf, sub {
        my ($ds, $drive) = @_;
 
        return if PVE::QemuServer::drive_is_cdrom($drive);
index e83d60d9b04b64b7ed7bef978cb760e5dd42ffec..2925b90d14320db71d8c812921879d24906fb38c 100644 (file)
@@ -17,6 +17,7 @@ use PVE::ReplicationState;
 use PVE::Storage;
 use PVE::Tools;
 
+use PVE::QemuConfig;
 use PVE::QemuServer::CPUConfig;
 use PVE::QemuServer::Drive;
 use PVE::QemuServer::Helpers qw(min_version);
@@ -477,7 +478,7 @@ sub sync_disks {
                }
 
                my $live_replicatable_volumes = {};
-               PVE::QemuServer::foreach_drive($conf, sub {
+               PVE::QemuConfig->foreach_volume($conf, sub {
                    my ($ds, $drive) = @_;
 
                    my $volid = $drive->{file};
@@ -508,7 +509,7 @@ sub sync_disks {
        # sizes in config have to be accurate for remote node to correctly
        # allocate disks, rescan to be sure
        my $volid_hash = PVE::QemuServer::scan_volids($storecfg, $vmid);
-       PVE::QemuServer::foreach_drive($conf, sub {
+       PVE::QemuConfig->foreach_volume($conf, sub {
            my ($key, $drive) = @_;
            my ($updated, $old_size, $new_size) = PVE::QemuServer::Drive::update_disksize($drive, $volid_hash);
            if (defined($updated)) {
index 038d1d86936ff74b697d4afb3dcf80822e79802d..de477e1a185db6d6dfe9f3f5ff6ee34c870c5503 100644 (file)
@@ -44,7 +44,7 @@ use PVE::QemuConfig;
 use PVE::QemuServer::Helpers qw(min_version config_aware_timeout);
 use PVE::QemuServer::Cloudinit;
 use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options);
-use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit drive_is_cdrom parse_drive print_drive foreach_drive foreach_volid);
+use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit drive_is_cdrom parse_drive print_drive);
 use PVE::QemuServer::Machine;
 use PVE::QemuServer::Memory;
 use PVE::QemuServer::Monitor qw(mon_cmd);
@@ -2038,7 +2038,7 @@ sub destroy_vm {
 
     if ($conf->{template}) {
        # check if any base image is still used by a linked clone
-       foreach_drive($conf, sub {
+       PVE::QemuConfig->foreach_volume($conf, sub {
                my ($ds, $drive) = @_;
                return if drive_is_cdrom($drive);
 
@@ -2052,7 +2052,7 @@ sub destroy_vm {
     }
 
     # only remove disks owned by this VM
-    foreach_drive($conf, sub {
+    PVE::QemuConfig->foreach_volume($conf, sub {
        my ($ds, $drive) = @_;
        return if drive_is_cdrom($drive, 1);
 
@@ -2341,7 +2341,7 @@ sub check_local_resources {
 sub check_storage_availability {
     my ($storecfg, $conf, $node) = @_;
 
-    foreach_drive($conf, sub {
+    PVE::QemuConfig->foreach_volume($conf, sub {
        my ($ds, $drive) = @_;
 
        my $volid = $drive->{file};
@@ -2364,7 +2364,7 @@ sub shared_nodes {
     my $nodehash = { map { $_ => 1 } @$nodelist };
     my $nodename = nodename();
 
-    foreach_drive($conf, sub {
+    PVE::QemuConfig->foreach_volume($conf, sub {
        my ($ds, $drive) = @_;
 
        my $volid = $drive->{file};
@@ -2396,7 +2396,7 @@ sub check_local_storage_availability {
     my $nodelist = PVE::Cluster::get_nodelist();
     my $nodehash = { map { $_ => {} } @$nodelist };
 
-    foreach_drive($conf, sub {
+    PVE::QemuConfig->foreach_volume($conf, sub {
        my ($ds, $drive) = @_;
 
        my $volid = $drive->{file};
@@ -3464,7 +3464,7 @@ sub config_to_command {
        push @$devices, '-iscsi', "initiator-name=$initiator";
     }
 
-    foreach_drive($conf, sub {
+    PVE::QemuConfig->foreach_volume($conf, sub {
        my ($ds, $drive) = @_;
 
        if (PVE::Storage::parse_volume_id($drive->{file}, 1)) {
@@ -4250,7 +4250,7 @@ sub qemu_volume_snapshot_delete {
 
        $running = undef;
        my $conf = PVE::QemuConfig->load_config($vmid);
-       foreach_drive($conf, sub {
+       PVE::QemuConfig->foreach_volume($conf, sub {
            my ($ds, $drive) = @_;
            $running = 1 if $drive->{file} eq $volid;
        });
@@ -4288,6 +4288,52 @@ sub set_migration_caps {
     mon_cmd($vmid, "migrate-set-capabilities", capabilities => $cap_ref);
 }
 
+sub foreach_volid {
+    my ($conf, $func, @param) = @_;
+
+    my $volhash = {};
+
+    my $test_volid = sub {
+       my ($volid, $is_cdrom, $replicate, $shared, $snapname, $size) = @_;
+
+       return if !$volid;
+
+       $volhash->{$volid}->{cdrom} //= 1;
+       $volhash->{$volid}->{cdrom} = 0 if !$is_cdrom;
+
+       $volhash->{$volid}->{replicate} //= 0;
+       $volhash->{$volid}->{replicate} = 1 if $replicate;
+
+       $volhash->{$volid}->{shared} //= 0;
+       $volhash->{$volid}->{shared} = 1 if $shared;
+
+       $volhash->{$volid}->{referenced_in_config} //= 0;
+       $volhash->{$volid}->{referenced_in_config} = 1 if !defined($snapname);
+
+       $volhash->{$volid}->{referenced_in_snapshot}->{$snapname} = 1
+           if defined($snapname);
+       $volhash->{$volid}->{size} = $size if $size;
+    };
+
+    PVE::QemuConfig->foreach_volume($conf, sub {
+       my ($ds, $drive) = @_;
+       $test_volid->($drive->{file}, drive_is_cdrom($drive), $drive->{replicate} // 1, $drive->{shared}, undef, $drive->{size});
+    });
+
+    foreach my $snapname (keys %{$conf->{snapshots}}) {
+       my $snap = $conf->{snapshots}->{$snapname};
+       $test_volid->($snap->{vmstate}, 0, 1, $snapname);
+       PVE::QemuConfig->foreach_volume($snap, sub {
+           my ($ds, $drive) = @_;
+           $test_volid->($drive->{file}, drive_is_cdrom($drive), $drive->{replicate} // 1, $drive->{shared}, $snapname);
+        });
+    }
+
+    foreach my $volid (keys %$volhash) {
+       &$func($volid, $volhash->{$volid}, @param);
+    }
+}
+
 my $fast_plug_option = {
     'lock' => 1,
     'name' => 1,
@@ -4747,7 +4793,7 @@ sub vm_migrate_get_nbd_disks {
     my ($storecfg, $conf, $replicated_volumes) = @_;
 
     my $local_volumes = {};
-    foreach_drive($conf, sub {
+    PVE::QemuConfig->foreach_volume($conf, sub {
        my ($ds, $drive) = @_;
 
        return if drive_is_cdrom($drive);
@@ -5606,7 +5652,7 @@ sub restore_file_archive {
 my $restore_cleanup_oldconf = sub {
     my ($storecfg, $vmid, $oldconf, $virtdev_hash) = @_;
 
-    foreach_drive($oldconf, sub {
+    PVE::QemuConfig->foreach_volume($oldconf, sub {
        my ($ds, $drive) = @_;
 
        return if drive_is_cdrom($drive, 1);
@@ -6476,7 +6522,7 @@ sub foreach_storage_used_by_vm {
 
     my $sidhash = {};
 
-    foreach_drive($conf, sub {
+    PVE::QemuConfig->foreach_volume($conf, sub {
        my ($ds, $drive) = @_;
        return if drive_is_cdrom($drive);
 
@@ -6527,7 +6573,7 @@ sub template_create {
 
     my $storecfg = PVE::Storage::config();
 
-    foreach_drive($conf, sub {
+    PVE::QemuConfig->foreach_volume($conf, sub {
        my ($ds, $drive) = @_;
 
        return if drive_is_cdrom($drive);
index 559f331f53cac3cc4e1f63fd40749e52f3b45eb1..b3ae57b11bdceaef514d2b2ee73652dc5bf8915a 100644 (file)
@@ -466,7 +466,7 @@ sub generate_cloudinitconfig {
 
     my $format = get_cloudinit_format($conf);
 
-    PVE::QemuServer::foreach_drive($conf, sub {
+    PVE::QemuConfig->foreach_volume($conf, sub {
         my ($ds, $drive) = @_;
 
        my ($storeid, $volname) = PVE::Storage::parse_volume_id($drive->{file}, 1);
index a08df668a20f6ccc5017cd6d404967f8b61c5853..f84333f5b2ea5ccd0802f0001ecc9d9269f9906c 100644 (file)
@@ -14,8 +14,6 @@ drive_is_cloudinit
 drive_is_cdrom
 parse_drive
 print_drive
-foreach_drive
-foreach_volid
 );
 
 our $QEMU_FORMAT_RE = qr/raw|cow|qcow|qcow2|qed|vmdk|cloop/;
@@ -503,65 +501,6 @@ sub print_drive {
     return PVE::JSONSchema::print_property_string($drive, $alldrive_fmt, $skip);
 }
 
-sub foreach_drive {
-    my ($conf, $func, @param) = @_;
-
-    foreach my $ds (valid_drive_names()) {
-       next if !defined($conf->{$ds});
-
-       my $drive = parse_drive($ds, $conf->{$ds});
-       next if !$drive;
-
-       &$func($ds, $drive, @param);
-    }
-}
-
-sub foreach_volid {
-    my ($conf, $func, @param) = @_;
-
-    my $volhash = {};
-
-    my $test_volid = sub {
-       my ($volid, $is_cdrom, $replicate, $shared, $snapname, $size) = @_;
-
-       return if !$volid;
-
-       $volhash->{$volid}->{cdrom} //= 1;
-       $volhash->{$volid}->{cdrom} = 0 if !$is_cdrom;
-
-       $volhash->{$volid}->{replicate} //= 0;
-       $volhash->{$volid}->{replicate} = 1 if $replicate;
-
-       $volhash->{$volid}->{shared} //= 0;
-       $volhash->{$volid}->{shared} = 1 if $shared;
-
-       $volhash->{$volid}->{referenced_in_config} //= 0;
-       $volhash->{$volid}->{referenced_in_config} = 1 if !defined($snapname);
-
-       $volhash->{$volid}->{referenced_in_snapshot}->{$snapname} = 1
-           if defined($snapname);
-       $volhash->{$volid}->{size} = $size if $size;
-    };
-
-    foreach_drive($conf, sub {
-       my ($ds, $drive) = @_;
-       $test_volid->($drive->{file}, drive_is_cdrom($drive), $drive->{replicate} // 1, $drive->{shared}, undef, $drive->{size});
-    });
-
-    foreach my $snapname (keys %{$conf->{snapshots}}) {
-       my $snap = $conf->{snapshots}->{$snapname};
-       $test_volid->($snap->{vmstate}, 0, 1, $snapname);
-       foreach_drive($snap, sub {
-           my ($ds, $drive) = @_;
-           $test_volid->($drive->{file}, drive_is_cdrom($drive), $drive->{replicate} // 1, $drive->{shared}, $snapname);
-        });
-    }
-
-    foreach my $volid (keys %$volhash) {
-       &$func($volid, $volhash->{$volid}, @param);
-    }
-}
-
 sub bootdisk_size {
     my ($storecfg, $conf) = @_;
 
index 08c29ba074feafc3cd42366e13d95c85993609d3..38dcdb111a42427971e4cfa47635eec48530d134 100644 (file)
@@ -19,6 +19,7 @@ use PVE::Storage;
 use PVE::Tools;
 use PVE::VZDump;
 
+use PVE::QemuConfig;
 use PVE::QemuServer;
 use PVE::QemuServer::Machine;
 use PVE::QemuServer::Monitor qw(mon_cmd);
@@ -68,7 +69,7 @@ sub prepare {
 
     my $vollist = [];
     my $drivehash = {};
-    PVE::QemuServer::foreach_drive($conf, sub {
+    PVE::QemuConfig->foreach_volume($conf, sub {
        my ($ds, $drive) = @_;
 
        return if PVE::QemuServer::drive_is_cdrom($drive);