Btrfs: subvolume quota groups (qgroups)
cover Btrfs: subvolume quota groups (qgroups)
This is a new version of Arne's qgroup patches from last October. The old patches didn't get the backref walking right, which is now based on the tree modification log.
You can limit the space available to subvolumes or any group of subvolumes. You can determine the amount of space that will get freed when deleting a snapshot.
The initial scan is still missing, so expect negative counters when you enable quotas on a non-empty volume and then delete stuff.
Arne's introduction and concept description can still be found at
http://sensille.com/qgroups.pdf
You can pull these patches from my git repository
git://git.jan-o-sch.net/btrfs-unstable qgroup
The user mode patches required were sent at October 11, 2011 by Arne, subject "[PATCH v0] btrfs-progs: add qgroup commands".
I tried to include some fair benchmark results with this cover letter. However, I tried several disk benchmarks from the phoronix test suite, none of them resulted in any write throughput decrease. I will have to create a more realistic setup on my own to benchmark the impact of qgroups (suggestions welcome). For now, I just wanted to get that patch set out :-)
Thanks,
-Jan
Arne Jansen (11):
Btrfs: qgroup on-disk format
Btrfs: add helper for tree enumeration
Btrfs: check the root passed to btrfs_end_transaction
Btrfs: added helper to create new trees
Btrfs: qgroup state and initialization
Btrfs: Test code to change the order of delayed-ref processing
Btrfs: qgroup implementation and prototypes
Btrfs: quota tree support and startup
Btrfs: hooks to reserve qgroup space
Btrfs: add qgroup ioctls
Btrfs: add qgroup inheritance
Jan Schmidt (4):
Btrfs: fix buffer leak in btrfs_next_old_leaf
Btrfs: join tree mod log code with the code holding back delayed refs
Btrfs: call the qgroup accounting functions
Btrfs: hooks for qgroup to record delayed refs
fs/btrfs/Makefile | 2 +- fs/btrfs/backref.c | 30 +- fs/btrfs/backref.h | 3 +- fs/btrfs/ctree.c | 348 ++++++++---- fs/btrfs/ctree.h | 233 +++++++- fs/btrfs/delayed-ref.c | 56 +- fs/btrfs/delayed-ref.h | 62 +-- fs/btrfs/disk-io.c | 134 ++++- fs/btrfs/disk-io.h | 6 + fs/btrfs/extent-tree.c | 119 ++++- fs/btrfs/ioctl.c | 244 +++++++- fs/btrfs/ioctl.h | 62 ++- fs/btrfs/qgroup.c | 1571 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/transaction.c | 57 ++- fs/btrfs/transaction.h | 11 + 15 files changed, 2696 insertions(+), 242 deletions(-) create mode 100644 fs/btrfs/qgroup.c
Signature · 1 line
1.7.3.4
PATCH 1/15 Btrfs: fix buffer leak in btrfs_next_old_leaf
When calling btrfs_next_old_leaf, we were leaking an extent buffer in the rare case of using the deadlock avoidance code needed for the tree mod log.
--- fs/btrfs/ctree.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/btrfs/ctree.c +1 -0
@@ -5127,6 +5127,7 @@ again:* locked. To solve this situation, we give up * on our lock and cycle. */ +free_extent_buffer (next);btrfs_release_path (path);cond_resched (); goto again;
Signature · 1 line
1.7.3.4
PATCH 2/15 Btrfs: join tree mod log code with the code holding back delayed refs
In reply to Jan SchmidtWe've got two mechanisms both required for reliable backref resolving (tree mod log and holding back delayed refs). You cannot make use of one without the other. So instead of requiring the user of this mechanism to setup both correctly, we join them into a single interface.
Additionally, we stop inserting non-blockers into fs_info->tree_mod_seq_list as we did before, which was of no value.
--- fs/btrfs/backref.c | 30 ++---- fs/btrfs/backref.h | 3 +- fs/btrfs/ctree.c | 275 ++++++++++++++++++++++++++++++------------------ fs/btrfs/ctree.h | 31 ++++-- fs/btrfs/delayed-ref.c | 44 ++++---- fs/btrfs/delayed-ref.h | 49 +-------- fs/btrfs/disk-io.c | 2 + fs/btrfs/extent-tree.c | 21 ++-- fs/btrfs/transaction.c | 4 - 9 files changed, 240 insertions(+), 219 deletions(-)
fs/btrfs/backref.c +9 -21
@@ -773,9 +773,8 @@ static int __add_keyed_refs(struct btrfs_fs_info *fs_info,*/ static int find_parent_nodes (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info,u64 bytenr, -u64 delayed_ref_seq,u64 time_seq, -struct ulist *refs,struct ulist *roots, -const u64 *extent_item_pos) +u64 time_seq,struct ulist *refs, +struct ulist *roots,const u64 *extent_item_pos) {struct btrfs_key key;struct btrfs_path *path;
@@ -837,7 +836,7 @@ again:btrfs_put_delayed_ref (&head->node); goto again; } - ret =__add_delayed_refs (head, delayed_ref_seq, + ret =__add_delayed_refs (head, time_seq, &prefs_delayed);mutex_unlock (&head->mutex);if (ret) {
@@ -981,8 +980,7 @@ static void free_leaf_list(struct ulist *blocks)*/ static int btrfs_find_all_leafs (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info,u64 bytenr, -u64 delayed_ref_seq,u64 time_seq, -struct ulist **leafs, +u64 time_seq,struct ulist **leafs,const u64 *extent_item_pos) {struct ulist *tmp;
@@ -997,7 +995,7 @@ static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans,return -ENOMEM ; } - ret =find_parent_nodes (trans, fs_info, bytenr, delayed_ref_seq, + ret =find_parent_nodes (trans, fs_info, bytenr, time_seq, *leafs, tmp, extent_item_pos);ulist_free (tmp);
@@ -1024,8 +1022,7 @@ static int btrfs_find_all_leafs(struct btrfs_trans_handle *trans,*/ int btrfs_find_all_roots (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info,u64 bytenr, -u64 delayed_ref_seq,u64 time_seq, -struct ulist **roots) +u64 time_seq,struct ulist **roots) {struct ulist *tmp;struct ulist_node *node =NULL ;
@@ -1043,7 +1040,7 @@ int btrfs_find_all_roots(struct btrfs_trans_handle *trans,ULIST_ITER_INIT (&uiter);while (1 ) { - ret =find_parent_nodes (trans, fs_info, bytenr, delayed_ref_seq, + ret =find_parent_nodes (trans, fs_info, bytenr, time_seq, tmp, *roots,NULL );if (ret <0 && ret != -ENOENT ) {ulist_free (tmp);
@@ -1376,11 +1373,9 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,struct ulist *roots =NULL ;struct ulist_node *ref_node =NULL ;struct ulist_node *root_node =NULL ; -struct seq_list seq_elem = {};struct seq_list tree_mod_seq_elem = {};struct ulist_iterator ref_uiter;struct ulist_iterator root_uiter; -struct btrfs_delayed_ref_root *delayed_refs =NULL ;pr_debug ("resolving all inodes for extent %llu\n" , extent_item_objectid);
@@ -1391,16 +1386,11 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info, trans =btrfs_join_transaction (fs_info->extent_root);if (IS_ERR (trans))return PTR_ERR (trans); - - delayed_refs = &trans->transaction->delayed_refs; -spin_lock (&delayed_refs->lock); -btrfs_get_delayed_seq (delayed_refs, &seq_elem); -spin_unlock (&delayed_refs->lock);btrfs_get_tree_mod_seq (fs_info, &tree_mod_seq_elem); } ret =btrfs_find_all_leafs (trans, fs_info, extent_item_objectid, - seq_elem.seq, tree_mod_seq_elem.seq, &refs, + tree_mod_seq_elem.seq, &refs, &extent_item_pos);if (ret) goto out;
@@ -1408,8 +1398,7 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,ULIST_ITER_INIT (&ref_uiter);while (!ret && (ref_node =ulist_next (refs, &ref_uiter))) { ret =btrfs_find_all_roots (trans, fs_info, ref_node->val, - seq_elem.seq, - tree_mod_seq_elem.seq, &roots); + tree_mod_seq_elem.seq, &roots);if (ret)break ;ULIST_ITER_INIT (&root_uiter);
@@ -1431,7 +1420,6 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info, out:if (!search_commit_root) {btrfs_put_tree_mod_seq (fs_info, &tree_mod_seq_elem); -btrfs_put_delayed_seq (delayed_refs, &seq_elem);btrfs_end_transaction (trans, fs_info->extent_root); }
fs/btrfs/backref.h +1 -2
@@ -58,8 +58,7 @@ int paths_from_inode(u64 inum, struct inode_fs_paths *ipath);int btrfs_find_all_roots (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info,u64 bytenr, -u64 delayed_ref_seq,u64 time_seq, -struct ulist **roots); +u64 time_seq,struct ulist **roots);struct btrfs_data_container *init_data_container (u32 total_bytes); struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root,
fs/btrfs/ctree.c +171 -104
493 lines not on this page · raw message
fs/btrfs/ctree.h +19 -12
@@ -1030,6 +1030,13 @@ struct btrfs_block_group_cache {struct list_head cluster_list; }; +/* delayed seq elem */ +struct seq_list { +struct list_head list; +u64 seq; +}; + +/* fs_info */ struct reloc_control ;struct btrfs_device ;struct btrfs_fs_devices ;
@@ -1144,6 +1151,8 @@ struct btrfs_fs_info {spinlock_t tree_mod_seq_lock;atomic_t tree_mod_seq;struct list_head tree_mod_seq_list; +struct seq_list tree_mod_seq_elem; +wait_queue_head_t tree_mod_seq_wait;/* this protects tree_mod_log */ rwlock_t tree_mod_log_lock;
@@ -2798,6 +2807,16 @@ static inline void free_fs_info(struct btrfs_fs_info *fs_info)kfree (fs_info); } +/* tree mod log functions from ctree.c */ +u64 btrfs_get_tree_mod_seq (struct btrfs_fs_info *fs_info, +struct seq_list *elem); +void btrfs_put_tree_mod_seq (struct btrfs_fs_info *fs_info, +struct seq_list *elem); +static inline u64 btrfs_inc_tree_mod_seq (struct btrfs_fs_info *fs_info) +{ +return atomic_inc_return (&fs_info->tree_mod_seq); +} +/* root-item.c */ int btrfs_find_root_ref(struct btrfs_root *tree_root, struct btrfs_path *path,
@@ -3157,18 +3176,6 @@ void btrfs_reada_detach(void *handle);int btree_readahead_hook (struct btrfs_root *root,struct extent_buffer *eb,u64 start,int err); -/* delayed seq elem */ -struct seq_list { -struct list_head list; -u64 seq; -u32 flags; -}; - -void btrfs_get_tree_mod_seq (struct btrfs_fs_info *fs_info, -struct seq_list *elem); -void btrfs_put_tree_mod_seq (struct btrfs_fs_info *fs_info, -struct seq_list *elem); -static inline int is_fstree (u64 rootid) { if (rootid == BTRFS_FS_TREE_OBJECTID ||
fs/btrfs/delayed-ref.c +24 -20
84 lines not on this page · raw message
fs/btrfs/delayed-ref.h +2 -47
61 lines not on this page · raw message
fs/btrfs/disk-io.c +2 -0
@@ -1944,6 +1944,8 @@ int open_ctree(struct super_block *sb, fs_info->free_chunk_space =0 ; fs_info->tree_mod_log =RB_ROOT ; +init_waitqueue_head (&fs_info->tree_mod_seq_wait); +/* readahead state */ INIT_RADIX_TREE (&fs_info->reada_tree,GFP_NOFS & ~__GFP_WAIT);spin_lock_init (&fs_info->reada_lock);
fs/btrfs/extent-tree.c +12 -9
@@ -2217,6 +2217,7 @@ static noinline int run_clustered_refs(struct btrfs_trans_handle *trans,struct btrfs_delayed_ref_node *ref;struct btrfs_delayed_ref_head *locked_ref =NULL ;struct btrfs_delayed_extent_op *extent_op; +struct btrfs_fs_info *fs_info = root->fs_info;int ret;int count =0 ;int must_insert_reserved =0 ;
@@ -2255,7 +2256,7 @@ static noinline int run_clustered_refs(struct btrfs_trans_handle *trans, ref =select_delayed_ref (locked_ref);if (ref && ref->seq && -btrfs_check_delayed_seq (delayed_refs, ref->seq)) { +btrfs_check_delayed_seq (fs_info, delayed_refs, ref->seq)) {/* * there are still refs with lower seq numbers in the * process of being added. Don't run this ref yet.
@@ -2337,7 +2338,7 @@ static noinline int run_clustered_refs(struct btrfs_trans_handle *trans, } next: -do_chunk_alloc (trans, root->fs_info->extent_root, +do_chunk_alloc (trans, fs_info->extent_root,2 *1024 *1024 ,btrfs_get_alloc_profile (root,0 ),CHUNK_ALLOC_NO_FORCE );
@@ -2347,18 +2348,19 @@ next:return count; } -static void wait_for_more_refs (struct btrfs_delayed_ref_root *delayed_refs, +static void wait_for_more_refs (struct btrfs_fs_info *fs_info, +struct btrfs_delayed_ref_root *delayed_refs,unsigned long num_refs,struct list_head *first_seq) {spin_unlock (&delayed_refs->lock);pr_debug ("waiting for more refs (num %ld, first %p)\n" , num_refs, first_seq); -wait_event (delayed_refs->seq_wait, +wait_event (fs_info->tree_mod_seq_wait, num_refs != delayed_refs->num_entries || - delayed_refs->seq_head.next != first_seq); + fs_info->tree_mod_seq_list.next != first_seq);pr_debug ("done waiting for more refs (num %ld, first %p)\n" , - delayed_refs->num_entries, delayed_refs->seq_head.next); + delayed_refs->num_entries, fs_info->tree_mod_seq_list.next);spin_lock (&delayed_refs->lock); }
@@ -2403,6 +2405,7 @@ int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, again: consider_waiting =0 ;spin_lock (&delayed_refs->lock); +if (count ==0 ) { count = delayed_refs->num_entries *2 ; run_most =1 ;
@@ -2437,7 +2440,7 @@ again: num_refs = delayed_refs->num_entries; first_seq = root->fs_info->tree_mod_seq_list.next; }else { -wait_for_more_refs (delayed_refs, +wait_for_more_refs (root->fs_info, delayed_refs, num_refs, first_seq);/* * after waiting, things have changed. we
@@ -5190,8 +5193,8 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans,rb_erase (&head->node.rb_node, &delayed_refs->root); delayed_refs->num_entries--; -if (waitqueue_active (&delayed_refs->seq_wait)) -wake_up (&delayed_refs->seq_wait); +if (waitqueue_active (&root->fs_info->tree_mod_seq_wait)) +wake_up (&root->fs_info->tree_mod_seq_wait);/* * we don't take a ref on the node because we're removing it from the
fs/btrfs/transaction.c +0 -4
@@ -38,7 +38,6 @@ void put_transaction(struct btrfs_transaction *transaction)if (atomic_dec_and_test (&transaction->use_count)) {BUG_ON (!list_empty (&transaction->list));WARN_ON (transaction->delayed_refs.root.rb_node); -WARN_ON (!list_empty (&transaction->delayed_refs.seq_head));memset (transaction,0 ,sizeof (*transaction));kmem_cache_free (btrfs_transaction_cachep, transaction); }
@@ -126,7 +125,6 @@ loop: cur_trans->delayed_refs.num_heads =0 ; cur_trans->delayed_refs.flushing =0 ; cur_trans->delayed_refs.run_delayed_start =0 ; - cur_trans->delayed_refs.seq =1 ;/* * although the tree mod log is per file system and not per transaction,
@@ -145,10 +143,8 @@ loop: }atomic_set (&fs_info->tree_mod_seq,0 ); -init_waitqueue_head (&cur_trans->delayed_refs.seq_wait);spin_lock_init (&cur_trans->commit_lock);spin_lock_init (&cur_trans->delayed_refs.lock); -INIT_LIST_HEAD (&cur_trans->delayed_refs.seq_head);INIT_LIST_HEAD (&cur_trans->pending_snapshots);list_add_tail (&cur_trans->list, &fs_info->trans_list);
Signature · 1 line
1.7.3.4
PATCH 3/15 Btrfs: qgroup on-disk format
In reply to Jan SchmidtFrom: Arne Jansen <[email protected]>
Not all features are in use by the current version and thus may change in the future.
--- fs/btrfs/ctree.h | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 136 insertions(+), 0 deletions(-)
fs/btrfs/ctree.h +136 -0
@@ -91,6 +91,9 @@ struct btrfs_ordered_sum;/* for storing balance parameters in the root tree */ #define BTRFS_BALANCE_OBJECTID -4ULL +/* holds quota configuration and tracking */ +#define BTRFS_QUOTA_TREE_OBJECTID 8ULL +/* orhpan objectid for tracking unlinked/truncated files */ #define BTRFS_ORPHAN_OBJECTID -5ULL
@@ -883,6 +886,72 @@ struct btrfs_block_group_item {__le64 flags; } __attribute__ ((__packed__)); +/* +* is subvolume quota turned on? +*/ +#define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0) +/* +* SCANNING is set during the initialization phase +*/ +#define BTRFS_QGROUP_STATUS_FLAG_SCANNING (1ULL << 1) +/* +* Some qgroup entries are known to be out of date, +* either because the configuration has changed in a way that +* makes a rescan necessary, or because the fs has been mounted +* with a non-qgroup-aware version. +* Turning qouta off and on again makes it inconsistent, too. +*/ +#define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2) + +#define BTRFS_QGROUP_STATUS_VERSION 1 + +struct btrfs_qgroup_status_item { +__le64 version; +/* +* the generation is updated during every commit. As older +* versions of btrfs are not aware of qgroups, it will be +* possible to detect inconsistencies by checking the +* generation on mount time +*/ +__le64 generation; + +/* flag definitions see above */ +__le64 flags; + +/* +* only used during scanning to record the progress +* of the scan. It contains a logical address +*/ +__le64 scan; +} __attribute__ ((__packed__ )); + +struct btrfs_qgroup_info_item { +__le64 generation; +__le64 rfer; +__le64 rfer_cmpr; +__le64 excl; +__le64 excl_cmpr; +} __attribute__ ((__packed__ )); + +/* flags definition for qgroup limits */ +#define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0) +#define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1) +#define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2) +#define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3) +#define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4) +#define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5) + +struct btrfs_qgroup_limit_item { +/* +* only updated when any of the other values change +*/ +__le64 flags; +__le64 max_rfer; +__le64 max_excl; +__le64 rsv_rfer; +__le64 rsv_excl; +} __attribute__ ((__packed__ )); +struct btrfs_space_info {u64 flags;
@@ -1534,6 +1603,30 @@ struct btrfs_ioctl_defrag_range_args {#define BTRFS_DEV_ITEM_KEY 216#define BTRFS_CHUNK_ITEM_KEY 228 +/* +* Records the overall state of the qgroups. +* There's only one instance of this key present, +* (0, BTRFS_QGROUP_STATUS_KEY, 0) +*/ +#define BTRFS_QGROUP_STATUS_KEY 240 +/* +* Records the currently used space of the qgroup. +* One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid). +*/ +#define BTRFS_QGROUP_INFO_KEY 242 +/* +* Contains the user configured limits for the qgroup. +* One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid). +*/ +#define BTRFS_QGROUP_LIMIT_KEY 244 +/* +* Records the child-parent relationship of qgroups. For +* each relation, 2 keys are present: +* (childid, BTRFS_QGROUP_RELATION_KEY, parentid) +* (parentid, BTRFS_QGROUP_RELATION_KEY, childid) +*/ +#define BTRFS_QGROUP_RELATION_KEY 246 +#define BTRFS_BALANCE_ITEM_KEY 248/*
@@ -2474,6 +2567,49 @@ static inline void btrfs_set_dev_stats_value(struct extent_buffer *eb, sizeof(val)); } +/* btrfs_qgroup_status_item */ +BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item, + generation,64 ); +BTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item, + version,64 ); +BTRFS_SETGET_FUNCS(qgroup_status_flags, struct btrfs_qgroup_status_item, + flags,64 ); +BTRFS_SETGET_FUNCS(qgroup_status_scan, struct btrfs_qgroup_status_item, + scan,64 ); + +/* btrfs_qgroup_info_item */ +BTRFS_SETGET_FUNCS(qgroup_info_generation, struct btrfs_qgroup_info_item, + generation,64 ); +BTRFS_SETGET_FUNCS(qgroup_info_rfer, struct btrfs_qgroup_info_item, rfer, 64); +BTRFS_SETGET_FUNCS(qgroup_info_rfer_cmpr, struct btrfs_qgroup_info_item, + rfer_cmpr,64 ); +BTRFS_SETGET_FUNCS(qgroup_info_excl, struct btrfs_qgroup_info_item, excl, 64); +BTRFS_SETGET_FUNCS(qgroup_info_excl_cmpr, struct btrfs_qgroup_info_item, + excl_cmpr,64 ); + +BTRFS_SETGET_STACK_FUNCS (stack_qgroup_info_generation, + struct btrfs_qgroup_info_item, generation, 64); +BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_rfer, struct btrfs_qgroup_info_item, + rfer,64 ); +BTRFS_SETGET_STACK_FUNCS (stack_qgroup_info_rfer_cmpr, + struct btrfs_qgroup_info_item, rfer_cmpr, 64); +BTRFS_SETGET_STACK_FUNCS(stack_qgroup_info_excl, struct btrfs_qgroup_info_item, + excl,64 ); +BTRFS_SETGET_STACK_FUNCS (stack_qgroup_info_excl_cmpr, + struct btrfs_qgroup_info_item, excl_cmpr, 64); + +/* btrfs_qgroup_limit_item */ +BTRFS_SETGET_FUNCS(qgroup_limit_flags, struct btrfs_qgroup_limit_item, + flags,64 ); +BTRFS_SETGET_FUNCS(qgroup_limit_max_rfer, struct btrfs_qgroup_limit_item, + max_rfer,64 ); +BTRFS_SETGET_FUNCS(qgroup_limit_max_excl, struct btrfs_qgroup_limit_item, + max_excl,64 ); +BTRFS_SETGET_FUNCS(qgroup_limit_rsv_rfer, struct btrfs_qgroup_limit_item, + rsv_rfer,64 ); +BTRFS_SETGET_FUNCS(qgroup_limit_rsv_excl, struct btrfs_qgroup_limit_item, + rsv_excl,64 ); +static inline struct btrfs_fs_info *btrfs_sb (struct super_block *sb) {return sb->s_fs_info;
Signature · 1 line
1.7.3.4
PATCH 4/15 Btrfs: add helper for tree enumeration
In reply to Jan SchmidtFrom: Arne Jansen <[email protected]>
Often no exact match is wanted but just the next lower or higher item. There's a lot of duplicated code throughout btrfs to deal with the corner cases. This patch adds a helper function that can facilitate searching.
--- fs/btrfs/ctree.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/ctree.h | 3 ++ 2 files changed, 75 insertions(+), 0 deletions(-)
fs/btrfs/ctree.c +72 -0
@@ -2789,6 +2789,78 @@ done: }/* +* helper to use instead of search slot if no exact match is needed but +* instead the next or previous item should be returned. +* When find_higher is true, the next higher item is returned, the next lower +* otherwise. +* When return_any and find_higher are both true, and no higher item is found, +* return the next lower instead. +* When return_any is true and find_higher is false, and no lower item is found, +* return the next higher instead. +* It returns 0 if any item is found, 1 if none is found (tree empty), and +* < 0 on error +*/ +int btrfs_search_slot_for_read (struct btrfs_root *root, +struct btrfs_key *key,struct btrfs_path *p, +int find_higher,int return_any) +{ +int ret; +struct extent_buffer *leaf; + +again: + ret =btrfs_search_slot (NULL , root, key, p,0 ,0 ); +if (ret <=0 ) +return ret; +/* +* a return value of 1 means the path is at the position where the +* item should be inserted. Normally this is the next bigger item, +* but in case the previous item is the last in a leaf, path points +* to the first free slot in the previous leaf, i.e. at an invalid +* item. +*/ + leaf = p->nodes[0 ]; + +if (find_higher) { +if (p->slots[0 ] >=btrfs_header_nritems (leaf)) { + ret =btrfs_next_leaf (root, p); +if (ret <=0 ) +return ret; +if (!return_any) +return 1 ; +/* +* no higher item found, return the next +* lower instead +*/ + return_any =0 ; + find_higher =0 ; +btrfs_release_path (p); + goto again; + } + }else { +if (p->slots[0 ] >=btrfs_header_nritems (leaf)) { +/* we're sitting on an invalid slot */ +if (p->slots[0 ] ==0 ) { + ret =btrfs_prev_leaf (root, p); +if (ret <=0 ) +return ret; +if (!return_any) +return 1 ; +/* +* no lower item found, return the next +* higher instead +*/ + return_any =0 ; + find_higher =1 ; +btrfs_release_path (p); + goto again; + } + --p->slots[0 ]; + } + } +return 0 ; +} + +/* * adjust the pointers going up the tree, starting at level * making sure the right key of each node is points to 'key'. * This is used after shifting pointers to the left, so it stops
fs/btrfs/ctree.h +3 -0
@@ -2856,6 +2856,9 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root ins_len, int cow);int btrfs_search_old_slot (struct btrfs_root *root,struct btrfs_key *key,struct btrfs_path *p,u64 time_seq); +int btrfs_search_slot_for_read (struct btrfs_root *root, +struct btrfs_key *key,struct btrfs_path *p, +int find_higher,int return_any); int btrfs_realloc_node(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *parent, int start_slot, int cache_only, u64 *last_ret,
Signature · 1 line
1.7.3.4
Re: [PATCH v1 04/15] Btrfs: add helper for tree enumeration
Quoted 8 lines · Jan Schmidt
From: Arne Jansen <[email protected]>
Often no exact match is wanted but just the next lower or higher item. There's a lot of duplicated code throughout btrfs to deal with the corner cases. This patch adds a helper function that can facilitate searching.
Signed-off-by Arne Jansen <[email protected]>
Hmm, I'm very sorry but my btrfs send/receive patchset has created some conflicts here. I had to fix the find_higher=0 case in this patch as it was not decrementing the slot at the right time. I changed the original patch from Arne and hoped that Jan and Arne would take that fixed version. I should have waited for an ACK from both, but instead forgot about communicating it properly and posted it. I'm not sure how to proceed now...asking for advise.
The version of the patch that I posted:
http://article.gmane.org/gmane.comp.file-systems.btrfs/18451
PATCH 5/15 Btrfs: check the root passed to btrfs_end_transaction
In reply to Jan SchmidtFrom: Arne Jansen <[email protected]>
This patch only add a consistancy check to validate that the same root is passed to start_transaction and end_transaction. Subvolume quota depends on this.
--- fs/btrfs/transaction.c | 6 ++++++ fs/btrfs/transaction.h | 6 ++++++ 2 files changed, 12 insertions(+), 0 deletions(-)
fs/btrfs/transaction.c +6 -0
@@ -345,6 +345,7 @@ again: h->transaction = cur_trans; h->blocks_used =0 ; h->bytes_reserved =0 ; + h->root = root; h->delayed_ref_updates =0 ; h->use_count =1 ; h->block_rsv =NULL ;
@@ -511,6 +512,11 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,btrfs_trans_release_metadata (trans, root); trans->block_rsv =NULL ; +/* +* the same root has to be passed to start_transaction and +* end_transaction. Subvolume quota depends on this. +*/ +WARN_ON (trans->root != root);while (count <2 ) {unsigned long cur = trans->delayed_ref_updates; trans->delayed_ref_updates =0 ;
fs/btrfs/transaction.h +6 -0
@@ -57,6 +57,12 @@ struct btrfs_trans_handle {struct btrfs_block_rsv *block_rsv;struct btrfs_block_rsv *orig_rsv;int aborted; +/* +* this root is only needed to validate that the root passed to +* start_transaction is the same as the one passed to end_transaction. +* Subvolume quota depends on this +*/ +struct btrfs_root *root; };struct btrfs_pending_snapshot {
Signature · 1 line
1.7.3.4
PATCH 6/15 Btrfs: added helper to create new trees
In reply to Jan SchmidtFrom: Arne Jansen <[email protected]>
This creates a brand new tree. Will be used to create the quota tree.
--- fs/btrfs/disk-io.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++- fs/btrfs/disk-io.h | 6 ++++ 2 files changed, 83 insertions(+), 1 deletions(-)
fs/btrfs/disk-io.c +77 -1
@@ -1225,6 +1225,82 @@ static struct btrfs_root *btrfs_alloc_root(struct btrfs_fs_info *fs_info)return root; } +struct btrfs_root *btrfs_create_tree (struct btrfs_trans_handle *trans, +struct btrfs_fs_info *fs_info, +u64 objectid) +{ +struct extent_buffer *leaf; +struct btrfs_root *tree_root = fs_info->tree_root; +struct btrfs_root *root; +struct btrfs_key key; +int ret =0 ; +u64 bytenr; + + root =btrfs_alloc_root (fs_info); +if (!root) +return ERR_PTR (-ENOMEM ); + +__setup_root (tree_root->nodesize, tree_root->leafsize, + tree_root->sectorsize, tree_root->stripesize, + root, fs_info, objectid); + root->root_key.objectid = objectid; + root->root_key.type =BTRFS_ROOT_ITEM_KEY ; + root->root_key.offset =0 ; + + leaf =btrfs_alloc_free_block (trans, root, root->leafsize, +0 , objectid,NULL ,0 ,0 ,0 ); +if (IS_ERR (leaf)) { + ret =PTR_ERR (leaf); + goto fail; + } + + bytenr = leaf->start; +memset_extent_buffer (leaf,0 ,0 ,sizeof (struct btrfs_header )); +btrfs_set_header_bytenr (leaf, leaf->start); +btrfs_set_header_generation (leaf, trans->transid); +btrfs_set_header_backref_rev (leaf,BTRFS_MIXED_BACKREF_REV ); +btrfs_set_header_owner (leaf, objectid); + root->node = leaf; + +write_extent_buffer (leaf, fs_info->fsid, + (unsigned long )btrfs_header_fsid (leaf), +BTRFS_FSID_SIZE ); +write_extent_buffer (leaf, fs_info->chunk_tree_uuid, + (unsigned long )btrfs_header_chunk_tree_uuid (leaf), +BTRFS_UUID_SIZE ); +btrfs_mark_buffer_dirty (leaf); + + root->commit_root =btrfs_root_node (root); + root->track_dirty =1 ; + + + root->root_item.flags =0 ; + root->root_item.byte_limit =0 ; +btrfs_set_root_bytenr (&root->root_item, leaf->start); +btrfs_set_root_generation (&root->root_item, trans->transid); +btrfs_set_root_level (&root->root_item,0 ); +btrfs_set_root_refs (&root->root_item,1 ); +btrfs_set_root_used (&root->root_item, leaf->len); +btrfs_set_root_last_snapshot (&root->root_item,0 ); +btrfs_set_root_dirid (&root->root_item,0 ); + root->root_item.drop_level =0 ; + + key.objectid = objectid; + key.type =BTRFS_ROOT_ITEM_KEY ; + key.offset =0 ; + ret =btrfs_insert_root (trans, tree_root, &key, &root->root_item); +if (ret) + goto fail; + +btrfs_tree_unlock (leaf); + +fail: +if (ret) +return ERR_PTR (ret); + +return root; +} +static struct btrfs_root *alloc_log_tree (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info) {
@@ -3260,7 +3336,7 @@ int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid)return btree_read_extent_buffer_pages (root, buf,0 , parent_transid); } -static int btree_lock_page_hook (struct page *page,void *data, +int btree_lock_page_hook (struct page *page,void *data,void (*flush_fn)(void *)) {struct inode *inode = page->mapping->host;
fs/btrfs/disk-io.h +6 -0
@@ -89,6 +89,12 @@ int btrfs_add_log_tree(struct btrfs_trans_handle *trans,int btrfs_cleanup_transaction (struct btrfs_root *root);void btrfs_cleanup_one_transaction (struct btrfs_transaction *trans,struct btrfs_root *root); +void btrfs_abort_devices (struct btrfs_root *root); +struct btrfs_root *btrfs_create_tree (struct btrfs_trans_handle *trans, +struct btrfs_fs_info *fs_info, +u64 objectid); +int btree_lock_page_hook (struct page *page,void *data, +void (*flush_fn)(void *));#ifdef CONFIG_DEBUG_LOCK_ALLOC void btrfs_init_lockdep (void );
Signature · 1 line
1.7.3.4
PATCH 7/15 Btrfs: qgroup state and initialization
In reply to Jan SchmidtFrom: Arne Jansen <[email protected]>
Add state to fs_info.
--- fs/btrfs/ctree.h | 24 ++++++++++++++++++++++++ fs/btrfs/disk-io.c | 7 +++++++ 2 files changed, 31 insertions(+), 0 deletions(-)
fs/btrfs/ctree.h +24 -0
@@ -1120,6 +1120,7 @@ struct btrfs_fs_info {struct btrfs_root *dev_root;struct btrfs_root *fs_root;struct btrfs_root *csum_root; +struct btrfs_root *quota_root;/* the log root tree is a directory of all the other log roots */ struct btrfs_root *log_root_tree;
@@ -1374,6 +1375,29 @@ struct btrfs_fs_info {#ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY u32 check_integrity_print_mask;#endif +/* +* quota information +*/ + unsigned int quota_enabled:1; + +/* +* quota_enabled only changes state after a commit. This holds the +* next state. +*/ + unsigned int pending_quota_state:1; + +/* is qgroup tracking in a consistent state? */ +u64 qgroup_flags; + +/* holds configuration and tracking. Protected by qgroup_lock */ +struct rb_root qgroup_tree; +spinlock_t qgroup_lock; + +/* list of dirty qgroups to be written at next commit */ +struct list_head dirty_qgroups; + +/* used by btrfs_qgroup_record_ref for an efficient tree traversal */ +u64 qgroup_seq;/* filesystem state */ u64 fs_state;
fs/btrfs/disk-io.c +7 -0
@@ -2110,6 +2110,13 @@ int open_ctree(struct super_block *sb,init_rwsem (&fs_info->cleanup_work_sem);init_rwsem (&fs_info->subvol_sem); +spin_lock_init (&fs_info->qgroup_lock); + fs_info->qgroup_tree =RB_ROOT ; +INIT_LIST_HEAD (&fs_info->dirty_qgroups); + fs_info->qgroup_seq =1 ; + fs_info->quota_enabled =0 ; + fs_info->pending_quota_state =0 ; +btrfs_init_free_cluster (&fs_info->meta_alloc_cluster);btrfs_init_free_cluster (&fs_info->data_alloc_cluster);
Signature · 1 line
1.7.3.4
PATCH 8/15 Btrfs: Test code to change the order of delayed-ref processing
In reply to Jan SchmidtFrom: Arne Jansen <[email protected]>
Normally delayed refs get processed in ascending bytenr order. This correlates in most cases to the order added. To expose dependencies on this order, we start to process the tree in the middle instead of the beginning.
This code is only effective when SCRAMBLE_DELAYED_REFS is defined.
--- fs/btrfs/extent-tree.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 49 insertions(+), 0 deletions(-)
fs/btrfs/extent-tree.c +49 -0
@@ -34,6 +34,8 @@#include "locking.h" #include "free-space-cache.h" +#undef SCRAMBLE_DELAYED_REFS +/* * control flags for do_chunk_alloc's force field * CHUNK_ALLOC_NO_FORCE means to only allocate a chunk
@@ -2364,6 +2366,49 @@ static void wait_for_more_refs(struct btrfs_fs_info *fs_info,spin_lock (&delayed_refs->lock); } +#ifdef SCRAMBLE_DELAYED_REFS +/* +* Normally delayed refs get processed in ascending bytenr order. This +* correlates in most cases to the order added. To expose dependencies on this +* order, we start to process the tree in the middle instead of the beginning +*/ +static u64 find_middle (struct rb_root *root) +{ +struct rb_node *n = root->rb_node; +struct btrfs_delayed_ref_node *entry; +int alt =1 ; +u64 middle; +u64 first =0 , last =0 ; + + n =rb_first (root); +if (n) { + entry = rb_entry(n, struct btrfs_delayed_ref_node, rb_node); + first = entry->bytenr; + } + n =rb_last (root); +if (n) { + entry = rb_entry(n, struct btrfs_delayed_ref_node, rb_node); + last = entry->bytenr; + } + n = root->rb_node; + +while (n) { + entry = rb_entry(n, struct btrfs_delayed_ref_node, rb_node); +WARN_ON (!entry->in_tree); + + middle = entry->bytenr; + +if (alt) + n = n->rb_left; +else + n = n->rb_right; + + alt =1 - alt; + } +return middle; +} +#endif +/* * this starts processing the delayed reference count updates and * extent insertions we have queued up so far. count can be
@@ -2406,6 +2451,10 @@ again: consider_waiting =0 ;spin_lock (&delayed_refs->lock); +#ifdef SCRAMBLE_DELAYED_REFS + delayed_refs->run_delayed_start =find_middle (&delayed_refs->root); +#endif +if (count ==0 ) { count = delayed_refs->num_entries *2 ; run_most =1 ;
Signature · 1 line
1.7.3.4
PATCH 9/15 Btrfs: qgroup implementation and prototypes
In reply to Jan SchmidtFrom: Arne Jansen <[email protected]>
--- fs/btrfs/Makefile | 2 +- fs/btrfs/ctree.h | 46 ++ fs/btrfs/extent-tree.c | 34 + fs/btrfs/ioctl.h | 24 + fs/btrfs/qgroup.c | 1571 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/transaction.c | 2 + fs/btrfs/transaction.h | 3 + 7 files changed, 1681 insertions(+), 1 deletions(-) create mode 100644 fs/btrfs/qgroup.c
fs/btrfs/Makefile +1 -1
@@ -8,7 +8,7 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \ extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \ export.o tree-log.o free-space-cache.o zlib.o lzo.o \ compression.o delayed-ref.o relocation.o delayed-inode.o scrub.o \ - reada.o backref.o ulist.o + reada.o backref.o ulist.o qgroup.o btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
fs/btrfs/ctree.h +46 -0
58 lines not on this page · raw message
fs/btrfs/extent-tree.c +34 -0
@@ -2409,6 +2409,40 @@ static u64 find_middle(struct rb_root *root) }#endif +int btrfs_delayed_refs_qgroup_accounting (struct btrfs_trans_handle *trans, +struct btrfs_fs_info *fs_info) +{ +struct qgroup_update *qgroup_update; +int ret =0 ; + +if (list_empty (&trans->qgroup_ref_list) != + !trans->delayed_ref_elem.seq) { +/* list without seq or seq without list */ +printk (KERN_ERR "btrfs: qgroup accounting update error, list is%s empty, seq is %llu\n" , +list_empty (&trans->qgroup_ref_list) ?"" :" not" , + trans->delayed_ref_elem.seq); +BUG (); + } + +if (!trans->delayed_ref_elem.seq) +return 0 ; + +while (!list_empty (&trans->qgroup_ref_list)) { + qgroup_update =list_first_entry (&trans->qgroup_ref_list, + struct qgroup_update, list); +list_del (&qgroup_update->list); +if (!ret) + ret =btrfs_qgroup_account_ref ( + trans, fs_info, qgroup_update->node, + qgroup_update->extent_op); +kfree (qgroup_update); + } + +btrfs_put_tree_mod_seq (fs_info, &trans->delayed_ref_elem); + +return ret; +} +/* * this starts processing the delayed reference count updates and * extent insertions we have queued up so far. count can be
fs/btrfs/ioctl.h +24 -0
@@ -35,6 +35,30 @@ struct btrfs_ioctl_vol_args {#define BTRFS_FSID_SIZE 16#define BTRFS_UUID_SIZE 16 +#define BTRFS_QGROUP_INHERIT_SET_LIMITS (1ULL << 0) + +struct btrfs_qgroup_limit { +__u64 flags; +__u64 max_rfer; +__u64 max_excl; +__u64 rsv_rfer; +__u64 rsv_excl; +}; + +struct btrfs_qgroup_inherit { +__u64 flags; +__u64 num_qgroups; +__u64 num_ref_copies; +__u64 num_excl_copies; +struct btrfs_qgroup_limit lim; +__u64 qgroups[0 ]; +}; + +struct btrfs_ioctl_qgroup_limit_args { +__u64 qgroupid; +struct btrfs_qgroup_limit lim; +}; +#define BTRFS_SUBVOL_NAME_MAX 4039struct btrfs_ioctl_vol_args_v2 {__s64 fd;
fs/btrfs/qgroup.c new file +1571 -0
1,571 lines not on this page · raw message
fs/btrfs/transaction.c +2 -0
@@ -351,6 +351,8 @@ again: h->block_rsv =NULL ; h->orig_rsv =NULL ; h->aborted =0 ; + h->delayed_ref_elem.seq =0 ; +INIT_LIST_HEAD (&h->qgroup_ref_list);smp_mb ();if (cur_trans->blocked &&may_wait_transaction (root, type)) {
fs/btrfs/transaction.h +3 -0
@@ -20,6 +20,7 @@#define __BTRFS_TRANSACTION__#include "btrfs_inode.h" #include "delayed-ref.h" +#include "ctree.h" struct btrfs_transaction {u64 transid;
@@ -63,6 +64,8 @@ struct btrfs_trans_handle {* Subvolume quota depends on this */ struct btrfs_root *root; +struct seq_list delayed_ref_elem; +struct list_head qgroup_ref_list; };struct btrfs_pending_snapshot {
Signature · 1 line
1.7.3.4
PATCH 10/15 Btrfs: call the qgroup accounting functions
In reply to Jan Schmidt--- fs/btrfs/extent-tree.c | 3 +++ fs/btrfs/transaction.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-)
fs/btrfs/extent-tree.c +3 -0
@@ -2479,6 +2479,8 @@ int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,2 *1024 *1024 ,btrfs_get_alloc_profile (root,0 ), CHUNK_ALLOC_NO_FORCE); +btrfs_delayed_refs_qgroup_accounting (trans, root->fs_info); + delayed_refs = &trans->transaction->delayed_refs;INIT_LIST_HEAD (&cluster); again:
@@ -2588,6 +2590,7 @@ again: } out:spin_unlock (&delayed_refs->lock); +assert_qgroups_uptodate (trans);return 0 ; }
fs/btrfs/transaction.c +14 -0
@@ -512,6 +512,11 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,return 0 ; } +/* +* do the qgroup accounting as early as possible +*/ + err =btrfs_delayed_refs_qgroup_accounting (trans, info); +btrfs_trans_release_metadata (trans, root); trans->block_rsv =NULL ;/*
@@ -571,6 +576,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, root->fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) { err = -EIO ; } +assert_qgroups_uptodate (trans);memset (trans,0 ,sizeof (*trans));kmem_cache_free (btrfs_trans_handle_cachep, trans);
@@ -1356,6 +1362,13 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, goto cleanup_transaction;/* +* running the delayed items may have added new refs. account +* them now so that they hinder processing of more delayed refs +* as little as possible. +*/ +btrfs_delayed_refs_qgroup_accounting (trans, root->fs_info); + +/* * rename don't use btrfs_join_transaction, so, once we * set the transaction to blocked above, we aren't going * to get any new ordered operations. We can safely run
@@ -1467,6 +1480,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, root->fs_info->chunk_root->node);switch_commit_root (root->fs_info->chunk_root); +assert_qgroups_uptodate (trans);update_super_roots (root);if (!root->fs_info->log_root_recovering) {
Signature · 1 line
1.7.3.4
PATCH 11/15 Btrfs: quota tree support and startup
In reply to Jan SchmidtFrom: Arne Jansen <[email protected]>
Init the quota tree along with the others on open_ctree and close_ctree. Add the quota tree to the list of well known trees in btrfs_read_fs_root_no_name.
--- fs/btrfs/ctree.h | 1 + fs/btrfs/disk-io.c | 47 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 6 deletions(-)
fs/btrfs/ctree.h +1 -0
@@ -2967,6 +2967,7 @@ static inline void free_fs_info(struct btrfs_fs_info *fs_info)kfree (fs_info->chunk_root);kfree (fs_info->dev_root);kfree (fs_info->csum_root); +kfree (fs_info->quota_root);kfree (fs_info->super_copy);kfree (fs_info->super_for_commit);kfree (fs_info);
fs/btrfs/disk-io.c +41 -6
135 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 12/15 Btrfs: hooks for qgroup to record delayed refs
In reply to Jan SchmidtHooks into qgroup code to record refs and into transaction commit. This is the main entry point for qgroup. Basically every change in extent backrefs got accounted to the appropriate qgroups.
--- fs/btrfs/delayed-ref.c | 16 ++++++++++------ fs/btrfs/delayed-ref.h | 19 +++++++++++++++++++ fs/btrfs/transaction.c | 7 +++++++ 3 files changed, 36 insertions(+), 6 deletions(-)
fs/btrfs/delayed-ref.c +10 -6
@@ -529,8 +529,8 @@ static noinline void add_delayed_tree_ref(struct btrfs_fs_info *fs_info, ref->is_head =0 ; ref->in_tree =1 ; -if (is_fstree (ref_root)) - seq =btrfs_inc_tree_mod_seq (fs_info); +if (need_ref_seq (for_cow, ref_root)) + seq =btrfs_get_tree_mod_seq (fs_info, &trans->delayed_ref_elem); ref->seq = seq; full_ref =btrfs_delayed_node_to_tree_ref (ref);
@@ -588,8 +588,8 @@ static noinline void add_delayed_data_ref(struct btrfs_fs_info *fs_info, ref->is_head =0 ; ref->in_tree =1 ; -if (is_fstree (ref_root)) - seq =btrfs_inc_tree_mod_seq (fs_info); +if (need_ref_seq (for_cow, ref_root)) + seq =btrfs_get_tree_mod_seq (fs_info, &trans->delayed_ref_elem); ref->seq = seq; full_ref =btrfs_delayed_node_to_data_ref (ref);
@@ -662,10 +662,12 @@ int btrfs_add_delayed_tree_ref(struct btrfs_fs_info *fs_info,add_delayed_tree_ref (fs_info, trans, &ref->node, bytenr, num_bytes, parent, ref_root, level, action, for_cow); -if (!is_fstree (ref_root) && +if (!need_ref_seq (for_cow, ref_root) &&waitqueue_active (&fs_info->tree_mod_seq_wait))wake_up (&fs_info->tree_mod_seq_wait);spin_unlock (&delayed_refs->lock); +if (need_ref_seq (for_cow, ref_root)) +btrfs_qgroup_record_ref (trans, &ref->node, extent_op);return 0 ; }
@@ -711,10 +713,12 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,add_delayed_data_ref (fs_info, trans, &ref->node, bytenr, num_bytes, parent, ref_root, owner, offset, action, for_cow); -if (!is_fstree (ref_root) && +if (!need_ref_seq (for_cow, ref_root) &&waitqueue_active (&fs_info->tree_mod_seq_wait))wake_up (&fs_info->tree_mod_seq_wait);spin_unlock (&delayed_refs->lock); +if (need_ref_seq (for_cow, ref_root)) +btrfs_qgroup_record_ref (trans, &ref->node, extent_op);return 0 ; }
fs/btrfs/delayed-ref.h +19 -0
@@ -180,6 +180,25 @@ int btrfs_check_delayed_seq(struct btrfs_fs_info *fs_info, u64 seq);/* +* delayed refs with a ref_seq > 0 must be held back during backref walking. +* this only applies to items in one of the fs-trees. for_cow items never need +* to be held back, so they won't get a ref_seq number. +*/ +static inline int need_ref_seq (int for_cow,u64 rootid) +{ +if (for_cow) +return 0 ; + +if (rootid ==BTRFS_FS_TREE_OBJECTID ) +return 1 ; + +if ((s64 )rootid >= (s64 )BTRFS_FIRST_FREE_OBJECTID ) +return 1 ; + +return 0 ; +} + +/* * a node might live in a head or a regular ref, this lets you * test for the proper type to use. */
fs/btrfs/transaction.c +7 -0
@@ -795,6 +795,13 @@ static noinline int commit_cowonly_roots(struct btrfs_trans_handle *trans, ret =btrfs_run_dev_stats (trans, root->fs_info);BUG_ON (ret); + ret =btrfs_run_qgroups (trans, root->fs_info); +BUG_ON (ret); + +/* run_qgroups might have added some more refs */ + ret =btrfs_run_delayed_refs (trans, root, (unsigned long )-1 ); +BUG_ON (ret); +while (!list_empty (&fs_info->dirty_cowonly_roots)) { next = fs_info->dirty_cowonly_roots.next;list_del_init (next);
Signature · 1 line
1.7.3.4
PATCH 13/15 Btrfs: hooks to reserve qgroup space
In reply to Jan SchmidtFrom: Arne Jansen <[email protected]>
Like block reserves, reserve a small piece of space on each transaction start and for delalloc. These are the hooks that can actually return EDQUOT to the user.
The amount of space reserved is tracked in the transaction handle.
--- fs/btrfs/extent-tree.c | 12 ++++++++++++ fs/btrfs/transaction.c | 16 ++++++++++++++++ fs/btrfs/transaction.h | 1 + 3 files changed, 29 insertions(+), 0 deletions(-)
fs/btrfs/extent-tree.c +12 -0
@@ -4565,6 +4565,13 @@ int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes) csum_bytes =BTRFS_I (inode)->csum_bytes;spin_unlock (&BTRFS_I (inode)->lock); +if (root->fs_info->quota_enabled) { + ret =btrfs_qgroup_reserve (root, num_bytes + + nr_extents * root->leafsize); +if (ret) +return ret; + } + ret =reserve_metadata_bytes (root, block_rsv, to_reserve, flush);if (ret) {u64 to_free =0 ;
@@ -4643,6 +4650,11 @@ void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes)trace_btrfs_space_reservation (root->fs_info,"delalloc" ,btrfs_ino (inode), to_free,0 ); +if (root->fs_info->quota_enabled) { +btrfs_qgroup_free (root, num_bytes + + dropped * root->leafsize); + } +btrfs_block_rsv_release (root, &root->fs_info->delalloc_block_rsv, to_free); }
fs/btrfs/transaction.c +16 -0
@@ -295,6 +295,7 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,struct btrfs_transaction *cur_trans;u64 num_bytes =0 ;int ret; +u64 qgroup_reserved =0 ;if (root->fs_info->fs_state &BTRFS_SUPER_FLAG_ERROR )return ERR_PTR (-EROFS );
@@ -313,6 +314,14 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,* the appropriate flushing if need be. */ if (num_items >0 && root != root->fs_info->chunk_root) { +if (root->fs_info->quota_enabled && +is_fstree (root->root_key.objectid)) { + qgroup_reserved = num_items * root->leafsize; + ret =btrfs_qgroup_reserve (root, qgroup_reserved); +if (ret) +return ERR_PTR (ret); + } + num_bytes =btrfs_calc_trans_metadata_size (root, num_items); ret = btrfs_block_rsv_add(root, &root->fs_info->trans_block_rsv,
@@ -351,6 +360,7 @@ again: h->block_rsv =NULL ; h->orig_rsv =NULL ; h->aborted =0 ; + h->qgroup_reserved = qgroup_reserved; h->delayed_ref_elem.seq =0 ;INIT_LIST_HEAD (&h->qgroup_ref_list);
@@ -524,6 +534,12 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,* end_transaction. Subvolume quota depends on this. */ WARN_ON (trans->root != root); + +if (trans->qgroup_reserved) { +btrfs_qgroup_free (root, trans->qgroup_reserved); + trans->qgroup_reserved =0 ; + } +while (count <2 ) {unsigned long cur = trans->delayed_ref_updates; trans->delayed_ref_updates =0 ;
fs/btrfs/transaction.h +1 -0
@@ -50,6 +50,7 @@ struct btrfs_transaction {struct btrfs_trans_handle {u64 transid;u64 bytes_reserved; +u64 qgroup_reserved;unsigned long use_count;unsigned long blocks_reserved;unsigned long blocks_used;
Signature · 1 line
1.7.3.4
PATCH 14/15 Btrfs: add qgroup ioctls
In reply to Jan SchmidtFrom: Arne Jansen <[email protected]>
Ioctls to control the qgroup feature like adding and removing qgroups and assigning qgroups.
--- fs/btrfs/ioctl.c | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/ioctl.h | 27 ++++++++ 2 files changed, 212 insertions(+), 0 deletions(-)
fs/btrfs/ioctl.c +185 -0
@@ -3390,6 +3390,183 @@ out:return ret; } +static long btrfs_ioctl_quota_ctl (struct btrfs_root *root,void __user *arg) +{ +struct btrfs_ioctl_quota_ctl_args *sa; +struct btrfs_trans_handle *trans =NULL ; +int ret; +int err; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + +if (root->fs_info->sb->s_flags &MS_RDONLY ) +return -EROFS ; + + sa =memdup_user (arg,sizeof (*sa)); +if (IS_ERR (sa)) +return PTR_ERR (sa); + +if (sa->cmd !=BTRFS_QUOTA_CTL_RESCAN ) { + trans =btrfs_start_transaction (root,2 ); +if (IS_ERR (trans)) { + ret =PTR_ERR (trans); + goto out; + } + } + +switch (sa->cmd) { +case BTRFS_QUOTA_CTL_ENABLE : + ret =btrfs_quota_enable (trans, root->fs_info); +break ; +case BTRFS_QUOTA_CTL_DISABLE : + ret =btrfs_quota_disable (trans, root->fs_info); +break ; +case BTRFS_QUOTA_CTL_RESCAN : + ret =btrfs_quota_rescan (root->fs_info); +break ; +default : + ret = -EINVAL ; +break ; + } + +if (copy_to_user (arg, sa,sizeof (*sa))) + ret = -EFAULT ; + +if (trans) { + err =btrfs_commit_transaction (trans, root); +if (err && !ret) + ret = err; + } + +out: +kfree (sa); +return ret; +} + +static long btrfs_ioctl_qgroup_assign (struct btrfs_root *root,void __user *arg) +{ +struct btrfs_ioctl_qgroup_assign_args *sa; +struct btrfs_trans_handle *trans; +int ret; +int err; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + +if (root->fs_info->sb->s_flags &MS_RDONLY ) +return -EROFS ; + + sa =memdup_user (arg,sizeof (*sa)); +if (IS_ERR (sa)) +return PTR_ERR (sa); + + trans =btrfs_join_transaction (root); +if (IS_ERR (trans)) { + ret =PTR_ERR (trans); + goto out; + } + +/* FIXME: check if the IDs really exist */ +if (sa->assign) { + ret =btrfs_add_qgroup_relation (trans, root->fs_info, + sa->src, sa->dst); + }else { + ret =btrfs_del_qgroup_relation (trans, root->fs_info, + sa->src, sa->dst); + } + + err =btrfs_end_transaction (trans, root); +if (err && !ret) + ret = err; + +out: +kfree (sa); +return ret; +} + +static long btrfs_ioctl_qgroup_create (struct btrfs_root *root,void __user *arg) +{ +struct btrfs_ioctl_qgroup_create_args *sa; +struct btrfs_trans_handle *trans; +int ret; +int err; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + +if (root->fs_info->sb->s_flags &MS_RDONLY ) +return -EROFS ; + + sa =memdup_user (arg,sizeof (*sa)); +if (IS_ERR (sa)) +return PTR_ERR (sa); + + trans =btrfs_join_transaction (root); +if (IS_ERR (trans)) { + ret =PTR_ERR (trans); + goto out; + } + +/* FIXME: check if the IDs really exist */ +if (sa->create) { + ret =btrfs_create_qgroup (trans, root->fs_info, sa->qgroupid, +NULL ); + }else { + ret =btrfs_remove_qgroup (trans, root->fs_info, sa->qgroupid); + } + + err =btrfs_end_transaction (trans, root); +if (err && !ret) + ret = err; + +out: +kfree (sa); +return ret; +} + +static long btrfs_ioctl_qgroup_limit (struct btrfs_root *root,void __user *arg) +{ +struct btrfs_ioctl_qgroup_limit_args *sa; +struct btrfs_trans_handle *trans; +int ret; +int err; +u64 qgroupid; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + +if (root->fs_info->sb->s_flags &MS_RDONLY ) +return -EROFS ; + + sa =memdup_user (arg,sizeof (*sa)); +if (IS_ERR (sa)) +return PTR_ERR (sa); + + trans =btrfs_join_transaction (root); +if (IS_ERR (trans)) { + ret =PTR_ERR (trans); + goto out; + } + + qgroupid = sa->qgroupid; +if (!qgroupid) { +/* take the current subvol as qgroup */ + qgroupid = root->root_key.objectid; + } + +/* FIXME: check if the IDs really exist */ + ret =btrfs_limit_qgroup (trans, root->fs_info, qgroupid, &sa->lim); + + err =btrfs_end_transaction (trans, root); +if (err && !ret) + ret = err; + +out: +kfree (sa); +return ret; +} +long btrfs_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {
@@ -3476,6 +3653,14 @@ long btrfs_ioctl(struct file *file, unsigned intreturn btrfs_ioctl_get_dev_stats (root, argp,0 );case BTRFS_IOC_GET_AND_RESET_DEV_STATS :return btrfs_ioctl_get_dev_stats (root, argp,1 ); +case BTRFS_IOC_QUOTA_CTL : +return btrfs_ioctl_quota_ctl (root, argp); +case BTRFS_IOC_QGROUP_ASSIGN : +return btrfs_ioctl_qgroup_assign (root, argp); +case BTRFS_IOC_QGROUP_CREATE : +return btrfs_ioctl_qgroup_create (root, argp); +case BTRFS_IOC_QGROUP_LIMIT : +return btrfs_ioctl_qgroup_limit (root, argp); }return -ENOTTY ;
fs/btrfs/ioctl.h +27 -0
@@ -319,6 +319,25 @@ struct btrfs_ioctl_get_dev_stats {__u64 unused[128 -2 -BTRFS_DEV_STAT_VALUES_MAX ];/* pad to 1k */ }; +#define BTRFS_QUOTA_CTL_ENABLE 1 +#define BTRFS_QUOTA_CTL_DISABLE 2 +#define BTRFS_QUOTA_CTL_RESCAN 3 +struct btrfs_ioctl_quota_ctl_args { +__u64 cmd; +__u64 status; +}; + +struct btrfs_ioctl_qgroup_assign_args { +__u64 assign; +__u64 src; +__u64 dst; +}; + +struct btrfs_ioctl_qgroup_create_args { +__u64 create; +__u64 qgroupid; +}; +#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ struct btrfs_ioctl_vol_args)#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
@@ -388,4 +407,12 @@ struct btrfs_ioctl_get_dev_stats {#define BTRFS_IOC_GET_AND_RESET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 53, \ struct btrfs_ioctl_get_dev_stats) +#define BTRFS_IOC_QUOTA_CTL _IOWR(BTRFS_IOCTL_MAGIC, 40, \ + struct btrfs_ioctl_quota_ctl_args) +#define BTRFS_IOC_QGROUP_ASSIGN _IOW(BTRFS_IOCTL_MAGIC, 41, \ + struct btrfs_ioctl_qgroup_assign_args) +#define BTRFS_IOC_QGROUP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 42, \ + struct btrfs_ioctl_qgroup_create_args) +#define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43, \ + struct btrfs_ioctl_qgroup_limit_args)#endif
Signature · 1 line
1.7.3.4
PATCH 15/15 Btrfs: add qgroup inheritance
In reply to Jan SchmidtFrom: Arne Jansen <[email protected]>
When creating a subvolume or snapshot, it is necessary to initialize the qgroup account with a copy of some other (tracking) qgroup. This patch adds parameters to the ioctls to pass the information from which qgroup to inherit.
--- fs/btrfs/ioctl.c | 59 ++++++++++++++++++++++++++++++++++------------- fs/btrfs/ioctl.h | 11 ++++++++- fs/btrfs/transaction.c | 8 ++++++ fs/btrfs/transaction.h | 1 + 4 files changed, 61 insertions(+), 18 deletions(-)
fs/btrfs/ioctl.c +42 -17
@@ -336,7 +336,8 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg) static noinline int create_subvol(struct btrfs_root *root,struct dentry *dentry,char *name,int namelen, -u64 *async_transid) +u64 *async_transid, +struct btrfs_qgroup_inherit **inherit) {struct btrfs_trans_handle *trans;struct btrfs_key key;
@@ -368,6 +369,11 @@ static noinline int create_subvol(struct btrfs_root *root,if (IS_ERR (trans))return PTR_ERR (trans); + ret =btrfs_qgroup_inherit (trans, root->fs_info,0 , objectid, + inherit ? *inherit :NULL ); +if (ret) + goto fail; + leaf =btrfs_alloc_free_block (trans, root, root->leafsize,0 , objectid,NULL ,0 ,0 ,0 );if (IS_ERR (leaf)) {
@@ -484,7 +490,7 @@ fail:static int create_snapshot (struct btrfs_root *root,struct dentry *dentry,char *name,int namelen,u64 *async_transid, -bool readonly) +bool readonly,struct btrfs_qgroup_inherit **inherit) {struct inode *inode;struct btrfs_pending_snapshot *pending_snapshot;
@@ -502,6 +508,10 @@ static int create_snapshot(struct btrfs_root *root, struct dentry *dentry, pending_snapshot->dentry = dentry; pending_snapshot->root = root; pending_snapshot->readonly = readonly; +if (inherit) { + pending_snapshot->inherit = *inherit; + *inherit =NULL ;/* take responsibility to free it */ + } trans =btrfs_start_transaction (root->fs_info->extent_root,5 );if (IS_ERR (trans)) {
@@ -635,7 +645,8 @@ static inline int btrfs_may_create(struct inode *dir, struct dentry *child) static noinline int btrfs_mksubvol(struct path *parent,char *name,int namelen,struct btrfs_root *snap_src, -u64 *async_transid,bool readonly) +u64 *async_transid,bool readonly, +struct btrfs_qgroup_inherit **inherit) {struct inode *dir = parent->dentry->d_inode;struct dentry *dentry;
@@ -666,11 +677,11 @@ static noinline int btrfs_mksubvol(struct path *parent, goto out_up_read;if (snap_src) { - error =create_snapshot (snap_src, dentry, - name, namelen, async_transid, readonly); + error =create_snapshot (snap_src, dentry, name, namelen, + async_transid, readonly, inherit); }else { error =create_subvol (BTRFS_I (dir)->root, dentry, - name, namelen, async_transid); + name, namelen, async_transid, inherit); }if (!error)fsnotify_mkdir (dir, dentry);
@@ -1379,11 +1390,9 @@ out: } static noinline int btrfs_ioctl_snap_create_transid(struct file *file, -char *name, -unsigned long fd, -int subvol, -u64 *transid, -bool readonly) +char *name,unsigned long fd,int subvol, +u64 *transid,bool readonly, +struct btrfs_qgroup_inherit **inherit) {struct btrfs_root *root =BTRFS_I (fdentry (file)->d_inode)->root;struct file *src_file;
@@ -1407,7 +1416,7 @@ static noinline int btrfs_ioctl_snap_create_transid(struct file *file,if (subvol) { ret =btrfs_mksubvol (&file->f_path, name, namelen, -NULL , transid, readonly); +NULL , transid, readonly, inherit); }else {struct inode *src_inode; src_file =fget (fd);
@@ -1426,7 +1435,7 @@ static noinline int btrfs_ioctl_snap_create_transid(struct file *file, } ret =btrfs_mksubvol (&file->f_path, name, namelen,BTRFS_I (src_inode)->root, - transid, readonly); + transid, readonly, inherit);fput (src_file); } out:
@@ -1446,7 +1455,7 @@ static noinline int btrfs_ioctl_snap_create(struct file *file, ret =btrfs_ioctl_snap_create_transid (file, vol_args->name, vol_args->fd, subvol, -NULL , false); +NULL , false,NULL );kfree (vol_args);return ret;
@@ -1460,6 +1469,7 @@ static noinline int btrfs_ioctl_snap_create_v2(struct file *file,u64 transid =0 ;u64 *ptr =NULL ;bool readonly = false; +struct btrfs_qgroup_inherit *inherit =NULL ; vol_args =memdup_user (arg,sizeof (*vol_args));if (IS_ERR (vol_args))
@@ -1467,7 +1477,8 @@ static noinline int btrfs_ioctl_snap_create_v2(struct file *file, vol_args->name[BTRFS_SUBVOL_NAME_MAX ] ='\0' ;if (vol_args->flags & - ~(BTRFS_SUBVOL_CREATE_ASYNC |BTRFS_SUBVOL_RDONLY )) { + ~(BTRFS_SUBVOL_CREATE_ASYNC |BTRFS_SUBVOL_RDONLY | +BTRFS_SUBVOL_QGROUP_INHERIT )) { ret = -EOPNOTSUPP ; goto out; }
@@ -1476,10 +1487,21 @@ static noinline int btrfs_ioctl_snap_create_v2(struct file *file, ptr = &transid;if (vol_args->flags &BTRFS_SUBVOL_RDONLY ) readonly = true; +if (vol_args->flags &BTRFS_SUBVOL_QGROUP_INHERIT ) { +if (vol_args->size >PAGE_CACHE_SIZE ) { + ret = -EINVAL ; + goto out; + } + inherit =memdup_user (vol_args->qgroup_inherit, vol_args->size); +if (IS_ERR (inherit)) { + ret =PTR_ERR (inherit); + goto out; + } + } ret =btrfs_ioctl_snap_create_transid (file, vol_args->name, - vol_args->fd, subvol, - ptr, readonly); + vol_args->fd, subvol, ptr, + readonly, &inherit);if (ret ==0 && ptr && copy_to_user(arg +
@@ -1488,6 +1510,7 @@ static noinline int btrfs_ioctl_snap_create_v2(struct file *file, ret = -EFAULT ; out:kfree (vol_args); +kfree (inherit);return ret; }
@@ -3588,6 +3611,8 @@ long btrfs_ioctl(struct file *file, unsigned intreturn btrfs_ioctl_snap_create_v2 (file, argp,0 );case BTRFS_IOC_SUBVOL_CREATE :return btrfs_ioctl_snap_create (file, argp,1 ); +case BTRFS_IOC_SUBVOL_CREATE_V2 : +return btrfs_ioctl_snap_create_v2 (file, argp,1 );case BTRFS_IOC_SNAP_DESTROY :return btrfs_ioctl_snap_destroy (file, argp);case BTRFS_IOC_SUBVOL_GETFLAGS :
fs/btrfs/ioctl.h +10 -1
@@ -32,6 +32,7 @@ struct btrfs_ioctl_vol_args {#define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0)#define BTRFS_SUBVOL_RDONLY (1ULL << 1) +#define BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2)#define BTRFS_FSID_SIZE 16#define BTRFS_UUID_SIZE 16
@@ -64,7 +65,13 @@ struct btrfs_ioctl_vol_args_v2 {__s64 fd;__u64 transid;__u64 flags; -__u64 unused[4 ]; +union { +struct { +__u64 size; +struct btrfs_qgroup_inherit __user *qgroup_inherit; + }; +__u64 unused[4 ]; + };char name[BTRFS_SUBVOL_NAME_MAX +1 ]; };
@@ -382,6 +389,8 @@ struct btrfs_ioctl_qgroup_create_args {#define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)#define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \ struct btrfs_ioctl_vol_args_v2) +#define BTRFS_IOC_SUBVOL_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 24, \ + struct btrfs_ioctl_vol_args_v2)#define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)#define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)#define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \
fs/btrfs/transaction.c +8 -0
@@ -990,6 +990,14 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, } } + ret =btrfs_qgroup_inherit (trans, fs_info, root->root_key.objectid, + objectid, pending->inherit); +kfree (pending->inherit); +if (ret) { + pending->error = ret; + goto fail; + } + key.objectid = objectid; key.offset = (u64)-1 ; key.type =BTRFS_ROOT_ITEM_KEY ;
fs/btrfs/transaction.h +1 -0
@@ -73,6 +73,7 @@ struct btrfs_pending_snapshot {struct dentry *dentry;struct btrfs_root *root;struct btrfs_root *snap; +struct btrfs_qgroup_inherit *inherit;/* block reservation for the operation */ struct btrfs_block_rsv block_rsv;/* extra metadata reseration for relocation */
Signature · 1 line
1.7.3.4
Jan,
I have studied to some extent the PDF and the code. I have some questions; perhaps you can address them?
1) btrfs_qgroup_account_ref() calling btrfs_find_all_roots():
I understand that bytenr indicates some EXTENT_ITEM, which is a back-reference for extent, which is perhaps a tree block (leaf or node) or EXTENT_DATA. I also understand, that we want to receive a list of subvolume roots, that reference this extent at some point in time in the middle of a transaction. However, there is mentioning of "finding all extents that reference this extent", which is something basic I don't understand. How an extent can back-reference another extent? Also, how do we encounter roots (which is what we need in the output) during this walking? Hope you can shed some light, or you can let me continue digging in the code:)
2) btrfs_qgroup_account_ref() step 3:
I understand that at this step, we look at all roots that we cannot reach from the new root (the one to/from which the ref is added/removed). And we check the refcnt before/after addition/deletion (respectively). Then we check that its refcnt before/after addition/deletion equals to the number of reachable roots before/after addition/deletion. I still don't understand fully why if these two values are equal, we can update exclusive count?
My partial understanding is that such root, let's say before addition, was exclusive owner of the extent. And now (since this root is not reachable from new root), we are adding the extent to some "disjoint" qgroup, so the previous root is not exclusive owner anymore. Is this correct direction?
3) The paper mentions "tracking groups" to account for referenced/exclusive properly during snapshot creation. Looking at btrfs-progs, I see that currently the user is expected to correctly indicate which values should be copied from where, and kernel (more or less) blindly copies those values. Is this correct?
4) GROUP_RELATION items:
We have two such items for every relation. How do we know which one is the child and which is the parent? It looks from the kernel code that it is expected that child-qgroupid < parent-qgroupid. Is this correct? If yes, who is enforcing this?
Thanks for your help,
Alex.
Quoted 76 lines · Jan Schmidt
This is a new version of Arne's qgroup patches from last October. The old patches didn't get the backref walking right, which is now based on the tree modification log.
You can limit the space available to subvolumes or any group of subvolumes. You can determine the amount of space that will get freed when deleting a snapshot.
The initial scan is still missing, so expect negative counters when you enable quotas on a non-empty volume and then delete stuff.
Arne's introduction and concept description can still be found at
http://sensille.com/qgroups.pdf
You can pull these patches from my git repository
git://git.jan-o-sch.net/btrfs-unstableqgroupThe user mode patches required were sent at October 11, 2011 by Arne, subject "[PATCH v0] btrfs-progs: add qgroup commands".
I tried to include some fair benchmark results with this cover letter. However, I tried several disk benchmarks from the phoronix test suite, none of them resulted in any write throughput decrease. I will have to create a more realistic setup on my own to benchmark the impact of qgroups (suggestions welcome). For now, I just wanted to get that patch set out :-)
Thanks,
-JanArne Jansen (11):
Btrfs: qgroup on-disk format
Btrfs: add helper for tree enumeration
Btrfs: check the root passed tobtrfs_end_transaction
Btrfs: added helper to create new trees
Btrfs: qgroup state and initialization
Btrfs: Test code to change the order of delayed-ref processing
Btrfs: qgroup implementation and prototypes
Btrfs: quota tree support and startup
Btrfs: hooks to reserve qgroup space
Btrfs: add qgroup ioctls
Btrfs: add qgroup inheritanceJan Schmidt (4):
Btrfs: fix buffer leak inbtrfs_next_old_leaf
Btrfs: join tree mod log code with the code holding back delayed refs
Btrfs: call the qgroup accounting functions
Btrfs: hooks for qgroup to record delayed refsfs/btrfs/Makefile | 2 +- fs/btrfs/backref.c | 30 +- fs/btrfs/backref.h | 3 +- fs/btrfs/ctree.c | 348 ++++++++---- fs/btrfs/ctree.h | 233 +++++++- fs/btrfs/delayed-ref.c | 56 +- fs/btrfs/delayed-ref.h | 62 +-- fs/btrfs/disk-io.c | 134 ++++- fs/btrfs/disk-io.h | 6 + fs/btrfs/extent-tree.c | 119 ++++- fs/btrfs/ioctl.c | 244 +++++++- fs/btrfs/ioctl.h | 62 ++- fs/btrfs/qgroup.c | 1571 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/transaction.c | 57 ++- fs/btrfs/transaction.h | 11 + 15 files changed, 2696 insertions(+), 242 deletions(-) create mode 100644 fs/btrfs/qgroup.c--
1.7.3.4--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 7 lines · Alex Lyakas
Jan,
I have studied to some extent the PDF and the code. I have some questions; perhaps you can address them?1)
btrfs_qgroup_account_ref()callingbtrfs_find_all_roots():
I understand that bytenr indicates someEXTENT_ITEM, which is a back-reference for extent, which is perhaps a tree block (leaf or
Not a backreference. The EXTENT_ITEM entry is the allocation of the extent. It also contains the back references.
Quoted 5 lines
node) or
EXTENT_DATA. I also understand, that we want to receive a list of subvolume roots, that reference this extent at some point in time in the middle of a transaction. However, there is mentioning of "finding all extents that reference this extent", which is something basic I don't understand. How an extent can back-reference another
Here, the forward reference is meant. Tree nodes and leaves are referenced by tree nodes, data extents are referenced by leaves.
Quoted 2 lines
extent? Also, how do we encounter roots (which is what we need in the output) during this walking? Hope you can shed some light, or you can
iirc the root backreferences itself, which is the criterion that we found a root.
Quoted 10 lines
let me continue digging in the code:)
2)
btrfs_qgroup_account_ref()step 3:
I understand that at this step, we look at all roots that we cannot reach from the new root (the one to/from which the ref is added/removed). And we check the refcnt before/after addition/deletion (respectively). Then we check that its refcnt before/after addition/deletion equals to the number of reachable roots before/after addition/deletion. I still don't understand fully why if these two values are equal, we can update exclusive count?
I would have to re-read the pdf, it's been a long time ;)
Quoted 5 lines
My partial understanding is that such root, let's say before addition, was exclusive owner of the extent. And now (since this root is not reachable from new root), we are adding the extent to some "disjoint" qgroup, so the previous root is not exclusive owner anymore. Is this correct direction?
I think so. Drawing trees helps a lot here. Don't give up too easily, it took us 2 weeks to work out the algorithm ;)
Quoted 6 lines
3) The paper mentions "tracking groups" to account for referenced/exclusive properly during snapshot creation. Looking at btrfs-progs, I see that currently the user is expected to correctly indicate which values should be copied from where, and kernel (more or less) blindly copies those values. Is this correct?
Yes. It might be useful to create a description language what you are going to snapshot from where and let progs take care that all tracking groups are set up properly. But that is an area for further research, currently it has to be done by hand.
Quoted 6 lines
4)
GROUP_RELATIONitems:
We have two such items for every relation. How do we know which one is the child and which is the parent? It looks from the kernel code that it is expected that child-qgroupid < parent-qgroupid. Is this correct? If yes, who is enforcing this?
The qgroupid contains the level, and the parent always has to have a level greater than that of the child. I think that is checked somewhere. As the level is encoded into the upper bits, the above relation holds.
-Arne
Quoted 81 lines
Thanks for your help,
Alex.Quoted 76 lines · Jan Schmidt
This is a new version of Arne's qgroup patches from last October. The old patches didn't get the backref walking right, which is now based on the tree modification log.
You can limit the space available to subvolumes or any group of subvolumes. You can determine the amount of space that will get freed when deleting a snapshot.
The initial scan is still missing, so expect negative counters when you enable quotas on a non-empty volume and then delete stuff.
Arne's introduction and concept description can still be found at
http://sensille.com/qgroups.pdf
You can pull these patches from my git repository
git://git.jan-o-sch.net/btrfs-unstableqgroupThe user mode patches required were sent at October 11, 2011 by Arne, subject "[PATCH v0] btrfs-progs: add qgroup commands".
I tried to include some fair benchmark results with this cover letter. However, I tried several disk benchmarks from the phoronix test suite, none of them resulted in any write throughput decrease. I will have to create a more realistic setup on my own to benchmark the impact of qgroups (suggestions welcome). For now, I just wanted to get that patch set out :-)
Thanks,
-JanArne Jansen (11):
Btrfs: qgroup on-disk format
Btrfs: add helper for tree enumeration
Btrfs: check the root passed tobtrfs_end_transaction
Btrfs: added helper to create new trees
Btrfs: qgroup state and initialization
Btrfs: Test code to change the order of delayed-ref processing
Btrfs: qgroup implementation and prototypes
Btrfs: quota tree support and startup
Btrfs: hooks to reserve qgroup space
Btrfs: add qgroup ioctls
Btrfs: add qgroup inheritanceJan Schmidt (4):
Btrfs: fix buffer leak inbtrfs_next_old_leaf
Btrfs: join tree mod log code with the code holding back delayed refs
Btrfs: call the qgroup accounting functions
Btrfs: hooks for qgroup to record delayed refsfs/btrfs/Makefile | 2 +- fs/btrfs/backref.c | 30 +- fs/btrfs/backref.h | 3 +- fs/btrfs/ctree.c | 348 ++++++++---- fs/btrfs/ctree.h | 233 +++++++- fs/btrfs/delayed-ref.c | 56 +- fs/btrfs/delayed-ref.h | 62 +-- fs/btrfs/disk-io.c | 134 ++++- fs/btrfs/disk-io.h | 6 + fs/btrfs/extent-tree.c | 119 ++++- fs/btrfs/ioctl.c | 244 +++++++- fs/btrfs/ioctl.h | 62 ++- fs/btrfs/qgroup.c | 1571 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/transaction.c | 57 ++- fs/btrfs/transaction.h | 11 + 15 files changed, 2696 insertions(+), 242 deletions(-) create mode 100644 fs/btrfs/qgroup.c--
1.7.3.4--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Arne Jansen
Quoted 2 lines · Alex Lyakas
extent? Also, how do we encounter roots (which is what we need in the output) during this walking? Hope you can shed some light, or you can
iirc the root backreferences itself, which is the criterion that we found a root.
As all the backref walking code, this differs between shared backrefs and indirect backrefs, too. In general, the criterion is: We've got a backref with a positive refcount, we've got a root id set for it, and we determined that this block has no parent block.
See where find_parent_nodes adds to the "roots" ulist.
Quoted 1 line
Quoted 1 line
let me continue digging in the code:)
Please do so :-)
-Jan
Arne,
thanks for your comments.
Quoted 68 lines · Arne Jansen
Quoted 7 lines · Alex Lyakas
Jan,
I have studied to some extent the PDF and the code. I have some questions; perhaps you can address them?1)
btrfs_qgroup_account_ref()callingbtrfs_find_all_roots():
I understand that bytenr indicates someEXTENT_ITEM, which is a back-reference for extent, which is perhaps a tree block (leaf orNot a backreference. The
EXTENT_ITEMentry is the allocation of the extent. It also contains the back references.Quoted 5 lines
node) or
EXTENT_DATA. I also understand, that we want to receive a list of subvolume roots, that reference this extent at some point in time in the middle of a transaction. However, there is mentioning of "finding all extents that reference this extent", which is something basic I don't understand. How an extent can back-reference anotherHere, the forward reference is meant. Tree nodes and leaves are referenced by tree nodes, data extents are referenced by leaves.
Quoted 2 lines
extent? Also, how do we encounter roots (which is what we need in the output) during this walking? Hope you can shed some light, or you can
iirc the root backreferences itself, which is the criterion that we found a root.
Quoted 10 lines
let me continue digging in the code:)
2)
btrfs_qgroup_account_ref()step 3:
I understand that at this step, we look at all roots that we cannot reach from the new root (the one to/from which the ref is added/removed). And we check the refcnt before/after addition/deletion (respectively). Then we check that its refcnt before/after addition/deletion equals to the number of reachable roots before/after addition/deletion. I still don't understand fully why if these two values are equal, we can update exclusive count?I would have to re-read the pdf, it's been a long time ;)
Quoted 5 lines
My partial understanding is that such root, let's say before addition, was exclusive owner of the extent. And now (since this root is not reachable from new root), we are adding the extent to some "disjoint" qgroup, so the previous root is not exclusive owner anymore. Is this correct direction?
I think so. Drawing trees helps a lot here. Don't give up too easily, it took us 2 weeks to work out the algorithm ;)
Quoted 6 lines
3) The paper mentions "tracking groups" to account for referenced/exclusive properly during snapshot creation. Looking at btrfs-progs, I see that currently the user is expected to correctly indicate which values should be copied from where, and kernel (more or less) blindly copies those values. Is this correct?
Yes. It might be useful to create a description language what you are going to snapshot from where and let progs take care that all tracking groups are set up properly. But that is an area for further research, currently it has to be done by hand.
Quoted 6 lines
4)
GROUP_RELATIONitems:
We have two such items for every relation. How do we know which one is the child and which is the parent? It looks from the kernel code that it is expected that child-qgroupid < parent-qgroupid. Is this correct? If yes, who is enforcing this?
Quoted 3 lines
The qgroupid contains the level, and the parent always has to have a level greater than that of the child. I think that is checked somewhere. As the level is encoded into the upper bits, the above relation holds.
I saw the 16-48 bit separation in the paper, but did not find any traces of that in the code. Probably there will not be more than 2^48 subvolumes/snapshots, so yes, this scheme works.
Alex.
Quoted 85 lines
-Arne
Quoted 81 lines
Thanks for your help,
Alex.Quoted 76 lines · Jan Schmidt
This is a new version of Arne's qgroup patches from last October. The old patches didn't get the backref walking right, which is now based on the tree modification log.
You can limit the space available to subvolumes or any group of subvolumes. You can determine the amount of space that will get freed when deleting a snapshot.
The initial scan is still missing, so expect negative counters when you enable quotas on a non-empty volume and then delete stuff.
Arne's introduction and concept description can still be found at
http://sensille.com/qgroups.pdf
You can pull these patches from my git repository
git://git.jan-o-sch.net/btrfs-unstableqgroupThe user mode patches required were sent at October 11, 2011 by Arne, subject "[PATCH v0] btrfs-progs: add qgroup commands".
I tried to include some fair benchmark results with this cover letter. However, I tried several disk benchmarks from the phoronix test suite, none of them resulted in any write throughput decrease. I will have to create a more realistic setup on my own to benchmark the impact of qgroups (suggestions welcome). For now, I just wanted to get that patch set out :-)
Thanks,
-JanArne Jansen (11):
Btrfs: qgroup on-disk format
Btrfs: add helper for tree enumeration
Btrfs: check the root passed tobtrfs_end_transaction
Btrfs: added helper to create new trees
Btrfs: qgroup state and initialization
Btrfs: Test code to change the order of delayed-ref processing
Btrfs: qgroup implementation and prototypes
Btrfs: quota tree support and startup
Btrfs: hooks to reserve qgroup space
Btrfs: add qgroup ioctls
Btrfs: add qgroup inheritanceJan Schmidt (4):
Btrfs: fix buffer leak inbtrfs_next_old_leaf
Btrfs: join tree mod log code with the code holding back delayed refs
Btrfs: call the qgroup accounting functions
Btrfs: hooks for qgroup to record delayed refsfs/btrfs/Makefile | 2 +- fs/btrfs/backref.c | 30 +- fs/btrfs/backref.h | 3 +- fs/btrfs/ctree.c | 348 ++++++++---- fs/btrfs/ctree.h | 233 +++++++- fs/btrfs/delayed-ref.c | 56 +- fs/btrfs/delayed-ref.h | 62 +-- fs/btrfs/disk-io.c | 134 ++++- fs/btrfs/disk-io.h | 6 + fs/btrfs/extent-tree.c | 119 ++++- fs/btrfs/ioctl.c | 244 +++++++- fs/btrfs/ioctl.h | 62 ++- fs/btrfs/qgroup.c | 1571 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/transaction.c | 57 ++- fs/btrfs/transaction.h | 11 + 15 files changed, 2696 insertions(+), 242 deletions(-) create mode 100644 fs/btrfs/qgroup.c--
1.7.3.4--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html