Skip to content

Commit 9a98f9e

Browse files
josefbacikbrauner
authored andcommitted
fs: make the i_state flags an enum
Adjusting i_state flags always means updating the values manually. Bring these forward into the 2020's and make a nice clean macro for defining the i_state values as an enum, providing __ variants for the cases where we need the bit position instead of the actual value, and leaving the actual NAME as the 1U << bit value. Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Link: https://lore.kernel.org/0da9348da6ece0dce12fccec07b1dd2b8e4cfdab.1756222464.git.josef@toxicpanda.com Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent bc986b1 commit 9a98f9e

1 file changed

Lines changed: 119 additions & 112 deletions

File tree

include/linux/fs.h

Lines changed: 119 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,124 @@ is_uncached_acl(struct posix_acl *acl)
664664
#define IOP_MGTIME 0x0020
665665
#define IOP_CACHED_LINK 0x0040
666666

667+
/*
668+
* Inode state bits. Protected by inode->i_lock
669+
*
670+
* Four bits determine the dirty state of the inode: I_DIRTY_SYNC,
671+
* I_DIRTY_DATASYNC, I_DIRTY_PAGES, and I_DIRTY_TIME.
672+
*
673+
* Four bits define the lifetime of an inode. Initially, inodes are I_NEW,
674+
* until that flag is cleared. I_WILL_FREE, I_FREEING and I_CLEAR are set at
675+
* various stages of removing an inode.
676+
*
677+
* Two bits are used for locking and completion notification, I_NEW and I_SYNC.
678+
*
679+
* I_DIRTY_SYNC Inode is dirty, but doesn't have to be written on
680+
* fdatasync() (unless I_DIRTY_DATASYNC is also set).
681+
* Timestamp updates are the usual cause.
682+
* I_DIRTY_DATASYNC Data-related inode changes pending. We keep track of
683+
* these changes separately from I_DIRTY_SYNC so that we
684+
* don't have to write inode on fdatasync() when only
685+
* e.g. the timestamps have changed.
686+
* I_DIRTY_PAGES Inode has dirty pages. Inode itself may be clean.
687+
* I_DIRTY_TIME The inode itself has dirty timestamps, and the
688+
* lazytime mount option is enabled. We keep track of this
689+
* separately from I_DIRTY_SYNC in order to implement
690+
* lazytime. This gets cleared if I_DIRTY_INODE
691+
* (I_DIRTY_SYNC and/or I_DIRTY_DATASYNC) gets set. But
692+
* I_DIRTY_TIME can still be set if I_DIRTY_SYNC is already
693+
* in place because writeback might already be in progress
694+
* and we don't want to lose the time update
695+
* I_NEW Serves as both a mutex and completion notification.
696+
* New inodes set I_NEW. If two processes both create
697+
* the same inode, one of them will release its inode and
698+
* wait for I_NEW to be released before returning.
699+
* Inodes in I_WILL_FREE, I_FREEING or I_CLEAR state can
700+
* also cause waiting on I_NEW, without I_NEW actually
701+
* being set. find_inode() uses this to prevent returning
702+
* nearly-dead inodes.
703+
* I_WILL_FREE Must be set when calling write_inode_now() if i_count
704+
* is zero. I_FREEING must be set when I_WILL_FREE is
705+
* cleared.
706+
* I_FREEING Set when inode is about to be freed but still has dirty
707+
* pages or buffers attached or the inode itself is still
708+
* dirty.
709+
* I_CLEAR Added by clear_inode(). In this state the inode is
710+
* clean and can be destroyed. Inode keeps I_FREEING.
711+
*
712+
* Inodes that are I_WILL_FREE, I_FREEING or I_CLEAR are
713+
* prohibited for many purposes. iget() must wait for
714+
* the inode to be completely released, then create it
715+
* anew. Other functions will just ignore such inodes,
716+
* if appropriate. I_NEW is used for waiting.
717+
*
718+
* I_SYNC Writeback of inode is running. The bit is set during
719+
* data writeback, and cleared with a wakeup on the bit
720+
* address once it is done. The bit is also used to pin
721+
* the inode in memory for flusher thread.
722+
*
723+
* I_REFERENCED Marks the inode as recently references on the LRU list.
724+
*
725+
* I_WB_SWITCH Cgroup bdi_writeback switching in progress. Used to
726+
* synchronize competing switching instances and to tell
727+
* wb stat updates to grab the i_pages lock. See
728+
* inode_switch_wbs_work_fn() for details.
729+
*
730+
* I_OVL_INUSE Used by overlayfs to get exclusive ownership on upper
731+
* and work dirs among overlayfs mounts.
732+
*
733+
* I_CREATING New object's inode in the middle of setting up.
734+
*
735+
* I_DONTCACHE Evict inode as soon as it is not used anymore.
736+
*
737+
* I_SYNC_QUEUED Inode is queued in b_io or b_more_io writeback lists.
738+
* Used to detect that mark_inode_dirty() should not move
739+
* inode between dirty lists.
740+
*
741+
* I_PINNING_FSCACHE_WB Inode is pinning an fscache object for writeback.
742+
*
743+
* I_LRU_ISOLATING Inode is pinned being isolated from LRU without holding
744+
* i_count.
745+
*
746+
* Q: What is the difference between I_WILL_FREE and I_FREEING?
747+
*
748+
* __I_{SYNC,NEW,LRU_ISOLATING} are used to derive unique addresses to wait
749+
* upon. There's one free address left.
750+
*/
751+
752+
enum inode_state_bits {
753+
__I_NEW = 0U,
754+
__I_SYNC = 1U,
755+
__I_LRU_ISOLATING = 2U
756+
/* reserved wait address bit 3 */
757+
};
758+
759+
enum inode_state_flags_t {
760+
I_NEW = (1U << __I_NEW),
761+
I_SYNC = (1U << __I_SYNC),
762+
I_LRU_ISOLATING = (1U << __I_LRU_ISOLATING),
763+
/* reserved flag bit 3 */
764+
I_DIRTY_SYNC = (1U << 4),
765+
I_DIRTY_DATASYNC = (1U << 5),
766+
I_DIRTY_PAGES = (1U << 6),
767+
I_WILL_FREE = (1U << 7),
768+
I_FREEING = (1U << 8),
769+
I_CLEAR = (1U << 9),
770+
I_REFERENCED = (1U << 10),
771+
I_LINKABLE = (1U << 11),
772+
I_DIRTY_TIME = (1U << 12),
773+
I_WB_SWITCH = (1U << 13),
774+
I_OVL_INUSE = (1U << 14),
775+
I_CREATING = (1U << 15),
776+
I_DONTCACHE = (1U << 16),
777+
I_SYNC_QUEUED = (1U << 17),
778+
I_PINNING_NETFS_WB = (1U << 18)
779+
};
780+
781+
#define I_DIRTY_INODE (I_DIRTY_SYNC | I_DIRTY_DATASYNC)
782+
#define I_DIRTY (I_DIRTY_INODE | I_DIRTY_PAGES)
783+
#define I_DIRTY_ALL (I_DIRTY | I_DIRTY_TIME)
784+
667785
/*
668786
* Keep mostly read-only and often accessed (especially for
669787
* the RCU path lookup and 'stat' data) fields at the beginning
@@ -722,7 +840,7 @@ struct inode {
722840
#endif
723841

724842
/* Misc */
725-
u32 i_state;
843+
enum inode_state_flags_t i_state;
726844
/* 32-bit hole */
727845
struct rw_semaphore i_rwsem;
728846

