]>
git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd/action/Status.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset: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 "include/rbd_types.h"
8 #include "common/errno.h"
9 #include "common/Formatter.h"
11 #include <boost/program_options.hpp>
17 namespace at
= argument_types
;
18 namespace po
= boost::program_options
;
20 static int do_show_status(librados::IoCtx
&io_ctx
, librbd::Image
&image
,
21 const char *imgname
, Formatter
*f
)
25 std::string header_oid
;
26 std::list
<obj_watch_t
> watchers
;
28 r
= image
.old_format(&old_format
);
34 header_oid
+= RBD_SUFFIX
;
37 r
= image
.get_id(&id
);
42 header_oid
= RBD_HEADER_PREFIX
+ id
;
45 r
= io_ctx
.list_watchers(header_oid
, &watchers
);
50 f
->open_object_section("status");
53 f
->open_array_section("watchers");
54 for (std::list
<obj_watch_t
>::iterator i
= watchers
.begin(); i
!= watchers
.end(); ++i
) {
55 f
->open_object_section("watcher");
56 f
->dump_string("address", i
->addr
);
57 f
->dump_unsigned("client", i
->watcher_id
);
58 f
->dump_unsigned("cookie", i
->cookie
);
63 if (watchers
.size()) {
64 std::cout
<< "Watchers:" << std::endl
;
65 for (std::list
<obj_watch_t
>::iterator i
= watchers
.begin();
66 i
!= watchers
.end(); ++i
) {
67 std::cout
<< "\twatcher=" << i
->addr
<< " client." << i
->watcher_id
68 << " cookie=" << i
->cookie
<< std::endl
;
71 std::cout
<< "Watchers: none" << std::endl
;
82 void get_arguments(po::options_description
*positional
,
83 po::options_description
*options
) {
84 at::add_image_spec_options(positional
, options
, at::ARGUMENT_MODIFIER_NONE
);
85 at::add_format_options(options
);
88 int execute(const po::variables_map
&vm
) {
90 std::string pool_name
;
91 std::string image_name
;
92 std::string snap_name
;
93 int r
= utils::get_pool_image_snapshot_names(
94 vm
, at::ARGUMENT_MODIFIER_NONE
, &arg_index
, &pool_name
, &image_name
,
95 &snap_name
, utils::SNAPSHOT_PRESENCE_NONE
, utils::SPEC_VALIDATION_NONE
);
100 at::Format::Formatter formatter
;
101 r
= utils::get_formatter(vm
, &formatter
);
106 librados::Rados rados
;
107 librados::IoCtx io_ctx
;
109 r
= utils::init_and_open_image(pool_name
, image_name
, "", "", true, &rados
,
115 r
= do_show_status(io_ctx
, image
, image_name
.c_str(), formatter
.get());
117 std::cerr
<< "rbd: show status failed: " << cpp_strerror(r
) << std::endl
;
123 Shell::Action
action(
124 {"status"}, {}, "Show the status of this image.", "", &get_arguments
,
127 } // namespace status
128 } // namespace action