[pve-devel] r5461 - in qemu-server/pve2: . PVE PVE/API2/Qemu PVE/VZDump

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Jan 28 10:24:20 CET 2011


Author: dietmar
Date: 2011-01-28 10:24:20 +0100 (Fri, 28 Jan 2011)
New Revision: 5461

Modified:
   qemu-server/pve2/PVE/API2/Qemu/Config.pm
   qemu-server/pve2/PVE/API2/Qemu/Status.pm
   qemu-server/pve2/PVE/API2/Qemu/VNC.pm
   qemu-server/pve2/PVE/QemuServer.pm
   qemu-server/pve2/PVE/VZDump/QemuServer.pm
   qemu-server/pve2/qm
   qemu-server/pve2/qmigrate
Log:
cleanup for cluster filesystem


Modified: qemu-server/pve2/PVE/API2/Qemu/Config.pm
===================================================================
--- qemu-server/pve2/PVE/API2/Qemu/Config.pm	2011-01-28 09:21:52 UTC (rev 5460)
+++ qemu-server/pve2/PVE/API2/Qemu/Config.pm	2011-01-28 09:24:20 UTC (rev 5461)
@@ -7,7 +7,7 @@
 use PVE::SafeSyslog;
 use PVE::Tools qw(extract_param);
 use PVE::Exception qw(raise raise_param_exc);
-use PVE::INotify qw(read_file);
+use PVE::Storage;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RESTHandler;
 use PVE::QemuServer;
@@ -127,7 +127,7 @@
 	die "unable to create vm $vmid: config file already exists\n" 
 	    if -f $filename;
 	
-	my $storecfg = read_file('storagecfg');
+	my $storecfg = PVE::Storage::config(); 
 
 	&$resolve_cdrom_alias($param);
 
@@ -239,7 +239,7 @@
 
 	die "no options specified\n" if !$delete && !scalar(keys %$param);
 
-	my $storecfg = read_file('storagecfg');
+	my $storecfg = PVE::Storage::config(); 
 
 	&$resolve_cdrom_alias($param);
 
@@ -391,7 +391,7 @@
 	raise_param_exc({ skiplock => "Only root may use this option." }) 
 	    if $user ne 'root';
 
-	my $storecfg = read_file('storagecfg');
+	my $storecfg = PVE::Storage::config(); 
 
 	PVE::QemuServer::vm_destroy ($storecfg, $vmid, $skiplock);
 

Modified: qemu-server/pve2/PVE/API2/Qemu/Status.pm
===================================================================
--- qemu-server/pve2/PVE/API2/Qemu/Status.pm	2011-01-28 09:21:52 UTC (rev 5460)
+++ qemu-server/pve2/PVE/API2/Qemu/Status.pm	2011-01-28 09:24:20 UTC (rev 5461)
@@ -7,10 +7,10 @@
 use PVE::SafeSyslog;
 use PVE::Tools qw(extract_param);
 use PVE::Exception qw(raise raise_param_exc);
-use PVE::INotify qw(read_file);
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RESTHandler;
 use PVE::QemuServer;
+use PVE::Storage;
 use PVE::RPCEnvironment;
 
 use Data::Dumper; # fixme: remove
@@ -111,7 +111,7 @@
 
 	my $command = $param->{command};
 
