]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: validate crush-failure-domain 38347/head
authorPrashant D <pdhange@redhat.com>
Tue, 15 Sep 2020 02:27:21 +0000 (22:27 -0400)
committerNathan Cutler <ncutler@suse.com>
Mon, 30 Nov 2020 12:24:11 +0000 (13:24 +0100)
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>
(cherry picked from commit f8b7fddc4c4a787d58fb9efef6ecb13cf878f92b)

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 c32f257d74851665f923176c9976494dc0d7a12a..3e8c9dc13e9ee21b0cfcfe22d48c383065fb458e 100644 (file)
@@ -10803,6 +10803,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;