From 9321c81488a3a3e5ba8c5278d3c2e951171b17e4 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 21 Jun 2022 19:44:15 +0200 Subject: [PATCH] btrfs-progs: wip - send progress Pass BTRFS_SEND_FLAG_CALCULATE_DATA_SIZE flag and add command line option. Unfinished. Signed-off-by: David Sterba --- cmds/send.c | 5 +++++ ioctl.h | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cmds/send.c b/cmds/send.c index f9446302..b917e0be 100644 --- a/cmds/send.c +++ b/cmds/send.c @@ -541,6 +541,7 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv) GETOPT_VAL_SEND_NO_DATA = GETOPT_VAL_FIRST, GETOPT_VAL_PROTO, GETOPT_VAL_COMPRESSED_DATA, + GETOPT_VAL_CALC_DATA_SIZE, }; static const struct option long_options[] = { { "verbose", no_argument, NULL, 'v' }, @@ -548,6 +549,7 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv) { "no-data", no_argument, NULL, GETOPT_VAL_SEND_NO_DATA }, { "proto", required_argument, NULL, GETOPT_VAL_PROTO }, { "compressed-data", no_argument, NULL, GETOPT_VAL_COMPRESSED_DATA }, + { "calc-data-size", no_argument, NULL, GETOPT_VAL_CALC_DATA_SIZE }, { NULL, 0, NULL, 0 } }; int c = getopt_long(argc, argv, "vqec:f:i:p:", long_options, NULL); @@ -648,6 +650,9 @@ static int cmd_send(const struct cmd_struct *cmd, int argc, char **argv) case GETOPT_VAL_COMPRESSED_DATA: send_flags |= BTRFS_SEND_FLAG_COMPRESSED; break; + case GETOPT_VAL_CALC_DATA_SIZE: + send_flags |= BTRFS_SEND_FLAG_CALC_DATA_SIZE; + break; default: usage_unknown_option(cmd, argv); } diff --git a/ioctl.h b/ioctl.h index f19695e3..db55c612 100644 --- a/ioctl.h +++ b/ioctl.h @@ -667,12 +667,23 @@ BUILD_ASSERT(sizeof(struct btrfs_ioctl_received_subvol_args_32) == 192); */ #define BTRFS_SEND_FLAG_COMPRESSED 0x10 +/* + * Calculate the amount (in bytes) of new file data between the send and + * parent snapshots, or in case of a full send, the total amount of file data + * we will send. + * This corresponds to the sum of the data lengths of each write and clone + * commands that are sent through the send stream. The receiving end can use + * this information to estimate progress. + */ +#define BTRFS_SEND_FLAG_CALC_DATA_SIZE 0x20 + #define BTRFS_SEND_FLAG_MASK \ (BTRFS_SEND_FLAG_NO_FILE_DATA | \ BTRFS_SEND_FLAG_OMIT_STREAM_HEADER | \ BTRFS_SEND_FLAG_OMIT_END_CMD | \ BTRFS_SEND_FLAG_VERSION | \ - BTRFS_SEND_FLAG_COMPRESSED) + BTRFS_SEND_FLAG_COMPRESSED | \ + BTRFS_SEND_FLAG_CALC_DATA_SIZE) struct btrfs_ioctl_send_args { __s64 send_fd; /* in */