]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: send: add stream v2 definitions
authorOmar Sandoval <osandov@fb.com>
Thu, 17 Mar 2022 17:25:39 +0000 (10:25 -0700)
committerDavid Sterba <dsterba@suse.com>
Mon, 25 Jul 2022 15:45:32 +0000 (17:45 +0200)
This adds the definitions of the new commands for send stream version 2
and their respective attributes: fallocate, FS_IOC_SETFLAGS (a.k.a.
chattr), and encoded writes. It also documents two changes to the send
stream format in v2: the receiver shouldn't assume a maximum command
size, and the DATA attribute is encoded differently to allow for writes
larger than 64k. These will be implemented in subsequent changes, and
then the ioctl will accept the new version and flag.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/send.c
fs/btrfs/send.h
include/uapi/linux/btrfs.h

index 237753860758cbcde27f65f7a395c907eca16c93..6ec31736c5228fdb9d4d47ff5af11432c711a2c8 100644 (file)
@@ -7552,7 +7552,7 @@ long btrfs_ioctl_send(struct inode *inode, struct btrfs_ioctl_send_args *arg)
 
        sctx->clone_roots_cnt = arg->clone_sources_count;
 
-       sctx->send_max_size = BTRFS_SEND_BUF_SIZE;
+       sctx->send_max_size = BTRFS_SEND_BUF_SIZE_V1;
        sctx->send_buf = kvmalloc(sctx->send_max_size, GFP_KERNEL);
        if (!sctx->send_buf) {
                ret = -ENOMEM;
index c47a2984aa5b17b5f6f8e70ae7300a0365108fa7..858ce8132614bf77099e9c3e92c38b86f3371408 100644 (file)
 #define BTRFS_SEND_STREAM_MAGIC "btrfs-stream"
 #define BTRFS_SEND_STREAM_VERSION 1
 
-#define BTRFS_SEND_BUF_SIZE SZ_64K
+/*
+ * In send stream v1, no command is larger than 64K. In send stream v2, no limit
+ * should be assumed.
+ */
+#define BTRFS_SEND_BUF_SIZE_V1                         SZ_64K
 
 enum btrfs_tlv_type {
        BTRFS_TLV_U8,
@@ -80,16 +84,20 @@ enum btrfs_send_cmd {
        BTRFS_SEND_C_MAX_V1             = 22,
 
        /* Version 2 */
-       BTRFS_SEND_C_MAX_V2             = 22,
+       BTRFS_SEND_C_FALLOCATE          = 23,
+       BTRFS_SEND_C_SETFLAGS           = 24,
+       BTRFS_SEND_C_ENCODED_WRITE      = 25,
+       BTRFS_SEND_C_MAX_V2             = 25,
 
        /* End */
-       BTRFS_SEND_C_MAX                = 22,
+       BTRFS_SEND_C_MAX                = 25,
 };
 
 /* attributes in send stream */
 enum {
        BTRFS_SEND_A_UNSPEC             = 0,
 
+       /* Version 1 */
        BTRFS_SEND_A_UUID               = 1,
        BTRFS_SEND_A_CTRANSID           = 2,
 
@@ -112,6 +120,11 @@ enum {
        BTRFS_SEND_A_PATH_LINK          = 17,
 
        BTRFS_SEND_A_FILE_OFFSET        = 18,
+       /*
+        * As of send stream v2, this attribute is special: it must be the last
+        * attribute in a command, its header contains only the type, and its
+        * length is implicitly the remaining length of the command.
+        */
        BTRFS_SEND_A_DATA               = 19,
 
        BTRFS_SEND_A_CLONE_UUID         = 20,
@@ -120,7 +133,26 @@ enum {
        BTRFS_SEND_A_CLONE_OFFSET       = 23,
        BTRFS_SEND_A_CLONE_LEN          = 24,
 
-       BTRFS_SEND_A_MAX                = 24,
+       BTRFS_SEND_A_MAX_V1             = 24,
+
+       /* Version 2 */
+       BTRFS_SEND_A_FALLOCATE_MODE     = 25,
+
+       BTRFS_SEND_A_SETFLAGS_FLAGS     = 26,
+
+       BTRFS_SEND_A_UNENCODED_FILE_LEN = 27,
+       BTRFS_SEND_A_UNENCODED_LEN      = 28,
+       BTRFS_SEND_A_UNENCODED_OFFSET   = 29,
+       /*
+        * COMPRESSION and ENCRYPTION default to NONE (0) if omitted from
+        * BTRFS_SEND_C_ENCODED_WRITE.
+        */
+       BTRFS_SEND_A_COMPRESSION        = 30,
+       BTRFS_SEND_A_ENCRYPTION         = 31,
+       BTRFS_SEND_A_MAX_V2             = 31,
+
+       /* End */
+       BTRFS_SEND_A_MAX                = 31,
 };
 
 #ifdef __KERNEL__
index d956b2993970f4c28aacb1d992266a08de98b1e6..b6f26a434b10970cc28b1aac2953656a1688cbdb 100644 (file)
@@ -777,6 +777,13 @@ struct btrfs_ioctl_received_subvol_args {
  */
 #define BTRFS_SEND_FLAG_VERSION                        0x8
 
+/*
+ * Send compressed data using the ENCODED_WRITE command instead of decompressing
+ * the data and sending it with the WRITE command. This requires protocol
+ * version >= 2.
+ */
+#define BTRFS_SEND_FLAG_COMPRESSED             0x10
+
 #define BTRFS_SEND_FLAG_MASK \
        (BTRFS_SEND_FLAG_NO_FILE_DATA | \
         BTRFS_SEND_FLAG_OMIT_STREAM_HEADER | \