[pve-devel] r5065 - qemu-server/pve2

svn-commits at proxmox.com svn-commits at proxmox.com
Thu Aug 26 13:13:31 CEST 2010


Author: dietmar
Date: 2010-08-26 11:13:31 +0000 (Thu, 26 Aug 2010)
New Revision: 5065

Modified:
   qemu-server/pve2/ChangeLog
   qemu-server/pve2/Makefile
   qemu-server/pve2/QemuServer.pm
Log:
* QemuServer.pm: use new libpve-common-perl


Modified: qemu-server/pve2/ChangeLog
===================================================================
--- qemu-server/pve2/ChangeLog	2010-08-26 10:44:32 UTC (rev 5064)
+++ qemu-server/pve2/ChangeLog	2010-08-26 11:13:31 UTC (rev 5065)
@@ -1,3 +1,7 @@
+2010-08-26  Proxmox Support Team  <support at proxmox.com>
+
+	* QemuServer.pm: use new libpve-common-perl
+
 2010-08-20  Proxmox Support Team  <support at proxmox.com>
 
 	* qmigrate (phase2): abort if migration status is 'failed'

Modified: qemu-server/pve2/Makefile
===================================================================
--- qemu-server/pve2/Makefile	2010-08-26 10:44:32 UTC (rev 5064)
+++ qemu-server/pve2/Makefile	2010-08-26 11:13:31 UTC (rev 5065)
@@ -88,7 +88,7 @@
 	dpkg-deb --build debian	
 	mv debian.deb ${DEB}
 	rm -rf debian
-	lintian ${DEB}
+	-lintian ${DEB}
 
 .PHONY: upload
 upload:

Modified: qemu-server/pve2/QemuServer.pm
===================================================================
--- qemu-server/pve2/QemuServer.pm	2010-08-26 10:44:32 UTC (rev 5064)
+++ qemu-server/pve2/QemuServer.pm	2010-08-26 11:13:31 UTC (rev 5065)
@@ -18,6 +18,8 @@
 use Fcntl;
 use Sys::Syslog;
 use PVE::Storage;
+use PVE::Tools qw(run_command lock_file);
+use PVE::INotify qw(read_file);
 
 # Note about locking: we use flock on the config file protect 
 # against concurent actions.
@@ -26,6 +28,8 @@
 # allowed when such lock is set. But you can ignore this kind of
 # lock wth the --skiplock flag.
 
