@@ -725,7 +725,7 @@ static int do_import_v2(librados::Rados &rados, int fd, librbd::Image &image,
725725
726726static int do_import_v1 (int fd, librbd::Image &image, uint64_t size,
727727 size_t imgblklen, utils::ProgressContext &pc,
728- size_t sparse_size)
728+ size_t sparse_size, size_t estimated_size )
729729{
730730 int r = 0 ;
731731 size_t reqlen = imgblklen; // amount requested from read
@@ -758,6 +758,8 @@ static int do_import_v1(int fd, librbd::Image &image, uint64_t size,
758758 }
759759 if (!from_stdin)
760760 pc.update_progress (image_pos, size);
761+ else if (estimated_size != 0 )
762+ pc.update_progress (image_pos, estimated_size);
761763
762764 bufferptr blkptr (p, blklen);
763765 // resize output image by binary expansion as we go for stdin
@@ -823,7 +825,8 @@ static int do_import_v1(int fd, librbd::Image &image, uint64_t size,
823825static int do_import (librados::Rados &rados, librbd::RBD &rbd,
824826 librados::IoCtx& io_ctx, const char *imgname,
825827 const char *path, librbd::ImageOptions& opts,
826- bool no_progress, int import_format, size_t sparse_size)
828+ bool no_progress, int import_format, size_t sparse_size,
829+ size_t estimated_size)
827830{
828831 int fd, r;
829832 struct stat stat_buf;
@@ -845,7 +848,11 @@ static int do_import(librados::Rados &rados, librbd::RBD &rbd,
845848 bool from_stdin = !strcmp (path, " -" );
846849 if (from_stdin) {
847850 fd = STDIN_FILENO;
848- size = 1ULL << order;
851+ if (estimated_size == 0 ) {
852+ size = 1ULL << order;
853+ } else {
854+ size = estimated_size;
855+ }
849856 } else {
850857 if ((fd = open (path, O_RDONLY|O_BINARY)) < 0 ) {
851858 r = -errno;
@@ -908,7 +915,8 @@ static int do_import(librados::Rados &rados, librbd::RBD &rbd,
908915 }
909916
910917 if (import_format == 1 ) {
911- r = do_import_v1 (fd, image, size, imgblklen, pc, sparse_size);
918+ r = do_import_v1 (fd, image, size, imgblklen, pc, sparse_size,
919+ estimated_size);
912920 } else {
913921 r = do_import_v2 (rados, fd, image, size, imgblklen, pc, sparse_size);
914922 }
@@ -942,6 +950,7 @@ void get_arguments(po::options_description *positional,
942950 at::add_sparse_size_option (options);
943951 at::add_no_progress_option (options);
944952 at::add_export_format_option (options);
953+ at::add_estimated_size_option (options);
945954
946955 // TODO legacy rbd allowed import to accept both 'image'/'dest' and
947956 // 'pool'/'dest-pool'
@@ -1017,9 +1026,25 @@ int execute(const po::variables_map &vm,
10171026 if (vm.count (" export-format" ))
10181027 format = vm[" export-format" ].as <uint64_t >();
10191028
1029+ size_t estimated_size = 0 ;
1030+ if (vm.count (at::IMAGE_ESTIMATED_SIZE)) {
1031+ if (path != " -" ) {
1032+ std::cerr << " rbd: --estimated-size can be specified "
1033+ << " only for import from stdin" << std::endl;
1034+ return -EINVAL;
1035+ }
1036+ if (format != 1 ) {
1037+ std::cerr << " rbd: --estimated-size can be specified "
1038+ << " only for raw import (--export-format 1)" << std::endl;
1039+ return -EINVAL;
1040+ }
1041+ estimated_size = vm[at::IMAGE_ESTIMATED_SIZE].as <size_t >();
1042+ }
1043+
10201044 librbd::RBD rbd;
10211045 r = do_import (rados, rbd, io_ctx, image_name.c_str (), path.c_str (),
1022- opts, vm[at::NO_PROGRESS].as <bool >(), format, sparse_size);
1046+ opts, vm[at::NO_PROGRESS].as <bool >(), format, sparse_size,
1047+ estimated_size);
10231048 if (r < 0 ) {
10241049 std::cerr << " rbd: import failed: " << cpp_strerror (r) << std::endl;
10251050 return r;
0 commit comments