Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

librbd: initial set of changes to migration API for instant-restore #37714

Merged
merged 13 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 38 additions & 15 deletions src/cls/rbd/cls_rbd_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,12 @@ std::ostream& operator<<(std::ostream& os,
}

void MigrationSpec::encode(bufferlist& bl) const {
ENCODE_START(2, 1, bl);
uint8_t min_version = 1;
if (!source_spec.empty()) {
min_version = 3;
}

ENCODE_START(3, min_version, bl);
encode(header_type, bl);
encode(pool_id, bl);
encode(pool_namespace, bl);
Expand All @@ -1232,11 +1237,12 @@ void MigrationSpec::encode(bufferlist& bl) const {
encode(state, bl);
encode(state_description, bl);
encode(static_cast<uint8_t>(mirror_image_mode), bl);
encode(source_spec, bl);
ENCODE_FINISH(bl);
}

void MigrationSpec::decode(bufferlist::const_iterator& bl) {
DECODE_START(2, bl);
DECODE_START(3, bl);
decode(header_type, bl);
decode(pool_id, bl);
decode(pool_namespace, bl);
Expand All @@ -1253,7 +1259,10 @@ void MigrationSpec::decode(bufferlist::const_iterator& bl) {
decode(int_mode, bl);
mirror_image_mode = static_cast<MirrorImageMode>(int_mode);
}
DECODE_FINISH(bl);
if (struct_v >= 3) {
decode(source_spec, bl);
}
DECODE_FINISH(bl);
}

std::ostream& operator<<(std::ostream& os,
Expand All @@ -1270,10 +1279,15 @@ std::ostream& operator<<(std::ostream& os,

void MigrationSpec::dump(Formatter *f) const {
f->dump_stream("header_type") << header_type;
f->dump_int("pool_id", pool_id);
f->dump_string("pool_namespace", pool_namespace);
f->dump_string("image_name", image_name);
f->dump_string("image_id", image_id);
if (header_type == MIGRATION_HEADER_TYPE_SRC ||
source_spec.empty()) {
f->dump_int("pool_id", pool_id);
f->dump_string("pool_namespace", pool_namespace);
f->dump_string("image_name", image_name);
f->dump_string("image_id", image_id);
} else {
f->dump_string("source_spec", source_spec);
}
f->dump_stream("snap_seqs") << snap_seqs;
f->dump_unsigned("overlap", overlap);
f->dump_bool("mirroring", mirroring);
Expand All @@ -1283,20 +1297,29 @@ void MigrationSpec::dump(Formatter *f) const {
void MigrationSpec::generate_test_instances(std::list<MigrationSpec*> &o) {
o.push_back(new MigrationSpec());
o.push_back(new MigrationSpec(MIGRATION_HEADER_TYPE_SRC, 1, "ns",
"image_name", "image_id", {{1, 2}}, 123, true,
MIRROR_IMAGE_MODE_SNAPSHOT, true,
"image_name", "image_id", "", {{1, 2}}, 123,
true, MIRROR_IMAGE_MODE_SNAPSHOT, true,
MIGRATION_STATE_PREPARED, "description"));
o.push_back(new MigrationSpec(MIGRATION_HEADER_TYPE_DST, -1, "", "", "",
"{\"format\": \"raw\"}", {{1, 2}}, 123,
true, MIRROR_IMAGE_MODE_SNAPSHOT, true,
MIGRATION_STATE_PREPARED, "description"));
}

std::ostream& operator<<(std::ostream& os,
const MigrationSpec& migration_spec) {
os << "["
<< "header_type=" << migration_spec.header_type << ", "
<< "pool_id=" << migration_spec.pool_id << ", "
<< "pool_namespace=" << migration_spec.pool_namespace << ", "
<< "image_name=" << migration_spec.image_name << ", "
<< "image_id=" << migration_spec.image_id << ", "
<< "snap_seqs=" << migration_spec.snap_seqs << ", "
<< "header_type=" << migration_spec.header_type << ", ";
if (migration_spec.header_type == MIGRATION_HEADER_TYPE_SRC ||
migration_spec.source_spec.empty()) {
os << "pool_id=" << migration_spec.pool_id << ", "
<< "pool_namespace=" << migration_spec.pool_namespace << ", "
<< "image_name=" << migration_spec.image_name << ", "
<< "image_id=" << migration_spec.image_id << ", ";
} else {
os << "source_spec=" << migration_spec.source_spec << ", ";
}
os << "snap_seqs=" << migration_spec.snap_seqs << ", "
<< "overlap=" << migration_spec.overlap << ", "
<< "flatten=" << migration_spec.flatten << ", "
<< "mirroring=" << migration_spec.mirroring << ", "
Expand Down
17 changes: 10 additions & 7 deletions src/cls/rbd/cls_rbd_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,7 @@ struct MigrationSpec {
std::string pool_namespace;
std::string image_name;
std::string image_id;
std::string source_spec;
std::map<uint64_t, uint64_t> snap_seqs;
uint64_t overlap = 0;
bool flatten = false;
Expand All @@ -962,14 +963,15 @@ struct MigrationSpec {
}
MigrationSpec(MigrationHeaderType header_type, int64_t pool_id,
const std::string& pool_namespace,
const std::string &image_name, const std::string &image_id,
const std::string& image_name, const std::string &image_id,
const std::string& source_spec,
const std::map<uint64_t, uint64_t> &snap_seqs, uint64_t overlap,
bool mirroring, MirrorImageMode mirror_image_mode, bool flatten,
MigrationState state, const std::string &state_description)
: header_type(header_type), pool_id(pool_id),
pool_namespace(pool_namespace), image_name(image_name),
image_id(image_id), snap_seqs(snap_seqs), overlap(overlap),
flatten(flatten), mirroring(mirroring),
image_id(image_id), source_spec(source_spec), snap_seqs(snap_seqs),
overlap(overlap), flatten(flatten), mirroring(mirroring),
mirror_image_mode(mirror_image_mode), state(state),
state_description(state_description) {
}
Expand All @@ -983,10 +985,11 @@ struct MigrationSpec {
inline bool operator==(const MigrationSpec& ms) const {
return header_type == ms.header_type && pool_id == ms.pool_id &&
pool_namespace == ms.pool_namespace && image_name == ms.image_name &&
image_id == ms.image_id && snap_seqs == ms.snap_seqs &&
overlap == ms.overlap && flatten == ms.flatten &&
mirroring == ms.mirroring && mirror_image_mode == ms.mirror_image_mode &&
state == ms.state && state_description == ms.state_description;
image_id == ms.image_id && source_spec == ms.source_spec &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just wondering, wouldn't it be more correct to compare the source spec just after comparing the header type?

It wouldn't make any difference in real life though I suppose...

snap_seqs == ms.snap_seqs && overlap == ms.overlap &&
flatten == ms.flatten && mirroring == ms.mirroring &&
mirror_image_mode == ms.mirror_image_mode && state == ms.state &&
state_description == ms.state_description;
}
};

Expand Down
4 changes: 4 additions & 0 deletions src/include/rbd/librbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,10 @@ CEPH_RBD_API int rbd_get_parent(rbd_image_t image,
rbd_linked_image_spec_t *parent_image,
rbd_snap_spec_t *parent_snap);

CEPH_RBD_API int rbd_get_migration_source_spec(rbd_image_t image,
char* source_spec,
size_t* max_len);

CEPH_RBD_API int rbd_get_flags(rbd_image_t image, uint64_t *flags);
CEPH_RBD_API int rbd_get_group(rbd_image_t image, rbd_group_info_t *group_info,
size_t group_info_size);
Expand Down
2 changes: 2 additions & 0 deletions src/include/rbd/librbd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ class CEPH_RBD_API Image
CEPH_RBD_DEPRECATED;
int get_parent(linked_image_spec_t *parent_image, snap_spec_t *parent_snap);

int get_migration_source_spec(std::string* source_spec);

int old_format(uint8_t *old);
int size(uint64_t *size);
int get_group(group_info_t *group_info, size_t group_info_size);
Expand Down
5 changes: 5 additions & 0 deletions src/librbd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ set(librbd_internal_srcs
managed_lock/ReacquireRequest.cc
managed_lock/ReleaseRequest.cc
managed_lock/Utils.cc
migration/FileStream.cc
migration/ImageDispatch.cc
migration/NativeFormat.cc
migration/OpenSourceImageRequest.cc
migration/RawFormat.cc
mirror/DemoteRequest.cc
mirror/DisableRequest.cc
mirror/EnableRequest.cc
Expand Down
6 changes: 6 additions & 0 deletions src/librbd/ImageCtx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ librados::IoCtx duplicate_io_ctx(librados::IoCtx& io_ctx) {
asok_hook(nullptr),
trace_endpoint("librbd")
{
ldout(cct, 10) << this << " " << __func__ << ": "
<< "image_name=" << image_name << ", "
<< "image_id=" << image_id << dendl;

if (snap)
snap_name = snap;

Expand All @@ -147,6 +151,8 @@ librados::IoCtx duplicate_io_ctx(librados::IoCtx& io_ctx) {
}

ImageCtx::~ImageCtx() {
ldout(cct, 10) << this << " " << __func__ << dendl;

ceph_assert(config_watcher == nullptr);
ceph_assert(image_watcher == NULL);
ceph_assert(exclusive_lock == NULL);
Expand Down
8 changes: 5 additions & 3 deletions src/librbd/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ struct MigrationInfo {
std::string pool_namespace;
std::string image_name;
std::string image_id;
std::string source_spec;
deep_copy::SnapMap snap_map;
uint64_t overlap = 0;
bool flatten = false;
Expand All @@ -123,15 +124,16 @@ struct MigrationInfo {
}
MigrationInfo(int64_t pool_id, const std::string& pool_namespace,
const std::string& image_name, const std::string& image_id,
const std::string& source_spec,
const deep_copy::SnapMap &snap_map, uint64_t overlap,
bool flatten)
: pool_id(pool_id), pool_namespace(pool_namespace), image_name(image_name),
image_id(image_id), snap_map(snap_map), overlap(overlap),
flatten(flatten) {
image_id(image_id), source_spec(source_spec), snap_map(snap_map),
overlap(overlap), flatten(flatten) {
}

bool empty() const {
return pool_id == -1;
return (pool_id == -1 && source_spec.empty());
}
};

Expand Down
Loading