From patchwork Wed Nov 1 21:24:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13443076 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 B54E1C4332F for ; Wed, 1 Nov 2023 21:25:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344705AbjKAVZR (ORCPT ); Wed, 1 Nov 2023 17:25:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344928AbjKAVZQ (ORCPT ); Wed, 1 Nov 2023 17:25:16 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 368F1115 for ; Wed, 1 Nov 2023 14:25:10 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CE9BA1F85D for ; Wed, 1 Nov 2023 21:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1698873908; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=cq6gaOD8A2KJZ0eM4yBiIKqhCBnXEtyWg8x+cL6mEaQ=; b=jbJPERQUOC2PbQ8lCiaCmfwzENu3vf2uHMyo94UPKU2I/7zvYTX3DFgZ6VrKbwlFLAD4NE tFiNSDpFTraiqK9/Lghac7gSvfmTDxQvKjmgJlQzdcvfZD5Blg1M7y0/CwZgSSPLp4IjjN XkYvpQ8quO8HIxIEW/NOuhtq6APJN8w= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0906113460 for ; Wed, 1 Nov 2023 21:25:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 2NRcLjPCQmWGQAAAMHmgww (envelope-from ) for ; Wed, 01 Nov 2023 21:25:07 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH] btrfs: add dmesg output when mounting and unmounting Date: Thu, 2 Nov 2023 07:54:50 +1030 Message-ID: <215e7eea95459d1b0cc4fd9ce522dc7c8f5d4e02.1698873846.git.wqu@suse.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org There is a feature request to add dmesg output when unmounting a btrfs. There are several alternative methods to do the same thing, but with their problems: - Use eBPF to watch btrfs_put_super()/open_ctree() Not end user friendly, they have to dip their head into the source code. - Watch for /sys/fs// This is way more simpler, but still requires some simple device -> uuid lookups. And a script needs to use inotify to watch /sys/fs/. Compared to all these, directly outputting the information into dmesg would be the most simple one, with both device and UUID included. And since we're here, also add the output when mounting a btrfs, to keep the dmesg paired. Now mounting a btrfs with all default mkfs options would look like this: [ 81.906566] BTRFS info (device dm-8): mounting filesystem 633b5c16-afe3-4b79-b195-138fe145e4f2 [ 81.907494] BTRFS info (device dm-8): using crc32c (crc32c-intel) checksum algorithm [ 81.908258] BTRFS info (device dm-8): using free space tree [ 81.912644] BTRFS info (device dm-8): auto enabling async discard [ 81.913277] BTRFS info (device dm-8): checking UUID tree [ 91.668256] BTRFS info (device dm-8): unmounting filesystem 633b5c16-afe3-4b79-b195-138fe145e4f2 Link: https://github.com/kdave/btrfs-progs/issues/689 Signed-off-by: Qu Wenruo Reviewed-by: Anand Jain --- fs/btrfs/disk-io.c | 1 + fs/btrfs/super.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 350e1b02cc8e..2fef94bfa2ff 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3209,6 +3209,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device goto fail_alloc; } + btrfs_info(fs_info, "mounting filesystem %pU", disk_super->fsid); /* * Verify the type first, if that or the checksum value are * corrupted, we'll find out diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 6ecf78d09694..fbcd8c8d23dc 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -80,7 +80,11 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data); static void btrfs_put_super(struct super_block *sb) { - close_ctree(btrfs_sb(sb)); + struct btrfs_fs_info *fs_info = btrfs_sb(sb); + + btrfs_info(fs_info, "unmounting filesystem %pU", + fs_info->fs_devices->fsid); + close_ctree(fs_info); } enum {