]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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/operation/MetadataSetRequest.h" | |
5 | #include "common/dout.h" | |
6 | #include "common/errno.h" | |
7 | #include "librbd/ImageCtx.h" | |
8 | ||
9 | #define dout_subsys ceph_subsys_rbd | |
10 | #undef dout_prefix | |
11 | #define dout_prefix *_dout << "librbd::MetadataSetRequest: " | |
12 | ||
13 | namespace librbd { | |
14 | namespace operation { | |
15 | ||
16 | template <typename I> | |
17 | MetadataSetRequest<I>::MetadataSetRequest(I &image_ctx, | |
18 | Context *on_finish, | |
19 | const std::string &key, | |
20 | const std::string &value) | |
21 | : Request<I>(image_ctx, on_finish), m_key(key), m_value(value) { | |
22 | } | |
23 | ||
24 | template <typename I> | |
25 | void MetadataSetRequest<I>::send_op() { | |
26 | send_metadata_set(); | |
27 | } | |
28 | ||
29 | template <typename I> | |
30 | bool MetadataSetRequest<I>::should_complete(int r) { | |
31 | I &image_ctx = this->m_image_ctx; | |
32 | CephContext *cct = image_ctx.cct; | |
11fdf7f2 | 33 | ldout(cct, 20) << this << " " << __func__ << " r=" << r << dendl; |
7c673cae FG |
34 | |
35 | if (r < 0) { | |
36 | lderr(cct) << "encountered error: " << cpp_strerror(r) << dendl; | |
37 | } | |
38 | return true; | |
39 | } | |
40 | ||
41 | template <typename I> | |
42 | void MetadataSetRequest<I>::send_metadata_set() { | |
43 | I &image_ctx = this->m_image_ctx; | |
9f95a23c | 44 | ceph_assert(ceph_mutex_is_locked(image_ctx.owner_lock)); |
7c673cae FG |
45 | |
46 | CephContext *cct = image_ctx.cct; | |
47 | ldout(cct, 20) << this << " " << __func__ << dendl; | |
48 | ||
49 | m_data[m_key].append(m_value); | |
50 | librados::ObjectWriteOperation op; | |
51 | cls_client::metadata_set(&op, m_data); | |
52 | ||
53 | librados::AioCompletion *comp = this->create_callback_completion(); | |
54 | int r = image_ctx.md_ctx.aio_operate(image_ctx.header_oid, comp, &op); | |
11fdf7f2 | 55 | ceph_assert(r == 0); |
7c673cae FG |
56 | comp->release(); |
57 | } | |
58 | ||
59 | } // namespace operation | |
60 | } // namespace librbd | |
61 | ||
62 | template class librbd::operation::MetadataSetRequest<librbd::ImageCtx>; |