Skip to content

Commit c3c616c

Browse files
committed
Merge branch 'vfs-6.18.inode.refcount.preliminaries'
Bring in cleanup patches from the inode reference counting rework. Signed-off-by: Christian Brauner <brauner@kernel.org>
2 parents f0883b9 + 2ef435a commit c3c616c

18 files changed

Lines changed: 213 additions & 151 deletions

File tree

arch/powerpc/platforms/cell/spufs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ static int spufs_mfc_open(struct inode *inode, struct file *file)
14301430
if (ctx->owner != current->mm)
14311431
return -EINVAL;
14321432

1433-
if (atomic_read(&inode->i_count) != 1)
1433+
if (icount_read(inode) != 1)
14341434
return -EBUSY;
14351435

14361436
mutex_lock(&ctx->mapping_lock);

fs/btrfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4538,7 +4538,7 @@ static void btrfs_prune_dentries(struct btrfs_root *root)
45384538

45394539
inode = btrfs_find_first_inode(root, min_ino);
45404540
while (inode) {
4541-
if (atomic_read(&inode->vfs_inode.i_count) > 1)
4541+
if (icount_read(&inode->vfs_inode) > 1)
45424542
d_prune_aliases(&inode->vfs_inode);
45434543

45444544
min_ino = btrfs_ino(inode) + 1;

fs/ceph/mds_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2221,7 +2221,7 @@ static int trim_caps_cb(struct inode *inode, int mds, void *arg)
22212221
int count;
22222222
dput(dentry);
22232223
d_prune_aliases(inode);
2224-
count = atomic_read(&inode->i_count);
2224+
count = icount_read(inode);
22252225
if (count == 1)
22262226
(*remaining)--;
22272227
doutc(cl, "%p %llx.%llx cap %p pruned, count now %d\n",

fs/ext4/ialloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)
252252
"nonexistent device\n", __func__, __LINE__);
253253
return;
254254
}
255-
if (atomic_read(&inode->i_count) > 1) {
255+
if (icount_read(inode) > 1) {
256256
ext4_msg(sb, KERN_ERR, "%s:%d: inode #%lu: count=%d",
257257
__func__, __LINE__, inode->i_ino,
258-
atomic_read(&inode->i_count));
258+
icount_read(inode));
259259
return;
260260
}
261261
if (inode->i_nlink) {

fs/f2fs/super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ static int f2fs_drop_inode(struct inode *inode)
17501750
if ((!inode_unhashed(inode) && inode->i_state & I_SYNC)) {
17511751
if (!inode->i_nlink && !is_bad_inode(inode)) {
17521752
/* to avoid evict_inode call simultaneously */
1753-
atomic_inc(&inode->i_count);
1753+
__iget(inode);
17541754
spin_unlock(&inode->i_lock);
17551755

17561756
/* should remain fi->extent_tree for writepage */
@@ -1769,7 +1769,7 @@ static int f2fs_drop_inode(struct inode *inode)
17691769
sb_end_intwrite(inode->i_sb);
17701770

17711771
spin_lock(&inode->i_lock);
1772-
atomic_dec(&inode->i_count);
1772+
iput(inode);
17731773
}
17741774
trace_f2fs_drop_inode(inode, 0);
17751775
return 0;

fs/fs-writeback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ static int writeback_single_inode(struct inode *inode,
17671767
int ret = 0;
17681768

17691769
spin_lock(&inode->i_lock);
1770-
if (!atomic_read(&inode->i_count))
1770+
if (!icount_read(inode))
17711771
WARN_ON(!(inode->i_state & (I_WILL_FREE|I_FREEING)));
17721772
else
17731773
WARN_ON(inode->i_state & I_WILL_FREE);

fs/gfs2/ops_fstype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,7 @@ static void gfs2_evict_inodes(struct super_block *sb)
17541754
spin_unlock(&inode->i_lock);
17551755
continue;
17561756
}
1757-
atomic_inc(&inode->i_count);
1757+
__iget(inode);
17581758
spin_unlock(&inode->i_lock);
17591759
spin_unlock(&sb->s_inode_list_lock);
17601760

fs/hpfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void hpfs_write_inode(struct inode *i)
184184
struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
185185
struct inode *parent;
186186
if (i->i_ino == hpfs_sb(i->i_sb)->sb_root) return;
187-
if (hpfs_inode->i_rddir_off && !atomic_read(&i->i_count)) {
187+
if (hpfs_inode->i_rddir_off && !icount_read(i)) {
188188
if (*hpfs_inode->i_rddir_off)
189189
pr_err("write_inode: some position still there\n");
190190
kfree(hpfs_inode->i_rddir_off);

fs/inode.c

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ static void __inode_add_lru(struct inode *inode, bool rotate)
534534
{
535535
if (inode->i_state & (I_DIRTY_ALL | I_SYNC | I_FREEING | I_WILL_FREE))
536536
return;
537-
if (atomic_read(&inode->i_count))
537+
if (icount_read(inode))
538538
return;
539539
if (!(inode->i_sb->s_flags & SB_ACTIVE))
540540
return;
@@ -550,11 +550,11 @@ static void __inode_add_lru(struct inode *inode, bool rotate)
550550
struct wait_queue_head *inode_bit_waitqueue(struct wait_bit_queue_entry *wqe,
551551
struct inode *inode, u32 bit)
552552
{
553-
void *bit_address;
553+
void *bit_address;
554554

555-
bit_address = inode_state_wait_address(inode, bit);
556-
init_wait_var_entry(wqe, bit_address, 0);
557-
return __var_waitqueue(bit_address);
555+
bit_address = inode_state_wait_address(inode, bit);
556+
init_wait_var_entry(wqe, bit_address, 0);
557+
return __var_waitqueue(bit_address);
558558
}
559559
EXPORT_SYMBOL(inode_bit_waitqueue);
560560

@@ -871,11 +871,11 @@ void evict_inodes(struct super_block *sb)
871871
again:
872872
spin_lock(&sb->s_inode_list_lock);
873873
list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
874-
if (atomic_read(&inode->i_count))
874+
if (icount_read(inode))
875875
continue;
876876

877877
spin_lock(&inode->i_lock);
878-
if (atomic_read(&inode->i_count)) {
878+
if (icount_read(inode)) {
879879
spin_unlock(&inode->i_lock);
880880
continue;
881881
}
@@ -937,7 +937,7 @@ static enum lru_status inode_lru_isolate(struct list_head *item,
937937
* unreclaimable for a while. Remove them lazily here; iput,
938938
* sync, or the last page cache deletion will requeue them.
939939
*/
940-
if (atomic_read(&inode->i_count) ||
940+
if (icount_read(inode) ||
941941
(inode->i_state & ~I_REFERENCED) ||
942942
!mapping_shrinkable(&inode->i_data)) {
943943
list_lru_isolate(lru, &inode->i_lru);
@@ -1279,6 +1279,8 @@ struct inode *inode_insert5(struct inode *inode, unsigned long hashval,
12791279
struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval);
12801280
struct inode *old;
12811281

1282+
might_sleep();
1283+
12821284
again:
12831285
spin_lock(&inode_hash_lock);
12841286
old = find_inode(inode->i_sb, head, test, data, true);
@@ -1382,6 +1384,8 @@ struct inode *iget5_locked_rcu(struct super_block *sb, unsigned long hashval,
13821384
struct hlist_head *head = inode_hashtable + hash(sb, hashval);
13831385
struct inode *inode, *new;
13841386

1387+
might_sleep();
1388+
13851389
again:
13861390
inode = find_inode(sb, head, test, data, false);
13871391
if (inode) {
@@ -1422,6 +1426,9 @@ struct inode *iget_locked(struct super_block *sb, unsigned long ino)
14221426
{
14231427
struct hlist_head *head = inode_hashtable + hash(sb, ino);
14241428
struct inode *inode;
1429+
1430+
might_sleep();
1431+
14251432
again:
14261433
inode = find_inode_fast(sb, head, ino, false);
14271434
if (inode) {
@@ -1605,6 +1612,9 @@ struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
16051612
int (*test)(struct inode *, void *), void *data)
16061613
{
16071614
struct inode *inode;
1615+
1616+
might_sleep();
1617+
16081618
again:
16091619
inode = ilookup5_nowait(sb, hashval, test, data);
16101620
if (inode) {
@@ -1630,6 +1640,9 @@ struct inode *ilookup(struct super_block *sb, unsigned long ino)
16301640
{
16311641
struct hlist_head *head = inode_hashtable + hash(sb, ino);
16321642
struct inode *inode;
1643+
1644+
might_sleep();
1645+
16331646
again:
16341647
inode = find_inode_fast(sb, head, ino, false);
16351648

@@ -1780,6 +1793,8 @@ int insert_inode_locked(struct inode *inode)
17801793
ino_t ino = inode->i_ino;
17811794
struct hlist_head *head = inode_hashtable + hash(sb, ino);
17821795

1796+
might_sleep();
1797+
17831798
while (1) {
17841799
struct inode *old = NULL;
17851800
spin_lock(&inode_hash_lock);
@@ -1826,6 +1841,8 @@ int insert_inode_locked4(struct inode *inode, unsigned long hashval,
18261841
{
18271842
struct inode *old;
18281843

1844+
might_sleep();
1845+
18291846
inode->i_state |= I_CREATING;
18301847
old = inode_insert5(inode, hashval, test, NULL, data);
18311848

@@ -1908,20 +1925,45 @@ static void iput_final(struct inode *inode)
19081925
*/
19091926
void iput(struct inode *inode)
19101927
{
1911-
if (!inode)
1928+
might_sleep();
1929+
if (unlikely(!inode))
19121930
return;
1913-
BUG_ON(inode->i_state & I_CLEAR);
1931+
19141932
retry:
1915-
if (atomic_dec_and_lock(&inode->i_count, &inode->i_lock)) {
1916-
if (inode->i_nlink && (inode->i_state & I_DIRTY_TIME)) {
1917-
atomic_inc(&inode->i_count);
1918-
spin_unlock(&inode->i_lock);
1919-
trace_writeback_lazytime_iput(inode);
1920-
mark_inode_dirty_sync(inode);
1921-
goto retry;
1922-
}
1923-
iput_final(inode);
1933+
lockdep_assert_not_held(&inode->i_lock);
1934+
VFS_BUG_ON_INODE(inode->i_state & I_CLEAR, inode);
1935+
/*
1936+
* Note this assert is technically racy as if the count is bogusly
1937+
* equal to one, then two CPUs racing to further drop it can both
1938+
* conclude it's fine.
1939+
*/
1940+
VFS_BUG_ON_INODE(atomic_read(&inode->i_count) < 1, inode);
1941+
1942+
if (atomic_add_unless(&inode->i_count, -1, 1))
1943+
return;
1944+
1945+
if ((inode->i_state & I_DIRTY_TIME) && inode->i_nlink) {
1946+
trace_writeback_lazytime_iput(inode);
1947+
mark_inode_dirty_sync(inode);
1948+
goto retry;
1949+
}
1950+
1951+
spin_lock(&inode->i_lock);
1952+
if (unlikely((inode->i_state & I_DIRTY_TIME) && inode->i_nlink)) {
1953+
spin_unlock(&inode->i_lock);
1954+
goto retry;
1955+
}
1956+
1957+
if (!atomic_dec_and_test(&inode->i_count)) {
1958+
spin_unlock(&inode->i_lock);
1959+
return;
19241960
}
1961+
1962+
/*
1963+
* iput_final() drops ->i_lock, we can't assert on it as the inode may
1964+
* be deallocated by the time the call returns.
1965+
*/
1966+
iput_final(inode);
19251967
}
19261968
EXPORT_SYMBOL(iput);
19271969

@@ -2911,10 +2953,18 @@ EXPORT_SYMBOL(mode_strip_sgid);
29112953
*
29122954
* TODO: add a proper inode dumping routine, this is a stub to get debug off the
29132955
* ground.
2956+
*
2957+
* TODO: handle getting to fs type with get_kernel_nofault()?
2958+
* See dump_mapping() above.
29142959
*/
29152960
void dump_inode(struct inode *inode, const char *reason)
29162961
{
2917-
pr_warn("%s encountered for inode %px", reason, inode);
2962+
struct super_block *sb = inode->i_sb;
2963+
2964+
pr_warn("%s encountered for inode %px\n"
2965+
"fs %s mode %ho opflags 0x%hx flags 0x%x state 0x%x count %d\n",
2966+
reason, inode, sb->s_type->name, inode->i_mode, inode->i_opflags,
2967+
inode->i_flags, inode->i_state, atomic_read(&inode->i_count));
29182968
}
29192969

29202970
EXPORT_SYMBOL(dump_inode);

fs/nfs/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr)
608608
inode->i_sb->s_id,
609609
(unsigned long long)NFS_FILEID(inode),
610610
nfs_display_fhandle_hash(fh),
611-
atomic_read(&inode->i_count));
611+
icount_read(inode));
612612

613613
out:
614614
return inode;
@@ -2229,7 +2229,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr)
22292229
dfprintk(VFS, "NFS: %s(%s/%lu fh_crc=0x%08x ct=%d info=0x%llx)\n",
22302230
__func__, inode->i_sb->s_id, inode->i_ino,
22312231
nfs_display_fhandle_hash(NFS_FH(inode)),
2232-
atomic_read(&inode->i_count), fattr->valid);
2232+
icount_read(inode), fattr->valid);
22332233

22342234
if (!(fattr->valid & NFS_ATTR_FATTR_FILEID)) {
22352235
/* Only a mounted-on-fileid? Just exit */

0 commit comments

Comments
 (0)