summaryrefslogtreecommitdiffstats
path: root/src/librbd/image/OpenRequest.h
blob: 0fe218a3982892705667b4e8ea6ee454f4ca4189 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPH_LIBRBD_IMAGE_OPEN_REQUEST_H
#define CEPH_LIBRBD_IMAGE_OPEN_REQUEST_H

#include "include/buffer.h"
#include <map>
#include <string>

class Context;

namespace librbd {

class ImageCtx;

namespace image {

template <typename ImageCtxT = ImageCtx>
class OpenRequest {
public:
  static OpenRequest *create(ImageCtxT *image_ctx, uint64_t flags,
                             Context *on_finish) {
    return new OpenRequest(image_ctx, flags, on_finish);
  }

  void send();

private:
  /**
   * @verbatim
   *
   * <start>
   *    |
   *    | (v1)
   *    |-----> V1_DETECT_HEADER
   *    |           |
   *    |           \-------------------------------\
   *    | (v2)                                      |
   *    \-----> V2_DETECT_HEADER                    |
   *                |                               |
   *                v                               |
   *            V2_GET_ID|NAME                      |
   *                |                               |
   *                v (skip if have name)           |
   *            V2_GET_NAME_FROM_TRASH              |
   *                |                               |
   *                v                               |
   *            V2_GET_INITIAL_METADATA             |
   *                |                               |
   *                v                               |
   *            V2_GET_STRIPE_UNIT_COUNT (skip if   |
   *                |                     disabled) |
   *                v                               |
   *            V2_GET_CREATE_TIMESTAMP             |
   *                |                               |
   *                v                               |
   *            V2_GET_ACCESS_MODIFIY_TIMESTAMP     |
   *                |                               |
   *                v                               |
   *            V2_GET_DATA_POOL --------------> REFRESH
   *                                                |
   *                                                v
   *                                             INIT_PLUGIN_REGISTRY
   *                                                |
   *                                                v
   *                                             INIT_CACHE
   *                                                |
   *                                                v
   *                                             REGISTER_WATCH (skip if
   *                                                |            read-only)
   *                                                v
   *                                             SET_SNAP (skip if no snap)
   *                                                |
   *                                                v
   *                                             <finish>
   *                                                ^
   *     (on error)                                 |
   *    * * * * * * > CLOSE ------------------------/
   *
   * @endverbatim
   */

  OpenRequest(ImageCtxT *image_ctx, uint64_t flags, Context *on_finish);

  ImageCtxT *m_image_ctx;
  bool m_skip_open_parent_image;
  Context *m_on_finish;

  bufferlist m_out_bl;
  int m_error_result;

  void send_v1_detect_header();
  Context *handle_v1_detect_header(int *result);

  void send_v2_detect_header();
  Context *handle_v2_detect_header(int *result);

  void send_v2_get_id();
  Context *handle_v2_get_id(int *result);

  void send_v2_get_name();
  Context *handle_v2_get_name(int *result);

  void send_v2_get_name_from_trash();
  Context *handle_v2_get_name_from_trash(int *result);

  void send_v2_get_initial_metadata();
  Context *handle_v2_get_initial_metadata(int *result);

  void send_v2_get_stripe_unit_count();
  Context *handle_v2_get_stripe_unit_count(int *result);

  void send_v2_get_create_timestamp();
  Context *handle_v2_get_create_timestamp(int *result);

  void send_v2_get_access_modify_timestamp();
  Context *handle_v2_get_access_modify_timestamp(int *result);

  void send_v2_get_data_pool();
  Context *handle_v2_get_data_pool(int *result);

  void send_refresh();
  Context *handle_refresh(int *result);

  void send_init_plugin_registry();
  Context* handle_init_plugin_registry(int *result);

  Context *send_init_cache(int *result);

  Context *send_register_watch(int *result);
  Context *handle_register_watch(int *result);

  Context *send_set_snap(int *result);
  Context *handle_set_snap(int *result);

  Context *finalize(int r);

  void send_close_image(int error_result);
  Context *handle_close_image(int *result);

};

} // namespace image
} // namespace librbd

extern template class librbd::image::OpenRequest<librbd::ImageCtx>;

#endif // CEPH_LIBRBD_IMAGE_OPEN_REQUEST_H