From patchwork Wed Apr 19 21:20:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13217440 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9079C6FD18 for ; Wed, 19 Apr 2023 21:29:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229655AbjDSV3A (ORCPT ); Wed, 19 Apr 2023 17:29:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbjDSV27 (ORCPT ); Wed, 19 Apr 2023 17:28:59 -0400 Received: from mail-oo1-xc2d.google.com (mail-oo1-xc2d.google.com [IPv6:2607:f8b0:4864:20::c2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1F95170E for ; Wed, 19 Apr 2023 14:28:55 -0700 (PDT) Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-5472ead2f56so110603eaf.0 for ; Wed, 19 Apr 2023 14:28:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1681939735; x=1684531735; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=BT7Zbax0bpxmHqvJ/MXdpLOfsE8EUXSfjxvOFFyb5kQ=; b=UpkD5sjMFVuNvqqDcdcGcdZhUQCJp6pYfyEhx+nR21tc3xnXi6wVqYCpc2oYVkEHSK q58M0l1QK7Rg4w9WmqyBiZQELM0SkKR/RrM2Nm2WAaFnG34jsIqSNB4/F8keNomy7KdQ AKMLgLDDg/V3X8gGNRMSDtLqNayVa8JkZLdB5Dt7D6nOBeaPNTLxQU1FPKhphK+BxMIc VucOVMOsnaV3uDnxUt8X9z72kF4jtFxObszG9+pvu80xpSO2TqGZv/Uv2QRHu2qz7sHB FlW2DV9YiwxCt4LdKK+2ImN2WrN3jrLETew/tZq26PzmK8pbLk0Ati8youRmFkmIUeh3 dGqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681939735; x=1684531735; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BT7Zbax0bpxmHqvJ/MXdpLOfsE8EUXSfjxvOFFyb5kQ=; b=TpZnxLauLMpGjRwIMv+vi9aExPaNf6QkiVY5qm2ZHSQ9FSem0DiCkhfp8TQzfWXlVd DTZh47hcdE59568iCB/Fwk5dbMIrhu7/8XkeAnUJfxMtPPwPjsPLT61sAy5CepuXukNm rivCcWlstu2hHoDqGBtOMgEkGieypq7zF93JHma6eGLEfclVH2v104hw3F0mpwMy6B8r /TYfyYN4lFvUbPqhRpr6CqDrLbmMGjDC40LgdCpTIoioxztuPn8D321dAuWwfugwOT7y Hj6J3rt5vnFV+HtF2TQdzhmQyaPG9Fy3JK/u4KRBMtOYVCX4Ox0mWaK5JtwzswPFXeiX IN3g== X-Gm-Message-State: AAQBX9fvl47wlt0/vmNw5tW201VZk8hKp219MQzZOTlaAi4Vx3knSTMz zzNQ14lwQdtQVNbGTOdH7QWeYs7BCIUwVLqlPcYt/Q== X-Google-Smtp-Source: AKy350brXqmv5svzm8zXiGzRvzYPlVRQIluiAqTg0esrLJWn70mwldJ46vRfWkIJ17K4fNHWjDTD8g== X-Received: by 2002:a05:6214:f2c:b0:5f1:6c0a:1df6 with SMTP id iw12-20020a0562140f2c00b005f16c0a1df6mr7041694qvb.37.1681939255189; Wed, 19 Apr 2023 14:20:55 -0700 (PDT) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id i8-20020a05620a27c800b0074e1625917bsm552183qkp.32.2023.04.19.14.20.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:20:54 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 01/10] btrfs-progs: const-ify the extent buffer helpers Date: Wed, 19 Apr 2023 17:20:41 -0400 Message-Id: <9e136253b6e9ae2cbd929552f4e36a3a641cad1f.1681939107.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org These helpers are all take const struct extent_buffer in the kernel, do the same in btrfs-progs in order to enable us to more easily sync ctree.c. Signed-off-by: Josef Bacik --- kernel-shared/extent_io.c | 15 ++++++++------- kernel-shared/extent_io.h | 10 ++++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/kernel-shared/extent_io.c b/kernel-shared/extent_io.c index 46c0fb3f..01dc5b1e 100644 --- a/kernel-shared/extent_io.c +++ b/kernel-shared/extent_io.c @@ -609,26 +609,27 @@ void write_extent_buffer(const struct extent_buffer *eb, const void *src, memcpy((void *)eb->data + start, src, len); } -void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src, +void copy_extent_buffer(const struct extent_buffer *dst, + const struct extent_buffer *src, unsigned long dst_offset, unsigned long src_offset, unsigned long len) { - memcpy(dst->data + dst_offset, src->data + src_offset, len); + memcpy((void *)dst->data + dst_offset, src->data + src_offset, len); } -void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, +void memmove_extent_buffer(const struct extent_buffer *dst, unsigned long dst_offset, unsigned long src_offset, unsigned long len) { - memmove(dst->data + dst_offset, dst->data + src_offset, len); + memmove((void *)dst->data + dst_offset, dst->data + src_offset, len); } -void memset_extent_buffer(struct extent_buffer *eb, char c, +void memset_extent_buffer(const struct extent_buffer *eb, char c, unsigned long start, unsigned long len) { - memset(eb->data + start, c, len); + memset((void *)eb->data + start, c, len); } -int extent_buffer_test_bit(struct extent_buffer *eb, unsigned long start, +int extent_buffer_test_bit(const struct extent_buffer *eb, unsigned long start, unsigned long nr) { return le_test_bit(nr, (u8 *)eb->data + start); diff --git a/kernel-shared/extent_io.h b/kernel-shared/extent_io.h index 8ba56eed..69133c3c 100644 --- a/kernel-shared/extent_io.h +++ b/kernel-shared/extent_io.h @@ -110,14 +110,16 @@ void read_extent_buffer(const struct extent_buffer *eb, void *dst, unsigned long start, unsigned long len); void write_extent_buffer(const struct extent_buffer *eb, const void *src, unsigned long start, unsigned long len); -void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src, +void copy_extent_buffer(const struct extent_buffer *dst, + const struct extent_buffer *src, unsigned long dst_offset, unsigned long src_offset, unsigned long len); -void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, +void memmove_extent_buffer(const struct extent_buffer *dst, + const unsigned long dst_offset, unsigned long src_offset, unsigned long len); -void memset_extent_buffer(struct extent_buffer *eb, char c, +void memset_extent_buffer(const struct extent_buffer *eb, char c, unsigned long start, unsigned long len); -int extent_buffer_test_bit(struct extent_buffer *eb, unsigned long start, +int extent_buffer_test_bit(const struct extent_buffer *eb, unsigned long start, unsigned long nr); int set_extent_buffer_dirty(struct extent_buffer *eb); int clear_extent_buffer_dirty(struct extent_buffer *eb); From patchwork Wed Apr 19 21:20:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13217415 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27DDCC77B73 for ; Wed, 19 Apr 2023 21:22:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232353AbjDSVW5 (ORCPT ); Wed, 19 Apr 2023 17:22:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231608AbjDSVW4 (ORCPT ); Wed, 19 Apr 2023 17:22:56 -0400 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22A9876BD for ; Wed, 19 Apr 2023 14:22:29 -0700 (PDT) Received: by mail-qv1-xf32.google.com with SMTP id op30so1106070qvb.3 for ; Wed, 19 Apr 2023 14:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1681939256; x=1684531256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=xz8gpPaByzawAWuecubJhEojv5oZuLnDMLW4n8G5Ikk=; b=SO+xpz7s/GDz4q1tB7Jjr+LcJUzgU497VQEMtdlikctbJJBnfYOS2yZGHE3T1teY+W TmkeJ1LSmSRL9mJJ+OhLC7dR97LrsH0v/Tt79rChT949By9rznT7eZ+Ojd8HEvX1blQ2 Gca2Yd66m5wc+oiQEQ0ho+B2qW7Aw7BxGYg85Vd9kbqJGpiK7l4H8euzHWmxgOtezelO YKZOlWvvNQv8X3X+EO14SLMuWiFuDvfrp0YBJoU0zitKiEH/yOJPn2I+NJ6vyHiKfyrv ESaPQ/NN1CgT/R28HTa8i9raPDszimcVwxqfu5p79Ov1l37c2VCujRnpetVM7oJAn6kO 2ETQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681939256; x=1684531256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xz8gpPaByzawAWuecubJhEojv5oZuLnDMLW4n8G5Ikk=; b=lIRFvq3Oqfr87wvMwiBG2fsYXuz/jTONLhxQMecO+eAX4Q28PmpdrqRQlyYb+T9O26 fWubOK8KlmchxuNCv3erm/09FHrI1td2ZFbCM/uiEWCMz8309AcNfds07ugyQeTL3cYm P1B4apv1tte+qEBvT7N1DgUPRBl5cQQWl8AUSEny22ItbF/s26qMYM/SH6GO8XhlWgxv q/F1jHwCEu6TAjibiN8TJ/I479fdaqSUnyVYFKjcBUBfaX7yZN/pnyrvQnu2t8Xm0ElL q/QWlgmyqRJeHY83QRpT1rFrOAcKlnoJk8I5yG8zGBu5TCC7PjXuy6Yulhhd2DFwOCeY e5/Q== X-Gm-Message-State: AAQBX9e9zLfETAqoaAFjKsl53AiKf/oELtmI+m4XwEjfXJTB0t8tviFg I+BN8FOor8Y5qNth2fhC717oefm8Dpi2groTplnFBw== X-Google-Smtp-Source: AKy350bGaRsaoIltxUxa4hWK3pbdvfMwZgH48UFup1ZqWWxxq0tmvkIUwWSHZsfiLYFKL8v7P60WTg== X-Received: by 2002:ad4:4eae:0:b0:5ca:83ed:12be with SMTP id ed14-20020ad44eae000000b005ca83ed12bemr37095458qvb.21.1681939256435; Wed, 19 Apr 2023 14:20:56 -0700 (PDT) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id pr27-20020a056214141b00b005dd8b9345f8sm4570844qvb.144.2023.04.19.14.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:20:56 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 02/10] btrfs-progs: bring root->state into btrfs-progs Date: Wed, 19 Apr 2023 17:20:42 -0400 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We changed from members in the root for all the different flags to a bit based flag system. In order to make syncing the kernel code into btrfs-progs easier go ahead and sync in the bits we use and update all the users of the old ->track_dirty and ->ref_cows to use the state bits. Signed-off-by: Josef Bacik --- check/main.c | 3 +- kernel-shared/ctree.c | 22 ++++++++----- kernel-shared/ctree.h | 66 +++++++++++++++++++++++++++++++++++-- kernel-shared/disk-io.c | 21 ++++++------ kernel-shared/extent-tree.c | 10 +++--- 5 files changed, 94 insertions(+), 28 deletions(-) diff --git a/check/main.c b/check/main.c index 99ff3bc3..45e3442d 100644 --- a/check/main.c +++ b/check/main.c @@ -63,6 +63,7 @@ #include "check/qgroup-verify.h" #include "check/clear-cache.h" #include "kernel-shared/uapi/btrfs.h" +#include "kernel-lib/bitops.h" /* Global context variables */ struct btrfs_fs_info *gfs_info; @@ -467,7 +468,7 @@ static void record_root_in_trans(struct btrfs_trans_handle *trans, struct btrfs_root *root) { if (root->last_trans != trans->transid) { - root->track_dirty = 1; + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); root->last_trans = trans->transid; root->commit_root = root->node; extent_buffer_get(root->node); diff --git a/kernel-shared/ctree.c b/kernel-shared/ctree.c index 911ec51c..cfbcc689 100644 --- a/kernel-shared/ctree.c +++ b/kernel-shared/ctree.c @@ -20,6 +20,7 @@ #include "kernel-shared/disk-io.h" #include "kernel-shared/transaction.h" #include "kernel-shared/print-tree.h" +#include "kernel-lib/bitops.h" #include "crypto/crc32c.h" #include "common/internal.h" #include "common/messages.h" @@ -119,7 +120,8 @@ void btrfs_release_path(struct btrfs_path *p) void add_root_to_dirty_list(struct btrfs_root *root) { - if (root->track_dirty && list_empty(&root->dirty_list)) { + if (test_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state) && + list_empty(&root->dirty_list)) { list_add(&root->dirty_list, &root->fs_info->dirty_cowonly_roots); } @@ -155,9 +157,10 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans, memcpy(new_root, root, sizeof(*new_root)); new_root->root_key.objectid = new_root_objectid; - WARN_ON(root->ref_cows && trans->transid != - root->fs_info->running_transaction->transid); - WARN_ON(root->ref_cows && trans->transid != root->last_trans); + WARN_ON(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) && + trans->transid != root->fs_info->running_transaction->transid); + WARN_ON(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) && + trans->transid != root->last_trans); level = btrfs_header_level(buf); if (level == 0) @@ -219,7 +222,7 @@ int btrfs_create_root(struct btrfs_trans_handle *trans, btrfs_setup_root(new_root, fs_info, objectid); if (!is_fstree(objectid)) - new_root->track_dirty = 1; + set_bit(BTRFS_ROOT_TRACK_DIRTY, &new_root->state); add_root_to_dirty_list(new_root); new_root->objectid = objectid; @@ -332,7 +335,7 @@ static int btrfs_block_can_be_shared(struct btrfs_root *root, * snapshot and the block was not allocated by tree relocation, * we know the block is not shared. */ - if (root->ref_cows && + if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) && buf != root->node && buf != root->commit_root && (btrfs_header_generation(buf) <= btrfs_root_last_snapshot(&root->root_item) || @@ -446,9 +449,10 @@ int __btrfs_cow_block(struct btrfs_trans_handle *trans, struct btrfs_disk_key disk_key; int level; - WARN_ON(root->ref_cows && trans->transid != - root->fs_info->running_transaction->transid); - WARN_ON(root->ref_cows && trans->transid != root->last_trans); + WARN_ON(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) && + trans->transid != root->fs_info->running_transaction->transid); + WARN_ON(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) && + trans->transid != root->last_trans); level = btrfs_header_level(buf); diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index 8de1fba4..84acefef 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -388,6 +388,68 @@ static inline bool btrfs_is_zoned(const struct btrfs_fs_info *fs_info) return fs_info->zoned != 0; } +/* + * The state of btrfs root + */ +enum { + /* + * btrfs_record_root_in_trans is a multi-step process, and it can race + * with the balancing code. But the race is very small, and only the + * first time the root is added to each transaction. So IN_TRANS_SETUP + * is used to tell us when more checks are required + */ + BTRFS_ROOT_IN_TRANS_SETUP, + + /* + * Set if tree blocks of this root can be shared by other roots. + * Only subvolume trees and their reloc trees have this bit set. + * Conflicts with TRACK_DIRTY bit. + * + * This affects two things: + * + * - How balance works + * For shareable roots, we need to use reloc tree and do path + * replacement for balance, and need various pre/post hooks for + * snapshot creation to handle them. + * + * While for non-shareable trees, we just simply do a tree search + * with COW. + * + * - How dirty roots are tracked + * For shareable roots, btrfs_record_root_in_trans() is needed to + * track them, while non-subvolume roots have TRACK_DIRTY bit, they + * don't need to set this manually. + */ + BTRFS_ROOT_SHAREABLE, + BTRFS_ROOT_TRACK_DIRTY, + BTRFS_ROOT_IN_RADIX, + BTRFS_ROOT_ORPHAN_ITEM_INSERTED, + BTRFS_ROOT_DEFRAG_RUNNING, + BTRFS_ROOT_FORCE_COW, + BTRFS_ROOT_MULTI_LOG_TASKS, + BTRFS_ROOT_DIRTY, + BTRFS_ROOT_DELETING, + + /* + * Reloc tree is orphan, only kept here for qgroup delayed subtree scan + * + * Set for the subvolume tree owning the reloc tree. + */ + BTRFS_ROOT_DEAD_RELOC_TREE, + /* Mark dead root stored on device whose cleanup needs to be resumed */ + BTRFS_ROOT_DEAD_TREE, + /* The root has a log tree. Used for subvolume roots and the tree root. */ + BTRFS_ROOT_HAS_LOG_TREE, + /* Qgroup flushing is in progress */ + BTRFS_ROOT_QGROUP_FLUSHING, + /* We started the orphan cleanup for this root. */ + BTRFS_ROOT_ORPHAN_CLEANUP, + /* This root has a drop operation that was started previously. */ + BTRFS_ROOT_UNFINISHED_DROP, + /* This reloc root needs to have its buffers lockdep class reset. */ + BTRFS_ROOT_RESET_LOCKDEP_CLASS, +}; + /* * in ram representation of the tree. extent_root is used for all allocations * and for the extent tree extent_root root. @@ -401,9 +463,7 @@ struct btrfs_root { u64 objectid; u64 last_trans; - int ref_cows; - int track_dirty; - + unsigned long state; u32 type; u64 last_inode_alloc; diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c index 030bc780..44462d8f 100644 --- a/kernel-shared/disk-io.c +++ b/kernel-shared/disk-io.c @@ -32,6 +32,7 @@ #include "crypto/crc32c.h" #include "common/utils.h" #include "kernel-shared/print-tree.h" +#include "kernel-lib/bitops.h" #include "common/rbtree-utils.h" #include "common/device-scan.h" #include "common/device-utils.h" @@ -491,8 +492,7 @@ void btrfs_setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info, { root->node = NULL; root->commit_root = NULL; - root->ref_cows = 0; - root->track_dirty = 0; + root->state = 0; root->fs_info = fs_info; root->objectid = objectid; @@ -654,9 +654,9 @@ out: } insert: if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) - root->track_dirty = 1; + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); if (is_fstree(root->root_key.objectid)) - root->ref_cows = 1; + set_bit(BTRFS_ROOT_SHAREABLE, &root->state); return root; } @@ -1062,7 +1062,7 @@ static int load_global_roots_objectid(struct btrfs_fs_info *fs_info, free(root); break; } - root->track_dirty = 1; + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); ret = btrfs_global_root_insert(fs_info, root); if (ret) { @@ -1099,7 +1099,7 @@ static int load_global_roots_objectid(struct btrfs_fs_info *fs_info, root->root_key.objectid = objectid; root->root_key.type = BTRFS_ROOT_ITEM_KEY; root->root_key.offset = i; - root->track_dirty = 1; + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); root->node = btrfs_find_create_tree_block(fs_info, 0); if (!root->node) { free(root); @@ -1232,7 +1232,8 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr, error("couldn't load block group tree"); return -EIO; } - fs_info->block_group_root->track_dirty = 1; + set_bit(BTRFS_ROOT_TRACK_DIRTY, + &fs_info->block_group_root->state); } ret = btrfs_find_and_setup_root(root, fs_info, @@ -1242,7 +1243,7 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr, printk("Couldn't setup device tree\n"); return -EIO; } - fs_info->dev_root->track_dirty = 1; + set_bit(BTRFS_ROOT_TRACK_DIRTY, &fs_info->dev_root->state); ret = btrfs_find_and_setup_root(root, fs_info, BTRFS_UUID_TREE_OBJECTID, @@ -1251,7 +1252,7 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr, free(fs_info->uuid_root); fs_info->uuid_root = NULL; } else { - fs_info->uuid_root->track_dirty = 1; + set_bit(BTRFS_ROOT_TRACK_DIRTY, &fs_info->uuid_root->state); } ret = btrfs_find_and_setup_root(root, fs_info, @@ -2355,7 +2356,7 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, extent_buffer_get(root->node); root->commit_root = root->node; - root->track_dirty = 1; + set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state); root->root_item.flags = 0; root->root_item.byte_limit = 0; diff --git a/kernel-shared/extent-tree.c b/kernel-shared/extent-tree.c index 2a71b97a..8f3477bf 100644 --- a/kernel-shared/extent-tree.c +++ b/kernel-shared/extent-tree.c @@ -1471,7 +1471,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans, nritems = btrfs_header_nritems(buf); level = btrfs_header_level(buf); - if (!root->ref_cows && level == 0) + if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state) && level == 0) return 0; if (inc) @@ -2359,11 +2359,11 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans, } /* - * Also preallocate metadata for csum tree and fs trees (root->ref_cows - * already set), as they can consume a lot of metadata space. - * Pre-allocate to avoid unexpected ENOSPC. + * Also preallocate metadata for csum tree and fs trees + * (BTRFS_ROOT_SHAREABLE already set) as they can consume a lot of + * metadata space. Pre-allocate to avoid unexpected ENOSPC. */ - if (root->ref_cows || + if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) || root->root_key.objectid == BTRFS_CSUM_TREE_OBJECTID) { if (!(profile & BTRFS_BLOCK_GROUP_METADATA)) { ret = do_chunk_alloc(trans, info, From patchwork Wed Apr 19 21:20:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13217417 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28BB2C6FD18 for ; Wed, 19 Apr 2023 21:23:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231582AbjDSVX0 (ORCPT ); Wed, 19 Apr 2023 17:23:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbjDSVXT (ORCPT ); Wed, 19 Apr 2023 17:23:19 -0400 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34B185BB2 for ; Wed, 19 Apr 2023 14:22:57 -0700 (PDT) Received: by mail-qt1-f181.google.com with SMTP id fy11so594892qtb.12 for ; Wed, 19 Apr 2023 14:22:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1681939258; x=1684531258; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=a1F3Va4ZvJHGkHs0CIEZEWjSXJYpO1ErBYNd34ZGR8s=; b=C973+sju0MjVp6PnRqJ6293n8VbJERRalLldIf2+p6ZlzPHE2VqpnEWFpFDmeu6/c1 wXU2V+xVeTLKp3FRV0pEsyNiv7pRcQn4CJJZupAPiIeH52HjIQ1spUHGiqFOQCPtFcBA tDxg1NI19CN5rUKBMu4gCtPEVNfAjhiW1xzHCO5YF4sOxn8NsjF5jyCTkzolKi2bgd0k Zg5WCOgv07uXlhUfFtaH0zWwZZIdEHUZgWuJvuzcWAVyOjqy8WV8clHKiPpGMr/5e2uh wEyZxzRsQ4Z0OU0fkgenX1LDT6p8AbyQZJMuuepwkL7ccOEoWjUIXNqJBCzdexSc1dMR C1Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681939258; x=1684531258; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a1F3Va4ZvJHGkHs0CIEZEWjSXJYpO1ErBYNd34ZGR8s=; b=H8A+1iGLxUjrzAdgDJZLt6Ar0oJOYyAzpd+bxyY+TFVd2ANo0bZn52aES9V9DBuFD1 xPghZ8gaOIpv2SnBpMLqmh7Zd7No9vHStFJO3NlVcSJ4rKaHh6DGOrLaAEGJ30d/JzEj uyv8cwuQC42VpNZmhBCUuJObMjrvBAihsRKPA86t97cMm/INxDRfT/qI2TLcM//NKWGQ 2Yk2fs46zT96jKUWRDFaPvk86AzsZIKMgDKwrCB4I2mTeWL0VyaQn/gy7ncXy11UfYHt 9Mch+s8f2FpKeI3toJ5SoEFWi75I0Ru9HrpYBoH8ri8Uq4SOdaxbRbwQIMul4WiEnqOF W5rA== X-Gm-Message-State: AAQBX9f5yXGk3XqqwfjxmxadfB15jqMAfc8Gm2UvADI7hNSXtHHo4ubS SfqN4DOhXCByEcIWbJ3VBj9tBw8NQcfUr5VxettnCg== X-Google-Smtp-Source: AKy350bkTz3QZadYCMqGvkkTy6A2+7CTZ+20Y0OndudOkyub1gKM38ash9X69Qf/Abi54h0cJAKrDQ== X-Received: by 2002:ac8:7d54:0:b0:3e6:386b:2314 with SMTP id h20-20020ac87d54000000b003e6386b2314mr8487651qtb.62.1681939257683; Wed, 19 Apr 2023 14:20:57 -0700 (PDT) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id q9-20020a05620a0d8900b00706b09b16fasm4944669qkl.11.2023.04.19.14.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:20:57 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 03/10] btrfs-progs: rename btrfs_alloc_free_block to btrfs_alloc_tree_block Date: Wed, 19 Apr 2023 17:20:43 -0400 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is in keeping with what the function actually does, and is named this way in the kernel. Signed-off-by: Josef Bacik --- check/main.c | 2 +- cmds/rescue-chunk-recover.c | 2 +- kernel-shared/ctree.c | 14 +++++++------- kernel-shared/ctree.h | 2 +- kernel-shared/disk-io.c | 2 +- kernel-shared/extent-tree.c | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/check/main.c b/check/main.c index 45e3442d..c5131b7a 100644 --- a/check/main.c +++ b/check/main.c @@ -9096,7 +9096,7 @@ static struct extent_buffer *btrfs_fsck_clear_root( if (!path) return ERR_PTR(-ENOMEM); - c = btrfs_alloc_free_block(trans, gfs_info->tree_root, + c = btrfs_alloc_tree_block(trans, gfs_info->tree_root, gfs_info->nodesize, key->objectid, &disk_key, 0, 0, 0); if (IS_ERR(c)) { diff --git a/cmds/rescue-chunk-recover.c b/cmds/rescue-chunk-recover.c index ce53da2e..b18d422e 100644 --- a/cmds/rescue-chunk-recover.c +++ b/cmds/rescue-chunk-recover.c @@ -1146,7 +1146,7 @@ static int __rebuild_chunk_root(struct btrfs_trans_handle *trans, btrfs_set_disk_key_type(&disk_key, BTRFS_DEV_ITEM_KEY); btrfs_set_disk_key_offset(&disk_key, min_devid); - cow = btrfs_alloc_free_block(trans, root, root->fs_info->nodesize, + cow = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize, BTRFS_CHUNK_TREE_OBJECTID, &disk_key, 0, 0, 0); btrfs_set_header_bytenr(cow, cow->start); diff --git a/kernel-shared/ctree.c b/kernel-shared/ctree.c index cfbcc689..230dae1b 100644 --- a/kernel-shared/ctree.c +++ b/kernel-shared/ctree.c @@ -167,7 +167,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans, btrfs_item_key(buf, &disk_key, 0); else btrfs_node_key(buf, &disk_key, 0); - cow = btrfs_alloc_free_block(trans, new_root, buf->len, + cow = btrfs_alloc_tree_block(trans, new_root, buf->len, new_root_objectid, &disk_key, level, buf->start, 0); if (IS_ERR(cow)) { @@ -230,7 +230,7 @@ int btrfs_create_root(struct btrfs_trans_handle *trans, new_root->root_key.type = BTRFS_ROOT_ITEM_KEY; new_root->root_key.offset = 0; - node = btrfs_alloc_free_block(trans, new_root, fs_info->nodesize, + node = btrfs_alloc_tree_block(trans, new_root, fs_info->nodesize, objectid, &disk_key, 0, 0, 0); if (IS_ERR(node)) { ret = PTR_ERR(node); @@ -285,7 +285,7 @@ int btrfs_create_root(struct btrfs_trans_handle *trans, /* * Essential trees can't be created by this function, yet. * As we expect such skeleton exists, or a lot of functions like - * btrfs_alloc_free_block() doesn't work at all + * btrfs_alloc_tree_block() doesn't work at all */ case BTRFS_ROOT_TREE_OBJECTID: case BTRFS_EXTENT_TREE_OBJECTID: @@ -461,7 +461,7 @@ int __btrfs_cow_block(struct btrfs_trans_handle *trans, else btrfs_node_key(buf, &disk_key, 0); - cow = btrfs_alloc_free_block(trans, root, buf->len, + cow = btrfs_alloc_tree_block(trans, root, buf->len, root->root_key.objectid, &disk_key, level, search_start, empty_size); if (IS_ERR(cow)) @@ -1732,7 +1732,7 @@ static int noinline insert_new_root(struct btrfs_trans_handle *trans, else btrfs_node_key(lower, &lower_key, 0); - c = btrfs_alloc_free_block(trans, root, root->fs_info->nodesize, + c = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize, root->root_key.objectid, &lower_key, level, root->node->start, 0); @@ -1858,7 +1858,7 @@ static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root mid = (c_nritems + 1) / 2; btrfs_node_key(c, &disk_key, mid); - split = btrfs_alloc_free_block(trans, root, root->fs_info->nodesize, + split = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize, root->root_key.objectid, &disk_key, level, c->start, 0); if (IS_ERR(split)) @@ -2425,7 +2425,7 @@ again: else btrfs_item_key(l, &disk_key, mid); - right = btrfs_alloc_free_block(trans, root, root->fs_info->nodesize, + right = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize, root->root_key.objectid, &disk_key, 0, l->start, 0); if (IS_ERR(right)) { diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index 84acefef..af60ba66 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -849,7 +849,7 @@ struct btrfs_block_group *btrfs_lookup_block_group(struct btrfs_fs_info *info, struct btrfs_block_group *btrfs_lookup_first_block_group(struct btrfs_fs_info *info, u64 bytenr); -struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, +struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, u32 blocksize, u64 root_objectid, struct btrfs_disk_key *key, int level, diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c index 44462d8f..6f9dc327 100644 --- a/kernel-shared/disk-io.c +++ b/kernel-shared/disk-io.c @@ -2333,7 +2333,7 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, btrfs_setup_root(root, fs_info, key->objectid); memcpy(&root->root_key, key, sizeof(struct btrfs_key)); - leaf = btrfs_alloc_free_block(trans, root, fs_info->nodesize, + leaf = btrfs_alloc_tree_block(trans, root, fs_info->nodesize, root->root_key.objectid, NULL, 0, 0, 0); if (IS_ERR(leaf)) { ret = PTR_ERR(leaf); diff --git a/kernel-shared/extent-tree.c b/kernel-shared/extent-tree.c index 8f3477bf..d0b3aee3 100644 --- a/kernel-shared/extent-tree.c +++ b/kernel-shared/extent-tree.c @@ -2555,7 +2555,7 @@ static int alloc_tree_block(struct btrfs_trans_handle *trans, * helper function to allocate a block for a given tree * returns the tree buffer or NULL. */ -struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, +struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, u32 blocksize, u64 root_objectid, struct btrfs_disk_key *key, int level, From patchwork Wed Apr 19 21:20:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13217439 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 682B9C6FD18 for ; Wed, 19 Apr 2023 21:26:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230024AbjDSV0R (ORCPT ); Wed, 19 Apr 2023 17:26:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231882AbjDSV0I (ORCPT ); Wed, 19 Apr 2023 17:26:08 -0400 Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com [209.85.160.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42EFE44B9 for ; Wed, 19 Apr 2023 14:26:01 -0700 (PDT) Received: by mail-qt1-f178.google.com with SMTP id u37so609107qtc.10 for ; Wed, 19 Apr 2023 14:26:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1681939259; x=1684531259; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Irty1JCzmlqfbhk1GjFOZaC956f0imcZUTjycoE/40I=; b=BDKQubUyJHfh0npSCFlilZXEHLux5FcXAdOfaXAW46Zvw30czzP9Nx+pS/NeTlkIUZ Di4vRWu5kVrMsbyC2ofykfb1YUOii2u/Z3Bhyc7MjltDWM1xkGvfKwd6UuKcHv5YP/df omxbg4BH1ab5UvZbRXJb5e9MqfbBK9psfpqtXhyj6DtGjylLCMmU8T2JGv2eQFAaDgrH x6UBQKdaMzcEAJTNrEjz+RcL+LqLjJPklvfyTx7a2G9Wmzb5acjz7MICpbfDSlHvRhHj nBdQciFZSHgjVC7G9e2gCssNmp/mxY8ksarPwF8n0h61/Mjal08EfEQTgNUSW1+Oljnq UY8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681939259; x=1684531259; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Irty1JCzmlqfbhk1GjFOZaC956f0imcZUTjycoE/40I=; b=Yi0Sx5p1NhpeQjjutuLej4st9JTxHJLs4ZeprZp5xMGt78urYej2gMQ9N5svjaAqRD UFv9PyGxQKPjJz4Q1rPQ80YKs0OvMs3MWJjzLS4mBlboTGLoEOGCkt95C4AKaXsfHBnu sZiigew6/VobHvHDwPK2vNqawzU6EnIxQ3aRwsw66+BmbGwDgtEjhJR0pIcz5GDzt+5e dCDzr9ZlcFx6TzirW9b276zz0/HVXxnS43Dpz6qCxz5BVmWgaBHRx+D3vi77yVynUDqr xb/VjO/Cpp4182DwHgFGV7Gahr5ZRIPLtP+HBACBcj3gWPX5DIQC/NgR4W+TxgVd1oVR BM8Q== X-Gm-Message-State: AAQBX9fnHJh1fnyjJYcm3XqpvcWDrCNu/pVSkYk0aiDPd2+X9m7luLbB Mpb+GE32yEz+FIeNhvYARobsTkyDvmW5+/Tg7T1JWg== X-Google-Smtp-Source: AKy350bqe63FzPzKG7DTsjAIg0UrA6iIC+blAsRWUI4NKZcqEK5dHKvoEP6/AmCkGXzt9uQq/sz4pg== X-Received: by 2002:ac8:5b8e:0:b0:3ee:4dc1:2c3a with SMTP id a14-20020ac85b8e000000b003ee4dc12c3amr7008991qta.64.1681939259006; Wed, 19 Apr 2023 14:20:59 -0700 (PDT) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id r2-20020a05622a034200b003ef42f84532sm35898qtw.49.2023.04.19.14.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:20:58 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 04/10] btrfs-progs: sync locking.h and stub out all the helpers Date: Wed, 19 Apr 2023 17:20:44 -0400 Message-Id: <8fa8bb3bb91f23cc1c0b567941eecce129499251.1681939107.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We want locking.h to have all the definitions that get used throughout the codebase, however we don't want to actually use any of the actual locking. This sync's the bulk of locking.h, and then stubs out all of the definitions. We need a locking.c for the root lock helpers that return the extent buffer, but everything else can simply be inlined out. Signed-off-by: Josef Bacik --- Makefile | 1 + include/kerncompat.h | 4 + kernel-shared/locking.c | 22 ++++ kernel-shared/locking.h | 258 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 285 insertions(+) create mode 100644 kernel-shared/locking.c create mode 100644 kernel-shared/locking.h diff --git a/Makefile b/Makefile index 43dfd296..8001f46a 100644 --- a/Makefile +++ b/Makefile @@ -182,6 +182,7 @@ objects = \ kernel-shared/free-space-tree.o \ kernel-shared/inode-item.o \ kernel-shared/inode.o \ + kernel-shared/locking.o \ kernel-shared/messages.o \ kernel-shared/print-tree.o \ kernel-shared/root-tree.o \ diff --git a/include/kerncompat.h b/include/kerncompat.h index 68007915..28e9f443 100644 --- a/include/kerncompat.h +++ b/include/kerncompat.h @@ -615,6 +615,10 @@ do { \ #define smp_mb__before_atomic() do {} while (0) #define smp_mb() do {} while (0) +struct percpu_counter { + int count; +}; + typedef struct refcount_struct { int refs; } refcount_t; diff --git a/kernel-shared/locking.c b/kernel-shared/locking.c new file mode 100644 index 00000000..c4138e68 --- /dev/null +++ b/kernel-shared/locking.c @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2008 Oracle. All rights reserved. + */ + +#include "ctree.h" +#include "locking.h" + +struct extent_buffer *btrfs_read_lock_root_node(struct btrfs_root *root) +{ + return root->node; +} + +struct extent_buffer *btrfs_try_read_lock_root_node(struct btrfs_root *root) +{ + return root->node; +} + +struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root) +{ + return root->node; +} diff --git a/kernel-shared/locking.h b/kernel-shared/locking.h new file mode 100644 index 00000000..02c302e4 --- /dev/null +++ b/kernel-shared/locking.h @@ -0,0 +1,258 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2008 Oracle. All rights reserved. + */ + +#ifndef BTRFS_LOCKING_H +#define BTRFS_LOCKING_H + +#include "kerncompat.h" + +#define BTRFS_WRITE_LOCK 1 +#define BTRFS_READ_LOCK 2 + +struct btrfs_root; + +/* + * We are limited in number of subclasses by MAX_LOCKDEP_SUBCLASSES, which at + * the time of this patch is 8, which is how many we use. Keep this in mind if + * you decide you want to add another subclass. + */ +enum btrfs_lock_nesting { + BTRFS_NESTING_NORMAL, + + /* + * When we COW a block we are holding the lock on the original block, + * and since our lockdep maps are rootid+level, this confuses lockdep + * when we lock the newly allocated COW'd block. Handle this by having + * a subclass for COW'ed blocks so that lockdep doesn't complain. + */ + BTRFS_NESTING_COW, + + /* + * Oftentimes we need to lock adjacent nodes on the same level while + * still holding the lock on the original node we searched to, such as + * for searching forward or for split/balance. + * + * Because of this we need to indicate to lockdep that this is + * acceptable by having a different subclass for each of these + * operations. + */ + BTRFS_NESTING_LEFT, + BTRFS_NESTING_RIGHT, + + /* + * When splitting we will be holding a lock on the left/right node when + * we need to cow that node, thus we need a new set of subclasses for + * these two operations. + */ + BTRFS_NESTING_LEFT_COW, + BTRFS_NESTING_RIGHT_COW, + + /* + * When splitting we may push nodes to the left or right, but still use + * the subsequent nodes in our path, keeping our locks on those adjacent + * blocks. Thus when we go to allocate a new split block we've already + * used up all of our available subclasses, so this subclass exists to + * handle this case where we need to allocate a new split block. + */ + BTRFS_NESTING_SPLIT, + + /* + * When promoting a new block to a root we need to have a special + * subclass so we don't confuse lockdep, as it will appear that we are + * locking a higher level node before a lower level one. Copying also + * has this problem as it appears we're locking the same block again + * when we make a snapshot of an existing root. + */ + BTRFS_NESTING_NEW_ROOT, + + /* + * We are limited to MAX_LOCKDEP_SUBLCLASSES number of subclasses, so + * add this in here and add a static_assert to keep us from going over + * the limit. As of this writing we're limited to 8, and we're + * definitely using 8, hence this check to keep us from messing up in + * the future. + */ + BTRFS_NESTING_MAX, +}; + +enum btrfs_lockdep_trans_states { + BTRFS_LOCKDEP_TRANS_COMMIT_START, + BTRFS_LOCKDEP_TRANS_UNBLOCKED, + BTRFS_LOCKDEP_TRANS_SUPER_COMMITTED, + BTRFS_LOCKDEP_TRANS_COMPLETED, +}; + +/* + * Lockdep annotation for wait events. + * + * @owner: The struct where the lockdep map is defined + * @lock: The lockdep map corresponding to a wait event + * + * This macro is used to annotate a wait event. In this case a thread acquires + * the lockdep map as writer (exclusive lock) because it has to block until all + * the threads that hold the lock as readers signal the condition for the wait + * event and release their locks. + */ +#define btrfs_might_wait_for_event(owner, lock) \ + do { \ + rwsem_acquire(&owner->lock##_map, 0, 0, _THIS_IP_); \ + rwsem_release(&owner->lock##_map, _THIS_IP_); \ + } while (0) + +/* + * Protection for the resource/condition of a wait event. + * + * @owner: The struct where the lockdep map is defined + * @lock: The lockdep map corresponding to a wait event + * + * Many threads can modify the condition for the wait event at the same time + * and signal the threads that block on the wait event. The threads that modify + * the condition and do the signaling acquire the lock as readers (shared + * lock). + */ +#define btrfs_lockdep_acquire(owner, lock) \ + rwsem_acquire_read(&owner->lock##_map, 0, 0, _THIS_IP_) + +/* + * Used after signaling the condition for a wait event to release the lockdep + * map held by a reader thread. + */ +#define btrfs_lockdep_release(owner, lock) \ + rwsem_release(&owner->lock##_map, _THIS_IP_) + +/* + * Macros for the transaction states wait events, similar to the generic wait + * event macros. + */ +#define btrfs_might_wait_for_state(owner, i) \ + do { \ + rwsem_acquire(&owner->btrfs_state_change_map[i], 0, 0, _THIS_IP_); \ + rwsem_release(&owner->btrfs_state_change_map[i], _THIS_IP_); \ + } while (0) + +#define btrfs_trans_state_lockdep_acquire(owner, i) \ + rwsem_acquire_read(&owner->btrfs_state_change_map[i], 0, 0, _THIS_IP_) + +#define btrfs_trans_state_lockdep_release(owner, i) \ + rwsem_release(&owner->btrfs_state_change_map[i], _THIS_IP_) + +/* Initialization of the lockdep map */ +#define btrfs_lockdep_init_map(owner, lock) \ + do { \ + static struct lock_class_key lock##_key; \ + lockdep_init_map(&owner->lock##_map, #lock, &lock##_key, 0); \ + } while (0) + +/* Initialization of the transaction states lockdep maps. */ +#define btrfs_state_lockdep_init_map(owner, lock, state) \ + do { \ + static struct lock_class_key lock##_key; \ + lockdep_init_map(&owner->btrfs_state_change_map[state], #lock, \ + &lock##_key, 0); \ + } while (0) + +struct btrfs_path; + +static inline void __btrfs_tree_lock(struct extent_buffer *eb, enum btrfs_lock_nesting nest) +{ +} + +static inline void btrfs_tree_lock(struct extent_buffer *eb) +{ +} + +static inline void btrfs_tree_unlock(struct extent_buffer *eb) +{ +} + +static inline void __btrfs_tree_read_lock(struct extent_buffer *eb, enum btrfs_lock_nesting nest) +{ +} + +static inline void btrfs_tree_read_lock(struct extent_buffer *eb) +{ +} + +static inline void btrfs_tree_read_unlock(struct extent_buffer *eb) +{ +} + +static inline int btrfs_try_tree_read_lock(struct extent_buffer *eb) +{ + return 1; +} + +static inline int btrfs_try_tree_write_lock(struct extent_buffer *eb) +{ + return 1; +} + +static inline void btrfs_assert_tree_write_locked(struct extent_buffer *eb) { } + +static inline void btrfs_unlock_up_safe(struct btrfs_path *path, int level) +{ +} + +struct extent_buffer *btrfs_read_lock_root_node(struct btrfs_root *root); +struct extent_buffer *btrfs_try_read_lock_root_node(struct btrfs_root *root); +struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root); + +static inline void btrfs_tree_unlock_rw(struct extent_buffer *eb, int rw) +{ + if (rw == BTRFS_WRITE_LOCK) + btrfs_tree_unlock(eb); + else if (rw == BTRFS_READ_LOCK) + btrfs_tree_read_unlock(eb); + else + BUG(); +} + +struct btrfs_drew_lock { + atomic_t readers; + struct percpu_counter writers; + wait_queue_head_t pending_writers; + wait_queue_head_t pending_readers; +}; + +static inline int btrfs_drew_lock_init(struct btrfs_drew_lock *lock) +{ + return 0; +} + +static inline void btrfs_drew_lock_destroy(struct btrfs_drew_lock *lock) +{ +} + +static inline void btrfs_drew_write_lock(struct btrfs_drew_lock *lock) +{ +} + +static inline bool btrfs_drew_try_write_lock(struct btrfs_drew_lock *lock) +{ + return true; +} + +static inline void btrfs_drew_write_unlock(struct btrfs_drew_lock *lock) +{ +} + +static inline void btrfs_drew_read_lock(struct btrfs_drew_lock *lock) +{ +} + +static inline void btrfs_drew_read_unlock(struct btrfs_drew_lock *lock) +{ +} + +static inline void btrfs_set_buffer_lockdep_class(u64 objectid, + struct extent_buffer *eb, int level) +{ +} +static inline void btrfs_maybe_reset_lockdep_class(struct btrfs_root *root, + struct extent_buffer *eb) +{ +} + +#endif From patchwork Wed Apr 19 21:20:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13217412 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5E38C6FD18 for ; Wed, 19 Apr 2023 21:22:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231953AbjDSVWi (ORCPT ); Wed, 19 Apr 2023 17:22:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbjDSVWh (ORCPT ); Wed, 19 Apr 2023 17:22:37 -0400 Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02FBC7D92 for ; Wed, 19 Apr 2023 14:22:04 -0700 (PDT) Received: by mail-qt1-x82d.google.com with SMTP id fg9so684417qtb.1 for ; Wed, 19 Apr 2023 14:22:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1681939260; x=1684531260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=mJL4BH5zfjlEK7ouLKrTVZCqb3jUq7HRx2RxvhPzGVE=; b=z4u88xZduHWoLJ5b8+7cAtW+tvGvHzYe//e+lFgt5GY5F9aDn0ShdwwrikbnCX1RpY fZcipgW+q3tSgTN6Iqce74zc61WbwtxfgDQFMDVjV1JBT6cN5bZ/w2IywcgUx/KKB5zC JLqs7+Hv6q75jSATpXD/nTLVLD77oY9TvSeMDWTb/pLPpKte3yYM4OGWjqovcO1gU7d7 jr9ShXsiYHZpl9CUGmbNqakchB2iuaLbDdVgDktMHjJD4iKnPHFRAsyNcTyZeKo8fEXl 0OnW8B8OdAPKZn3wzV/uZySDTcAw/by+Hhi9Tiy6yNe548LQ/3oY7w/Ix0a+FpH9YGz1 j9dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681939260; x=1684531260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mJL4BH5zfjlEK7ouLKrTVZCqb3jUq7HRx2RxvhPzGVE=; b=YE1YpqiOF34EeSXypakIAKMuyKv3kZS9VR3IGsPIeGaI3xvcbneJ79Cx8m1WuOGoCM 6nLj7GpYYd+wXmVOucSEjsG4N9ZqI7kB9hboWCNyVPNbMqxNyqn4IyuHo+SH2i4uCvc0 woOmzkzNoKVhQstA/wh7sRMIh50JUUnplhjXu7+VFW55mp0ieWSthFZGocDGZLW0EscU 9fsohpxaeh272IAdzELRHmSJG52ifobzmQRgZJgwxTrnVb0W9oUeqmgpDw6lQdmAd5jm HGpscHn98rA2Bp2R+Spkf2vlZ8ELRTWYVifN+tTMB1ogHYVviomOnpKFoDPUdFQOQ7r3 /1PA== X-Gm-Message-State: AAQBX9f838o9bJ2xH/TBtNJnd8YxTACNvXuG7rL5umQwU6KGrF5BbTSo PAKPKScP1jy0AvQZiFkeQmAvpHgfbiv9VZTVdcHI6w== X-Google-Smtp-Source: AKy350YsAJujj4dGNNM2q7kUEBukfDyhuL45Y7WH+KB99w1tnzhF55CijRm9KLRVaeOlRKsN/GoQyg== X-Received: by 2002:a05:622a:1454:b0:3e8:69dd:c62d with SMTP id v20-20020a05622a145400b003e869ddc62dmr9669570qtx.57.1681939260307; Wed, 19 Apr 2023 14:21:00 -0700 (PDT) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id i2-20020a05620a404200b007468765b411sm4950333qko.45.2023.04.19.14.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:20:59 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 05/10] btrfs-progs: add btrfs_locking_nest to btrfs_alloc_tree_block Date: Wed, 19 Apr 2023 17:20:45 -0400 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is how btrfs_alloc_tree_block is defined in the kernel, so when we go to sync this code in it'll be easier if we're already setup to accept this argument. Since we're in progs we don't care about nesting so just use BTRFS_NORMAL_NESTING everywhere, as we sync in the kernel code it'll get updated to whatever is appropriate. Signed-off-by: Josef Bacik --- check/main.c | 2 +- cmds/rescue-chunk-recover.c | 2 +- kernel-shared/ctree.c | 18 ++++++++++++------ kernel-shared/ctree.h | 4 +++- kernel-shared/disk-io.c | 3 ++- kernel-shared/extent-tree.c | 3 ++- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/check/main.c b/check/main.c index c5131b7a..09805511 100644 --- a/check/main.c +++ b/check/main.c @@ -9098,7 +9098,7 @@ static struct extent_buffer *btrfs_fsck_clear_root( c = btrfs_alloc_tree_block(trans, gfs_info->tree_root, gfs_info->nodesize, key->objectid, - &disk_key, 0, 0, 0); + &disk_key, 0, 0, 0, BTRFS_NESTING_NORMAL); if (IS_ERR(c)) { btrfs_free_path(path); return c; diff --git a/cmds/rescue-chunk-recover.c b/cmds/rescue-chunk-recover.c index b18d422e..52119d98 100644 --- a/cmds/rescue-chunk-recover.c +++ b/cmds/rescue-chunk-recover.c @@ -1148,7 +1148,7 @@ static int __rebuild_chunk_root(struct btrfs_trans_handle *trans, cow = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize, BTRFS_CHUNK_TREE_OBJECTID, - &disk_key, 0, 0, 0); + &disk_key, 0, 0, 0, BTRFS_NESTING_NORMAL); btrfs_set_header_bytenr(cow, cow->start); btrfs_set_header_generation(cow, trans->transid); btrfs_set_header_nritems(cow, 0); diff --git a/kernel-shared/ctree.c b/kernel-shared/ctree.c index 230dae1b..cad15093 100644 --- a/kernel-shared/ctree.c +++ b/kernel-shared/ctree.c @@ -169,7 +169,8 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans, btrfs_node_key(buf, &disk_key, 0); cow = btrfs_alloc_tree_block(trans, new_root, buf->len, new_root_objectid, &disk_key, - level, buf->start, 0); + level, buf->start, 0, + BTRFS_NESTING_NORMAL); if (IS_ERR(cow)) { kfree(new_root); return PTR_ERR(cow); @@ -231,7 +232,8 @@ int btrfs_create_root(struct btrfs_trans_handle *trans, new_root->root_key.offset = 0; node = btrfs_alloc_tree_block(trans, new_root, fs_info->nodesize, - objectid, &disk_key, 0, 0, 0); + objectid, &disk_key, 0, 0, 0, + BTRFS_NESTING_NORMAL); if (IS_ERR(node)) { ret = PTR_ERR(node); error("failed to create root node for tree %llu: %d (%m)", @@ -463,7 +465,8 @@ int __btrfs_cow_block(struct btrfs_trans_handle *trans, cow = btrfs_alloc_tree_block(trans, root, buf->len, root->root_key.objectid, &disk_key, - level, search_start, empty_size); + level, search_start, empty_size, + BTRFS_NESTING_NORMAL); if (IS_ERR(cow)) return PTR_ERR(cow); @@ -1734,7 +1737,8 @@ static int noinline insert_new_root(struct btrfs_trans_handle *trans, c = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize, root->root_key.objectid, &lower_key, - level, root->node->start, 0); + level, root->node->start, 0, + BTRFS_NESTING_NORMAL); if (IS_ERR(c)) return PTR_ERR(c); @@ -1860,7 +1864,8 @@ static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root split = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize, root->root_key.objectid, - &disk_key, level, c->start, 0); + &disk_key, level, c->start, 0, + BTRFS_NESTING_NORMAL); if (IS_ERR(split)) return PTR_ERR(split); @@ -2427,7 +2432,8 @@ again: right = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize, root->root_key.objectid, - &disk_key, 0, l->start, 0); + &disk_key, 0, l->start, 0, + BTRFS_NESTING_NORMAL); if (IS_ERR(right)) { BUG_ON(1); return PTR_ERR(right); diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index af60ba66..f416fc36 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -29,6 +29,7 @@ #include "kernel-shared/uapi/btrfs_tree.h" #include "accessors.h" #include "extent-io-tree.h" +#include "locking.h" struct btrfs_root; struct btrfs_trans_handle; @@ -853,7 +854,8 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, u32 blocksize, u64 root_objectid, struct btrfs_disk_key *key, int level, - u64 hint, u64 empty_size); + u64 hint, u64 empty_size, + enum btrfs_lock_nesting nest); int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info, u64 bytenr, u64 offset, int metadata, u64 *refs, u64 *flags); diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c index 6f9dc327..7ee45ad1 100644 --- a/kernel-shared/disk-io.c +++ b/kernel-shared/disk-io.c @@ -2334,7 +2334,8 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, memcpy(&root->root_key, key, sizeof(struct btrfs_key)); leaf = btrfs_alloc_tree_block(trans, root, fs_info->nodesize, - root->root_key.objectid, NULL, 0, 0, 0); + root->root_key.objectid, NULL, 0, 0, 0, + BTRFS_NESTING_NORMAL); if (IS_ERR(leaf)) { ret = PTR_ERR(leaf); leaf = NULL; diff --git a/kernel-shared/extent-tree.c b/kernel-shared/extent-tree.c index d0b3aee3..916eb840 100644 --- a/kernel-shared/extent-tree.c +++ b/kernel-shared/extent-tree.c @@ -2559,7 +2559,8 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, u32 blocksize, u64 root_objectid, struct btrfs_disk_key *key, int level, - u64 hint, u64 empty_size) + u64 hint, u64 empty_size, + enum btrfs_lock_nesting nest) { struct btrfs_key ins; int ret; From patchwork Wed Apr 19 21:20:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13217413 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B61FC77B73 for ; Wed, 19 Apr 2023 21:22:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232290AbjDSVWk (ORCPT ); Wed, 19 Apr 2023 17:22:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229960AbjDSVWj (ORCPT ); Wed, 19 Apr 2023 17:22:39 -0400 Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DD92903C for ; Wed, 19 Apr 2023 14:22:06 -0700 (PDT) Received: by mail-qt1-x834.google.com with SMTP id ay32so63972qtb.0 for ; Wed, 19 Apr 2023 14:22:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1681939261; x=1684531261; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=cm9ffGkLcH0XBb3U/IhrXrKQIhZzlp8ny3RtCxuDam4=; b=be5tpLtrbuhYaMeJAdmXJOcOra79Q53QsV+JcDUvRiFnQp2pTE8mjTPABf5ClDuLPX HM/thefoacgB90q020hvx+171++0Q8EAFGLYXtlR7oZOsUPSggwqYGkabDcC53MICQpk +fwJB2SVFcg1WIeA2FoxGxYp6b7dIfRAqVbGoLeqkuuxUaspCmOQf0dGqWl5+DLX5lRr TWoN6rSigdhQDNRqgLzT4srGS8+MWqVfdeNe4JshTR+x87TT2ysET0wxXuk0cvWJEqPx gsfGSbSVkPCE4tgg367AO2FxDTi9A8t3zfvc7eGady4gXE6lSa4okIgLs18bXQh8vguf YXyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681939261; x=1684531261; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cm9ffGkLcH0XBb3U/IhrXrKQIhZzlp8ny3RtCxuDam4=; b=MdwJJEwfFvD/84aei+2egUhUUSDJ+oC/NgZExSR+U1wZA6BO5NFVW03JczkyKVmogZ a/IPv6EhLUQQ66RMtHCCUJArrjRRH1wenbA9HSndpu+U5qvzpIS1R0DQlFWDKImLm0BR nKnKT7yHWOlfiKWXYhMsbJJorjLLTgVArpogR+Cd0yf1rvLclTugc7CuBip7+2LPtoqz bYUeQ7qRmCN7V6pS1N7sjX1Wb3JyjuiLEktU2w0vAj9DxbxuDVMMD7OKSvlefQQMlXMv 43jCdqZYGkgT8TVW7WI8Z6f3h3vEw5SBmHu9xd/o6XLRUrGYkBeOvRlMRZoH3Mb0n8jD IsHA== X-Gm-Message-State: AAQBX9fzrSjqRXKDHQfdbqb6oyJsoZ4a9vqSQySMtE1pM6UlOdaXORQQ /jnYaTqkW8n7wmQt+ucsiXwwCgFiAqGXq5ltpMxkkg== X-Google-Smtp-Source: AKy350ZsMGx4hdgq83/tQhyoXs523JOfCpJQQcI4qJHMmSsQQNH2kSzKPagBHf7jtgaxL/+OvNQdGg== X-Received: by 2002:a05:622a:1d4:b0:3e3:882d:4b47 with SMTP id t20-20020a05622a01d400b003e3882d4b47mr9072468qtw.26.1681939261590; Wed, 19 Apr 2023 14:21:01 -0700 (PDT) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id j20-20020a05620a289400b0074a0051fcd4sm4899227qkp.88.2023.04.19.14.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:21:01 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 06/10] btrfs-progs: add some missing extent buffer helpers Date: Wed, 19 Apr 2023 17:20:46 -0400 Message-Id: <8c23286a4b3630e17540bcddce98eabebdf9c8a3.1681939107.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The following are some extent buffer helpers we have in the kernel but not in btrfs-progs. Sync these in to make syncing ctree.c easier. Signed-off-by: Josef Bacik --- kernel-shared/extent_io.c | 11 +++++++++++ kernel-shared/extent_io.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/kernel-shared/extent_io.c b/kernel-shared/extent_io.c index 01dc5b1e..f740b3a6 100644 --- a/kernel-shared/extent_io.c +++ b/kernel-shared/extent_io.c @@ -617,6 +617,12 @@ void copy_extent_buffer(const struct extent_buffer *dst, memcpy((void *)dst->data + dst_offset, src->data + src_offset, len); } +void copy_extent_buffer_full(const struct extent_buffer *dst, + const struct extent_buffer *src) +{ + copy_extent_buffer(dst, src, 0, 0, src->len); +} + void memmove_extent_buffer(const struct extent_buffer *dst, unsigned long dst_offset, unsigned long src_offset, unsigned long len) { @@ -634,3 +640,8 @@ int extent_buffer_test_bit(const struct extent_buffer *eb, unsigned long start, { return le_test_bit(nr, (u8 *)eb->data + start); } + +void write_extent_buffer_fsid(const struct extent_buffer *eb, const void *srcv) +{ + write_extent_buffer(eb, srcv, btrfs_header_fsid(), BTRFS_FSID_SIZE); +} diff --git a/kernel-shared/extent_io.h b/kernel-shared/extent_io.h index 69133c3c..103f93cb 100644 --- a/kernel-shared/extent_io.h +++ b/kernel-shared/extent_io.h @@ -114,6 +114,8 @@ void copy_extent_buffer(const struct extent_buffer *dst, const struct extent_buffer *src, unsigned long dst_offset, unsigned long src_offset, unsigned long len); +void copy_extent_buffer_full(const struct extent_buffer *dst, + const struct extent_buffer *src); void memmove_extent_buffer(const struct extent_buffer *dst, const unsigned long dst_offset, unsigned long src_offset, unsigned long len); @@ -133,5 +135,6 @@ void extent_buffer_bitmap_set(struct extent_buffer *eb, unsigned long start, unsigned long pos, unsigned long len); void extent_buffer_init_cache(struct btrfs_fs_info *fs_info); void extent_buffer_free_cache(struct btrfs_fs_info *fs_info); +void write_extent_buffer_fsid(const struct extent_buffer *eb, const void *srcv); #endif From patchwork Wed Apr 19 21:20:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13217419 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87241C6FD18 for ; Wed, 19 Apr 2023 21:23:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230030AbjDSVXp (ORCPT ); Wed, 19 Apr 2023 17:23:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229573AbjDSVXo (ORCPT ); Wed, 19 Apr 2023 17:23:44 -0400 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F122E6A66 for ; Wed, 19 Apr 2023 14:23:22 -0700 (PDT) Received: by mail-qt1-f174.google.com with SMTP id gb12so642138qtb.6 for ; Wed, 19 Apr 2023 14:23:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1681939263; x=1684531263; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Ksq8LnPUyd2VA7eDtt0QHlRpPKRWB2/v6YOoeF68kiQ=; b=QG0/LUvbO4K2kgoWiTuTPD9sUSfUYojm4ORSaJvoYFkyz7Q89xTbu6S/+FhbJhfRPm yFYIjS1XIkUiKJK/rSdZE5XWFoQB1Lg4QfCKXpRKZMLmLQ3udZsgaw9sxsdbJEZVqsDl fwr6Hq+AhlBU0e3hb7AbIPixI40g6I6+zhANM9zUfxkoCTN+LfN05COeMdk4ugOdaHK3 EjIjqHeRECjiGldXhN9Ir0w5wEu2bSwQb6l/yD3xGZvLr+H+nqbDoF+xVaM4E4FNnnhh ezcQV+BoG0OscTRSGx60YJU/0h3RNm4iBYRqUCpG8vWwwnubscOoBpofR5A7/xfb7YVk 7GWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681939263; x=1684531263; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ksq8LnPUyd2VA7eDtt0QHlRpPKRWB2/v6YOoeF68kiQ=; b=hgJT0EwP3xSytcfzlaYXCsuNr+E9Py5OVKj/T86d5w5wznRmEbqDq2xi+kzE/t3BSQ jn5eEHEcdCfpZaeCZt1MDBeWF4rI31Y94uDrH9TUfgOhVgQbFAJZ/40WJVxwbDDA/W/G E+w+0eH01Ynd7lQU2FYOll+Q/Z11TSMc7IZrokkX8Dw2JQEnNFc2RGX/okB6AeHyV2PJ A/W1XtMTQNB+gUif+FFX/cMSWPqJqVWX1a1Bnuu6K04elpYqDb4R7LTqHLtIS2ldkXjp lNi2XldFcyqTtfJTcEULgGOflKJhTuPkHjtivTM1o09M77srOUhPT6sTw8bFQm2mhzf3 I8Rg== X-Gm-Message-State: AAQBX9desAwV9wIHM6R2NIuIZjbOiY9b7/FpYCK1gw072+6GO9QZEiNG /ZRPNMuN9SnhqdSS6POvBca9e01bfdg8791COul33A== X-Google-Smtp-Source: AKy350YnqqW/if0E/PxpWF/IGui4F7zepnRMkH01N/PaXkH3HQwEKiZyR7X8dc4/wklDYpjPHjPAJw== X-Received: by 2002:a05:622a:14a:b0:3ef:20fc:6f99 with SMTP id v10-20020a05622a014a00b003ef20fc6f99mr9093450qtw.49.1681939262886; Wed, 19 Apr 2023 14:21:02 -0700 (PDT) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id j13-20020a05620a288d00b0073b8745fd39sm4906873qkp.110.2023.04.19.14.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:21:02 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 07/10] btrfs-progs: rename btrfs_set_block_flags -> btrfs_set_disk_extent_flags Date: Wed, 19 Apr 2023 17:20:47 -0400 Message-Id: <9ac26c031920b4f4dad3edafe10cb0fd783f9c0d.1681939107.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This helper in the kernel is named btrfs_set_disk_extent_flags, which is a more accurate description than btrfs_set_block_flags. Rename to the in kernel name to make sync'ing ctree.c easier. Signed-off-by: Josef Bacik --- kernel-shared/ctree.c | 6 +++--- kernel-shared/ctree.h | 4 ++-- kernel-shared/extent-tree.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel-shared/ctree.c b/kernel-shared/ctree.c index cad15093..e95dcc79 100644 --- a/kernel-shared/ctree.c +++ b/kernel-shared/ctree.c @@ -419,9 +419,9 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans, BUG_ON(ret); } if (new_flags != 0) { - ret = btrfs_set_block_flags(trans, buf->start, - btrfs_header_level(buf), - new_flags); + ret = btrfs_set_disk_extent_flags(trans, buf->start, + btrfs_header_level(buf), + new_flags); BUG_ON(ret); } } else { diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index f416fc36..aaace45e 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -859,8 +859,8 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info, u64 bytenr, u64 offset, int metadata, u64 *refs, u64 *flags); -int btrfs_set_block_flags(struct btrfs_trans_handle *trans, u64 bytenr, - int level, u64 flags); +int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, u64 bytenr, + int level, u64 flags); int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *buf, int record_parent); int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, diff --git a/kernel-shared/extent-tree.c b/kernel-shared/extent-tree.c index 916eb840..8a6ab996 100644 --- a/kernel-shared/extent-tree.c +++ b/kernel-shared/extent-tree.c @@ -1375,8 +1375,8 @@ out: return ret; } -int btrfs_set_block_flags(struct btrfs_trans_handle *trans, u64 bytenr, - int level, u64 flags) +int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, u64 bytenr, + int level, u64 flags) { struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_root *extent_root = btrfs_extent_root(fs_info, bytenr); From patchwork Wed Apr 19 21:20:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13217414 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B71B4C77B73 for ; Wed, 19 Apr 2023 21:22:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232344AbjDSVWv (ORCPT ); Wed, 19 Apr 2023 17:22:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232008AbjDSVWr (ORCPT ); Wed, 19 Apr 2023 17:22:47 -0400 Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E92C5FFB for ; Wed, 19 Apr 2023 14:22:17 -0700 (PDT) Received: by mail-qv1-xf2d.google.com with SMTP id l17so1001418qvq.10 for ; Wed, 19 Apr 2023 14:22:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1681939264; x=1684531264; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=gXYTMM5IFzCAiwb3Gjxa/lzL/UdbgTanL1/vxWy4ljg=; b=bCtinitQ54edgQ6VPmuPFM1k2qzM0kMx0Dywnm4GuowzvU35MUbmNG2Zq4teib+Xrz paTs/mJKwOqW7wJAX1o0ZVqwTVUEsGutQYJsmlksfT/hDljViuMkcoVezWJFVAZWF5IJ kJ5I1NP8b1OxKQDxiLrFCR1MlQ+uOf2UgAQDPqaZX3NeHmzITeYtYWj/0gGN0OESUvle Hcd9GmtvairCtkxs2kyZuZrMjzEXmFnm36FZTvfu6Lnbqa3HWTegu1tH1okMlOEvBuh2 phyL6TcODVMQHruczMu7/bSZnbDvb+8KzySl6hOI+Guok8SfQsr0+xCfKQNd1tAllJ21 yr1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681939264; x=1684531264; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gXYTMM5IFzCAiwb3Gjxa/lzL/UdbgTanL1/vxWy4ljg=; b=ku9+D6vDZgl77IoqP844lA9eF5bP4T4aHsQiCDTIgGGAq9p/wUCzoPwnukeG515R1w nw+10P/M8o8p0J+a8Xwmf1JBEhz3PjnY40Z2oxSzuUe9PTOpbtfBA89eLOT8mZ9Sic1W fJIxIIqKTlKKy5Y6XQrOHUL0H2sogD5sKhpAzZ33kIEwXuL/EhJvNWZFWuWkijlq4RRK HM/HIBLhf5BB+qhb/olBLtqowN3atMP40Ty9jLRVtvDfkBBq6rSdKE0IhlNbu12UTwQl hORMeIySCQFA39dgs+QZO46W4hSDFcyv/Xs8sMCWDK7JrkSKF2fX82Nu/4yQz+BaP+SC Wu7w== X-Gm-Message-State: AAQBX9fMIE8tSs3MHspafdxINcndZ9xJA0dMegeYCosFJsWxud2v3KvR W9EXTWFTd+V3mJvZhIBf7FA1bDp+akjg52VXKa7zQg== X-Google-Smtp-Source: AKy350b/ShGTkg4WnoE9/lF2A/wGLi97QpCZNKxZjNfj7SpwtA/AyoVjb+5fQdzIfO+FV4wM6kUibw== X-Received: by 2002:a05:6214:27e6:b0:5b0:67f3:d91b with SMTP id jt6-20020a05621427e600b005b067f3d91bmr37288722qvb.35.1681939264211; Wed, 19 Apr 2023 14:21:04 -0700 (PDT) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id b10-20020a05620a0cca00b0074c398c0bf7sm2289647qkj.71.2023.04.19.14.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:21:03 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 08/10] btrfs-progs: cleanup args for btrfs_set_disk_extent_flags Date: Wed, 19 Apr 2023 17:20:48 -0400 Message-Id: <346af6d7b9a7b23f475a090f4e4fc0d318048a57.1681939107.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In the kernel we just pass in the extent_buffer and get the fields we need from that to update the extent ref flags. Update this helper to match the kernel to make syncing ctree.c easier. Signed-off-by: Josef Bacik --- kernel-shared/ctree.c | 4 +--- kernel-shared/ctree.h | 4 ++-- kernel-shared/extent-tree.c | 11 +++++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/kernel-shared/ctree.c b/kernel-shared/ctree.c index e95dcc79..ea2a7af3 100644 --- a/kernel-shared/ctree.c +++ b/kernel-shared/ctree.c @@ -419,9 +419,7 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans, BUG_ON(ret); } if (new_flags != 0) { - ret = btrfs_set_disk_extent_flags(trans, buf->start, - btrfs_header_level(buf), - new_flags); + ret = btrfs_set_disk_extent_flags(trans, buf, new_flags); BUG_ON(ret); } } else { diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index aaace45e..069e000d 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -859,8 +859,8 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info, u64 bytenr, u64 offset, int metadata, u64 *refs, u64 *flags); -int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, u64 bytenr, - int level, u64 flags); +int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, + struct extent_buffer *eb, u64 flags); int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *buf, int record_parent); int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, diff --git a/kernel-shared/extent-tree.c b/kernel-shared/extent-tree.c index 8a6ab996..cfce4426 100644 --- a/kernel-shared/extent-tree.c +++ b/kernel-shared/extent-tree.c @@ -1375,26 +1375,29 @@ out: return ret; } -int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, u64 bytenr, - int level, u64 flags) +int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, + struct extent_buffer *eb, u64 flags) { struct btrfs_fs_info *fs_info = trans->fs_info; - struct btrfs_root *extent_root = btrfs_extent_root(fs_info, bytenr); + struct btrfs_root *extent_root; struct btrfs_path *path; int ret; struct btrfs_key key; struct extent_buffer *l; struct btrfs_extent_item *item; u32 item_size; + u64 bytenr = eb->start; int skinny_metadata = btrfs_fs_incompat(fs_info, SKINNY_METADATA); path = btrfs_alloc_path(); if (!path) return -ENOMEM; + extent_root = btrfs_extent_root(fs_info, bytenr); + key.objectid = bytenr; if (skinny_metadata) { - key.offset = level; + key.offset = btrfs_header_level(eb); key.type = BTRFS_METADATA_ITEM_KEY; } else { key.offset = fs_info->nodesize; From patchwork Wed Apr 19 21:20:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13217416 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 008E9C6FD18 for ; Wed, 19 Apr 2023 21:23:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231608AbjDSVW7 (ORCPT ); Wed, 19 Apr 2023 17:22:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230030AbjDSVW6 (ORCPT ); Wed, 19 Apr 2023 17:22:58 -0400 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CED037EFD for ; Wed, 19 Apr 2023 14:22:33 -0700 (PDT) Received: by mail-qt1-x832.google.com with SMTP id ei23so677900qtb.2 for ; Wed, 19 Apr 2023 14:22:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1681939265; x=1684531265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=JQGcgc7znl8Vmhgxyjz/2T51un9Yluw+ia9GUneEN1A=; b=pQt56q+DJ+5CeP6eANyZ0rKTJx2iI/KL5o++9/U7atkIQO1TBM+8SfRF1rQ2TXqHV0 p+w29ojSsM7jPMY6kU9bpAKwYOmPioDoiOm7itZlplBS3t77BMYATHsMcVNmNLeLhbMY bLm0nrpZqQK6CxqJ+jqaOcPz9UMdk0cChN+0yl5BPogFi9J2y53nH4vJGPfukYcwJSfu n/PlWrTc6ZQCqfQEUHvznhTRtnSIbUkErul6/Jsh1GWkLtYr3ziEq3snL+ad/pYz/E0u NPG2bXsWO7KovHaW2Gc3wrHxT+NpQKP1osVHuvbuzvA20wE6tU6gWFET/VVKnBLZgeIV EOVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681939265; x=1684531265; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JQGcgc7znl8Vmhgxyjz/2T51un9Yluw+ia9GUneEN1A=; b=VIpvgYf6o35UGuACsMzoWCdK0DD0YoiA038i+6ezw1pH9OycgtR54ePEm/NKdLifTc RHjDFpSgbAeY7+5CaatVWfNvf0OyxLdH9/zv87J1alzo9FKqlhRrVf5MhKmXz1T8n+8I ePqeZtiomEc1g94rCX5PvHxe00sjtnkoIvFxfsqhefDL4hxIE2Wy7Z07ZHeulxxckloC U5m3QaeCa7QXDTD/sa80BdQ3tNLchPmo7YyGIoEVLcKsdF1GJ6bghzUXra9it9CRppFx Gx95/4++dhpjXKg7++Ol9S0scrr4Yc/oduE6nk5Splcg45o2sOIcIaV/JKIp8UCRpPks sXqQ== X-Gm-Message-State: AAQBX9fieEK0NIx0lwwkKsW1m7LiEUo964bF+k/ttUK6HIJrQZ3dUvHA YiGNDYeKwICm0CylETeUaSFK/VY+eNd4jnJ1pJErfA== X-Google-Smtp-Source: AKy350aIAI97UbfObTLRYteunt2RPyHJSY6CzfG7imCIkRy+SmdOyovn4DmlWuqF2RdQgqxrdnV+dQ== X-Received: by 2002:a05:622a:1193:b0:3ed:a811:23d0 with SMTP id m19-20020a05622a119300b003eda81123d0mr8463761qtk.41.1681939265528; Wed, 19 Apr 2023 14:21:05 -0700 (PDT) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id b10-20020a05620a0cca00b0074c398c0bf7sm2289663qkj.71.2023.04.19.14.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:21:05 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 09/10] btrfs-progs: rename clear_extent_buffer_dirty => btrfs_clear_buffer_dirty Date: Wed, 19 Apr 2023 17:20:49 -0400 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is a mirror of the change I've done in the kernel, but in progs it's even more simply because clean_tree_block was just a wrapper around clear_extent_buffer_dirty. Change this to btrfs_clear_buffer_dirty, and then update all the callers to use this helper instead of clean_tree_block and clear_extent_buffer_dirty. Signed-off-by: Josef Bacik --- cmds/rescue.c | 2 +- kernel-shared/ctree.c | 12 ++++++------ kernel-shared/disk-io.c | 7 +------ kernel-shared/extent-tree.c | 2 +- kernel-shared/extent_io.c | 2 +- kernel-shared/extent_io.h | 2 +- kernel-shared/transaction.c | 4 ++-- 7 files changed, 13 insertions(+), 18 deletions(-) diff --git a/cmds/rescue.c b/cmds/rescue.c index cbeaa6f2..b84166ea 100644 --- a/cmds/rescue.c +++ b/cmds/rescue.c @@ -340,7 +340,7 @@ static int clear_uuid_tree(struct btrfs_fs_info *fs_info) if (ret < 0) goto out; list_del(&uuid_root->dirty_list); - ret = clean_tree_block(uuid_root->node); + ret = btrfs_clear_buffer_dirty(uuid_root->node); if (ret < 0) goto out; ret = btrfs_free_tree_block(trans, uuid_root, uuid_root->node, 0, 1); diff --git a/kernel-shared/ctree.c b/kernel-shared/ctree.c index ea2a7af3..4d33994d 100644 --- a/kernel-shared/ctree.c +++ b/kernel-shared/ctree.c @@ -433,7 +433,7 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans, ret = btrfs_dec_ref(trans, root, buf, 1); BUG_ON(ret); } - clean_tree_block(buf); + btrfs_clear_buffer_dirty(buf); } return 0; } @@ -936,7 +936,7 @@ static int balance_level(struct btrfs_trans_handle *trans, root->node = child; add_root_to_dirty_list(root); path->nodes[level] = NULL; - clean_tree_block(mid); + btrfs_clear_buffer_dirty(mid); /* once for the path */ free_extent_buffer(mid); @@ -991,7 +991,7 @@ static int balance_level(struct btrfs_trans_handle *trans, u64 bytenr = right->start; u32 blocksize = right->len; - clean_tree_block(right); + btrfs_clear_buffer_dirty(right); free_extent_buffer(right); right = NULL; wret = btrfs_del_ptr(root, path, level + 1, pslot + 1); @@ -1039,7 +1039,7 @@ static int balance_level(struct btrfs_trans_handle *trans, /* we've managed to empty the middle node, drop it */ u64 bytenr = mid->start; u32 blocksize = mid->len; - clean_tree_block(mid); + btrfs_clear_buffer_dirty(mid); free_extent_buffer(mid); mid = NULL; wret = btrfs_del_ptr(root, path, level + 1, pslot); @@ -3012,7 +3012,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, if (leaf == root->node) { btrfs_set_header_level(leaf, 0); } else { - clean_tree_block(leaf); + btrfs_clear_buffer_dirty(leaf); wret = btrfs_del_leaf(trans, root, path, leaf); BUG_ON(ret); if (wret) @@ -3048,7 +3048,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, } if (btrfs_header_nritems(leaf) == 0) { - clean_tree_block(leaf); + btrfs_clear_buffer_dirty(leaf); path->slots[1] = slot; ret = btrfs_del_leaf(trans, root, path, leaf); BUG_ON(ret); diff --git a/kernel-shared/disk-io.c b/kernel-shared/disk-io.c index 7ee45ad1..7bbcc381 100644 --- a/kernel-shared/disk-io.c +++ b/kernel-shared/disk-io.c @@ -2255,11 +2255,6 @@ skip_commit: return err; } -int clean_tree_block(struct extent_buffer *eb) -{ - return clear_extent_buffer_dirty(eb); -} - void btrfs_mark_buffer_dirty(struct extent_buffer *eb) { set_extent_buffer_dirty(eb); @@ -2303,7 +2298,7 @@ int btrfs_delete_and_free_root(struct btrfs_trans_handle *trans, return ret; list_del(&root->dirty_list); - ret = clean_tree_block(root->node); + ret = btrfs_clear_buffer_dirty(root->node); if (ret) return ret; ret = btrfs_free_tree_block(trans, root, root->node, 0, 1); diff --git a/kernel-shared/extent-tree.c b/kernel-shared/extent-tree.c index cfce4426..4dfb35d4 100644 --- a/kernel-shared/extent-tree.c +++ b/kernel-shared/extent-tree.c @@ -1902,7 +1902,7 @@ static int pin_down_bytes(struct btrfs_trans_handle *trans, u64 bytenr, if (header_owner != BTRFS_TREE_LOG_OBJECTID && header_transid == trans->transid && !btrfs_header_flag(buf, BTRFS_HEADER_FLAG_WRITTEN)) { - clean_tree_block(buf); + btrfs_clear_buffer_dirty(buf); free_extent_buffer(buf); return 1; } diff --git a/kernel-shared/extent_io.c b/kernel-shared/extent_io.c index f740b3a6..4dff81bd 100644 --- a/kernel-shared/extent_io.c +++ b/kernel-shared/extent_io.c @@ -579,7 +579,7 @@ int set_extent_buffer_dirty(struct extent_buffer *eb) return 0; } -int clear_extent_buffer_dirty(struct extent_buffer *eb) +int btrfs_clear_buffer_dirty(struct extent_buffer *eb) { struct extent_io_tree *tree = &eb->fs_info->dirty_buffers; if (eb->flags & EXTENT_BUFFER_DIRTY) { diff --git a/kernel-shared/extent_io.h b/kernel-shared/extent_io.h index 103f93cb..09f3c82a 100644 --- a/kernel-shared/extent_io.h +++ b/kernel-shared/extent_io.h @@ -124,7 +124,7 @@ void memset_extent_buffer(const struct extent_buffer *eb, char c, int extent_buffer_test_bit(const struct extent_buffer *eb, unsigned long start, unsigned long nr); int set_extent_buffer_dirty(struct extent_buffer *eb); -int clear_extent_buffer_dirty(struct extent_buffer *eb); +int btrfs_clear_buffer_dirty(struct extent_buffer *eb); int read_data_from_disk(struct btrfs_fs_info *info, void *buf, u64 logical, u64 *len, int mirror); int write_data_to_disk(struct btrfs_fs_info *info, void *buf, u64 offset, diff --git a/kernel-shared/transaction.c b/kernel-shared/transaction.c index b16c07c3..f99bc684 100644 --- a/kernel-shared/transaction.c +++ b/kernel-shared/transaction.c @@ -161,7 +161,7 @@ again: goto cleanup; } start += eb->len; - clear_extent_buffer_dirty(eb); + btrfs_clear_buffer_dirty(eb); free_extent_buffer(eb); } } @@ -184,7 +184,7 @@ cleanup: eb = find_first_extent_buffer(fs_info, start); BUG_ON(!eb || eb->start != start); start += eb->len; - clear_extent_buffer_dirty(eb); + btrfs_clear_buffer_dirty(eb); free_extent_buffer(eb); } } From patchwork Wed Apr 19 21:20:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13217418 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 203CFC6FD18 for ; Wed, 19 Apr 2023 21:23:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232008AbjDSVXb (ORCPT ); Wed, 19 Apr 2023 17:23:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232422AbjDSVXZ (ORCPT ); Wed, 19 Apr 2023 17:23:25 -0400 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72F3F7EFD for ; Wed, 19 Apr 2023 14:23:05 -0700 (PDT) Received: by mail-qv1-f54.google.com with SMTP id oo30so982229qvb.12 for ; Wed, 19 Apr 2023 14:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1681939267; x=1684531267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=1D3d8BY++HkXeNeR5D26QjZUpybljb+AlCx9JHGZMug=; b=oLYWNeIhMJPEtdzHK6A5gzghZzMnoNXUP6JOwQiVXAefz2/11QJq1iHYcwn76jJGXs bXPtNaHdajWTE3EtBeax8WCXLgBr3W480QgoZ6DGpKov2b4LIH2saIiERox1ZQ+O/adS gyiL9wsybPGMCs37q9A7CDFUACD7sGo/rTuEVbydROstyi9YYiS04TDPSH3Qib72+FgN /mJVskiY9+TYI3JFz+P3KGzBl2qqurUlw4LrYGaxxoFZhFVQ1IUkPbQYd1oTi6CqQUYp IXCrI4SvDFQEE5jPh3Ny+LeJV24jTQ6lOIORxNoxeBIwZMOXNL+LqG96udbpKc810T6o HawA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681939267; x=1684531267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1D3d8BY++HkXeNeR5D26QjZUpybljb+AlCx9JHGZMug=; b=h4q73BwNdFlG6bE36Sp+8pkb3b7vivdigYi4/ZlP/C3e+Wllgk+xQgDeHOe5i9rmhf jwHUBgC+kaX3TFax8xuwiZw/IG3XU8RUHot63S1AbJPSryp5cOWafpY0KKiq++CAXdRB GbVkOdH02LEyCsvbsop4NKbFEPVcFJsH2BEnmGvJAdvSZbZ898+np7TSU83hNc+WnHsy yRs/OzpxQhSRZHIwufYBm97LKm+IQoVDyRYIoSjFjIeeU1lTsqaE6cpUoW7Ncn1NBWpG KZ661z6xe5A0SrWBxgtulH5dFpUuEsQYsBB+ONIjkS4WYyo8/LN+GyVsy0hrMnETr0WJ L/vQ== X-Gm-Message-State: AAQBX9dUYLAeohwjK6pod2Gkt9eh+FMIDF8iSY0Tkkf1jffe0b2YKmJo B+9NE1iKZlXVGqfNo2mK06QQ9pXWLZKZbP5nwtuJPQ== X-Google-Smtp-Source: AKy350YFQTmRsOrWF7A65E356ka/l8hl3eqKoBVsAk9X4LZ4J9MzlW861EKtX0EoiTJYdlfOcaBeVw== X-Received: by 2002:a05:6214:406:b0:5a2:6074:6cfa with SMTP id z6-20020a056214040600b005a260746cfamr37759348qvx.38.1681939266761; Wed, 19 Apr 2023 14:21:06 -0700 (PDT) Received: from localhost (cpe-174-109-170-245.nc.res.rr.com. [174.109.170.245]) by smtp.gmail.com with ESMTPSA id ei18-20020ad45a12000000b005eac706d223sm4625436qvb.124.2023.04.19.14.21.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 14:21:06 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 10/10] btrfs-progs: make __btrfs_cow_block static Date: Wed, 19 Apr 2023 17:20:50 -0400 Message-Id: <75f9f2e629a446d747d138364f3354543e5e9ae3.1681939107.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This isn't used anywhere other than ctree.c, make it static. Signed-off-by: Josef Bacik --- kernel-shared/ctree.c | 2 +- kernel-shared/ctree.h | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/kernel-shared/ctree.c b/kernel-shared/ctree.c index 4d33994d..da9282b9 100644 --- a/kernel-shared/ctree.c +++ b/kernel-shared/ctree.c @@ -438,7 +438,7 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans, return 0; } -int __btrfs_cow_block(struct btrfs_trans_handle *trans, +static int __btrfs_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *buf, struct extent_buffer *parent, int parent_slot, diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index 069e000d..655b714f 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -936,12 +936,6 @@ int btrfs_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *buf, struct extent_buffer *parent, int parent_slot, struct extent_buffer **cow_ret); -int __btrfs_cow_block(struct btrfs_trans_handle *trans, - struct btrfs_root *root, - struct extent_buffer *buf, - struct extent_buffer *parent, int parent_slot, - struct extent_buffer **cow_ret, - u64 search_start, u64 empty_size); int btrfs_copy_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *buf,