Skip to content

Commit c96e6da

Browse files
committed
Merge tag 'gfs2-4.13.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2
Pull GFS2 updates from Bob Peterson: "We've got eight GFS2 patches for this merge window: - Andreas Gruenbacher has four patches related to cleaning up the GFS2 inode evict process. This is about half of his patches designed to fix a long-standing GFS2 hang related to the inode shrinker: Shrinker calls gfs2 evict, evict calls DLM, DLM requires memory and blocks on the shrinker. These four patches have been well tested. His second set of patches are still being tested, so I plan to hold them until the next merge window, after we have more weeks of testing. The first patch eliminates the flush_delayed_work, which can block. - Andreas's second patch protects setting of gl_object for rgrps with a spin_lock to prevent proven races. - His third patch introduces a centralized mechanism for queueing glock work with better reference counting, to prevent more races. -His fourth patch retains a reference to inode glocks when an error occurs while creating an inode. This keeps the subsequent evict from needing to reacquire the glock, which might call into DLM and block in low memory conditions. - Arvind Yadav has a patch to add const to attribute_group structures. - I have a patch to detect directory entry inconsistencies and withdraw the file system if any are found. Better that than silent corruption. - I have a patch to remove a vestigial variable from glock structures, saving some slab space. - I have another patch to remove a vestigial variable from the GFS2 in-core superblock structure" * tag 'gfs2-4.13.fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2: GFS2: constify attribute_group structures. gfs2: gfs2_create_inode: Keep glock across iput gfs2: Clean up glock work enqueuing gfs2: Protect gl->gl_object by spin lock gfs2: Get rid of flush_delayed_work in gfs2_evict_inode GFS2: Eliminate vestigial sd_log_flush_wrapped GFS2: Remove gl_list from glock structure GFS2: Withdraw when directory entry inconsistencies are detected
2 parents 8c27cb3 + 2969525 commit c96e6da

14 files changed

Lines changed: 175 additions & 102 deletions

File tree

‎fs/gfs2/bmap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ static int sweep_bh_for_rgrps(struct gfs2_inode *ip, struct gfs2_holder *rd_gh,
970970
continue;
971971
bn = be64_to_cpu(*p);
972972
if (gfs2_holder_initialized(rd_gh)) {
973-
rgd = (struct gfs2_rgrpd *)rd_gh->gh_gl->gl_object;
973+
rgd = gfs2_glock2rgrp(rd_gh->gh_gl);
974974
gfs2_assert_withdraw(sdp,
975975
gfs2_glock_is_locked_by_me(rd_gh->gh_gl));
976976
} else {

‎fs/gfs2/dir.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,7 @@ static int gfs2_dir_read_leaf(struct inode *inode, struct dir_context *ctx,
14441444
"g.offset (%u)\n",
14451445
(unsigned long long)bh->b_blocknr,
14461446
entries2, g.offset);
1447-
1447+
gfs2_consist_inode(ip);
14481448
error = -EIO;
14491449
goto out_free;
14501450
}
@@ -1612,6 +1612,7 @@ int gfs2_dir_read(struct inode *inode, struct dir_context *ctx,
16121612
(unsigned long long)dip->i_no_addr,
16131613
dip->i_entries,
16141614
g.offset);
1615+
gfs2_consist_inode(dip);
16151616
error = -EIO;
16161617
goto out;
16171618
}
@@ -2031,8 +2032,8 @@ static int leaf_dealloc(struct gfs2_inode *dip, u32 index, u32 len,
20312032
gfs2_rlist_alloc(&rlist, LM_ST_EXCLUSIVE);
20322033

20332034
for (x = 0; x < rlist.rl_rgrps; x++) {
2034-
struct gfs2_rgrpd *rgd;
2035-
rgd = rlist.rl_ghs[x].gh_gl->gl_object;
2035+
struct gfs2_rgrpd *rgd = gfs2_glock2rgrp(rlist.rl_ghs[x].gh_gl);
2036+
20362037
rg_blocks += rgd->rd_length;
20372038
}
20382039

‎fs/gfs2/glock.c‎

Lines changed: 74 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,34 @@ static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl)
152152
spin_unlock(&lru_lock);
153153
}
154154

155-
/**
156-
* gfs2_glock_put() - Decrement reference count on glock
157-
* @gl: The glock to put
158-
*
155+
/*
156+
* Enqueue the glock on the work queue. Passes one glock reference on to the
157+
* work queue.
159158
*/
159+
static void __gfs2_glock_queue_work(struct gfs2_glock *gl, unsigned long delay) {
160+
if (!queue_delayed_work(glock_workqueue, &gl->gl_work, delay)) {
161+
/*
162+
* We are holding the lockref spinlock, and the work was still
163+
* queued above. The queued work (glock_work_func) takes that
164+
* spinlock before dropping its glock reference(s), so it
165+
* cannot have dropped them in the meantime.
166+
*/
167+
GLOCK_BUG_ON(gl, gl->gl_lockref.count < 2);
168+
gl->gl_lockref.count--;
169+
}
170+
}
160171