+PVE::INotify::register_regex('/etc/qemu-server', qr/\d+\.conf/, \&parse_config);
+
 #no warnings 'redefine';
 
 unless(defined(&_VZSYSCALLS_H_)) {
@@ -270,6 +274,7 @@
 
 # a clumsy way to split an argument string into an array,
 # we simply pass it to the cli (exec call)
+# fixme: use Text::ParseWords::shellwords() ?
 sub split_args {
     my ($str) = @_;
 
@@ -280,7 +285,7 @@
     my $cmd = 'perl -e \'foreach my $a (@ARGV) { print "$a\n"; } \' -- ' . $str;
 
     eval {
-	PVE::Storage::run_command ($cmd, outfunc => sub {
+	run_command ($cmd, outfunc => sub {
 	    my $data = shift;
 	    push @$args, $data;
 	});
@@ -341,7 +346,7 @@
 
     bless ($self, $class);
 
-    $storecfg = PVE::Storage::load_config() if !$storecfg;
+    $storecfg = read_file('storagecfg') if !$storecfg;
 
     $self->{storecfg} = $storecfg;
 
@@ -455,12 +460,6 @@
     return $settings;
 }
 
-#sub create_conf {
-#    my ($vmid, $settings) = @_;
-#
-#    lock_config ($vmid, &create_conf_nolock, $settings);
-#}
-
 sub create_conf_nolock {
     my ($self, $vmid, $settings) = @_;
 
@@ -710,63 +709,9 @@
 
     my $filename = config_file_lock ($vmid);
 
-    lock_file ($filename, "VM $vmid", $code, @param);
-}
+    lock_file($filename, 10, "VM $vmid", $code, @param);
 
-# flock: we use one file handle per process, so lock file
-# can be called multiple times and succeeds for the same process.
-
-my $lock_handles =  {};
-
-sub lock_file {
-    my ($filename, $text, $code, @param) = @_;
-
-    my $timeout = 10;
-
-    my $res;
-
-    eval {
-
-	local $SIG{ALRM} = sub { die "got timeout\n"; };
-
-	alarm ($timeout);
-
-	if (!$lock_handles->{$$}->{$filename}) {
-	    $lock_handles->{$$}->{$filename} = new IO::File (">>$filename") ||
-		die "can't open lock for $text '$filename' - $!\n";
-	}
-
-	if (!flock ($lock_handles->{$$}->{$filename}, LOCK_EX|LOCK_NB)) {
-	    print STDERR "trying to aquire lock...";
-	    if (!flock ($lock_handles->{$$}->{$filename}, LOCK_EX)) {
-		print STDERR " failed\n";
-		die "can't aquire lock for $text '$filename' - $!\n";
-	    }
-	    print STDERR " OK\n";
-	}
-	alarm (0);
-
-	$res = &$code (@param);
-    };
-
-    my $err = $@;
-
-    alarm (0);
-
-    if ($lock_handles->{$$}->{$filename}) {
-	my $fh = $lock_handles->{$$}->{$filename};
-	$lock_handles->{$$}->{$filename} = undef;
-	close ($fh);
-    }
-
-    if ($err) {
-	$@ = $err;
-	return undef;
-    }
-
-    $@ = undef;
-
-    return $res;
+    die $@ if $@;
 }
 
 sub config_file {
@@ -900,11 +845,7 @@
 
     my $filename = config_file ($vmid);
 
-    my $fh = new IO::File ($filename, "r") ||
-	die "unable to read config for VM $vmid\n";
- 
-
-    return parse_config ($filename, $fh, $self->{storecfg});
+    return read_file($filename);
 }  
 
 sub parse_config {
@@ -985,8 +926,6 @@
     my ($vmid, $settings, $unset, $skiplock) = @_;
 
     lock_config ($vmid, &change_config_nolock, $settings, $unset, $skiplock);
-
-    die $@ if $@;
 }
 
 sub change_config_nolock {
@@ -1579,7 +1518,7 @@
 
 	$self->activate_volumes ($conf);
 
-	eval  { PVE::Storage::run_command ($cmd, timeout => $migrate_uri ? undef : 30); };
+	eval  { run_command ($cmd, timeout => $migrate_uri ? undef : 30); };
 
 	my $err = $@;
 
@@ -1612,8 +1551,6 @@
 	    eval { $self->vm_monitor_command ($vmid, $cmd, 1); };
 	}
     });
-
-    die $@ if $@;
 }
 
 sub __read_avail {
@@ -1758,8 +1695,6 @@
 
 	$self->vm_monitor_command ($vmid, "system_reset", 1);
     });
-    
-    die $@ if $@;
 }
 
 sub vm_wait {
@@ -1794,8 +1729,6 @@
 
 	$self->vm_monitor_command ($vmid, "system_powerdown", 1);
     });
-
-    die $@ if $@;
 }
 
 sub vm_stop {
@@ -1855,8 +1788,6 @@
 
 	fairsched_rmnod ($vmid); # try to destroy group
     });
-
-    die $@ if $@;
 }
 
 sub vm_suspend {
@@ -1872,8 +1803,6 @@
 
 	$self->vm_monitor_command ($vmid, "stop", 1);
     });
-
-    die $@ if $@;
 }
 
 sub vm_resume {
@@ -1889,8 +1818,6 @@
 
 	$self->vm_monitor_command ($vmid, "cont", 1);
     });
-
-    die $@ if $@;
 }
 
 sub vm_cad {
@@ -1906,8 +1833,6 @@
     
 	$self->vm_monitor_command ($vmid, "sendkey ctrl-alt-delete", 1);
     });
-
-    die $@ if $@;
 }
 
 sub vm_cdrom {
@@ -1962,8 +1887,6 @@
 	    $self->vm_monitor_command ($vmid, "change $qdn \"$path\"", 1);
 	}
     });
-
-    die $@ if $@;
 }
 
 sub vm_destroy {
@@ -1993,8 +1916,6 @@
 	    die $err;
 	}
     });
-
-    die $@ if $@;
 }
 
 sub vm_startall {



More information about the pve-devel mailing list