summaryrefslogtreecommitdiffstats
path: root/src/librbd/image/AttachChildRequest.h
blob: a40afaf544fddcf8d83f6e4e35c858ba045f5d62 (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
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPH_LIBRBD_IMAGE_ATTACH_CHILD_REQUEST_H
#define CEPH_LIBRBD_IMAGE_ATTACH_CHILD_REQUEST_H

#include "include/common_fwd.h"
#include "include/int_types.h"
#include "include/rados/librados.hpp"

class Context;

namespace librbd {

class ImageCtx;

namespace image {

template <typename ImageCtxT = ImageCtx>
class AttachChildRequest {
public:
  static AttachChildRequest* create(ImageCtxT *image_ctx,
                                    ImageCtxT *parent_image_ctx,
                                    const librados::snap_t &parent_snap_id,
                                    ImageCtxT *old_parent_image_ctx,
                                    const librados::snap_t &old_parent_snap_id,
                                    uint32_t clone_format,
                                    Context* on_finish) {
      return new AttachChildRequest(image_ctx, parent_image_ctx, parent_snap_id,
                                    old_parent_image_ctx, old_parent_snap_id,
                                    clone_format, on_finish);
  }

  AttachChildRequest(ImageCtxT *image_ctx,
                     ImageCtxT *parent_image_ctx,
                     const librados::snap_t &parent_snap_id,
                     ImageCtxT *old_parent_image_ctx,
                     const librados::snap_t &old_parent_snap_id,
                     uint32_t clone_format,
                     Context* on_finish);

  void send();

private:
  /**
   * @verbatim
   *
   *                     <start>
   *    (clone v1)          |        (clone v2)
   *      /----------------/ \---------------\
   *      |                                  |
   *      v                                  v
   *  V1 ADD CHILD                       V2 SET CLONE
   *      |                                  |
   *      v                                  v
   *  V1 VALIDATE PROTECTED              V2 ATTACH CHILD
   *      |                                  |
   *      |                                  v
   *  V1 REMOVE CHILD FROM OLD PARENT    V2 DETACH CHILD FROM OLD PARENT
   *      |                                  |
   *      \----------------\ /---------------/
   *                        |
   *                        v
   *                     <finish>
   *
   * @endverbatim
   */

  ImageCtxT *m_image_ctx;
  ImageCtxT *m_parent_image_ctx;
  librados::snap_t m_parent_snap_id;
  ImageCtxT *m_old_parent_image_ctx;
  librados::snap_t m_old_parent_snap_id;
  uint32_t m_clone_format;
  Context* m_on_finish;

  CephContext *m_cct;

  void v1_add_child();
  void handle_v1_add_child(int r);

  void v1_refresh();
  void handle_v1_refresh(int r);

  void v1_remove_child_from_old_parent();
  void handle_v1_remove_child_from_old_parent(int r);

  void v2_set_op_feature();
  void handle_v2_set_op_feature(int r);

  void v2_child_attach();
  void handle_v2_child_attach(int r);

  void v2_child_detach_from_old_parent();
  void handle_v2_child_detach_from_old_parent(int r);

  void finish(int r);
};

} // namespace image
} // namespace librbd

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

#endif // CEPH_LIBRBD_IMAGE_ATTACH_CHILD_REQUEST_H