From: Simon Glass <simon.glass@canonical.com> Add inode_state_read_once(), inode_state_clear() and related accessor functions to ext4_uboot.h to match the Linux kernel API. These are simplified versions for U-Boot's single-threaded environment - Linux uses READ_ONCE/WRITE_ONCE with lockdep assertions, while U-Boot uses direct access. Update inode.c and orphan.c to use these new accessors instead of direct i_state field access, aligning them with the Linux kernel source. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> --- fs/ext4l/ext4_uboot.h | 46 +++++++++++++++++++++++++++++++++++++++++++ fs/ext4l/inode.c | 10 +++++----- fs/ext4l/orphan.c | 4 ++-- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index b3da5bfa002..943cb31d694 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -934,6 +934,52 @@ static inline void simple_inode_init_ts(struct inode *inode) inode->i_ctime = ts; } +/* + * Inode state accessors - simplified for single-threaded U-Boot. + * Linux uses READ_ONCE/WRITE_ONCE and lockdep assertions; we use direct access. + */ +static inline unsigned long inode_state_read_once(struct inode *inode) +{ + return inode->i_state; +} + +static inline unsigned long inode_state_read(struct inode *inode) +{ + return inode->i_state; +} + +static inline void inode_state_set_raw(struct inode *inode, unsigned long flags) +{ + inode->i_state |= flags; +} + +static inline void inode_state_set(struct inode *inode, unsigned long flags) +{ + inode->i_state |= flags; +} + +static inline void inode_state_clear_raw(struct inode *inode, + unsigned long flags) +{ + inode->i_state &= ~flags; +} + +static inline void inode_state_clear(struct inode *inode, unsigned long flags) +{ + inode->i_state &= ~flags; +} + +static inline void inode_state_assign_raw(struct inode *inode, + unsigned long flags) +{ + inode->i_state = flags; +} + +static inline void inode_state_assign(struct inode *inode, unsigned long flags) +{ + inode->i_state = flags; +} + #define QSTR_INIT(n, l) { .name = (const unsigned char *)(n), .len = (l) } /* dotdot_name for ".." lookups */ diff --git a/fs/ext4l/inode.c b/fs/ext4l/inode.c index dc151c068bb..415c9f7f62f 100644 --- a/fs/ext4l/inode.c +++ b/fs/ext4l/inode.c @@ -403,7 +403,7 @@ void ext4_check_map_extents_env(struct inode *inode) if (!S_ISREG(inode->i_mode) || IS_NOQUOTA(inode) || IS_VERITY(inode) || is_special_ino(inode->i_sb, inode->i_ino) || - (inode->i_state & (I_FREEING | I_WILL_FREE | I_NEW)) || + (inode_state_read_once(inode) & (I_FREEING | I_WILL_FREE | I_NEW)) || ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE) || ext4_verity_in_progress(inode)) return; @@ -3451,7 +3451,7 @@ static bool ext4_inode_datasync_dirty(struct inode *inode) /* Any metadata buffers to write? */ if (!list_empty(&inode->i_mapping->i_private_list)) return true; - return inode->i_state & I_DIRTY_DATASYNC; + return inode_state_read_once(inode) & I_DIRTY_DATASYNC; } static void ext4_set_iomap(struct inode *inode, struct iomap *iomap, @@ -4530,7 +4530,7 @@ int ext4_truncate(struct inode *inode) * or it's a completely new inode. In those cases we might not * have i_rwsem locked because it's not necessary. */ - if (!(inode->i_state & (I_NEW|I_FREEING))) + if (!(inode_state_read_once(inode) & (I_NEW | I_FREEING))) WARN_ON(!inode_is_locked(inode)); trace_ext4_truncate_enter(inode); @@ -5188,7 +5188,7 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, inode = iget_locked(sb, ino); if (!inode) return ERR_PTR(-ENOMEM); - if (!(inode->i_state & I_NEW)) { + if (!(inode_state_read_once(inode) & I_NEW)) { ret = check_igot_inode(inode, flags, function, line); if (ret) { iput(inode); @@ -5527,7 +5527,7 @@ static void __ext4_update_other_inode_time(struct super_block *sb, if (inode_is_dirtytime_only(inode)) { struct ext4_inode_info *ei = EXT4_I(inode); - inode->i_state &= ~I_DIRTY_TIME; + inode_state_clear(inode, I_DIRTY_TIME); spin_unlock(&inode->i_lock); spin_lock(&ei->i_raw_lock); diff --git a/fs/ext4l/orphan.c b/fs/ext4l/orphan.c index b142c1bd21f..65d0d177c5d 100644 --- a/fs/ext4l/orphan.c +++ b/fs/ext4l/orphan.c @@ -115,7 +115,7 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode) if (!sbi->s_journal || is_bad_inode(inode)) return 0; - WARN_ON_ONCE(!(inode->i_state & (I_NEW | I_FREEING)) && + WARN_ON_ONCE(!(inode_state_read_once(inode) & (I_NEW | I_FREEING)) && !inode_is_locked(inode)); if (ext4_inode_orphan_tracked(inode)) return 0; @@ -240,7 +240,7 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode) if (!sbi->s_journal && !(sbi->s_mount_state & EXT4_ORPHAN_FS)) return 0; - WARN_ON_ONCE(!(inode->i_state & (I_NEW | I_FREEING)) && + WARN_ON_ONCE(!(inode_state_read_once(inode) & (I_NEW | I_FREEING)) && !inode_is_locked(inode)); if (ext4_test_inode_state(inode, EXT4_STATE_ORPHAN_FILE)) return ext4_orphan_file_del(handle, inode); -- 2.43.0