Update bcachefs sources to caffe5f36f39 bcachefs: Compatibility with v6.18

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2025-10-15 13:38:09 -04:00
parent 87b7adc49b
commit 825b55e747
10 changed files with 41 additions and 20 deletions

View File

@ -1 +1 @@
a3e0941d427cf4c0ae75f4afd5b525dddcf407a2
caffe5f36f39ef62d58383b77dfdce931104f8c2

View File

@ -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)
/*

View File

@ -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)

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -16,6 +16,7 @@
#include <linux/ratelimit.h>
#include <linux/slab.h>
#include <linux/sort.h>
#include <linux/version.h>
#include <linux/vmalloc.h>
#include <linux/workqueue.h>
@ -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;

View File

@ -17,6 +17,7 @@
#include <linux/fsnotify.h>
#include <linux/mount.h>
#include <linux/namei.h>
#include <linux/version.h>
#include <linux/security.h>
#include <linux/writeback.h>
@ -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);

View File

@ -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);
}