Skip to content

Commit a0e3cc6

Browse files
committed
gfs2: Turn gl_delete into a delayed work
This requires flushing delayed work items in gfs2_make_fs_ro (which is called before unmounting a filesystem). When inodes are deleted and then recreated, pending gl_delete work items would have no effect because the inode generations will have changed, so we can cancel any pending gl_delete works before reusing iopen glocks. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
1 parent f286d62 commit a0e3cc6

7 files changed

Lines changed: 65 additions & 8 deletions

File tree

‎fs/gfs2/glock.c‎

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,11 +776,16 @@ bool gfs2_inode_already_deleted(struct gfs2_glock *gl, u64 generation)
776776

777777
static void delete_work_func(struct work_struct *work)
778778
{
779-
struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_delete);
779+
struct delayed_work *dwork = to_delayed_work(work);
780+
struct gfs2_glock *gl = container_of(dwork, struct gfs2_glock, gl_delete);
780781
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
781782
struct inode *inode;
782783
u64 no_addr = gl->gl_name.ln_number;
783784

785+
spin_lock(&gl->gl_lockref.lock);
786+
clear_bit(GLF_PENDING_DELETE, &gl->gl_flags);
787+
spin_unlock(&gl->gl_lockref.lock);
788+
784789
/* If someone's using this glock to create a new dinode, the block must
785790
have been freed by another node, then re-used, in which case our
786791
iopen callback is too late after the fact. Ignore it. */
@@ -949,7 +954,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
949954
gl->gl_object = NULL;
950955
gl->gl_hold_time = GL_GLOCK_DFT_HOLD;
951956
INIT_DELAYED_WORK(&gl->gl_work, glock_work_func);
952-
INIT_WORK(&gl->gl_delete, delete_work_func);
957+
INIT_DELAYED_WORK(&gl->gl_delete, delete_work_func);
953958

954959
mapping = gfs2_glock2aspace(gl);
955960
if (mapping) {
@@ -1772,6 +1777,44 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
17721777
rhashtable_walk_exit(&iter);
17731778
}
17741779

1780+
bool gfs2_queue_delete_work(struct gfs2_glock *gl, unsigned long delay)
1781+
{
1782+
bool queued;
1783+
1784+
spin_lock(&gl->gl_lockref.lock);
1785+
queued = queue_delayed_work(gfs2_delete_workqueue,
1786+
&gl->gl_delete, delay);
1787+
if (queued)
1788+
set_bit(GLF_PENDING_DELETE, &gl->gl_flags);
1789+
spin_unlock(&gl->gl_lockref.lock);
1790+
return queued;
1791+
}
1792+
1793+
void gfs2_cancel_delete_work(struct gfs2_glock *gl)
1794+
{
1795+
if (cancel_delayed_work_sync(&gl->gl_delete)) {
1796+
clear_bit(GLF_PENDING_DELETE, &gl->gl_flags);
1797+
gfs2_glock_put(gl);
1798+
}
1799+
}
1800+
1801+
bool gfs2_delete_work_queued(const struct gfs2_glock *gl)
1802+
{
1803+
return test_bit(GLF_PENDING_DELETE, &gl->gl_flags);
1804+
}
1805+
1806+
static void flush_delete_work(struct gfs2_glock *gl)
1807+
{
1808+
flush_delayed_work(&gl->gl_delete);
1809+
gfs2_glock_queue_work(gl, 0);
1810+
}
1811+
1812+
void gfs2_flush_delete_work(struct gfs2_sbd *sdp)
1813+
{
1814+
glock_hash_walk(flush_delete_work, sdp);
1815+
flush_workqueue(gfs2_delete_workqueue);
1816+
}
1817+
17751818
/**
17761819
* thaw_glock - thaw out a glock which has an unprocessed reply waiting
17771820
* @gl: The glock to thaw

‎fs/gfs2/glock.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ static inline int gfs2_glock_nq_init(struct gfs2_glock *gl,
235235

236236
extern void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state);
237237
extern void gfs2_glock_complete(struct gfs2_glock *gl, int ret);
238+
extern bool gfs2_queue_delete_work(struct gfs2_glock *gl, unsigned long delay);
239+
extern void gfs2_cancel_delete_work(struct gfs2_glock *gl);
240+
extern bool gfs2_delete_work_queued(const struct gfs2_glock *gl);
241+
extern void gfs2_flush_delete_work(struct gfs2_sbd *sdp);
238242
extern void gfs2_gl_hash_clear(struct gfs2_sbd *sdp);
239243
extern void gfs2_glock_finish_truncate(struct gfs2_inode *ip);
240244
extern void gfs2_glock_thaw(struct gfs2_sbd *sdp);

‎fs/gfs2/glops.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,11 +608,17 @@ static void iopen_go_callback(struct gfs2_glock *gl, bool remote)
608608
if (gl->gl_demote_state == LM_ST_UNLOCKED &&
609609
gl->gl_state == LM_ST_SHARED && ip) {
610610
gl->gl_lockref.count++;
611-
if (queue_work(gfs2_delete_workqueue, &gl->gl_delete) == 0)
611+
if (!queue_delayed_work(gfs2_delete_workqueue,
612+
&gl->gl_delete, 0))
612613
gl->gl_lockref.count--;
613614
}
614615
}
615616

617+
static int iopen_go_demote_ok(const struct gfs2_glock *gl)
618+
{
619+
return !gfs2_delete_work_queued(gl);
620+
}
621+
616622
/**
617623
* inode_go_free - wake up anyone waiting for dlm's unlock ast to free it
618624
* @gl: glock being freed
@@ -716,6 +722,7 @@ const struct gfs2_glock_operations gfs2_freeze_glops = {
716722
const struct gfs2_glock_operations gfs2_iopen_glops = {
717723
.go_type = LM_TYPE_IOPEN,
718724
.go_callback = iopen_go_callback,
725+
.go_demote_ok = iopen_go_demote_ok,
719726
.go_flags = GLOF_LRU | GLOF_NONDISK,
720727
};
721728

‎fs/gfs2/incore.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ enum {
345345
GLF_OBJECT = 14, /* Used only for tracing */
346346
GLF_BLOCKING = 15,
347347
GLF_INODE_CREATING = 16, /* Inode creation occurring */
348+
GLF_PENDING_DELETE = 17,
348349
GLF_FREEING = 18, /* Wait for glock to be freed */
349350
};
350351

