]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/operation/MetadataSetRequest.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / librbd / operation / MetadataSetRequest.cc
CommitLineData
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
13namespace librbd {
14namespace operation {
15
16template <typename I>
17MetadataSetRequest<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
24template <typename I>
25void MetadataSetRequest<I>::send_op() {
26 send_metadata_set();
27}
28
29template <typename I>
30bool 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
41template <typename I>
42void 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
62template class librbd::operation::MetadataSetRequest<librbd::ImageCtx>;