161-
void gfs2_glock_put(struct gfs2_glock *gl)
172+
static void gfs2_glock_queue_work(struct gfs2_glock *gl, unsigned long delay) {
173+
spin_lock(&gl->gl_lockref.lock);
174+
__gfs2_glock_queue_work(gl, delay);
175+
spin_unlock(&gl->gl_lockref.lock);
176+
}
177+
178+
static void __gfs2_glock_put(struct gfs2_glock *gl)
162179
{
163180
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
164181
struct address_space *mapping = gfs2_glock2aspace(gl);
165182

166-
if (lockref_put_or_lock(&gl->gl_lockref))
167-
return;
168-
169183
lockref_mark_dead(&gl->gl_lockref);
170184

171185
gfs2_glock_remove_from_lru(gl);
@@ -177,6 +191,20 @@ void gfs2_glock_put(struct gfs2_glock *gl)
177191
sdp->sd_lockstruct.ls_ops->lm_put_lock(gl);
178192
}
179193

194+
/**
195+
* gfs2_glock_put() - Decrement reference count on glock
196+
* @gl: The glock to put
197+
*
198+
*/
199+
200+
void gfs2_glock_put(struct gfs2_glock *gl)
201+
{
202+
if (lockref_put_or_lock(&gl->gl_lockref))
203+
return;
204+
205+
__gfs2_glock_put(gl);
206+
}
207+
180208
/**
181209
* may_grant - check if its ok to grant a new lock
182210
* @gl: The glock
@@ -482,8 +510,7 @@ __acquires(&gl->gl_lockref.lock)
482510
target == LM_ST_UNLOCKED &&
483511
test_bit(SDF_SKIP_DLM_UNLOCK, &sdp->sd_flags)) {
484512
finish_xmote(gl, target);
485-
if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
486-
gfs2_glock_put(gl);
513+
gfs2_glock_queue_work(gl, 0);
487514
}
488515
else if (ret) {
489516
pr_err("lm_lock ret %d\n", ret);
@@ -492,8 +519,7 @@ __acquires(&gl->gl_lockref.lock)
492519
}
493520
} else { /* lock_nolock */
494521
finish_xmote(gl, target);
495-
if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
496-
gfs2_glock_put(gl);
522+
gfs2_glock_queue_work(gl, 0);
497523
}
498524

499525
spin_lock(&gl->gl_lockref.lock);
@@ -565,8 +591,7 @@ __acquires(&gl->gl_lockref.lock)
565591
clear_bit(GLF_LOCK, &gl->gl_flags);
566592
smp_mb__after_atomic();
567593
gl->gl_lockref.count++;
568-
if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
569-
gl->gl_lockref.count--;
594+
__gfs2_glock_queue_work(gl, 0);
570595
return;
571596

572597
out_unlock:
@@ -601,11 +626,11 @@ static void glock_work_func(struct work_struct *work)
601626
{
602627
unsigned long delay = 0;
603628
struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_work.work);
604-
int drop_ref = 0;
629+
unsigned int drop_refs = 1;
605630

606631
if (test_and_clear_bit(GLF_REPLY_PENDING, &gl->gl_flags)) {
607632
finish_xmote(gl, gl->gl_reply);
608-
drop_ref = 1;
633+
drop_refs++;
609634
}
610635
spin_lock(&gl->gl_lockref.lock);
611636
if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
@@ -623,17 +648,25 @@ static void glock_work_func(struct work_struct *work)
623648
}
624649
}
625650
run_queue(gl, 0);
626-
spin_unlock(&gl->gl_lockref.lock);
627-
if (!delay)
628-
gfs2_glock_put(gl);
629-
else {
651+
if (delay) {
652+
/* Keep one glock reference for the work we requeue. */
653+
drop_refs--;
630654
if (gl->gl_name.ln_type != LM_TYPE_INODE)
631655
delay = 0;
632-
if (queue_delayed_work(glock_workqueue, &gl->gl_work, delay) == 0)
633-
gfs2_glock_put(gl);
656+
__gfs2_glock_queue_work(gl, delay);
634657
}
635-
if (drop_ref)
636-
gfs2_glock_put(gl);
658+
659+
/*
660+
* Drop the remaining glock references manually here. (Mind that
661+
* __gfs2_glock_queue_work depends on the lockref spinlock begin held
662+
* here as well.)
663+
*/
664+
gl->gl_lockref.count -= drop_refs;
665+
if (!gl->gl_lockref.count) {
666+
__gfs2_glock_put(gl);
667+
return;
668+
}
669+
spin_unlock(&gl->gl_lockref.lock);
637670
}
638671

