Skip to content

Commit 5c623c3

Browse files
committed
Merge tag 'gfs2-v5.16-rc4-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2
Pull gfs2 fixes from Andreas Gruenbacher: - Since commit 486408d ("gfs2: Cancel remote delete work asynchronously"), inode create and lookup-by-number can overlap more easily and we can end up with temporary duplicate inodes. Fix the code to prevent that. - Fix a BUG demoting weak glock holders from a remote node. * tag 'gfs2-v5.16-rc4-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2: gfs2: gfs2_create_inode rework gfs2: gfs2_inode_lookup rework gfs2: gfs2_inode_lookup cleanup gfs2: Fix remote demote of weak glock holders
2 parents 12119cf + 3d36e57 commit 5c623c3

File tree

2 files changed

+52
-67
lines changed

2 files changed

+52
-67
lines changed

fs/gfs2/glock.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,6 @@ void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs)
18571857

18581858
void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
18591859
{
1860-
struct gfs2_holder mock_gh = { .gh_gl = gl, .gh_state = state, };
18611860
unsigned long delay = 0;
18621861
unsigned long holdtime;
18631862
unsigned long now = jiffies;
@@ -1890,8 +1889,13 @@ void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
18901889
* keep the glock until the last strong holder is done with it.
18911890
*/
18921891
if (!find_first_strong_holder(gl)) {
1893-
if (state == LM_ST_UNLOCKED)
1894-
mock_gh.gh_state = LM_ST_EXCLUSIVE;
1892+
struct gfs2_holder mock_gh = {
1893+
.gh_gl = gl,
1894+
.gh_state = (state == LM_ST_UNLOCKED) ?
1895+
LM_ST_EXCLUSIVE : state,
1896+
.gh_iflags = BIT(HIF_HOLDER)
1897+
};
1898+
18951899
demote_incompat_holders(gl, &mock_gh);
18961900
}
18971901
handle_callback(gl, state, delay, true);

fs/gfs2/inode.c

Lines changed: 45 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -40,37 +40,6 @@ static const struct inode_operations gfs2_file_iops;
4040
static const struct inode_operations gfs2_dir_iops;
4141
static const struct inode_operations gfs2_symlink_iops;
4242

43-
static int iget_test(struct inode *inode, void *opaque)
44-
{
45-
u64 no_addr = *(u64 *)opaque;
46-
47-
return GFS2_I(inode)->i_no_addr == no_addr;
48-
}
49-
50-
static int iget_set(struct inode *inode, void *opaque)
51-
{
52-
u64 no_addr = *(u64 *)opaque;
53-
54-
GFS2_I(inode)->i_no_addr = no_addr;
55-
inode->i_ino = no_addr;
56-
return 0;
57-
}
58-
59-
static struct inode *gfs2_iget(struct super_block *sb, u64 no_addr)
60-
{
61-
struct inode *inode;
62-
63-
repeat:
64-
inode = iget5_locked(sb, no_addr, iget_test, iget_set, &no_addr);
65-
if (!inode)
66-
return inode;
67-
if (is_bad_inode(inode)) {
68-
iput(inode);
69-
goto repeat;
70-
}
71-
return inode;
72-
}
73-
7443
/**
7544
* gfs2_set_iop - Sets inode operations
7645
* @inode: The inode with correct i_mode filled in
@@ -104,6 +73,22 @@ static void gfs2_set_iop(struct inode *inode)
10473
}
10574
}
10675

76+
static int iget_test(struct inode *inode, void *opaque)
77+
{
78+
u64 no_addr = *(u64 *)opaque;
79+
80+
return GFS2_I(inode)->i_no_addr == no_addr;
81+
}
82+
83+
static int iget_set(struct inode *inode, void *opaque)
84+
{
85+
u64 no_addr = *(u64 *)opaque;
86+
87+
GFS2_I(inode)->i_no_addr = no_addr;
88+
inode->i_ino = no_addr;
89+
return 0;
90+
}
91+
10792
/**
10893
* gfs2_inode_lookup - Lookup an inode
10994
* @sb: The super block
@@ -132,35 +117,28 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
132117
{
133118
struct inode *inode;
134119
struct gfs2_inode *ip;
135-
struct gfs2_glock *io_gl = NULL;
136120
struct gfs2_holder i_gh;
137121
int error;
138122

139123
gfs2_holder_mark_uninitialized(&i_gh);
140-
inode = gfs2_iget(sb, no_addr);
124+
inode = iget5_locked(sb, no_addr, iget_test, iget_set, &no_addr);
141125
if (!inode)
142126
return ERR_PTR(-ENOMEM);
143127

144128
ip = GFS2_I(inode);
145129

146130
if (inode->i_state & I_NEW) {
147131
struct gfs2_sbd *sdp = GFS2_SB(inode);
132+
struct gfs2_glock *io_gl;
148133

149134
error = gfs2_glock_get(sdp, no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);
150135
if (unlikely(error))
151136
goto fail;
152-
flush_delayed_work(&ip->i_gl->gl_work);
153-
154-
error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
155-
if (unlikely(error))
156-
goto fail;
157-
if (blktype != GFS2_BLKST_UNLINKED)
158-
gfs2_cancel_delete_work(io_gl);
159137

160138
if (type == DT_UNKNOWN || blktype != GFS2_BLKST_FREE) {
161139
/*
162140
* The GL_SKIP flag indicates to skip reading the inode
163-
* block. We read the inode with gfs2_inode_refresh
141+
* block. We read the inode when instantiating it
164142
* after possibly checking the block type.
165143
*/
166144
error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE,
@@ -181,56 +159,55 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
181159
}
182160
}
183161

