btrfs_init_new_device() calls btrfs_attach_transaction() to
commit sys chunks, and it should error out if it fails.

Signed-off-by: Anand Jain <anand.j...@oracle.com>
Reviewed-by: Qu Wenruo <quwenruo.bt...@gmx.com>
---
v4: make this patch as part of this set.
    avoid double mutext unlock.
v3: not part of this set
v2: patch did not exist
v1: patch did not exist
 fs/btrfs/volumes.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 4cb575fbf643..bdb8f04663a4 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2323,6 +2323,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, 
const char *device_path
        u64 tmp;
        int seeding_dev = 0;
        int ret = 0;
+       bool unlocked = false;
 
        if (sb_rdonly(sb) && !fs_info->fs_devices->seeding)
                return -EROFS;
@@ -2482,6 +2483,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, 
const char *device_path
        if (seeding_dev) {
                mutex_unlock(&uuid_mutex);
                up_write(&sb->s_umount);
+               unlocked = true;
 
                if (ret) /* transaction commit */
                        return ret;
@@ -2494,7 +2496,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, 
const char *device_path
                if (IS_ERR(trans)) {
                        if (PTR_ERR(trans) == -ENOENT)
                                return 0;
-                       return PTR_ERR(trans);
+                       ret = PTR_ERR(trans);
+                       goto error_sysfs;
                }
                ret = btrfs_commit_transaction(trans);
        }
@@ -2513,7 +2516,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, 
const char *device_path
        kfree(device);
 error:
        blkdev_put(bdev, FMODE_EXCL);
-       if (seeding_dev) {
+       if (seeding_dev && !unlocked) {
                mutex_unlock(&uuid_mutex);
                up_write(&sb->s_umount);
        }
-- 
2.13.1

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to