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

#ifndef CEPH_LIBRBD_IMAGE_REFRESH_PARENT_REQUEST_H
#define CEPH_LIBRBD_IMAGE_REFRESH_PARENT_REQUEST_H

#include "include/int_types.h"
#include "librbd/Types.h"

class Context;

namespace librbd {

class ImageCtx;

namespace image {

template <typename ImageCtxT = ImageCtx>
class RefreshParentRequest {
public:
  static RefreshParentRequest *create(ImageCtxT &child_image_ctx,
                                      const ParentImageInfo &parent_md,
                                      const MigrationInfo &migration_info,
                                      Context *on_finish) {
    return new RefreshParentRequest(child_image_ctx, parent_md, migration_info,
                                    on_finish);
  }

  static bool is_refresh_required(ImageCtxT &child_image_ctx,
                                  const ParentImageInfo &parent_md,
                                  const MigrationInfo &migration_info);

  void send();
  void apply();
  void finalize(Context *on_finish);

private:
  /**
   * @verbatim
   *
   * <start>
   *    |
   *    | (open required)
   *    |----------------> OPEN_PARENT * * * * * * * * * * * * * * *
   *    |                     |                                    *
   *    |                     v                        (on error)  *
   *    \----------------> <apply>                                 *
   *                          |                                    *
   *                          | (close required)                   *
   *                          |-----------------> CLOSE_PARENT     *
   *                          |                      |             *
   *                          |                      v             *
   *                          |                   RESET_EXISTENCE  *
   *                          |                      |             *
   *                          |                      v             *
   *                          \-----------------> <finish> < * * * *
   *
   * @endverbatim
   */

  RefreshParentRequest(ImageCtxT &child_image_ctx,
                       const ParentImageInfo &parent_md,
                       const MigrationInfo &migration_info, Context *on_finish);

  ImageCtxT &m_child_image_ctx;
  ParentImageInfo m_parent_md;
  MigrationInfo m_migration_info;
  Context *m_on_finish;

  ImageCtxT *m_parent_image_ctx;
  uint64_t m_parent_snap_id;

  int m_error_result;

  static bool is_close_required(ImageCtxT &child_image_ctx,
                                const ParentImageInfo &parent_md,
                                const MigrationInfo &migration_info);
  static bool is_open_required(ImageCtxT &child_image_ctx,
                               const ParentImageInfo &parent_md,
                               const MigrationInfo &migration_info);
  static bool does_parent_exist(ImageCtxT &child_image_ctx,
                                const ParentImageInfo &parent_md,
                                const MigrationInfo &migration_info);

  void send_open_parent();
  Context *handle_open_parent(int *result);

  void send_close_parent();
  Context *handle_close_parent(int *result);

  void send_reset_existence_cache();
  Context *handle_reset_existence_cache(int *result);

  void send_complete(int r);

  void save_result(int *result) {
    if (m_error_result == 0 && *result < 0) {
      m_error_result = *result;
    }
  }

};

} // namespace image
} // namespace librbd

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

#endif // CEPH_LIBRBD_IMAGE_REFRESH_PARENT_REQUEST_H