[pve-devel] [PATCH manager v2 2/2] vzdump: whitespace and style cleanup, typo fix

Philip Abernethy p.abernethy at proxmox.com
Thu Sep 14 12:03:46 CEST 2017


Mostly whitespace fixes, a stray semicolon, some style fixes and a
grammar correction
---
 PVE/VZDump.pm | 111 ++++++++++++++++++++++++++++------------------------------
 1 file changed, 53 insertions(+), 58 deletions(-)

diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index c6a4b449..844a9449 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -242,10 +242,10 @@ sub storage_info {
     my $cfg = PVE::Storage::config();
     my $scfg = PVE::Storage::storage_config($cfg, $storage);
     my $type = $scfg->{type};
- 
-    die "can't use storage type '$type' for backup\n" 
+
+    die "can't use storage type '$type' for backup\n"
 	if (!($type eq 'dir' || $type eq 'nfs' || $type eq 'glusterfs'));
-    die "can't use storage '$storage' for backups - wrong content type\n" 
+    die "can't use storage '$storage' for backups - wrong content type\n"
 	if (!$scfg->{content}->{backup});
 
     PVE::Storage::activate_storage($cfg, $storage);
@@ -272,7 +272,7 @@ sub format_size {
     } else {
 	my $gb = $mb / 1024;
 	return sprintf ("%.2fGB", $gb);
-    } 
+    }
 }
 
 sub format_time {
@@ -331,7 +331,6 @@ sub check_vmids {
     return $res;
 }
 
-
 sub read_vzdump_defaults {
 
     my $fn = "/etc/vzdump.conf";
@@ -339,7 +338,7 @@ sub read_vzdump_defaults {
     my $defaults = {
 	map {
 	    my $default = $confdesc->{$_}->{default};
-	     defined($default) ? ($_ => $default) : ()
+	    defined($default) ? ($_ => $default) : ()
 	} keys %$confdesc
     };
 
@@ -413,15 +412,15 @@ sub sendmail {
 	if  ($task->{state} eq 'ok') {
 
 	    $text .= sprintf ("%-10s %-6s %10s %10s  %s\n", $vmid,
-				$task->{state},
-				format_time($task->{backuptime}),
-				format_size ($task->{size}),
-				$task->{tarfile});
+		$task->{state},
+		format_time($task->{backuptime}),
+		format_size ($task->{size}),
+		$task->{tarfile});
 	} else {
 	    $text .= sprintf ("%-10s %-6s %10s %8.2fMB  %s\n", $vmid,
-				$task->{state},
-				format_time($task->{backuptime}),
-				0, '-');
+		$task->{state},
+		format_time($task->{backuptime}),
+		0, '-');
 	}
     }
 
@@ -460,19 +459,19 @@ sub sendmail {
 	    $ssize += $task->{size};
 
 	    $html .= sprintf ("<tr><td>%s<td>%s<td>OK<td>%s<td align=right>%s<td>%s</tr>\n",
-				$vmid, $name,
-				format_time($task->{backuptime}),
-				format_size ($task->{size}),
-				escape_html ($task->{tarfile}));
+		$vmid, $name,
+		format_time($task->{backuptime}),
+		format_size ($task->{size}),
+		escape_html ($task->{tarfile}));
 	} else {
 	    $html .= sprintf ("<tr><td>%s<td>%s<td><font color=red>FAILED<td>%s<td colspan=2>%s</tr>\n",
-				$vmid, $name, format_time($task->{backuptime}),
-				escape_html ($task->{msg}));
+		$vmid, $name, format_time($task->{backuptime}),
+		escape_html ($task->{msg}));
 	}
     }
 
     $html .= sprintf ("<tr><td align=left colspan=3>TOTAL<td>%s<td>%s<td></tr>",
- format_time ($totaltime), format_size ($ssize));
+	format_time ($totaltime), format_size ($ssize));
 
     $html .= "</table><br><br>\n";
     $html .= "Detailed backup logs:<br /><br />\n";
