Skip to contentSkip to conversation

btrfs: add dmesg output when mounting and unmounting

PATCH In review Qu Wenruo 4 participants 13 messages Nov 1, 2023 – Nov 21, 2023 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/1 btrfs: add dmesg output when mounting and unmounting

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/<uuid>/
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
---
 fs/btrfs/disk-io.c | 1 +
 fs/btrfs/super.c   | 6 +++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
fs/btrfs/disk-io.c +1 -0
index 350e1b02cc8e..2fef94bfa2ff 100644
@@ -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
fs/btrfs/super.c +5 -1
index 6ecf78d09694..fbcd8c8d23dc 100644
@@ -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 {
Signature · 1 line
2.42.0
#1 lore raw
Quoted 16 lines · Qu Wenruo

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/<uuid>/
This is way more simpler, but still requires some simple device -> uuid lookups.
And a script needs to use inotify to watch /sys/fs/.

Quoted 3 lines

Compared to all these, directly outputting the information into dmesg would be the most simple one, with both device and UUID included.

Well, I submitted a patch for this in 2017, but I'm not sure why it wasn't integrated or commented.

https://lore.kernel.org/linux-btrfs/[email protected]/

Thanks, Anand

Quoted 48 lines

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
---
  fs/btrfs/disk-io.c | 1 +
  fs/btrfs/super.c   | 6 +++++-
  2 files changed, 6 insertions(+), 1 deletion(-)
fs/btrfs/disk-io.c +1 -0
index 350e1b02cc8e..2fef94bfa2ff 100644
@@ -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
fs/btrfs/super.c +5 -1
index 6ecf78d09694..fbcd8c8d23dc 100644
@@ -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 {
#2 lore raw
Quoted 17 lines · Anand Jain
Quoted 14 lines · Qu Wenruo

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/<uuid>/
This is way more simpler, but still requires some simple device -> uuid lookups.
And a script needs to use inotify to watch /sys/fs/.

Quoted 8 lines
Quoted 3 lines

Compared to all these, directly outputting the information into dmesg would be the most simple one, with both device and UUID included.

Well, I submitted a patch for this in 2017, but I'm not sure why it wasn't integrated or commented.

https://lore.kernel.org/linux-btrfs/[email protected]/

I think you sent it more than once and that I replied, messages about mounting each subvolume (as in your patch) seem to be duplicating what eg. audit or some policy layer should do. The same comment is in the github issue.

The patch here and the request is to track only the first and last mount of the same filesystem with a bit different use case, eg. properly waiting until lazy umount finishe, or in container environments to be sure that the last mount is gone.

The suggested waiting on /sys/fs/btrfs/UUID could eventually wrapped in a subcommand, for conveniencie.

#3 lore raw
Quoted 32 lines · David Sterba
Quoted 17 lines · Anand Jain
Quoted 14 lines · Qu Wenruo

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/<uuid>/
This is way more simpler, but still requires some simple device -> uuid lookups.
And a script needs to use inotify to watch /sys/fs/.

Quoted 8 lines
Quoted 3 lines

Compared to all these, directly outputting the information into dmesg would be the most simple one, with both device and UUID included.

Well, I submitted a patch for this in 2017, but I'm not sure why it wasn't integrated or commented.

https://lore.kernel.org/linux-btrfs/[email protected]/

I think you sent it more than once and that I replied, messages about mounting each subvolume (as in your patch) seem to be duplicating what eg. audit or some policy layer should do. The same comment is in the github issue.

Quoted 7 lines

The patch here and the request is to track only the first and last mount of the same filesystem with a bit different use case, eg. properly waiting until lazy umount finishe, or in container environments to be sure that the last mount is gone.

The suggested waiting on /sys/fs/btrfs/UUID could eventually wrapped in a subcommand, for conveniencie.

My bad, I didn't realize until I crafted the btrfs monitor watch command.

Inotify just doesn't work on sysfs....

So I believe for now, the patch is the best way to go, unless we want to something like checking the sysfs every second...

Thanks,
Qu

#4 lore raw
In reply to Qu Wenruo
Quoted 20 lines · Qu Wenruo

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/<uuid>/
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.

Quoted 8 lines

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

On a fresh look, I' suggest to write the messages like

BTRFS info (...): first mount of filesystem UUID
...
BTRFS info (...): last umount of filesystem UUID

This is not for each mount so it's slightly confusing.

#5 lore raw
Quoted 30 lines · David Sterba
Quoted 20 lines · Qu Wenruo

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/<uuid>/
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.

Quoted 8 lines

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
Quoted 8 lines

On a fresh look, I' suggest to write the messages like

BTRFS info (...): first mount of filesystem UUID
...
BTRFS info (...): last umount of filesystem UUID

This is not for each mount so it's slightly confusing.

Sure, I'm totally fine to change the words.

Do I need to resend or the change is small enough to get updated in the branch?

Thanks,
Qu

#6 lore raw
Quoted 39 lines · Qu Wenruo
Quoted 36 lines · David Sterba
Quoted 20 lines · Qu Wenruo

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/<uuid>/
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.

Quoted 8 lines

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

On a fresh look, I' suggest to write the messages like

BTRFS info (...): first mount of filesystem UUID
...
BTRFS info (...): last umount of filesystem UUID

Quoted 6 lines
Quoted 2 lines

This is not for each mount so it's slightly confusing.

Sure, I'm totally fine to change the words.

Do I need to resend or the change is small enough to get updated in the branch?

No need to resend for such changes, is more for the feedback and sanity check.

#9 lore raw
Quoted 7 lines · Anand Jain

On misc-next:

3212 btrfs_info(fs_info, "frist mount of filesystem %pU",
disk_super->fsid);

Has typo error.

Fixed, thanks for catching it.

#11 lore raw

Starting from v5.4?

Quoted 4 lines · Anand Jain

Also, is it possible to CC the stable kernel? It's not a bug fix but a debug essential patch.

Thx, Anand

#12 lore raw
In reply to Anand Jain
Quoted 2 lines · Anand Jain

Also, is it possible to CC the stable kernel? It's not a bug fix but a debug essential patch.

Yes we can do that, it's a usability improvement.