mon: move paxos write wait into a helper

Avoid duplicated code.

Signed-off-by: Sage Weil <sage@redhat.com>
mon: flush paxos write before setting shutdown state

Paxos::commit_finish() makes assertions about our state (writing |
writing-previous).

Fixes: #9635
Signed-off-by: Sage Weil <sage@redhat.com>
mon: wait for paxos writes before touching state

Fix two other paths where may change the mon state so that we wait for the
pending write first.  start_election() in particular can be triggered at
almost any time if we see an election message from another mon.

Signed-off-by: Sage Weil <sage@redhat.com>
Merge pull request #2655 from ceph/wip-9635

mon: fix async write completion waits

Fixes: #9635

Reviewed-by: Joao Eduardo Luis <joao@redhat.com>