delayed-ref.h revision 00f04b88791ff49dc64ada18819d40a5b0671709
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 2156bec294dea971335d4466b30f2d959f28f6e36dChris Mason/* these are the possible values of struct btrfs_delayed_ref->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; 5556bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* is this node still in the rbtree? */ 565d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng unsigned int is_head:1; 5756bec294dea971335d4466b30f2d959f28f6e36dChris Mason unsigned int in_tree:1; 5856bec294dea971335d4466b30f2d959f28f6e36dChris Mason}; 5956bec294dea971335d4466b30f2d959f28f6e36dChris Mason 605d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zhengstruct btrfs_delayed_extent_op { 615d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng struct btrfs_disk_key key; 625d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 flags_to_set; 635d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng unsigned int update_key:1; 645d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng unsigned int update_flags:1; 655d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng unsigned int is_data:1; 665d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng}; 675d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng 6856bec294dea971335d4466b30f2d959f28f6e36dChris Mason/* 6956bec294dea971335d4466b30f2d959f28f6e36dChris Mason * the head refs are used to hold a lock on a given extent, which allows us 7056bec294dea971335d4466b30f2d959f28f6e36dChris Mason * to make sure that only one process is running the delayed refs 7156bec294dea971335d4466b30f2d959f28f6e36dChris Mason * at a time for a single extent. They also store the sum of all the 7256bec294dea971335d4466b30f2d959f28f6e36dChris Mason * reference count modifications we've queued up. 7356bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 7456bec294dea971335d4466b30f2d959f28f6e36dChris Masonstruct btrfs_delayed_ref_head { 7556bec294dea971335d4466b30f2d959f28f6e36dChris Mason struct btrfs_delayed_ref_node node; 7656bec294dea971335d4466b30f2d959f28f6e36dChris Mason 7756bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* 7856bec294dea971335d4466b30f2d959f28f6e36dChris Mason * the mutex is held while running the refs, and it is also 7956bec294dea971335d4466b30f2d959f28f6e36dChris Mason * held when checking the sum of reference modifications. 8056bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 8156bec294dea971335d4466b30f2d959f28f6e36dChris Mason struct mutex mutex; 8256bec294dea971335d4466b30f2d959f28f6e36dChris Mason 83c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason struct list_head cluster; 84c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason 855d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng struct btrfs_delayed_extent_op *extent_op; 8656bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* 8756bec294dea971335d4466b30f2d959f28f6e36dChris Mason * when a new extent is allocated, it is just reserved in memory 8856bec294dea971335d4466b30f2d959f28f6e36dChris Mason * The actual extent isn't inserted into the extent allocation tree 8956bec294dea971335d4466b30f2d959f28f6e36dChris Mason * until the delayed ref is processed. must_insert_reserved is 9056bec294dea971335d4466b30f2d959f28f6e36dChris Mason * used to flag a delayed ref so the accounting can be updated 9156bec294dea971335d4466b30f2d959f28f6e36dChris Mason * when a full insert is done. 9256bec294dea971335d4466b30f2d959f28f6e36dChris Mason * 9356bec294dea971335d4466b30f2d959f28f6e36dChris Mason * It is possible the extent will be freed before it is ever 9456bec294dea971335d4466b30f2d959f28f6e36dChris Mason * inserted into the extent allocation tree. In this case 9556bec294dea971335d4466b30f2d959f28f6e36dChris Mason * we need to update the in ram accounting to properly reflect 9656bec294dea971335d4466b30f2d959f28f6e36dChris Mason * the free has happened. 9756bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 9856bec294dea971335d4466b30f2d959f28f6e36dChris Mason unsigned int must_insert_reserved:1; 995d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng unsigned int is_data:1; 10056bec294dea971335d4466b30f2d959f28f6e36dChris Mason}; 10156bec294dea971335d4466b30f2d959f28f6e36dChris Mason 1025d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zhengstruct btrfs_delayed_tree_ref { 10356bec294dea971335d4466b30f2d959f28f6e36dChris Mason struct btrfs_delayed_ref_node node; 104eebe063b7f916087cd5c61de57b20a3a30894a96Arne Jansen u64 root; 105eebe063b7f916087cd5c61de57b20a3a30894a96Arne Jansen u64 parent; 1065d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng int level; 1075d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng}; 10856bec294dea971335d4466b30f2d959f28f6e36dChris Mason 1095d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zhengstruct btrfs_delayed_data_ref { 1105d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng struct btrfs_delayed_ref_node node; 111eebe063b7f916087cd5c61de57b20a3a30894a96Arne Jansen u64 root; 112eebe063b7f916087cd5c61de57b20a3a30894a96Arne Jansen u64 parent; 1135d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 objectid; 1145d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 offset; 11556bec294dea971335d4466b30f2d959f28f6e36dChris Mason}; 11656bec294dea971335d4466b30f2d959f28f6e36dChris Mason 11756bec294dea971335d4466b30f2d959f28f6e36dChris Masonstruct btrfs_delayed_ref_root { 11856bec294dea971335d4466b30f2d959f28f6e36dChris Mason struct rb_root root; 11956bec294dea971335d4466b30f2d959f28f6e36dChris Mason 12056bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* this spin lock protects the rbtree and the entries inside */ 12156bec294dea971335d4466b30f2d959f28f6e36dChris Mason spinlock_t lock; 12256bec294dea971335d4466b30f2d959f28f6e36dChris Mason 12356bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* how many delayed ref updates we've queued, used by the 12456bec294dea971335d4466b30f2d959f28f6e36dChris Mason * throttling code 12556bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 12656bec294dea971335d4466b30f2d959f28f6e36dChris Mason unsigned long num_entries; 12756bec294dea971335d4466b30f2d959f28f6e36dChris Mason 128c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason /* total number of head nodes in tree */ 129c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason unsigned long num_heads; 130c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason 131c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason /* total number of head nodes ready for processing */ 132c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason unsigned long num_heads_ready; 133c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason 13456bec294dea971335d4466b30f2d959f28f6e36dChris Mason /* 13556bec294dea971335d4466b30f2d959f28f6e36dChris Mason * set when the tree is flushing before a transaction commit, 13656bec294dea971335d4466b30f2d959f28f6e36dChris Mason * used by the throttling code to decide if new updates need 13756bec294dea971335d4466b30f2d959f28f6e36dChris Mason * to be run right away 13856bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 13956bec294dea971335d4466b30f2d959f28f6e36dChris Mason int flushing; 140c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason 141c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason u64 run_delayed_start; 14200f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 14300f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen /* 14400f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen * seq number of delayed refs. We need to know if a backref was being 14500f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen * added before the currently processed ref or afterwards. 14600f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen */ 14700f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen u64 seq; 14800f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 14900f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen /* 15000f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen * seq_list holds a list of all seq numbers that are currently being 15100f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen * added to the list. While walking backrefs (btrfs_find_all_roots, 15200f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen * qgroups), which might take some time, no newer ref must be processed, 15300f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen * as it might influence the outcome of the walk. 15400f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen */ 15500f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen struct list_head seq_head; 15656bec294dea971335d4466b30f2d959f28f6e36dChris Mason}; 15756bec294dea971335d4466b30f2d959f28f6e36dChris Mason 15856bec294dea971335d4466b30f2d959f28f6e36dChris Masonstatic inline void btrfs_put_delayed_ref(struct btrfs_delayed_ref_node *ref) 15956bec294dea971335d4466b30f2d959f28f6e36dChris Mason{ 16056bec294dea971335d4466b30f2d959f28f6e36dChris Mason WARN_ON(atomic_read(&ref->refs) == 0); 16156bec294dea971335d4466b30f2d959f28f6e36dChris Mason if (atomic_dec_and_test(&ref->refs)) { 16256bec294dea971335d4466b30f2d959f28f6e36dChris Mason WARN_ON(ref->in_tree); 16356bec294dea971335d4466b30f2d959f28f6e36dChris Mason kfree(ref); 16456bec294dea971335d4466b30f2d959f28f6e36dChris Mason } 16556bec294dea971335d4466b30f2d959f28f6e36dChris Mason} 16656bec294dea971335d4466b30f2d959f28f6e36dChris Mason 16766d7e7f09f77456fe68683247d77721032a00ee5Arne Jansenint btrfs_add_delayed_tree_ref(struct btrfs_fs_info *fs_info, 16866d7e7f09f77456fe68683247d77721032a00ee5Arne Jansen struct btrfs_trans_handle *trans, 1695d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 bytenr, u64 num_bytes, u64 parent, 1705d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 ref_root, int level, int action, 17166d7e7f09f77456fe68683247d77721032a00ee5Arne Jansen struct btrfs_delayed_extent_op *extent_op, 17266d7e7f09f77456fe68683247d77721032a00ee5Arne Jansen int for_cow); 17366d7e7f09f77456fe68683247d77721032a00ee5Arne Jansenint btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info, 17466d7e7f09f77456fe68683247d77721032a00ee5Arne Jansen struct btrfs_trans_handle *trans, 1755d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 bytenr, u64 num_bytes, 1765d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 parent, u64 ref_root, 1775d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 owner, u64 offset, int action, 17866d7e7f09f77456fe68683247d77721032a00ee5Arne Jansen struct btrfs_delayed_extent_op *extent_op, 17966d7e7f09f77456fe68683247d77721032a00ee5Arne Jansen int for_cow); 18066d7e7f09f77456fe68683247d77721032a00ee5Arne Jansenint btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info, 18166d7e7f09f77456fe68683247d77721032a00ee5Arne Jansen struct btrfs_trans_handle *trans, 1825d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng u64 bytenr, u64 num_bytes, 1835d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng struct btrfs_delayed_extent_op *extent_op); 18456bec294dea971335d4466b30f2d959f28f6e36dChris Mason 1851887be66dcc3140a81d1299958a41fc0eedfa64fChris Masonstruct btrfs_delayed_ref_head * 1861887be66dcc3140a81d1299958a41fc0eedfa64fChris Masonbtrfs_find_delayed_ref_head(struct btrfs_trans_handle *trans, u64 bytenr); 187c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Masonint btrfs_delayed_ref_lock(struct btrfs_trans_handle *trans, 188c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason struct btrfs_delayed_ref_head *head); 189c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Masonint btrfs_find_ref_cluster(struct btrfs_trans_handle *trans, 190c3e69d58e86c3917ae4e9e31b4acf490a7cafe60Chris Mason struct list_head *cluster, u64 search_start); 19100f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 19200f04b88791ff49dc64ada18819d40a5b0671709Arne Jansenstruct seq_list { 19300f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen struct list_head list; 19400f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen u64 seq; 19500f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen}; 19600f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 19700f04b88791ff49dc64ada18819d40a5b0671709Arne Jansenstatic inline u64 inc_delayed_seq(struct btrfs_delayed_ref_root *delayed_refs) 19800f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen{ 19900f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen assert_spin_locked(&delayed_refs->lock); 20000f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen ++delayed_refs->seq; 20100f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen return delayed_refs->seq; 20200f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen} 20300f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 20400f04b88791ff49dc64ada18819d40a5b0671709Arne Jansenstatic inline void 20500f04b88791ff49dc64ada18819d40a5b0671709Arne Jansenbtrfs_get_delayed_seq(struct btrfs_delayed_ref_root *delayed_refs, 20600f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen struct seq_list *elem) 20700f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen{ 20800f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen assert_spin_locked(&delayed_refs->lock); 20900f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen elem->seq = delayed_refs->seq; 21000f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen list_add_tail(&elem->list, &delayed_refs->seq_head); 21100f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen} 21200f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 21300f04b88791ff49dc64ada18819d40a5b0671709Arne Jansenstatic inline void 21400f04b88791ff49dc64ada18819d40a5b0671709Arne Jansenbtrfs_put_delayed_seq(struct btrfs_delayed_ref_root *delayed_refs, 21500f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen struct seq_list *elem) 21600f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen{ 21700f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen spin_lock(&delayed_refs->lock); 21800f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen list_del(&elem->list); 21900f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen spin_unlock(&delayed_refs->lock); 22000f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen} 22100f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 22200f04b88791ff49dc64ada18819d40a5b0671709Arne Jansenint btrfs_check_delayed_seq(struct btrfs_delayed_ref_root *delayed_refs, 22300f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen u64 seq); 22400f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 22500f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen/* 22600f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen * delayed refs with a ref_seq > 0 must be held back during backref walking. 22700f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen * this only applies to items in one of the fs-trees. for_cow items never need 22800f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen * to be held back, so they won't get a ref_seq number. 22900f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen */ 23000f04b88791ff49dc64ada18819d40a5b0671709Arne Jansenstatic inline int need_ref_seq(int for_cow, u64 rootid) 23100f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen{ 23200f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen if (for_cow) 23300f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen return 0; 23400f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 23500f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen if (rootid == BTRFS_FS_TREE_OBJECTID) 23600f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen return 1; 23700f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 23800f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen if ((s64)rootid >= (s64)BTRFS_FIRST_FREE_OBJECTID) 23900f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen return 1; 24000f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 24100f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen return 0; 24200f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen} 24300f04b88791ff49dc64ada18819d40a5b0671709Arne Jansen 24456bec294dea971335d4466b30f2d959f28f6e36dChris Mason/* 24556bec294dea971335d4466b30f2d959f28f6e36dChris Mason * a node might live in a head or a regular ref, this lets you 24656bec294dea971335d4466b30f2d959f28f6e36dChris Mason * test for the proper type to use. 24756bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 24856bec294dea971335d4466b30f2d959f28f6e36dChris Masonstatic int btrfs_delayed_ref_is_head(struct btrfs_delayed_ref_node *node) 24956bec294dea971335d4466b30f2d959f28f6e36dChris Mason{ 2505d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng return node->is_head; 25156bec294dea971335d4466b30f2d959f28f6e36dChris Mason} 25256bec294dea971335d4466b30f2d959f28f6e36dChris Mason 25356bec294dea971335d4466b30f2d959f28f6e36dChris Mason/* 25456bec294dea971335d4466b30f2d959f28f6e36dChris Mason * helper functions to cast a node into its container 25556bec294dea971335d4466b30f2d959f28f6e36dChris Mason */ 2565d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zhengstatic inline struct btrfs_delayed_tree_ref * 2575d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zhengbtrfs_delayed_node_to_tree_ref(struct btrfs_delayed_ref_node *node) 25856bec294dea971335d4466b30f2d959f28f6e36dChris Mason{ 25956bec294dea971335d4466b30f2d959f28f6e36dChris Mason WARN_ON(btrfs_delayed_ref_is_head(node)); 2605d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng return container_of(node, struct btrfs_delayed_tree_ref, node); 2615d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng} 26256bec294dea971335d4466b30f2d959f28f6e36dChris Mason 2635d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zhengstatic inline struct btrfs_delayed_data_ref * 2645d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zhengbtrfs_delayed_node_to_data_ref(struct btrfs_delayed_ref_node *node) 2655d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng{ 2665d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng WARN_ON(btrfs_delayed_ref_is_head(node)); 2675d4f98a28c7d334091c1b7744f48a1acdd2a4ae0Yan Zheng return container_of(node, struct btrfs_delayed_data_ref, node); 26856bec294dea971335d4466b30f2d959f28f6e36dChris Mason} 26956bec294dea971335d4466b30f2d959f28f6e36dChris Mason 27056bec294dea971335d4466b30f2d959f28f6e36dChris Masonstatic inline struct btrfs_delayed_ref_head * 27156bec294dea971335d4466b30f2d959f28f6e36dChris Masonbtrfs_delayed_node_to_head(struct btrfs_delayed_ref_node *node) 27256bec294dea971335d4466b30f2d959f28f6e36dChris Mason{ 27356bec294dea971335d4466b30f2d959f28f6e36dChris Mason WARN_ON(!btrfs_delayed_ref_is_head(node)); 27456bec294dea971335d4466b30f2d959f28f6e36dChris Mason return container_of(node, struct btrfs_delayed_ref_head, node); 27556bec294dea971335d4466b30f2d959f28f6e36dChris Mason} 27656bec294dea971335d4466b30f2d959f28f6e36dChris Mason#endif 277