]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/exclusive_lock/PreReleaseRequest.h
98e3a1e9dac73cc467910603ff0baa2aa8c888de
[ceph.git] / ceph / src / librbd / exclusive_lock / PreReleaseRequest.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_EXCLUSIVE_LOCK_PRE_RELEASE_REQUEST_H
5 #define CEPH_LIBRBD_EXCLUSIVE_LOCK_PRE_RELEASE_REQUEST_H
6
7 #include "librbd/ImageCtx.h"
8 #include <string>
9
10 class Context;
11
12 namespace librbd {
13
14 struct ImageCtx;
15
16 namespace exclusive_lock {
17
18 template <typename ImageCtxT = ImageCtx>
19 class PreReleaseRequest {
20 public:
21 static PreReleaseRequest* create(ImageCtxT &image_ctx, bool shutting_down,
22 Context *on_finish);
23
24 ~PreReleaseRequest();
25 void send();
26
27 private:
28 /**
29 * @verbatim
30 *
31 * <start>
32 * |
33 * v
34 * PREPARE_LOCK
35 * |
36 * v
37 * CANCEL_OP_REQUESTS
38 * |
39 * v
40 * BLOCK_WRITES
41 * |
42 * v
43 * INVALIDATE_CACHE
44 * |
45 * v
46 * FLUSH_NOTIFIES . . . . . . . . . . . . . .
47 * | .
48 * v .
49 * CLOSE_JOURNAL .
50 * | (journal disabled, .
51 * v object map enabled) .
52 * CLOSE_OBJECT_MAP < . . . . . . . . . . . .
53 * | .
54 * v (object map disabled) .
55 * <finish> < . . . . . . . . . . . . . . . . .
56 *
57 * @endverbatim
58 */
59
60 PreReleaseRequest(ImageCtxT &image_ctx, bool shutting_down,
61 Context *on_finish);
62
63 ImageCtxT &m_image_ctx;
64 Context *m_on_finish;
65 bool m_shutting_down;
66
67 int m_error_result;
68
69 decltype(m_image_ctx.object_map) m_object_map;
70 decltype(m_image_ctx.journal) m_journal;
71
72 void send_prepare_lock();
73 void handle_prepare_lock(int r);
74
75 void send_cancel_op_requests();
76 void handle_cancel_op_requests(int r);
77
78 void send_block_writes();
79 void handle_block_writes(int r);
80
81 void send_invalidate_cache(bool purge_on_error);
82 void handle_invalidate_cache(int r);
83
84 void send_flush_notifies();
85 void handle_flush_notifies(int r);
86
87 void send_close_journal();
88 void handle_close_journal(int r);
89
90 void send_close_object_map();
91 void handle_close_object_map(int r);
92
93 void send_unlock();
94
95 void finish();
96
97 void save_result(int result) {
98 if (m_error_result == 0 && result < 0) {
99 m_error_result = result;
100 }
101 }
102
103 };
104
105 } // namespace exclusive_lock
106 } // namespace librbd
107
108 #endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_PRE_RELEASE_REQUEST_H