aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.h
diff options
context:
space:
mode:
authorChris Mason <chris.mason@fusionio.com>2012-07-25 16:11:38 -0400
committerChris Mason <chris.mason@fusionio.com>2012-07-25 16:11:38 -0400
commitb478b2baa37ac99fc04a30809c780dd5dfd43595 (patch)
treebed7af1466e5b1e0b0501eba18f77c804a864d7d /fs/btrfs/ctree.h
parent67c9684f48ea9cbc5e9b8a1feb3151800e9dcc22 (diff)
parent6f72c7e20dbaea55f04546de69586c84a3654503 (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.h233
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
908struct 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
928struct 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
944struct 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
886struct btrfs_space_info { 955struct 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 */
1103struct seq_list {
1104 struct list_head list;
1105 u64 seq;
1106};
1107
1108/* fs_info */
1033struct reloc_control; 1109struct reloc_control;
1034struct btrfs_device; 1110struct btrfs_device;
1035struct btrfs_fs_devices; 1111struct 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 */
2638BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item,
2639 generation, 64);
2640BTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item,
2641 version, 64);
2642BTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item,
2643 flags, 64);
2644BTRFS_SETGET_FUNCS(qgroup_status_scan, struct btrfs_qgroup_status_item,
2645 scan, 64);
2646
2647/* btrfs_qgroup_info_item */
2648BTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item,
2649 generation, 64);
2650BTRFS_SETGET_FUNCS(qgroup_info_rfer, struct btrfs_qgroup_info_item, rfer, 64);
2651BTRFS_SETGET_FUNCS(qgroup_info_rfer_cmpr, struct btrfs_qgroup_info_item,
2652 rfer_cmpr, 64);
2653BTRFS_SETGET_FUNCS(qgroup_info_excl, struct btrfs_qgroup_info_item, excl, 64);
2654BTRFS_SETGET_FUNCS(qgroup_info_excl_cmpr, struct btrfs_qgroup_info_item,
2655 excl_cmpr, 64);
2656
2657BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_generation,
2658 struct btrfs_qgroup_info_item, generation, 64);
2659BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer, struct btrfs_qgroup_info_item,
2660 rfer, 64);
2661BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer_cmpr,
2662 struct btrfs_qgroup_info_item, rfer_cmpr, 64);
2663BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl, struct btrfs_qgroup_info_item,
2664 excl, 64);
2665BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl_cmpr,
2666 struct btrfs_qgroup_info_item, excl_cmpr, 64);
2667
2668/* btrfs_qgroup_limit_item */
2669BTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item,
2670 flags, 64);
2671BTRFS_SETGET_FUNCS(qgroup_limit_max_rfer, struct btrfs_qgroup_limit_item,
2672 max_rfer, 64);
2673BTRFS_SETGET_FUNCS(qgroup_limit_max_excl, struct btrfs_qgroup_limit_item,
2674 max_excl, 64);
2675BTRFS_SETGET_FUNCS(qgroup_limit_rsv_rfer, struct btrfs_qgroup_limit_item,
2676 rsv_rfer, 64);
2677BTRFS_SETGET_FUNCS(qgroup_limit_rsv_excl, struct btrfs_qgroup_limit_item,
2678 rsv_excl, 64);
2679
2511static inline struct btrfs_fs_info *btrfs_sb(struct super_block *sb) 2680static 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,
2703int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range); 2872int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range);
2704 2873
2705int btrfs_init_space_info(struct btrfs_fs_info *fs_info); 2874int btrfs_init_space_info(struct btrfs_fs_info *fs_info);
2875int btrfs_delayed_refs_qgroup_accounting(struct btrfs_trans_handle *trans,
2876 struct btrfs_fs_info *fs_info);
2706/* ctree.c */ 2877/* ctree.c */
2707int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, 2878int 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);
2754int btrfs_search_old_slot(struct btrfs_root *root, struct btrfs_key *key, 2925int 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);
2927int 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);
2756int btrfs_realloc_node(struct btrfs_trans_handle *trans, 2930int 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 */
3019u64 btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info,
3020 struct seq_list *elem);
3021void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
3022 struct seq_list *elem);
3023static 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 */
2844int btrfs_find_root_ref(struct btrfs_root *tree_root, 3029int 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);
3198int btree_readahead_hook(struct btrfs_root *root, struct extent_buffer *eb, 3383int 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 */
3202struct seq_list { 3387struct 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
3208void btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info, 3393int btrfs_quota_enable(struct btrfs_trans_handle *trans,
3209 struct seq_list *elem); 3394 struct btrfs_fs_info *fs_info);
3210void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info, 3395int btrfs_quota_disable(struct btrfs_trans_handle *trans,
3211 struct seq_list *elem); 3396 struct btrfs_fs_info *fs_info);
3397int btrfs_quota_rescan(struct btrfs_fs_info *fs_info);
3398int btrfs_add_qgroup_relation(struct btrfs_trans_handle *trans,
3399 struct btrfs_fs_info *fs_info, u64 src, u64 dst);
3400int btrfs_del_qgroup_relation(struct btrfs_trans_handle *trans,
3401 struct btrfs_fs_info *fs_info, u64 src, u64 dst);
3402int btrfs_create_qgroup(struct btrfs_trans_handle *trans,
3403 struct btrfs_fs_info *fs_info, u64 qgroupid,
3404 char *name);
3405int btrfs_remove_qgroup(struct btrfs_trans_handle *trans,
3406 struct btrfs_fs_info *fs_info, u64 qgroupid);
3407int btrfs_limit_qgroup(struct btrfs_trans_handle *trans,
3408 struct btrfs_fs_info *fs_info, u64 qgroupid,
3409 struct btrfs_qgroup_limit *limit);
3410int btrfs_read_qgroup_config(struct btrfs_fs_info *fs_info);
3411void btrfs_free_qgroup_config(struct btrfs_fs_info *fs_info);
3412struct btrfs_delayed_extent_op;
3413int btrfs_qgroup_record_ref(struct btrfs_trans_handle *trans,
3414 struct btrfs_delayed_ref_node *node,
3415 struct btrfs_delayed_extent_op *extent_op);
3416int 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);
3420int btrfs_run_qgroups(struct btrfs_trans_handle *trans,
3421 struct btrfs_fs_info *fs_info);
3422int 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);
3425int btrfs_qgroup_reserve(struct btrfs_root *root, u64 num_bytes);
3426void btrfs_qgroup_free(struct btrfs_root *root, u64 num_bytes);
3427
3428void assert_qgroups_uptodate(struct btrfs_trans_handle *trans);
3212 3429
3213static inline int is_fstree(u64 rootid) 3430static inline int is_fstree(u64 rootid)
3214{ 3431{