-	my $storecfg = read_file('storagecfg');
+	my $storecfg = PVE::Storage::config(); 
 	
 	if ($command eq 'start') {
 	    my $statefile = undef; # fixme: --incoming parameter

Modified: qemu-server/pve2/PVE/API2/Qemu/VNC.pm
===================================================================
--- qemu-server/pve2/PVE/API2/Qemu/VNC.pm	2011-01-28 09:21:52 UTC (rev 5460)
+++ qemu-server/pve2/PVE/API2/Qemu/VNC.pm	2011-01-28 09:24:20 UTC (rev 5461)
@@ -6,7 +6,7 @@
 use PVE::SafeSyslog;
 use PVE::Tools qw(extract_param);
 use PVE::Exception qw(raise raise_param_exc);
-use PVE::INotify qw(read_file);
+use PVE::Cluster;
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RESTHandler;
 use PVE::QemuServer;

Modified: qemu-server/pve2/PVE/QemuServer.pm
===================================================================
--- qemu-server/pve2/PVE/QemuServer.pm	2011-01-28 09:21:52 UTC (rev 5460)
+++ qemu-server/pve2/PVE/QemuServer.pm	2011-01-28 09:24:20 UTC (rev 5461)
@@ -16,12 +16,13 @@
 use Cwd 'abs_path';
 use IPC::Open3;
 use Fcntl;
-use Sys::Syslog;
+use PVE::SafeSyslog;
 use Storable qw(dclone);
 use PVE::Exception qw(raise raise_param_exc);
 use PVE::Storage;
 use PVE::Tools qw(run_command lock_file file_read_firstline);
-use PVE::INotify qw(read_file);
+use PVE::Cluster qw(cfs_register_file cfs_read_file cfs_write_file cfs_lock_file);
+use PVE::INotify;
 use PVE::ProcFSTools;
 use Time::HiRes qw (gettimeofday);
 
@@ -32,9 +33,9 @@
 # Adiitionaly, we have a 'lock' setting in the config file. This
 # can be set to 'migrate' or 'backup'. Most actions are not
 # allowed when such lock is set. But you can ignore this kind of
-# lock wth the --skiplock flag.
+# lock with the --skiplock flag.
 
-PVE::INotify::register_regex('/etc/qemu-server', qr/\d+\.conf/, \&parse_config);
+cfs_register_file('/qemu-server/', \&parse_vm_config);  
 
 #no warnings 'redefine';
 
@@ -110,10 +111,17 @@
     return fairsched_rate ($id, $op, $cpulim1024);
 }
 
-my $confdir = '/etc/qemu-server';
+my $nodename = PVE::INotify::nodename();
 
+mkdir "/etc/pve/nodes/$nodename";
+my $confdir = "/etc/pve/nodes/$nodename/qemu-server";
+mkdir $confdir;
+
 my $var_run_tmpdir = "/var/run/qemu-server";
+mkdir $var_run_tmpdir;
+
 my $lock_dir = "/var/lock/qemu-server";
+mkdir $lock_dir;
 
 my $pcisysfs = "/sys/bus/pci";
 
@@ -510,6 +518,13 @@
 
 }
 
+sub disknames {
+    # order is important - used to autoselect boot disk
+    return ((map { "ide$_" } (0 .. ($MAX_IDE_DISKS - 1))),  
+            (map { "scsi$_" } (0 .. ($MAX_SCSI_DISKS - 1))),
+            (map { "virtio$_" } (0 .. ($MAX_VIRTIO_DISKS - 1))));
+}
+
 sub valid_drivename {
     my $dev = shift;
 
@@ -1043,10 +1058,17 @@
     die $@ if $@;
 }
 
