[--journal-object-size <journal-object-size>]
[--journal-pool <journal-pool>]
[--sparse-size <sparse-size>] [--no-progress]
- [--export-format <export-format>] [--pool <pool>]
+ [--export-format <export-format>]
+ [--estimated-size <estimated-size>] [--pool <pool>]
[--image <image>]
<path-name> <dest-image-spec>
--sparse-size arg sparse size in B/K/M [default: 4K]
--no-progress disable progress output
--export-format arg format of image file
+ --estimated-size arg estimated image size (valid only for raw import
+ from stdin, in M/G/T) [default: M]
Image Features:
(*) supports enabling/disabling on existing images
static const std::string IMAGE_FEATURES("image-feature");
static const std::string IMAGE_SHARED("image-shared");
static const std::string IMAGE_SIZE("size");
+static const std::string IMAGE_ESTIMATED_SIZE("estimated-size");
static const std::string IMAGE_STRIPE_UNIT("stripe-unit");
static const std::string IMAGE_STRIPE_COUNT("stripe-count");
static const std::string IMAGE_DATA_POOL("data-pool");
void add_size_option(boost::program_options::options_description *opt);
+void add_estimated_size_option(boost::program_options::options_description *opt);
+
void add_sparse_size_option(boost::program_options::options_description *opt);
void add_path_options(boost::program_options::options_description *pos,
static int do_import_v1(int fd, librbd::Image &image, uint64_t size,
size_t imgblklen, utils::ProgressContext &pc,
- size_t sparse_size)
+ size_t sparse_size, size_t estimated_size)
{
int r = 0;
size_t reqlen = imgblklen; // amount requested from read
}
if (!from_stdin)
pc.update_progress(image_pos, size);
+ else if (estimated_size != 0)
+ pc.update_progress(image_pos, estimated_size);
bufferptr blkptr(p, blklen);
// resize output image by binary expansion as we go for stdin
static int do_import(librados::Rados &rados, librbd::RBD &rbd,
librados::IoCtx& io_ctx, const char *imgname,
const char *path, librbd::ImageOptions& opts,
- bool no_progress, int import_format, size_t sparse_size)
+ bool no_progress, int import_format, size_t sparse_size,
+ size_t estimated_size)
{
int fd, r;
struct stat stat_buf;
bool from_stdin = !strcmp(path, "-");
if (from_stdin) {
fd = STDIN_FILENO;
- size = 1ULL << order;
+ if (estimated_size == 0) {
+ size = 1ULL << order;
+ } else {
+ size = estimated_size;
+ }
} else {
if ((fd = open(path, O_RDONLY|O_BINARY)) < 0) {
r = -errno;
}
if (import_format == 1) {
- r = do_import_v1(fd, image, size, imgblklen, pc, sparse_size);
+ r = do_import_v1(fd, image, size, imgblklen, pc, sparse_size,
+ estimated_size);
} else {
r = do_import_v2(rados, fd, image, size, imgblklen, pc, sparse_size);
}
at::add_sparse_size_option(options);
at::add_no_progress_option(options);
at::add_export_format_option(options);
+ at::add_estimated_size_option(options);
// TODO legacy rbd allowed import to accept both 'image'/'dest' and
// 'pool'/'dest-pool'
if (vm.count("export-format"))
format = vm["export-format"].as<uint64_t>();
+ size_t estimated_size = 0;
+ if (vm.count(at::IMAGE_ESTIMATED_SIZE)) {
+ if (path != "-") {
+ std::cerr << "rbd: --estimated-size can be specified "
+ << "only for import from stdin" << std::endl;
+ return -EINVAL;
+ }
+ if (format != 1) {
+ std::cerr << "rbd: --estimated-size can be specified "
+ << "only for raw import (--export-format 1)" << std::endl;
+ return -EINVAL;
+ }
+ estimated_size = vm[at::IMAGE_ESTIMATED_SIZE].as<size_t>();
+ }
+
librbd::RBD rbd;
r = do_import(rados, rbd, io_ctx, image_name.c_str(), path.c_str(),
- opts, vm[at::NO_PROGRESS].as<bool>(), format, sparse_size);
+ opts, vm[at::NO_PROGRESS].as<bool>(), format, sparse_size,
+ estimated_size);
if (r < 0) {
std::cerr << "rbd: import failed: " << cpp_strerror(r) << std::endl;
return r;