]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
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_CACHE_PWL_SHUTDOWN_REQUEST_H | |
5 | #define CEPH_LIBRBD_CACHE_PWL_SHUTDOWN_REQUEST_H | |
6 | ||
7 | class Context; | |
8 | ||
9 | namespace librbd { | |
10 | ||
11 | class ImageCtx; | |
12 | namespace plugin { template <typename> struct Api; } | |
13 | ||
14 | namespace cache { | |
15 | ||
16 | namespace pwl { | |
17 | ||
18 | template<typename> | |
19 | class ImageCacheState; | |
20 | ||
21 | template <typename ImageCtxT = ImageCtx> | |
22 | class DiscardRequest { | |
23 | public: | |
24 | static DiscardRequest* create( | |
25 | ImageCtxT &image_ctx, | |
26 | plugin::Api<ImageCtxT>& plugin_api, | |
27 | Context *on_finish); | |
28 | ||
29 | void send(); | |
30 | ||
31 | private: | |
32 | ||
33 | /** | |
34 | * @verbatim | |
35 | * | |
36 | * Shutdown request goes through the following state machine: | |
37 | * | |
38 | * <start> | |
39 | * | | |
40 | * v | |
41 | * REMOVE_IMAGE_CACHE_FILE | |
42 | * | | |
43 | * v | |
44 | * REMOVE_IMAGE_CACHE_STATE | |
45 | * | | |
46 | * v | |
47 | * REMOVE_IMAGE_FEATURE_BIT | |
48 | * | | |
49 | * v | |
50 | * <finish> | |
51 | * | |
52 | * @endverbatim | |
53 | */ | |
54 | ||
55 | DiscardRequest(ImageCtxT &image_ctx, | |
56 | plugin::Api<ImageCtxT>& plugin_api, | |
57 | Context *on_finish); | |
58 | ||
59 | ImageCtxT &m_image_ctx; | |
60 | ImageCacheState<ImageCtxT>* m_cache_state; | |
61 | plugin::Api<ImageCtxT>& m_plugin_api; | |
62 | Context *m_on_finish; | |
63 | ||
64 | int m_error_result; | |
65 | ||
66 | void delete_image_cache_file(); | |
67 | ||
68 | void remove_image_cache_state(); | |
69 | void handle_remove_image_cache_state(int r); | |
70 | ||
71 | void remove_feature_bit(); | |
72 | void handle_remove_feature_bit(int r); | |
73 | ||
74 | void finish(); | |
75 | ||
76 | void save_result(int result) { | |
77 | if (m_error_result == 0 && result < 0) { | |
78 | m_error_result = result; | |
79 | } | |
80 | } | |
81 | ||
82 | }; | |
83 | ||
84 | } // namespace pwl | |
85 | } // namespace cache | |
86 | } // namespace librbd | |
87 | ||
88 | extern template class librbd::cache::pwl::DiscardRequest<librbd::ImageCtx>; | |
89 | ||
90 | #endif // CEPH_LIBRBD_CACHE_PWL_SHUTDOWN_REQUEST_H |