static const std::string RBD_DIFF_BANNER ("rbd diff v1\n");
+#define RBD_DIFF_FROM_SNAP 'f'
+#define RBD_DIFF_TO_SNAP 't'
+#define RBD_DIFF_IMAGE_SIZE 's'
+#define RBD_DIFF_WRITE 'w'
+#define RBD_DIFF_ZERO 'z'
+#define RBD_DIFF_END 'e'
+
enum SnapshotPresence {
SNAPSHOT_PRESENCE_NONE,
SNAPSHOT_PRESENCE_PERMITTED,
uint64_t length, bool exists) {
// extent
bufferlist bl;
- __u8 tag = exists ? 'w' : 'z';
+ __u8 tag = exists ? RBD_DIFF_WRITE : RBD_DIFF_ZERO;
::encode(tag, bl);
::encode(offset, bl);
::encode(length, bl);
__u8 tag;
if (fromsnapname) {
- tag = 'f';
+ tag = RBD_DIFF_FROM_SNAP;
::encode(tag, bl);
std::string from(fromsnapname);
::encode(from, bl);
}
if (endsnapname) {
- tag = 't';
+ tag = RBD_DIFF_TO_SNAP;
::encode(tag, bl);
std::string to(endsnapname);
::encode(to, bl);
}
- tag = 's';
+ tag = RBD_DIFF_IMAGE_SIZE;
::encode(tag, bl);
uint64_t endsize = info.size;
::encode(endsize, bl);
}
{
- __u8 tag = 'e';
+ __u8 tag = RBD_DIFF_END;
bufferlist bl;
::encode(tag, bl);
r = bl.write_fd(fd);
goto done;
}
- if (tag == 'e') {
+ if (tag == RBD_DIFF_END) {
dout(2) << " end diff" << dendl;
break;
- } else if (tag == 'f') {
+ } else if (tag == RBD_DIFF_FROM_SNAP) {
r = utils::read_string(fd, 4096, &from); // 4k limit to make sure we don't get a garbage string
if (r < 0)
goto done;
goto done;
}
}
- else if (tag == 't') {
+ else if (tag == RBD_DIFF_TO_SNAP) {
r = utils::read_string(fd, 4096, &to); // 4k limit to make sure we don't get a garbage string
if (r < 0)
goto done;
r = -EEXIST;
goto done;
}
- } else if (tag == 's') {
+ } else if (tag == RBD_DIFF_IMAGE_SIZE) {
uint64_t end_size;
char buf[8];
r = safe_read_exact(fd, buf, 8);
}
if (from_stdin)
size = end_size;
- } else if (tag == 'w' || tag == 'z') {
+ } else if (tag == RBD_DIFF_WRITE || tag == RBD_DIFF_ZERO) {
uint64_t len;
char buf[16];
r = safe_read_exact(fd, buf, 16);
::decode(off, p);
::decode(len, p);
- if (tag == 'w') {
+ if (tag == RBD_DIFF_WRITE) {
bufferptr bp = buffer::create(len);
r = safe_read_exact(fd, bp.c_str(), len);
if (r < 0)
if (r < 0)
return r;
- if (*tag == 'f') {
+ if (*tag == RBD_DIFF_FROM_SNAP) {
r = utils::read_string(fd, 4096, from); // 4k limit to make sure we don't get a garbage string
if (r < 0)
return r;
dout(2) << " from snap " << *from << dendl;
- } else if (*tag == 't') {
+ } else if (*tag == RBD_DIFF_TO_SNAP) {
r = utils::read_string(fd, 4096, to); // 4k limit to make sure we don't get a garbage string
if (r < 0)
return r;
dout(2) << " to snap " << *to << dendl;
- } else if (*tag == 's') {
+ } else if (*tag == RBD_DIFF_IMAGE_SIZE) {
char buf[8];
r = safe_read_exact(fd, buf, 8);
if (r < 0)
return r;
}
- if (*tag == 'e') {
+ if (*tag == RBD_DIFF_END) {
offset = 0;
length = 0;
return 0;
}
- if (*tag != 'w' && *tag != 'z')
+ if (*tag != RBD_DIFF_WRITE && *tag != RBD_DIFF_ZERO)
return -ENOTSUP;
char buf[16];
*/
static int accept_diff_body(int fd, int pd, __u8 tag, uint64_t offset, uint64_t length)
{
- if (tag == 'e')
+ if (tag == RBD_DIFF_END)
return 0;
bufferlist bl;
if (r < 0)
return r;
- if (tag == 'w') {
+ if (tag == RBD_DIFF_WRITE) {
bufferptr bp = buffer::create(length);
r = safe_read_exact(fd, bp.c_str(), length);
if (r < 0)
__u8 tag;
if (f_from.size()) {
- tag = 'f';
+ tag = RBD_DIFF_FROM_SNAP;
::encode(tag, bl);
::encode(f_from, bl);
}
if (s_to.size()) {
- tag = 't';
+ tag = RBD_DIFF_TO_SNAP;
::encode(tag, bl);
::encode(s_to, bl);
}
- tag = 's';
+ tag = RBD_DIFF_IMAGE_SIZE;
::encode(tag, bl);
::encode(s_size, bl);
goto done;
}
- if (f_tag == 'e') {
+ if (f_tag == RBD_DIFF_END) {
f_end = true;
- f_tag = 'z';
+ f_tag = RBD_DIFF_ZERO;
f_off = f_size;
if (f_size < s_size)
f_len = s_size - f_size;
goto done;
}
- if (s_tag == 'e') {
+ if (s_tag == RBD_DIFF_END) {
s_end = true;
s_off = s_size;
if (s_size < f_size)
uint64_t delta = s_off + s_len - f_off;
if (delta > f_len)
delta = f_len;
- if (f_tag == 'w') {
+ if (f_tag == RBD_DIFF_WRITE) {
if (first_stdin) {
bufferptr bp = buffer::create(delta);
r = safe_read_exact(fd, bp.c_str(), delta);
}
{//tail
- __u8 tag = 'e';
+ __u8 tag = RBD_DIFF_END;
bufferlist bl;
::encode(tag, bl);
r = bl.write_fd(pd);