ReplicatedPG: do not preserve op context during flush

Any information stashed in the OpContext may be obsolete by the time we
actually mark the object clean.  Instead, let the start_flush caller
clean up its OpContext and in try_flush_mark_clean we'll create a new
one.  The primary reason to keep the OpContext would have been locking,
but we can set the obc as blocking without holding an OpContext, and
that would allow trimming to happen in the mean time (which is good
since trim_object does not respect rw locks since it doesn't change user
visible state).  In try_flush_mark_clean, we requeue the fop->op along
with (but ahead of) the fop->dup_ops.

Fixes: #8068
Signed-off-by: Samuel Just <sam.just@inktank.com>
(cherry picked from commit d83b8f58513e86c68aa6c25d4f909d9a3c4a103e)
ReplicatedPG: we can get EAGAIN on missing clone flush

Signed-off-by: Samuel Just <sam.just@inktank.com>
(cherry picked from commit 060105c313c5b4a777c55f17115eeb95ebb17117)
ECBackend::continue_recovery_op: handle a source shard going down

get_min_avail_to_read_shards might return an error if there are
no longer enough sources to reconstruct the missing shards.
This is possible if osds went down while we were writing the
previous chunk -- we already notice in check_recovery_sources
if a source goes down during a read.

Fixes: #8161
Signed-off-by: Samuel Just <sam.just@inktank.com>
(cherry picked from commit 1885792c517670086332a8bab237c58558ee6dda)
rados.h,ReplicatedPG: add CEPH_OSD_FLAG_ENFORCE_SNAPC and use on flush

We need to ensure that even with pool snaps, we use the snapc provided in order
to ensure that the clones are written back correctly.

Fixes: #7941
Signed-off-by: Samuel Just <sam.just@inktank.com>
(cherry picked from commit 499adb1db1cd225c91acce31b5f48fad5145043b)
ReplicatedPG: block scrub on blocked object contexts

Fixes: #8011
Signed-off-by: Samuel Just <sam.just@inktank.com>
Reviewed-by: Sage Weil <sage@inktank.com>
(cherry picked from commit e66f2e36c06ca00c1147f922d3513f56b122a5c0)
RWLock: assert pthread function return values

Signed-off-by: Samuel Just <sam.just@inktank.com>
Reviewed-by: Greg Farnum <greg@inktank.com>
PG: constify the init() function params

Signed-off-by: Greg Farnum <greg@inktank.com>
OSD::_share_map_incoming: line wrap debug output

Formatting only.

Signed-off-by: Samuel Just <sam.just@inktank.com>
Reviewed-by: Greg Farnum <greg@inktank.com>
OSD: add handle_osd_map debug output

Signed-off-by: Greg Farnum <greg@inktank.com>
OSD: replace handle_pg_scan, handle_pg_backfill with handle_replica_op

Signed-off-by: Samuel Just <sam.just@inktank.com>
Reviewed-by: Greg Farnum <greg@inktank.com>
OSD: remove unused push_wq

Signed-off-by: Greg Farnum <greg@inktank.com>
OSD: rename gen_wq, schedule_work, and PG_QueueAsync to include "recovery"

These all hook into the recovery thread pool and need to make that obvious.

Signed-off-by: Greg Farnum <greg@inktank.com>
OSD: remove never-activated while loop from send_incremental_map

Signed-off-by: Greg Farnum <greg@inktank.com>
DispatchQueue: factor out pre_dispatch and post_dispatch

Signed-off-by: Samuel Just <sam.just@inktank.com>
Reviewed-by: Greg Farnum <greg@inktank.com>
Messenger,DispatchQueue: add ms_fast_dispatch mechanism

This adds a Dispatcher interface allowing the implementation
to accept ms_fast_dispatch calls for some messages without
going through the DispatchQueue. To support that, we also add
1) new synchronous notifications on connect and accept events
2) a fast_preprocess mechanism

Signed-off-by: Samuel Just <sam.just@inktank.com>
Signed-off-by: Greg Farnum <greg@inktank.com>
msgr: enable fast_dispatch on local connections

We do two things:
1) Call ms_handle_fast_connect() when setting up the local connection, so
the Dispatcher can set up any state it needs
2)Move local_delivery into a separate thread from the sender's. fast_dispatch
makes this entirely necessary since otherwise we're dipping back in to the
Dispatcher while holding whatever locks it held when it sent the Message.

Implementation starts with a thread and a list of messages to process and
proceeds as you'd expect from that.

Signed-off-by: Greg Farnum <greg@inktank.com>
msgr: change the delay queue flushing semantics

Since we're doing fast_dispatch out of the delay queue, we don't want to
flush while holding the pipe lock. Instead, make flush set it up for instant
delivery, and steal the delay queue when replacing pipes. If we're shutting
down a pipe, wait until flushing has completed before doing so.

Signed-off-by: Greg Farnum <greg@inktank.com>
OSDService: add osdmap reservation mechanism

The goal here is to be able to get "reserved" refs
to next_map, and ensure that pgs won't see a newer
map until the ref is "released".  I haven't done
a cute RAII trick here yet...probably not worth
the effort.

Signed-off-by: Samuel Just <sam.just@inktank.com>
Reviewed-by: Greg Farnum <greg@inktank.com>

Conflicts:
	src/osd/OSD.h
Signed-off-by: Greg Farnum <greg@inktank.com>
OSD: add a RWLock pg_map_lock

If we're going to dispatch ops without grabbing the osd lock, we need
something else to protect the pg map (and it'll be a little
contended, so use a read-write lock).

We repurpose the (previously oddly-named) _lookup_lock_pg_with_map_lock_held()
function to refer to the pg_map_lock. handle_pg_query and handle_pg_remove
switch to use that version, because they're holding pg_map_lock already and
we know the PG they're referring to exists.

Signed-off-by: Samuel Just <sam.just@inktank.com>
Signed-off-by: Greg Farnum <greg@inktank.com>
OSD: pass osdmap to handle_op and handle_replica_op

We need a map to process them, and we don't want to
take the OSD lock to access one. (And we can't just
use the service because we need all processing of
a message to be done with the same map.)

Signed-off-by: Samuel Just <sam.just@inktank.com>
Signed-off-by: Greg Farnum <greg@inktank.com>