11
11
// encryption arguments
12
12
static const std::string ENCRYPTION_FORMAT("encryption-format");
13
13
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
15
15
--- a/src/tools/rbd/action/Export.cc
16
16
+++ b/src/tools/rbd/action/Export.cc
17
- @@ -123,16 +123,26 @@ class C_ExportDiff : public Context {
17
+ @@ -123,16 +123,27 @@ private:
18
18
19
19
20
20
int do_export_diff_fd(librbd::Image& image, const char *fromsnapname,
@@ -27,10 +27,11 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
27
27
int r;
28
28
librbd::image_info_t info;
29
29
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;
34
35
+
35
36
r = image.stat(info, sizeof(info));
36
37
if (r < 0)
@@ -43,7 +44,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
43
44
{
44
45
// header
45
46
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,
47
48
48
49
__u8 tag;
49
50
uint64_t len = 0;
@@ -56,7 +57,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
56
57
if (export_format == 2) {
57
58
len = from.length() + 4;
58
59
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,
60
61
encode(from, bl);
61
62
}
62
63
@@ -69,7 +70,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
69
70
if (export_format == 2) {
70
71
len = to.length() + 4;
71
72
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,
73
74
return r;
74
75
}
75
76
}
@@ -82,7 +83,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
82
83
&C_ExportDiff::export_diff_cb, (void *)&edc);
83
84
if (r < 0) {
84
85
goto out;
85
- @@ -223,8 +233 ,9 @@ int do_export_diff_fd(librbd::Image& image, const char *fromsnapname,
86
+ @@ -223,8 +234 ,9 @@ out:
86
87
}
87
88
88
89
int do_export_diff(librbd::Image& image, const char *fromsnapname,
@@ -94,7 +95,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
94
95
{
95
96
int r;
96
97
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,
98
99
if (fd < 0)
99
100
return -errno;
100
101
@@ -105,7 +106,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
105
106
106
107
if (fd != 1)
107
108
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,
109
110
options->add_options()
110
111
(at::FROM_SNAPSHOT_NAME.c_str(), po::value<std::string>(),
111
112
"snapshot starting point")
@@ -139,7 +140,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
139
140
+ }
140
141
+
141
142
+ 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);
143
144
+ }
144
145
+
145
146
+ if (*length == 0) {
@@ -148,7 +149,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
148
149
+ }
149
150
+
150
151
+ 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);
152
153
+ } else {
153
154
+ *length = info.size - *offset;
154
155
+ }
@@ -159,7 +160,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
159
160
int execute_diff(const po::variables_map &vm,
160
161
const std::vector<std::string> &ceph_global_init_args) {
161
162
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,
163
164
from_snap_name = vm[at::FROM_SNAPSHOT_NAME].as<std::string>();
164
165
}
165
166
@@ -186,14 +187,18 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
186
187
librados::Rados rados;
187
188
librados::IoCtx io_ctx;
188
189
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,
190
191
return r;
191
192
}
192
193
193
194
+ std::string out_from_snap_name = from_snap_name;
194
195
+ std::string out_end_snap_name = snap_name;
195
196
+
196
197
+ 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
+ + }
197
202
+ r = get_snapshot_name_for_offset_length(image, mid_snap_prefix,
198
203
+ &out_from_snap_name, &out_end_snap_name,
199
204
+ &offset, &length);
@@ -211,7 +216,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
211
216
vm[at::WHOLE_OBJECT].as<bool>(), path.c_str(),
212
217
vm[at::NO_PROGRESS].as<bool>());
213
218
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
215
220
const char *last_snap = NULL;
216
221
for (size_t i = 0; i < snaps.size(); ++i) {
217
222
utils::snap_set(image, snaps[i].name.c_str());
@@ -221,7 +226,7 @@ index ddcf0f2c30cef..cc84a68193bdc 100644
221
226
if (r < 0) {
222
227
return r;
223
228
}
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
225
230
last_snap = snaps[i].name.c_str();
226
231
}
227
232
utils::snap_set(image, std::string(""));
0 commit comments