]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mon: validate crush-failure-domain
authorPrashant D <pdhange@redhat.com>
Tue, 15 Sep 2020 02:27:21 +0000 (22:27 -0400)
committerPrashant D <pdhange@redhat.com>
Tue, 22 Sep 2020 11:27:22 +0000 (07:27 -0400)
While creating erasure-coded profile make sure
that user is specifying valid crush-failure-domain.

Fixes: https://tracker.ceph.com/issues/47452
Signed-off-by: Prashant Dhange <pdhange@redhat.com>
qa/standalone/mon/osd-erasure-code-profile.sh
src/mon/OSDMonitor.cc

index 364b4c169508d5d0e3a9f2785200f04180dcf7d1..0afc5fc0b92f02b9df26ec0615fa1d7f269a5da1 100755 (executable)
@@ -222,6 +222,17 @@ function TEST_profile_k_sanity() {
         m=1 || return 1
 }
 
+function TEST_invalid_crush_failure_domain() {
+    local dir=$1
+
+    run_mon $dir a || return 1
+
+    local profile=ec_profile
+    local crush_failure_domain=invalid_failure_domain
+
+    ! ceph osd erasure-code-profile set $profile k=4 m=2 crush-failure-domain=$crush_failure_domain 2>&1 || return 1
+}
+
 main osd-erasure-code-profile "$@"
 
 # Local Variables:
index 7bf38899af28ea9825ff8c8bb341dd1c84ccdef9..5c44f91d7742b828b045ef2349f5db6a1d885707 100644 (file)
@@ -10919,6 +10919,18 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
     err = parse_erasure_code_profile(profile, &profile_map, &ss);
     if (err)
       goto reply;
+    if (auto found = profile_map.find("crush-failure-domain");
+       found != profile_map.end()) {
+      const auto& failure_domain = found->second;
+      int failure_domain_type = osdmap.crush->get_type_id(failure_domain);
+      if (failure_domain_type < 0) {
+       ss << "erasure-code-profile " << profile_map
+         << " contains an invalid failure-domain " << std::quoted(failure_domain);
+       err = -EINVAL;
+       goto reply;
+      }
+    }
+
     if (profile_map.find("plugin") == profile_map.end()) {
       ss << "erasure-code-profile " << profile_map
         << " must contain a plugin entry" << std::endl;