super.c (37bef8f989ed85cdc6cf6fb9c1b1c096179b0708) super.c (8965593e41dd2d0e2a2f1e6f245336005ea94a2c)
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

--- 183 unchanged lines hidden (view full) ---

192 {Opt_discard, "discard"},
193 {Opt_space_cache, "space_cache"},
194 {Opt_clear_cache, "clear_cache"},
195 {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
196 {Opt_enospc_debug, "enospc_debug"},
197 {Opt_subvolrootid, "subvolrootid=%d"},
198 {Opt_defrag, "autodefrag"},
199 {Opt_inode_cache, "inode_cache"},
1/*
2 * Copyright (C) 2007 Oracle. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,

--- 183 unchanged lines hidden (view full) ---

192 {Opt_discard, "discard"},
193 {Opt_space_cache, "space_cache"},
194 {Opt_clear_cache, "clear_cache"},
195 {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"},
196 {Opt_enospc_debug, "enospc_debug"},
197 {Opt_subvolrootid, "subvolrootid=%d"},
198 {Opt_defrag, "autodefrag"},
199 {Opt_inode_cache, "inode_cache"},
200 {Opt_no_space_cache, "no_space_cache"},
200 {Opt_no_space_cache, "nospace_cache"},
201 {Opt_recovery, "recovery"},
202 {Opt_err, NULL},
203};
204
205/*
206 * Regular mount options parser. Everything that is needed only when
207 * reading in a new superblock is parsed here.
208 */

--- 234 unchanged lines hidden (view full) ---

443 while ((p = strsep(&opts, ",")) != NULL) {
444 int token;
445 if (!*p)
446 continue;
447
448 token = match_token(p, tokens, args);
449 switch (token) {
450 case Opt_subvol:
201 {Opt_recovery, "recovery"},
202 {Opt_err, NULL},
203};
204
205/*
206 * Regular mount options parser. Everything that is needed only when
207 * reading in a new superblock is parsed here.
208 */

--- 234 unchanged lines hidden (view full) ---

443 while ((p = strsep(&opts, ",")) != NULL) {
444 int token;
445 if (!*p)
446 continue;
447
448 token = match_token(p, tokens, args);
449 switch (token) {
450 case Opt_subvol:
451 kfree(*subvol_name);
451 *subvol_name = match_strdup(&args[0]);
452 break;
453 case Opt_subvolid:
454 intarg = 0;
455 error = match_int(&args[0], &intarg);
456 if (!error) {
457 /* we want the original fs_tree */
458 if (!intarg)

--- 246 unchanged lines hidden (view full) ---

705 seq_puts(seq, ",flushoncommit");
706 if (btrfs_test_opt(root, DISCARD))
707 seq_puts(seq, ",discard");
708 if (!(root->fs_info->sb->s_flags & MS_POSIXACL))
709 seq_puts(seq, ",noacl");
710 if (btrfs_test_opt(root, SPACE_CACHE))
711 seq_puts(seq, ",space_cache");
712 else
452 *subvol_name = match_strdup(&args[0]);
453 break;
454 case Opt_subvolid:
455 intarg = 0;
456 error = match_int(&args[0], &intarg);
457 if (!error) {
458 /* we want the original fs_tree */
459 if (!intarg)

--- 246 unchanged lines hidden (view full) ---

706 seq_puts(seq, ",flushoncommit");
707 if (btrfs_test_opt(root, DISCARD))
708 seq_puts(seq, ",discard");
709 if (!(root->fs_info->sb->s_flags & MS_POSIXACL))
710 seq_puts(seq, ",noacl");
711 if (btrfs_test_opt(root, SPACE_CACHE))
712 seq_puts(seq, ",space_cache");
713 else
713 seq_puts(seq, ",no_space_cache");
714 seq_puts(seq, ",nospace_cache");
714 if (btrfs_test_opt(root, CLEAR_CACHE))
715 seq_puts(seq, ",clear_cache");
716 if (btrfs_test_opt(root, USER_SUBVOL_RM_ALLOWED))
717 seq_puts(seq, ",user_subvol_rm_allowed");
718 if (btrfs_test_opt(root, ENOSPC_DEBUG))
719 seq_puts(seq, ",enospc_debug");
720 if (btrfs_test_opt(root, AUTO_DEFRAG))
721 seq_puts(seq, ",autodefrag");

--- 163 unchanged lines hidden (view full) ---

885 */
886static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
887 const char *device_name, void *data)
888{
889 struct block_device *bdev = NULL;
890 struct super_block *s;
891 struct dentry *root;
892 struct btrfs_fs_devices *fs_devices = NULL;
715 if (btrfs_test_opt(root, CLEAR_CACHE))
716 seq_puts(seq, ",clear_cache");
717 if (btrfs_test_opt(root, USER_SUBVOL_RM_ALLOWED))
718 seq_puts(seq, ",user_subvol_rm_allowed");
719 if (btrfs_test_opt(root, ENOSPC_DEBUG))
720 seq_puts(seq, ",enospc_debug");
721 if (btrfs_test_opt(root, AUTO_DEFRAG))
722 seq_puts(seq, ",autodefrag");

--- 163 unchanged lines hidden (view full) ---

886 */
887static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
888 const char *device_name, void *data)
889{
890 struct block_device *bdev = NULL;
891 struct super_block *s;
892 struct dentry *root;
893 struct btrfs_fs_devices *fs_devices = NULL;
893 struct btrfs_root *tree_root = NULL;
894 struct btrfs_fs_info *fs_info = NULL;
895 fmode_t mode = FMODE_READ;
896 char *subvol_name = NULL;
897 u64 subvol_objectid = 0;
898 u64 subvol_rootid = 0;
899 int error = 0;
900
901 if (!(flags & MS_RDONLY))
902 mode |= FMODE_WRITE;
903
904 error = btrfs_parse_early_options(data, mode, fs_type,
905 &subvol_name, &subvol_objectid,
906 &subvol_rootid, &fs_devices);
894 struct btrfs_fs_info *fs_info = NULL;
895 fmode_t mode = FMODE_READ;
896 char *subvol_name = NULL;
897 u64 subvol_objectid = 0;
898 u64 subvol_rootid = 0;
899 int error = 0;
900
901 if (!(flags & MS_RDONLY))
902 mode |= FMODE_WRITE;
903
904 error = btrfs_parse_early_options(data, mode, fs_type,
905 &subvol_name, &subvol_objectid,
906 &subvol_rootid, &fs_devices);
907 if (error)
907 if (error) {
908 kfree(subvol_name);
908 return ERR_PTR(error);
909 return ERR_PTR(error);
910 }
909
910 if (subvol_name) {
911 root = mount_subvol(subvol_name, flags, device_name, data);
912 kfree(subvol_name);
913 return root;
914 }
915
916 error = btrfs_scan_one_device(device_name, mode, fs_type, &fs_devices);
917 if (error)
918 return ERR_PTR(error);
919
911
912 if (subvol_name) {
913 root = mount_subvol(subvol_name, flags, device_name, data);
914 kfree(subvol_name);
915 return root;
916 }
917
918 error = btrfs_scan_one_device(device_name, mode, fs_type, &fs_devices);
919 if (error)
920 return ERR_PTR(error);
921
920 error = btrfs_open_devices(fs_devices, mode, fs_type);
921 if (error)
922 return ERR_PTR(error);
923
924 if (!(flags & MS_RDONLY) && fs_devices->rw_devices == 0) {
925 error = -EACCES;
926 goto error_close_devices;
927 }
928
929 /*
930 * Setup a dummy root and fs_info for test/set super. This is because
931 * we don't actually fill this stuff out until open_ctree, but we need
932 * it for searching for existing supers, so this lets us do that and
933 * then open_ctree will properly initialize everything later.
934 */
935 fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_NOFS);
922 /*
923 * Setup a dummy root and fs_info for test/set super. This is because
924 * we don't actually fill this stuff out until open_ctree, but we need
925 * it for searching for existing supers, so this lets us do that and
926 * then open_ctree will properly initialize everything later.
927 */
928 fs_info = kzalloc(sizeof(struct btrfs_fs_info), GFP_NOFS);
936 tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
937 if (!fs_info || !tree_root) {
929 if (!fs_info)
930 return ERR_PTR(-ENOMEM);
931
932 fs_info->tree_root = kzalloc(sizeof(struct btrfs_root), GFP_NOFS);
933 if (!fs_info->tree_root) {
938 error = -ENOMEM;
934 error = -ENOMEM;
939 goto error_close_devices;
935 goto error_fs_info;
940 }
936 }
941 fs_info->tree_root = tree_root;
937 fs_info->tree_root->fs_info = fs_info;
942 fs_info->fs_devices = fs_devices;
938 fs_info->fs_devices = fs_devices;
943 tree_root->fs_info = fs_info;
944
945 fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS);
946 fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS);
947 if (!fs_info->super_copy || !fs_info->super_for_commit) {
948 error = -ENOMEM;
939
940 fs_info->super_copy = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS);
941 fs_info->super_for_commit = kzalloc(BTRFS_SUPER_INFO_SIZE, GFP_NOFS);
942 if (!fs_info->super_copy || !fs_info->super_for_commit) {
943 error = -ENOMEM;
944 goto error_fs_info;
945 }
946
947 error = btrfs_open_devices(fs_devices, mode, fs_type);
948 if (error)
949 goto error_fs_info;
950
951 if (!(flags & MS_RDONLY) && fs_devices->rw_devices == 0) {
952 error = -EACCES;
949 goto error_close_devices;
950 }
951
952 bdev = fs_devices->latest_bdev;
953 goto error_close_devices;
954 }
955
956 bdev = fs_devices->latest_bdev;
953 s = sget(fs_type, btrfs_test_super, btrfs_set_super, tree_root);
957 s = sget(fs_type, btrfs_test_super, btrfs_set_super,
958 fs_info->tree_root);
954 if (IS_ERR(s)) {
955 error = PTR_ERR(s);
956 goto error_close_devices;
957 }
958
959 if (s->s_root) {
960 if ((flags ^ s->s_flags) & MS_RDONLY) {
961 deactivate_locked_super(s);
959 if (IS_ERR(s)) {
960 error = PTR_ERR(s);
961 goto error_close_devices;
962 }
963
964 if (s->s_root) {
965 if ((flags ^ s->s_flags) & MS_RDONLY) {
966 deactivate_locked_super(s);
962 return ERR_PTR(-EBUSY);
967 error = -EBUSY;
968 goto error_close_devices;
963 }
964
965 btrfs_close_devices(fs_devices);
966 free_fs_info(fs_info);
969 }
970
971 btrfs_close_devices(fs_devices);
972 free_fs_info(fs_info);
967 kfree(tree_root);
968 } else {
969 char b[BDEVNAME_SIZE];
970
971 s->s_flags = flags | MS_NOSEC;
972 strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));
973 btrfs_sb(s)->fs_info->bdev_holder = fs_type;
974 error = btrfs_fill_super(s, fs_devices, data,
975 flags & MS_SILENT ? 1 : 0);

--- 10 unchanged lines hidden (view full) ---

986 deactivate_locked_super(s);
987 return root;
988 }
989
990 return root;
991
992error_close_devices:
993 btrfs_close_devices(fs_devices);
973 } else {
974 char b[BDEVNAME_SIZE];
975
976 s->s_flags = flags | MS_NOSEC;
977 strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));
978 btrfs_sb(s)->fs_info->bdev_holder = fs_type;
979 error = btrfs_fill_super(s, fs_devices, data,
980 flags & MS_SILENT ? 1 : 0);

--- 10 unchanged lines hidden (view full) ---

991 deactivate_locked_super(s);
992 return root;
993 }
994
995 return root;
996
997error_close_devices:
998 btrfs_close_devices(fs_devices);
999error_fs_info:
994 free_fs_info(fs_info);
1000 free_fs_info(fs_info);
995 kfree(tree_root);
996 return ERR_PTR(error);
997}
998
999static int btrfs_remount(struct super_block *sb, int *flags, char *data)
1000{
1001 struct btrfs_root *root = btrfs_sb(sb);
1002 int ret;
1003

--- 400 unchanged lines hidden ---
1001 return ERR_PTR(error);
1002}
1003
1004static int btrfs_remount(struct super_block *sb, int *flags, char *data)
1005{
1006 struct btrfs_root *root = btrfs_sb(sb);
1007 int ret;
1008

--- 400 unchanged lines hidden ---