PG: always clear_primary_state when leaving Primary

Otherwise, entries from the log collection process might leak into the next
epoch, where we might end up choosing a different authoritative log.  In this
case, it resulted in us not rolling back to log entries on one of the replicas
prior to trying to recover from an affected object due to the peer_missing not
being cleared.

Fixes: #10059
Backport: giant, firefly, dumpling
Signed-off-by: Samuel Just <sjust@redhat.com>
PG: always clear_primary_state on new interval, but only clear pg temp if not primary

Signed-off-by: Samuel Just <sjust@redhat.com>
PGLog: include rollback_info_trimmed_to in (read|write)_log

Fixes: #10157
Backport: firefly, giant
Signed-off-by: Samuel Just <sjust@redhat.com>
safe_io: do not set ending \0 in safe_read_file()

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
AsyncMessenger: Async event threads shared by all AsyncMessenger

WorkerPool is a singleton class which is served to AsyncMessenger. All
AsyncMessenger used the same worker pool.

Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
AsyncConnection: Ensure "mark_down" complete when returned

Now AsyncConnection try to process or modify any own variables within self
thread. It means actual function will be called by event loop not external.
So we can avoid lockdep or unnecessary lock for AsyncConnection.

So "mark_down" should be returned after _stop completed and all events has
be processed.

"external" for unregister_conn is unnecessary, because the caller won't
own AsyncMessenger::Lock again.

Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
AsyncConnection: Introduce "signal" event

Ensure signal cond after all previous events has be done

Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
Event: Fix Coverity error

Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
AsyncConnection: Avoid deadlock for AsyncConnection::lock

accept and connection will be send to queue and deliver to dispatcher. So
it can avoid caller stuck into AsyncConnection::lock deadlock

Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
AsyncConnection: Skip delete_file_event if sd < 0

Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
AsyncMessenger: Fix thread destroy when no active Messenger

Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
Cycles: A precious performance profile tool using rdstc

Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
ObjectStoreBenchmark: Used to perf ObjectStore::Transaction

Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
CephContext: Add AssociatedSingletonObject to allow CephContext's singleton

If some objects associated to CephContext want to create a singleton object,
it can inherit AssociatedSingletonObject and implement destruction to get notified.

Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
AsyncMessenger: Make WorkerPool use CephContext's singleton

Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
mds: disallow write operations when MDS is readonly

Signed-off-by: Yan, Zheng <zyan@redhat.com>
mds: don't trim log when MDS is readonly

When MDS is readonly, keep metadata objects (not include the journal) of
cephfs unchanged. This allows us to submit new entries to the log while
MDS is readonly. (Log entries submitted after MDS becomes readonly can
be safely dropped)

Signed-off-by: Yan, Zheng <zyan@redhat.com>
mds: keep locks in sync state when MDS is readonly

when transit locks to sync state, we may submit new entries to the log.
This should be safe as long as we don't trim old log segments.

Signed-off-by: Yan, Zheng <zyan@redhat.com>
mds: disallow slave requests when MDS is readonly

Signed-off-by: Yan, Zheng <zyan@redhat.com>
mds: disable misc internal activitiles when MDS is readonly

Signed-off-by: Yan, Zheng <zyan@redhat.com>