+sub cfs_config_path {
+    my ($vmid) = @_;
+
+    return "nodes/$nodename/qemu-server/$vmid.conf";
+}
+
 sub config_file {
     my ($vmid) = @_;
 
-    return "$confdir/$vmid.conf";
+    my $cfspath = cfs_config_path($vmid);
+    return "/etc/pve/$cfspath";
 }
 
 sub config_file_lock {
@@ -1222,26 +1244,29 @@
 sub load_config {
     my ($vmid) = @_;
 
-    my $filename = config_file ($vmid);
+    my $cfspath = cfs_config_path($vmid);
 
-    my $conf = read_file($filename);
+    my $conf = PVE::Cluster::cfs_read_file($cfspath);
 
     die "no such VM ('$vmid')\n" if !defined($conf);
 
     return $conf;
 }  
 
-sub parse_config {
-    my ($filename, $fh, $storecfg) = @_;
+sub parse_vm_config {
+    my ($filename, $raw) = @_;
 
+    return undef if !defined($raw);
+
     my $res = {};
 
-    $filename =~ m|/(\d+)\.conf$| 
+    $filename =~ m|/qemu-server/(\d+)\.conf$| 
 	|| die "got strange filename '$filename'";
 
     my $vmid = $1;
 
-    while (my $line = <$fh>) {
+    while ($raw =~ s/^(.*)\n//) {
+	my $line = $1;
 	
 	next if $line =~ m/^\#/;
 
@@ -1260,8 +1285,8 @@
 	    } else {
 		my $fmt = $confdesc->{$key}->{format};
 		if ($fmt && $fmt eq 'pve-qm-drive') {
-		    my $v = parse_drive ($key, $value);
-		    if (my $volid = filename_to_volume_id ($vmid, $v->{file}, $v->{media})) {
+		    my $v = parse_drive($key, $value);
+		    if (my $volid = filename_to_volume_id($vmid, $v->{file}, $v->{media})) {
 			$v->{file} = $volid;
 			$value = print_drive ($vmid, $v);
 		    } else {
@@ -1297,11 +1322,13 @@
 sub change_config_nolock {
     my ($vmid, $settings, $unset, $skiplock) = @_;
 
+    die "not implemented - fixme";
+
     my $res = {};
 
     $unset->{ide2} = $unset->{cdrom} if $unset->{cdrom};
 
-    check_lock ($settings) if !$skiplock;
+    check_lock($settings) if !$skiplock;
 
     # we do not use 'smp' any longer
     if ($settings->{sockets}) {
@@ -1328,7 +1355,7 @@
 	}
     }
 
-    my $filename = config_file ($vmid);
+    my $filename = config_file($vmid);
     my $tmpfn = "$filename.$$.tmp";
 
     my $fh = new IO::File ($filename, "r") ||
@@ -1449,7 +1476,7 @@
 
 sub config_list {
 
-    my $fd = IO::Dir->new ($confdir);
+    my $fd = IO::Dir->new($confdir);
     my $res = {};
 
     return $res if !$fd;
@@ -1551,17 +1578,16 @@
     my $list =  vzlist();
     my ($uptime) = PVE::ProcFSTools::read_proc_uptime();
 
+    foreach my $vmid (keys %$list) {
+	my $cfspath = cfs_config_path($vmid);
+	my $conf = PVE::Cluster::cfs_read_file($cfspath) || {};
 
-    foreach my $veid (keys %$list) {
-	my $fn = config_file ($veid);
-	my $conf = read_file ($fn);
-
 	my $d = {};
 	$d->{type} = 'qemu';
 	$d->{nproc} = 0;
-	$d->{pid} = $list->{$veid}->{pid};
+	$d->{pid} = $list->{$vmid}->{pid};
 	# fixme: better status?
-	$d->{status} = $list->{$veid}->{pid} ? 'running' : 'stopped';
+	$d->{status} = $list->{$vmid}->{pid} ? 'running' : 'stopped';
 	$d->{ip} = '-';
 
 	# fixme: where to get disk info/usage ?
@@ -1569,7 +1595,7 @@
 	$d->{maxdisk} = 0;
 
 	$d->{cpus} = ($conf->{sockets} || 1) * ($conf->{cores} || 1);
-	$d->{name} = $conf->{name} || "VM$veid";
+	$d->{name} = $conf->{name} || "VM$vmid";
 	$d->{maxmem} = $conf->{memory} ? $conf->{memory} : 0; 
 
 
@@ -1578,7 +1604,7 @@
 	$d->{relcpu} = 0;
 	$d->{mem} = 0;
 
-	$res->{$veid} = $d;
+	$res->{$vmid} = $d;
 
     }
 
@@ -1586,9 +1612,9 @@
     my $cpucount = $cpuinfo->{cpus} || 1;
     my $ctime = gettimeofday;
 
-    foreach my $veid (keys %$list) {
+    foreach my $vmid (keys %$list) {
 
-	my $d = $res->{$veid};
+	my $d = $res->{$vmid};
 	my $pid = $d->{pid};
 	next if !$pid;
 

Modified: qemu-server/pve2/PVE/VZDump/QemuServer.pm
===================================================================
--- qemu-server/pve2/PVE/VZDump/QemuServer.pm	2011-01-28 09:21:52 UTC (rev 5460)
+++ qemu-server/pve2/PVE/VZDump/QemuServer.pm	2011-01-28 09:24:20 UTC (rev 5461)
@@ -25,7 +25,7 @@
 use File::Path;
 use File::Basename;
 use PVE::VZDump;
-use PVE::INotify qw(read_file);
+use PVE::Cluster;
 use PVE::Storage;
 use PVE::QemuServer;
 use Sys::Hostname;
@@ -41,7 +41,7 @@
     my $self = bless { vzdump => $vzdump };
 
     $self->{vmlist} = PVE::QemuServer::vzlist();
-    $self->{storecfg} = read_file('storagecfg');
+    $self->{storecfg} = PVE::Storage::config();
 
     return $self;
 };

Modified: qemu-server/pve2/qm
===================================================================
--- qemu-server/pve2/qm	2011-01-28 09:21:52 UTC (rev 5460)
+++ qemu-server/pve2/qm	2011-01-28 09:24:20 UTC (rev 5461)
@@ -10,7 +10,7 @@
 use PVE::Tools qw(extract_param);
 use PVE::Cluster;
 use PVE::SafeSyslog;
-use PVE::INotify qw(read_file);
+use PVE::INotify;
 use PVE::RPCEnvironment;
 use PVE::QemuServer;
 use PVE::API2::Qemu::Config;
@@ -37,7 +37,7 @@
 
 $rpcenv->set_user('root'); 
 
-my $hostname = PVE::INotify::nodename();
+my $nodename = PVE::INotify::nodename();
 
 sub run_vnc_proxy {
     my ($vmid) = @_;
@@ -95,8 +95,8 @@
     code => sub {
 	my ($param) = @_;
 
-	my $storecfg = read_file('storagecfg');
-	print PVE::QemuServer::vm_commandline ($storecfg, $param->{vmid}) . "\n";
+	my $storecfg = PVE::Storage::config();
+	print PVE::QemuServer::vm_commandline($storecfg, $param->{vmid}) . "\n";
 
 	return undef;
     }});
@@ -215,16 +215,16 @@
 	my ($param) = @_;
 
 	my $vzlist = PVE::QemuServer::vzlist();
-	my $storecfg = read_file('storagecfg');
+	my $storecfg = PVE::Storage::config();
 
 	foreach my $vmid (keys %$vzlist) {
 	    next if $vzlist->{$vmid}->{pid}; # already running
 
 	    eval {
-		my $conf = PVE::QemuServer::load_config ($vmid);
+		my $conf = PVE::QemuServer::load_config($vmid);
 		if ($conf->{onboot}) {
 		    print STDERR "Starting Qemu VM $vmid\n";
-		    PVE::QemuServer::vm_start ($storecfg, $vmid);
+		    PVE::QemuServer::vm_start($storecfg, $vmid);
 		}
 	    };
 	    print STDERR $@ if $@;
@@ -343,7 +343,7 @@
 
 my $cmddef = {
     list => [ "PVE::API2::Qemu::Config", 'vmlist', [],
-	     { node => $hostname }, sub {
+	     { node => $nodename }, sub {
 		 my $vmlist = shift;
 
 		 exit 0 if (!scalar(@$vmlist));
@@ -359,16 +359,16 @@
 		 
 	      } ],
 
-    create => [ "PVE::API2::Qemu::Config", 'create_vm', ['vmid'], { node => $hostname } ],
+    create => [ "PVE::API2::Qemu::Config", 'create_vm', ['vmid'], { node => $nodename } ],
 
-    destroy => [ "PVE::API2::Qemu::Config", 'destroy_vm', ['vmid'], { node => $hostname } ],
+    destroy => [ "PVE::API2::Qemu::Config", 'destroy_vm', ['vmid'], { node => $nodename } ],
 
-    set => [ "PVE::API2::Qemu::Config", 'update_vm', ['vmid'], { node => $hostname } ],
+    set => [ "PVE::API2::Qemu::Config", 'update_vm', ['vmid'], { node => $nodename } ],
 
-    unlink => [ "PVE::API2::Qemu::Config", 'unlink', ['vmid', 'idlist'], { node => $hostname } ],
+    unlink => [ "PVE::API2::Qemu::Config", 'unlink', ['vmid', 'idlist'], { node => $nodename } ],
 
     config => [ "PVE::API2::Qemu::Config", 'vm_config', ['vmid'], 
-		{ node => $hostname }, sub {
+		{ node => $nodename }, sub {
 		    my $config = shift;
 		    foreach my $k (sort (keys %$config)) {
 			my $v = $config->{$k};
@@ -396,17 +396,17 @@
 
 
     start => [ "PVE::API2::Qemu::Status", 'vm_command', ['vmid'], 
-	       { node => $hostname, command => 'start' } ],
+	       { node => $nodename, command => 'start' } ],
     stop => [ "PVE::API2::Qemu::Status", 'vm_command', ['vmid'], 
-	      { node => $hostname, command => 'stop' } ],
+	      { node => $nodename, command => 'stop' } ],
     reset => [ "PVE::API2::Qemu::Status", 'vm_command', ['vmid'], 
-	       { node => $hostname, command => 'reset' } ],
+	       { node => $nodename, command => 'reset' } ],
     suspend => [ "PVE::API2::Qemu::Status", 'vm_command', ['vmid'], 
-		 { node => $hostname, command => 'suspend' } ],
+		 { node => $nodename, command => 'suspend' } ],
     resume => [ "PVE::API2::Qemu::Status", 'vm_command', ['vmid'], 
-		{ node => $hostname, command => 'resume' } ],
+		{ node => $nodename, command => 'resume' } ],
     cad => [ "PVE::API2::Qemu::Status", 'vm_command', ['vmid'], 
-	     { node => $hostname, command => 'cad' } ],
+	     { node => $nodename, command => 'cad' } ],
 	
 };
 

Modified: qemu-server/pve2/qmigrate
===================================================================
--- qemu-server/pve2/qmigrate	2011-01-28 09:21:52 UTC (rev 5460)
+++ qemu-server/pve2/qmigrate	2011-01-28 09:24:20 UTC (rev 5461)
@@ -2,18 +2,23 @@
 
 use strict;
 use Getopt::Long;
-use Sys::Syslog;
+use PVE::SafeSyslog;
 use IO::Select;
 use IPC::Open3;
 use IPC::Open2;
-use PVE::INotify qw(read_file);
+use PVE::Cluster;
 use PVE::QemuServer;
 use PVE::Storage;
 use POSIX qw(strftime);
 
+# fimxe: adopt for new cluster filestem
+
+die "not implemented - fixme!";
+
 # fixme: kvm > 88 has more migration options and verbose status
 
-openlog ('qmigrate', 'cons,pid', 'daemon');
+initlog('qmigrate');
+PVE::Cluster::cfs_update();
 
 sub print_usage {
     my $msg = shift;
@@ -24,6 +29,7 @@
     exit (-1);
 }
 
+
 # fixme: bwlimit ?
 
 my $opt_online;
@@ -70,7 +76,7 @@
 logmsg ('err', "illegal VMID") if $vmid !~ m/^\d+$/;
 $vmid = int ($vmid); # remove leading zeros
 
-my $storecfg = read_file('storagecfg');
+my $storecfg = PVE::Storage::config(); 
 
 my $conffile = PVE::QemuServer::config_file ($vmid);
 



More information about the pve-devel mailing list