639672
/**
@@ -986,8 +1019,7 @@ int gfs2_glock_nq(struct gfs2_holder *gh)
9861019
test_and_clear_bit(GLF_FROZEN, &gl->gl_flags))) {
9871020
set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
9881021
gl->gl_lockref.count++;
989-
if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
990-
gl->gl_lockref.count--;
1022+
__gfs2_glock_queue_work(gl, 0);
9911023
}
9921024
run_queue(gl, 1);
9931025
spin_unlock(&gl->gl_lockref.lock);
@@ -1047,17 +1079,15 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
10471079
gfs2_glock_add_to_lru(gl);
10481080

10491081
trace_gfs2_glock_queue(gh, 0);
1082+
if (unlikely(!fast_path)) {
1083+
gl->gl_lockref.count++;
1084+
if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
1085+
!test_bit(GLF_DEMOTE, &gl->gl_flags) &&
1086+
gl->gl_name.ln_type == LM_TYPE_INODE)
1087+
delay = gl->gl_hold_time;
1088+
__gfs2_glock_queue_work(gl, delay);
1089+
}
10501090
spin_unlock(&gl->gl_lockref.lock);
1051-
if (likely(fast_path))
1052-
return;
1053-
1054-
gfs2_glock_hold(gl);
1055-
if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
1056-
!test_bit(GLF_DEMOTE, &gl->gl_flags) &&
1057-
gl->gl_name.ln_type == LM_TYPE_INODE)
1058-
delay = gl->gl_hold_time;
1059-
if (queue_delayed_work(glock_workqueue, &gl->gl_work, delay) == 0)
1060-
gfs2_glock_put(gl);
10611091
}
10621092

10631093
void gfs2_glock_dq_wait(struct gfs2_holder *gh)
@@ -1233,9 +1263,8 @@ void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
12331263

12341264
spin_lock(&gl->gl_lockref.lock);
12351265
handle_callback(gl, state, delay, true);
1266+
__gfs2_glock_queue_work(gl, delay);
12361267
spin_unlock(&gl->gl_lockref.lock);
1237-
if (queue_delayed_work(glock_workqueue, &gl->gl_work, delay) == 0)
1238-
gfs2_glock_put(gl);
12391268
}
12401269

12411270
/**
@@ -1294,10 +1323,8 @@ void gfs2_glock_complete(struct gfs2_glock *gl, int ret)
12941323

12951324
gl->gl_lockref.count++;
12961325
set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1326+
__gfs2_glock_queue_work(gl, 0);
12971327
spin_unlock(&gl->gl_lockref.lock);
1298-
1299-
if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
1300-
gfs2_glock_put(gl);
13011328
}
13021329

13031330
static int glock_cmp(void *priv, struct list_head *a, struct list_head *b)
@@ -1355,8 +1382,7 @@ __acquires(&lru_lock)
13551382
if (demote_ok(gl))
13561383
handle_callback(gl, LM_ST_UNLOCKED, 0, false);
13571384
WARN_ON(!test_and_clear_bit(GLF_LOCK, &gl->gl_flags));
1358-
if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
1359-
gl->gl_lockref.count--;
1385+
__gfs2_glock_queue_work(gl, 0);
13601386
spin_unlock(&gl->gl_lockref.lock);
13611387
cond_resched_lock(&lru_lock);
13621388
}
@@ -1462,13 +1488,12 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
14621488

14631489
static void thaw_glock(struct gfs2_glock *gl)
14641490
{
1465-
if (!test_and_clear_bit(GLF_FROZEN, &gl->gl_flags))
1466-
goto out;
1467-
set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1468-
if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0) {
1469-
out:
1491+
if (!test_and_clear_bit(GLF_FROZEN, &gl->gl_flags)) {
14701492
gfs2_glock_put(gl);
1493+
return;
14711494
}
1495+
set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1496+
gfs2_glock_queue_work(gl, 0);
14721497
}
14731498

14741499
/**
@@ -1484,9 +1509,8 @@ static void clear_glock(struct gfs2_glock *gl)
14841509
spin_lock(&gl->gl_lockref.lock);
14851510
if (gl->gl_state != LM_ST_UNLOCKED)
14861511
handle_callback(gl, LM_ST_UNLOCKED, 0, false);
1512+
__gfs2_glock_queue_work(gl, 0);
14871513
spin_unlock(&gl->gl_lockref.lock);
1488-
if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
1489-
gfs2_glock_put(gl);
14901514
}
14911515

14921516
/**

‎fs/gfs2/glock.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,11 @@ static inline bool gfs2_holder_initialized(struct gfs2_holder *gh)
257257
return gh->gh_gl;
258258
}
259259

260+
static inline void glock_set_object(struct gfs2_glock *gl, void *object)
261+
{
262+
spin_lock(&gl->gl_lockref.lock);
263+
gl->gl_object = object;
264+
spin_unlock(&gl->gl_lockref.lock);
265+
}
266+
260267
#endif /* __GLOCK_DOT_H__ */

0 commit comments

Comments
 (0)