aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/transaction.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-09-29 15:18:18 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-29 15:18:18 -0400
commitd352ac68148b69937d39ca5d48bcc4478e118dbf (patch)
tree7951dd7311999d9e77766acdc7f8e93de97874d8 /fs/btrfs/transaction.c
parent9a5e1ea1e1e539e244a54afffc330fc368376ab9 (diff)
Btrfs: add and improve comments
This improves the comments at the top of many functions. It didn't dive into the guts of functions because I was trying to avoid merging problems with the new allocator and back reference work. extent-tree.c and volumes.c were both skipped, and there is definitely more work todo in cleaning and commenting the code. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/transaction.c')
-rw-r--r--fs/btrfs/transaction.c67
1 files changed, 65 insertions, 2 deletions
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 444abe0796ae..11266d68a6c9 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -46,6 +46,9 @@ static noinline void put_transaction(struct btrfs_transaction *transaction)
46 } 46 }
47} 47}
48 48
49/*
50 * either allocate a new transaction or hop into the existing one
51 */
49static noinline int join_transaction(struct btrfs_root *root) 52static noinline int join_transaction(struct btrfs_root *root)
50{ 53{
51 struct btrfs_transaction *cur_trans; 54 struct btrfs_transaction *cur_trans;
@@ -85,6 +88,12 @@ static noinline int join_transaction(struct btrfs_root *root)
85 return 0; 88 return 0;
86} 89}
87 90
91/*
92 * this does all the record keeping required to make sure that a
93 * reference counted root is properly recorded in a given transaction.
94 * This is required to make sure the old root from before we joined the transaction
95 * is deleted when the transaction commits
96 */
88noinline int btrfs_record_root_in_trans(struct btrfs_root *root) 97noinline int btrfs_record_root_in_trans(struct btrfs_root *root)
89{ 98{
90 struct btrfs_dirty_root *dirty; 99 struct btrfs_dirty_root *dirty;
@@ -127,6 +136,10 @@ noinline int btrfs_record_root_in_trans(struct btrfs_root *root)
127 return 0; 136 return 0;
128} 137}
129 138
139/* wait for commit against the current transaction to become unblocked
140 * when this is done, it is safe to start a new transaction, but the current
141 * transaction might not be fully on disk.
142 */
130static void wait_current_trans(struct btrfs_root *root) 143static void wait_current_trans(struct btrfs_root *root)
131{ 144{
132 struct btrfs_transaction *cur_trans; 145 struct btrfs_transaction *cur_trans;
@@ -198,7 +211,7 @@ struct btrfs_trans_handle *btrfs_start_ioctl_transaction(struct btrfs_root *r,
198 return start_transaction(r, num_blocks, 2); 211 return start_transaction(r, num_blocks, 2);
199} 212}
200 213
201 214/* wait for a transaction commit to be fully complete */
202static noinline int wait_for_commit(struct btrfs_root *root, 215static noinline int wait_for_commit(struct btrfs_root *root,
203 struct btrfs_transaction *commit) 216 struct btrfs_transaction *commit)
204{ 217{
@@ -218,6 +231,10 @@ static noinline int wait_for_commit(struct btrfs_root *root,
218 return 0; 231 return 0;
219} 232}
220 233
234/*
235 * rate limit against the drop_snapshot code. This helps to slow down new operations
236 * if the drop_snapshot code isn't able to keep up.
237 */
221static void throttle_on_drops(struct btrfs_root *root) 238static void throttle_on_drops(struct btrfs_root *root)
222{ 239{
223 struct btrfs_fs_info *info = root->fs_info; 240 struct btrfs_fs_info *info = root->fs_info;
@@ -302,7 +319,11 @@ int btrfs_end_transaction_throttle(struct btrfs_trans_handle *trans,
302 return __btrfs_end_transaction(trans, root, 1); 319 return __btrfs_end_transaction(trans, root, 1);
303} 320}
304 321
305 322/*
323 * when btree blocks are allocated, they have some corresponding bits set for
324 * them in one of two extent_io trees. This is used to make sure all of
325 * those extents are on disk for transaction or log commit
326 */
306int btrfs_write_and_wait_marked_extents(struct btrfs_root *root, 327int btrfs_write_and_wait_marked_extents(struct btrfs_root *root,
307 struct extent_io_tree *dirty_pages) 328 struct extent_io_tree *dirty_pages)
308{ 329{
@@ -393,6 +414,16 @@ int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
393 &trans->transaction->dirty_pages); 414 &trans->transaction->dirty_pages);
394} 415}
395 416
417/*
418 * this is used to update the root pointer in the tree of tree roots.
419 *
420 * But, in the case of the extent allocation tree, updating the root
421 * pointer may allocate blocks which may change the root of the extent
422 * allocation tree.
423 *
424 * So, this loops and repeats and makes sure the cowonly root didn't
425 * change while the root pointer was being updated in the metadata.
426 */
396static int update_cowonly_root(struct btrfs_trans_handle *trans, 427static int update_cowonly_root(struct btrfs_trans_handle *trans,
397 struct btrfs_root *root) 428 struct btrfs_root *root)
398{ 429{
@@ -418,6 +449,9 @@ static int update_cowonly_root(struct btrfs_trans_handle *trans,
418 return 0; 449 return 0;
419} 450}
420 451
452/*
453 * update all the cowonly tree roots on disk
454 */
421int btrfs_commit_tree_roots(struct btrfs_trans_handle *trans, 455int btrfs_commit_tree_roots(struct btrfs_trans_handle *trans,
422 struct btrfs_root *root) 456 struct btrfs_root *root)
423{ 457{
@@ -433,6 +467,11 @@ int btrfs_commit_tree_roots(struct btrfs_trans_handle *trans,
433 return 0; 467 return 0;
434} 468}
435 469
470/*
471 * dead roots are old snapshots that need to be deleted. This allocates
472 * a dirty root struct and adds it into the list of dead roots that need to
473 * be deleted
474 */
436int btrfs_add_dead_root(struct btrfs_root *root, struct btrfs_root *latest) 475int btrfs_add_dead_root(struct btrfs_root *root, struct btrfs_root *latest)
437{ 476{
438 struct btrfs_dirty_root *dirty; 477 struct btrfs_dirty_root *dirty;
@@ -449,6 +488,12 @@ int btrfs_add_dead_root(struct btrfs_root *root, struct btrfs_root *latest)
449 return 0; 488 return 0;
450} 489}
451 490
491/*
492 * at transaction commit time we need to schedule the old roots for
493 * deletion via btrfs_drop_snapshot. This runs through all the
494 * reference counted roots that were modified in the current
495 * transaction and puts them into the drop list
496 */
452static noinline int add_dirty_roots(struct btrfs_trans_handle *trans, 497static noinline int add_dirty_roots(struct btrfs_trans_handle *trans,
453 struct radix_tree_root *radix, 498 struct radix_tree_root *radix,
454 struct list_head *list) 499 struct list_head *list)
@@ -541,6 +586,10 @@ static noinline int add_dirty_roots(struct btrfs_trans_handle *trans,
541 return err; 586 return err;
542} 587}
543 588
589/*
590 * defrag a given btree. If cacheonly == 1, this won't read from the disk,
591 * otherwise every leaf in the btree is read and defragged.
592 */
544int btrfs_defrag_root(struct btrfs_root *root, int cacheonly) 593int btrfs_defrag_root(struct btrfs_root *root, int cacheonly)
545{ 594{
546 struct btrfs_fs_info *info = root->fs_info; 595 struct btrfs_fs_info *info = root->fs_info;
@@ -570,6 +619,10 @@ int btrfs_defrag_root(struct btrfs_root *root, int cacheonly)
570 return 0; 619 return 0;
571} 620}
572 621
622/*
623 * Given a list of roots that need to be deleted, call btrfs_drop_snapshot on
624 * all of them
625 */
573static noinline int drop_dirty_roots(struct btrfs_root *tree_root, 626static noinline int drop_dirty_roots(struct btrfs_root *tree_root,
574 struct list_head *list) 627 struct list_head *list)
575{ 628{
@@ -664,6 +717,10 @@ static noinline int drop_dirty_roots(struct btrfs_root *tree_root,
664 return ret; 717 return ret;
665} 718}
666 719
720/*
721 * new snapshots need to be created at a very specific time in the
722 * transaction commit. This does the actual creation
723 */
667static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, 724static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
668 struct btrfs_fs_info *fs_info, 725 struct btrfs_fs_info *fs_info,
669 struct btrfs_pending_snapshot *pending) 726 struct btrfs_pending_snapshot *pending)
@@ -734,6 +791,9 @@ fail:
734 return ret; 791 return ret;
735} 792}
736 793
794/*
795 * create all the snapshots we've scheduled for creation
796 */
737static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans, 797static noinline int create_pending_snapshots(struct btrfs_trans_handle *trans,
738 struct btrfs_fs_info *fs_info) 798 struct btrfs_fs_info *fs_info)
739{ 799{
@@ -944,6 +1004,9 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
944 return ret; 1004 return ret;
945} 1005}
946 1006
1007/*
1008 * interface function to delete all the snapshots we have scheduled for deletion
1009 */
947int btrfs_clean_old_snapshots(struct btrfs_root *root) 1010int btrfs_clean_old_snapshots(struct btrfs_root *root)
948{ 1011{
949 struct list_head dirty_roots; 1012 struct list_head dirty_roots;