super.c (53113b06e48c6c38f7612c1f8043b8a0d2adf72b) | super.c (d0b678cb0a26783ab7238784f1e7e608e5caafa3) |
---|---|
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, --- 54 unchanged lines hidden (view full) --- 63 sb->s_fs_info = NULL; 64} 65 66enum { 67 Opt_degraded, Opt_subvol, Opt_subvolid, Opt_device, Opt_nodatasum, 68 Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd, 69 Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress, 70 Opt_compress_force, Opt_notreelog, Opt_ratio, Opt_flushoncommit, | 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, --- 54 unchanged lines hidden (view full) --- 63 sb->s_fs_info = NULL; 64} 65 66enum { 67 Opt_degraded, Opt_subvol, Opt_subvolid, Opt_device, Opt_nodatasum, 68 Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd, 69 Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress, 70 Opt_compress_force, Opt_notreelog, Opt_ratio, Opt_flushoncommit, |
71 Opt_discard, Opt_err, | 71 Opt_discard, Opt_space_cache, Opt_clear_cache, Opt_err, |
72}; 73 74static match_table_t tokens = { 75 {Opt_degraded, "degraded"}, 76 {Opt_subvol, "subvol=%s"}, 77 {Opt_subvolid, "subvolid=%d"}, 78 {Opt_device, "device=%s"}, 79 {Opt_nodatasum, "nodatasum"}, --- 7 unchanged lines hidden (view full) --- 87 {Opt_ssd, "ssd"}, 88 {Opt_ssd_spread, "ssd_spread"}, 89 {Opt_nossd, "nossd"}, 90 {Opt_noacl, "noacl"}, 91 {Opt_notreelog, "notreelog"}, 92 {Opt_flushoncommit, "flushoncommit"}, 93 {Opt_ratio, "metadata_ratio=%d"}, 94 {Opt_discard, "discard"}, | 72}; 73 74static match_table_t tokens = { 75 {Opt_degraded, "degraded"}, 76 {Opt_subvol, "subvol=%s"}, 77 {Opt_subvolid, "subvolid=%d"}, 78 {Opt_device, "device=%s"}, 79 {Opt_nodatasum, "nodatasum"}, --- 7 unchanged lines hidden (view full) --- 87 {Opt_ssd, "ssd"}, 88 {Opt_ssd_spread, "ssd_spread"}, 89 {Opt_nossd, "nossd"}, 90 {Opt_noacl, "noacl"}, 91 {Opt_notreelog, "notreelog"}, 92 {Opt_flushoncommit, "flushoncommit"}, 93 {Opt_ratio, "metadata_ratio=%d"}, 94 {Opt_discard, "discard"}, |
95 {Opt_space_cache, "space_cache"}, 96 {Opt_clear_cache, "clear_cache"}, |
|
95 {Opt_err, NULL}, 96}; 97 98/* 99 * Regular mount options parser. Everything that is needed only when 100 * reading in a new superblock is parsed here. 101 */ 102int btrfs_parse_options(struct btrfs_root *root, char *options) --- 127 unchanged lines hidden (view full) --- 230 info->metadata_ratio = intarg; 231 printk(KERN_INFO "btrfs: metadata ratio %d\n", 232 info->metadata_ratio); 233 } 234 break; 235 case Opt_discard: 236 btrfs_set_opt(info->mount_opt, DISCARD); 237 break; | 97 {Opt_err, NULL}, 98}; 99 100/* 101 * Regular mount options parser. Everything that is needed only when 102 * reading in a new superblock is parsed here. 103 */ 104int btrfs_parse_options(struct btrfs_root *root, char *options) --- 127 unchanged lines hidden (view full) --- 232 info->metadata_ratio = intarg; 233 printk(KERN_INFO "btrfs: metadata ratio %d\n", 234 info->metadata_ratio); 235 } 236 break; 237 case Opt_discard: 238 btrfs_set_opt(info->mount_opt, DISCARD); 239 break; |
240 case Opt_space_cache: 241 printk(KERN_INFO "btrfs: enabling disk space caching\n"); 242 btrfs_set_opt(info->mount_opt, SPACE_CACHE); 243 case Opt_clear_cache: 244 printk(KERN_INFO "btrfs: force clearing of disk cache\n"); 245 btrfs_set_opt(info->mount_opt, CLEAR_CACHE); 246 break; |
|
238 case Opt_err: 239 printk(KERN_INFO "btrfs: unrecognized mount option " 240 "'%s'\n", p); 241 ret = -EINVAL; 242 goto out; 243 default: 244 break; 245 } --- 129 unchanged lines hidden (view full) --- 375 } 376 377 btrfs_dir_item_key_to_cpu(path->nodes[0], di, &location); 378 btrfs_free_path(path); 379 380find_root: 381 new_root = btrfs_read_fs_root_no_name(root->fs_info, &location); 382 if (IS_ERR(new_root)) | 247 case Opt_err: 248 printk(KERN_INFO "btrfs: unrecognized mount option " 249 "'%s'\n", p); 250 ret = -EINVAL; 251 goto out; 252 default: 253 break; 254 } --- 129 unchanged lines hidden (view full) --- 384 } 385 386 btrfs_dir_item_key_to_cpu(path->nodes[0], di, &location); 387 btrfs_free_path(path); 388 389find_root: 390 new_root = btrfs_read_fs_root_no_name(root->fs_info, &location); 391 if (IS_ERR(new_root)) |
383 return ERR_PTR(PTR_ERR(new_root)); | 392 return ERR_CAST(new_root); |
384 385 if (btrfs_root_refs(&new_root->root_item) == 0) 386 return ERR_PTR(-ENOENT); 387 388 dir_id = btrfs_root_dirid(&new_root->root_item); 389setup_root: 390 location.objectid = dir_id; 391 location.type = BTRFS_INODE_ITEM_KEY; --- 163 unchanged lines hidden (view full) --- 555} 556 557/* 558 * Find a superblock for the given device / mount point. 559 * 560 * Note: This is based on get_sb_bdev from fs/super.c with a few additions 561 * for multiple device setup. Make sure to keep it in sync. 562 */ | 393 394 if (btrfs_root_refs(&new_root->root_item) == 0) 395 return ERR_PTR(-ENOENT); 396 397 dir_id = btrfs_root_dirid(&new_root->root_item); 398setup_root: 399 location.objectid = dir_id; 400 location.type = BTRFS_INODE_ITEM_KEY; --- 163 unchanged lines hidden (view full) --- 564} 565 566/* 567 * Find a superblock for the given device / mount point. 568 * 569 * Note: This is based on get_sb_bdev from fs/super.c with a few additions 570 * for multiple device setup. Make sure to keep it in sync. 571 */ |
563static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, 564 const char *dev_name, void *data) | 572static int btrfs_get_sb(struct file_system_type *fs_type, int flags, 573 const char *dev_name, void *data, struct vfsmount *mnt) |
565{ 566 struct block_device *bdev = NULL; 567 struct super_block *s; 568 struct dentry *root; 569 struct btrfs_fs_devices *fs_devices = NULL; 570 fmode_t mode = FMODE_READ; 571 char *subvol_name = NULL; 572 u64 subvol_objectid = 0; 573 int error = 0; 574 int found = 0; 575 576 if (!(flags & MS_RDONLY)) 577 mode |= FMODE_WRITE; 578 579 error = btrfs_parse_early_options(data, mode, fs_type, 580 &subvol_name, &subvol_objectid, 581 &fs_devices); 582 if (error) | 574{ 575 struct block_device *bdev = NULL; 576 struct super_block *s; 577 struct dentry *root; 578 struct btrfs_fs_devices *fs_devices = NULL; 579 fmode_t mode = FMODE_READ; 580 char *subvol_name = NULL; 581 u64 subvol_objectid = 0; 582 int error = 0; 583 int found = 0; 584 585 if (!(flags & MS_RDONLY)) 586 mode |= FMODE_WRITE; 587 588 error = btrfs_parse_early_options(data, mode, fs_type, 589 &subvol_name, &subvol_objectid, 590 &fs_devices); 591 if (error) |
583 return ERR_PTR(error); | 592 return error; |
584 585 error = btrfs_scan_one_device(dev_name, mode, fs_type, &fs_devices); 586 if (error) 587 goto error_free_subvol_name; 588 589 error = btrfs_open_devices(fs_devices, mode, fs_type); 590 if (error) 591 goto error_free_subvol_name; --- 32 unchanged lines hidden (view full) --- 624 btrfs_sb(s)->fs_info->bdev_holder = fs_type; 625 s->s_flags |= MS_ACTIVE; 626 } 627 628 root = get_default_root(s, subvol_objectid); 629 if (IS_ERR(root)) { 630 error = PTR_ERR(root); 631 deactivate_locked_super(s); | 593 594 error = btrfs_scan_one_device(dev_name, mode, fs_type, &fs_devices); 595 if (error) 596 goto error_free_subvol_name; 597 598 error = btrfs_open_devices(fs_devices, mode, fs_type); 599 if (error) 600 goto error_free_subvol_name; --- 32 unchanged lines hidden (view full) --- 633 btrfs_sb(s)->fs_info->bdev_holder = fs_type; 634 s->s_flags |= MS_ACTIVE; 635 } 636 637 root = get_default_root(s, subvol_objectid); 638 if (IS_ERR(root)) { 639 error = PTR_ERR(root); 640 deactivate_locked_super(s); |
632 goto error; | 641 goto error_free_subvol_name; |
633 } 634 /* if they gave us a subvolume name bind mount into that */ 635 if (strcmp(subvol_name, ".")) { 636 struct dentry *new_root; 637 mutex_lock(&root->d_inode->i_mutex); 638 new_root = lookup_one_len(subvol_name, root, 639 strlen(subvol_name)); 640 mutex_unlock(&root->d_inode->i_mutex); 641 642 if (IS_ERR(new_root)) { 643 deactivate_locked_super(s); 644 error = PTR_ERR(new_root); 645 dput(root); | 642 } 643 /* if they gave us a subvolume name bind mount into that */ 644 if (strcmp(subvol_name, ".")) { 645 struct dentry *new_root; 646 mutex_lock(&root->d_inode->i_mutex); 647 new_root = lookup_one_len(subvol_name, root, 648 strlen(subvol_name)); 649 mutex_unlock(&root->d_inode->i_mutex); 650 651 if (IS_ERR(new_root)) { 652 deactivate_locked_super(s); 653 error = PTR_ERR(new_root); 654 dput(root); |
646 goto error_close_devices; | 655 goto error_free_subvol_name; |
647 } 648 if (!new_root->d_inode) { 649 dput(root); 650 dput(new_root); 651 deactivate_locked_super(s); 652 error = -ENXIO; | 656 } 657 if (!new_root->d_inode) { 658 dput(root); 659 dput(new_root); 660 deactivate_locked_super(s); 661 error = -ENXIO; |
653 goto error_close_devices; | 662 goto error_free_subvol_name; |
654 } 655 dput(root); 656 root = new_root; 657 } 658 | 663 } 664 dput(root); 665 root = new_root; 666 } 667 |
668 mnt->mnt_sb = s; 669 mnt->mnt_root = root; 670 |
|
659 kfree(subvol_name); | 671 kfree(subvol_name); |
660 return root; | 672 return 0; |
661 662error_s: 663 error = PTR_ERR(s); 664error_close_devices: 665 btrfs_close_devices(fs_devices); 666error_free_subvol_name: 667 kfree(subvol_name); | 673 674error_s: 675 error = PTR_ERR(s); 676error_close_devices: 677 btrfs_close_devices(fs_devices); 678error_free_subvol_name: 679 kfree(subvol_name); |
668error: 669 return ERR_PTR(error); | 680 return error; |
670} 671 672static int btrfs_remount(struct super_block *sb, int *flags, char *data) 673{ 674 struct btrfs_root *root = btrfs_sb(sb); 675 int ret; 676 677 ret = btrfs_parse_options(root, data); --- 30 unchanged lines hidden (view full) --- 708 709static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) 710{ 711 struct btrfs_root *root = btrfs_sb(dentry->d_sb); 712 struct btrfs_super_block *disk_super = &root->fs_info->super_copy; 713 struct list_head *head = &root->fs_info->space_info; 714 struct btrfs_space_info *found; 715 u64 total_used = 0; | 681} 682 683static int btrfs_remount(struct super_block *sb, int *flags, char *data) 684{ 685 struct btrfs_root *root = btrfs_sb(sb); 686 int ret; 687 688 ret = btrfs_parse_options(root, data); --- 30 unchanged lines hidden (view full) --- 719 720static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) 721{ 722 struct btrfs_root *root = btrfs_sb(dentry->d_sb); 723 struct btrfs_super_block *disk_super = &root->fs_info->super_copy; 724 struct list_head *head = &root->fs_info->space_info; 725 struct btrfs_space_info *found; 726 u64 total_used = 0; |
727 u64 total_used_data = 0; |
|
716 int bits = dentry->d_sb->s_blocksize_bits; 717 __be32 *fsid = (__be32 *)root->fs_info->fsid; 718 719 rcu_read_lock(); | 728 int bits = dentry->d_sb->s_blocksize_bits; 729 __be32 *fsid = (__be32 *)root->fs_info->fsid; 730 731 rcu_read_lock(); |
720 list_for_each_entry_rcu(found, head, list) | 732 list_for_each_entry_rcu(found, head, list) { 733 if (found->flags & (BTRFS_BLOCK_GROUP_METADATA | 734 BTRFS_BLOCK_GROUP_SYSTEM)) 735 total_used_data += found->disk_total; 736 else 737 total_used_data += found->disk_used; |
721 total_used += found->disk_used; | 738 total_used += found->disk_used; |
739 } |
|
722 rcu_read_unlock(); 723 724 buf->f_namelen = BTRFS_NAME_LEN; 725 buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits; 726 buf->f_bfree = buf->f_blocks - (total_used >> bits); | 740 rcu_read_unlock(); 741 742 buf->f_namelen = BTRFS_NAME_LEN; 743 buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits; 744 buf->f_bfree = buf->f_blocks - (total_used >> bits); |
727 buf->f_bavail = buf->f_bfree; | 745 buf->f_bavail = buf->f_blocks - (total_used_data >> bits); |
728 buf->f_bsize = dentry->d_sb->s_blocksize; 729 buf->f_type = BTRFS_SUPER_MAGIC; 730 731 /* We treat it as constant endianness (it doesn't matter _which_) 732 because we want the fsid to come out the same whether mounted 733 on a big-endian or little-endian host */ 734 buf->f_fsid.val[0] = be32_to_cpu(fsid[0]) ^ be32_to_cpu(fsid[2]); 735 buf->f_fsid.val[1] = be32_to_cpu(fsid[1]) ^ be32_to_cpu(fsid[3]); 736 /* Mask in the root object ID too, to disambiguate subvols */ 737 buf->f_fsid.val[0] ^= BTRFS_I(dentry->d_inode)->root->objectid >> 32; 738 buf->f_fsid.val[1] ^= BTRFS_I(dentry->d_inode)->root->objectid; 739 740 return 0; 741} 742 743static struct file_system_type btrfs_fs_type = { 744 .owner = THIS_MODULE, 745 .name = "btrfs", | 746 buf->f_bsize = dentry->d_sb->s_blocksize; 747 buf->f_type = BTRFS_SUPER_MAGIC; 748 749 /* We treat it as constant endianness (it doesn't matter _which_) 750 because we want the fsid to come out the same whether mounted 751 on a big-endian or little-endian host */ 752 buf->f_fsid.val[0] = be32_to_cpu(fsid[0]) ^ be32_to_cpu(fsid[2]); 753 buf->f_fsid.val[1] = be32_to_cpu(fsid[1]) ^ be32_to_cpu(fsid[3]); 754 /* Mask in the root object ID too, to disambiguate subvols */ 755 buf->f_fsid.val[0] ^= BTRFS_I(dentry->d_inode)->root->objectid >> 32; 756 buf->f_fsid.val[1] ^= BTRFS_I(dentry->d_inode)->root->objectid; 757 758 return 0; 759} 760 761static struct file_system_type btrfs_fs_type = { 762 .owner = THIS_MODULE, 763 .name = "btrfs", |
746 .mount = btrfs_mount, | 764 .get_sb = btrfs_get_sb, |
747 .kill_sb = kill_anon_super, 748 .fs_flags = FS_REQUIRES_DEV, 749}; 750 751/* 752 * used by btrfsctl to scan devices when no FS is mounted 753 */ 754static long btrfs_control_ioctl(struct file *file, unsigned int cmd, --- 52 unchanged lines hidden (view full) --- 807 .freeze_fs = btrfs_freeze, 808 .unfreeze_fs = btrfs_unfreeze, 809}; 810 811static const struct file_operations btrfs_ctl_fops = { 812 .unlocked_ioctl = btrfs_control_ioctl, 813 .compat_ioctl = btrfs_control_ioctl, 814 .owner = THIS_MODULE, | 765 .kill_sb = kill_anon_super, 766 .fs_flags = FS_REQUIRES_DEV, 767}; 768 769/* 770 * used by btrfsctl to scan devices when no FS is mounted 771 */ 772static long btrfs_control_ioctl(struct file *file, unsigned int cmd, --- 52 unchanged lines hidden (view full) --- 825 .freeze_fs = btrfs_freeze, 826 .unfreeze_fs = btrfs_unfreeze, 827}; 828 829static const struct file_operations btrfs_ctl_fops = { 830 .unlocked_ioctl = btrfs_control_ioctl, 831 .compat_ioctl = btrfs_control_ioctl, 832 .owner = THIS_MODULE, |
815 .llseek = noop_llseek, | |
816}; 817 818static struct miscdevice btrfs_misc = { 819 .minor = BTRFS_MINOR, 820 .name = "btrfs-control", 821 .fops = &btrfs_ctl_fops 822}; 823 --- 74 unchanged lines hidden --- | 833}; 834 835static struct miscdevice btrfs_misc = { 836 .minor = BTRFS_MINOR, 837 .name = "btrfs-control", 838 .fops = &btrfs_ctl_fops 839}; 840 --- 74 unchanged lines hidden --- |