From: Yan, Zheng Date: Fri, 28 Nov 2014 13:13:25 +0000 (+0800) Subject: client: handle MDS 'force readonly' message X-Git-Tag: v0.91~52^2~14^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6b59eade276cc0029af1ebe2987f35696337377d;p=ceph.git client: handle MDS 'force readonly' message make client return -EROFS for write when MDS is readonly, instead of waiting forever. Signed-off-by: Yan, Zheng --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 6b43ccce3896..dffbb61645e2 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -1752,6 +1752,10 @@ void Client::handle_client_session(MClientSession *m) session->con->send_message(new MClientSession(CEPH_SESSION_FLUSHMSG_ACK, m->get_seq())); break; + case CEPH_SESSION_FORCE_RO: + force_session_readonly(session); + break; + default: assert(0); } @@ -2148,6 +2152,8 @@ void Client::send_reconnect(MetaSession *session) // trim unused caps to reduce MDS's cache rejoin time trim_cache_for_reconnect(session); + session->readonly = false; + if (session->release) { session->release->put(); session->release = NULL; @@ -2541,6 +2547,10 @@ int Client::get_caps(Inode *in, int need, int want, int *phave, loff_t endoff) } ldout(cct, 10) << "waiting for caps need " << ccap_string(need) << " want " << ccap_string(want) << dendl; } + + if ((need & CEPH_CAP_FILE_WR) && in->auth_cap && + in->auth_cap->session->readonly) + return -EROFS; wait_on_list(in->waitfor_caps); } @@ -3353,6 +3363,16 @@ void Client::trim_caps(MetaSession *s, int max) _invalidate_kernel_dcache(); } +void Client::force_session_readonly(MetaSession *s) +{ + s->readonly = true; + for (xlist::iterator p = s->caps.begin(); !p.end(); ++p) { + Inode *in = (*p)->inode; + if (in->caps_wanted() & CEPH_CAP_FILE_WR) + signal_cond_list(in->waitfor_caps); + } +} + void Client::mark_caps_dirty(Inode *in, int caps) { ldout(cct, 10) << "mark_caps_dirty " << *in << " " << ccap_string(in->dirty_caps) << " -> " diff --git a/src/client/Client.h b/src/client/Client.h index 4afc206077d5..96807a6d33e3 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -433,7 +433,10 @@ protected: void dump_inode(Formatter *f, Inode *in, set& did, bool disconnected); void dump_cache(Formatter *f); // debug - + + // force read-only + void force_session_readonly(MetaSession *s); + // trace generation ofstream traceout; diff --git a/src/client/MetaSession.h b/src/client/MetaSession.h index 6eb813cb22d4..1e0d17b0a9e0 100644 --- a/src/client/MetaSession.h +++ b/src/client/MetaSession.h @@ -37,6 +37,8 @@ struct MetaSession { STATE_STALE, } state; + bool readonly; + list waiting_for_open; xlist caps; @@ -52,7 +54,7 @@ struct MetaSession { MetaSession() : mds_num(-1), con(NULL), seq(0), cap_gen(0), cap_renew_seq(0), num_caps(0), - state(STATE_NEW), s_cap_iterator(NULL), + state(STATE_NEW), readonly(false), s_cap_iterator(NULL), release(NULL) {} ~MetaSession();