mds: require filter for client/session evict command

This commit fixes the issues in client/session evict command
using below solutions:
(1) client evict without filter is forbidden
(2) SessionFilter::parse is modified to support id=* (id=0 is not allowed)
(3) Invalid id error is handled
User can use client evict id=* to evict all clients.

Fixes:  https://tracker.ceph.com/issues/58619
Signed-off-by: Neeraj Pratap Singh <neesingh@redhat.com>
This commit is contained in:
neeraj pratap singh 2023-11-07 16:14:54 +05:30
parent 423a086601
commit 0ef5941a2e
3 changed files with 10 additions and 3 deletions

View File

@ -407,11 +407,11 @@ void MDSDaemon::set_up_admin_socket()
asok_hook,
"List client sessions based on a filter");
ceph_assert(r == 0);
r = admin_socket->register_command("session evict name=filters,type=CephString,n=N,req=false",
r = admin_socket->register_command("session evict name=filters,type=CephString,n=N,req=true",
asok_hook,
"Evict client session(s) based on a filter");
ceph_assert(r == 0);
r = admin_socket->register_command("client evict name=filters,type=CephString,n=N,req=false",
r = admin_socket->register_command("client evict name=filters,type=CephString,n=N,req=true",
asok_hook,
"Evict client session(s) based on a filter");
ceph_assert(r == 0);

View File

@ -3115,7 +3115,7 @@ void MDSRankDispatcher::evict_clients(
dout(20) << __func__ << " matched " << victims.size() << " sessions" << dendl;
if (victims.empty()) {
on_finish(0, {}, outbl);
on_finish(-ESRCH, "no hosts match", outbl);
return;
}

View File

@ -1217,6 +1217,13 @@ int SessionFilter::parse(
state = v;
} else if (k == "id") {
std::string err;
if (v == "*") {
// evict all clients , by default id set to 0
return 0;
} else if (v == "0") {
*ss << "Invalid value";
return -CEPHFS_EINVAL;
}
id = strict_strtoll(v.c_str(), 10, &err);
if (!err.empty()) {
*ss << err;