bool ClientCursor::eraseIfAuthorized(CursorId id) { std::string ns; { recursive_scoped_lock lock(ccmutex); ClientCursor* cursor = find_inlock(id); if (!cursor) { return false; } ns = cursor->ns(); } // Can't be in a lock when checking authorization if (!cc().getAuthorizationManager()->checkAuthorization(ns, ActionType::killCursors)) { return false; } // It is safe to lookup the cursor again after temporarily releasing the mutex because // of 2 invariants: that the cursor ID won't be re-used in a short period of time, and that // the namespace associated with a cursor cannot change. recursive_scoped_lock lock(ccmutex); ClientCursor* cursor = find_inlock(id); if (!cursor) { // Cursor was deleted in another thread since we found it earlier in this function. return false; } if (cursor->ns() != ns) { warning() << "Cursor namespace changed. Previous ns: " << ns << ", current ns: " << cursor->ns() << endl; return false; } return _erase_inlock(cursor); }
bool ClientCursor::erase(CursorId id) { recursive_scoped_lock lock(ccmutex); ClientCursor* cursor = find_inlock(id); if (!cursor) { return false; } _erase_inlock(cursor); return true; }
bool ClientCursor::eraseIfAuthorized(CursorId id) { NamespaceString ns; { recursive_scoped_lock lock(ccmutex); ClientCursor* cursor = find_inlock(id); if (!cursor) { audit::logKillCursorsAuthzCheck( &cc(), NamespaceString(), id, ErrorCodes::CursorNotFound); return false; } ns = NamespaceString(cursor->ns()); } // Can't be in a lock when checking authorization const bool isAuthorized = cc().getAuthorizationSession()->isAuthorizedForActionsOnNamespace( ns, ActionType::killCursors); audit::logKillCursorsAuthzCheck( &cc(), ns, id, isAuthorized ? ErrorCodes::OK : ErrorCodes::Unauthorized); if (!isAuthorized) { return false; } // It is safe to lookup the cursor again after temporarily releasing the mutex because // of 2 invariants: that the cursor ID won't be re-used in a short period of time, and that // the namespace associated with a cursor cannot change. recursive_scoped_lock lock(ccmutex); ClientCursor* cursor = find_inlock(id); if (!cursor) { // Cursor was deleted in another thread since we found it earlier in this function. return false; } if (ns != cursor->ns()) { warning() << "Cursor namespace changed. Previous ns: " << ns << ", current ns: " << cursor->ns() << endl; return false; } _erase_inlock(cursor); return true; }
// static ClientCursor* ClientCursor::find(CursorId id, bool warn) { recursive_scoped_lock lock(ccmutex); ClientCursor *c = find_inlock(id, warn); // if this asserts, your code was not thread safe - you either need to set no timeout // for the cursor or keep a ClientCursor::Pointer in scope for it. massert( 12521, "internal error: use of an unlocked ClientCursor", c == 0 || c->_pinValue ); return c; }
bool ClientCursor::erase( CursorId id ) { recursive_scoped_lock lock( ccmutex ); ClientCursor *cursor = find_inlock( id ); if ( ! cursor ) return false; if ( ! cc().getAuthenticationInfo()->isAuthorizedReads( nsToDatabase( cursor->ns() ) ) ) return false; assert( cursor->_pinValue < 100 ); // mustn't have an active ClientCursor::Pointer delete cursor; return true; }
bool ClientCursor::eraseIfAuthorized(CursorId id) { recursive_scoped_lock lock(ccmutex); ClientCursor* cursor = find_inlock(id); if (!cursor) { return false; } if (!cc().getAuthorizationManager()->checkAuthorization(cursor->ns(), ActionType::find) || !cc().getAuthenticationInfo()->isAuthorizedReads(nsToDatabase(cursor->ns()))) { return false; } return _erase_inlock(cursor); }
bool ClientCursor::erase( CursorId id ) { recursive_scoped_lock lock( ccmutex ); ClientCursor *cursor = find_inlock( id ); if ( ! cursor ) return false; if ( ! cc().getAuthenticationInfo()->isAuthorizedReads( nsToDatabase( cursor->ns() ) ) ) return false; // Must not have an active ClientCursor::Pin. massert( 16089, str::stream() << "Cannot kill active cursor " << id, cursor->_pinValue < 100 ); delete cursor; return true; }
/** find associated MMF object for a given pointer. threadsafe @param ofs out returns offset into the view of the pointer, if found. @return the MongoMMF to which this pointer belongs. null if not found. */ MongoMMF* PointerToMMF::find(void *p, /*out*/ size_t& ofs) { mutex::scoped_lock lk(_m); return find_inlock(p, ofs); }
/** find associated MMF object for a given pointer. threadsafe @param ofs out returns offset into the view of the pointer, if found. @return the DurableMappedFile to which this pointer belongs. null if not found. */ DurableMappedFile* PointerToDurableMappedFile::find(void *p, /*out*/ size_t& ofs) { mutex::scoped_lock lk(_m); return find_inlock(p, ofs); }