From 825b55e7473d7458bd41e2773d15a64ebc062911 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Wed, 15 Oct 2025 13:38:09 -0400 Subject: [PATCH] Update bcachefs sources to caffe5f36f39 bcachefs: Compatibility with v6.18 Signed-off-by: Kent Overstreet --- .bcachefs_revision | 2 +- include/linux/blk_types.h | 12 +++++------- include/linux/slab.h | 1 + libbcachefs/btree/read.c | 3 ++- libbcachefs/journal/init.c | 6 +++--- libbcachefs/journal/read.c | 2 +- libbcachefs/sb/io.c | 2 +- libbcachefs/util/util.h | 14 ++++++++++++++ libbcachefs/vfs/ioctl.c | 13 ++++++++++--- linux/bio.c | 6 +++--- 10 files changed, 41 insertions(+), 20 deletions(-) diff --git a/.bcachefs_revision b/.bcachefs_revision index ac21ce2e..0973e434 100644 --- a/.bcachefs_revision +++ b/.bcachefs_revision @@ -1 +1 @@ -a3e0941d427cf4c0ae75f4afd5b525dddcf407a2 +caffe5f36f39ef62d58383b77dfdce931104f8c2 diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index b4495886..edef79e8 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -135,15 +135,13 @@ struct bio { struct bio_vec *bi_io_vec; /* the actual vec list */ struct bio_set *bi_pool; - - /* - * We can inline a number of vecs at the end of the bio, to avoid - * double allocations for a small number of bio_vecs. This member - * MUST obviously be kept at the very end of the bio. - */ - struct bio_vec bi_inline_vecs[0]; }; +static inline struct bio_vec *bio_inline_vecs(struct bio *bio) +{ + return (struct bio_vec *)(bio + 1); +} + #define BIO_RESET_BYTES offsetof(struct bio, bi_max_vecs) /* diff --git a/include/linux/slab.h b/include/linux/slab.h index 0aafd707..58fed0f5 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -116,6 +116,7 @@ static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags) DEFINE_FREE(kfree, void *, if (!IS_ERR_OR_NULL(_T)) kfree(_T)) #define kvmalloc(size, flags) kmalloc(size, flags) +#define kvmalloc_node_align_noprof(size, align, flags, node) kmalloc(size, flags) #define kvmalloc_noprof(size, flags) kmalloc(size, flags) #define kvzalloc(size, flags) kzalloc(size, flags) #define kvfree(p) kfree(p) diff --git a/libbcachefs/btree/read.c b/libbcachefs/btree/read.c index 61744581..41899bec 100644 --- a/libbcachefs/btree/read.c +++ b/libbcachefs/btree/read.c @@ -1227,6 +1227,7 @@ struct btree_node_scrub { struct work_struct work; struct bio bio; + struct bio_vec inline_vecs[]; }; static bool btree_node_scrub_check(struct bch_fs *c, struct btree_node *data, unsigned ptr_written, @@ -1368,7 +1369,7 @@ int bch2_btree_node_scrub(struct btree_trans *trans, INIT_WORK(&scrub->work, btree_node_scrub_work); - bio_init(&scrub->bio, ca->disk_sb.bdev, scrub->bio.bi_inline_vecs, vecs, REQ_OP_READ); + bio_init(&scrub->bio, ca->disk_sb.bdev, scrub->inline_vecs, vecs, REQ_OP_READ); bch2_bio_map(&scrub->bio, scrub->buf, c->opts.btree_node_size); scrub->bio.bi_iter.bi_sector = pick.ptr.offset; scrub->bio.bi_end_io = btree_node_scrub_endio; diff --git a/libbcachefs/journal/init.c b/libbcachefs/journal/init.c index fb73ee00..1837fd81 100644 --- a/libbcachefs/journal/init.c +++ b/libbcachefs/journal/init.c @@ -533,14 +533,14 @@ int bch2_dev_journal_init(struct bch_dev *ca, struct bch_sb *sb) * performance can be sensitive to anything that affects journal * pipelining. */ - ja->bio[i] = kvzalloc(struct_size(ja->bio[i], bio.bi_inline_vecs, - nr_bvecs), GFP_KERNEL); + ja->bio[i] = kvzalloc(sizeof(struct bio) + sizeof(struct bio_vec) * nr_bvecs, + GFP_KERNEL); if (!ja->bio[i]) return bch_err_throw(c, ENOMEM_dev_journal_init); ja->bio[i]->ca = ca; ja->bio[i]->buf_idx = i; - bio_init(&ja->bio[i]->bio, NULL, ja->bio[i]->bio.bi_inline_vecs, nr_bvecs, 0); + bio_init(&ja->bio[i]->bio, NULL, bio_inline_vecs(&ja->bio[i]->bio), nr_bvecs, 0); } ja->buckets = kcalloc(ja->nr, sizeof(u64), GFP_KERNEL); diff --git a/libbcachefs/journal/read.c b/libbcachefs/journal/read.c index bdb91ba4..e516c3db 100644 --- a/libbcachefs/journal/read.c +++ b/libbcachefs/journal/read.c @@ -1080,7 +1080,7 @@ reread: bio = bio_kmalloc(nr_bvecs, GFP_KERNEL); if (!bio) return bch_err_throw(c, ENOMEM_journal_read_bucket); - bio_init(bio, ca->disk_sb.bdev, bio->bi_inline_vecs, nr_bvecs, REQ_OP_READ); + bio_init(bio, ca->disk_sb.bdev, bio_inline_vecs(bio), nr_bvecs, REQ_OP_READ); bio->bi_iter.bi_sector = offset; bch2_bio_map(bio, buf->data, sectors_read << 9); diff --git a/libbcachefs/sb/io.c b/libbcachefs/sb/io.c index 94a09d19..1bf35308 100644 --- a/libbcachefs/sb/io.c +++ b/libbcachefs/sb/io.c @@ -235,7 +235,7 @@ int bch2_sb_realloc(struct bch_sb_handle *sb, unsigned u64s) if (!bio) return -BCH_ERR_ENOMEM_sb_bio_realloc; - bio_init(bio, NULL, bio->bi_inline_vecs, nr_bvecs, 0); + bio_init(bio, NULL, bio_inline_vecs(bio), nr_bvecs, 0); kfree(sb->bio); sb->bio = bio; diff --git a/libbcachefs/util/util.h b/libbcachefs/util/util.h index b74d5eff..354c2cf2 100644 --- a/libbcachefs/util/util.h +++ b/libbcachefs/util/util.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -48,6 +49,13 @@ struct closure; (__builtin_types_compatible_p(typeof(_val), _type) || \ __builtin_types_compatible_p(typeof(_val), const _type)) +#if defined(_KERNEL__) && LINUX_VERSION_CODE <= KERNEL_VERSION(6,17,0) +static inline struct bio_vec *bio_inline_vecs(struct bio *bio) +{ + return (struct bio_vec *)(bio + 1); +} +#endif + /* Userspace doesn't align allocations as nicely as the kernel allocators: */ static inline size_t buf_pages(void *p, size_t len) { @@ -58,9 +66,15 @@ static inline size_t buf_pages(void *p, size_t len) static inline void *bch2_kvmalloc_noprof(size_t n, gfp_t flags) { +#if LINUX_VERSION_CODE <= KERNEL_VERSION(6,17,0) void *p = unlikely(n >= INT_MAX) ? vmalloc_noprof(n) : kvmalloc_noprof(n, flags & ~__GFP_ZERO); +#else + void *p = unlikely(n >= INT_MAX) + ? vmalloc_noprof(n) + : kvmalloc_node_align_noprof(n, 1, flags & ~__GFP_ZERO, NUMA_NO_NODE); +#endif if (p && (flags & __GFP_ZERO)) memset(p, 0, n); return p; diff --git a/libbcachefs/vfs/ioctl.c b/libbcachefs/vfs/ioctl.c index bc9efae2..397d84d0 100644 --- a/libbcachefs/vfs/ioctl.c +++ b/libbcachefs/vfs/ioctl.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -25,6 +26,12 @@ #define FSOP_GOING_FLAGS_LOGFLUSH 0x1 /* flush log but not data */ #define FSOP_GOING_FLAGS_NOLOGFLUSH 0x2 /* don't flush log nor data */ +#if LINUX_VERSION_CODE <= KERNEL_VERSION(6,17,0) +#define start_creating_user_path user_path_create +#define end_creating_path done_path_create +#define start_removing_user_path_at user_path_locked_at +#endif + static int bch2_reinherit_attrs_fn(struct btree_trans *trans, struct bch_inode_info *inode, struct bch_inode_unpacked *bi, @@ -257,7 +264,7 @@ static long __bch2_ioctl_subvolume_create(struct bch_fs *c, struct file *filp, snapshot_src = inode_inum(to_bch_ei(src_path.dentry->d_inode)); } - dst_dentry = user_path_create(arg.dirfd, + dst_dentry = start_creating_user_path(arg.dirfd, (const char __user *)(unsigned long)arg.dst_ptr, &dst_path, lookup_flags); error = PTR_ERR_OR_ZERO(dst_dentry); @@ -316,7 +323,7 @@ static long __bch2_ioctl_subvolume_create(struct bch_fs *c, struct file *filp, d_instantiate(dst_dentry, &inode->v); fsnotify_mkdir(dir, dst_dentry); err3: - done_path_create(&dst_path, dst_dentry); + end_creating_path(&dst_path, dst_dentry); err2: if (arg.src_ptr) path_put(&src_path); @@ -363,7 +370,7 @@ static long __bch2_ioctl_subvolume_destroy(struct bch_fs *c, struct file *filp, if (arg.flags) return -EINVAL; - victim = user_path_locked_at(arg.dirfd, name, &path); + victim = start_removing_user_path_at(arg.dirfd, name, &path); if (IS_ERR(victim)) return PTR_ERR(victim); diff --git a/linux/bio.c b/linux/bio.c index eb115a90..65d186b3 100644 --- a/linux/bio.c +++ b/linux/bio.c @@ -306,7 +306,7 @@ struct bio *bio_kmalloc(unsigned int nr_iovecs, gfp_t gfp_mask) sizeof(struct bio_vec) * nr_iovecs, gfp_mask); if (unlikely(!bio)) return NULL; - bio_init(bio, NULL, nr_iovecs ? bio->bi_inline_vecs : NULL, nr_iovecs, 0); + bio_init(bio, NULL, nr_iovecs ? bio_inline_vecs(bio) : NULL, nr_iovecs, 0); bio->bi_pool = NULL; return bio; } @@ -320,7 +320,7 @@ struct bio *bio_alloc(struct block_device *bdev, unsigned nr_iovecs, sizeof(struct bio_vec) * nr_iovecs, gfp_mask); if (unlikely(!bio)) return NULL; - bio_init(bio, bdev, nr_iovecs ? bio->bi_inline_vecs : NULL, nr_iovecs, opf); + bio_init(bio, NULL, nr_iovecs ? bio_inline_vecs(bio) : NULL, nr_iovecs, opf); bio->bi_pool = NULL; return bio; } @@ -372,7 +372,7 @@ struct bio *bio_alloc_bioset(struct block_device *bdev, bio_init(bio, bdev, bvl, nr_iovecs, opf); } else if (nr_iovecs) { - bio_init(bio, bdev, bio->bi_inline_vecs, BIO_INLINE_VECS, opf); + bio_init(bio, bdev, bio_inline_vecs(bio), BIO_INLINE_VECS, opf); } else { bio_init(bio, bdev, NULL, 0, opf); }