]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mon: catch bad_cmd_exception and reply EINVAL
authorSage Weil <sage@redhat.com>
Thu, 2 Aug 2018 19:34:44 +0000 (14:34 -0500)
committerSage Weil <sage@redhat.com>
Sun, 5 Aug 2018 02:54:24 +0000 (21:54 -0500)
If we get bad input we should always reply EINVAL.  Note that bad_cmd_get
will be reserved for invalid input, not missing/optional input, like
passing a float when an int is expected.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/AuthMonitor.cc
src/mon/ConfigMonitor.cc
src/mon/LogMonitor.cc
src/mon/MDSMonitor.cc
src/mon/MgrMonitor.cc
src/mon/MonmapMonitor.cc
src/mon/OSDMonitor.cc

index 147e4d69f81b828c85b5709cd6b0a3961bc53fd6..b8a3b320e2d21d7fca372643a06f04c237f84af0 100644 (file)
@@ -363,7 +363,14 @@ bool AuthMonitor::preprocess_query(MonOpRequestRef op)
   dout(10) << "preprocess_query " << *m << " from " << m->get_orig_source_inst() << dendl;
   switch (m->get_type()) {
   case MSG_MON_COMMAND:
-    return preprocess_command(op);
+    try {
+      return preprocess_command(op);
+    }
+    catch (const bad_cmd_get& e) {
+      bufferlist bl;
+      mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed());
+      return true;
+    }
 
   case CEPH_MSG_AUTH:
     return prep_auth(op, false);
@@ -383,7 +390,14 @@ bool AuthMonitor::prepare_update(MonOpRequestRef op)
   dout(10) << "prepare_update " << *m << " from " << m->get_orig_source_inst() << dendl;
   switch (m->get_type()) {
   case MSG_MON_COMMAND:
-    return prepare_command(op);
+    try {
+      return prepare_command(op);
+    }
+    catch (const bad_cmd_get& e) {
+      bufferlist bl;
+      mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed());
+      return true;
+    }
   case MSG_MON_GLOBAL_ID:
     return prepare_global_id(op);
   case CEPH_MSG_AUTH:
index 1f5cfb25d8e5a834cac765998a93f2b344559e9d..872a4c5257a9a32bef9158766c948cd49d8f3edd 100644 (file)
@@ -109,7 +109,14 @@ bool ConfigMonitor::preprocess_query(MonOpRequestRef op)
 {
   switch (op->get_req()->get_type()) {
   case MSG_MON_COMMAND:
-    return preprocess_command(op);
+    try {
+      return preprocess_command(op);
+    }
+    catch (const bad_cmd_get& e) {
+      bufferlist bl;
+      mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed());
+      return true;
+    }
   }
   return false;
 }
@@ -367,7 +374,14 @@ bool ConfigMonitor::prepare_update(MonOpRequestRef op)
          << " from " << m->get_orig_source_inst() << dendl;
   switch (m->get_type()) {
   case MSG_MON_COMMAND:
-    return prepare_command(op);
+    try {
+      return prepare_command(op);
+    }
+    catch (const bad_cmd_get& e) {
+      bufferlist bl;
+      mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed());
+      return true;
+    }
   }
   return false;
 }
index 95ea2bda5aab7e85f39e6de10553327c325011e2..28d57d3e81291a420b7e3a19a7082e5db13bc915 100644 (file)
@@ -258,7 +258,14 @@ bool LogMonitor::preprocess_query(MonOpRequestRef op)
   dout(10) << "preprocess_query " << *m << " from " << m->get_orig_source_inst() << dendl;
   switch (m->get_type()) {
   case MSG_MON_COMMAND:
-    return preprocess_command(op);
+    try {
+      return preprocess_command(op);
+    }
+    catch (const bad_cmd_get& e) {
+      bufferlist bl;
+      mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed());
+      return true;
+    }
 
   case MSG_LOG:
     return preprocess_log(op);
@@ -276,7 +283,14 @@ bool LogMonitor::prepare_update(MonOpRequestRef op)
   dout(10) << "prepare_update " << *m << " from " << m->get_orig_source_inst() << dendl;
   switch (m->get_type()) {
   case MSG_MON_COMMAND:
-    return prepare_command(op);
+    try {
+      return prepare_command(op);
+    }
+    catch (const bad_cmd_get& e) {
+      bufferlist bl;
+      mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed());
+      return true;
+    }
   case MSG_LOG:
     return prepare_log(op);
   default:
