Add write_config, drop cfs_read_file

Use PVE::Storage::config() and the new
PVE::Storage::write_config() instead of cfs_read_file and
cfs_write_file with a hardcoded filename.
This commit is contained in:
Fabian Grünbichler
2016-03-25 15:07:24 +01:00
committed by Dietmar Maurer
parent 59ca7928cf
commit 83d7192ff9
4 changed files with 25 additions and 19 deletions

View File

@ -70,7 +70,7 @@ __PACKAGE__->register_method ({
my $rpcenv = PVE::RPCEnvironment::get();
my $authuser = $rpcenv->get_user();
my $cfg = cfs_read_file("storage.cfg");
my $cfg = PVE::Storage::config();
my @sids = PVE::Storage::storage_ids($cfg);
@ -105,7 +105,7 @@ __PACKAGE__->register_method ({
code => sub {
my ($param) = @_;
my $cfg = cfs_read_file("storage.cfg");
my $cfg = PVE::Storage::config();
return &$api_storage_config($cfg, $param->{storage});
}});
@ -137,7 +137,7 @@ __PACKAGE__->register_method ({
PVE::Storage::lock_storage_config(
sub {
my $cfg = cfs_read_file('storage.cfg');
my $cfg = PVE::Storage::config();
if (my $scfg = PVE::Storage::storage_config($cfg, $storeid, 1)) {
die "storage ID '$storeid' already defined\n";
@ -170,7 +170,7 @@ __PACKAGE__->register_method ({
PVE::Storage::activate_storage($cfg, $storeid);
}
cfs_write_file('storage.cfg', $cfg);
PVE::Storage::write_config($cfg);
}, "create storage failed");
@ -197,7 +197,7 @@ __PACKAGE__->register_method ({
PVE::Storage::lock_storage_config(
sub {
my $cfg = cfs_read_file('storage.cfg');
my $cfg = PVE::Storage::config();
PVE::SectionConfig::assert_if_modified($cfg, $digest);
@ -210,7 +210,7 @@ __PACKAGE__->register_method ({
$scfg->{$k} = $opts->{$k};
}
cfs_write_file('storage.cfg', $cfg);
PVE::Storage::write_config($cfg);
}, "update storage failed");
@ -243,7 +243,7 @@ __PACKAGE__->register_method ({
PVE::Storage::lock_storage_config(
sub {
my $cfg = cfs_read_file('storage.cfg');
my $cfg = PVE::Storage::config();
die "storage '$storeid' does not exist\n"
if !($cfg->{ids}->{$storeid});
@ -253,7 +253,7 @@ __PACKAGE__->register_method ({
delete $cfg->{ids}->{$storeid};
cfs_write_file('storage.cfg', $cfg);
PVE::Storage::write_config($cfg);
}, "delete storage failed");

View File

@ -5,7 +5,7 @@ use warnings;
use Data::Dumper;
use PVE::SafeSyslog;
use PVE::Cluster qw(cfs_read_file);
use PVE::Cluster;
use PVE::Storage;
use PVE::INotify;
use PVE::Exception qw(raise_param_exc);
@ -66,7 +66,7 @@ __PACKAGE__->register_method ({
my $storeid = $param->{storage};
my $cfg = cfs_read_file("storage.cfg");
my $cfg = PVE::Storage::config();
my $vollist = PVE::Storage::volume_list($cfg, $storeid, $param->{vmid}, $param->{content});
@ -150,7 +150,7 @@ __PACKAGE__->register_method ({
$param->{format} = $fmt;
}
my $cfg = cfs_read_file('storage.cfg');
my $cfg = PVE::Storage::config();
my $volid = PVE::Storage::vdisk_alloc ($cfg, $storeid, $param->{vmid},
$param->{format},
@ -217,7 +217,7 @@ __PACKAGE__->register_method ({
my ($volid, $storeid) = &$real_volume_id($param->{storage}, $param->{volume});
my $cfg = cfs_read_file('storage.cfg');
my $cfg = PVE::Storage::config();
$rpcenv->check_volume_access($authuser, $cfg, undef, $volid);
@ -267,7 +267,7 @@ __PACKAGE__->register_method ({
my $rpcenv = PVE::RPCEnvironment::get();
my $authuser = $rpcenv->get_user();
my $cfg = cfs_read_file('storage.cfg');
my $cfg = PVE::Storage::config();
my ($volid, $storeid) = &$real_volume_id($param->{storage}, $param->{volume});
@ -331,7 +331,7 @@ __PACKAGE__->register_method ({
print "DEBUG: COPY $src_volid TO $dst_volid\n";
my $cfg = cfs_read_file('storage.cfg');
my $cfg = PVE::Storage::config();
# do all parameter checks first

View File

@ -7,7 +7,7 @@ use File::Path;
use File::Basename;
use PVE::Tools;
use PVE::INotify;
use PVE::Cluster qw(cfs_read_file);
use PVE::Cluster;
use PVE::Storage;
use PVE::API2::Storage::Content;
use PVE::RESTHandler;
@ -85,7 +85,7 @@ __PACKAGE__->register_method ({
undef $target if $target && ($target eq $localnode || $target eq 'localhost');
my $cfg = cfs_read_file("storage.cfg");
my $cfg = PVE::Storage::config();
my $info = PVE::Storage::storage_info($cfg, $param->{content});
@ -182,7 +182,7 @@ __PACKAGE__->register_method ({
code => sub {
my ($param) = @_;
my $cfg = cfs_read_file("storage.cfg");
my $cfg = PVE::Storage::config();
my $info = PVE::Storage::storage_info($cfg, $param->{content});
@ -323,7 +323,7 @@ __PACKAGE__->register_method ({
my $user = $rpcenv->get_user();
my $cfg = cfs_read_file("storage.cfg");
my $cfg = PVE::Storage::config();
my $node = $param->{node};
my $scfg = PVE::Storage::storage_check_enabled($cfg, $param->{storage}, $node);

View File

@ -13,7 +13,7 @@ use Cwd 'abs_path';
use Socket;
use PVE::Tools qw(run_command file_read_firstline $IPV6RE);
use PVE::Cluster qw(cfs_read_file cfs_lock_file);
use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file);
use PVE::Exception qw(raise_param_exc);
use PVE::JSONSchema;
use PVE::INotify;
@ -56,6 +56,12 @@ sub config {
return cfs_read_file("storage.cfg");
}
sub write_config {
my ($cfg) = @_;
cfs_write_file('storage.cfg', $cfg);
}
sub lock_storage_config {
my ($code, $errmsg) = @_;