1919#include <uapi/linux/btrfs_tree.h>
2020#include <trace/events/btrfs.h>
2121#include "block-rsv.h"
22- #include "btrfs_inode.h"
2322#include "extent_map.h"
2423#include "extent_io.h"
2524#include "extent-io-tree.h"
@@ -89,6 +88,29 @@ enum {
8988 BTRFS_INODE_FREE_SPACE_INODE ,
9089 /* Set when there are no capabilities in XATTs for the inode. */
9190 BTRFS_INODE_NO_CAP_XATTR ,
91+ /*
92+ * Indicate this is a directory that points to a subvolume for which
93+ * there is no root reference item. That's a case like the following:
94+ *
95+ * $ btrfs subvolume create /mnt/parent
96+ * $ btrfs subvolume create /mnt/parent/child
97+ * $ btrfs subvolume snapshot /mnt/parent /mnt/snap
98+ *
99+ * If subvolume "parent" is root 256, subvolume "child" is root 257 and
100+ * snapshot "snap" is root 258, then there's no root reference item (key
101+ * BTRFS_ROOT_REF_KEY in the root tree) for the subvolume "child"
102+ * associated to root 258 (the snapshot) - there's only for the root
103+ * of the "parent" subvolume (root 256). In the chunk root we have a
104+ * (256 BTRFS_ROOT_REF_KEY 257) key but we don't have a
105+ * (258 BTRFS_ROOT_REF_KEY 257) key - the sames goes for backrefs, we
106+ * have a (257 BTRFS_ROOT_BACKREF_KEY 256) but we don't have a
107+ * (257 BTRFS_ROOT_BACKREF_KEY 258) key.
108+ *
109+ * So when opening the "child" dentry from the snapshot's directory,
110+ * we don't find a root ref item and we create a stub inode. This is
111+ * done at new_simple_dir(), called from btrfs_lookup_dentry().
112+ */
113+ BTRFS_INODE_ROOT_STUB ,
92114 /*
93115 * Set if an error happened when doing a COW write before submitting a
94116 * bio or during writeback. Used for both buffered writes and direct IO
@@ -106,10 +128,14 @@ struct btrfs_inode {
106128 /* which subvolume this inode belongs to */
107129 struct btrfs_root * root ;
108130
109- /* key used to find this inode on disk. This is used by the code
110- * to read in roots of subvolumes
131+ #if BITS_PER_LONG == 32
132+ /*
133+ * The objectid of the corresponding BTRFS_INODE_ITEM_KEY.
134+ * On 64 bits platforms we can get it from vfs_inode.i_ino, which is an
135+ * unsigned long and therefore 64 bits on such platforms.
111136 */
112- struct btrfs_key location ;
137+ u64 objectid ;
138+ #endif
113139
114140 /* Cached value of inode property 'compression'. */
115141 u8 prop_compress ;
@@ -165,9 +191,6 @@ struct btrfs_inode {
165191 */
166192 struct list_head delalloc_inodes ;
167193
168- /* node for the red-black tree that links inodes in subvolume root */
169- struct rb_node rb_node ;
170-
171194 unsigned long runtime_flags ;
172195
173196 /* full 64 bit generation number, struct vfs_inode doesn't have a big
@@ -228,11 +251,20 @@ struct btrfs_inode {
228251 u64 last_dir_index_offset ;
229252 };
230253
231- /*
232- * Total number of bytes pending defrag, used by stat to check whether
233- * it needs COW. Protected by 'lock'.
234- */
235- u64 defrag_bytes ;
254+ union {
255+ /*
256+ * Total number of bytes pending defrag, used by stat to check whether
257+ * it needs COW. Protected by 'lock'.
258+ * Used by inodes other than the data relocation inode.
259+ */
260+ u64 defrag_bytes ;
261+
262+ /*
263+ * Logical address of the block group being relocated.
264+ * Used only by the data relocation inode.
265+ */
266+ u64 reloc_block_group_start ;
267+ };
236268
237269 /*
238270 * The size of the file stored in the metadata on disk. data=ordered
@@ -241,12 +273,21 @@ struct btrfs_inode {
241273 */
242274 u64 disk_i_size ;
243275
244- /*
245- * If this is a directory then index_cnt is the counter for the index
246- * number for new files that are created. For an empty directory, this
247- * must be initialized to BTRFS_DIR_START_INDEX.
248- */
249- u64 index_cnt ;
276+ union {
277+ /*
278+ * If this is a directory then index_cnt is the counter for the
279+ * index number for new files that are created. For an empty
280+ * directory, this must be initialized to BTRFS_DIR_START_INDEX.
281+ */
282+ u64 index_cnt ;
283+
284+ /*
285+ * If this is not a directory, this is the number of bytes
286+ * outstanding that are going to need csums. This is used in
287+ * ENOSPC accounting. Protected by 'lock'.
288+ */
289+ u64 csum_bytes ;
290+ };
250291
251292 /* Cache the directory index number to speed the dir/file remove */
252293 u64 dir_index ;
@@ -258,22 +299,25 @@ struct btrfs_inode {
258299 */
259300 u64 last_unlink_trans ;
260301
261- /*
262- * The id/generation of the last transaction where this inode was
263- * either the source or the destination of a clone/dedupe operation.
264- * Used when logging an inode to know if there are shared extents that
265- * need special care when logging checksum items, to avoid duplicate
266- * checksum items in a log (which can lead to a corruption where we end
267- * up with missing checksum ranges after log replay).
268- * Protected by the vfs inode lock.
269- */
270- u64 last_reflink_trans ;
302+ union {
303+ /*
304+ * The id/generation of the last transaction where this inode
305+ * was either the source or the destination of a clone/dedupe
306+ * operation. Used when logging an inode to know if there are
307+ * shared extents that need special care when logging checksum
308+ * items, to avoid duplicate checksum items in a log (which can
309+ * lead to a corruption where we end up with missing checksum
310+ * ranges after log replay). Protected by the VFS inode lock.
311+ * Used for regular files only.
312+ */
313+ u64 last_reflink_trans ;
271314
272- /*
273- * Number of bytes outstanding that are going to need csums. This is
274- * used in ENOSPC accounting. Protected by 'lock'.
275- */
276- u64 csum_bytes ;
315+ /*
316+ * In case this a root stub inode (BTRFS_INODE_ROOT_STUB flag set),
317+ * the ID of that root.
318+ */
319+ u64 ref_root_id ;
320+ };
277321
278322 /* Backwards incompatible flags, lower half of inode_item::flags */
279323 u32 flags ;
@@ -331,10 +375,9 @@ static inline unsigned long btrfs_inode_hash(u64 objectid,
331375 */
332376static inline u64 btrfs_ino (const struct btrfs_inode * inode )
333377{
334- u64 ino = inode -> location . objectid ;
378+ u64 ino = inode -> objectid ;
335379
336- /* type == BTRFS_ROOT_ITEM_KEY: subvol dir */
337- if (inode -> location .type == BTRFS_ROOT_ITEM_KEY )
380+ if (test_bit (BTRFS_INODE_ROOT_STUB , & inode -> runtime_flags ))
338381 ino = inode -> vfs_inode .i_ino ;
339382 return ino ;
340383}
@@ -348,18 +391,34 @@ static inline u64 btrfs_ino(const struct btrfs_inode *inode)
348391
349392#endif
350393
394+ static inline void btrfs_get_inode_key (const struct btrfs_inode * inode ,
395+ struct btrfs_key * key )
396+ {
397+ key -> objectid = btrfs_ino (inode );
398+ key -> type = BTRFS_INODE_ITEM_KEY ;
399+ key -> offset = 0 ;
400+ }
401+
402+ static inline void btrfs_set_inode_number (struct btrfs_inode * inode , u64 ino )
403+ {
404+ #if BITS_PER_LONG == 32
405+ inode -> objectid = ino ;
406+ #endif
407+ inode -> vfs_inode .i_ino = ino ;
408+ }
409+
351410static inline void btrfs_i_size_write (struct btrfs_inode * inode , u64 size )
352411{
353412 i_size_write (& inode -> vfs_inode , size );
354413 inode -> disk_i_size = size ;
355414}
356415
357- static inline bool btrfs_is_free_space_inode (struct btrfs_inode * inode )
416+ static inline bool btrfs_is_free_space_inode (const struct btrfs_inode * inode )
358417{
359418 return test_bit (BTRFS_INODE_FREE_SPACE_INODE , & inode -> runtime_flags );
360419}
361420
362- static inline bool is_data_inode (struct inode * inode )
421+ static inline bool is_data_inode (const struct inode * inode )
363422{
364423 return btrfs_ino (BTRFS_I (inode )) != BTRFS_BTREE_INODE_OBJECTID ;
365424}
@@ -455,8 +514,8 @@ int btrfs_check_sector_csum(struct btrfs_fs_info *fs_info, struct page *page,
455514bool btrfs_data_csum_ok (struct btrfs_bio * bbio , struct btrfs_device * dev ,
456515 u32 bio_offset , struct bio_vec * bv );
457516noinline int can_nocow_extent (struct inode * inode , u64 offset , u64 * len ,
458- u64 * orig_start , u64 * orig_block_len ,
459- u64 * ram_bytes , bool nowait , bool strict );
517+ struct btrfs_file_extent * file_extent ,
518+ bool nowait , bool strict );
460519
461520void btrfs_del_delalloc_inode (struct btrfs_inode * inode );
462521struct inode * btrfs_lookup_dentry (struct inode * dir , struct dentry * dentry );
0 commit comments