@@ -491,7 +490,7 @@ sub sendmail {
 	while (my $line = <TMP>) {
 	    if ($line =~ m/^\S+\s\d+\s+\d+:\d+:\d+\s+(ERROR|WARN):/) {
 		$html .= encode8bit ("$vmid: <font color=red>".
-				       escape_html ($line) . "</font>");
+		    escape_html ($line) . "</font>");
 	    } else {
 		$html .= encode8bit ("$vmid: " . escape_html ($line));
 	    }
@@ -509,7 +508,7 @@ sub sendmail {
     my $mailfrom = $dcconf->{email_from} || "root";
 
     PVE::Tools::sendmail($mailto, $subject, $text, $html, $mailfrom, "vzdump backup tool");
-};
+}
 
 sub new {
     my ($class, $cmdline, $opts, $skiplist) = @_;
@@ -564,9 +563,7 @@ sub new {
     }
 
     if ($opts->{stdexcludes}) {
-	push @$findexcl, '/tmp/?*',
-	                 '/var/tmp/?*',
-	                 '/var/run/?*.pid';
+	push @$findexcl, '/tmp/?*', '/var/tmp/?*', '/var/run/?*.pid';
     }
 
     foreach my $p (@plugins) {
@@ -597,7 +594,7 @@ sub new {
     } elsif ($opts->{stdout}) {
 	# Nothing to do here. We don't handle what comes after stdout
     } else {
-	die "internal error"; 
+	die "internal error";
     }
 
     if ($opts->{tmpdir} && ! -d $opts->{tmpdir}) {
@@ -648,9 +645,9 @@ sub getlock {
     my ($self, $upid) = @_;
 
     my $fh;
-	    
+
     my $maxwait = $self->{opts}->{lockwait} || $self->{lockwait};
- 
+
     die "missimg UPID" if !$upid; # should not happen
 
     if (!open (SERVER_FLCK, ">>$lockfile")) {
@@ -669,7 +666,7 @@ sub getlock {
 
 	eval {
 	    alarm ($maxwait * 60);
-	
+
 	    local $SIG{ALRM} = sub { alarm (0); die "got timeout\n"; };
 
 	    if (!flock (SERVER_FLCK, LOCK_EX)) {
@@ -681,9 +678,9 @@ sub getlock {
 	    alarm (0);
 	};
 	alarm (0);
-    
+
 	my $err = $@;
-	
+
 	if ($err) {
 	    debugmsg ('err', "can't aquire lock '$lockfile' - $err", undef, 1);
 	    die "can't aquire lock '$lockfile' - $err";
@@ -758,17 +755,17 @@ sub get_backup_file_list {
 
     return $bklist;
 }
- 
+
 sub exec_backup_task {
     my ($self, $task) = @_;
-	 
+
     my $opts = $self->{opts};
 
     my $vmid = $task->{vmid};
     my $plugin = $task->{plugin};
 
     my $vmstarttime = time ();
-    
+
     my $logfd;
 
     my $cleanup = {};
@@ -794,19 +791,19 @@ sub exec_backup_task {
 	my $lt = localtime();
 
 	my $bkname = "vzdump-$vmtype-$vmid";
-	my $basename = sprintf "${bkname}-%04d_%02d_%02d-%02d_%02d_%02d", 
-	$lt->year + 1900, $lt->mon + 1, $lt->mday, 
+	my $basename = sprintf "${bkname}-%04d_%02d_%02d-%02d_%02d_%02d",
+	    $lt->year + 1900, $lt->mon + 1, $lt->mday,
 	$lt->hour, $lt->min, $lt->sec;
 
 	my $maxfiles = $opts->{maxfiles};
 
 	if ($maxfiles && !$opts->{remove}) {
 	    my $bklist = get_backup_file_list($opts->{dumpdir}, $bkname);
-	    die "only $maxfiles backup(s) allowed - please consider to remove old backup files.\n" 
+	    die "only $maxfiles backup(s) allowed - please consider removing old backup files.\n"
 		if scalar(@$bklist) >= $maxfiles;
 	}
 
-	my $logfile = $task->{logfile} = "$opts->{dumpdir}/$basename.log";
+	my $logfile = $task->{logfile} = !$opts->{stdout} ? "$opts->{dumpdir}/$basename.log" : undef;
 
 	my $ext = $vmtype eq 'qemu' ? '.vma' : '.tar';
 	my ($comp, $comp_ext) = compressor_info($opts);
@@ -826,17 +823,17 @@ sub exec_backup_task {
 	$task->{vmtype} = $vmtype;
 
 	if ($opts->{tmpdir}) {
-	    $task->{tmpdir} = "$opts->{tmpdir}/vzdumptmp$$"; 
+	    $task->{tmpdir} = "$opts->{tmpdir}/vzdumptmp$$";
 	} else {
 	    # dumpdir is posix? then use it as temporary dir
 	    my $info = get_mount_info($opts->{dumpdir});
-	    if ($vmtype eq 'qemu' || 
+	    if ($vmtype eq 'qemu' ||
 		grep ($_ eq $info->{fstype}, @posix_filesystems)) {
 		$task->{tmpdir} = "$opts->{dumpdir}/$basename.tmp";
 	    } else {
 		$task->{tmpdir} = "/var/tmp/vzdumptmp$$";
 		debugmsg ('info', "filesystem type on dumpdir is '$info->{fstype}' -" .
-			  "using $task->{tmpdir} for temporary files", $logfd);
+		    "using $task->{tmpdir} for temporary files", $logfd);
 	    }
 	}
 
@@ -880,7 +877,7 @@ sub exec_backup_task {
 		debugmsg ('info',  $err, $logfd);
 		debugmsg ('info',  "trying 'suspend' mode instead", $logfd);
 		$mode = 'suspend'; # so prepare is called again below
-		%$task = %saved_task; 
+		%$task = %saved_task;
 	    }
 	}
 
@@ -888,7 +885,7 @@ sub exec_backup_task {
 
 	$task->{mode} = $mode;
 
-   	debugmsg ('info', "backup mode: $mode", $logfd);
+	debugmsg ('info', "backup mode: $mode", $logfd);
 
 	debugmsg ('info', "bandwidth limit: $opts->{bwlimit} KB/s", $logfd)
 	    if $opts->{bwlimit};
@@ -908,7 +905,6 @@ sub exec_backup_task {
 		$plugin->stop_vm ($task, $vmid);
 		$cleanup->{restart} = 1;
 	    }
- 
 
 	} elsif ($mode eq 'suspend') {
 
@@ -939,7 +935,7 @@ sub exec_backup_task {
 		my $delay = time () - $vmstoptime;
 		debugmsg('info', "vm is online again after $delay seconds", $logfd);
 	    }
-	    
+
 	} elsif ($mode eq 'snapshot') {
 
 	    $self->run_hook_script ('backup-start', $task, $logfd);
@@ -975,8 +971,8 @@ sub exec_backup_task {
 
 	# assemble archive image
 	$plugin->assemble ($task, $vmid);
-	
-	# produce archive 
+
+	# produce archive
 
 	if ($opts->{stdout}) {
 	    debugmsg ('info', "sending archive to stdout", $logfd);
@@ -993,7 +989,7 @@ sub exec_backup_task {
 
 	# determine size
 	$task->{size} = (-s $task->{tarfile}) || 0;
-	my $cs = format_size ($task->{size}); 
+	my $cs = format_size ($task->{size});
 	debugmsg ('info', "archive file size: $cs", $logfd);
 
 	# purge older backup
@@ -1033,8 +1029,8 @@ sub exec_backup_task {
 	eval { $plugin->set_logfd (undef); };
 	warn $@ if $@;
 
-	if ($cleanup->{resume} || $cleanup->{restart}) {	
-	    eval { 
+	if ($cleanup->{resume} || $cleanup->{restart}) {
+	    eval {
 		$self->run_hook_script ('pre-restart', $task, $logfd);
 		if ($cleanup->{resume}) {
 		    debugmsg ('info', "resume vm", $logfd);
@@ -1080,7 +1076,7 @@ sub exec_backup_task {
     }
 
     close ($logfd) if $logfd;
-    
+
     if ($task->{tmplog} && $task->{logfile}) {
 	system {'cp'} 'cp', $task->{tmplog}, $task->{logfile};
     }
@@ -1098,7 +1094,7 @@ sub exec_backup {
     debugmsg ('info', "starting new backup job: $self->{cmdline}", undef, 1);
     debugmsg ('info', "skip external VMs: " . join(', ', @{$self->{skiplist}}))
 	if scalar(@{$self->{skiplist}});
- 
+
     my $tasklist = [];
 
     if ($opts->{all}) {
@@ -1107,7 +1103,7 @@ sub exec_backup {
 	    foreach my $vmid (sort @$vmlist) {
 		next if grep { $_ eq  $vmid } @{$opts->{exclude}};
 		next if !$rpcenv->check($authuser, "/vms/$vmid", [ 'VM.Backup' ], 1);
-	        push @$tasklist, { vmid => $vmid,  state => 'todo', plugin => $plugin, mode => $opts->{mode} };
+		push @$tasklist, { vmid => $vmid,  state => 'todo', plugin => $plugin, mode => $opts->{mode} };
 	    }
 	}
     } else {
@@ -1168,12 +1164,11 @@ sub exec_backup {
 
     die $err if $err;
 
-    die "job errors\n" if $errcount; 
+    die "job errors\n" if $errcount;
 
     unlink $pidfile;
 }
 
-
 sub option_exists {
     my $key = shift;
     return defined($confdesc->{$key});
@@ -1202,7 +1197,7 @@ sub verify_vzdump_parameters {
     $param->{all} = 1 if defined($param->{exclude});
 
     warn "option 'size' is deprecated and will be removed in a future " .
-	 "release, please update your script/configuration!\n"
+	"release, please update your script/configuration!\n"
 	if defined($param->{size});
 
     return if !$check_missing;
@@ -1220,7 +1215,7 @@ sub stop_running_backups {
 
     my $task = PVE::Tools::upid_decode($upid);
 
-    if (PVE::ProcFSTools::check_process_running($task->{pid}, $task->{pstart}) && 
+    if (PVE::ProcFSTools::check_process_running($task->{pid}, $task->{pstart}) &&
 	PVE::ProcFSTools::read_proc_starttime($task->{pid}) == $task->{pstart}) {
 	kill(15, $task->{pid});
 	# wait max 15 seconds to shut down (else, do nothing for now)
@@ -1244,7 +1239,7 @@ sub command_line {
 
     foreach my $p (keys %$param) {
 	next if $p eq 'id' || $p eq 'vmid' || $p eq 'starttime' ||
-	        $p eq 'dow' || $p eq 'stdout' || $p eq 'enabled';
+	    $p eq 'dow' || $p eq 'stdout' || $p eq 'enabled';
 	my $v = $param->{$p};
 	my $pd = $confdesc->{$p} || die "no such vzdump option '$p'\n";
 	if ($p eq 'exclude-path') {
-- 
2.11.0





More information about the pve-devel mailing list