Skip to content

Commit add9c20

Browse files
committed
Merge branch 'b-for-next' into for-next-next-v6.10-20240607
# Conflicts: # fs/btrfs/btrfs_inode.h # fs/btrfs/file.c
2 parents 6a646d7 + 481cfcc commit add9c20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2691
-2199
lines changed

fs/btrfs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
3333
uuid-tree.o props.o free-space-tree.o tree-checker.o space-info.o \
3434
block-rsv.o delalloc-space.o block-group.o discard.o reflink.o \
3535
subpage.o tree-mod-log.o extent-io-tree.o fs.o messages.o bio.o \
36-
lru_cache.o raid-stripe-tree.o
36+
lru_cache.o raid-stripe-tree.o fiemap.o
3737

3838
btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o
3939
btrfs-$(CONFIG_BTRFS_FS_REF_VERIFY) += ref-verify.o

fs/btrfs/accessors.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void btrfs_init_map_token(struct btrfs_map_token *token, struct extent_buffer *e
3434

3535
static inline u8 get_unaligned_le8(const void *p)
3636
{
37-
return *(u8 *)p;
37+
return *(const u8 *)p;
3838
}
3939

4040
static inline void put_unaligned_le8(u8 val, void *p)
@@ -48,8 +48,8 @@ static inline void put_unaligned_le8(u8 val, void *p)
4848
offsetof(type, member), \
4949
sizeof_field(type, member)))
5050

51-
#define write_eb_member(eb, ptr, type, member, result) (\
52-
write_extent_buffer(eb, (char *)(result), \
51+
#define write_eb_member(eb, ptr, type, member, source) ( \
52+
write_extent_buffer(eb, (const char *)(source), \
5353
((unsigned long)(ptr)) + \
5454
offsetof(type, member), \
5555
sizeof_field(type, member)))
@@ -353,7 +353,7 @@ static inline void btrfs_tree_block_key(const struct extent_buffer *eb,
353353

354354
static inline void btrfs_set_tree_block_key(const struct extent_buffer *eb,
355355
struct btrfs_tree_block_info *item,
356-
struct btrfs_disk_key *key)
356+
const struct btrfs_disk_key *key)
357357
{
358358
write_eb_member(eb, item, struct btrfs_tree_block_info, key, key);
359359
}
@@ -446,7 +446,7 @@ void btrfs_node_key(const struct extent_buffer *eb,
446446
struct btrfs_disk_key *disk_key, int nr);
447447

448448
static inline void btrfs_set_node_key(const struct extent_buffer *eb,
449-
struct btrfs_disk_key *disk_key, int nr)
449+
const struct btrfs_disk_key *disk_key, int nr)
450450
{
451451
unsigned long ptr;
452452

@@ -512,7 +512,7 @@ static inline void btrfs_item_key(const struct extent_buffer *eb,
512512
}
513513

514514
static inline void btrfs_set_item_key(struct extent_buffer *eb,
515-
struct btrfs_disk_key *disk_key, int nr)
515+
const struct btrfs_disk_key *disk_key, int nr)
516516
{
517517
struct btrfs_item *item = btrfs_item_nr(eb, nr);
518518

fs/btrfs/block-group.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,13 @@ static void clear_incompat_bg_bits(struct btrfs_fs_info *fs_info, u64 flags)
10221022
}
10231023
}
10241024

1025+
static struct btrfs_root *btrfs_block_group_root(struct btrfs_fs_info *fs_info)
1026+
{
1027+
if (btrfs_fs_compat_ro(fs_info, BLOCK_GROUP_TREE))
1028+
return fs_info->block_group_root;
1029+
return btrfs_extent_root(fs_info, 0);
1030+
}
1031+
10251032
static int remove_block_group_item(struct btrfs_trans_handle *trans,
10261033
struct btrfs_path *path,
10271034
struct btrfs_block_group *block_group)

fs/btrfs/btrfs_inode.h

Lines changed: 99 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
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
*/
332376
static 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+
351410
static 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,
455514
bool btrfs_data_csum_ok(struct btrfs_bio *bbio, struct btrfs_device *dev,
456515
u32 bio_offset, struct bio_vec *bv);
457516
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);
460519

461520
void btrfs_del_delalloc_inode(struct btrfs_inode *inode);
462521
struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry);

fs/btrfs/compression.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void btrfs_free_compr_folio(struct folio *folio)
261261
folio_put(folio);
262262
}
263263

264-
static void end_bbio_comprssed_read(struct btrfs_bio *bbio)
264+
static void end_bbio_compressed_read(struct btrfs_bio *bbio)
265265
{
266266
struct compressed_bio *cb = to_compressed_bio(bbio);
267267
blk_status_t status = bbio->bio.bi_status;
@@ -334,7 +334,7 @@ static void btrfs_finish_compressed_write_work(struct work_struct *work)
334334
* This also calls the writeback end hooks for the file pages so that metadata
335335
* and checksums can be updated in the file.
336336
*/
337-
static void end_bbio_comprssed_write(struct btrfs_bio *bbio)
337+
static void end_bbio_compressed_write(struct btrfs_bio *bbio)
338338
{
339339
struct compressed_bio *cb = to_compressed_bio(bbio);
340340
struct btrfs_fs_info *fs_info = bbio->inode->root->fs_info;
@@ -383,7 +383,7 @@ void btrfs_submit_compressed_write(struct btrfs_ordered_extent *ordered,
383383

384384
cb = alloc_compressed_bio(inode, ordered->file_offset,
385385
REQ_OP_WRITE | write_flags,
386-
end_bbio_comprssed_write);
386+
end_bbio_compressed_write);
387387
cb->start = ordered->file_offset;
388388
cb->len = ordered->num_bytes;
389389
cb->compressed_folios = compressed_folios;
@@ -507,7 +507,8 @@ static noinline int add_ra_bio_pages(struct inode *inode,
507507
*/
508508
if (!em || cur < em->start ||
509509
(cur + fs_info->sectorsize > extent_map_end(em)) ||
510-
(em->block_start >> SECTOR_SHIFT) != orig_bio->bi_iter.bi_sector) {
510+
(extent_map_block_start(em) >> SECTOR_SHIFT) !=
511+
orig_bio->bi_iter.bi_sector) {
511512
free_extent_map(em);
512513
unlock_extent(tree, cur, page_end, NULL);
513514
unlock_page(page);
@@ -585,12 +586,12 @@ void btrfs_submit_compressed_read(struct btrfs_bio *bbio)
585586
}
586587

587588
ASSERT(extent_map_is_compressed(em));
588-
compressed_len = em->block_len;
589+
compressed_len = em->disk_num_bytes;
589590

590591
cb = alloc_compressed_bio(inode, file_offset, REQ_OP_READ,
591-
end_bbio_comprssed_read);
592+
end_bbio_compressed_read);
592593

593-
cb->start = em->orig_start;
594+
cb->start = em->start - em->offset;
594595
em_len = em->len;
595596
em_start = em->start;
596597

fs/btrfs/ctree.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,11 @@ struct btrfs_root {
221221

222222
struct list_head root_list;
223223

224-
spinlock_t inode_lock;
225-
/* red-black tree that keeps track of in-memory inodes */
226-
struct rb_root inode_tree;
224+
/*
225+
* Xarray that keeps track of in-memory inodes, protected by the lock
226+
* @inode_lock.
227+
*/
228+
struct xarray inodes;
227229

228230
/*
229231
* Xarray that keeps track of delayed nodes of every inode, protected

0 commit comments

Comments
 (0)