Skip to content

Commit c2c7132

Browse files
Stefan BehrensJosef Bacik
authored andcommitted
Btrfs: allow omitting stream header and end-cmd for btrfs send
Two new flags are added to allow omitting the stream header and the end command for btrfs send streams. This is used in cases where you send multiple snapshots back-to-back in one stream. This used to be encoded like this (with 2 snapshots in this example): <stream header> + <sequence of commands> + <end cmd> + <stream header> + <sequence of commands> + <end cmd> + EOF The new format (if the two new flags are used) is this one: <stream header> + <sequence of commands> + <sequence of commands> + <end cmd> Note that the currently existing receivers treat <end cmd> only as an indication that a new <stream header> is following. This means, you can just skip the sequence <end cmd> <stream header> without loosing compatibility. As long as an EOF is following, the currently existing receivers handle the new format (if the two new flags are used) exactly as the old one. So what is the benefit of this change? The goal is to be able to use a single stream (one TCP connection) to multiplex a request/response handshake plus Btrfs send streams, all in the same stream. In this case you cannot evaluate an EOF condition as an end of the Btrfs send stream. You need something else, and the <end cmd> is just perfect for this purpose. The summary is: The format change is driven by the need to send several Btrfs send streams over a single TCP connections, with the ability for a repeated request/response handshake in the middle. And this format change does not break any existing tool, it is completely compatible. You could compare the old behaviour of the Btrfs send stream to the one of ftp where you need a seperate request/response channel and newly opened data transfer channels for each file, while the new behaviour is more like http using a single stream for everything. Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de> Signed-off-by: Josef Bacik <jbacik@fusionio.com>
1 parent 692206b commit c2c7132

2 files changed

Lines changed: 33 additions & 11 deletions

File tree

‎fs/btrfs/send.c‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4529,9 +4529,11 @@ static int send_subvol(struct send_ctx *sctx)
45294529
{
45304530
int ret;
45314531

4532-
ret = send_header(sctx);
4533-
if (ret < 0)
4534-
goto out;
4532+
if (!(sctx->flags & BTRFS_SEND_FLAG_OMIT_STREAM_HEADER)) {
4533+
ret = send_header(sctx);
4534+
if (ret < 0)
4535+
goto out;
4536+
}
45354537

45364538
ret = send_subvol_begin(sctx);
45374539
if (ret < 0)
@@ -4593,7 +4595,7 @@ long btrfs_ioctl_send(struct file *mnt_file, void __user *arg_)
45934595
goto out;
45944596
}
45954597

4596-
if (arg->flags & ~BTRFS_SEND_FLAG_NO_FILE_DATA) {
4598+
if (arg->flags & ~BTRFS_SEND_FLAG_MASK) {
45974599
ret = -EINVAL;
45984600
goto out;
45994601
}
@@ -4704,12 +4706,14 @@ long btrfs_ioctl_send(struct file *mnt_file, void __user *arg_)
47044706
if (ret < 0)
47054707
goto out;
47064708

4707-
ret = begin_cmd(sctx, BTRFS_SEND_C_END);
4708-
if (ret < 0)
4709-
goto out;
4710-
ret = send_cmd(sctx);
4711-
if (ret < 0)
4712-
goto out;
4709+
if (!(sctx->flags & BTRFS_SEND_FLAG_OMIT_END_CMD)) {
4710+
ret = begin_cmd(sctx, BTRFS_SEND_C_END);
4711+
if (ret < 0)
4712+
goto out;
4713+
ret = send_cmd(sctx);
4714+
if (ret < 0)
4715+
goto out;
4716+
}
47134717

47144718
out:
47154719
kfree(arg);

‎include/uapi/linux/btrfs.h‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,25 @@ struct btrfs_ioctl_received_subvol_args {
412412
* search of clone sources doesn't find an extent. UPDATE_EXTENT
413413
* commands will be sent instead of WRITE commands.
414414
*/
415-
#define BTRFS_SEND_FLAG_NO_FILE_DATA 0x1
415+
#define BTRFS_SEND_FLAG_NO_FILE_DATA 0x1
416+
417+
/*
418+
* Do not add the leading stream header. Used when multiple snapshots
419+
* are sent back to back.
420+
*/
421+
#define BTRFS_SEND_FLAG_OMIT_STREAM_HEADER 0x2
422+
423+
/*
424+
* Omit the command at the end of the stream that indicated the end
425+
* of the stream. This option is used when multiple snapshots are
426+
* sent back to back.
427+
*/
428+
#define BTRFS_SEND_FLAG_OMIT_END_CMD 0x4
429+
430+
#define BTRFS_SEND_FLAG_MASK \
431+
(BTRFS_SEND_FLAG_NO_FILE_DATA | \
432+
BTRFS_SEND_FLAG_OMIT_STREAM_HEADER | \
433+
BTRFS_SEND_FLAG_OMIT_END_CMD)
416434

417435
struct btrfs_ioctl_send_args {
418436
__s64 send_fd; /* in */

0 commit comments

Comments
 (0)