[pve-devel] r5015 - pve-storage/pve2
svn-commits at proxmox.com
svn-commits at proxmox.com
Mon Aug 16 13:49:19 CEST 2010
Author: dietmar
Date: 2010-08-16 11:49:19 +0000 (Mon, 16 Aug 2010)
New Revision: 5015
Modified:
pve-storage/pve2/Storage.pm
Log:
import safe_print
Modified: pve-storage/pve2/Storage.pm
===================================================================
--- pve-storage/pve2/Storage.pm 2010-08-16 11:48:13 UTC (rev 5014)
+++ pve-storage/pve2/Storage.pm 2010-08-16 11:49:19 UTC (rev 5015)
@@ -16,6 +16,7 @@
use Socket;
use Digest::SHA1;
use PVE::Tools qw(run_command lock_file);
+use PVE::INotify qw(register_file read_file write_file);
my $ISCSIADM = '/usr/bin/iscsiadm';
my $UDEVADM = '/sbin/udevadm';
@@ -28,21 +29,35 @@
# we need the cluster configuration for locking operations
-sub read_hostname {
+register_file ('hostname', "/etc/hostname",
+ \&read_etc_hostname,
+ \&write_etc_hostname);
- my $filename = "/etc/hostname";
+register_file ('clustercfg', "/etc/pve/cluster.cfg",
+ \&read_cluster_config);
- my $hostname = 'localhost';
+register_file ('storagecfg', "/etc/pve/storage.cfg",
+ \&parse_config, undef, undef,
+ always_call_parser => 1);
- if (my $fh = IO::File->new ($filename, 'r')) {
- $hostname = <$fh>;
- chomp $hostname;
- close $fh;
- }
+sub read_etc_hostname {
+ my ($filename, $fd) = @_;
+ my $hostname = <$fd>;
+
+ chomp $hostname;
+
return $hostname;
}
+sub write_etc_hostname {
+ my ($filename, $fh, $hostname) = @_;
+
+ print $fh "$hostname\n";
+
+ return $hostname;
+}
+
sub read_cluster_config {
my ($filename, $fh) = @_;
@@ -127,7 +142,7 @@
$cinfo->{"CID_$ni->{cid}"} = $ni;
}
- my $hostname = read_hostname();
+ my $hostname = read_file('hostname');
$cinfo->{local} = {
role => '-',
@@ -430,6 +445,8 @@
my $sha1 = Digest::SHA1->new;
+ # returns defaults if !$fh;
+
my $pri = 0;
while ($fh && defined (my $line = <$fh>)) {
$sha1->add ($line); # compute digest
@@ -620,20 +637,6 @@
return $cfg;
}
-sub load_cluster_config {
-
- my $cfg;
-
- my $filename = "/etc/pve/cluster.cfg";
-
- if (my $fh = IO::File->new ($filename, 'r')) {
- $cfg = read_cluster_config ($filename, $fh);
- $fh->close();
- }
-
- return $cfg;
-}
-
sub fork_command_pipe {
my ($cmd) = @_;
@@ -713,7 +716,7 @@
sub cluster_lock_storage {
my ($storeid, $shared, $timeout, $func, @param) = @_;
- my $ccfg = load_cluster_config();
+ my $ccfg = read_file('clustercfg');
my $masterip = $ccfg && $ccfg->{master} ? $ccfg->{master}->{ip} : undef;
More information about the pve-devel
mailing list