From 9c82efcc79382797183006ee276d1e0c8a1ccbeb Mon Sep 17 00:00:00 2001 From: Yunchuan Wen Date: Wed, 7 Jan 2015 16:32:58 +0800 Subject: [PATCH] rbd: parse diff file body for diff merging Signed-off-by: MingXin Liu Signed-off-by: Yunchuan Wen Reviewed-by: Li Wang --- src/rbd.cc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/rbd.cc b/src/rbd.cc index 91761af2c1e..781ba7af4f4 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -1762,6 +1762,42 @@ static int parse_diff_header(int fd, __u8 *tag, string *from, string *to, uint64 return 0; } +static int parse_diff_body(int fd, __u8 *tag, uint64_t *offset, uint64_t *length) +{ + int r; + + if (!(*tag)) { + r = safe_read_exact(fd, tag, 1); + if (r < 0) + return r; + } + + if (*tag == 'e') { + offset = 0; + length = 0; + return 0; + } + + if (*tag != 'w' && *tag != 'z') + return -ENOTSUP; + + char buf[16]; + r = safe_read_exact(fd, buf, 16); + if (r < 0) + return r; + + bufferlist bl; + bl.append(buf, 16); + bufferlist::iterator p = bl.begin(); + ::decode(*offset, p); + ::decode(*length, p); + + if (!(*length)) + return -ENOTSUP; + + return 0; +} + /* * fd: the diff file to read from * pd: the diff file to be written into -- 2.47.3