]> git.proxmox.com Git - pve-storage.git/commitdiff
Add write_config, drop cfs_read_file
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 25 Mar 2016 14:07:24 +0000 (15:07 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 30 Mar 2016 08:42:12 +0000 (10:42 +0200)
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
PVE/API2/Storage/Content.pm
PVE/API2/Storage/Status.pm
PVE/Storage.pm

index b9fdc0e24087719f854145c82157ad85037e9c84..4668af61169a45c46ebff4d83055d40de22fb35a 100755 (executable)
@@ -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");
 
index 03f9b26741797d4f2006a4a698f28867f023ba7a..47ef03b7c4df8ca845b0f1514e43e9abdc24f556 100644 (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
 
index 49bb58cb36198ea81f4a61c1625f74cc72023101..ddd2fa49b8da8451a9a4907e45fdf10ee76d1e34 100644 (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);
index 415301ace7788d7eedaa7c63fdf49e7d91060a2e..9d8c468d8a3d2a3eaa8334f3fe3e3e30d162afb6 100755 (executable)
@@ -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) = @_;