]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/object_map/CreateRequest.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / librbd / object_map / CreateRequest.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "librbd/object_map/CreateRequest.h"
5 #include "include/ceph_assert.h"
6 #include "common/dout.h"
7 #include "common/errno.h"
8 #include "cls/rbd/cls_rbd_client.h"
9 #include "osdc/Striper.h"
10 #include "librbd/ImageCtx.h"
11 #include "librbd/ObjectMap.h"
12 #include "librbd/Utils.h"
13
14 #define dout_subsys ceph_subsys_rbd
15 #undef dout_prefix
16 #define dout_prefix *_dout << "librbd::object_map::CreateRequest: "
17
18 namespace librbd {
19 namespace object_map {
20
21 using util::create_context_callback;
22 using util::create_rados_callback;
23
24 template <typename I>
25 CreateRequest<I>::CreateRequest(I *image_ctx, Context *on_finish)
26 : m_image_ctx(image_ctx), m_on_finish(on_finish) {
27 }
28
29 template <typename I>
30 void CreateRequest<I>::send() {
31 CephContext *cct = m_image_ctx->cct;
32
33 uint64_t max_size = m_image_ctx->size;
34
35 {
36 RWLock::WLocker snap_locker(m_image_ctx->snap_lock);
37 m_snap_ids.push_back(CEPH_NOSNAP);
38 for (auto it : m_image_ctx->snap_info) {
39 max_size = std::max(max_size, it.second.size);
40 m_snap_ids.push_back(it.first);
41 }
42
43 if (ObjectMap<>::is_compatible(m_image_ctx->layout, max_size)) {
44 send_object_map_resize();
45 return;
46 }
47 }
48
49 lderr(cct) << "image size not compatible with object map" << dendl;
50 m_on_finish->complete(-EINVAL);
51 }
52
53 template <typename I>
54 void CreateRequest<I>::send_object_map_resize() {
55 CephContext *cct = m_image_ctx->cct;
56 ldout(cct, 20) << __func__ << dendl;
57
58 Context *ctx = create_context_callback<
59 CreateRequest<I>, &CreateRequest<I>::handle_object_map_resize>(this);
60 C_Gather *gather_ctx = new C_Gather(cct, ctx);
61
62 for (auto snap_id : m_snap_ids) {
63 librados::ObjectWriteOperation op;
64 uint64_t snap_size = m_image_ctx->get_image_size(snap_id);
65
66 cls_client::object_map_resize(&op, Striper::get_num_objects(
67 m_image_ctx->layout, snap_size),
68 OBJECT_NONEXISTENT);
69
70 std::string oid(ObjectMap<>::object_map_name(m_image_ctx->id, snap_id));
71 librados::AioCompletion *comp = create_rados_callback(gather_ctx->new_sub());
72 int r = m_image_ctx->md_ctx.aio_operate(oid, comp, &op);
73 ceph_assert(r == 0);
74 comp->release();
75 }
76 gather_ctx->activate();
77 }
78
79 template <typename I>
80 Context *CreateRequest<I>::handle_object_map_resize(int *result) {
81 CephContext *cct = m_image_ctx->cct;
82 ldout(cct, 20) << __func__ << ": r=" << *result << dendl;
83
84 if (*result < 0) {
85 lderr(cct) << "object map resize failed: " << cpp_strerror(*result)
86 << dendl;
87 }
88 return m_on_finish;
89 }
90
91 } // namespace object_map
92 } // namespace librbd
93
94 template class librbd::object_map::CreateRequest<librbd::ImageCtx>;