[pve-devel] [PATCH manager 3/6] ceph: add PUT 'flags' api call

Dominik Csapak d.csapak at proxmox.com
Mon Jul 22 16:08:49 CEST 2019


this api call can set multiple flags at once, but does this in a
worker since this can take quiet some time

also we only set/unset flags that are not already set/unset (respectively)

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/API2/Ceph.pm | 65 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm
index 72cac7e5..9cc6234a 100644
--- a/PVE/API2/Ceph.pm
+++ b/PVE/API2/Ceph.pm
@@ -918,6 +918,71 @@ __PACKAGE__->register_method ({
 	return $stat->{flags} // '';
     }});
 
+__PACKAGE__->register_method ({
+    name => 'set_flags',
+    path => 'flags',
+    method => 'PUT',
+    description => "Set/Unset multiple ceph flags at once.",
+    proxyto => 'node',
+    protected => 1,
+    permissions => {
+	check => ['perm', '/', [ 'Sys.Modify' ]],
+    },
+    parameters => {
+	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    %$possible_flags,
+	},
+    },
+    returns => { type => 'string' },
+    code => sub {
+	my ($param) = @_;
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+	my $user = $rpcenv->get_user();
+	PVE::Ceph::Tools::check_ceph_inited();
+
+	my $pve_ckeyring_path = PVE::Ceph::Tools::get_config('pve_ckeyring_path');
+
+	die "not fully configured - missing '$pve_ckeyring_path'\n"
+	    if ! -f $pve_ckeyring_path;
+
+	my $rados = PVE::RADOS->new();
+
+	my $worker = sub {
+	    # reopen rados object
+	    my $rados = PVE::RADOS->new();
+	    my $stat = $rados->mon_command({ prefix => 'osd dump' });
+	    my $setflags = {};
+	    map { $setflags->{$_} = 1 } PVE::Tools::split_list($stat->{flags} // '');
+	    my $errors = 0;
+	    foreach my $flag (sort keys %$possible_flags) {
+		next if !defined($param->{$flag});
+		my $val = $param->{$flag};
+		my $realflag = $flagmap->{$flag} // $flag;
+		next if $val && $setflags->{$realflag}; # we do not set already set flags
+		next if !$val && !$setflags->{$realflag}; # we do not unset not set flags
+
+		my $prefix = $val ? 'set' : 'unset';
+		eval {
+		    warn "$prefix $flag\n";
+		    $rados->mon_command({ prefix => "osd $prefix", key => $flag, });
+		};
+		if (my $err = $@) {
+		    warn $err;
+		    $errors++;
+		}
+	    }
+
+	    if ($errors) {
+		die "could not set/unset $errors flags\n";
+	    }
+	};
+
+	return $rpcenv->fork_worker('cephsetflags', undef,  $user, $worker);
+    }});
+
 __PACKAGE__->register_method ({
     name => 'set_flag',
     path => 'flags/{flag}',
-- 
2.20.1





More information about the pve-devel mailing list