156bec294dea971335d4466b30f2d959f28f6e36dChris Mason/* 256bec294dea971335d4466b30f2d959f28f6e36dChris Mason * Copyright (C) 2008 Oracle. All rights reserved. 356bec294dea971335d4466b30f2d959f28f6e36dChris Mason * 456bec294dea971335d4466b30f2d959f28f6e36dChris Mason * This program is free software; you can redistribute it and/or 556bec294dea971335d4466b30f2d959f28f6e36dChris Mason * modify it under the terms of the GNU General Public 656bec294dea971335d4466b30f2d959f28f6e36dChris Mason * License v2 as published by the Free Software Foundation. 756bec294dea971335d4466b30f2d959f28f6e36dChris Mason * 856bec294dea971335d4466b30f2d959f28f6e36dChris Mason * This program is distributed in the hope that it will be useful, 956bec294dea971335d4466b30f2d959f28f6e36dChris Mason * but WITHOUT ANY WARRANTY; without even the implied warranty of 1056bec294dea971335d4466b30f2d959f28f6e36dChris Mason * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1156bec294dea971335d4466b30f2d959f28f6e36dChris Mason * General Public License for more details. 1256bec294dea971335d4466b30f2d959f28f6e36dChris Mason * 1356bec294dea971335d4466b30f2d959f28f6e36dChris Mason * You should have received a copy of the GNU General Public 1456bec294dea971335d4466b30f2d959f28f6e36dChris Mason * License along with this program; if not, write to the 1556bec294dea971335d4466b30f2d959f28f6e36dChris Mason * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 1656bec294dea971335d4466b30f2d959f28f6e36dChris Mason * Boston, MA 021110-1307, USA. 1756bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 1856bec294dea971335d4466b30f2d959f28f6e36dChris Mason#ifndef __DELAYED_REF__ 1956bec294dea971335d4466b30f2d959f28f6e36dChris Mason#define __DELAYED_REF__ 2056bec294dea971335d4466b30f2d959f28f6e36dChris Mason 2144a075bde9ab32d13bb2ff89f3e72fd869f272c4Wang Sheng-Hui/* these are the possible values of struct btrfs_delayed_ref_node->action */ 2256bec294dea971335d4466b30f2d959f28f6e36dChris Mason#define BTRFS_ADD_DELAYED_REF 1 /* add one backref to the tree */ 2356bec294dea971335d4466b30f2d959f28f6e36dChris Mason#define BTRFS_DROP_DELAYED_REF 2 /* delete one backref from the tree */ 2456bec294dea971335d4466b30f2d959f28f6e36dChris Mason#define BTRFS_ADD_DELAYED_EXTENT 3 /* record a full extent allocation */ 251a81af4d1d9c60d4313309f937a1fc5567205a87Chris Mason#define BTRFS_UPDATE_DELAYED_HEAD 4 /* not changing ref count on head ref */ 2656bec294dea971335d4466b30f2d959f28f6e36dChris Mason 2756bec294dea971335d4466b30f2d959f28f6e36dChris Masonstruct btrfs_delayed_ref_node { 2856bec294dea971335d4466b30f2d959f28f6e36dChris Mason struct rb_node rb_node; 2956bec294dea971335d4466b30f2d959f28f6e36dChris Mason 3056bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* the starting bytenr of the extent */ 3156bec294dea971335d4466b30f2d959f28f6e36dChris Mason u64 bytenr; 3256bec294dea971335d4466b30f2d959f28f6e36dChris Mason 3356bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* the size of the extent */ 3456bec294dea971335d4466b30f2d959f28f6e36dChris Mason u64 num_bytes; 3556bec294dea971335d4466b30f2d959f28f6e36dChris Mason 3600f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen /* seq number to keep track of insertion order */ 3700f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen u64 seq; 3800f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 3956bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* ref count on this data structure */ 4056bec294dea971335d4466b30f2d959f28f6e36dChris Mason atomic_t refs; 4156bec294dea971335d4466b30f2d959f28f6e36dChris Mason 4256bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* 4356bec294dea971335d4466b30f2d959f28f6e36dChris Mason * how many refs is this entry adding or deleting. For 4456bec294dea971335d4466b30f2d959f28f6e36dChris Mason * head refs, this may be a negative number because it is keeping 4556bec294dea971335d4466b30f2d959f28f6e36dChris Mason * track of the total mods done to the reference count. 4656bec294dea971335d4466b30f2d959f28f6e36dChris Mason * For individual refs, this will always be a positive number 4756bec294dea971335d4466b30f2d959f28f6e36dChris Mason * 4856bec294dea971335d4466b30f2d959f28f6e36dChris Mason * It may be more than one, since it is possible for a single 4956bec294dea971335d4466b30f2d959f28f6e36dChris Mason * parent to have more than one ref on an extent 5056bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 5156bec294dea971335d4466b30f2d959f28f6e36dChris Mason int ref_mod; 5256bec294dea971335d4466b30f2d959f28f6e36dChris Mason 535d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng unsigned int action:8; 545d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng unsigned int type:8; 55fcebe4562dec83b3f8d3088d77584727b09130b2Josef Bacik unsigned int no_quota:1; 5656bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* is this node still in the rbtree? */ 575d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng unsigned int is_head:1; 5856bec294dea971335d4466b30f2d959f28f6e36dChris Mason unsigned int in_tree:1; 5956bec294dea971335d4466b30f2d959f28f6e36dChris Mason}; 6056bec294dea971335d4466b30f2d959f28f6e36dChris Mason 615d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zhengstruct btrfs_delayed_extent_op { 625d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng struct btrfs_disk_key key; 635d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 flags_to_set; 64b1c79e0947e0c190f865e2eb7b84a0fea0021cecJosef Bacik int level; 655d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng unsigned int update_key:1; 665d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng unsigned int update_flags:1; 675d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng unsigned int is_data:1; 685d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng}; 695d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng 7056bec294dea971335d4466b30f2d959f28f6e36dChris Mason/* 7156bec294dea971335d4466b30f2d959f28f6e36dChris Mason * the head refs are used to hold a lock on a given extent, which allows us 7256bec294dea971335d4466b30f2d959f28f6e36dChris Mason * to make sure that only one process is running the delayed refs 7356bec294dea971335d4466b30f2d959f28f6e36dChris Mason * at a time for a single extent. They also store the sum of all the 7456bec294dea971335d4466b30f2d959f28f6e36dChris Mason * reference count modifications we've queued up. 7556bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 7656bec294dea971335d4466b30f2d959f28f6e36dChris Masonstruct btrfs_delayed_ref_head { 7756bec294dea971335d4466b30f2d959f28f6e36dChris Mason struct btrfs_delayed_ref_node node; 7856bec294dea971335d4466b30f2d959f28f6e36dChris Mason 7956bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* 8056bec294dea971335d4466b30f2d959f28f6e36dChris Mason * the mutex is held while running the refs, and it is also 8156bec294dea971335d4466b30f2d959f28f6e36dChris Mason * held when checking the sum of reference modifications. 8256bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 8356bec294dea971335d4466b30f2d959f28f6e36dChris Mason struct mutex mutex; 8456bec294dea971335d4466b30f2d959f28f6e36dChris Mason 85d7df2c796d7eedd72a334dc89c65e1fec8171431Josef Bacik spinlock_t lock; 86d7df2c796d7eedd72a334dc89c65e1fec8171431Josef Bacik struct rb_root ref_root; 87c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason 88c46effa601f869f3d20a7386a745d9c002838eb8Liu Bo struct rb_node href_node; 89c46effa601f869f3d20a7386a745d9c002838eb8Liu Bo 905d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng struct btrfs_delayed_extent_op *extent_op; 9156bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* 9256bec294dea971335d4466b30f2d959f28f6e36dChris Mason * when a new extent is allocated, it is just reserved in memory 9356bec294dea971335d4466b30f2d959f28f6e36dChris Mason * The actual extent isn't inserted into the extent allocation tree 9456bec294dea971335d4466b30f2d959f28f6e36dChris Mason * until the delayed ref is processed. must_insert_reserved is 9556bec294dea971335d4466b30f2d959f28f6e36dChris Mason * used to flag a delayed ref so the accounting can be updated 9656bec294dea971335d4466b30f2d959f28f6e36dChris Mason * when a full insert is done. 9756bec294dea971335d4466b30f2d959f28f6e36dChris Mason * 9856bec294dea971335d4466b30f2d959f28f6e36dChris Mason * It is possible the extent will be freed before it is ever 9956bec294dea971335d4466b30f2d959f28f6e36dChris Mason * inserted into the extent allocation tree. In this case 10056bec294dea971335d4466b30f2d959f28f6e36dChris Mason * we need to update the in ram accounting to properly reflect 10156bec294dea971335d4466b30f2d959f28f6e36dChris Mason * the free has happened. 10256bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 10356bec294dea971335d4466b30f2d959f28f6e36dChris Mason unsigned int must_insert_reserved:1; 1045d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng unsigned int is_data:1; 105d7df2c796d7eedd72a334dc89c65e1fec8171431Josef Bacik unsigned int processing:1; 10656bec294dea971335d4466b30f2d959f28f6e36dChris Mason}; 10756bec294dea971335d4466b30f2d959f28f6e36dChris Mason 1085d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zhengstruct btrfs_delayed_tree_ref { 10956bec294dea971335d4466b30f2d959f28f6e36dChris Mason struct btrfs_delayed_ref_node node; 110eebe063b7f916087cd5c61de57b20a3a30894a96Arne Jansen u64 root; 111eebe063b7f916087cd5c61de57b20a3a30894a96Arne Jansen u64 parent; 1125d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng int level; 1135d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng}; 11456bec294dea971335d4466b30f2d959f28f6e36dChris Mason 1155d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zhengstruct btrfs_delayed_data_ref { 1165d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng struct btrfs_delayed_ref_node node; 117eebe063b7f916087cd5c61de57b20a3a30894a96Arne Jansen u64 root; 118eebe063b7f916087cd5c61de57b20a3a30894a96Arne Jansen u64 parent; 1195d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 objectid; 1205d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 offset; 12156bec294dea971335d4466b30f2d959f28f6e36dChris Mason}; 12256bec294dea971335d4466b30f2d959f28f6e36dChris Mason 12356bec294dea971335d4466b30f2d959f28f6e36dChris Masonstruct btrfs_delayed_ref_root { 124c46effa601f869f3d20a7386a745d9c002838eb8Liu Bo /* head ref rbtree */ 125c46effa601f869f3d20a7386a745d9c002838eb8Liu Bo struct rb_root href_root; 126c46effa601f869f3d20a7386a745d9c002838eb8Liu Bo 12756bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* this spin lock protects the rbtree and the entries inside */ 12856bec294dea971335d4466b30f2d959f28f6e36dChris Mason spinlock_t lock; 12956bec294dea971335d4466b30f2d959f28f6e36dChris Mason 13056bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* how many delayed ref updates we've queued, used by the 13156bec294dea971335d4466b30f2d959f28f6e36dChris Mason * throttling code 13256bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 133d7df2c796d7eedd72a334dc89c65e1fec8171431Josef Bacik atomic_t num_entries; 13456bec294dea971335d4466b30f2d959f28f6e36dChris Mason 135c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason /* total number of head nodes in tree */ 136c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason unsigned long num_heads; 137c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason 138c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason /* total number of head nodes ready for processing */ 139c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason unsigned long num_heads_ready; 140c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason 14156bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* 14256bec294dea971335d4466b30f2d959f28f6e36dChris Mason * set when the tree is flushing before a transaction commit, 14356bec294dea971335d4466b30f2d959f28f6e36dChris Mason * used by the throttling code to decide if new updates need 14456bec294dea971335d4466b30f2d959f28f6e36dChris Mason * to be run right away 14556bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 14656bec294dea971335d4466b30f2d959f28f6e36dChris Mason int flushing; 147c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason 148c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason u64 run_delayed_start; 14956bec294dea971335d4466b30f2d959f28f6e36dChris Mason}; 15056bec294dea971335d4466b30f2d959f28f6e36dChris Mason 15178a6184a3ff9041280ee56273c01e5679a831b39Miao Xieextern struct kmem_cache *btrfs_delayed_ref_head_cachep; 15278a6184a3ff9041280ee56273c01e5679a831b39Miao Xieextern struct kmem_cache *btrfs_delayed_tree_ref_cachep; 15378a6184a3ff9041280ee56273c01e5679a831b39Miao Xieextern struct kmem_cache *btrfs_delayed_data_ref_cachep; 15478a6184a3ff9041280ee56273c01e5679a831b39Miao Xieextern struct kmem_cache *btrfs_delayed_extent_op_cachep; 15578a6184a3ff9041280ee56273c01e5679a831b39Miao Xie 15678a6184a3ff9041280ee56273c01e5679a831b39Miao Xieint btrfs_delayed_ref_init(void); 15778a6184a3ff9041280ee56273c01e5679a831b39Miao Xievoid btrfs_delayed_ref_exit(void); 15878a6184a3ff9041280ee56273c01e5679a831b39Miao Xie 15978a6184a3ff9041280ee56273c01e5679a831b39Miao Xiestatic inline struct btrfs_delayed_extent_op * 16078a6184a3ff9041280ee56273c01e5679a831b39Miao Xiebtrfs_alloc_delayed_extent_op(void) 16178a6184a3ff9041280ee56273c01e5679a831b39Miao Xie{ 16278a6184a3ff9041280ee56273c01e5679a831b39Miao Xie return kmem_cache_alloc(btrfs_delayed_extent_op_cachep, GFP_NOFS); 16378a6184a3ff9041280ee56273c01e5679a831b39Miao Xie} 16478a6184a3ff9041280ee56273c01e5679a831b39Miao Xie 16578a6184a3ff9041280ee56273c01e5679a831b39Miao Xiestatic inline void 16678a6184a3ff9041280ee56273c01e5679a831b39Miao Xiebtrfs_free_delayed_extent_op(struct btrfs_delayed_extent_op *op) 16778a6184a3ff9041280ee56273c01e5679a831b39Miao Xie{ 16878a6184a3ff9041280ee56273c01e5679a831b39Miao Xie if (op) 16978a6184a3ff9041280ee56273c01e5679a831b39Miao Xie kmem_cache_free(btrfs_delayed_extent_op_cachep, op); 17078a6184a3ff9041280ee56273c01e5679a831b39Miao Xie} 17178a6184a3ff9041280ee56273c01e5679a831b39Miao Xie 17256bec294dea971335d4466b30f2d959f28f6e36dChris Masonstatic inline void btrfs_put_delayed_ref(struct btrfs_delayed_ref_node *ref) 17356bec294dea971335d4466b30f2d959f28f6e36dChris Mason{ 17456bec294dea971335d4466b30f2d959f28f6e36dChris Mason WARN_ON(atomic_read(&ref->refs) == 0); 17556bec294dea971335d4466b30f2d959f28f6e36dChris Mason if (atomic_dec_and_test(&ref->refs)) { 17656bec294dea971335d4466b30f2d959f28f6e36dChris Mason WARN_ON(ref->in_tree); 17778a6184a3ff9041280ee56273c01e5679a831b39Miao Xie switch (ref->type) { 17878a6184a3ff9041280ee56273c01e5679a831b39Miao Xie case BTRFS_TREE_BLOCK_REF_KEY: 17978a6184a3ff9041280ee56273c01e5679a831b39Miao Xie case BTRFS_SHARED_BLOCK_REF_KEY: 18078a6184a3ff9041280ee56273c01e5679a831b39Miao Xie kmem_cache_free(btrfs_delayed_tree_ref_cachep, ref); 18178a6184a3ff9041280ee56273c01e5679a831b39Miao Xie break; 18278a6184a3ff9041280ee56273c01e5679a831b39Miao Xie case BTRFS_EXTENT_DATA_REF_KEY: 18378a6184a3ff9041280ee56273c01e5679a831b39Miao Xie case BTRFS_SHARED_DATA_REF_KEY: 18478a6184a3ff9041280ee56273c01e5679a831b39Miao Xie kmem_cache_free(btrfs_delayed_data_ref_cachep, ref); 18578a6184a3ff9041280ee56273c01e5679a831b39Miao Xie break; 18678a6184a3ff9041280ee56273c01e5679a831b39Miao Xie case 0: 18778a6184a3ff9041280ee56273c01e5679a831b39Miao Xie kmem_cache_free(btrfs_delayed_ref_head_cachep, ref); 18878a6184a3ff9041280ee56273c01e5679a831b39Miao Xie break; 18978a6184a3ff9041280ee56273c01e5679a831b39Miao Xie default: 19078a6184a3ff9041280ee56273c01e5679a831b39Miao Xie BUG(); 19178a6184a3ff9041280ee56273c01e5679a831b39Miao Xie } 19256bec294dea971335d4466b30f2d959f28f6e36dChris Mason } 19356bec294dea971335d4466b30f2d959f28f6e36dChris Mason} 19456bec294dea971335d4466b30f2d959f28f6e36dChris Mason 19566d7e7f09f77456fe68683247d77721032a00ee5Arne Jansenint btrfs_add_delayed_tree_ref(struct btrfs_fs_info *fs_info, 19666d7e7f09f77456fe68683247d77721032a00ee5Arne Jansen struct btrfs_trans_handle *trans, 1975d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 bytenr, u64 num_bytes, u64 parent, 1985d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 ref_root, int level, int action, 19966d7e7f09f77456fe68683247d77721032a00ee5Arne Jansen struct btrfs_delayed_extent_op *extent_op, 200fcebe4562dec83b3f8d3088d77584727b09130b2Josef Bacik int no_quota); 20166d7e7f09f77456fe68683247d77721032a00ee5Arne Jansenint btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info, 20266d7e7f09f77456fe68683247d77721032a00ee5Arne Jansen struct btrfs_trans_handle *trans, 2035d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 bytenr, u64 num_bytes, 2045d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 parent, u64 ref_root, 2055d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 owner, u64 offset, int action, 20666d7e7f09f77456fe68683247d77721032a00ee5Arne Jansen struct btrfs_delayed_extent_op *extent_op, 207fcebe4562dec83b3f8d3088d77584727b09130b2Josef Bacik int no_quota); 20866d7e7f09f77456fe68683247d77721032a00ee5Arne Jansenint btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info, 20966d7e7f09f77456fe68683247d77721032a00ee5Arne Jansen struct btrfs_trans_handle *trans, 2105d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 bytenr, u64 num_bytes, 2115d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng struct btrfs_delayed_extent_op *extent_op); 212ae1e206b806ccc490dadff59af8a7a2477b32884Josef Bacikvoid btrfs_merge_delayed_refs(struct btrfs_trans_handle *trans, 213ae1e206b806ccc490dadff59af8a7a2477b32884Josef Bacik struct btrfs_fs_info *fs_info, 214ae1e206b806ccc490dadff59af8a7a2477b32884Josef Bacik struct btrfs_delayed_ref_root *delayed_refs, 215ae1e206b806ccc490dadff59af8a7a2477b32884Josef Bacik struct btrfs_delayed_ref_head *head); 21656bec294dea971335d4466b30f2d959f28f6e36dChris Mason 2171887be66dcc3140a81d1299958a41fc0eedfa64fChris Masonstruct btrfs_delayed_ref_head * 2181887be66dcc3140a81d1299958a41fc0eedfa64fChris Masonbtrfs_find_delayed_ref_head(struct btrfs_trans_handle *trans, u64 bytenr); 219c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Masonint btrfs_delayed_ref_lock(struct btrfs_trans_handle *trans, 220c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason struct btrfs_delayed_ref_head *head); 221093486c453a55230ccdad4b48863b872fe68c46eMiao Xiestatic inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head) 222093486c453a55230ccdad4b48863b872fe68c46eMiao Xie{ 223093486c453a55230ccdad4b48863b872fe68c46eMiao Xie mutex_unlock(&head->mutex); 224093486c453a55230ccdad4b48863b872fe68c46eMiao Xie} 225093486c453a55230ccdad4b48863b872fe68c46eMiao Xie 226d7df2c796d7eedd72a334dc89c65e1fec8171431Josef Bacik 227d7df2c796d7eedd72a334dc89c65e1fec8171431Josef Bacikstruct btrfs_delayed_ref_head * 228d7df2c796d7eedd72a334dc89c65e1fec8171431Josef Bacikbtrfs_select_ref_head(struct btrfs_trans_handle *trans); 22900f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 230097b8a7c9e48e2cb50fd0eb9315791921beaf484Jan Schmidtint btrfs_check_delayed_seq(struct btrfs_fs_info *fs_info, 231097b8a7c9e48e2cb50fd0eb9315791921beaf484Jan Schmidt struct btrfs_delayed_ref_root *delayed_refs, 23200f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen u64 seq); 23300f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 23400f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen/* 23556bec294dea971335d4466b30f2d959f28f6e36dChris Mason * a node might live in a head or a regular ref, this lets you 23656bec294dea971335d4466b30f2d959f28f6e36dChris Mason * test for the proper type to use. 23756bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 23856bec294dea971335d4466b30f2d959f28f6e36dChris Masonstatic int btrfs_delayed_ref_is_head(struct btrfs_delayed_ref_node *node) 23956bec294dea971335d4466b30f2d959f28f6e36dChris Mason{ 2405d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng return node->is_head; 24156bec294dea971335d4466b30f2d959f28f6e36dChris Mason} 24256bec294dea971335d4466b30f2d959f28f6e36dChris Mason 24356bec294dea971335d4466b30f2d959f28f6e36dChris Mason/* 24456bec294dea971335d4466b30f2d959f28f6e36dChris Mason * helper functions to cast a node into its container 24556bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 2465d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zhengstatic inline struct btrfs_delayed_tree_ref * 2475d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zhengbtrfs_delayed_node_to_tree_ref(struct btrfs_delayed_ref_node *node) 24856bec294dea971335d4466b30f2d959f28f6e36dChris Mason{ 24956bec294dea971335d4466b30f2d959f28f6e36dChris Mason WARN_ON(btrfs_delayed_ref_is_head(node)); 2505d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng return container_of(node, struct btrfs_delayed_tree_ref, node); 2515d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng} 25256bec294dea971335d4466b30f2d959f28f6e36dChris Mason 2535d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zhengstatic inline struct btrfs_delayed_data_ref * 2545d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zhengbtrfs_delayed_node_to_data_ref(struct btrfs_delayed_ref_node *node) 2555d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng{ 2565d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng WARN_ON(btrfs_delayed_ref_is_head(node)); 2575d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng return container_of(node, struct btrfs_delayed_data_ref, node); 25856bec294dea971335d4466b30f2d959f28f6e36dChris Mason} 25956bec294dea971335d4466b30f2d959f28f6e36dChris Mason 26056bec294dea971335d4466b30f2d959f28f6e36dChris Masonstatic inline struct btrfs_delayed_ref_head * 26156bec294dea971335d4466b30f2d959f28f6e36dChris Masonbtrfs_delayed_node_to_head(struct btrfs_delayed_ref_node *node) 26256bec294dea971335d4466b30f2d959f28f6e36dChris Mason{ 26356bec294dea971335d4466b30f2d959f28f6e36dChris Mason WARN_ON(!btrfs_delayed_ref_is_head(node)); 26456bec294dea971335d4466b30f2d959f28f6e36dChris Mason return container_of(node, struct btrfs_delayed_ref_head, node); 26556bec294dea971335d4466b30f2d959f28f6e36dChris Mason} 26656bec294dea971335d4466b30f2d959f28f6e36dChris Mason#endif 267