diff mbox series

: btrfs: print warning message if bdev_file_open_by_path function fails during mount

Message ID 1720962326-19300-1-git-send-email-zhanglikernel@gmail.com (mailing list archive)
State New, archived
Headers show
Series : btrfs: print warning message if bdev_file_open_by_path function fails during mount | expand

Commit Message

Li Zhang July 14, 2024, 1:05 p.m. UTC
[ENHANCEMENT]
When mounting a btrfs filesystem, the filesystem opens the
block device, and if this fails, there is no message about
it. Print a message about it to help debugging.

[IMPLEMENTATION]
Print warning message if bdev_file_open_by_path fails.

[TEST]
I have a btrfs filesystem on three block devices,
one of which is write-protected, so regular mounts fail,
but there is no message in dmesg.

/dev/vdb normal
/dev/vdc write protected
/dev/vdd normal

Before patch:
$ sudo mount /dev/vdb /mnt/
mount: mount(2) failed: no such file or directory
$ sudo dmesg # Show only messages about missing block devices
....
[ 352.947196] BTRFS error (device vdb): devid 2 uuid 4ee2c625-a3b2-4fe0-b411-756b23e08533 missing
....

After patch:
$ sudo mount /dev/vdb /mnt/
mount: mount(2) failed: no such file or directory
$ sudo dmesg # Show bdev_file_open_by_path failed.
....
[ 352.944328] bdev_file_open_by_path failed device_path:/dev/vdc ret::-13
[ 352.947196] BTRFS error (device vdb): missing devid 2 uuid 4ee2c625-a3b2-4fe0-b411-756b23e08533
....

Signed-off-by: Li Zhang <zhanglikernel@gmail.com>
---
 fs/btrfs/volumes.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Filipe Manana July 14, 2024, 3:34 p.m. UTC | #1
On Sun, Jul 14, 2024 at 2:06 PM Li Zhang <zhanglikernel@gmail.com> wrote:
>
> [ENHANCEMENT]
> When mounting a btrfs filesystem, the filesystem opens the
> block device, and if this fails, there is no message about
> it. Print a message about it to help debugging.
>
> [IMPLEMENTATION]
> Print warning message if bdev_file_open_by_path fails.
>
> [TEST]
> I have a btrfs filesystem on three block devices,
> one of which is write-protected, so regular mounts fail,
> but there is no message in dmesg.
>
> /dev/vdb normal
> /dev/vdc write protected
> /dev/vdd normal
>
> Before patch:
> $ sudo mount /dev/vdb /mnt/
> mount: mount(2) failed: no such file or directory
> $ sudo dmesg # Show only messages about missing block devices
> ....
> [ 352.947196] BTRFS error (device vdb): devid 2 uuid 4ee2c625-a3b2-4fe0-b411-756b23e08533 missing
> ....
>
> After patch:
> $ sudo mount /dev/vdb /mnt/
> mount: mount(2) failed: no such file or directory
> $ sudo dmesg # Show bdev_file_open_by_path failed.
> ....
> [ 352.944328] bdev_file_open_by_path failed device_path:/dev/vdc ret::-13
> [ 352.947196] BTRFS error (device vdb): missing devid 2 uuid 4ee2c625-a3b2-4fe0-b411-756b23e08533
> ....
>
> Signed-off-by: Li Zhang <zhanglikernel@gmail.com>
> ---
>  fs/btrfs/volumes.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index c39145e..0713b44 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -476,6 +476,7 @@ static noinline struct btrfs_fs_devices *find_fsid(
>
>         if (IS_ERR(*bdev_file)) {
>                 ret = PTR_ERR(*bdev_file);
> +               printk(KERN_WARNING "bdev_file_open_by_path failed device_path:%s ret::%d\n", device_path, ret);

Please use the btrfs helpers to print messages: btrfs_warn(),
btrfs_err(), btrfs_crit(), etc.
This is what we prefer to do.

About the message itself:

1) Don't use a function name like bdev_file_open_by_path in the
message, we don't do that anywhere else, and we have 3 different
places calling it;

2) Try to comply with the style we follow. After a ":" leave a space
for better readability;

3) Don't use "::", we don't do it anywhere else and it's even
inconsistent with the rest of the message you added;

4) An error level is more appropriate since we have a failure.

Look at the example we have at device_list_add():

btrfs_err(NULL, "failed to lookup block device for path %s: %d", path, error);

So I would suggest changing it to:

btrfs_err(NULL, "failed to open device for path %s with flags 0x%x:
%d", device_path, flags, ret);

Thanks.


>                 goto error;
>         }
>         bdev = file_bdev(*bdev_file);
> --
> 1.8.3.1
>
>
diff mbox series

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index c39145e..0713b44 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -476,6 +476,7 @@  static noinline struct btrfs_fs_devices *find_fsid(
 
 	if (IS_ERR(*bdev_file)) {
 		ret = PTR_ERR(*bdev_file);
+		printk(KERN_WARNING "bdev_file_open_by_path failed device_path:%s ret::%d\n", device_path, ret);
 		goto error;
 	}
 	bdev = file_bdev(*bdev_file);