1 // -*- mode:C++; tab-width:8; c-basic-offsset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "tools/rbd/ArgumentTypes.h"
5 #include "tools/rbd/Shell.h"
6 #include "tools/rbd/Utils.h"
7 #include "common/errno.h"
8 #include "common/Formatter.h"
10 #include <boost/program_options.hpp>
16 namespace at
= argument_types
;
17 namespace po
= boost::program_options
;
19 int do_list_children(librbd::Image
&image
, Formatter
*f
)
21 std::set
<std::pair
<std::string
, std::string
> > children
;
24 r
= image
.list_children(&children
);
29 f
->open_array_section("children");
31 for (auto &child_it
: children
) {
33 f
->open_object_section("child");
34 f
->dump_string("pool", child_it
.first
);
35 f
->dump_string("image", child_it
.second
);
38 std::cout
<< child_it
.first
<< "/" << child_it
.second
<< std::endl
;
50 void get_arguments(po::options_description
*positional
,
51 po::options_description
*options
) {
52 at::add_snap_spec_options(positional
, options
, at::ARGUMENT_MODIFIER_NONE
);
53 at::add_format_options(options
);
56 int execute(const po::variables_map
&vm
) {
58 std::string pool_name
;
59 std::string image_name
;
60 std::string snap_name
;
61 int r
= utils::get_pool_image_snapshot_names(
62 vm
, at::ARGUMENT_MODIFIER_NONE
, &arg_index
, &pool_name
, &image_name
,
63 &snap_name
, utils::SNAPSHOT_PRESENCE_REQUIRED
, utils::SPEC_VALIDATION_NONE
);
68 at::Format::Formatter formatter
;
69 r
= utils::get_formatter(vm
, &formatter
);
74 librados::Rados rados
;
75 librados::IoCtx io_ctx
;
77 r
= utils::init_and_open_image(pool_name
, image_name
, "", snap_name
, true,
78 &rados
, &io_ctx
, &image
);
83 r
= do_list_children(image
, formatter
.get());
85 std::cerr
<< "rbd: listing children failed: " << cpp_strerror(r
)
93 {"children"}, {}, "Display children of snapshot.", "", &get_arguments
,
96 } // namespace children