@@ -670,36 +670,43 @@ static void dump_block_entry(struct btrfs_fs_info *fs_info,
670670
671671/*
672672 * btrfs_ref_tree_mod: called when we modify a ref for a bytenr
673- * @root: the root we are making this modification from.
674- * @bytenr: the bytenr we are modifying.
675- * @num_bytes: number of bytes.
676- * @parent: the parent bytenr.
677- * @ref_root: the original root owner of the bytenr.
678- * @owner: level in the case of metadata, inode in the case of data.
679- * @offset: 0 for metadata, file offset for data.
680- * @action: the action that we are doing, this is the same as the delayed ref
681- * action.
682673 *
683674 * This will add an action item to the given bytenr and do sanity checks to make
684675 * sure we haven't messed something up. If we are making a new allocation and
685676 * this block entry has history we will delete all previous actions as long as
686677 * our sanity checks pass as they are no longer needed.
687678 */
688- int btrfs_ref_tree_mod (struct btrfs_root * root , u64 bytenr , u64 num_bytes ,
689- u64 parent , u64 ref_root , u64 owner , u64 offset ,
690- int action )
679+ int btrfs_ref_tree_mod (struct btrfs_fs_info * fs_info ,
680+ struct btrfs_ref * generic_ref )
691681{
692- struct btrfs_fs_info * fs_info = root -> fs_info ;
693682 struct ref_entry * ref = NULL , * exist ;
694683 struct ref_action * ra = NULL ;
695684 struct block_entry * be = NULL ;
696685 struct root_entry * re = NULL ;
686+ int action = generic_ref -> action ;
697687 int ret = 0 ;
698- bool metadata = owner < BTRFS_FIRST_FREE_OBJECTID ;
688+ bool metadata ;
689+ u64 bytenr = generic_ref -> bytenr ;
690+ u64 num_bytes = generic_ref -> len ;
691+ u64 parent = generic_ref -> parent ;
692+ u64 ref_root ;
693+ u64 owner ;
694+ u64 offset ;
699695
700- if (!btrfs_test_opt (root -> fs_info , REF_VERIFY ))
696+ if (!btrfs_test_opt (fs_info , REF_VERIFY ))
701697 return 0 ;
702698
699+ if (generic_ref -> type == BTRFS_REF_METADATA ) {
700+ ref_root = generic_ref -> tree_ref .root ;
701+ owner = generic_ref -> tree_ref .level ;
702+ offset = 0 ;
703+ } else {
704+ ref_root = generic_ref -> data_ref .ref_root ;
705+ owner = generic_ref -> data_ref .ino ;
706+ offset = generic_ref -> data_ref .offset ;
707+ }
708+ metadata = owner < BTRFS_FIRST_FREE_OBJECTID ;
709+
703710 ref = kzalloc (sizeof (struct ref_entry ), GFP_NOFS );
704711 ra = kmalloc (sizeof (struct ref_action ), GFP_NOFS );
705712 if (!ra || !ref ) {
@@ -732,7 +739,7 @@ int btrfs_ref_tree_mod(struct btrfs_root *root, u64 bytenr, u64 num_bytes,
732739
733740 INIT_LIST_HEAD (& ra -> list );
734741 ra -> action = action ;
735- ra -> root = root -> root_key . objectid ;
742+ ra -> root = generic_ref -> real_root ;
736743
737744 /*
738745 * This is an allocation, preallocate the block_entry in case we haven't
@@ -745,7 +752,7 @@ int btrfs_ref_tree_mod(struct btrfs_root *root, u64 bytenr, u64 num_bytes,
745752 * is and the new root objectid, so let's not treat the passed
746753 * in root as if it really has a ref for this bytenr.
747754 */
748- be = add_block_entry (root -> fs_info , bytenr , num_bytes , ref_root );
755+ be = add_block_entry (fs_info , bytenr , num_bytes , ref_root );
749756 if (IS_ERR (be )) {
750757 kfree (ra );
751758 ret = PTR_ERR (be );
@@ -787,13 +794,13 @@ int btrfs_ref_tree_mod(struct btrfs_root *root, u64 bytenr, u64 num_bytes,
787794 * one we want to lookup below when we modify the
788795 * re->num_refs.
789796 */
790- ref_root = root -> root_key . objectid ;
791- re -> root_objectid = root -> root_key . objectid ;
797+ ref_root = generic_ref -> real_root ;
798+ re -> root_objectid = generic_ref -> real_root ;
792799 re -> num_refs = 0 ;
793800 }
794801
795- spin_lock (& root -> fs_info -> ref_verify_lock );
796- be = lookup_block_entry (& root -> fs_info -> block_tree , bytenr );
802+ spin_lock (& fs_info -> ref_verify_lock );
803+ be = lookup_block_entry (& fs_info -> block_tree , bytenr );
797804 if (!be ) {
798805 btrfs_err (fs_info ,
799806"trying to do action %d to bytenr %llu num_bytes %llu but there is no existing entry!" ,
@@ -862,7 +869,7 @@ int btrfs_ref_tree_mod(struct btrfs_root *root, u64 bytenr, u64 num_bytes,
862869 * didn't think of some other corner case.
863870 */
864871 btrfs_err (fs_info , "failed to find root %llu for %llu" ,
865- root -> root_key . objectid , be -> bytenr );
872+ generic_ref -> real_root , be -> bytenr );
866873 dump_block_entry (fs_info , be );
867874 dump_ref_action (fs_info , ra );
868875 kfree (ra );
@@ -881,7 +888,7 @@ int btrfs_ref_tree_mod(struct btrfs_root *root, u64 bytenr, u64 num_bytes,
881888 list_add_tail (& ra -> list , & be -> actions );
882889 ret = 0 ;
883890out_unlock :
884- spin_unlock (& root -> fs_info -> ref_verify_lock );
891+ spin_unlock (& fs_info -> ref_verify_lock );
885892out :
886893 if (ret )
887894 btrfs_clear_opt (fs_info -> mount_opt , REF_VERIFY );
0 commit comments