| 28 | namespace po = boost::program_options; |
| 29 | |
| 30 | static int parse_diff_header(int fd, __u8 *tag, string *from, string *to, uint64_t *size) |
| 31 | { |
| 32 | int r; |
| 33 | |
| 34 | {//header |
| 35 | char buf[utils::RBD_DIFF_BANNER.size() + 1]; |
| 36 | r = safe_read_exact(fd, buf, utils::RBD_DIFF_BANNER.size()); |
| 37 | if (r < 0) |
| 38 | return r; |
| 39 | |
| 40 | buf[utils::RBD_DIFF_BANNER.size()] = '\0'; |
| 41 | if (strcmp(buf, utils::RBD_DIFF_BANNER.c_str())) { |
| 42 | std::cerr << "invalid banner '" << buf << "', expected '" |
| 43 | << utils::RBD_DIFF_BANNER << "'" << std::endl; |
| 44 | return -EINVAL; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | while (true) { |
| 49 | r = safe_read_exact(fd, tag, 1); |
| 50 | if (r < 0) |
| 51 | return r; |
| 52 | |
| 53 | if (*tag == RBD_DIFF_FROM_SNAP) { |
| 54 | r = utils::read_string(fd, 4096, from); // 4k limit to make sure we don't get a garbage string |
| 55 | if (r < 0) |
| 56 | return r; |
| 57 | dout(2) << " from snap " << *from << dendl; |
| 58 | } else if (*tag == RBD_DIFF_TO_SNAP) { |
| 59 | r = utils::read_string(fd, 4096, to); // 4k limit to make sure we don't get a garbage string |
| 60 | if (r < 0) |
| 61 | return r; |
| 62 | dout(2) << " to snap " << *to << dendl; |
| 63 | } else if (*tag == RBD_DIFF_IMAGE_SIZE) { |
| 64 | char buf[8]; |
| 65 | r = safe_read_exact(fd, buf, 8); |
| 66 | if (r < 0) |
| 67 | return r; |
| 68 | |
| 69 | bufferlist bl; |
| 70 | bl.append(buf, 8); |
| 71 | auto p = bl.cbegin(); |
| 72 | decode(*size, p); |
| 73 | } else { |
| 74 | break; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static int parse_diff_body(int fd, __u8 *tag, uint64_t *offset, uint64_t *length) |
| 82 | { |
no test coverage detected