]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: make stop properly cancel restart
authorMykola Golub <mgolub@suse.com>
Tue, 5 May 2020 14:23:59 +0000 (15:23 +0100)
committerMykola Golub <mgolub@suse.com>
Thu, 10 Jun 2021 12:00:03 +0000 (15:00 +0300)
Previously, if stop was issued when restart was at "stopping"
stage, the stop was just ignored.

Signed-off-by: Mykola Golub <mgolub@suse.com>
(cherry picked from commit 0a3794e56256be33a71e363da34ee84ffc34fef7)

Conflicts:
src/tools/rbd_mirror/ImageReplayer.cc (FunctionContext vs LambdaContext,
                                       update stop's args in handle_remote_journal_metadata_updated)
src/tools/rbd_mirror/ImageReplayer.h (Mutex vs ceph::mutex)

src/tools/rbd_mirror/ImageReplayer.cc
src/tools/rbd_mirror/ImageReplayer.h

index 6c6ee2d5fb9bc8ca0db5eae26f07836b1ff7eaed..7c7e87a988d6643759488696653cbdd27a0ddaed 100644 (file)
@@ -342,7 +342,7 @@ void ImageReplayer<I>::set_state_description(int r, const std::string &desc) {
 }
 
 template <typename I>
-void ImageReplayer<I>::start(Context *on_finish, bool manual)
+void ImageReplayer<I>::start(Context *on_finish, bool manual, bool restart)
 {
   dout(10) << "on_finish=" << on_finish << dendl;
 
@@ -356,12 +356,16 @@ void ImageReplayer<I>::start(Context *on_finish, bool manual)
       dout(5) << "stopped manually, ignoring start without manual flag"
              << dendl;
       r = -EPERM;
+    } else if (restart && !m_restart_requested) {
+      dout(10) << "canceled restart" << dendl;
+      r = -ECANCELED;
     } else {
       m_state = STATE_STARTING;
       m_last_r = 0;
       m_state_desc.clear();
       m_manual_stop = false;
       m_delete_requested = false;
+      m_restart_requested = false;
 
       if (on_finish != nullptr) {
         ceph_assert(m_on_start_finish == nullptr);
@@ -729,11 +733,10 @@ bool ImageReplayer<I>::on_start_interrupted(Mutex& lock) {
 }
 
 template <typename I>
-void ImageReplayer<I>::stop(Context *on_finish, bool manual, int r,
-                           const std::string& desc)
+void ImageReplayer<I>::stop(Context *on_finish, bool manual, bool restart)
 {
   dout(10) << "on_finish=" << on_finish << ", manual=" << manual
-          << ", desc=" << desc << dendl;
+           << ", restart=" << restart << dendl;
 
   image_replayer::BootstrapRequest<I> *bootstrap_request = nullptr;
   bool shut_down_replay = false;
@@ -741,8 +744,16 @@ void ImageReplayer<I>::stop(Context *on_finish, bool manual, int r,
   {
     Mutex::Locker locker(m_lock);
 
+    if (restart) {
+      m_restart_requested = true;
+    }
+
     if (!is_running_()) {
       running = false;
+      if (!restart && m_restart_requested) {
+        dout(10) << "canceling restart" << dendl;
+        m_restart_requested = false;
+      }
     } else {
       if (!is_stopped_()) {
        if (m_state == STATE_STARTING) {
@@ -780,7 +791,7 @@ void ImageReplayer<I>::stop(Context *on_finish, bool manual, int r,
   }
 
   if (shut_down_replay) {
-    on_stop_journal_replay(r, desc);
+    on_stop_journal_replay();
   } else if (on_finish != nullptr) {
     on_finish->complete(0);
   }
@@ -842,14 +853,19 @@ void ImageReplayer<I>::handle_replay_ready()
 template <typename I>
 void ImageReplayer<I>::restart(Context *on_finish)
 {
+  {
+    Mutex::Locker locker(m_lock);
+    m_restart_requested = true;
+  }
+
   FunctionContext *ctx = new FunctionContext(
     [this, on_finish](int r) {
       if (r < 0) {
        // Try start anyway.
       }
-      start(on_finish, true);
+      start(on_finish, true, true);
     });
-  stop(ctx);
+  stop(ctx, false, true);
 }
 
 template <typename I>
@@ -1782,7 +1798,7 @@ void ImageReplayer<I>::handle_remote_journal_metadata_updated() {
 
   if (client.state != cls::journal::CLIENT_STATE_CONNECTED) {
     dout(0) << "client flagged disconnected, stopping image replay" << dendl;
-    stop(nullptr, false, -ENOTCONN, "disconnected");
+    stop(nullptr, false, false);
   }
 }
 
index 9af3e9611cd99d108ca07975169178019797afb9..de3637a6b8beb4181e8526765a0f03d3ae1950ce 100644 (file)
@@ -113,9 +113,10 @@ public:
     return m_global_image_id;
   }
 
-  void start(Context *on_finish = nullptr, bool manual = false);
+  void start(Context *on_finish = nullptr, bool manual = false,
+             bool restart = false);
   void stop(Context *on_finish = nullptr, bool manual = false,
-           int r = 0, const std::string& desc = "");
+            bool restart = false);
   void restart(Context *on_finish = nullptr);
   void flush();
 
@@ -197,11 +198,11 @@ protected:
    * @endverbatim
    */
 
-  virtual void on_start_fail(int r, const std::string &desc);
-  virtual bool on_start_interrupted();
-  virtual bool on_start_interrupted(Mutex& lock);
+  void on_start_fail(int r, const std::string &desc);
+  bool on_start_interrupted();
+  bool on_start_interrupted(Mutex& lock);
 
-  virtual void on_stop_journal_replay(int r = 0, const std::string &desc = "");
+  void on_stop_journal_replay(int r = 0, const std::string &desc = "");
 
   bool on_replay_interrupted();
 
@@ -292,6 +293,7 @@ private:
   bool m_finished = false;
   bool m_delete_requested = false;
   bool m_resync_requested = false;
+  bool m_restart_requested = false;
 
   image_replayer::EventPreprocessor<ImageCtxT> *m_event_preprocessor = nullptr;
   image_replayer::ReplayStatusFormatter<ImageCtxT> *m_replay_status_formatter =