]> git.proxmox.com Git - qemu-server.git/commitdiff
vm_start: condense signature
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Mon, 30 Mar 2020 11:41:30 +0000 (13:41 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 1 Apr 2020 15:42:15 +0000 (17:42 +0200)
as preparation for refactoring it further. remote migration will add
another 1-2 parameters, and it is already unwieldly enough as it is.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
PVE/API2/Qemu.pm
PVE/QemuConfig.pm
PVE/QemuServer.pm
PVE/VZDump/QemuServer.pm
test/snapshot-test.pm

index 396879a5555542b61fb2e2d265f6c7bd6459cb91..788db9392dfb0418fc5cfdd870655f3eec969510 100644 (file)
@@ -2114,9 +2114,24 @@ __PACKAGE__->register_method({
 
                syslog('info', "start VM $vmid: $upid\n");
 
-               PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock, $migratedfrom, undef, $machine,
-                                         $spice_ticket, $migration_network, $migration_type, $targetstorage, $timeout,
-                                         $nbd_protocol_version, $replicated_volumes);
+               my $migrate_opts = {
+                   migratedfrom => $migratedfrom,
+                   spice_ticket => $spice_ticket,
+                   network => $migration_network,
+                   type => $migration_type,
+                   targetstorage => $targetstorage,
+                   nbd_proto_version => $nbd_protocol_version,
+                   replicated_volumes => $replicated_volumes,
+               };
+
+               my $params = {
+                   statefile => $stateuri,
+                   skiplock => $skiplock,
+                   forcemachine => $machine,
+                   timeout => $timeout,
+               };
+
+               PVE::QemuServer::vm_start($storecfg, $vmid, $params, $migrate_opts);
                return;
            };
 
@@ -2584,7 +2599,7 @@ __PACKAGE__->register_method({
                PVE::QemuServer::vm_resume($vmid, $skiplock, $nocheck);
            } else {
                my $storecfg = PVE::Storage::config();
-               PVE::QemuServer::vm_start($storecfg, $vmid, undef, $skiplock);
+               PVE::QemuServer::vm_start($storecfg, $vmid, { skiplock => $skiplock });
            }
 
            return;
index 63220896ac3fa9a846f5e0b068cf0f6e0126ee0c..f32618efc99965ddc21721aad3be006c34fa29c6 100644 (file)
@@ -392,7 +392,11 @@ sub __snapshot_rollback_vm_start {
     my ($class, $vmid, $vmstate, $data) = @_;
 
     my $storecfg = PVE::Storage::config();
-    PVE::QemuServer::vm_start($storecfg, $vmid, $vmstate, undef, undef, undef, $data->{forcemachine});
+    my $params = {
+       statefile => $vmstate,
+       forcemachine => $data->{forcemachine},
+    };
+    PVE::QemuServer::vm_start($storecfg, $vmid, $params);
 }
 
 sub __snapshot_rollback_get_unused {
index daab7acb9bdaaa0a473e6899e037db891a3f854e..55602f50f7818bf4d949cd05aabca6a58eac796e 100644 (file)
@@ -4709,12 +4709,30 @@ sub vmconfig_update_disk {
     vm_deviceplug($storecfg, $conf, $vmid, $opt, $drive, $arch, $machine_type);
 }
 
+# params:
+#   statefile => 'tcp', 'unix' for migration or path/volid for RAM state
+#   skiplock => 0/1, skip checking for config lock
+#   forcemachine => to force Qemu machine (rollback/migration)
+#   timeout => in seconds
+#   paused => start VM in paused state (backup)
+# migrate_opts:
+#   migratedfrom => source node
+#   spice_ticket => used for spice migration, passed via tunnel/stdin
+#   network => CIDR of migration network
+#   type => secure/insecure - tunnel over encrypted connection or plain-text
+#   targetstorage = storageid/'1' - target storage for disks migrated over NBD
+#   nbd_proto_version => int, 0 for TCP, 1 for UNIX
+#   replicated_volumes = which volids should be re-used with bitmaps for nbd migration
 sub vm_start {
-    my ($storecfg, $vmid, $statefile, $skiplock, $migratedfrom, $paused,
-       $forcemachine, $spice_ticket, $migration_network, $migration_type,
-       $targetstorage, $timeout, $nbd_protocol_version, $replicated_volumes) = @_;
+    my ($storecfg, $vmid, $params, $migrate_opts) = @_;
 
     PVE::QemuConfig->lock_config($vmid, sub {
+       my $statefile = $params->{statefile};
+
+       my $migratedfrom = $migrate_opts->{migratedfrom};
+       my $migration_type = $migrate_opts->{type};
+       my $targetstorage = $migrate_opts->{targetstorage};
+
        my $conf = PVE::QemuConfig->load_config($vmid, $migratedfrom);
 
        die "you can't start a vm if it's a template\n" if PVE::QemuConfig->is_template($conf);
@@ -4722,7 +4740,7 @@ sub vm_start {
        my $is_suspended = PVE::QemuConfig->has_lock($conf, 'suspended');
 
        PVE::QemuConfig->check_lock($conf)
-           if !($skiplock || $is_suspended);
+           if !($params->{skiplock} || $is_suspended);
 
        die "VM $vmid already running\n" if check_running($vmid, undef, $migratedfrom);
 
@@ -4766,7 +4784,7 @@ sub vm_start {
            foreach my $opt (sort keys %$local_volumes) {
 
                my ($volid, $storeid, $volname) = @{$local_volumes->{$opt}};
-               if ($replicated_volumes->{$volid}) {
+               if ($migrate_opts->{replicated_volumes}->{$volid}) {
                    # re-use existing, replicated volume with bitmap on source side
                    $local_volumes->{$opt} = $conf->{${opt}};
                    print "re-using replicated volume: $opt - $volid\n";
@@ -4801,6 +4819,7 @@ sub vm_start {
 
        PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'pre-start', 1);
 
+       my $forcemachine = $params->{forcemachine};
        if ($is_suspended) {
            # enforce machine type on suspended vm to ensure HW compatibility
            $forcemachine = $conf->{runningmachine};
@@ -4811,10 +4830,12 @@ sub vm_start {
 
        my $migration_ip;
        my $get_migration_ip = sub {
-           my ($cidr, $nodename) = @_;
+           my ($nodename) = @_;
 
            return $migration_ip if defined($migration_ip);
 
+           my $cidr = $migrate_opts->{network};
+
            if (!defined($cidr)) {
                my $dc_conf = PVE::Cluster::cfs_read_file('datacenter.cfg');
                $cidr = $dc_conf->{migration}->{network};
@@ -4854,7 +4875,7 @@ sub vm_start {
                }
 
                if ($migration_type eq 'insecure') {
-                   $localip = $get_migration_ip->($migration_network, $nodename);
+                   $localip = $get_migration_ip->($nodename);
                    $localip = "[$localip]" if Net::IP::ip_is_ipv6($localip);
                }
 
@@ -4883,7 +4904,7 @@ sub vm_start {
                push @$vollist, $statefile;
                push @$cmd, '-loadstate', $statepath;
            }
-       } elsif ($paused) {
+       } elsif ($params->{paused}) {
            push @$cmd, '-S';
        }
 
@@ -4924,7 +4945,7 @@ sub vm_start {
        my $cpuunits = defined($conf->{cpuunits}) ? $conf->{cpuunits}
                                                  : $defaults->{cpuunits};
 
-       my $start_timeout = $timeout // config_aware_timeout($conf, $is_suspended);
+       my $start_timeout = $params->{timeout} // config_aware_timeout($conf, $is_suspended);
        my %run_params = (
            timeout => $statefile ? undef : $start_timeout,
            umask => 0077,
@@ -4996,7 +5017,7 @@ sub vm_start {
 
        #start nbd server for storage migration
        if ($targetstorage) {
-           $nbd_protocol_version //= 0;
+           my $nbd_protocol_version = $migrate_opts->{nbd_proto_version} // 0;
 
            my $migrate_storage_uri;
            # nbd_protocol_version > 0 for unix socket support
@@ -5006,7 +5027,7 @@ sub vm_start {
                $migrate_storage_uri = "nbd:unix:$socket_path";
            } else {
                my $nodename = nodename();
-               my $localip = $get_migration_ip->($migration_network, $nodename);
+               my $localip = $get_migration_ip->($nodename);
                my $pfamily = PVE::Tools::get_host_address_family($nodename);
                my $storage_migrate_port = PVE::Tools::next_migrate_port($pfamily);
 
@@ -5030,8 +5051,8 @@ sub vm_start {
 
            if ($spice_port) {
                print "spice listens on port $spice_port\n";
-               if ($spice_ticket) {
-                   mon_cmd($vmid, "set_password", protocol => 'spice', password => $spice_ticket);
+               if ($migrate_opts->{spice_ticket}) {
+                   mon_cmd($vmid, "set_password", protocol => 'spice', password => $migrate_opts->{spice_ticket});
                    mon_cmd($vmid, "expire_password", protocol => 'spice', time => "+30");
                }
            }
index 35a5d21e2226f57b6a1d16b59db029a84c294989..08c29ba074feafc3cd42366e13d95c85993609d3 100644 (file)
@@ -676,7 +676,11 @@ sub enforce_vm_running_for_backup {
     eval {
        $self->loginfo("starting kvm to execute backup task");
        # start with skiplock
-       PVE::QemuServer::vm_start($self->{storecfg}, $vmid, undef, 1, undef, 1);
+       my $params = {
+           skiplock => 1,
+           paused => 1,
+       };
+       PVE::QemuServer::vm_start($self->{storecfg}, $vmid, $params);
     };
     die $@ if $@;
 }
index ee9fc13f53752b3d8735c4c53a64ed8f7fb68ce6..f79db6b473887fa590685a780a48fd5843a003d9 100644 (file)
@@ -356,13 +356,13 @@ sub do_snapshots_with_qemu {
 }
 
 sub vm_start {
-    my ($storecfg, $vmid, $statefile, $skiplock, $migratedfrom, $paused, $forcemachine) = @_;
+    my ($storecfg, $vmid, $params, $migrate_opts) = @_;
 
     die "Storage config not mocked! aborting\n"
        if defined($storecfg);
 
     die "statefile and forcemachine must be both defined or undefined! aborting\n"
-       if defined($statefile) xor defined($forcemachine);
+       if defined($params->{statefile}) xor defined($params->{forcemachine});
 
     return;
 }