Skip to content

Commit 2db3132

Browse files
adam900710kdave
authored andcommitted
btrfs: add dmesg output for first mount and last unmount of a filesystem
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 own 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 directory /sys/fs/<uuid>/ This is way more simple, 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 filesystem for the first time for parity. A more fine grained monitoring of subvolume mounts should be done by another layer, like audit. Now mounting a btrfs with all default mkfs options would look like this: [81.906566] BTRFS info (device dm-8): first mount of 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): last unmount of filesystem 633b5c16-afe3-4b79-b195-138fe145e4f2 CC: stable@vger.kernel.org # 5.4+ Link: kdave/btrfs-progs#689 Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> [ update changelog ] Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 8049ba5 commit 2db3132

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

fs/btrfs/disk-io.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,6 +3213,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
32133213
goto fail_alloc;
32143214
}
32153215

3216+
btrfs_info(fs_info, "first mount of filesystem %pU", disk_super->fsid);
32163217
/*
32173218
* Verify the type first, if that or the checksum value are
32183219
* corrupted, we'll find out

fs/btrfs/super.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data);
8080

8181
static void btrfs_put_super(struct super_block *sb)
8282
{
83-
close_ctree(btrfs_sb(sb));
83+
struct btrfs_fs_info *fs_info = btrfs_sb(sb);
84+
85+
btrfs_info(fs_info, "last unmount of filesystem %pU", fs_info->fs_devices->fsid);
86+
close_ctree(fs_info);
8487
}
8588

8689
enum {

0 commit comments

Comments
 (0)