]>
git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd/action/Create.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 "common/errno.h"
9 #include <boost/program_options.hpp>
15 namespace at
= argument_types
;
16 namespace po
= boost::program_options
;
18 static int do_create(librbd::RBD
&rbd
, librados::IoCtx
& io_ctx
,
19 const char *imgname
, uint64_t size
,
20 librbd::ImageOptions
& opts
) {
21 return rbd
.create4(io_ctx
, imgname
, size
, opts
);
24 void get_arguments(po::options_description
*positional
,
25 po::options_description
*options
) {
26 at::add_image_spec_options(positional
, options
, at::ARGUMENT_MODIFIER_NONE
);
27 at::add_create_image_options(options
, true);
28 at::add_size_option(options
);
31 int execute(const po::variables_map
&vm
) {
33 std::string pool_name
;
34 std::string image_name
;
35 std::string snap_name
;
36 int r
= utils::get_pool_image_snapshot_names(
37 vm
, at::ARGUMENT_MODIFIER_NONE
, &arg_index
, &pool_name
, &image_name
,
38 &snap_name
, utils::SNAPSHOT_PRESENCE_NONE
, utils::SPEC_VALIDATION_FULL
);
43 librbd::ImageOptions opts
;
44 r
= utils::get_image_options(vm
, true, &opts
);
50 r
= utils::get_image_size(vm
, &size
);
55 librados::Rados rados
;
56 librados::IoCtx io_ctx
;
57 r
= utils::init(pool_name
, &rados
, &io_ctx
);
63 r
= do_create(rbd
, io_ctx
, image_name
.c_str(), size
, opts
);
65 std::cerr
<< "rbd: create error: " << cpp_strerror(r
) << std::endl
;
72 {"create"}, {}, "Create an empty image.", at::get_long_features_help(),
73 &get_arguments
, &execute
);