184-
glock_set_object(ip->i_gl, ip);
185162
set_bit(GLF_INSTANTIATE_NEEDED, &ip->i_gl->gl_flags);
186-
error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh);
163+
164+
error = gfs2_glock_get(sdp, no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
187165
if (unlikely(error))
188166
goto fail;
189-
glock_set_object(ip->i_iopen_gh.gh_gl, ip);
167+
if (blktype != GFS2_BLKST_UNLINKED)
168+
gfs2_cancel_delete_work(io_gl);
169+
error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh);
190170
gfs2_glock_put(io_gl);
191-
io_gl = NULL;
171+
if (unlikely(error))
172+
goto fail;
192173

193174
/* Lowest possible timestamp; will be overwritten in gfs2_dinode_in. */
194175
inode->i_atime.tv_sec = 1LL << (8 * sizeof(inode->i_atime.tv_sec) - 1);
195176
inode->i_atime.tv_nsec = 0;
196177

178+
glock_set_object(ip->i_gl, ip);
179+
197180
if (type == DT_UNKNOWN) {
198181
/* Inode glock must be locked already */
199182
error = gfs2_instantiate(&i_gh);
200-
if (error)
183+
if (error) {
184+
glock_clear_object(ip->i_gl, ip);
201185
goto fail;
186+
}
202187
} else {
203188
ip->i_no_formal_ino = no_formal_ino;
204189
inode->i_mode = DT2IF(type);
205190
}
206191

207192
if (gfs2_holder_initialized(&i_gh))
208193
gfs2_glock_dq_uninit(&i_gh);
194+
glock_set_object(ip->i_iopen_gh.gh_gl, ip);
209195

210196
gfs2_set_iop(inode);
197+
unlock_new_inode(inode);
211198
}
212199

213200
if (no_formal_ino && ip->i_no_formal_ino &&
214201
no_formal_ino != ip->i_no_formal_ino) {
215-
error = -ESTALE;
216-
if (inode->i_state & I_NEW)
217-
goto fail;
218202
iput(inode);
219-
return ERR_PTR(error);
203+
return ERR_PTR(-ESTALE);
220204
}
221205

222-
if (inode->i_state & I_NEW)
223-
unlock_new_inode(inode);
224-
225206
return inode;
226207

227208
fail:
228-
if (gfs2_holder_initialized(&ip->i_iopen_gh)) {
229-
glock_clear_object(ip->i_iopen_gh.gh_gl, ip);
209+
if (gfs2_holder_initialized(&ip->i_iopen_gh))
230210
gfs2_glock_dq_uninit(&ip->i_iopen_gh);
231-
}
232-
if (io_gl)
233-
gfs2_glock_put(io_gl);
234211
if (gfs2_holder_initialized(&i_gh))
235212
gfs2_glock_dq_uninit(&i_gh);
236213
iget_failed(inode);
@@ -730,18 +707,19 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
730707
error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_inode_glops, CREATE, &ip->i_gl);
731708
if (error)
732709
goto fail_free_inode;
733-
flush_delayed_work(&ip->i_gl->gl_work);
734710

735711
error = gfs2_glock_get(sdp, ip->i_no_addr, &gfs2_iopen_glops, CREATE, &io_gl);
736712
if (error)
737713
goto fail_free_inode;
738714
gfs2_cancel_delete_work(io_gl);
739715

716+
error = insert_inode_locked4(inode, ip->i_no_addr, iget_test, &ip->i_no_addr);
717+
BUG_ON(error);
718+
740719
error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_SKIP, ghs + 1);
741720
if (error)
742721
goto fail_gunlock2;
743722

744-
glock_set_object(ip->i_gl, ip);
745723
error = gfs2_trans_begin(sdp, blocks, 0);
746724
if (error)
747725
goto fail_gunlock2;
@@ -757,9 +735,9 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
757735
if (error)
758736
goto fail_gunlock2;
759737

738+
glock_set_object(ip->i_gl, ip);
760739
glock_set_object(io_gl, ip);
761740
gfs2_set_iop(inode);
762-
insert_inode_hash(inode);
763741

764742
free_vfs_inode = 0; /* After this point, the inode is no longer
765743
considered free. Any failures need to undo
@@ -801,17 +779,17 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
801779
gfs2_glock_dq_uninit(ghs + 1);
802780
gfs2_glock_put(io_gl);
803781
gfs2_qa_put(dip);
782+
unlock_new_inode(inode);
804783
return error;
805784

806785
fail_gunlock3:
786+
glock_clear_object(ip->i_gl, ip);
807787
glock_clear_object(io_gl, ip);
808788
gfs2_glock_dq_uninit(&ip->i_iopen_gh);
809789
fail_gunlock2:
810-
glock_clear_object(io_gl, ip);
811790
gfs2_glock_put(io_gl);
812791
fail_free_inode:
813792
if (ip->i_gl) {
814-
glock_clear_object(ip->i_gl, ip);
815793
if (free_vfs_inode) /* else evict will do the put for us */
816794
gfs2_glock_put(ip->i_gl);
817795
}
@@ -829,7 +807,10 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
829807
mark_inode_dirty(inode);
830808
set_bit(free_vfs_inode ? GIF_FREE_VFS_INODE : GIF_ALLOC_FAILED,
831809
&GFS2_I(inode)->i_flags);
832-
iput(inode);
810+
if (inode->i_state & I_NEW)
811+
iget_failed(inode);
812+
else
813+
iput(inode);
833814
}
834815
if (gfs2_holder_initialized(ghs + 1))
835816
gfs2_glock_dq_uninit(ghs + 1);

0 commit comments

Comments
 (0)