[pve-devel] [PATCH storage 2/2] register ceph.conf parser/writer

Dominik Csapak d.csapak at proxmox.com
Wed Dec 19 11:24:40 CET 2018


With this we can use cfs_read_file/cfs_write_file and cfs_lock_file.

Code for writing is mostly copied from pve-managers CephTools.pm,
with the addition of mgr sections.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/CephConfig.pm | 60 +++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 54 insertions(+), 6 deletions(-)

diff --git a/PVE/CephConfig.pm b/PVE/CephConfig.pm
index c851ea2..5b2d19e 100644
--- a/PVE/CephConfig.pm
+++ b/PVE/CephConfig.pm
@@ -4,16 +4,18 @@ use strict;
 use warnings;
 use Net::IP;
 use PVE::Tools qw(run_command);
+use PVE::Cluster qw(cfs_register_file);
 
-my $parse_ceph_file = sub {
-    my ($filename) = @_;
+cfs_register_file('ceph.conf',
+		  \&parse_ceph_config,
+		  \&write_ceph_config);
 
-    my $cfg = {};
+sub parse_ceph_config {
+    my ($filename, $raw) = @_;
 
-    return $cfg if ! -f $filename;
+    my $cfg = {};
 
-    my $content = PVE::Tools::file_get_contents($filename);
-    my @lines = split /\n/, $content;
+    my @lines = split /\n/, $raw;
 
     my $section;
 
@@ -36,8 +38,54 @@ my $parse_ceph_file = sub {
     }
 
     return $cfg;
+}
+
+my $parse_ceph_file = sub {
+    my ($filename) = @_;
+
+    my $cfg = {};
+
+    return $cfg if ! -f $filename;
+
+    my $content = PVE::Tools::file_get_contents($filename);
+
+    return parse_ceph_config($filename, $content);
 };
 
+sub write_ceph_config {
+    my ($filename, $cfg) = @_;
+
+    my $out = '';
+
+    my $cond_write_sec = sub {
+	my $re = shift;
+
+	foreach my $section (keys %$cfg) {
+	    next if $section !~ m/^$re$/;
+	    $out .= "[$section]\n";
+	    foreach my $key (sort keys %{$cfg->{$section}}) {
+		$out .= "\t $key = $cfg->{$section}->{$key}\n";
+	    }
+	    $out .= "\n";
+	}
+    };
+
+    &$cond_write_sec('global');
+    &$cond_write_sec('client');
+
+    &$cond_write_sec('mds');
+    &$cond_write_sec('mon');
+    &$cond_write_sec('osd');
+    &$cond_write_sec('mgr');
+
+    &$cond_write_sec('mds\..*');
+    &$cond_write_sec('mon\..*');
+    &$cond_write_sec('osd\..*');
+    &$cond_write_sec('mgr\..*');
+
+    return $out;
+}
+
 my $ceph_get_key = sub {
     my ($keyfile, $username) = @_;
 
-- 
2.11.0





More information about the pve-devel mailing list