]>
git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/api/PoolMetadata.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/api/PoolMetadata.h"
5 #include "cls/rbd/cls_rbd_client.h"
6 #include "common/dout.h"
7 #include "common/errno.h"
8 #include "librbd/Utils.h"
9 #include "librbd/api/Config.h"
11 #define dout_subsys ceph_subsys_rbd
13 #define dout_prefix *_dout << "librbd::PoolMetadata: " << __func__ << ": "
19 int PoolMetadata
<I
>::get(librados::IoCtx
& io_ctx
,
20 const std::string
&key
, std::string
*value
) {
21 CephContext
*cct
= (CephContext
*)io_ctx
.cct();
23 int r
= cls_client::metadata_get(&io_ctx
, RBD_INFO
, key
, value
);
24 if (r
< 0 && r
!= -ENOENT
) {
25 lderr(cct
) << "failed reading metadata " << key
<< ": " << cpp_strerror(r
)
33 int PoolMetadata
<I
>::set(librados::IoCtx
& io_ctx
, const std::string
&key
,
34 const std::string
&value
) {
35 CephContext
*cct
= (CephContext
*)io_ctx
.cct();
37 std::string config_key
;
38 if (util::is_metadata_config_override(key
, &config_key
)) {
39 if (!librbd::api::Config
<I
>::is_option_name(io_ctx
, config_key
)) {
40 lderr(cct
) << "validation for " << key
41 << " failed: not allowed pool level override" << dendl
;
44 int r
= ConfigProxy
{false}.set_val(config_key
.c_str(), value
);
46 lderr(cct
) << "validation for " << key
<< " failed: " << cpp_strerror(r
)
55 int r
= cls_client::metadata_set(&io_ctx
, RBD_INFO
, {{key
, bl
}});
57 lderr(cct
) << "failed setting metadata " << key
<< ": " << cpp_strerror(r
)
66 int PoolMetadata
<I
>::remove(librados::IoCtx
& io_ctx
, const std::string
&key
) {
67 CephContext
*cct
= (CephContext
*)io_ctx
.cct();
70 int r
= cls_client::metadata_get(&io_ctx
, RBD_INFO
, key
, &value
);
73 ldout(cct
, 1) << "metadata " << key
<< " does not exist" << dendl
;
75 lderr(cct
) << "failed reading metadata " << key
<< ": " << cpp_strerror(r
)
81 r
= cls_client::metadata_remove(&io_ctx
, RBD_INFO
, key
);
83 lderr(cct
) << "failed removing metadata " << key
<< ": " << cpp_strerror(r
)
92 int PoolMetadata
<I
>::list(librados::IoCtx
& io_ctx
, const std::string
&start
,
94 std::map
<std::string
, ceph::bufferlist
> *pairs
) {
95 CephContext
*cct
= (CephContext
*)io_ctx
.cct();
97 int r
= cls_client::metadata_list(&io_ctx
, RBD_INFO
, start
, max
, pairs
);
101 lderr(cct
) << "failed listing metadata: " << cpp_strerror(r
)
110 } // namespace librbd
112 template class librbd::api::PoolMetadata
<librbd::ImageCtx
>;