Initialize pool for use by RBD. Newly created pools must initialized
prior to use.
-:command:`resize` (-s | --size *size-in-M/G/T*) [--allow-shrink] *image-spec*
+:command:`resize` (-s | --size *size-in-M/G/T*) [--allow-shrink] [--encryption-format *encryption-format* --encryption-passphrase-file *passphrase-file*]... *image-spec*
Resize rbd image. The size parameter also needs to be specified.
The --allow-shrink option lets the size be reduced.
#include "librbd/Utils.h"
#include "librbd/api/Config.h"
#include "librbd/asio/ContextWQ.h"
+#include "librbd/io/Utils.h"
#include "librbd/journal/DisabledPolicy.h"
#include "librbd/journal/StandardPolicy.h"
#include "librbd/operation/DisableFeaturesRequest.h"
CephContext *cct = m_image_ctx.cct;
m_image_ctx.image_lock.lock_shared();
- ldout(cct, 5) << this << " " << __func__ << ": "
- << "size=" << m_image_ctx.size << ", "
- << "new_size=" << size << dendl;
+ uint64_t raw_size = io::util::area_to_raw_offset(m_image_ctx, size,
+ io::ImageArea::DATA);
+ ldout(cct, 5) << this << " " << __func__
+ << ": size=" << size
+ << " raw_size=" << m_image_ctx.size
+ << " new_raw_size=" << raw_size << dendl;
m_image_ctx.image_lock.unlock_shared();
int r = m_image_ctx.state->refresh_if_required();
}
if (m_image_ctx.test_features(RBD_FEATURE_OBJECT_MAP) &&
- !ObjectMap<>::is_compatible(m_image_ctx.layout, size)) {
+ !ObjectMap<>::is_compatible(m_image_ctx.layout, raw_size)) {
lderr(cct) << "New size not compatible with object map" << dendl;
return -EINVAL;
}
CephContext *cct = m_image_ctx.cct;
m_image_ctx.image_lock.lock_shared();
- ldout(cct, 5) << this << " " << __func__ << ": "
- << "size=" << m_image_ctx.size << ", "
- << "new_size=" << size << dendl;
+ uint64_t raw_size = io::util::area_to_raw_offset(m_image_ctx, size,
+ io::ImageArea::DATA);
+ ldout(cct, 5) << this << " " << __func__
+ << ": size=" << size
+ << " raw_size=" << m_image_ctx.size
+ << " new_raw_size=" << raw_size << dendl;
if (m_image_ctx.snap_id != CEPH_NOSNAP || m_image_ctx.read_only ||
m_image_ctx.operations_disabled) {
return;
} else if (m_image_ctx.test_features(RBD_FEATURE_OBJECT_MAP,
m_image_ctx.image_lock) &&
- !ObjectMap<>::is_compatible(m_image_ctx.layout, size)) {
+ !ObjectMap<>::is_compatible(m_image_ctx.layout, raw_size)) {
m_image_ctx.image_lock.unlock_shared();
on_finish->complete(-EINVAL);
return;
m_image_ctx.image_lock.unlock_shared();
operation::ResizeRequest<I> *req = new operation::ResizeRequest<I>(
- m_image_ctx, new C_NotifyUpdate<I>(m_image_ctx, on_finish), size, allow_shrink,
- prog_ctx, journal_op_tid, false);
+ m_image_ctx, new C_NotifyUpdate<I>(m_image_ctx, on_finish), raw_size,
+ allow_shrink, prog_ctx, journal_op_tid, false);
req->send();
}
rbd help resize
usage: rbd resize [--pool <pool>] [--namespace <namespace>]
[--image <image>] --size <size> [--allow-shrink]
- [--no-progress]
+ [--no-progress] [--encryption-format <encryption-format>]
+ [--encryption-passphrase-file <encryption-passphrase-file>]
<image-spec>
Resize (expand or shrink) image.
Positional arguments
- <image-spec> image specification
- (example: [<pool-name>/[<namespace>/]]<image-name>)
+ <image-spec> image specification
+ (example:
+ [<pool-name>/[<namespace>/]]<image-name>)
Optional arguments
- -p [ --pool ] arg pool name
- --namespace arg namespace name
- --image arg image name
- -s [ --size ] arg image size (in M/G/T) [default: M]
- --allow-shrink permit shrinking
- --no-progress disable progress output
+ -p [ --pool ] arg pool name
+ --namespace arg namespace name
+ --image arg image name
+ -s [ --size ] arg image size (in M/G/T) [default: M]
+ --allow-shrink permit shrinking
+ --no-progress disable progress output
+ --encryption-format arg encryption formats [possible values: luks]
+ --encryption-passphrase-file arg path to file containing passphrase for
+ unlocking the image
rbd help snap create
usage: rbd snap create [--pool <pool>] [--namespace <namespace>]
}
}
+TEST_F(TestLibRBD, EncryptedResize)
+{
+ REQUIRE(!is_feature_enabled(RBD_FEATURE_JOURNALING));
+
+ librados::IoCtx ioctx;
+ ASSERT_EQ(0, _rados.ioctx_create(m_pool_name.c_str(), ioctx));
+
+ librbd::RBD rbd;
+ auto name = get_temp_image_name();
+ uint64_t luks2_meta_size = 16 << 20;
+ uint64_t data_size = 10 << 20;
+ std::string passphrase = "some passphrase";
+
+ {
+ int order = 0;
+ ASSERT_EQ(0, create_image_pp(rbd, ioctx, name.c_str(),
+ luks2_meta_size + data_size, &order));
+ librbd::Image image;
+ ASSERT_EQ(0, rbd.open(ioctx, image, name.c_str(), nullptr));
+
+ uint64_t size;
+ ASSERT_EQ(0, image.size(&size));
+ ASSERT_EQ(luks2_meta_size + data_size, size);
+
+ librbd::encryption_luks2_format_options_t opts = {
+ RBD_ENCRYPTION_ALGORITHM_AES256, passphrase};
+ ASSERT_EQ(0, image.encryption_format(RBD_ENCRYPTION_FORMAT_LUKS2, &opts,
+ sizeof(opts)));
+ ASSERT_EQ(0, image.size(&size));
+ ASSERT_EQ(data_size, size);
+ ASSERT_EQ(0, image.resize(data_size * 3));
+ ASSERT_EQ(0, image.size(&size));
+ ASSERT_EQ(data_size * 3, size);
+ }
+
+ {
+ librbd::Image image;
+ ASSERT_EQ(0, rbd.open(ioctx, image, name.c_str(), nullptr));
+
+ uint64_t size;
+ ASSERT_EQ(0, image.size(&size));
+ ASSERT_EQ(luks2_meta_size + data_size * 3, size);
+
+ librbd::encryption_luks_format_options_t opts = {passphrase};
+ ASSERT_EQ(0, image.encryption_load(RBD_ENCRYPTION_FORMAT_LUKS, &opts,
+ sizeof(opts)));
+ ASSERT_EQ(0, image.size(&size));
+ ASSERT_EQ(data_size * 3, size);
+ ASSERT_EQ(0, image.resize(data_size / 2));
+ ASSERT_EQ(0, image.size(&size));
+ ASSERT_EQ(data_size / 2, size);
+ }
+
+ {
+ librbd::Image image;
+ ASSERT_EQ(0, rbd.open(ioctx, image, name.c_str(), nullptr));
+
+ uint64_t size;
+ ASSERT_EQ(0, image.size(&size));
+ ASSERT_EQ(luks2_meta_size + data_size / 2, size);
+
+ librbd::encryption_luks_format_options_t opts = {passphrase};
+ ASSERT_EQ(0, image.encryption_load(RBD_ENCRYPTION_FORMAT_LUKS, &opts,
+ sizeof(opts)));
+ ASSERT_EQ(0, image.size(&size));
+ ASSERT_EQ(data_size / 2, size);
+ ASSERT_EQ(0, image.resize(0));
+ ASSERT_EQ(0, image.size(&size));
+ ASSERT_EQ(0, size);
+ }
+
+ {
+ librbd::Image image;
+ ASSERT_EQ(0, rbd.open(ioctx, image, name.c_str(), nullptr));
+
+ uint64_t size;
+ ASSERT_EQ(0, image.size(&size));
+ ASSERT_EQ(luks2_meta_size, size);
+
+ librbd::encryption_luks_format_options_t opts = {passphrase};
+ ASSERT_EQ(0, image.encryption_load(RBD_ENCRYPTION_FORMAT_LUKS, &opts,
+ sizeof(opts)));
+ ASSERT_EQ(0, image.size(&size));
+ ASSERT_EQ(0, size);
+ ASSERT_EQ(0, image.resize(data_size));
+ ASSERT_EQ(0, image.size(&size));
+ ASSERT_EQ(data_size, size);
+ }
+
+ {
+ librbd::Image image;
+ ASSERT_EQ(0, rbd.open(ioctx, image, name.c_str(), nullptr));
+
+ uint64_t size;
+ ASSERT_EQ(0, image.size(&size));
+ ASSERT_EQ(luks2_meta_size + data_size, size);
+ }
+}
+
#endif
TEST_F(TestLibRBD, TestIOWithIOHint)
options->add_options()
("allow-shrink", po::bool_switch(), "permit shrinking");
at::add_no_progress_option(options);
+ at::add_encryption_options(options);
}
int execute(const po::variables_map &vm,
return r;
}
+ utils::EncryptionOptions encryption_options;
+ r = utils::get_encryption_options(vm, &encryption_options);
+ if (r < 0) {
+ return r;
+ }
+
librados::Rados rados;
librados::IoCtx io_ctx;
librbd::Image image;
return r;
}
+ if (!encryption_options.specs.empty()) {
+ r = image.encryption_load2(encryption_options.specs.data(),
+ encryption_options.specs.size());
+ if (r < 0) {
+ std::cerr << "rbd: encryption load failed: " << cpp_strerror(r)
+ << std::endl;
+ return r;
+ }
+ }
+
librbd::image_info_t info;
r = image.stat(info, sizeof(info));
if (r < 0) {