]> git.proxmox.com Git - qemu-server.git/commitdiff
migrate: fix warning about uninitialized values
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 13 Jul 2012 10:37:19 +0000 (12:37 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 13 Jul 2012 10:37:19 +0000 (12:37 +0200)
And display acurate byte values instead of KB

PVE/QemuMigrate.pm

index 85566c3b1ac3a10a8553c2bfe40178adf47db063..b0059c37ceef7f9267526cc215c741a12e37e813 100644 (file)
@@ -329,28 +329,13 @@ sub phase2 {
     };
     my $merr = $@;
 
-    my $lstat = undef;
+    my $lstat = 0;
     while (1) {
        sleep (2);
        my $stat = PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "query-migrate");
-       
        if ($stat->{status} =~ m/^(active|completed|failed|cancelled)$/im) {
            $merr = undef;
 
-           if ($stat->{ram}->{transferred} ne $lstat) {
-               if ($stat->{status} eq 'active') {
-                   my ($trans, $rem, $total) = (0, 0, 0);
-                   $trans = sprintf "%.2f", $stat->{ram}->{transferred}/1024 if $stat->{ram}->{transferred};
-                   $rem = sprintf "%.2f", $stat->{ram}->{remaining}/1024 if $stat->{ram}->{remaining};
-                   $total = sprintf "%.2f", $stat->{ram}->{total}/1024 if $stat->{ram}->{total};
-
-                   $self->log('info', "migration status: $stat->{status} (transferred ${trans}KB, " .
-                              "remaining ${rem}KB), total ${total}KB)");
-               } else {
-                   $self->log('info', "migration status: $stat->{status}");
-               }
-           }
-
            if ($stat->{status} eq 'completed') {
                my $delay = time() - $start;
                if ($delay > 0) {
@@ -363,13 +348,27 @@ sub phase2 {
                die "aborting\n"
            }
 
-           last if $stat->{status} ne 'active';
+           if ($stat->{status} ne 'active') {
+               $self->log('info', "migration status: $stat->{status}");
+               last;
+           }
+
+           if ($stat->{ram}->{transferred} ne $lstat) {
+               my $trans = $stat->{ram}->{transferred} || 0;
+               my $rem = $stat->{ram}->{remaining} || 0;
+               my $total = $stat->{ram}->{total} || 0;
+
+               $self->log('info', "migration status: $stat->{status} (transferred ${trans}, " .
+                          "remaining ${rem}), total ${total})");
+           }
+
+           $lstat = $stat->{ram}->{transferred};
+
        } else {
            die $merr if $merr;
            die "unable to parse migration status '$stat->{status}' - aborting\n";
        }
-       $lstat = $lstat->{ram}->{transferred};
-    };
+    }
 }
 
 sub phase3 {