]>
git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/api/Image.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/Image.h"
5 #include "include/rados/librados.hpp"
6 #include "common/dout.h"
7 #include "common/errno.h"
8 #include "cls/rbd/cls_rbd_client.h"
9 #include "librbd/ImageCtx.h"
10 #include "librbd/ImageState.h"
12 #define dout_subsys ceph_subsys_rbd
14 #define dout_prefix *_dout << "librbd::api::Image: " << __func__ << ": "
20 int Image
<I
>::list_images(librados::IoCtx
& io_ctx
, ImageNameToIds
*images
) {
21 CephContext
*cct
= (CephContext
*)io_ctx
.cct();
22 ldout(cct
, 20) << "io_ctx=" << &io_ctx
<< dendl
;
24 // new format images are accessed by class methods
27 string last_read
= "";
29 map
<string
, string
> images_page
;
30 r
= cls_client::dir_list(&io_ctx
, RBD_DIRECTORY
,
31 last_read
, max_read
, &images_page
);
32 if (r
< 0 && r
!= -ENOENT
) {
33 lderr(cct
) << "error listing image in directory: "
34 << cpp_strerror(r
) << dendl
;
36 } else if (r
== -ENOENT
) {
39 for (map
<string
, string
>::const_iterator it
= images_page
.begin();
40 it
!= images_page
.end(); ++it
) {
43 if (!images_page
.empty()) {
44 last_read
= images_page
.rbegin()->first
;
46 r
= images_page
.size();
47 } while (r
== max_read
);
53 int Image
<I
>::list_children(I
*ictx
, const ParentSpec
&parent_spec
,
54 PoolImageIds
*pool_image_ids
)
56 CephContext
*cct
= ictx
->cct
;
58 // no children for non-layered or old format image
59 if (!ictx
->test_features(RBD_FEATURE_LAYERING
, ictx
->snap_lock
)) {
63 pool_image_ids
->clear();
64 // search all pools for children depending on this snapshot
65 librados::Rados
rados(ictx
->md_ctx
);
66 std::list
<std::pair
<int64_t, std::string
> > pools
;
67 int r
= rados
.pool_list2(pools
);
69 lderr(cct
) << "error listing pools: " << cpp_strerror(r
) << dendl
;
73 for (auto it
= pools
.begin(); it
!= pools
.end(); ++it
) {
75 r
= rados
.pool_get_base_tier(it
->first
, &base_tier
);
77 ldout(cct
, 1) << "pool " << it
->second
<< " no longer exists" << dendl
;
80 lderr(cct
) << "error retrieving base tier for pool " << it
->second
84 if (it
->first
!= base_tier
) {
85 // pool is a cache; skip it
90 r
= rados
.ioctx_create2(it
->first
, ioctx
);
92 ldout(cct
, 1) << "pool " << it
->second
<< " no longer exists" << dendl
;
95 lderr(cct
) << "error accessing child image pool " << it
->second
100 set
<string
> image_ids
;
101 r
= cls_client::get_children(&ioctx
, RBD_CHILDREN
, parent_spec
,
103 if (r
< 0 && r
!= -ENOENT
) {
104 lderr(cct
) << "error reading list of children from pool " << it
->second
108 pool_image_ids
->insert({*it
, image_ids
});
115 } // namespace librbd
117 template class librbd::api::Image
<librbd::ImageCtx
>;