#include <iostream>
#include <boost/program_options.hpp>
#include <boost/scoped_ptr.hpp>
-#include "include/assert.h"
+#include "include/ceph_assert.h"
#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_rbd
ImportDiffContext(librbd::Image *image, int fd, size_t size, bool no_progress)
: image(image), fd(fd), size(size), pc("Importing image diff", no_progress),
throttle((fd == STDIN_FILENO) ? 1 :
- g_conf->get_val<int64_t>("rbd_concurrent_management_ops"),
+ g_conf().get_val<uint64_t>("rbd_concurrent_management_ops"),
false),
last_offset(0) {
}
class C_ImportDiff : public Context {
public:
C_ImportDiff(ImportDiffContext *idiffctx, bufferlist data, uint64_t offset,
- uint64_t length, bool discard)
+ uint64_t length, bool write_zeroes)
: m_idiffctx(idiffctx), m_data(data), m_offset(offset), m_length(length),
- m_discard(discard) {
+ m_write_zeroes(write_zeroes) {
// use block offset (stdin) or import file position to report
// progress.
if (m_idiffctx->fd == STDIN_FILENO) {
new librbd::RBD::AioCompletion(ctx, &utils::aio_context_callback);
int r;
- if (m_discard) {
- r = m_idiffctx->image->aio_discard(m_offset, m_length, aio_completion);
+ if (m_write_zeroes) {
+ r = m_idiffctx->image->aio_write_zeroes(m_offset, m_length,
+ aio_completion, 0U,
+ LIBRADOS_OP_FLAG_FADVISE_NOCACHE);
} else {
r = m_idiffctx->image->aio_write2(m_offset, m_length, m_data,
- aio_completion, LIBRADOS_OP_FLAG_FADVISE_NOCACHE);
+ aio_completion,
+ LIBRADOS_OP_FLAG_FADVISE_NOCACHE);
}
if (r < 0) {
bufferlist m_data;
uint64_t m_offset;
uint64_t m_length;
- bool m_discard;
+ bool m_write_zeroes;
uint64_t m_prog_offset;
};
bufferlist bl;
bl.append(buf, sizeof(buf));
- bufferlist::iterator p = bl.begin();
- ::decode(end_size, p);
+ auto p = bl.cbegin();
+ decode(end_size, p);
uint64_t cur_size;
idiffctx->image->size(&cur_size);
return 0;
}
-static int do_image_io(ImportDiffContext *idiffctx, bool discard, size_t sparse_size)
+static int do_image_io(ImportDiffContext *idiffctx, bool write_zeroes,
+ size_t sparse_size)
{
int r;
char buf[16];
bufferlist bl;
bl.append(buf, sizeof(buf));
- bufferlist::iterator p = bl.begin();
+ auto p = bl.cbegin();
uint64_t image_offset, buffer_length;
- ::decode(image_offset, p);
- ::decode(buffer_length, p);
+ decode(image_offset, p);
+ decode(buffer_length, p);
- if (!discard) {
+ if (!write_zeroes) {
bufferptr bp = buffer::create(buffer_length);
r = safe_read_exact(idiffctx->fd, bp.c_str(), buffer_length);
if (r < 0) {
bool zeroed = false;
utils::calc_sparse_extent(bp, sparse_size, buffer_offset, buffer_length,
&write_length, &zeroed);
- assert(write_length > 0);
+ ceph_assert(write_length > 0);
bufferlist write_bl;
if (!zeroed) {
bufferptr write_ptr(bp, buffer_offset, write_length);
write_bl.push_back(write_ptr);
- assert(write_bl.length() == write_length);
+ ceph_assert(write_bl.length() == write_length);
}
C_ImportDiff *ctx = new C_ImportDiff(idiffctx, write_bl,
bufferlist bl;
bl.append(buf, sizeof(buf));
- bufferlist::iterator p = bl.begin();
- ::decode(*readlen, p);
+ auto p = bl.cbegin();
+ decode(*readlen, p);
}
return 0;
return r;
}
- std::string skip_partial_discard;
- r = rados.conf_get("rbd_skip_partial_discard", skip_partial_discard);
- if (r < 0 || skip_partial_discard != "false") {
- dout(1) << "disabling sparse import" << dendl;
- sparse_size = 0;
- r = 0;
- }
-
// begin image import
std::string tosnap;
bool is_protected = false;
if (strcmp(path, "-") == 0) {
fd = STDIN_FILENO;
} else {
- fd = open(path, O_RDONLY);
+ fd = open(path, O_RDONLY|O_BINARY);
if (fd < 0) {
r = -errno;
std::cerr << "rbd: error opening " << path << std::endl;
at::add_no_progress_option(options);
}
-int execute_diff(const po::variables_map &vm) {
+int execute_diff(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
std::string path;
- int r = utils::get_path(vm, utils::get_positional_argument(vm, 0), &path);
+ size_t arg_index = 0;
+ int r = utils::get_path(vm, &arg_index, &path);
if (r < 0) {
return r;
}
- size_t arg_index = 1;
std::string pool_name;
+ std::string namespace_name;
std::string image_name;
std::string snap_name;
r = utils::get_pool_image_snapshot_names(
- vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &image_name,
- &snap_name, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_NONE);
+ vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &namespace_name,
+ &image_name, &snap_name, true, utils::SNAPSHOT_PRESENCE_NONE,
+ utils::SPEC_VALIDATION_NONE);
if (r < 0) {
return r;
}
librados::Rados rados;
librados::IoCtx io_ctx;
librbd::Image image;
- r = utils::init_and_open_image(pool_name, image_name, "", "", false,
- &rados, &io_ctx, &image);
+ r = utils::init_and_open_image(pool_name, namespace_name, image_name, "", "",
+ false, &rados, &io_ctx, &image);
if (r < 0) {
return r;
}
bufferlist bl;
bl.append(buf, sizeof(buf));
- bufferlist::iterator it;
- it = bl.begin();
+ auto it = bl.cbegin();
uint64_t val;
- ::decode(val, it);
+ decode(val, it);
if (opts.get(imageopt, &val) != 0) {
opts.set(imageopt, val);
while (r == 0) {
__u8 tag;
- uint64_t length;
+ uint64_t length = 0;
r = read_tag(fd, RBD_EXPORT_IMAGE_END, image_format, &tag, &length);
if (r < 0 || tag == RBD_EXPORT_IMAGE_END) {
break;
}
bufferlist bl;
bl.append(buf, sizeof(buf));
- bufferlist::iterator p = bl.begin();
+ auto p = bl.cbegin();
uint64_t diff_num;
- ::decode(diff_num, p);
-
+ decode(diff_num, p);
for (size_t i = 0; i < diff_num; i++) {
r = do_import_diff_fd(rados, image, fd, true, 2, sparse_size);
if (r < 0) {
throttle.reset(new SimpleThrottle(1, false));
} else {
throttle.reset(new SimpleThrottle(
- g_conf->get_val<int64_t>("rbd_concurrent_management_ops"), false));
+ g_conf().get_val<uint64_t>("rbd_concurrent_management_ops"), false));
}
reqlen = min<uint64_t>(reqlen, size);
bufferlist write_bl;
bufferptr write_ptr(blkptr, buffer_offset, write_length);
write_bl.push_back(write_ptr);
- assert(write_bl.length() == write_length);
+ ceph_assert(write_bl.length() == write_length);
C_Import *ctx = new C_Import(*throttle, image, write_bl,
image_pos + buffer_offset);
utils::ProgressContext pc("Importing image", no_progress);
std::map<std::string, std::string> imagemetas;
- assert(imgname);
+ ceph_assert(imgname);
uint64_t order;
if (opts.get(RBD_IMAGE_OPTION_ORDER, &order) != 0) {
- order = g_conf->get_val<int64_t>("rbd_default_order");
+ order = g_conf().get_val<uint64_t>("rbd_default_order");
}
// try to fill whole imgblklen blocks for sparsification
fd = STDIN_FILENO;
size = 1ULL << order;
} else {
- if ((fd = open(path, O_RDONLY)) < 0) {
+ if ((fd = open(path, O_RDONLY|O_BINARY)) < 0) {
r = -errno;
std::cerr << "rbd: error opening " << path << std::endl;
goto done2;
if (!size) {
int64_t bdev_size = 0;
- r = get_block_device_size(fd, &bdev_size);
+ BlkDev blkdev(fd);
+ r = blkdev.get_size(&bdev_size);
if (r < 0) {
std::cerr << "rbd: unable to get size of file/block device"
<< std::endl;
goto done;
}
- assert(bdev_size >= 0);
+ ceph_assert(bdev_size >= 0);
size = (uint64_t) bdev_size;
}
#ifdef HAVE_POSIX_FADVISE
// TODO legacy rbd allowed import to accept both 'image'/'dest' and
// 'pool'/'dest-pool'
- at::add_pool_option(options, at::ARGUMENT_MODIFIER_NONE, " (deprecated)");
- at::add_image_option(options, at::ARGUMENT_MODIFIER_NONE, " (deprecated)");
+ at::add_pool_option(options, at::ARGUMENT_MODIFIER_NONE, " deprecated[:dest-pool]");
+ at::add_image_option(options, at::ARGUMENT_MODIFIER_NONE, " deprecated[:dest]");
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
std::string path;
- int r = utils::get_path(vm, utils::get_positional_argument(vm, 0), &path);
+ size_t arg_index = 0;
+ int r = utils::get_path(vm, &arg_index, &path);
if (r < 0) {
return r;
}
std::string deprecated_pool_name;
if (vm.count(at::POOL_NAME)) {
deprecated_pool_name = vm[at::POOL_NAME].as<std::string>();
- std::cerr << "rbd: --pool is deprecated for import, use --dest-pool"
- << std::endl;
}
std::string deprecated_image_name;
if (vm.count(at::IMAGE_NAME)) {
deprecated_image_name = vm[at::IMAGE_NAME].as<std::string>();
- std::cerr << "rbd: --image is deprecated for import, use --dest"
- << std::endl;
} else {
- deprecated_image_name = path.substr(path.find_last_of("/") + 1);
+ deprecated_image_name = path.substr(path.find_last_of("/\\") + 1);
}
std::string deprecated_snap_name;
r = utils::extract_spec(deprecated_image_name, &deprecated_pool_name,
- &deprecated_image_name, &deprecated_snap_name,
- utils::SPEC_VALIDATION_FULL);
+ nullptr, &deprecated_image_name,
+ &deprecated_snap_name, utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
sparse_size = vm[at::IMAGE_SPARSE_SIZE].as<size_t>();
}
- size_t arg_index = 1;
std::string pool_name = deprecated_pool_name;
+ std::string namespace_name;
std::string image_name;
std::string snap_name = deprecated_snap_name;
r = utils::get_pool_image_snapshot_names(
- vm, at::ARGUMENT_MODIFIER_DEST, &arg_index, &pool_name, &image_name,
- &snap_name, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL,
- false);
+ vm, at::ARGUMENT_MODIFIER_DEST, &arg_index, &pool_name, &namespace_name,
+ &image_name, &snap_name, false, utils::SNAPSHOT_PRESENCE_NONE,
+ utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
librados::Rados rados;
librados::IoCtx io_ctx;
- r = utils::init(pool_name, &rados, &io_ctx);
+ r = utils::init(pool_name, namespace_name, &rados, &io_ctx);
if (r < 0) {
return r;
}