From patchwork Fri Dec 1 22:11:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13476508 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="WUnV6Pku" Received: from mail-yw1-x1132.google.com (mail-yw1-x1132.google.com [IPv6:2607:f8b0:4864:20::1132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA15810FD for ; Fri, 1 Dec 2023 14:12:21 -0800 (PST) Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-5c08c47c055so29080907b3.1 for ; Fri, 01 Dec 2023 14:12:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1701468741; x=1702073541; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LzinTCkDfALoxVW/93SBKBIC+NFbTZc80WmEA1KnS5U=; b=WUnV6PkuCDym8X1mVrgDN/JsQ4eQ3oJDQE9h7LPJFoPja1CHIcOMX0hssakH2PvnQk C6rEx51hh9TPwDSYcDUaluUu058Sg5fdNWFXOFj8kGrFw5dwfxQoUybBHWIzzGflxU7l YEdpK/fPMJmu/Gg1dFIAxSXuGMUZ2LBwPco1xpdn7aPWM3dYDZTGrgMroWWJGknJwBpr jnzpNybm3M2pDAj3iEmqhyL3+/L4SBBvwGcmV8wa1FGDAoIqu/RZP3dcEs4Z56QRBu06 fG3suXMzAwnBzqpWO74uCntKY4OYf+X5y6u3LJi7+ZkV0Q213VhiqNDeF8PZhJj4uPBW vpnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701468741; x=1702073541; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LzinTCkDfALoxVW/93SBKBIC+NFbTZc80WmEA1KnS5U=; b=dfvS+tTRa55xfnncFW1Tw83TLh5ZdeDjqVv/vhKXywAX3lG5XNAqGKSfub07E49Qem 3MWCDfQONDtmsp3ZfDt9Pugx6DgHb3j2QoHNctjnH46wKvmdArDJ7eW6w4Hc9LAHtV75 u4Nk+yz5JLuT0ks6+3Zk7bok7lOrEOpjouX2vYdFmDYKK/e0owJd0D/PGrLFW5eaFXx6 V0AjMjMexpxe5RDO9INLR8b+IgtQ9SMFJ4v1JFfmDb3VNX3voU1f4Z3tqYqzInVzOVrr lvSDt2ZUh4RpVLIrs151O6UwChRoKIpBEziEMJ0jEGGqJBl+gKZznNNSYjRx3piT/JgI la8A== X-Gm-Message-State: AOJu0YwtJuXS0eQlC6RwV9QQ890d+5CkAxVG9nYOpQcp3Dblmees4dC6 Q10lltT0xCd6+bxdsfMnvfvluo2PjyNYbtZ/xyVsZA== X-Google-Smtp-Source: AGHT+IH8/SL3ehe18tXNjC/LUcLv0rpp8LnrsfN3yJxi/vBfvyeg3PxZcURMLxz/UEEyuMChRPHn6A== X-Received: by 2002:a05:690c:30a:b0:5ce:1046:c85e with SMTP id bg10-20020a05690c030a00b005ce1046c85emr400921ywb.28.1701468741014; Fri, 01 Dec 2023 14:12:21 -0800 (PST) Received: from localhost (076-182-020-124.res.spectrum.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id n14-20020a819e4e000000b0059b2be24f88sm1344917ywj.143.2023.12.01.14.12.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 14:12:20 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, linux-fsdevel@vger.kernel.org Cc: Sweet Tea Dorminy Subject: [PATCH v4 20/46] btrfs: set file extent encryption excplicitly Date: Fri, 1 Dec 2023 17:11:17 -0500 Message-ID: <7337bfb86c3546ffedb706df0e785e2a346aa374.1701468306.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Sweet Tea Dorminy This puts the long-preserved 1-byte encryption field to work, storing whether the extent is encrypted. Update the tree-checker to allow for the encryption bit to be set to our valid types. Signed-off-by: Sweet Tea Dorminy Signed-off-by: Josef Bacik --- fs/btrfs/accessors.h | 2 ++ fs/btrfs/inode.c | 8 ++++++-- fs/btrfs/tree-checker.c | 8 +++++--- fs/btrfs/tree-log.c | 2 ++ include/uapi/linux/btrfs_tree.h | 8 +++++++- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/accessors.h b/fs/btrfs/accessors.h index aa0844535644..5aaf204fa55f 100644 --- a/fs/btrfs/accessors.h +++ b/fs/btrfs/accessors.h @@ -949,6 +949,8 @@ BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes, struct btrfs_file_extent_item, disk_num_bytes, 64); BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression, struct btrfs_file_extent_item, compression, 8); +BTRFS_SETGET_STACK_FUNCS(stack_file_extent_encryption, + struct btrfs_file_extent_item, encryption, 8); BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 60d1e93c2567..f894f5b5e786 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3001,7 +3001,9 @@ static int insert_ordered_extent_file_extent(struct btrfs_trans_handle *trans, btrfs_set_stack_file_extent_num_bytes(&stack_fi, num_bytes); btrfs_set_stack_file_extent_ram_bytes(&stack_fi, ram_bytes); btrfs_set_stack_file_extent_compression(&stack_fi, oe->compress_type); - /* Encryption and other encoding is reserved and all 0 */ + btrfs_set_stack_file_extent_encryption(&stack_fi, + BTRFS_ENCRYPTION_NONE); + /* Other encoding is reserved and always 0 */ /* * For delalloc, when completing an ordered extent we update the inode's @@ -9671,7 +9673,9 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent( btrfs_set_stack_file_extent_num_bytes(&stack_fi, len); btrfs_set_stack_file_extent_ram_bytes(&stack_fi, len); btrfs_set_stack_file_extent_compression(&stack_fi, BTRFS_COMPRESS_NONE); - /* Encryption and other encoding is reserved and all 0 */ + btrfs_set_stack_file_extent_encryption(&stack_fi, + BTRFS_ENCRYPTION_NONE); + /* Other encoding is reserved and always 0 */ qgroup_released = btrfs_qgroup_release_data(inode, file_offset, len); if (qgroup_released < 0) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index 50fdc69fdddf..1af2c967436b 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -211,6 +211,7 @@ static int check_extent_data_item(struct extent_buffer *leaf, u32 sectorsize = fs_info->sectorsize; u32 item_size = btrfs_item_size(leaf, slot); u64 extent_end; + u8 policy; if (unlikely(!IS_ALIGNED(key->offset, sectorsize))) { file_extent_err(leaf, slot, @@ -262,10 +263,11 @@ static int check_extent_data_item(struct extent_buffer *leaf, BTRFS_NR_COMPRESS_TYPES - 1); return -EUCLEAN; } - if (unlikely(btrfs_file_extent_encryption(leaf, fi))) { + policy = btrfs_file_extent_encryption(leaf, fi); + if (unlikely(policy >= BTRFS_NR_ENCRYPTION_TYPES)) { file_extent_err(leaf, slot, - "invalid encryption for file extent, have %u expect 0", - btrfs_file_extent_encryption(leaf, fi)); + "invalid encryption for file extent, have %u expect range [0, %u]", + policy, BTRFS_NR_ENCRYPTION_TYPES - 1); return -EUCLEAN; } if (btrfs_file_extent_type(leaf, fi) == BTRFS_FILE_EXTENT_INLINE) { diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 89d3dc769b15..36063dc39443 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -4627,6 +4627,7 @@ static int log_one_extent(struct btrfs_trans_handle *trans, u64 extent_offset = em->start - em->orig_start; u64 block_len; int ret; + u8 encryption = BTRFS_ENCRYPTION_NONE; btrfs_set_stack_file_extent_generation(&fi, trans->transid); if (test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) @@ -4648,6 +4649,7 @@ static int log_one_extent(struct btrfs_trans_handle *trans, btrfs_set_stack_file_extent_num_bytes(&fi, em->len); btrfs_set_stack_file_extent_ram_bytes(&fi, em->ram_bytes); btrfs_set_stack_file_extent_compression(&fi, em->compress_type); + btrfs_set_stack_file_extent_encryption(&fi, encryption); ret = log_extent_csums(trans, inode, log, em, ctx); if (ret) diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h index 08f561da33cd..af56a5eb3a00 100644 --- a/include/uapi/linux/btrfs_tree.h +++ b/include/uapi/linux/btrfs_tree.h @@ -1101,8 +1101,14 @@ struct btrfs_file_extent_item { * but not for stat. */ __u8 compression; + + /* + * Type of encryption in use. Unencrypted value is 0. + */ __u8 encryption; - __le16 other_encoding; /* spare for later use */ + + /* spare for later use */ + __le16 other_encoding; /* are we inline data or a real extent? */ __u8 type;