@@ -2482,117 +2600,6 @@ static inline void kiocb_clone(struct kiocb *kiocb, struct kiocb *kiocb_src,
24822600
};
24832601
}
24842602

2485-
/*
2486-
* Inode state bits. Protected by inode->i_lock
2487-
*
2488-
* Four bits determine the dirty state of the inode: I_DIRTY_SYNC,
2489-
* I_DIRTY_DATASYNC, I_DIRTY_PAGES, and I_DIRTY_TIME.
2490-
*
2491-
* Four bits define the lifetime of an inode. Initially, inodes are I_NEW,
2492-
* until that flag is cleared. I_WILL_FREE, I_FREEING and I_CLEAR are set at
2493-
* various stages of removing an inode.
2494-
*
2495-
* Two bits are used for locking and completion notification, I_NEW and I_SYNC.
2496-
*
2497-
* I_DIRTY_SYNC Inode is dirty, but doesn't have to be written on
2498-
* fdatasync() (unless I_DIRTY_DATASYNC is also set).
2499-
* Timestamp updates are the usual cause.
2500-
* I_DIRTY_DATASYNC Data-related inode changes pending. We keep track of
2501-
* these changes separately from I_DIRTY_SYNC so that we
2502-
* don't have to write inode on fdatasync() when only
2503-
* e.g. the timestamps have changed.
2504-
* I_DIRTY_PAGES Inode has dirty pages. Inode itself may be clean.
2505-
* I_DIRTY_TIME The inode itself has dirty timestamps, and the
2506-
* lazytime mount option is enabled. We keep track of this
2507-
* separately from I_DIRTY_SYNC in order to implement
2508-
* lazytime. This gets cleared if I_DIRTY_INODE
2509-
* (I_DIRTY_SYNC and/or I_DIRTY_DATASYNC) gets set. But
2510-
* I_DIRTY_TIME can still be set if I_DIRTY_SYNC is already
2511-
* in place because writeback might already be in progress
2512-
* and we don't want to lose the time update
2513-
* I_NEW Serves as both a mutex and completion notification.
2514-
* New inodes set I_NEW. If two processes both create
2515-
* the same inode, one of them will release its inode and
2516-
* wait for I_NEW to be released before returning.
2517-
* Inodes in I_WILL_FREE, I_FREEING or I_CLEAR state can
2518-
* also cause waiting on I_NEW, without I_NEW actually
2519-
* being set. find_inode() uses this to prevent returning
2520-
* nearly-dead inodes.
2521-
* I_WILL_FREE Must be set when calling write_inode_now() if i_count
2522-
* is zero. I_FREEING must be set when I_WILL_FREE is
2523-
* cleared.
2524-
* I_FREEING Set when inode is about to be freed but still has dirty
2525-
* pages or buffers attached or the inode itself is still
2526-
* dirty.
2527-
* I_CLEAR Added by clear_inode(). In this state the inode is
2528-
* clean and can be destroyed. Inode keeps I_FREEING.
2529-
*
2530-
* Inodes that are I_WILL_FREE, I_FREEING or I_CLEAR are
2531-
* prohibited for many purposes. iget() must wait for
2532-
* the inode to be completely released, then create it
2533-
* anew. Other functions will just ignore such inodes,
2534-
* if appropriate. I_NEW is used for waiting.
2535-
*
2536-
* I_SYNC Writeback of inode is running. The bit is set during
2537-
* data writeback, and cleared with a wakeup on the bit
2538-
* address once it is done. The bit is also used to pin
2539-
* the inode in memory for flusher thread.
2540-
*
2541-
* I_REFERENCED Marks the inode as recently references on the LRU list.
2542-
*
2543-
* I_WB_SWITCH Cgroup bdi_writeback switching in progress. Used to
2544-
* synchronize competing switching instances and to tell
2545-
* wb stat updates to grab the i_pages lock. See
2546-
* inode_switch_wbs_work_fn() for details.
2547-
*
2548-
* I_OVL_INUSE Used by overlayfs to get exclusive ownership on upper
2549-
* and work dirs among overlayfs mounts.
2550-
*
2551-
* I_CREATING New object's inode in the middle of setting up.
2552-
*
2553-
* I_DONTCACHE Evict inode as soon as it is not used anymore.
2554-
*
2555-
* I_SYNC_QUEUED Inode is queued in b_io or b_more_io writeback lists.
2556-
* Used to detect that mark_inode_dirty() should not move
2557-
* inode between dirty lists.
2558-
*
2559-
* I_PINNING_FSCACHE_WB Inode is pinning an fscache object for writeback.
2560-
*
2561-
* I_LRU_ISOLATING Inode is pinned being isolated from LRU without holding
2562-
* i_count.
2563-
*
2564-
* Q: What is the difference between I_WILL_FREE and I_FREEING?
2565-
*
2566-
* __I_{SYNC,NEW,LRU_ISOLATING} are used to derive unique addresses to wait
2567-
* upon. There's one free address left.
2568-
*/
2569-
#define __I_NEW 0
2570-
#define I_NEW (1 << __I_NEW)
2571-
#define __I_SYNC 1
2572-
#define I_SYNC (1 << __I_SYNC)
2573-
#define __I_LRU_ISOLATING 2
2574-
#define I_LRU_ISOLATING (1 << __I_LRU_ISOLATING)
2575-
2576-
#define I_DIRTY_SYNC (1 << 3)
2577-
#define I_DIRTY_DATASYNC (1 << 4)
2578-
#define I_DIRTY_PAGES (1 << 5)
2579-
#define I_WILL_FREE (1 << 6)
2580-
#define I_FREEING (1 << 7)
2581-
#define I_CLEAR (1 << 8)
2582-
#define I_REFERENCED (1 << 9)
2583-
#define I_LINKABLE (1 << 10)
2584-
#define I_DIRTY_TIME (1 << 11)
2585-
#define I_WB_SWITCH (1 << 12)
2586-
#define I_OVL_INUSE (1 << 13)
2587-
#define I_CREATING (1 << 14)
2588-
#define I_DONTCACHE (1 << 15)
2589-
#define I_SYNC_QUEUED (1 << 16)
2590-
#define I_PINNING_NETFS_WB (1 << 17)
2591-
2592-
#define I_DIRTY_INODE (I_DIRTY_SYNC | I_DIRTY_DATASYNC)
2593-
#define I_DIRTY (I_DIRTY_INODE | I_DIRTY_PAGES)
2594-
#define I_DIRTY_ALL (I_DIRTY | I_DIRTY_TIME)
2595-
25962603
extern void __mark_inode_dirty(struct inode *, int);
25972604
static inline void mark_inode_dirty(struct inode *inode)
25982605
{

0 commit comments

Comments
 (0)