Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Yuji Ito <llamerada.jp@gmail.com>
  • Loading branch information
llamerada-jp committed Jan 9, 2025
1 parent 664f7bb commit 7a3a3d3
Showing 1 changed file with 45 additions and 49 deletions.
94 changes: 45 additions & 49 deletions ceph/custom-export.patch
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// encryption arguments
static const std::string ENCRYPTION_FORMAT("encryption-format");
diff --git a/src/tools/rbd/action/Export.cc b/src/tools/rbd/action/Export.cc
index ddcf0f2c30cef..491d38d0d5c5e 100644
index ddcf0f2c30cef..fbe2a57488516 100644
--- a/src/tools/rbd/action/Export.cc
+++ b/src/tools/rbd/action/Export.cc
@@ -123,8 +123,8 @@ class C_ExportDiff : public Context {
Expand Down Expand Up @@ -71,7 +71,7 @@ index ddcf0f2c30cef..491d38d0d5c5e 100644

if (fd != 1)
close(fd);
@@ -260,7 +266,11 @@ void get_arguments_diff(po::options_description *positional,
@@ -260,10 +266,52 @@ void get_arguments_diff(po::options_description *positional,
options->add_options()
(at::FROM_SNAPSHOT_NAME.c_str(), po::value<std::string>(),
"snapshot starting point")
Expand All @@ -84,7 +84,48 @@ index ddcf0f2c30cef..491d38d0d5c5e 100644
at::add_no_progress_option(options);
}

@@ -290,6 +300,26 @@ int execute_diff(const po::variables_map &vm,
+int get_snapshot_name_for_offset_length(librbd::Image& image,
+ const std::string& mid_snap_prefix,
+ std::string* from_snap_name,
+ std::string* snap_name,
+ uint64_t* offset, uint64_t* length)
+{
+ int r;
+ librbd::image_info_t info;
+
+ r = image.stat(info, sizeof(info));
+ if (r < 0)
+ return r;
+
+ // ⚠️ should be test when offset == info.size
+ if (*offset > info.size) {
+ std::cerr << "rbd: offset " << *offset << " exceeds image size "
+ << info.size << std::endl;
+ return -EINVAL;
+ }
+
+ if (*offset > 0) {
+ *from_snap_name = mid_snap_prefix + "-" + std::to_string(*offset);
+ }
+
+ if (*length == 0) {
+ *length = info.size - *offset;
+ return 0;
+ }
+
+ if (*offset + *length < info.size) {
+ *snap_name = mid_snap_prefix + "-" + std::to_string(*offset + *length);
+ } else {
+ *length = info.size - *offset;
+ }
+
+ return 0;
+}
+
int execute_diff(const po::variables_map &vm,
const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
@@ -290,6 +338,26 @@ int execute_diff(const po::variables_map &vm,
from_snap_name = vm[at::FROM_SNAPSHOT_NAME].as<std::string>();
}

Expand All @@ -111,7 +152,7 @@ index ddcf0f2c30cef..491d38d0d5c5e 100644
librados::Rados rados;
librados::IoCtx io_ctx;
librbd::Image image;
@@ -299,9 +329,19 @@ int execute_diff(const po::variables_map &vm,
@@ -299,9 +367,19 @@ int execute_diff(const po::variables_map &vm,
return r;
}

Expand All @@ -131,51 +172,6 @@ index ddcf0f2c30cef..491d38d0d5c5e 100644
vm[at::WHOLE_OBJECT].as<bool>(), path.c_str(),
vm[at::NO_PROGRESS].as<bool>());
if (r < 0) {
@@ -311,6 +351,44 @@ int execute_diff(const po::variables_map &vm,
return 0;
}

+int get_snapshot_name_for_offset_length(librbd::Image& image,
+ const std::string& mid_snap_prefix,
+ std::string* from_snap_name,
+ std::string* snap_name,
+ uint64_t* offset, uint64_t* length)
+{
+ int r;
+ librbd::image_info_t info;
+
+ r = image.stat(info, sizeof(info));
+ if (r < 0)
+ return r;
+
+ // ⚠️ should be test when offset == info.size
+ if (*offset > info.size) {
+ std::cerr << "rbd: offset " << *offset << " exceeds image size "
+ << info.size << std::endl;
+ return -EINVAL;
+ }
+
+ if (*offset > 0) {
+ *from_snap_name = mid_snap_prefix + "-" + std::to_string(*offset);
+ }
+
+ if (*length == 0) {
+ *length = info.size - *offset;
+ return 0;
+ }
+
+ if (*offset + *length < info.size) {
+ *snap_name = mid_snap_prefix + "-" + std::to_string(*offset + *length);
+ } else {
+ *length = info.size - *offset;
+ }
+
+ return 0;
+}
+
Shell::Action action_diff(
{"export-diff"}, {}, "Export incremental diff to file.", "",
&get_arguments_diff, &execute_diff);
@@ -501,7 +579,7 @@ static int do_export_v2(librbd::Image& image, librbd::image_info_t &info, int fd
const char *last_snap = NULL;
for (size_t i = 0; i < snaps.size(); ++i) {
Expand Down

0 comments on commit 7a3a3d3

Please sign in to comment.