Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / watcher / RewatchRequest.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_LIBRBD_WATCHER_REWATCH_REQUEST_H
5 #define CEPH_LIBRBD_WATCHER_REWATCH_REQUEST_H
6
7 #include "include/int_types.h"
8 #include "include/rados/librados.hpp"
9
10 struct Context;
11 struct RWLock;
12
13 namespace librbd {
14
15 namespace watcher {
16
17 class RewatchRequest {
18 public:
19
20   static RewatchRequest *create(librados::IoCtx& ioctx, const std::string& oid,
21                                 RWLock &watch_lock,
22                                 librados::WatchCtx2 *watch_ctx,
23                                 uint64_t *watch_handle, Context *on_finish) {
24     return new RewatchRequest(ioctx, oid, watch_lock, watch_ctx, watch_handle,
25                               on_finish);
26   }
27
28   RewatchRequest(librados::IoCtx& ioctx, const std::string& oid,
29                  RWLock &watch_lock, librados::WatchCtx2 *watch_ctx,
30                  uint64_t *watch_handle, Context *on_finish);
31
32   void send();
33
34 private:
35   /**
36    * @verbatim
37    *
38    * <start>
39    *    |
40    *    v
41    * UNWATCH
42    *    |
43    *    |  . . . .
44    *    |  .     . (recoverable error)
45    *    v  v     .
46    * REWATCH . . .
47    *    |
48    *    v
49    * <finish>
50    *
51    * @endverbatim
52    */
53
54   librados::IoCtx& m_ioctx;
55   std::string m_oid;
56   RWLock &m_watch_lock;
57   librados::WatchCtx2 *m_watch_ctx;
58   uint64_t *m_watch_handle;
59   Context *m_on_finish;
60
61   uint64_t m_rewatch_handle = 0;
62
63   void unwatch();
64   void handle_unwatch(int r);
65
66   void rewatch();
67   void handle_rewatch(int r);
68
69   void finish(int r);
70 };
71
72 } // namespace watcher
73 } // namespace librbd
74
75 #endif // CEPH_LIBRBD_WATCHER_REWATCH_REQUEST_H