index f716a75419a7c5897d6fdafceba063a201771a17..22b8d566f240c972e52ed5f0730e56216840d915 100644 (file)
@@ -286,7 +286,14 @@ bool MDSMonitor::preprocess_query(MonOpRequestRef op)
     return preprocess_beacon(op);
     
   case MSG_MON_COMMAND:
-    return preprocess_command(op);
+    try {
+      return preprocess_command(op);
+    }
+    catch (const bad_cmd_get& e) {
+      bufferlist bl;
+      mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed());
+      return true;
+    }
 
   case MSG_MDS_OFFLOAD_TARGETS:
     return preprocess_offload_targets(op);
@@ -497,7 +504,14 @@ bool MDSMonitor::prepare_update(MonOpRequestRef op)
     return prepare_beacon(op);
 
   case MSG_MON_COMMAND:
-    return prepare_command(op);
+    try {
+      return prepare_command(op);
+    }
+    catch (const bad_cmd_get& e) {
+      bufferlist bl;
+      mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed());
+      return true;
+    }
 
   case MSG_MDS_OFFLOAD_TARGETS:
     return prepare_offload_targets(op);
index a7af4241c00dd33327f386d6999f40287e511c55..e4207c4eba4082b451ab1cff962905ea02f49cc4 100644 (file)
@@ -220,7 +220,15 @@ bool MgrMonitor::preprocess_query(MonOpRequestRef op)
     case MSG_MGR_BEACON:
       return preprocess_beacon(op);
     case MSG_MON_COMMAND:
-      return preprocess_command(op);
+      try {
+       return preprocess_command(op);
+      }
+      catch (const bad_cmd_get& e) {
+      bufferlist bl;
+      mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed());
+      return true;
+    }
+
     default:
       mon->no_reply(op);
       derr << "Unhandled message type " << m->get_type() << dendl;
@@ -236,7 +244,14 @@ bool MgrMonitor::prepare_update(MonOpRequestRef op)
       return prepare_beacon(op);
 
     case MSG_MON_COMMAND:
-      return prepare_command(op);
+      try {
+       return prepare_command(op);
+      }
+      catch (const bad_cmd_get& e) {
+       bufferlist bl;
+       mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed());
+       return true;
+      }
 
     default:
       mon->no_reply(op);
index 245acde6e162e4e852d3ffdd4f93ba0e38b69d3f..2397d4642dcc8fe423f4a9fe28ba9b9d69fafc4c 100644 (file)
@@ -201,7 +201,14 @@ bool MonmapMonitor::preprocess_query(MonOpRequestRef op)
   switch (m->get_type()) {
     // READs
   case MSG_MON_COMMAND:
-    return preprocess_command(op);
+    try {
+      return preprocess_command(op);
+    }
+    catch (const bad_cmd_get& e) {
+      bufferlist bl;
+      mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed());
+      return true;
+    }
   case MSG_MON_JOIN:
     return preprocess_join(op);
   default:
@@ -405,7 +412,14 @@ bool MonmapMonitor::prepare_update(MonOpRequestRef op)
   
   switch (m->get_type()) {
   case MSG_MON_COMMAND:
-    return prepare_command(op);
+    try {
+      return prepare_command(op);
+    }
+    catch (const bad_cmd_get& e) {
+      bufferlist bl;
+      mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed());
+      return true;
+    }
   case MSG_MON_JOIN:
     return prepare_join(op);
   default:
index 02900318feedc2432996ebae9d56116377416eca..27c26a7d63d9194bf42bf47122f6ee43d34e7cf2 100644 (file)
@@ -2037,7 +2037,14 @@ bool OSDMonitor::preprocess_query(MonOpRequestRef op)
   switch (m->get_type()) {
     // READs
   case MSG_MON_COMMAND:
-    return preprocess_command(op);
+    try {
+      return preprocess_command(op);
+    }
+    catch (const bad_cmd_get& e) {
+      bufferlist bl;
+      mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed());
+      return true;
+    }
   case CEPH_MSG_MON_GET_OSDMAP:
     return preprocess_get_osdmap(op);
 
@@ -2097,7 +2104,14 @@ bool OSDMonitor::prepare_update(MonOpRequestRef op)
     return prepare_beacon(op);
 
   case MSG_MON_COMMAND:
-    return prepare_command(op);
+    try {
+      return prepare_command(op);
+    }
+    catch (const bad_cmd_get& e) {
+      bufferlist bl;
+      mon->reply_command(op, -EINVAL, e.what(), bl, get_last_committed());
+      return true;
+    }
 
   case CEPH_MSG_POOLOP:
     return prepare_pool_op(op);