Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mds: add command that config individual client session #29104

Merged
merged 2 commits into from Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions qa/tasks/cephfs/test_client_recovery.py
Expand Up @@ -601,3 +601,22 @@ def test_dont_mark_unresponsive_client_stale(self):
self.assertLess(time.time(), time_at_beg + SESSION_AUTOCLOSE)

self.mount_a.send_signal('sigcont')

def test_config_session_timeout(self):
self.fs.mds_asok(['config', 'set', 'mds_defer_session_stale', 'false'])
session_timeout = self.fs.get_var("session_timeout")
mount_a_gid = self.mount_a.get_global_id()

self.fs.mds_asok(['session', 'config', '%s' % mount_a_gid, 'timeout', '%s' % (session_timeout * 2)])

self.mount_a.kill();

self.assert_session_count(2)

time.sleep(session_timeout * 1.5)
self.assert_session_state(mount_a_gid, "open")

time.sleep(session_timeout)
self.assert_session_count(1)

self.mount_a.kill_cleanup()
21 changes: 16 additions & 5 deletions src/mds/MDSDaemon.cc
Expand Up @@ -271,16 +271,23 @@ void MDSDaemon::set_up_admin_socket()
asok_hook,
"Evict a CephFS client");
ceph_assert(r == 0);
r = admin_socket->register_command("osdmap barrier",
"osdmap barrier name=target_epoch,type=CephInt",
asok_hook,
"Wait until the MDS has this OSD map epoch");
ceph_assert(r == 0);
r = admin_socket->register_command("session ls",
"session ls",
asok_hook,
"Enumerate connected CephFS clients");
ceph_assert(r == 0);
r = admin_socket->register_command("session config",
"session config name=client_id,type=CephInt,req=true "
"name=option,type=CephString,req=true "
"name=value,type=CephString,req=false ",
asok_hook,
"Config a CephFS client session");
assert(r == 0);
r = admin_socket->register_command("osdmap barrier",
"osdmap barrier name=target_epoch,type=CephInt",
asok_hook,
"Wait until the MDS has this OSD map epoch");
ukernel marked this conversation as resolved.
Show resolved Hide resolved
ceph_assert(r == 0);
r = admin_socket->register_command("flush journal",
"flush journal",
asok_hook,
Expand Down Expand Up @@ -563,6 +570,10 @@ const std::vector<MDSDaemon::MDSCommand>& MDSDaemon::get_commands()
MDSCommand("client ls name=filters,type=CephString,n=N,req=false", "List client sessions"),
MDSCommand("session evict name=filters,type=CephString,n=N,req=false", "Evict client session(s)"),
MDSCommand("client evict name=filters,type=CephString,n=N,req=false", "Evict client session(s)"),
MDSCommand("session config name=client_id,type=CephInt name=option,type=CephString name=value,type=CephString,req=false",
"Config a client session"),
MDSCommand("client config name=client_id,type=CephInt name=option,type=CephString name=value,type=CephString,req=false",
"Config a client session"),
MDSCommand("damage ls", "List detected metadata damage"),
ukernel marked this conversation as resolved.
Show resolved Hide resolved
MDSCommand("damage rm name=damage_id,type=CephInt", "Remove a damage table entry"),
MDSCommand("version", "report version of MDS"),
Expand Down
59 changes: 59 additions & 0 deletions src/mds/MDSRank.cc
Expand Up @@ -2497,6 +2497,18 @@ bool MDSRankDispatcher::handle_asok_command(std::string_view command,
ss << dss.str();
}
mds_lock.Unlock();
} else if (command == "session config") {
int64_t client_id;
std::string option;
std::string value;

cmd_getval(g_ceph_context, cmdmap, "client_id", client_id);
cmd_getval(g_ceph_context, cmdmap, "option", option);
bool got_value = cmd_getval(g_ceph_context, cmdmap, "value", value);

mds_lock.Lock();
config_client(client_id, !got_value, option, value, ss);
mds_lock.Unlock();
} else if (command == "scrub_path") {
string path;
vector<string> scrubop_vec;
Expand Down Expand Up @@ -3322,6 +3334,42 @@ void MDSRankDispatcher::handle_osd_map()
objecter->maybe_request_map();
}

int MDSRank::config_client(int64_t session_id, bool remove,
const std::string& option, const std::string& value,
std::ostream& ss)
{
Session *session = sessionmap.get_session(entity_name_t(CEPH_ENTITY_TYPE_CLIENT, session_id));
if (!session) {
ss << "session " << session_id << " not in sessionmap!";
return -ENOENT;
}

if (option == "timeout") {
if (remove) {
auto it = session->info.client_metadata.find("timeout");
if (it == session->info.client_metadata.end()) {
ss << "Nonexistent config: " << option;
return -ENODATA;
}
session->info.client_metadata.erase(it);
} else {
char *end;
strtoul(value.c_str(), &end, 0);
if (*end) {
ss << "Invalid config for timeout: " << value;
return -EINVAL;
}
session->info.client_metadata[option] = value;
}
//sessionmap._mark_dirty(session, true);
} else {
ss << "Invalid config option: " << option;
return -EINVAL;
}

return 0;
}

bool MDSRank::evict_client(int64_t session_id,
bool wait, bool blacklist, std::ostream& err_ss,
Context *on_killed)
Expand Down Expand Up @@ -3523,6 +3571,17 @@ bool MDSRankDispatcher::handle_command(

*need_reply = false;
return true;
} else if (prefix == "session config" || prefix == "client config") {
int64_t client_id;
std::string option;
std::string value;

cmd_getval(g_ceph_context, cmdmap, "client_id", client_id);
cmd_getval(g_ceph_context, cmdmap, "option", option);
bool got_value = cmd_getval(g_ceph_context, cmdmap, "value", value);

*r = config_client(client_id, !got_value, option, value, *ss);
return true;
} else if (prefix == "damage ls") {
JSONFormatter f(true);
damage_table.dump(&f);
Expand Down
3 changes: 3 additions & 0 deletions src/mds/MDSRank.h
Expand Up @@ -452,6 +452,9 @@ class MDSRank {

bool evict_client(int64_t session_id, bool wait, bool blacklist,
std::ostream& ss, Context *on_killed=nullptr);
int config_client(int64_t session_id, bool remove,
const std::string& option, const std::string& value,
std::ostream& ss);

void mark_base_recursively_scrubbed(inodeno_t ino);

Expand Down
1 change: 1 addition & 0 deletions src/mds/mdstypes.h
Expand Up @@ -1138,6 +1138,7 @@ struct client_metadata_t {
iterator find(const std::string& key) const { return kv_map.find(key); }
iterator begin() const { return kv_map.begin(); }
iterator end() const { return kv_map.end(); }
void erase(iterator it) { kv_map.erase(it); }
std::string& operator[](const std::string& key) { return kv_map[key]; }
void merge(const client_metadata_t& other) {
kv_map.insert(other.kv_map.begin(), other.kv_map.end());
Expand Down