|
@@ -448,6 +448,7 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags,
|
|
token = match_token(p, tokens, args);
|
|
token = match_token(p, tokens, args);
|
|
switch (token) {
|
|
switch (token) {
|
|
case Opt_subvol:
|
|
case Opt_subvol:
|
|
|
|
+ kfree(*subvol_name);
|
|
*subvol_name = match_strdup(&args[0]);
|
|
*subvol_name = match_strdup(&args[0]);
|
|
break;
|
|
break;
|
|
case Opt_subvolid:
|
|
case Opt_subvolid:
|
|
@@ -890,7 +891,6 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
|
|
struct super_block *s;
|
|
struct super_block *s;
|
|
struct dentry *root;
|
|
struct dentry *root;
|
|
struct btrfs_fs_devices *fs_devices = NULL;
|
|
struct btrfs_fs_devices *fs_devices = NULL;
|
|
- struct btrfs_root *tree_root = NULL;
|
|
|
|
struct btrfs_fs_info *fs_info = NULL;
|
|
struct btrfs_fs_info *fs_info = NULL;
|
|
fmode_t mode = FMODE_READ;
|
|
fmode_t mode = FMODE_READ;
|
|
char *subvol_name = NULL;
|
|
char *subvol_name = NULL;
|
|
@@ -904,8 +904,10 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
|
|
error = btrfs_parse_early_options(data, mode, fs_type,
|
|
error = btrfs_parse_early_options(data, mode, fs_type,
|
|
&subvol_name, &subvol_objectid,
|
|
&subvol_name, &subvol_objectid,
|
|
&subvol_rootid, &fs_devices);
|
|
&subvol_rootid, &fs_devices);
|
|
- if (error)
|
|
|
|
|
|
+ if (error) {
|
|
|
|
+ kfree(subvol_name);
|
|
return ERR_PTR(error);
|
|
return ERR_PTR(error);
|
|
|
|
+ }
|
|
|
|
|
|
if (subvol_name) {
|
|
if (subvol_name) {
|
|
root = mount_subvol(subvol_name, flags, device_name, data);
|
|
root = mount_subvol(subvol_name, flags, device_name, data);
|
|
@@ -917,15 +919,6 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
|
|
if (error)
|
|
if (error)
|
|
return ERR_PTR(error);
|
|
return ERR_PTR(error);
|
|
|
|
|
|
- error = btrfs_open_devices(fs_devices, mode, fs_type);
|
|
|
|
- if (error)
|
|
|
|
- return ERR_PTR(error);
|
|
|
|
-
|
|
|
|
- if (!(flags & MS_RDONLY) && fs_devices->rw_devices == 0) {
|
|
|
|
- error = -EACCES;
|
|
|
|
- goto error_close_devices;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/*
|
|
/*
|
|
* Setup a dummy root and fs_info for test/set super. This is because
|
|
* Setup a dummy root and fs_info for test/set super. This is because
|
|
* we don't actually fill this stuff out until open_ctree, but we need
|
|
* we don't actually fill this stuff out until open_ctree, but we need
|
|
@@ -933,28 +926,36 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
|
|
* then open_ctree will properly initialize everything later.
|
|
* then open_ctree will properly initialize everything later.
|
|
*/
|
|
*/
|
|
fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_NOFS);
|
|
fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_NOFS);
|
|
- if (!fs_info) {
|
|
|
|
- error = -ENOMEM;
|
|
|
|
- goto error_close_devices;
|
|
|
|
- }
|
|
|
|
- tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
|
|
|
|
- if (!tree_root) {
|
|
|
|
|
|
+ if (!fs_info)
|
|
|
|
+ return ERR_PTR(-ENOMEM);
|
|
|
|
+
|
|
|
|
+ fs_info->tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
|
|
|
|
+ if (!fs_info->tree_root) {
|
|
error = -ENOMEM;
|
|
error = -ENOMEM;
|
|
- goto error_close_devices;
|
|
|
|
|
|
+ goto error_fs_info;
|
|
}
|
|
}
|
|
- fs_info->tree_root = tree_root;
|
|
|
|
|
|
+ fs_info->tree_root->fs_info = fs_info;
|
|
fs_info->fs_devices = fs_devices;
|
|
fs_info->fs_devices = fs_devices;
|
|
- tree_root->fs_info = fs_info;
|
|
|
|
|
|
|
|
fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS);
|
|
fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS);
|
|
fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS);
|
|
fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS);
|
|
if (!fs_info->super_copy || !fs_info->super_for_commit) {
|
|
if (!fs_info->super_copy || !fs_info->super_for_commit) {
|
|
error = -ENOMEM;
|
|
error = -ENOMEM;
|
|
|
|
+ goto error_fs_info;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ error = btrfs_open_devices(fs_devices, mode, fs_type);
|
|
|
|
+ if (error)
|
|
|
|
+ goto error_fs_info;
|
|
|
|
+
|
|
|
|
+ if (!(flags & MS_RDONLY) && fs_devices->rw_devices == 0) {
|
|
|
|
+ error = -EACCES;
|
|
goto error_close_devices;
|
|
goto error_close_devices;
|
|
}
|
|
}
|
|
|
|
|
|
bdev = fs_devices->latest_bdev;
|
|
bdev = fs_devices->latest_bdev;
|
|
- s = sget(fs_type, btrfs_test_super, btrfs_set_super, tree_root);
|
|
|
|
|
|
+ s = sget(fs_type, btrfs_test_super, btrfs_set_super,
|
|
|
|
+ fs_info->tree_root);
|
|
if (IS_ERR(s)) {
|
|
if (IS_ERR(s)) {
|
|
error = PTR_ERR(s);
|
|
error = PTR_ERR(s);
|
|
goto error_close_devices;
|
|
goto error_close_devices;
|
|
@@ -963,7 +964,8 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
|
|
if (s->s_root) {
|
|
if (s->s_root) {
|
|
if ((flags ^ s->s_flags) & MS_RDONLY) {
|
|
if ((flags ^ s->s_flags) & MS_RDONLY) {
|
|
deactivate_locked_super(s);
|
|
deactivate_locked_super(s);
|
|
- return ERR_PTR(-EBUSY);
|
|
|
|
|
|
+ error = -EBUSY;
|
|
|
|
+ goto error_close_devices;
|
|
}
|
|
}
|
|
|
|
|
|
btrfs_close_devices(fs_devices);
|
|
btrfs_close_devices(fs_devices);
|
|
@@ -994,6 +996,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
|
|
|
|
|
|
error_close_devices:
|
|
error_close_devices:
|
|
btrfs_close_devices(fs_devices);
|
|
btrfs_close_devices(fs_devices);
|
|
|
|
+error_fs_info:
|
|
free_fs_info(fs_info);
|
|
free_fs_info(fs_info);
|
|
return ERR_PTR(error);
|
|
return ERR_PTR(error);
|
|
}
|
|
}
|