Skip to content

Commit ed02363

Browse files
adam900710kdave
authored andcommitted
btrfs: add extra error messages to cover non-ENOMEM errors from device_add_list()
[BUG] When test case btrfs/219 (aka, mount a registered device but with a lower generation) failed, there is not any useful information for the end user to find out what's going wrong. The mount failure just looks like this: # mount -o loop /tmp/219.img2 /mnt/btrfs/ mount: /mnt/btrfs: mount(2) system call failed: File exists. dmesg(1) may have more information after failed mount system call. While the dmesg contains nothing but the loop device change: loop1: detected capacity change from 0 to 524288 [CAUSE] In device_list_add() we have a lot of extra checks to reject invalid cases. That function also contains the regular device scan result like the following prompt: BTRFS: device fsid 6222333e-f9f1-47e6-b306-55ddd4dcaef4 devid 1 transid 8 /dev/loop0 scanned by systemd-udevd (3027) But unfortunately not all errors have their own error messages, thus if we hit something wrong in device_add_list(), there may be no error messages at all. [FIX] Add errors message for all non-ENOMEM errors. For ENOMEM, I'd say we're in a much worse situation, and there should be some OOM messages way before our call sites. CC: [email protected] # 6.0+ Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 2ba48b2 commit ed02363

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fs/btrfs/volumes.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,11 @@ static noinline struct btrfs_device *device_list_add(const char *path,
768768
BTRFS_SUPER_FLAG_CHANGING_FSID_V2);
769769

770770
error = lookup_bdev(path, &path_devt);
771-
if (error)
771+
if (error) {
772+
btrfs_err(NULL, "failed to lookup block device for path %s: %d",
773+
path, error);
772774
return ERR_PTR(error);
775+
}
773776

774777
if (fsid_change_in_progress) {
775778
if (!has_metadata_uuid)
@@ -836,6 +839,9 @@ static noinline struct btrfs_device *device_list_add(const char *path,
836839
unsigned int nofs_flag;
837840

838841
if (fs_devices->opened) {
842+
btrfs_err(NULL,
843+
"device %s belongs to fsid %pU, and the fs is already mounted",
844+
path, fs_devices->fsid);
839845
mutex_unlock(&fs_devices->device_list_mutex);
840846
return ERR_PTR(-EBUSY);
841847
}
@@ -905,6 +911,9 @@ static noinline struct btrfs_device *device_list_add(const char *path,
905911
* generation are equal.
906912
*/
907913
mutex_unlock(&fs_devices->device_list_mutex);
914+
btrfs_err(NULL,
915+
"device %s already registered with a higher generation, found %llu expect %llu",
916+
path, found_transid, device->generation);
908917
return ERR_PTR(-EEXIST);
909918
}
910919

0 commit comments

Comments
 (0)