btrfs-progs: send-stream: switch to common message helpers

Signed-off-by: David Sterba <dsterba@suse.com>
master
David Sterba 2016-11-15 14:02:48 +01:00
parent 5ee216a86f
commit eb4cfd8921
1 changed files with 13 additions and 16 deletions

View File

@ -22,6 +22,7 @@
#include "send.h" #include "send.h"
#include "send-stream.h" #include "send-stream.h"
#include "crc32c.h" #include "crc32c.h"
#include "utils.h"
struct btrfs_send_stream { struct btrfs_send_stream {
int fd; int fd;
@ -45,7 +46,7 @@ static int read_buf(struct btrfs_send_stream *s, void *buf, int len)
ret = read(s->fd, (char*)buf + pos, len - pos); ret = read(s->fd, (char*)buf + pos, len - pos);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
fprintf(stderr, "ERROR: read from stream failed. %s\n", error("read from stream failed: %s",
strerror(-ret)); strerror(-ret));
goto out; goto out;
} }
@ -86,7 +87,7 @@ static int read_cmd(struct btrfs_send_stream *s)
goto out; goto out;
if (ret) { if (ret) {
ret = -EINVAL; ret = -EINVAL;
fprintf(stderr, "ERROR: unexpected EOF in stream.\n"); error("unexpected EOF in stream");
goto out; goto out;
} }
@ -100,7 +101,7 @@ static int read_cmd(struct btrfs_send_stream *s)
goto out; goto out;
if (ret) { if (ret) {
ret = -EINVAL; ret = -EINVAL;
fprintf(stderr, "ERROR: unexpected EOF in stream.\n"); error("unexpected EOF in stream");
goto out; goto out;
} }
@ -112,7 +113,7 @@ static int read_cmd(struct btrfs_send_stream *s)
if (crc != crc2) { if (crc != crc2) {
ret = -EINVAL; ret = -EINVAL;
fprintf(stderr, "ERROR: crc32 mismatch in command.\n"); error("crc32 mismatch in command");
goto out; goto out;
} }
@ -124,8 +125,7 @@ static int read_cmd(struct btrfs_send_stream *s)
if (tlv_type <= 0 || tlv_type > BTRFS_SEND_A_MAX || if (tlv_type <= 0 || tlv_type > BTRFS_SEND_A_MAX ||
tlv_len < 0 || tlv_len > BTRFS_SEND_BUF_SIZE) { tlv_len < 0 || tlv_len > BTRFS_SEND_BUF_SIZE) {
fprintf(stderr, "ERROR: invalid tlv in cmd. " error("invalid tlv in cmd tlv_type = %d, tlv_len = %d",
"tlv_type = %d, tlv_len = %d\n",
tlv_type, tlv_len); tlv_type, tlv_len);
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
@ -150,17 +150,14 @@ static int tlv_get(struct btrfs_send_stream *s, int attr, void **data, int *len)
struct btrfs_tlv_header *h; struct btrfs_tlv_header *h;
if (attr <= 0 || attr > BTRFS_SEND_A_MAX) { if (attr <= 0 || attr > BTRFS_SEND_A_MAX) {
fprintf(stderr, "ERROR: invalid attribute requested. " error("invalid attribute requested, attr = %d", attr);
"attr = %d\n",
attr);
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
h = s->cmd_attrs[attr]; h = s->cmd_attrs[attr];
if (!h) { if (!h) {
fprintf(stderr, "ERROR: attribute %d requested " error("attribute %d requested but not present", attr);
"but not present.\n", attr);
ret = -ENOENT; ret = -ENOENT;
goto out; goto out;
} }
@ -190,8 +187,8 @@ out:
#define TLV_CHECK_LEN(expected, got) \ #define TLV_CHECK_LEN(expected, got) \
do { \ do { \
if (expected != got) { \ if (expected != got) { \
fprintf(stderr, "ERROR: invalid size for attribute. " \ error("invalid size for attribute, " \
"expected = %d, got = %d\n", \ "expected = %d, got = %d", \
(int)expected, (int)got); \ (int)expected, (int)got); \
ret = -EINVAL; \ ret = -EINVAL; \
goto tlv_get_failed; \ goto tlv_get_failed; \
@ -465,15 +462,15 @@ int btrfs_read_and_process_send_stream(int fd,
if (strcmp(hdr.magic, BTRFS_SEND_STREAM_MAGIC)) { if (strcmp(hdr.magic, BTRFS_SEND_STREAM_MAGIC)) {
ret = -EINVAL; ret = -EINVAL;
fprintf(stderr, "ERROR: Unexpected header\n"); error("unexpected header");
goto out; goto out;
} }
s.version = le32_to_cpu(hdr.version); s.version = le32_to_cpu(hdr.version);
if (s.version > BTRFS_SEND_STREAM_VERSION) { if (s.version > BTRFS_SEND_STREAM_VERSION) {
ret = -EINVAL; ret = -EINVAL;
fprintf(stderr, "ERROR: Stream version %d not supported. " error("stream version %d not supported, please use newer version",
"Please upgrade btrfs-progs\n", s.version); s.version);
goto out; goto out;
} }