Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp650092rbb; Sat, 24 Feb 2024 18:41:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVk6E6aMwbcWZ+ZYHBpRinRiPKOsG91D/kCr3a3dCD/HPHP01gSR0roWOcd2eg9b9X+eDwQ8e5M/IjQIXyErkIqHrjlX04gLcv0P5BcLQ== X-Google-Smtp-Source: AGHT+IEu8ta3VqiyW/gXxtQtuVnTPNPVAXET8Z39zYIxpWwmFvo6j01nRuyHIDgyTT5LTfjcBnbL X-Received: by 2002:a05:6a00:1817:b0:6e4:ea94:3625 with SMTP id y23-20020a056a00181700b006e4ea943625mr5187128pfa.13.1708828914951; Sat, 24 Feb 2024 18:41:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708828914; cv=pass; d=google.com; s=arc-20160816; b=kXV/fUKWaMbVS+0WnIbT/IcUT0o0yYUp5RvXDVMzP3ZfSVE1zQYeEi8R+45gqrAmtB QnT2xC1kFTTrNz8z0p/ywngT8lmkn94q63HGp9VgRzNHflRTHnXkNtFZVuFpQ480Ldds Pk2CgAvi+txMKCPifI86TL+mbgfMh9njwRlTJowi8qyRssoB96jjqqK+AOJPvuXTbENv Wli27nhxYjDCL/QuNFmSNwEW3uMc/PVCXbYbQPiL2p4TCiTkcUiDJoYEC/u0dR1EGZrl 2JV7/Xscf/TiVz3sILRWrPE/pvVyqZGTebx5liPXTsu9awAYkwpDHM08MC9b9Lk2URkr s08w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Qtt8N3DTXT8YcoliwHPFpPxKQXIz9TTQtDYUciFTLnM=; fh=cHCDtKbuQPXHd8MTSa2UUr5dC1B5BRlSqWWb9m+1Nbw=; b=clhYppr1tTCs5MBw3Csm342ZqEpNQbDsXbtST3jKJMLwZ+9YXF8kPThQneQuuxOUbC WytEYf6ArwQz8yno1CrG3ASAzawZZUGNFHvf+MCVuamiU0m4m4oSpRsl2sunSJJYuXGv 3vBKpEDKllp39OjhtAY6M769usu6sJRS7nhU9dstzG4az6+bcr12y1w04bRqubt+fJQV tJ/y0zYNj3Wl8FFfWlEIV0hFHTyG4TJvYqa8QDseiJSHKvzE9rFZyiA9tBg/MDl7bzEU bEsNwqLfHMYmA0uONKOwy7Wv3QtqlmfE6B3tdhw2kpcp4Kv1/idIV1tOZMqaD753qMSp 1Y9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=t5Uq6mW9; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79944-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79944-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b6-20020a63cf46000000b005dc528a9d0bsi1623331pgj.241.2024.02.24.18.41.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:41:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79944-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=t5Uq6mW9; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-79944-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79944-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A6DD9281CDD for ; Sun, 25 Feb 2024 02:41:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B589663B; Sun, 25 Feb 2024 02:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="t5Uq6mW9" Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF0E317BBB for ; Sun, 25 Feb 2024 02:38:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828732; cv=none; b=aaa47r7CRweTWVCw1cg+Up3mMUj+FvtoBi0dK+lljd0wX3Bsp5YVmGOP2nfBskhk0WdKdCIsRXDmIfSBZfbZLbrDlfhQ3GKn0PudWWUE4xqkJ8Ax75cKIe7gDb0AscvBZig8wUOQBFGHW3IxOyvo3EIC/Ssu4KRD4qnsHYZqEFI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828732; c=relaxed/simple; bh=693nN94qUSbbDkqHrUPV8kMgo4OMZv7SWEQcI8AOyfo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HPDPzzRrjxFQG2bayNX7etKnCs0ChDJsEaGuBnXa1I6GOPjZxspUE4QuXiIbxlifzcYgpQI+6OmF0x71YvEiOBPSkYpT1S6G1aRprIFz/xjxVVbsVs+Dw0JiGaok093q8yjevgHwzNy/KYISfOU+B8nYRtQfySClTisrpfjSaic= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=t5Uq6mW9; arc=none smtp.client-ip=95.215.58.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1708828729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qtt8N3DTXT8YcoliwHPFpPxKQXIz9TTQtDYUciFTLnM=; b=t5Uq6mW9GG3Iozxg1JY5qA7lforHDcbj+wg4MIkQsFH4ck90PVZ93xMlSgL4eMlDl2woyi EvPtgsLVWvtMuqILOQqRjhSeb3Dmsvw1RAoitJjHJDyZJ4aMCg5VZlKRoiFlMU1RXMTgZb bE7B3hd9Ir4lBJC32mIPIaOweIf8fqk= From: Kent Overstreet To: linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kent Overstreet , djwong@kernel.org, bfoster@redhat.com Subject: [PATCH 16/21] bcachefs: bch2_verify_accounting_clean() Date: Sat, 24 Feb 2024 21:38:18 -0500 Message-ID: <20240225023826.2413565-17-kent.overstreet@linux.dev> In-Reply-To: <20240225023826.2413565-1-kent.overstreet@linux.dev> References: <20240225023826.2413565-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Verify that the in-memory accounting verifies the on-disk accounting after a clean shutdown. Signed-off-by: Kent Overstreet --- fs/bcachefs/disk_accounting.c | 27 +++++++++++++++++++++++++++ fs/bcachefs/disk_accounting.h | 4 +++- fs/bcachefs/super.c | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/fs/bcachefs/disk_accounting.c b/fs/bcachefs/disk_accounting.c index 2884615adc1e..8d7b6ab66e71 100644 --- a/fs/bcachefs/disk_accounting.c +++ b/fs/bcachefs/disk_accounting.c @@ -513,6 +513,33 @@ int bch2_dev_usage_init(struct bch_dev *ca, bool gc) return ret; } +void bch2_verify_accounting_clean(struct bch_fs *c) +{ + bch2_trans_run(c, + for_each_btree_key(trans, iter, + BTREE_ID_accounting, POS_MIN, + BTREE_ITER_ALL_SNAPSHOTS, k, ({ + u64 v[BCH_ACCOUNTING_MAX_COUNTERS]; + struct bkey_s_c_accounting a = bkey_s_c_to_accounting(k); + unsigned nr = bch2_accounting_counters(k.k); + + bch2_accounting_mem_read(c, k.k->p, v, nr); + + if (memcmp(a.v->d, v, nr * sizeof(u64))) { + struct printbuf buf = PRINTBUF; + + bch2_bkey_val_to_text(&buf, c, k); + prt_str(&buf, " in mem"); + for (unsigned j = 0; j < nr; j++) + prt_printf(&buf, " %llu", v[j]); + + WARN(1, "accounting mismatch: %s", buf.buf); + printbuf_exit(&buf); + } + 0; + }))); +} + void bch2_accounting_free(struct bch_accounting_mem *acc) { darray_exit(&acc->k); diff --git a/fs/bcachefs/disk_accounting.h b/fs/bcachefs/disk_accounting.h index 70ac67f4a3cb..a0cf7a0b84a7 100644 --- a/fs/bcachefs/disk_accounting.h +++ b/fs/bcachefs/disk_accounting.h @@ -164,7 +164,7 @@ static inline void bch2_accounting_mem_read_counters(struct bch_fs *c, unsigned { memset(v, 0, sizeof(*v) * nr); - struct bch_accounting_mem *acc = &c->accounting[0]; + struct bch_accounting_mem *acc = &c->accounting[gc]; if (unlikely(idx >= acc->k.nr)) return; @@ -194,6 +194,8 @@ int bch2_accounting_read(struct bch_fs *); int bch2_dev_usage_remove(struct bch_fs *, unsigned); int bch2_dev_usage_init(struct bch_dev *, bool); +void bch2_verify_accounting_clean(struct bch_fs *c); + void bch2_accounting_free(struct bch_accounting_mem *); void bch2_fs_accounting_exit(struct bch_fs *); diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index 6617c8912e51..201d7767e478 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -355,6 +355,7 @@ void bch2_fs_read_only(struct bch_fs *c) BUG_ON(atomic_long_read(&c->btree_key_cache.nr_dirty)); BUG_ON(c->btree_write_buffer.inc.keys.nr); BUG_ON(c->btree_write_buffer.flushing.keys.nr); + bch2_verify_accounting_clean(c); bch_verbose(c, "marking filesystem clean"); bch2_fs_mark_clean(c); -- 2.43.0