From 83d7192ff979cc25135191e3adc97dd6a679508c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Fri, 25 Mar 2016 15:07:24 +0100 Subject: [PATCH] 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. --- PVE/API2/Storage/Config.pm | 16 ++++++++-------- PVE/API2/Storage/Content.pm | 12 ++++++------ PVE/API2/Storage/Status.pm | 8 ++++---- PVE/Storage.pm | 8 +++++++- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/PVE/API2/Storage/Config.pm b/PVE/API2/Storage/Config.pm index b9fdc0e..4668af6 100755 --- a/PVE/API2/Storage/Config.pm +++ b/PVE/API2/Storage/Config.pm @@ -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"); diff --git a/PVE/API2/Storage/Content.pm b/PVE/API2/Storage/Content.pm index 03f9b26..47ef03b 100644 --- a/PVE/API2/Storage/Content.pm +++ b/PVE/API2/Storage/Content.pm @@ -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 diff --git a/PVE/API2/Storage/Status.pm b/PVE/API2/Storage/Status.pm index 49bb58c..ddd2fa4 100644 --- a/PVE/API2/Storage/Status.pm +++ b/PVE/API2/Storage/Status.pm @@ -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); diff --git a/PVE/Storage.pm b/PVE/Storage.pm index 415301a..9d8c468 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -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) = @_;