diff options
author | Chris Mason <chris.mason@fusionio.com> | 2012-07-25 16:11:38 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@fusionio.com> | 2012-07-25 16:11:38 -0400 |
commit | b478b2baa37ac99fc04a30809c780dd5dfd43595 (patch) | |
tree | bed7af1466e5b1e0b0501eba18f77c804a864d7d /fs/btrfs/ctree.h | |
parent | 67c9684f48ea9cbc5e9b8a1feb3151800e9dcc22 (diff) | |
parent | 6f72c7e20dbaea55f04546de69586c84a3654503 (diff) |
Merge branch 'qgroup' of git://git.jan-o-sch.net/btrfs-unstable into for-linus
Conflicts:
fs/btrfs/ioctl.c
fs/btrfs/ioctl.h
fs/btrfs/transaction.c
fs/btrfs/transaction.h
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r-- | fs/btrfs/ctree.h | 233 |
1 files changed, 225 insertions, 8 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index a0ee2f8e0566..00f9a50f986d 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -91,6 +91,9 @@ struct btrfs_ordered_sum; | |||
91 | /* for storing balance parameters in the root tree */ | 91 | /* for storing balance parameters in the root tree */ |
92 | #define BTRFS_BALANCE_OBJECTID -4ULL | 92 | #define BTRFS_BALANCE_OBJECTID -4ULL |
93 | 93 | ||
94 | /* holds quota configuration and tracking */ | ||
95 | #define BTRFS_QUOTA_TREE_OBJECTID 8ULL | ||
96 | |||
94 | /* orhpan objectid for tracking unlinked/truncated files */ | 97 | /* orhpan objectid for tracking unlinked/truncated files */ |
95 | #define BTRFS_ORPHAN_OBJECTID -5ULL | 98 | #define BTRFS_ORPHAN_OBJECTID -5ULL |
96 | 99 | ||
@@ -883,6 +886,72 @@ struct btrfs_block_group_item { | |||
883 | __le64 flags; | 886 | __le64 flags; |
884 | } __attribute__ ((__packed__)); | 887 | } __attribute__ ((__packed__)); |
885 | 888 | ||
889 | /* | ||
890 | * is subvolume quota turned on? | ||
891 | */ | ||
892 | #define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0) | ||
893 | /* | ||
894 | * SCANNING is set during the initialization phase | ||
895 | */ | ||
896 | #define BTRFS_QGROUP_STATUS_FLAG_SCANNING (1ULL << 1) | ||
897 | /* | ||
898 | * Some qgroup entries are known to be out of date, | ||
899 | * either because the configuration has changed in a way that | ||
900 | * makes a rescan necessary, or because the fs has been mounted | ||
901 | * with a non-qgroup-aware version. | ||
902 | * Turning qouta off and on again makes it inconsistent, too. | ||
903 | */ | ||
904 | #define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2) | ||
905 | |||
906 | #define BTRFS_QGROUP_STATUS_VERSION 1 | ||
907 | |||
908 | struct btrfs_qgroup_status_item { | ||
909 | __le64 version; | ||
910 | /* | ||
911 | * the generation is updated during every commit. As older | ||
912 | * versions of btrfs are not aware of qgroups, it will be | ||
913 | * possible to detect inconsistencies by checking the | ||
914 | * generation on mount time | ||
915 | */ | ||
916 | __le64 generation; | ||
917 | |||
918 | /* flag definitions see above */ | ||
919 | __le64 flags; | ||
920 | |||
921 | /* | ||
922 | * only used during scanning to record the progress | ||
923 | * of the scan. It contains a logical address | ||
924 | */ | ||
925 | __le64 scan; | ||
926 | } __attribute__ ((__packed__)); | ||
927 | |||
928 | struct btrfs_qgroup_info_item { | ||
929 | __le64 generation; | ||
930 | __le64 rfer; | ||
931 | __le64 rfer_cmpr; | ||
932 | __le64 excl; | ||
933 | __le64 excl_cmpr; | ||
934 | } __attribute__ ((__packed__)); | ||
935 | |||
936 | /* flags definition for qgroup limits */ | ||
937 | #define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0) | ||
938 | #define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1) | ||
939 | #define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2) | ||
940 | #define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3) | ||
941 | #define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4) | ||
942 | #define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5) | ||
943 | |||
944 | struct btrfs_qgroup_limit_item { | ||
945 | /* | ||
946 | * only updated when any of the other values change | ||
947 | */ | ||
948 | __le64 flags; | ||
949 | __le64 max_rfer; | ||
950 | __le64 max_excl; | ||
951 | __le64 rsv_rfer; | ||
952 | __le64 rsv_excl; | ||
953 | } __attribute__ ((__packed__)); | ||
954 | |||
886 | struct btrfs_space_info { | 955 | struct btrfs_space_info { |
887 | u64 flags; | 956 | u64 flags; |
888 | 957 | ||
@@ -1030,6 +1099,13 @@ struct btrfs_block_group_cache { | |||
1030 | struct list_head cluster_list; | 1099 | struct list_head cluster_list; |
1031 | }; | 1100 | }; |
1032 | 1101 | ||
1102 | /* delayed seq elem */ | ||
1103 | struct seq_list { | ||
1104 | struct list_head list; | ||
1105 | u64 seq; | ||
1106 | }; | ||
1107 | |||
1108 | /* fs_info */ | ||
1033 | struct reloc_control; | 1109 | struct reloc_control; |
1034 | struct btrfs_device; | 1110 | struct btrfs_device; |
1035 | struct btrfs_fs_devices; | 1111 | struct btrfs_fs_devices; |
@@ -1044,6 +1120,7 @@ struct btrfs_fs_info { | |||
1044 | struct btrfs_root *dev_root; | 1120 | struct btrfs_root *dev_root; |
1045 | struct btrfs_root *fs_root; | 1121 | struct btrfs_root *fs_root; |
1046 | struct btrfs_root *csum_root; | 1122 | struct btrfs_root *csum_root; |
1123 | struct btrfs_root *quota_root; | ||
1047 | 1124 | ||
1048 | /* the log root tree is a directory of all the other log roots */ | 1125 | /* the log root tree is a directory of all the other log roots */ |
1049 | struct btrfs_root *log_root_tree; | 1126 | struct btrfs_root *log_root_tree; |
@@ -1144,6 +1221,8 @@ struct btrfs_fs_info { | |||
1144 | spinlock_t tree_mod_seq_lock; | 1221 | spinlock_t tree_mod_seq_lock; |
1145 | atomic_t tree_mod_seq; | 1222 | atomic_t tree_mod_seq; |
1146 | struct list_head tree_mod_seq_list; | 1223 | struct list_head tree_mod_seq_list; |
1224 | struct seq_list tree_mod_seq_elem; | ||
1225 | wait_queue_head_t tree_mod_seq_wait; | ||
1147 | 1226 | ||
1148 | /* this protects tree_mod_log */ | 1227 | /* this protects tree_mod_log */ |
1149 | rwlock_t tree_mod_log_lock; | 1228 | rwlock_t tree_mod_log_lock; |
@@ -1298,6 +1377,29 @@ struct btrfs_fs_info { | |||
1298 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY | 1377 | #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY |
1299 | u32 check_integrity_print_mask; | 1378 | u32 check_integrity_print_mask; |
1300 | #endif | 1379 | #endif |
1380 | /* | ||
1381 | * quota information | ||
1382 | */ | ||
1383 | unsigned int quota_enabled:1; | ||
1384 | |||
1385 | /* | ||
1386 | * quota_enabled only changes state after a commit. This holds the | ||
1387 | * next state. | ||
1388 | */ | ||
1389 | unsigned int pending_quota_state:1; | ||
1390 | |||
1391 | /* is qgroup tracking in a consistent state? */ | ||
1392 | u64 qgroup_flags; | ||
1393 | |||
1394 | /* holds configuration and tracking. Protected by qgroup_lock */ | ||
1395 | struct rb_root qgroup_tree; | ||
1396 | spinlock_t qgroup_lock; | ||
1397 | |||
1398 | /* list of dirty qgroups to be written at next commit */ | ||
1399 | struct list_head dirty_qgroups; | ||
1400 | |||
1401 | /* used by btrfs_qgroup_record_ref for an efficient tree traversal */ | ||
1402 | u64 qgroup_seq; | ||
1301 | 1403 | ||
1302 | /* filesystem state */ | 1404 | /* filesystem state */ |
1303 | u64 fs_state; | 1405 | u64 fs_state; |
@@ -1527,6 +1629,30 @@ struct btrfs_ioctl_defrag_range_args { | |||
1527 | #define BTRFS_DEV_ITEM_KEY 216 | 1629 | #define BTRFS_DEV_ITEM_KEY 216 |
1528 | #define BTRFS_CHUNK_ITEM_KEY 228 | 1630 | #define BTRFS_CHUNK_ITEM_KEY 228 |
1529 | 1631 | ||
1632 | /* | ||
1633 | * Records the overall state of the qgroups. | ||
1634 | * There's only one instance of this key present, | ||
1635 | * (0, BTRFS_QGROUP_STATUS_KEY, 0) | ||
1636 | */ | ||
1637 | #define BTRFS_QGROUP_STATUS_KEY 240 | ||
1638 | /* | ||
1639 | * Records the currently used space of the qgroup. | ||
1640 | * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid). | ||
1641 | */ | ||
1642 | #define BTRFS_QGROUP_INFO_KEY 242 | ||
1643 | /* | ||
1644 | * Contains the user configured limits for the qgroup. | ||
1645 | * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid). | ||
1646 | */ | ||
1647 | #define BTRFS_QGROUP_LIMIT_KEY 244 | ||
1648 | /* | ||
1649 | * Records the child-parent relationship of qgroups. For | ||
1650 | * each relation, 2 keys are present: | ||
1651 | * (childid, BTRFS_QGROUP_RELATION_KEY, parentid) | ||
1652 | * (parentid, BTRFS_QGROUP_RELATION_KEY, childid) | ||
1653 | */ | ||
1654 | #define BTRFS_QGROUP_RELATION_KEY 246 | ||
1655 | |||
1530 | #define BTRFS_BALANCE_ITEM_KEY 248 | 1656 | #define BTRFS_BALANCE_ITEM_KEY 248 |
1531 | 1657 | ||
1532 | /* | 1658 | /* |
@@ -2508,6 +2634,49 @@ static inline void btrfs_set_dev_stats_value(struct extent_buffer *eb, | |||
2508 | sizeof(val)); | 2634 | sizeof(val)); |
2509 | } | 2635 | } |
2510 | 2636 | ||
2637 | /* btrfs_qgroup_status_item */ | ||
2638 | BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item, | ||
2639 | generation, 64); | ||
2640 | BTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item, | ||
2641 | version, 64); | ||
2642 | BTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item, | ||
2643 | flags, 64); | ||
2644 | BTRFS_SETGET_FUNCS(qgroup_status_scan, struct btrfs_qgroup_status_item, | ||
2645 | scan, 64); | ||
2646 | |||
2647 | /* btrfs_qgroup_info_item */ | ||
2648 | BTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item, | ||
2649 | generation, 64); | ||
2650 | BTRFS_SETGET_FUNCS(qgroup_info_rfer, struct btrfs_qgroup_info_item, rfer, 64); | ||
2651 | BTRFS_SETGET_FUNCS(qgroup_info_rfer_cmpr, struct btrfs_qgroup_info_item, | ||
2652 | rfer_cmpr, 64); | ||
2653 | BTRFS_SETGET_FUNCS(qgroup_info_excl, struct btrfs_qgroup_info_item, excl, 64); | ||
2654 | BTRFS_SETGET_FUNCS(qgroup_info_excl_cmpr, struct btrfs_qgroup_info_item, | ||
2655 | excl_cmpr, 64); | ||
2656 | |||
2657 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_generation, | ||
2658 | struct btrfs_qgroup_info_item, generation, 64); | ||
2659 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer, struct btrfs_qgroup_info_item, | ||
2660 | rfer, 64); | ||
2661 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer_cmpr, | ||
2662 | struct btrfs_qgroup_info_item, rfer_cmpr, 64); | ||
2663 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl, struct btrfs_qgroup_info_item, | ||
2664 | excl, 64); | ||
2665 | BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl_cmpr, | ||
2666 | struct btrfs_qgroup_info_item, excl_cmpr, 64); | ||
2667 | |||
2668 | /* btrfs_qgroup_limit_item */ | ||
2669 | BTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item, | ||
2670 | flags, 64); | ||
2671 | BTRFS_SETGET_FUNCS(qgroup_limit_max_rfer, struct btrfs_qgroup_limit_item, | ||
2672 | max_rfer, 64); | ||
2673 | BTRFS_SETGET_FUNCS(qgroup_limit_max_excl, struct btrfs_qgroup_limit_item, | ||
2674 | max_excl, 64); | ||
2675 | BTRFS_SETGET_FUNCS(qgroup_limit_rsv_rfer, struct btrfs_qgroup_limit_item, | ||
2676 | rsv_rfer, 64); | ||
2677 | BTRFS_SETGET_FUNCS(qgroup_limit_rsv_excl, struct btrfs_qgroup_limit_item, | ||
2678 | rsv_excl, 64); | ||
2679 | |||
2511 | static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb) | 2680 | static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb) |
2512 | { | 2681 | { |
2513 | return sb->s_fs_info; | 2682 | return sb->s_fs_info; |
@@ -2703,6 +2872,8 @@ int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, | |||
2703 | int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range); | 2872 | int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range); |
2704 | 2873 | ||
2705 | int btrfs_init_space_info(struct btrfs_fs_info *fs_info); | 2874 | int btrfs_init_space_info(struct btrfs_fs_info *fs_info); |
2875 | int btrfs_delayed_refs_qgroup_accounting(struct btrfs_trans_handle *trans, | ||
2876 | struct btrfs_fs_info *fs_info); | ||
2706 | /* ctree.c */ | 2877 | /* ctree.c */ |
2707 | int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, | 2878 | int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, |
2708 | int level, int *slot); | 2879 | int level, int *slot); |
@@ -2753,6 +2924,9 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root | |||
2753 | ins_len, int cow); | 2924 | ins_len, int cow); |
2754 | int btrfs_search_old_slot(struct btrfs_root *root, struct btrfs_key *key, | 2925 | int btrfs_search_old_slot(struct btrfs_root *root, struct btrfs_key *key, |
2755 | struct btrfs_path *p, u64 time_seq); | 2926 | struct btrfs_path *p, u64 time_seq); |
2927 | int btrfs_search_slot_for_read(struct btrfs_root *root, | ||
2928 | struct btrfs_key *key, struct btrfs_path *p, | ||
2929 | int find_higher, int return_any); | ||
2756 | int btrfs_realloc_node(struct btrfs_trans_handle *trans, | 2930 | int btrfs_realloc_node(struct btrfs_trans_handle *trans, |
2757 | struct btrfs_root *root, struct extent_buffer *parent, | 2931 | struct btrfs_root *root, struct extent_buffer *parent, |
2758 | int start_slot, int cache_only, u64 *last_ret, | 2932 | int start_slot, int cache_only, u64 *last_ret, |
@@ -2835,11 +3009,22 @@ static inline void free_fs_info(struct btrfs_fs_info *fs_info) | |||
2835 | kfree(fs_info->chunk_root); | 3009 | kfree(fs_info->chunk_root); |
2836 | kfree(fs_info->dev_root); | 3010 | kfree(fs_info->dev_root); |
2837 | kfree(fs_info->csum_root); | 3011 | kfree(fs_info->csum_root); |
3012 | kfree(fs_info->quota_root); | ||
2838 | kfree(fs_info->super_copy); | 3013 | kfree(fs_info->super_copy); |
2839 | kfree(fs_info->super_for_commit); | 3014 | kfree(fs_info->super_for_commit); |
2840 | kfree(fs_info); | 3015 | kfree(fs_info); |
2841 | } | 3016 | } |
2842 | 3017 | ||
3018 | /* tree mod log functions from ctree.c */ | ||
3019 | u64 btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info, | ||
3020 | struct seq_list *elem); | ||
3021 | void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info, | ||
3022 | struct seq_list *elem); | ||
3023 | static inline u64 btrfs_inc_tree_mod_seq(struct btrfs_fs_info *fs_info) | ||
3024 | { | ||
3025 | return atomic_inc_return(&fs_info->tree_mod_seq); | ||
3026 | } | ||
3027 | |||
2843 | /* root-item.c */ | 3028 | /* root-item.c */ |
2844 | int btrfs_find_root_ref(struct btrfs_root *tree_root, | 3029 | int btrfs_find_root_ref(struct btrfs_root *tree_root, |
2845 | struct btrfs_path *path, | 3030 | struct btrfs_path *path, |
@@ -3198,17 +3383,49 @@ void btrfs_reada_detach(void *handle); | |||
3198 | int btree_readahead_hook(struct btrfs_root *root, struct extent_buffer *eb, | 3383 | int btree_readahead_hook(struct btrfs_root *root, struct extent_buffer *eb, |
3199 | u64 start, int err); | 3384 | u64 start, int err); |
3200 | 3385 | ||
3201 | /* delayed seq elem */ | 3386 | /* qgroup.c */ |
3202 | struct seq_list { | 3387 | struct qgroup_update { |
3203 | struct list_head list; | 3388 | struct list_head list; |
3204 | u64 seq; | 3389 | struct btrfs_delayed_ref_node *node; |
3205 | u32 flags; | 3390 | struct btrfs_delayed_extent_op *extent_op; |
3206 | }; | 3391 | }; |
3207 | 3392 | ||
3208 | void btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info, | 3393 | int btrfs_quota_enable(struct btrfs_trans_handle *trans, |
3209 | struct seq_list *elem); | 3394 | struct btrfs_fs_info *fs_info); |
3210 | void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info, | 3395 | int btrfs_quota_disable(struct btrfs_trans_handle *trans, |
3211 | struct seq_list *elem); | 3396 | struct btrfs_fs_info *fs_info); |
3397 | int btrfs_quota_rescan(struct btrfs_fs_info *fs_info); | ||
3398 | int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans, | ||
3399 | struct btrfs_fs_info *fs_info, u64 src, u64 dst); | ||
3400 | int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans, | ||
3401 | struct btrfs_fs_info *fs_info, u64 src, u64 dst); | ||
3402 | int btrfs_create_qgroup(struct btrfs_trans_handle *trans, | ||
3403 | struct btrfs_fs_info *fs_info, u64 qgroupid, | ||
3404 | char *name); | ||
3405 | int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, | ||
3406 | struct btrfs_fs_info *fs_info, u64 qgroupid); | ||
3407 | int btrfs_limit_qgroup(struct btrfs_trans_handle *trans, | ||
3408 | struct btrfs_fs_info *fs_info, u64 qgroupid, | ||
3409 | struct btrfs_qgroup_limit *limit); | ||
3410 | int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info); | ||
3411 | void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info); | ||
3412 | struct btrfs_delayed_extent_op; | ||
3413 | int btrfs_qgroup_record_ref(struct btrfs_trans_handle *trans, | ||
3414 | struct btrfs_delayed_ref_node *node, | ||
3415 | struct btrfs_delayed_extent_op *extent_op); | ||
3416 | int btrfs_qgroup_account_ref(struct btrfs_trans_handle *trans, | ||
3417 | struct btrfs_fs_info *fs_info, | ||
3418 | struct btrfs_delayed_ref_node *node, | ||
3419 | struct btrfs_delayed_extent_op *extent_op); | ||
3420 | int btrfs_run_qgroups(struct btrfs_trans_handle *trans, | ||
3421 | struct btrfs_fs_info *fs_info); | ||
3422 | int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, | ||
3423 | struct btrfs_fs_info *fs_info, u64 srcid, u64 objectid, | ||
3424 | struct btrfs_qgroup_inherit *inherit); | ||
3425 | int btrfs_qgroup_reserve(struct btrfs_root *root, u64 num_bytes); | ||
3426 | void btrfs_qgroup_free(struct btrfs_root *root, u64 num_bytes); | ||
3427 | |||
3428 | void assert_qgroups_uptodate(struct btrfs_trans_handle *trans); | ||
3212 | 3429 | ||
3213 | static inline int is_fstree(u64 rootid) | 3430 | static inline int is_fstree(u64 rootid) |
3214 | { | 3431 | { |