From: Simon Glass <simon.glass@canonical.com> Add journal.c to the jbd2 Makefile and update includes to use the ext4l compatibility layer. Add stubs for functions from recovery.c, revoke.c, and transaction.c that journal.c depends on. Remove JBD2 function stubs from stub.c that are now provided by journal.c. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 106 ++++++++++++++++++++++- fs/ext4l/stub.c | 190 +++++++++++++++++++----------------------- fs/jbd2/Makefile | 2 +- fs/jbd2/commit.c | 15 +--- fs/jbd2/journal.c | 28 +------ 5 files changed, 193 insertions(+), 148 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 62815e334c8..0d24940e74e 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -126,6 +126,12 @@ struct kobject { const char *name; }; +/* lockdep stubs - needed before jbd2.h is included */ +struct lockdep_map { int dummy; }; +struct lock_class_key { int dummy; }; +#define rwsem_acquire(l, s, t, i) do { } while (0) +#define rwsem_release(l, i) do { } while (0) + /* completion - stub */ struct completion { unsigned int done; @@ -1211,8 +1217,11 @@ struct folio_batch { /* folio operations - stubs */ #define folio_mark_dirty(f) do { (void)(f); } while (0) -#define offset_in_folio(f, p) ({ (void)(f); (unsigned int)((p) & (PAGE_SIZE - 1)); }) +#define offset_in_folio(f, p) ({ (void)(f); (unsigned int)((unsigned long)(p) & (PAGE_SIZE - 1)); }) #define folio_buffers(f) ({ (void)(f); (struct buffer_head *)NULL; }) +#define virt_to_folio(p) ({ (void)(p); (struct folio *)NULL; }) +#define folio_set_bh(bh, f, off) do { (void)(bh); (void)(f); (void)(off); } while (0) +#define memcpy_from_folio(dst, f, off, len) do { (void)(dst); (void)(f); (void)(off); (void)(len); } while (0) #define folio_test_uptodate(f) ({ (void)(f); 1; }) #define folio_pos(f) ({ (void)(f); 0LL; }) #define folio_size(f) ({ (void)(f); PAGE_SIZE; }) @@ -2782,4 +2791,99 @@ struct wait_bit_entry { #define trace_jbd2_drop_transaction(j, t) \ do { (void)(j); (void)(t); } while (0) +/* JBD2 commit.c stubs */ +#define clear_bit_unlock(nr, addr) clear_bit(nr, addr) +#define smp_mb__after_atomic() do { } while (0) +#define folio_trylock(f) ({ (void)(f); 1; }) +#define ktime_get_coarse_real_ts64(ts) do { (ts)->tv_sec = 0; (ts)->tv_nsec = 0; } while (0) +#define filemap_fdatawait_range_keep_errors(m, s, e) \ + ({ (void)(m); (void)(s); (void)(e); 0; }) +#define crc32_be(crc, p, len) crc32(crc, p, len) +#define free_buffer_head(bh) kfree(bh) +#define sb_is_blkdev_sb(sb) ({ (void)(sb); 0; }) + +/* DEFINE_WAIT stub - creates a wait queue entry */ +#define DEFINE_WAIT(name) int name = 0 + +/* cond_resched_lock - conditionally reschedule while holding a lock */ +#define cond_resched_lock(lock) do { (void)(lock); } while (0) + +/* More JBD2 trace stubs for commit.c */ +#define trace_jbd2_submit_inode_data(i) do { (void)(i); } while (0) +#define trace_jbd2_start_commit(j, t) do { (void)(j); (void)(t); } while (0) +#define trace_jbd2_commit_locking(j, t) do { (void)(j); (void)(t); } while (0) +#define trace_jbd2_commit_flushing(j, t) do { (void)(j); (void)(t); } while (0) +#define trace_jbd2_commit_logging(j, t) do { (void)(j); (void)(t); } while (0) +#define trace_jbd2_run_stats(d, tid, stats) \ + do { (void)(d); (void)(tid); (void)(stats); } while (0) +#define trace_jbd2_end_commit(j, t) do { (void)(j); (void)(t); } while (0) + +/* JBD2 journal.c stubs */ +#define alloc_buffer_head(gfp) ((struct buffer_head *)kzalloc(sizeof(struct buffer_head), gfp)) +#define __getblk(bdev, block, size) ({ (void)(bdev); (void)(block); (void)(size); (struct buffer_head *)NULL; }) +#define bmap(inode, block) ({ (void)(inode); (void)(block); 0; }) +#define trace_jbd2_update_log_tail(j, t, b, f) \ + do { (void)(j); (void)(t); (void)(b); (void)(f); } while (0) + +/* seq_file operations for /proc - stubs */ +#define seq_open(f, ops) ({ (void)(f); (void)(ops); 0; }) +#define seq_release(i, f) ({ (void)(i); (void)(f); 0; }) + +/* proc_ops structure for journal.c */ +struct proc_ops { + int (*proc_open)(struct inode *, struct file *); + ssize_t (*proc_read)(struct file *, char *, size_t, loff_t *); + loff_t (*proc_lseek)(struct file *, loff_t, int); + int (*proc_release)(struct inode *, struct file *); +}; + +/* seq_read and seq_lseek declarations (defined in stub.c) */ +ssize_t seq_read(struct file *f, char *b, size_t s, loff_t *p); +loff_t seq_lseek(struct file *f, loff_t o, int w); + +/* S_IRUGO file mode if not defined */ +#ifndef S_IRUGO +#define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH) +#endif + +/* procfs stubs */ +#define proc_mkdir(name, parent) ({ (void)(name); (void)(parent); (struct proc_dir_entry *)NULL; }) +#define proc_create_data(n, m, p, ops, d) \ + ({ (void)(n); (void)(m); (void)(p); (void)(ops); (void)(d); (struct proc_dir_entry *)NULL; }) +#define remove_proc_entry(n, p) do { (void)(n); (void)(p); } while (0) + +/* lockdep stubs (struct lock_class_key defined earlier) */ +#define lockdep_init_map(...) do { } while (0) + +/* More JBD2 trace stubs for journal.c */ +#define trace_jbd2_shrink_scan_enter(j, n, c) \ + do { (void)(j); (void)(n); (void)(c); } while (0) +#define trace_jbd2_shrink_scan_exit(j, n, s, c) \ + do { (void)(j); (void)(n); (void)(s); (void)(c); } while (0) +#define trace_jbd2_shrink_count(j, n, c) \ + do { (void)(j); (void)(n); (void)(c); } while (0) +#define trace_jbd2_write_superblock(j, f) \ + do { (void)(j); (void)(f); } while (0) + +/* Block device operations for journal.c */ +#define bh_read(bh, flags) ({ (void)(bh); (void)(flags); 0; }) +#define truncate_inode_pages_range(m, s, e) \ + do { (void)(m); (void)(s); (void)(e); } while (0) +#define blkdev_issue_discard(bdev, s, n, gfp) \ + ({ (void)(bdev); (void)(s); (void)(n); (void)(gfp); 0; }) +#define blkdev_issue_zeroout(bdev, s, n, gfp, f) \ + ({ (void)(bdev); (void)(s); (void)(n); (void)(gfp); (void)(f); 0; }) +#ifndef SECTOR_SHIFT +#define SECTOR_SHIFT 9 +#endif +#define mapping_max_folio_order(m) ({ (void)(m); 0; }) + +/* Memory allocation for journal.c */ +#define __get_free_pages(gfp, order) ((unsigned long)memalign(PAGE_SIZE, PAGE_SIZE << (order))) +#define free_pages(addr, order) free((void *)(addr)) +#define get_order(size) ilog2(roundup_pow_of_two((size) / PAGE_SIZE)) + +/* Ratelimited printk for journal.c */ +#define pr_notice_ratelimited(fmt, ...) pr_notice(fmt, ##__VA_ARGS__) + #endif /* __EXT4_UBOOT_H__ */ diff --git a/fs/ext4l/stub.c b/fs/ext4l/stub.c index 0458191c496..c9d1d3f99eb 100644 --- a/fs/ext4l/stub.c +++ b/fs/ext4l/stub.c @@ -96,10 +96,7 @@ int jbd2_journal_dirty_metadata(handle_t *handle, struct buffer_head *bh) return 0; } -int jbd2_journal_force_commit_nested(journal_t *journal) -{ - return 0; -} +/* jbd2_journal_force_commit_nested is now in journal.c */ int jbd2__journal_restart(void *handle, int nblocks, int revoke_records, int gfp_mask) @@ -107,10 +104,7 @@ int jbd2__journal_restart(void *handle, int nblocks, int revoke_records, return 0; } -int jbd2_trans_will_send_data_barrier(journal_t *journal, unsigned long tid) -{ - return 0; -} +/* jbd2_trans_will_send_data_barrier is now in journal.c */ /* * Stubs for balloc.c @@ -189,53 +183,15 @@ struct extent_status; /* ext4_fc_replay_check_excluded is now in fast_commit.c */ -/* - * JBD2 fast commit stubs - */ -int jbd2_fc_get_buf(void *journal, struct buffer_head **bh_out) -{ - *bh_out = NULL; - return -ENOSPC; -} - -void jbd2_fc_release_bufs(void *journal) -{ -} - -int jbd2_fc_begin_commit(void *journal, unsigned int tid) -{ - return -EOPNOTSUPP; -} - -int jbd2_fc_end_commit(void *journal) -{ - return 0; -} - -int jbd2_fc_end_commit_fallback(void *journal) -{ - return 0; -} - -int jbd2_submit_inode_data(void *journal, void *jinode) -{ - return 0; -} - -int jbd2_wait_inode_data(void *journal, void *jinode) -{ - return 0; -} - -int jbd2_fc_wait_bufs(void *journal, int num) -{ - return 0; -} - -int jbd2_complete_transaction(void *journal, unsigned int tid) -{ - return 0; -} +/* jbd2_submit_inode_data is now in commit.c */ +/* jbd2_wait_inode_data is now in commit.c */ +/* jbd2_fc_get_buf is now in journal.c */ +/* jbd2_fc_release_bufs is now in journal.c */ +/* jbd2_fc_begin_commit is now in journal.c */ +/* jbd2_fc_end_commit is now in journal.c */ +/* jbd2_fc_end_commit_fallback is now in journal.c */ +/* jbd2_fc_wait_bufs is now in journal.c */ +/* jbd2_complete_transaction is now in journal.c */ void ext4_reset_inode_seed(struct inode *inode) { @@ -268,16 +224,8 @@ struct ext4_iloc; */ #include <linux/sched.h> -/* JBD2 stubs for inode.c */ -int jbd2_journal_blocks_per_folio(struct inode *inode) -{ - return 1; -} - -int jbd2_transaction_committed(void *journal, unsigned int tid) -{ - return 1; -} +/* jbd2_journal_blocks_per_folio is now in journal.c */ +/* jbd2_transaction_committed is now in journal.c */ /* __ext4_warning_inode is now in super.c */ @@ -318,10 +266,7 @@ void jbd2_journal_invalidate_folio(void *journal, void *folio, { } -int jbd2_log_wait_commit(void *journal, unsigned int tid) -{ - return 0; -} +/* jbd2_log_wait_commit is now in journal.c */ /* ext4_fc_track_range is now in fast_commit.c */ @@ -334,10 +279,7 @@ void jbd2_journal_unlock_updates(void *journal) { } -int jbd2_journal_flush(void *journal, unsigned int flags) -{ - return 0; -} +/* jbd2_journal_flush is now in journal.c */ /* ext4_fc_track_inode is now in fast_commit.c */ @@ -370,17 +312,14 @@ int jbd2_journal_inode_ranged_wait(void *handle, struct inode *inode, /* xattr stubs are now in xattr.c */ -/* JBD2 stubs for inode.c */ -struct kmem_cache *jbd2_inode_cache; +/* jbd2_inode_cache is now in journal.c */ int jbd2_journal_try_to_free_buffers(journal_t *journal, struct folio *folio) { return 1; } -void jbd2_journal_init_jbd_inode(void *jinode, struct inode *inode) -{ -} +/* jbd2_journal_init_jbd_inode is now in journal.c */ /* ext4_read_inline_link is now in inline.c */ @@ -629,11 +568,7 @@ void ext4_unregister_sysfs(void *sb) { } -/* Journal destroy */ -int jbd2_journal_destroy(void *journal) -{ - return 0; -} +/* jbd2_journal_destroy is now in journal.c */ /* percpu rwsem */ void percpu_free_rwsem(struct percpu_rw_semaphore *sem) @@ -771,11 +706,7 @@ void fsnotify_sb_error(struct super_block *sb, struct inode *inode, int error) { } -/* JBD2 force commit */ -int jbd2_journal_force_commit(void *journal) -{ - return 0; -} +/* jbd2_journal_force_commit is now in journal.c */ /* File path */ char *file_path(struct file *file, char *buf, int buflen) @@ -796,15 +727,9 @@ long ext4_ioctl(struct file *file, unsigned int cmd, unsigned long arg) return -ENOTSUPP; } -/* JBD2 journal abort */ -void jbd2_journal_abort(void *journal, int error) -{ -} +/* jbd2_journal_abort is now in journal.c */ -/* JBD2 journal inode release */ -void jbd2_journal_release_jbd_inode(void *journal, void *jinode) -{ -} +/* jbd2_journal_release_jbd_inode is now in journal.c */ /* nop_mnt_idmap - no-op mount ID map for xattr.c */ struct mnt_idmap nop_mnt_idmap; @@ -833,30 +758,85 @@ void dquot_free_block(struct inode *inode, loff_t nr) * Note: These use void* to avoid pulling in jbd2.h types which would conflict */ -int jbd2_journal_get_log_tail(void *journal, void *tid, unsigned long *block) +/* jbd2_journal_get_log_tail is now in journal.c */ +/* __jbd2_update_log_tail is now in journal.c */ +/* jbd2_journal_grab_journal_head is now in journal.c */ +/* jbd2_journal_put_journal_head is now in journal.c */ + +void jbd2_journal_free_transaction(void *transaction) { - return 0; } -int __jbd2_update_log_tail(void *journal, unsigned int tid, unsigned long block) +/* jbd2_log_start_commit is now in journal.c */ + +/* jbd2_journal_get_descriptor_buffer is now in journal.c */ +/* jbd2_journal_update_sb_log_tail is now in journal.c */ +/* jbd2_free is now in journal.c */ + +/* journal_tag_bytes is now in journal.c */ + +void jbd2_journal_wait_updates(void *journal) { - return 0; } -void *jbd2_journal_grab_journal_head(struct buffer_head *bh) +void jbd2_journal_refile_buffer(void *journal, void *jh) { - return NULL; } -void jbd2_journal_put_journal_head(void *jh) +void jbd2_clear_buffer_revoked_flags(void *journal) { } -void jbd2_journal_free_transaction(void *transaction) +void jbd2_journal_switch_revoke_table(void *journal) +{ +} + +void jbd2_journal_write_revoke_records(void *journal, void *transaction, + int write_flags) +{ +} + +void jbd2_buffer_abort_trigger(void *jh, void *triggers) +{ +} + +/* jbd2_journal_next_log_block is now in journal.c */ +/* jbd2_journal_write_metadata_buffer is now in journal.c */ +/* jbd2_descriptor_block_csum_set is now in journal.c */ +/* jbd2_update_log_tail is now in journal.c */ + +void jbd2_journal_file_buffer(void *jh, void *transaction, int type) +{ +} + +void __jbd2_journal_refile_buffer(void *jh) +{ +} + +/* cond_resched_lock is now a macro in ext4_uboot.h */ + +/* + * JBD2 stubs for journal.c - functions from recovery.c, revoke.c, transaction.c + */ +int jbd2_journal_destroy_revoke(void *journal) { + return 0; +} + +int jbd2_journal_recover(void *journal) +{ + return 0; } -int jbd2_log_start_commit(void *journal, unsigned int tid) +int jbd2_journal_skip_recovery(void *journal) { return 0; } + +void jbd2_buffer_frozen_trigger(void *jh, void *mapped_data, void *triggers) +{ +} + +void __jbd2_journal_file_buffer(void *jh, void *transaction, int type) +{ +} diff --git a/fs/jbd2/Makefile b/fs/jbd2/Makefile index 03e8ba0f2ec..f0f84bfb707 100644 --- a/fs/jbd2/Makefile +++ b/fs/jbd2/Makefile @@ -3,4 +3,4 @@ # Makefile for JBD2 journaling layer (used by ext4l) # -obj-y := checkpoint.o +obj-y := checkpoint.o commit.o journal.o diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c index 7203d2d2624..d4e63a91e87 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c @@ -10,21 +10,8 @@ * part of the ext2fs journaling system. */ -#include <linux/time.h> -#include <linux/fs.h> +#include "../ext4l/ext4_uboot.h" #include <linux/jbd2.h> -#include <linux/errno.h> -#include <linux/slab.h> -#include <linux/mm.h> -#include <linux/pagemap.h> -#include <linux/jiffies.h> -#include <linux/crc32.h> -#include <linux/writeback.h> -#include <linux/backing-dev.h> -#include <linux/bio.h> -#include <linux/blkdev.h> -#include <linux/bitops.h> -#include <trace/events/jbd2.h> /* * IO end handler for temporary buffer_heads handling writes to the journal. diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index d480b94117c..0b77fd0f34b 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -19,34 +19,8 @@ * journaling (ext2 can use a reserved inode for storing the log). */ -#include <linux/module.h> -#include <linux/time.h> -#include <linux/fs.h> +#include "../ext4l/ext4_uboot.h" #include <linux/jbd2.h> -#include <linux/errno.h> -#include <linux/slab.h> -#include <linux/init.h> -#include <linux/mm.h> -#include <linux/freezer.h> -#include <linux/pagemap.h> -#include <linux/kthread.h> -#include <linux/poison.h> -#include <linux/proc_fs.h> -#include <linux/seq_file.h> -#include <linux/math64.h> -#include <linux/hash.h> -#include <linux/log2.h> -#include <linux/vmalloc.h> -#include <linux/backing-dev.h> -#include <linux/bitops.h> -#include <linux/ratelimit.h> -#include <linux/sched/mm.h> - -#define CREATE_TRACE_POINTS -#include <trace/events/jbd2.h> - -#include <linux/uaccess.h> -#include <asm/page.h> #ifdef CONFIG_JBD2_DEBUG static ushort jbd2_journal_enable_debug __read_mostly; -- 2.43.0