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 "common/errno.h"
9 #include <boost/program_options.hpp>
15 namespace at = argument_types;
16 namespace po = boost::program_options;
18 static int do_flatten(librbd::Image& image, bool no_progress)
20 utils::ProgressContext pc("Image flatten", no_progress);
21 int r = image.flatten_with_progress(pc);
30 void get_arguments(po::options_description *positional,
31 po::options_description *options) {
32 at::add_image_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
33 at::add_no_progress_option(options);
36 int execute(const po::variables_map &vm) {
38 std::string pool_name;
39 std::string image_name;
40 std::string snap_name;
41 int r = utils::get_pool_image_snapshot_names(
42 vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &image_name,
43 &snap_name, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_NONE);
48 librados::Rados rados;
49 librados::IoCtx io_ctx;
51 r = utils::init_and_open_image(pool_name, image_name, "", "", false,
52 &rados, &io_ctx, &image);
57 r = do_flatten(image, vm[at::NO_PROGRESS].as<bool>());
59 std::cerr << "rbd: flatten error: " << cpp_strerror(r) << std::endl;
66 {"flatten"}, {}, "Fill clone with parent data (make it independent).", "",
67 &get_arguments, &execute);
69 } // namespace flatten