Btrfs: check if the to-be-added device is writable
authorLi Zefan <lizf@cn.fujitsu.com>
Thu, 8 Dec 2011 01:08:40 +0000 (20:08 -0500)
committerChris Mason <chris.mason@oracle.com>
Thu, 8 Dec 2011 13:55:46 +0000 (08:55 -0500)
If we call ioctl(BTRFS_IOC_ADD_DEV) directly, we'll succeed in adding
a readonly device to a btrfs filesystem, and btrfs will write to
that device, emitting kernel errors:

[ 3109.833692] lost page write due to I/O error on loop2
[ 3109.833720] lost page write due to I/O error on loop2
...

Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
fs/btrfs/volumes.c

index c37433d3cd82464adbe13173433521a4ab1cca14..0a8c8f8304b14c3d9190926eeee3dfa5e3d59d33 100644 (file)
@@ -1611,7 +1611,7 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
        if ((sb->s_flags & MS_RDONLY) && !root->fs_info->fs_devices->seeding)
                return -EINVAL;
 
-       bdev = blkdev_get_by_path(device_path, FMODE_EXCL,
+       bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL,
                                  root->fs_info->bdev_holder);
        if (IS_ERR(bdev))
                return PTR_ERR(bdev);