]>
git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/mirror/snapshot/GetImageStateRequest.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "librbd/mirror/snapshot/GetImageStateRequest.h"
5 #include "common/dout.h"
6 #include "common/errno.h"
7 #include "librbd/ImageCtx.h"
8 #include "librbd/Utils.h"
9 #include "librbd/mirror/snapshot/Types.h"
10 #include "librbd/mirror/snapshot/Utils.h"
12 #define dout_subsys ceph_subsys_rbd
15 #define dout_prefix *_dout << "librbd::mirror::snapshot::GetImageStateRequest: " \
16 << this << " " << __func__ << ": "
22 using librbd::util::create_rados_callback
;
25 void GetImageStateRequest
<I
>::send() {
31 void GetImageStateRequest
<I
>::read_object() {
32 CephContext
*cct
= m_image_ctx
->cct
;
34 auto oid
= util::image_state_object_name(m_image_ctx
, m_snap_id
,
36 ldout(cct
, 20) << oid
<< dendl
;
38 librados::ObjectReadOperation op
;
40 op
.read(0, 0, &m_bl
, nullptr);
42 librados::AioCompletion
*comp
= create_rados_callback
<
43 GetImageStateRequest
<I
>,
44 &GetImageStateRequest
<I
>::handle_read_object
>(this);
45 int r
= m_image_ctx
->md_ctx
.aio_operate(oid
, comp
, &op
, nullptr);
51 void GetImageStateRequest
<I
>::handle_read_object(int r
) {
52 CephContext
*cct
= m_image_ctx
->cct
;
53 ldout(cct
, 20) << "r=" << r
<< dendl
;
56 lderr(cct
) << "failed to read image state object: " << cpp_strerror(r
)
62 auto iter
= m_bl
.cbegin();
64 if (m_object_index
== 0) {
65 ImageStateHeader header
;
69 } catch (const buffer::error
&err
) {
70 lderr(cct
) << "failed to decode image state object header" << dendl
;
74 m_object_count
= header
.object_count
;
78 bl
.substr_of(m_bl
, iter
.get_off(), m_bl
.length() - iter
.get_off());
79 m_state_bl
.claim_append(bl
);
83 if (m_object_index
>= m_object_count
) {
92 void GetImageStateRequest
<I
>::finish(int r
) {
93 CephContext
*cct
= m_image_ctx
->cct
;
94 ldout(cct
, 20) << "r=" << r
<< dendl
;
99 decode(*m_image_state
, m_state_bl
);
100 } catch (const buffer::error
&err
) {
101 lderr(cct
) << "failed to decode image state" << dendl
;
106 m_on_finish
->complete(r
);
110 } // namespace snapshot
111 } // namespace mirror
112 } // namespace librbd
114 template class librbd::mirror::snapshot::GetImageStateRequest
<librbd::ImageCtx
>;