19
19
#include <uapi/linux/btrfs_tree.h>
20
20
#include <trace/events/btrfs.h>
21
21
#include "block-rsv.h"
22
- #include "btrfs_inode.h"
23
22
#include "extent_map.h"
24
23
#include "extent_io.h"
25
24
#include "extent-io-tree.h"
@@ -89,6 +88,29 @@ enum {
89
88
BTRFS_INODE_FREE_SPACE_INODE ,
90
89
/* Set when there are no capabilities in XATTs for the inode. */
91
90
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 ,
92
114
/*
93
115
* Set if an error happened when doing a COW write before submitting a
94
116
* bio or during writeback. Used for both buffered writes and direct IO
@@ -106,10 +128,14 @@ struct btrfs_inode {
106
128
/* which subvolume this inode belongs to */
107
129
struct btrfs_root * root ;
108
130
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.
111
136
*/
112
- struct btrfs_key location ;
137
+ u64 objectid ;
138
+ #endif
113
139
114
140
/* Cached value of inode property 'compression'. */
115
141
u8 prop_compress ;
@@ -165,9 +191,6 @@ struct btrfs_inode {
165
191
*/
166
192
struct list_head delalloc_inodes ;
167
193
168
- /* node for the red-black tree that links inodes in subvolume root */
169
- struct rb_node rb_node ;
170
-
171
194
unsigned long runtime_flags ;
172
195
173
196
/* full 64 bit generation number, struct vfs_inode doesn't have a big
@@ -228,11 +251,20 @@ struct btrfs_inode {
228
251
u64 last_dir_index_offset ;
229
252
};
230
253
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
+ };
236
268
237
269
/*
238
270
* The size of the file stored in the metadata on disk. data=ordered
@@ -241,12 +273,21 @@ struct btrfs_inode {
241
273
*/
242
274
u64 disk_i_size ;
243
275
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
+ };
250
291
251
292
/* Cache the directory index number to speed the dir/file remove */
252
293
u64 dir_index ;
@@ -258,22 +299,25 @@ struct btrfs_inode {
258
299
*/
259
300
u64 last_unlink_trans ;
260
301
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 ;
271
314
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
+ };
277
321
278
322
/* Backwards incompatible flags, lower half of inode_item::flags */
279
323
u32 flags ;
@@ -331,10 +375,9 @@ static inline unsigned long btrfs_inode_hash(u64 objectid,
331
375
*/
332
376
static inline u64 btrfs_ino (const struct btrfs_inode * inode )
333
377
{
334
- u64 ino = inode -> location . objectid ;
378
+ u64 ino = inode -> objectid ;
335
379
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 ))
338
381
ino = inode -> vfs_inode .i_ino ;
339
382
return ino ;
340
383
}
@@ -348,18 +391,34 @@ static inline u64 btrfs_ino(const struct btrfs_inode *inode)
348
391
349
392
#endif
350
393
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
+
351
410
static inline void btrfs_i_size_write (struct btrfs_inode * inode , u64 size )
352
411
{
353
412
i_size_write (& inode -> vfs_inode , size );
354
413
inode -> disk_i_size = size ;
355
414
}
356
415
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 )
358
417
{
359
418
return test_bit (BTRFS_INODE_FREE_SPACE_INODE , & inode -> runtime_flags );
360
419
}
361
420
362
- static inline bool is_data_inode (struct inode * inode )
421
+ static inline bool is_data_inode (const struct inode * inode )
363
422
{
364
423
return btrfs_ino (BTRFS_I (inode )) != BTRFS_BTREE_INODE_OBJECTID ;
365
424
}
@@ -455,8 +514,8 @@ int btrfs_check_sector_csum(struct btrfs_fs_info *fs_info, struct page *page,
455
514
bool btrfs_data_csum_ok (struct btrfs_bio * bbio , struct btrfs_device * dev ,
456
515
u32 bio_offset , struct bio_vec * bv );
457
516
noinline 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 );
460
519
461
520
void btrfs_del_delalloc_inode (struct btrfs_inode * inode );
462
521
struct inode * btrfs_lookup_dentry (struct inode * dir , struct dentry * dentry );
0 commit comments