From: Simon Glass <simon.glass@canonical.com> Add the page I/O module (page-io.c) to the build. This implements ext4's asynchronous page writeback infrastructure. Stubs added for: - bio structure and related operations - folio_iter for bio iteration - refcount operations (mapped to atomic) - fscrypt bounce folio operations - folio writeback operations - writeback control operations - i_write_hint member to inode struct Remove stub functions now implemented in page-io.c: - ext4_io_submit_init, ext4_init_io_end - ext4_io_submit, ext4_put_io_end_defer - ext4_put_io_end, ext4_alloc_io_end_vec Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/Makefile | 2 +- fs/ext4l/ext4_uboot.h | 99 +++++++++++++++++++++++++++++++++++++++++++ fs/ext4l/page-io.c | 15 +------ fs/ext4l/stub.c | 37 ++++------------ 4 files changed, 110 insertions(+), 43 deletions(-) diff --git a/fs/ext4l/Makefile b/fs/ext4l/Makefile index dc3858165c3..506e76b959e 100644 --- a/fs/ext4l/Makefile +++ b/fs/ext4l/Makefile @@ -8,6 +8,6 @@ obj-y := interface.o stub.o obj-y += balloc.o bitmap.o block_validity.o dir.o ext4_jbd2.o extents.o \ extents_status.o file.o fsync.o hash.o ialloc.o \ indirect.o inline.o inode.o mballoc.o \ - namei.o super.o symlink.o xattr.o \ + namei.o page_io.o super.o symlink.o xattr.o \ xattr_hurd.o xattr_trusted.o \ xattr_user.o orphan.o diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 9ea3afdd798..c5895dc902a 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -834,6 +834,7 @@ struct inode { atomic_t i_writecount; /* Count of writers */ struct rw_semaphore i_rwsem; /* inode lock */ const char *i_link; /* Symlink target for fast symlinks */ + unsigned short i_write_hint; /* Write life time hint */ }; /* Inode time accessors */ @@ -1515,6 +1516,7 @@ static inline char *d_path(const struct path *path, char *buf, int buflen) /* fscrypt stubs - additional */ #define fscrypt_inode_uses_fs_layer_crypto(i) (0) #define fscrypt_decrypt_pagecache_blocks(f, l, o) ({ (void)(f); (void)(l); (void)(o); 0; }) +#define fscrypt_encrypt_pagecache_blocks(f, l, o, g) ({ (void)(f); (void)(l); (void)(o); (void)(g); (struct page *)NULL; }) #define fscrypt_zeroout_range(i, lb, pb, l) ({ (void)(i); (void)(lb); (void)(pb); (void)(l); 0; }) #define fscrypt_limit_io_blocks(i, lb, l) (l) #define fscrypt_prepare_setattr(d, a) ({ (void)(d); (void)(a); 0; }) @@ -2565,4 +2567,101 @@ struct seq_operations { #define bdev_discard_granularity(bdev) \ ({ (void)(bdev); 0U; }) +/* + * Stubs for page-io.c + */ + +/* bio_vec - segment in a bio */ +struct bio_vec { + struct page *bv_page; + unsigned int bv_len; + unsigned int bv_offset; +}; + +/* bvec_iter - iterator for bio_vec */ +struct bvec_iter { + sector_t bi_sector; + unsigned int bi_size; + unsigned int bi_idx; + unsigned int bi_bvec_done; +}; + +/* bio - block I/O structure */ +struct bio { + struct bio *bi_next; + struct block_device *bi_bdev; + unsigned long bi_opf; + unsigned short bi_flags; + unsigned short bi_ioprio; + unsigned short bi_write_hint; + int bi_status; + struct bvec_iter bi_iter; + atomic_t __bi_remaining; + void *bi_private; + void (*bi_end_io)(struct bio *); +}; + +/* folio_iter for bio iteration */ +struct folio_iter { + int i; + struct folio *folio; + size_t offset; + size_t length; +}; + +/* bio operations - stubs */ +#define bio_for_each_folio_all(fi, bio) \ + for ((fi).i = 0; (fi).i < 0; (fi).i++) +#define bio_put(bio) free(bio) +#define bio_alloc(bdev, vecs, op, gfp) ((struct bio *)calloc(1, sizeof(struct bio))) +#define submit_bio(bio) do { } while (0) +#define BIO_MAX_VECS 256 + +/* refcount operations - map to atomic */ +#define refcount_set(r, v) atomic_set((atomic_t *)(r), v) +#define refcount_dec_and_test(r) atomic_dec_and_test((atomic_t *)(r)) +#define refcount_inc(r) atomic_inc((atomic_t *)(r)) + +/* xchg - exchange value atomically */ +#define xchg(ptr, new) ({ typeof(*(ptr)) __old = *(ptr); *(ptr) = (new); __old; }) + +/* printk_ratelimited - just use regular printk */ +#define printk_ratelimited(fmt, ...) do { } while (0) + +/* mapping_set_error - record error in address_space */ +#define mapping_set_error(m, e) do { (void)(m); (void)(e); } while (0) + +/* blk_status_to_errno - convert block status to errno */ +#define blk_status_to_errno(status) (-(status)) + +/* atomic_inc - increment atomic */ +#define atomic_inc(v) ((v)->counter++) + +/* GFP_NOIO - allocation without I/O */ +#define GFP_NOIO 0 + +/* fscrypt stubs for page-io.c */ +#define fscrypt_is_bounce_folio(f) ({ (void)(f); 0; }) +#define fscrypt_pagecache_folio(f) (f) +#define fscrypt_free_bounce_page(p) do { (void)(p); } while (0) +#define fscrypt_set_bio_crypt_ctx_bh(bio, bh, gfp) \ + do { (void)(bio); (void)(bh); (void)(gfp); } while (0) +#define fscrypt_mergeable_bio_bh(bio, bh) \ + ({ (void)(bio); (void)(bh); 1; }) + +/* folio writeback operations */ +#define folio_end_writeback(f) do { (void)(f); } while (0) +#define folio_start_writeback(f) do { (void)(f); } while (0) +#define folio_start_writeback_keepwrite(f) do { (void)(f); } while (0) +bool __folio_start_writeback(struct folio *folio, bool keep_write); + +/* writeback control stubs */ +#define wbc_init_bio(wbc, bio) do { (void)(wbc); (void)(bio); } while (0) +#define wbc_account_cgroup_owner(wbc, folio, bytes) \ + do { (void)(wbc); (void)(folio); (void)(bytes); } while (0) + +/* bio operations */ +#define bio_add_folio(bio, folio, len, off) \ + ({ (void)(bio); (void)(folio); (void)(len); (void)(off); 1; }) + #endif /* __EXT4_UBOOT_H__ */ diff --git a/fs/ext4l/page-io.c b/fs/ext4l/page-io.c index 39abfeec5f3..657c6f4eedb 100644 --- a/fs/ext4l/page-io.c +++ b/fs/ext4l/page-io.c @@ -7,24 +7,11 @@ * Written by Theodore Ts'o, 2010. */ -#include <linux/fs.h> +#include "ext4_uboot.h" #include <linux/time.h> -#include <linux/highuid.h> -#include <linux/pagemap.h> -#include <linux/quotaops.h> #include <linux/string.h> -#include <linux/buffer_head.h> -#include <linux/writeback.h> -#include <linux/pagevec.h> #include <linux/mpage.h> -#include <linux/namei.h> -#include <linux/uio.h> -#include <linux/bio.h> -#include <linux/workqueue.h> #include <linux/kernel.h> -#include <linux/slab.h> -#include <linux/mm.h> -#include <linux/sched/mm.h> #include "ext4_jbd2.h" #include "xattr.h" diff --git a/fs/ext4l/stub.c b/fs/ext4l/stub.c index ca8a2bc0f91..935e93f49f1 100644 --- a/fs/ext4l/stub.c +++ b/fs/ext4l/stub.c @@ -199,6 +199,14 @@ int ext4_fc_replay_check_excluded(struct super_block *sb, unsigned long long blk return 0; } +/* + * Stubs for page-io.c + */ +bool __folio_start_writeback(struct folio *folio, bool keep_write) +{ + return false; +} + /* ext4_read_bh is now in super.c */ /* ext4_sb_bread_nofail is now in super.c */ @@ -262,34 +270,7 @@ int ext4_fc_commit(void *journal, unsigned int tid) /* Inline data is now in inline.c */ -/* I/O submit */ -void ext4_io_submit_init(void *io, void *wbc) -{ -} - - -void *ext4_init_io_end(struct inode *inode, int gfp) -{ - return NULL; -} - -void ext4_io_submit(void *io) -{ -} - -void ext4_put_io_end_defer(void *io_end) -{ -} - -void ext4_put_io_end(void *io_end) -{ -} - -void *ext4_alloc_io_end_vec(void *io_end, unsigned long num) -{ - return NULL; -} - +/* I/O submit stubs are now in page-io.c */ /* JBD2 ordered truncate */ int jbd2_journal_begin_ordered_truncate(void *ji, loff_t new_size) -- 2.43.0