projects
/
platform
/
upstream
/
btrfs-progs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
btrfs-progs: update CHANGES for v4.13.3
[platform/upstream/btrfs-progs.git]
/
send-stream.c
diff --git
a/send-stream.c
b/send-stream.c
index
3720e7d
..
78f2571
100644
(file)
--- a/
send-stream.c
+++ b/
send-stream.c
@@
-33,10
+33,23
@@
struct btrfs_send_stream {
struct btrfs_tlv_header *cmd_attrs[BTRFS_SEND_A_MAX + 1];
u32 version;
struct btrfs_tlv_header *cmd_attrs[BTRFS_SEND_A_MAX + 1];
u32 version;
+ /*
+ * end of last successful read, equivalent to start of current
+ * malformated part of block
+ */
+ size_t stream_pos;
+
struct btrfs_send_ops *ops;
void *user;
};
struct btrfs_send_ops *ops;
void *user;
};
+/*
+ * Read len bytes to buf.
+ * Return:
+ * 0 - success
+ * < 0 - negative errno in case of error
+ * > 0 - no data read, EOF
+ */
static int read_buf(struct btrfs_send_stream *sctx, char *buf, size_t len)
{
int ret;
static int read_buf(struct btrfs_send_stream *sctx, char *buf, size_t len)
{
int ret;
@@
-54,13
+67,20
@@
static int read_buf(struct btrfs_send_stream *sctx, char *buf, size_t len)
}
if (rbytes == 0) {
ret = 1;
}
if (rbytes == 0) {
ret = 1;
- goto out;
+ goto out
_eof
;
}
pos += rbytes;
}
}
pos += rbytes;
}
-
ret = 0;
ret = 0;
+out_eof:
+ if (0 < pos && pos < len) {
+ error("short read from stream: expected %zu read %zu", len, pos);
+ ret = -EIO;
+ } else {
+ sctx->stream_pos += pos;
+ }
+
out:
return ret;
}
out:
return ret;
}
@@
-68,11
+88,15
@@
out:
/*
* Reads a single command from kernel space and decodes the TLV's into
* sctx->cmd_attrs
/*
* Reads a single command from kernel space and decodes the TLV's into
* sctx->cmd_attrs
+ *
+ * Returns:
+ * 0 - success
+ * < 0 - an error in the command
*/
static int read_cmd(struct btrfs_send_stream *sctx)
{
int ret;
*/
static int read_cmd(struct btrfs_send_stream *sctx)
{
int ret;
-
int
cmd;
+
u16
cmd;
u32 cmd_len;
char *data;
u32 pos;
u32 cmd_len;
char *data;
u32 pos;
@@
-158,7
+182,7
@@
out:
static int tlv_get(struct btrfs_send_stream *sctx, int attr, void **data, int *len)
{
int ret;
static int tlv_get(struct btrfs_send_stream *sctx, int attr, void **data, int *len)
{
int ret;
- struct btrfs_tlv_header *h;
+ struct btrfs_tlv_header *h
dr
;
if (attr <= 0 || attr > BTRFS_SEND_A_MAX) {
error("invalid attribute requested, attr = %d", attr);
if (attr <= 0 || attr > BTRFS_SEND_A_MAX) {
error("invalid attribute requested, attr = %d", attr);
@@
-166,15
+190,15
@@
static int tlv_get(struct btrfs_send_stream *sctx, int attr, void **data, int *l
goto out;
}
goto out;
}
- h = sctx->cmd_attrs[attr];
- if (!h) {
+ h
dr
= sctx->cmd_attrs[attr];
+ if (!h
dr
) {
error("attribute %d requested but not present", attr);
ret = -ENOENT;
goto out;
}
error("attribute %d requested but not present", attr);
ret = -ENOENT;
goto out;
}
- *len = le16_to_cpu(h->tlv_len);
- *data = h + 1;
+ *len = le16_to_cpu(h
dr
->tlv_len);
+ *data = h
dr
+ 1;
ret = 0;
ret = 0;
@@
-462,12
+486,13
@@
int btrfs_read_and_process_send_stream(int fd,
sctx.fd = fd;
sctx.ops = ops;
sctx.user = user;
sctx.fd = fd;
sctx.ops = ops;
sctx.user = user;
+ sctx.stream_pos = 0;
ret = read_buf(&sctx, (char*)&hdr, sizeof(hdr));
if (ret < 0)
goto out;
if (ret) {
ret = read_buf(&sctx, (char*)&hdr, sizeof(hdr));
if (ret < 0)
goto out;
if (ret) {
- ret =
1
;
+ ret =
-ENODATA
;
goto out;
}
goto out;
}