mon: catch bad_cmd_exception and reply EINVAL

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>
This commit is contained in:
Sage Weil 2018-08-02 14:34:44 -05:00
parent fecb9021c1
commit b684f02c72
7 changed files with 113 additions and 14 deletions

View 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:

View 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;
}

View 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:

View 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);

View 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);

View 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:

View 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);