+sub ecprofile_exists {
+ my ($name) = @_;
+
+ my $rados = PVE::RADOS->new();
+ my $res = $rados->mon_command({ prefix => 'osd erasure-code-profile ls' });
+
+ my $profiles = { map { $_ => 1 } @$res };
+ return $profiles->{$name};
+}
+
+sub create_ecprofile {
+ my ($name, $k, $m, $failure_domain, $device_class) = @_;
+
+ $failure_domain = 'host' if !$failure_domain;
+
+ my $profile = [
+ "crush-failure-domain=${failure_domain}",
+ "k=${k}",
+ "m=${m}",
+ ];
+
+ push(@$profile, "crush-device-class=${device_class}") if $device_class;
+
+ my $rados = PVE::RADOS->new();
+ $rados->mon_command({
+ prefix => 'osd erasure-code-profile set',
+ name => $name,
+ profile => $profile,
+ });
+}
+
+sub destroy_ecprofile {
+ my ($profile) = @_;
+
+ my $rados = PVE::RADOS->new();
+ my $command = {
+ prefix => 'osd erasure-code-profile rm',
+ name => $profile,
+ format => 'plain',
+ };
+ return $rados->mon_command($command);
+}
+
+sub get_ecprofile_name {
+ my ($name) = @_;
+ return "pve_ec_${name}";
+}
+
+sub destroy_crush_rule {
+ my ($rule) = @_;
+ my $rados = PVE::RADOS->new();
+ my $command = {
+ prefix => 'osd crush rule rm',
+ name => $rule,
+ format => 'plain',
+ };
+ return $rados->mon_command($command);
+}
+