[pve-devel] r5460 - pve-cluster/trunk/data/perl

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Jan 28 10:21:52 CET 2011


Author: dietmar
Date: 2011-01-28 10:21:52 +0100 (Fri, 28 Jan 2011)
New Revision: 5460

Modified:
   pve-cluster/trunk/data/perl/Cluster.pm
Log:
mplement cache for qemu-server configs


Modified: pve-cluster/trunk/data/perl/Cluster.pm
===================================================================
--- pve-cluster/trunk/data/perl/Cluster.pm	2011-01-28 08:58:52 UTC (rev 5459)
+++ pve-cluster/trunk/data/perl/Cluster.pm	2011-01-28 09:21:52 UTC (rev 5460)
@@ -42,6 +42,7 @@
     'user.cfg' => 1,
     'priv/domains.cfg' => 1,
     'priv/shadow.cfg' => 1,
+    '/qemu-server/' => 1,
 };
 
 sub check_cfs_is_mounted {
@@ -429,28 +430,48 @@
     };
 }
 
-sub cfs_read_file {
-    my ($filename) = @_;
+my $ccache_read = sub {
+    my ($filename, $parser, $version) = @_;
 
-    my $info = $file_info->{$filename} || die "unknown file '$filename'";
-
-    my $parser = $info->{parser};
-
     $ccache->{$filename} = {} if !$ccache->{$filename};
 
     my $ci = $ccache->{$filename};
 
-    if (!$ci->{version} || $ci->{version} != $versions->{$filename}) {
+    if (!$ci->{version} || $ci->{version} != $version) {
 
 	my $data = get_config($filename);
 
 	$ci->{data} = &$parser("/etc/pve/$filename", $data);
-	$ci->{version} = $versions->{$filename};
+	$ci->{version} = $version;
     }
 
     my $res = ref($ci->{data}) ? dclone($ci->{data}) : $ci->{data};
 
     return $res;
+};
+
+sub cfs_read_file {
+    my ($filename) = @_;
+
+    my $version;
+    my $infotag;
+    if ($filename =~ m|^nodes/[^/]+/qemu-server/(\d+)\.conf$|) {
+	my $vmid = $1;
+	if ($vmlist && $vmlist->{ids} && $vmlist->{ids}->{$vmid}) {
+	    $version = $vmlist->{ids}->{$vmid}->{version};
+	}
+	$infotag = "/qemu-server/";
+    } else {
+	$infotag = $filename;
+	$version = $versions->{$filename};
+    }
+
+    my $info = $file_info->{$infotag} || 
+	die "unknown file type '$filename' (no parser registered)\n";
+
+    my $parser = $info->{parser};
+
+    return &$ccache_read($filename, $parser, $version);
 }
 
 sub cfs_write_file {



More information about the pve-devel mailing list