Forwarded: [PATCH] gfs2: add debug printk to trace existing entry in gfs2_create_inode

syzbot
2026-03-06T10:41:51Z

fs/gfs2/inode.c | 26 +++++++++++++++++++++++++-
fs/namei.c | 30 ++++++++++++++++++++++++++++--
2 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 8344040ecaf7..e252f7720735 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -725,19 +725,26 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
error = gfs2_rindex_update(sdp);
if (error)
goto fail;
+ pr_warn("DEBUG GFS2: after glock_nq dir=%px rwsem owner=%px current=%px\n",
+ dir, READ_ONCE(dir->i_rwsem.owner), current);

error = gfs2_glock_nq_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, &d_gh);
+ pr_warn("DEBUG GFS2 A: dir=%px rwsem owner=%px\n", dir, READ_ONCE(dir->i_rwsem.owner));
if (error)
goto fail;
gfs2_holder_mark_uninitialized(&gh);

error = create_ok(dip, name, mode);
+ pr_warn("DEBUG GFS2 B: dir=%px rwsem owner=%px error=%d\n", dir, READ_ONCE(dir->i_rwsem.owner), error);
if (error)
goto fail_gunlock;

inode = gfs2_dir_search(dir, &dentry->d_name, !S_ISREG(mode) || excl);
error = PTR_ERR(inode);
if (!IS_ERR(inode)) {
+ pr_warn("DEBUG GFS2: gfs2_create_inode found existing entry! dir=%px mode=%o file=%px inode=%px S_ISDIR=%d rwsem owner=%px current=%px\n",
+ dir, mode, file, inode, S_ISDIR(inode->i_mode),
+ READ_ONCE(dir->i_rwsem.owner), current);
if (S_ISDIR(inode->i_mode)) {
iput(inode);
inode = NULL;
@@ -759,6 +766,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
}

error = gfs2_diradd_alloc_required(dir, name, &da);
+ pr_warn("DEBUG GFS2 C: dir=%px rwsem owner=%px error=%d\n", dir, READ_ONCE(dir->i_rwsem.owner), error);
if (error < 0)
goto fail_gunlock;

@@ -820,16 +828,20 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
blocks++;

error = alloc_dinode(ip, aflags, &blocks);
+ pr_warn("DEBUG GFS2 D: dir=%px rwsem owner=%px error=%d\n", dir, READ_ONCE(dir->i_rwsem.owner), error);
if (error)
goto fail_free_inode;

gfs2_set_inode_blocks(inode, blocks);

error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);
+ pr_warn("DEBUG GFS2 D1: dir=%px rwsem owner=%px error=%d\n", dir, READ_ONCE(dir->i_rwsem.owner), error);
+ if (error)
if (error)
goto fail_dealloc_inode;

error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
+ pr_warn("DEBUG GFS2 D2: dir=%px rwsem owner=%px error=%d\n", dir, READ_ONCE(dir->i_rwsem.owner), error);
if (error)
goto fail_dealloc_inode;
gfs2_cancel_delete_work(io_gl);
@@ -837,6 +849,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,

retry:
error = insert_inode_locked4(inode, ip->i_no_addr, iget_test, &ip->i_no_addr);
+ pr_warn("DEBUG GFS2 D3: dir=%px rwsem owner=%px error=%d\n", dir, READ_ONCE(dir->i_rwsem.owner), error);
if (error == -EBUSY)
goto retry;
if (error)
@@ -844,6 +857,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,

error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT | GL_NOPID,
&ip->i_iopen_gh);
+ pr_warn("DEBUG GFS2 E: dir=%px rwsem owner=%px error=%d\n", dir, READ_ONCE(dir->i_rwsem.owner), error);
if (error)
goto fail_gunlock2;

@@ -862,7 +876,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
}
init_dinode(dip, ip, symname);
gfs2_trans_end(sdp);
-
+ pr_warn("DEBUG GFS2 F: dir=%px rwsem owner=%px\n", dir, READ_ONCE(dir->i_rwsem.owner));
glock_set_object(ip->i_gl, ip);
glock_set_object(io_gl, ip);
gfs2_set_iop(inode);
@@ -888,11 +902,15 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
goto fail_gunlock4;

error = link_dinode(dip, name, ip, &da);
+ pr_warn("DEBUG GFS2 G: dir=%px rwsem owner=%px error=%d\n", dir, READ_ONCE(dir->i_rwsem.owner), error);
if (error)
goto fail_gunlock4;

mark_inode_dirty(inode);
d_instantiate(dentry, inode);
+ pr_warn("DEBUG GFS2 H: dir=%px rwsem owner=%px\n", dir, READ_ONCE(dir->i_rwsem.owner));
+ pr_warn("DEBUG GFS2: before glock_dq dir=%px rwsem owner=%px current=%px\n",
+ dir, READ_ONCE(dir->i_rwsem.owner), current);
/* After instantiate, errors should result in evict which will destroy
* both inode and iopen glocks properly. */
if (file) {
@@ -900,6 +918,8 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
error = finish_open(file, dentry, gfs2_open_common);
}
gfs2_glock_dq_uninit(&d_gh);
+ pr_warn("DEBUG GFS2: after glock_dq dir=%px rwsem owner=%px current=%px\n",
+ dir, READ_ONCE(dir->i_rwsem.owner), current);
gfs2_qa_put(ip);
gfs2_glock_dq_uninit(&gh);
gfs2_glock_put(io_gl);
@@ -937,7 +957,11 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
posix_acl_release(acl);
fail_gunlock:
gfs2_dir_no_add(&da);
+ pr_warn("DEBUG GFS2: fail_gunlock before glock_dq dir=%px rwsem owner=%px current=%px error=%d\n",
+ dir, READ_ONCE(dir->i_rwsem.owner), current, error);
gfs2_glock_dq_uninit(&d_gh);
+ pr_warn("DEBUG GFS2: fail_gunlock after glock_dq dir=%px rwsem owner=%px current=%px\n",
+ dir, READ_ONCE(dir->i_rwsem.owner), current);
if (!IS_ERR_OR_NULL(inode)) {
if (inode_state_read_once(inode) & I_NEW)
iget_failed(inode);