Skip to content

Commit be69bda

Browse files
Merge pull request #111 from cybozu-go/fix-snapname
fix snapshot name
2 parents 303a532 + 2f1f8c3 commit be69bda

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

ceph/export-diff.patch

+23-18
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
// encryption arguments
1212
static const std::string ENCRYPTION_FORMAT("encryption-format");
1313
diff --git a/src/tools/rbd/action/Export.cc b/src/tools/rbd/action/Export.cc
14-
index ddcf0f2c30cef..cc84a68193bdc 100644
14+
index ddcf0f2c30c..01c96d40911 100644
1515
--- a/src/tools/rbd/action/Export.cc
1616
+++ b/src/tools/rbd/action/Export.cc
17-
@@ -123,16 +123,26 @@ class C_ExportDiff : public Context {
17+
@@ -123,16 +123,27 @@ private:
1818

1919

2020
int do_export_diff_fd(librbd::Image& image, const char *fromsnapname,
@@ -27,10 +27,11 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
2727
int r;
2828
librbd::image_info_t info;
2929

30-
+ std::cerr << "do_export_diff: fromsnapname=" << fromsnapname <<
31-
+ " endsnapname=" << endsnapname << " out_fromsnapname=" << out_fromsnapname <<
32-
+ " out_endsnapname=" << out_endsnapname << " offset=" << offset <<
33-
+ " length=" << length << std::endl;
30+
+ std::cerr << "do_export_diff(fromsnapname=" << (fromsnapname ? fromsnapname : "null") <<
31+
+ " endsnapname=" << (endsnapname ? endsnapname : "null") <<
32+
+ " out_fromsnapname=" << (out_fromsnapname ? out_fromsnapname : "null") <<
33+
+ " out_endsnapname=" << (out_endsnapname ? out_endsnapname : "null") <<
34+
+ " offset=" << offset << " length=" << length << ")" << std::endl;
3435
+
3536
r = image.stat(info, sizeof(info));
3637
if (r < 0)
@@ -43,7 +44,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
4344
{
4445
// header
4546
bufferlist bl;
46-
@@ -143,10 +153,10 @@ int do_export_diff_fd(librbd::Image& image, const char *fromsnapname,
47+
@@ -143,10 +154,10 @@ int do_export_diff_fd(librbd::Image& image, const char *fromsnapname,
4748

4849
__u8 tag;
4950
uint64_t len = 0;
@@ -56,7 +57,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
5657
if (export_format == 2) {
5758
len = from.length() + 4;
5859
encode(len, bl);
59-
@@ -154,10 +164,10 @@ int do_export_diff_fd(librbd::Image& image, const char *fromsnapname,
60+
@@ -154,10 +165,10 @@ int do_export_diff_fd(librbd::Image& image, const char *fromsnapname,
6061
encode(from, bl);
6162
}
6263

@@ -69,7 +70,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
6970
if (export_format == 2) {
7071
len = to.length() + 4;
7172
encode(len, bl);
72-
@@ -192,10 +202,10 @@ int do_export_diff_fd(librbd::Image& image, const char *fromsnapname,
73+
@@ -192,10 +203,10 @@ int do_export_diff_fd(librbd::Image& image, const char *fromsnapname,
7374
return r;
7475
}
7576
}
@@ -82,7 +83,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
8283
&C_ExportDiff::export_diff_cb, (void *)&edc);
8384
if (r < 0) {
8485
goto out;
85-
@@ -223,8 +233,9 @@ int do_export_diff_fd(librbd::Image& image, const char *fromsnapname,
86+
@@ -223,8 +234,9 @@ out:
8687
}
8788

8889
int do_export_diff(librbd::Image& image, const char *fromsnapname,
@@ -94,7 +95,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
9495
{
9596
int r;
9697
int fd;
97-
@@ -236,7 +247,9 @@ int do_export_diff(librbd::Image& image, const char *fromsnapname,
98+
@@ -236,7 +248,9 @@ int do_export_diff(librbd::Image& image, const char *fromsnapname,
9899
if (fd < 0)
99100
return -errno;
100101

@@ -105,7 +106,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
105106

106107
if (fd != 1)
107108
close(fd);
108-
@@ -260,10 +273,52 @@ void get_arguments_diff(po::options_description *positional,
109+
@@ -260,10 +274,52 @@ void get_arguments_diff(po::options_description *positional,
109110
options->add_options()
110111
(at::FROM_SNAPSHOT_NAME.c_str(), po::value<std::string>(),
111112
"snapshot starting point")
@@ -139,7 +140,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
139140
+ }
140141
+
141142
+ if (*offset > 0) {
142-
+ *from_snap_name = mid_snap_prefix + "-" + std::to_string(*offset);
143+
+ *from_snap_name = mid_snap_prefix + "-offset-" + std::to_string(*offset);
143144
+ }
144145
+
145146
+ if (*length == 0) {
@@ -148,7 +149,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
148149
+ }
149150
+
150151
+ if (*offset + *length < info.size) {
151-
+ *snap_name = mid_snap_prefix + "-" + std::to_string(*offset + *length);
152+
+ *snap_name = mid_snap_prefix + "-offset-" + std::to_string(*offset + *length);
152153
+ } else {
153154
+ *length = info.size - *offset;
154155
+ }
@@ -159,7 +160,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
159160
int execute_diff(const po::variables_map &vm,
160161
const std::vector<std::string> &ceph_global_init_args) {
161162
size_t arg_index = 0;
162-
@@ -290,6 +345,26 @@ int execute_diff(const po::variables_map &vm,
163+
@@ -290,6 +346,26 @@ int execute_diff(const po::variables_map &vm,
163164
from_snap_name = vm[at::FROM_SNAPSHOT_NAME].as<std::string>();
164165
}
165166

@@ -186,14 +187,18 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
186187
librados::Rados rados;
187188
librados::IoCtx io_ctx;
188189
librbd::Image image;
189-
@@ -299,9 +374,24 @@ int execute_diff(const po::variables_map &vm,
190+
@@ -299,9 +375,28 @@ int execute_diff(const po::variables_map &vm,
190191
return r;
191192
}
192193

193194
+ std::string out_from_snap_name = from_snap_name;
194195
+ std::string out_end_snap_name = snap_name;
195196
+
196197
+ if (offset != 0 || length != 0) {
198+
+ if (snap_name.empty()) {
199+
+ std::cerr << "rbd: must specify snapshot when specifying offset and length" << std::endl;
200+
+ return -EINVAL;
201+
+ }
197202
+ r = get_snapshot_name_for_offset_length(image, mid_snap_prefix,
198203
+ &out_from_snap_name, &out_end_snap_name,
199204
+ &offset, &length);
@@ -211,7 +216,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
211216
vm[at::WHOLE_OBJECT].as<bool>(), path.c_str(),
212217
vm[at::NO_PROGRESS].as<bool>());
213218
if (r < 0) {
214-
@@ -501,7 +591,8 @@ static int do_export_v2(librbd::Image& image, librbd::image_info_t &info, int fd
219+
@@ -501,7 +596,8 @@ static int do_export_v2(librbd::Image& image, librbd::image_info_t &info, int fd
215220
const char *last_snap = NULL;
216221
for (size_t i = 0; i < snaps.size(); ++i) {
217222
utils::snap_set(image, snaps[i].name.c_str());
@@ -221,7 +226,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
221226
if (r < 0) {
222227
return r;
223228
}
224-
@@ -509,7 +600,8 @@ static int do_export_v2(librbd::Image& image, librbd::image_info_t &info, int fd
229+
@@ -509,7 +605,8 @@ static int do_export_v2(librbd::Image& image, librbd::image_info_t &info, int fd
225230
last_snap = snaps[i].name.c_str();
226231
}
227232
utils::snap_set(image, std::string(""));

0 commit comments

Comments
 (0)