@@ -378,8 +379,8 @@ struct gfs2_glock {
378379
atomic_t gl_revokes;
379380
struct delayed_work gl_work;
380381
union {
381-
/* For inode and iopen glocks only */
382-
struct work_struct gl_delete;
382+
/* For iopen glocks only */
383+
struct delayed_work gl_delete;
383384
/* For rgrp glocks only */
384385
struct {
385386
loff_t start;

‎fs/gfs2/inode.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type,
170170
error = gfs2_glock_nq_init(io_gl, LM_ST_SHARED, GL_EXACT, &ip->i_iopen_gh);
171171
if (unlikely(error))
172172
goto fail;
173+
gfs2_cancel_delete_work(ip->i_iopen_gh.gh_gl);
173174
glock_set_object(ip->i_iopen_gh.gh_gl, ip);
174175
gfs2_glock_put(io_gl);
175176
io_gl = NULL;
@@ -724,6 +725,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
724725
if (error)
725726
goto fail_gunlock2;
726727

728+
gfs2_cancel_delete_work(ip->i_iopen_gh.gh_gl);
727729
glock_set_object(ip->i_iopen_gh.gh_gl, ip);
728730
gfs2_set_iop(inode);
729731
insert_inode_hash(inode);

‎fs/gfs2/rgrp.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1835,7 +1835,7 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip
18351835
*/
18361836
ip = gl->gl_object;
18371837

1838-
if (ip || queue_work(gfs2_delete_workqueue, &gl->gl_delete) == 0)
1838+
if (ip || !gfs2_queue_delete_work(gl, 0))
18391839
gfs2_glock_put(gl);
18401840
else
18411841
found++;

‎fs/gfs2/super.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
626626
}
627627
}
628628

629-
flush_workqueue(gfs2_delete_workqueue);
629+
gfs2_flush_delete_work(sdp);
630630
if (!log_write_allowed && current == sdp->sd_quotad_process)
631631
fs_warn(sdp, "The quotad daemon is withdrawing.\n");
632632
else if (sdp->sd_quotad_process)
@@ -1054,7 +1054,7 @@ static int gfs2_drop_inode(struct inode *inode)
10541054
struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
10551055

10561056
gfs2_glock_hold(gl);
1057-
if (queue_work(gfs2_delete_workqueue, &gl->gl_delete) == 0)
1057+
if (!gfs2_queue_delete_work(gl, 0))
10581058
gfs2_glock_queue_put(gl);
10591059
return false;
10601060
}

0 commit comments

Comments
 (0)