#include "common/Mutex.h"
#include "common/Cond.h"
+#include "common/RWLock.h"
#include "common/Timer.h"
uint32_t want;
uint32_t have;
uint32_t need;
+ RWLock lock;
public:
AuthClientHandler(CephContext *cct_)
- : cct(cct_), global_id(0), want(CEPH_ENTITY_TYPE_AUTH), have(0), need(0) {}
+ : cct(cct_), global_id(0), want(CEPH_ENTITY_TYPE_AUTH), have(0), need(0),
+ lock("AuthClientHandler::lock") {}
virtual ~AuthClientHandler() {}
void init(EntityName& n) { name = n; }
void set_want_keys(__u32 keys) {
+ RWLock::WLocker l(lock);
want = keys | CEPH_ENTITY_TYPE_AUTH;
validate_tickets();
}
void add_want_keys(__u32 keys) {
+ RWLock::WLocker l(lock);
want |= keys;
validate_tickets();
}
- bool have_keys(__u32 k) {
- validate_tickets();
- return (k & have) == have;
- }
- bool have_keys() {
- validate_tickets();
- return (want & have) == have;
- }
-
-
virtual int get_protocol() = 0;
virtual void reset() = 0;
ldout(cct, 10) << "build_request" << dendl;
ldout(cct, 10) << "validate_tickets: want=" << want << " need=" << need << " have=" << have << dendl;
+
+ lock.get_write();
validate_tickets();
+ lock.put_write();
+ RWLock::RLocker l(lock);
ldout(cct, 10) << "want=" << want << " need=" << need << " have=" << have << dendl;
CephXTicketHandler& ticket_handler = tickets.get_handler(CEPH_ENTITY_TYPE_AUTH);
int CephxClientHandler::handle_response(int ret, bufferlist::iterator& indata)
{
ldout(cct, 10) << "handle_response ret = " << ret << dendl;
+ RWLock::WLocker l(lock);
if (ret < 0)
return ret; // hrm!
AuthAuthorizer *CephxClientHandler::build_authorizer(uint32_t service_id)
{
+ RWLock::RLocker l(lock);
ldout(cct, 10) << "build_authorizer for service " << ceph_entity_type_name(service_id) << dendl;
return tickets.build_authorizer(service_id);
}
void CephxClientHandler::validate_tickets()
{
+ // lock should be held for write
tickets.validate_tickets(want, have, need);
}
bool CephxClientHandler::need_tickets()
{
+ RWLock::WLocker l(lock);
validate_tickets();
ldout(cct, 20) << "need_tickets: want=" << want << " need=" << need << " have=" << have << dendl;
}
void reset() {
+ RWLock::WLocker l(lock);
starting = true;
server_challenge = 0;
}
bool need_tickets();
void set_global_id(uint64_t id) {
+ RWLock::WLocker l(lock);
global_id = id;
tickets.global_id = id;
}
void tick() {}
AuthAuthorizer *build_authorizer(uint32_t service_id) {
+ RWLock::RLocker l(lock);
AuthNoneAuthorizer *auth = new AuthNoneAuthorizer();
if (auth) {
auth->build_authorizer(cct->_conf->name, global_id);
void validate_tickets() { }
bool need_tickets() { return false; }
- void set_global_id(uint64_t id) { global_id = id; }
+ void set_global_id(uint64_t id) {
+ RWLock::WLocker l(lock);
+ global_id = id;
+ }
};
#endif
void tick() {}
AuthAuthorizer *build_authorizer(uint32_t service_id) {
+ RWLock::RLocker l(lock);
AuthUnknownAuthorizer *auth = new AuthUnknownAuthorizer();
if (auth) {
auth->build_authorizer(cct->_conf->name, global_id);
void validate_tickets() { }
bool need_tickets() { return false; }
- void set_global_id(uint64_t id) { global_id = id; }
+ void set_global_id(uint64_t id) {
+ RWLock::WLocker l(lock);
+ global_id = id;
+ }
};
#endif