Skip to content

Commit 15562c4

Browse files
committed
GFS2: Move glock superblock pointer to field gl_name
What uniquely identifies a glock in the glock hash table is not gl_name, but gl_name and its superblock pointer. This patch makes the gl_name field correspond to a unique glock identifier. That will allow us to simplify hashing with a future patch, since the hash algorithm can then take the gl_name and hash its components in one operation. Signed-off-by: Bob Peterson <rpeterso@redhat.com> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Acked-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent 81648d0 commit 15562c4

File tree

11 files changed

+75
-74
lines changed

11 files changed

+75
-74
lines changed

fs/gfs2/glock.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static void gfs2_glock_dealloc(struct rcu_head *rcu)
119119

120120
void gfs2_glock_free(struct gfs2_glock *gl)
121121
{
122-
struct gfs2_sbd *sdp = gl->gl_sbd;
122+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
123123

124124
call_rcu(&gl->gl_rcu, gfs2_glock_dealloc);
125125
if (atomic_dec_and_test(&sdp->sd_glock_disposal))
@@ -192,7 +192,7 @@ static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl)
192192

193193
void gfs2_glock_put(struct gfs2_glock *gl)
194194
{
195-
struct gfs2_sbd *sdp = gl->gl_sbd;
195+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
196196
struct address_space *mapping = gfs2_glock2aspace(gl);
197197

198198
if (lockref_put_or_lock(&gl->gl_lockref))
@@ -220,7 +220,6 @@ void gfs2_glock_put(struct gfs2_glock *gl)
220220
*/
221221

222222
static struct gfs2_glock *search_bucket(unsigned int hash,
223-
const struct gfs2_sbd *sdp,
224223
const struct lm_lockname *name)
225224
{
226225
struct gfs2_glock *gl;
@@ -229,8 +228,6 @@ static struct gfs2_glock *search_bucket(unsigned int hash,
229228
hlist_bl_for_each_entry_rcu(gl, h, &gl_hash_table[hash], gl_list) {
230229
if (!lm_name_equal(&gl->gl_name, name))
231230
continue;
232-
if (gl->gl_sbd != sdp)
233-
continue;
234231
if (lockref_get_not_dead(&gl->gl_lockref))
235232
return gl;
236233
}
@@ -506,7 +503,7 @@ __releases(&gl->gl_spin)
506503
__acquires(&gl->gl_spin)
507504
{
508505
const struct gfs2_glock_operations *glops = gl->gl_ops;
509-
struct gfs2_sbd *sdp = gl->gl_sbd;
506+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
510507
unsigned int lck_flags = gh ? gh->gh_flags : 0;
511508
int ret;
512509

@@ -628,7 +625,7 @@ __acquires(&gl->gl_spin)
628625
static void delete_work_func(struct work_struct *work)
629626
{
630627
struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_delete);
631-
struct gfs2_sbd *sdp = gl->gl_sbd;
628+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
632629
struct gfs2_inode *ip;
633630
struct inode *inode;
634631
u64 no_addr = gl->gl_name.ln_number;
@@ -704,14 +701,16 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
704701
struct gfs2_glock **glp)
705702
{
706703
struct super_block *s = sdp->sd_vfs;
707-
struct lm_lockname name = { .ln_number = number, .ln_type = glops->go_type };
704+
struct lm_lockname name = { .ln_number = number,
705+
.ln_type = glops->go_type,
706+
.ln_sbd = sdp };
708707
struct gfs2_glock *gl, *tmp;
709708
unsigned int hash = gl_hash(sdp, &name);
710709
struct address_space *mapping;
711710
struct kmem_cache *cachep;
712711

713712
rcu_read_lock();
714-
gl = search_bucket(hash, sdp, &name);
713+
gl = search_bucket(hash, &name);
715714
rcu_read_unlock();
716715

717716
*glp = gl;
@@ -739,7 +738,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
739738
}
740739

741740
atomic_inc(&sdp->sd_glock_disposal);
742-
gl->gl_sbd = sdp;
743741
gl->gl_flags = 0;
744742
gl->gl_name = name;
745743
gl->gl_lockref.count = 1;
@@ -772,7 +770,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
772770
}
773771

774772
spin_lock_bucket(hash);
775-
tmp = search_bucket(hash, sdp, &name);
773+
tmp = search_bucket(hash, &name);
776774
if (tmp) {
777775
spin_unlock_bucket(hash);
778776
kfree(gl->gl_lksb.sb_lvbptr);
@@ -928,7 +926,7 @@ __releases(&gl->gl_spin)
928926
__acquires(&gl->gl_spin)
929927
{
930928
struct gfs2_glock *gl = gh->gh_gl;
931-
struct gfs2_sbd *sdp = gl->gl_sbd;
929+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
932930
struct list_head *insert_pt = NULL;
933931
struct gfs2_holder *gh2;
934932
int try_futile = 0;
@@ -1006,7 +1004,7 @@ __acquires(&gl->gl_spin)
10061004
int gfs2_glock_nq(struct gfs2_holder *gh)
10071005
{
10081006
struct gfs2_glock *gl = gh->gh_gl;
1009-
struct gfs2_sbd *sdp = gl->gl_sbd;
1007+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
10101008
int error = 0;
10111009

10121010
if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
@@ -1313,7 +1311,7 @@ static int gfs2_should_freeze(const struct gfs2_glock *gl)
13131311

13141312
void gfs2_glock_complete(struct gfs2_glock *gl, int ret)
13151313
{
1316-
struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct;
1314+
struct lm_lockstruct *ls = &gl->gl_name.ln_sbd->sd_lockstruct;
13171315

13181316
spin_lock(&gl->gl_spin);
13191317
gl->gl_reply = ret;
@@ -1471,7 +1469,7 @@ static void examine_bucket(glock_examiner examiner, const struct gfs2_sbd *sdp,
14711469

14721470
rcu_read_lock();
14731471
hlist_bl_for_each_entry_rcu(gl, pos, head, gl_list) {
1474-
if ((gl->gl_sbd == sdp) && lockref_get_not_dead(&gl->gl_lockref))
1472+
if ((gl->gl_name.ln_sbd == sdp) && lockref_get_not_dead(&gl->gl_lockref))
14751473
examiner(gl);
14761474
}
14771475
rcu_read_unlock();
@@ -1569,7 +1567,7 @@ void gfs2_glock_finish_truncate(struct gfs2_inode *ip)
15691567
int ret;
15701568

15711569
ret = gfs2_truncatei_resume(ip);
1572-
gfs2_assert_withdraw(gl->gl_sbd, ret == 0);
1570+
gfs2_assert_withdraw(gl->gl_name.ln_sbd, ret == 0);
15731571

15741572
spin_lock(&gl->gl_spin);
15751573
clear_bit(GLF_LOCK, &gl->gl_flags);
@@ -1872,7 +1870,7 @@ static int gfs2_glock_iter_next(struct gfs2_glock_iter *gi)
18721870
gi->nhash = 0;
18731871
}
18741872
/* Skip entries for other sb and dead entries */
1875-
} while (gi->sdp != gi->gl->gl_sbd ||
1873+
} while (gi->sdp != gi->gl->gl_name.ln_sbd ||
18761874
__lockref_is_dead(&gi->gl->gl_lockref));
18771875

18781876
return 0;

fs/gfs2/glops.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ struct workqueue_struct *gfs2_freeze_wq;
3232

3333
static void gfs2_ail_error(struct gfs2_glock *gl, const struct buffer_head *bh)
3434
{
35-
fs_err(gl->gl_sbd, "AIL buffer %p: blocknr %llu state 0x%08lx mapping %p page state 0x%lx\n",
35+
fs_err(gl->gl_name.ln_sbd,
36+
"AIL buffer %p: blocknr %llu state 0x%08lx mapping %p page "
37+
"state 0x%lx\n",
3638
bh, (unsigned long long)bh->b_blocknr, bh->b_state,
3739
bh->b_page->mapping, bh->b_page->flags);
38-
fs_err(gl->gl_sbd, "AIL glock %u:%llu mapping %p\n",
40+
fs_err(gl->gl_name.ln_sbd, "AIL glock %u:%llu mapping %p\n",
3941
gl->gl_name.ln_type, gl->gl_name.ln_number,
4042
gfs2_glock2aspace(gl));
41-
gfs2_lm_withdraw(gl->gl_sbd, "AIL error\n");
43+
gfs2_lm_withdraw(gl->gl_name.ln_sbd, "AIL error\n");
4244
}
4345

4446
/**
@@ -52,7 +54,7 @@ static void gfs2_ail_error(struct gfs2_glock *gl, const struct buffer_head *bh)
5254
static void __gfs2_ail_flush(struct gfs2_glock *gl, bool fsync,
5355
unsigned int nr_revokes)
5456
{
55-
struct gfs2_sbd *sdp = gl->gl_sbd;
57+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
5658
struct list_head *head = &gl->gl_ail_list;
5759
struct gfs2_bufdata *bd, *tmp;
5860
struct buffer_head *bh;
@@ -80,7 +82,7 @@ static void __gfs2_ail_flush(struct gfs2_glock *gl, bool fsync,
8082

8183
static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
8284
{
83-
struct gfs2_sbd *sdp = gl->gl_sbd;
85+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
8486
struct gfs2_trans tr;
8587

8688
memset(&tr, 0, sizeof(tr));
@@ -109,7 +111,7 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
109111

110112
void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
111113
{
112-
struct gfs2_sbd *sdp = gl->gl_sbd;
114+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
113115
unsigned int revokes = atomic_read(&gl->gl_ail_count);
114116
unsigned int max_revokes = (sdp->sd_sb.sb_bsize - sizeof(struct gfs2_log_descriptor)) / sizeof(u64);
115117
int ret;
@@ -139,7 +141,7 @@ void gfs2_ail_flush(struct gfs2_glock *gl, bool fsync)
139141

140142
static void rgrp_go_sync(struct gfs2_glock *gl)
141143
{
142-
struct gfs2_sbd *sdp = gl->gl_sbd;
144+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
143145
struct address_space *mapping = &sdp->sd_aspace;
144146
struct gfs2_rgrpd *rgd;
145147
int error;
@@ -179,7 +181,7 @@ static void rgrp_go_sync(struct gfs2_glock *gl)
179181

180182
static void rgrp_go_inval(struct gfs2_glock *gl, int flags)
181183
{
182-
struct gfs2_sbd *sdp = gl->gl_sbd;
184+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
183185
struct address_space *mapping = &sdp->sd_aspace;
184186
struct gfs2_rgrpd *rgd = gl->gl_object;
185187

@@ -218,7 +220,7 @@ static void inode_go_sync(struct gfs2_glock *gl)
218220

219221
GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_EXCLUSIVE);
220222

221-
gfs2_log_flush(gl->gl_sbd, gl, NORMAL_FLUSH);
223+
gfs2_log_flush(gl->gl_name.ln_sbd, gl, NORMAL_FLUSH);
222224
filemap_fdatawrite(metamapping);
223225
if (ip) {
224226
struct address_space *mapping = ip->i_inode.i_mapping;
@@ -252,7 +254,7 @@ static void inode_go_inval(struct gfs2_glock *gl, int flags)
252254
{
253255
struct gfs2_inode *ip = gl->gl_object;
254256

255-
gfs2_assert_withdraw(gl->gl_sbd, !atomic_read(&gl->gl_ail_count));
257+
gfs2_assert_withdraw(gl->gl_name.ln_sbd, !atomic_read(&gl->gl_ail_count));
256258

257259
if (flags & DIO_METADATA) {
258260
struct address_space *mapping = gfs2_glock2aspace(gl);
@@ -264,9 +266,9 @@ static void inode_go_inval(struct gfs2_glock *gl, int flags)
264266
}
265267
}
266268

267-
if (ip == GFS2_I(gl->gl_sbd->sd_rindex)) {
268-
gfs2_log_flush(gl->gl_sbd, NULL, NORMAL_FLUSH);
269-
gl->gl_sbd->sd_rindex_uptodate = 0;
269+
if (ip == GFS2_I(gl->gl_name.ln_sbd->sd_rindex)) {
270+
gfs2_log_flush(gl->gl_name.ln_sbd, NULL, NORMAL_FLUSH);
271+
gl->gl_name.ln_sbd->sd_rindex_uptodate = 0;
270272
}
271273
if (ip && S_ISREG(ip->i_inode.i_mode))
272274
truncate_inode_pages(ip->i_inode.i_mapping, 0);
@@ -281,7 +283,7 @@ static void inode_go_inval(struct gfs2_glock *gl, int flags)
281283

282284
static int inode_go_demote_ok(const struct gfs2_glock *gl)
283285
{
284-
struct gfs2_sbd *sdp = gl->gl_sbd;
286+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
285287
struct gfs2_holder *gh;
286288

287289
if (sdp->sd_jindex == gl->gl_object || sdp->sd_rindex == gl->gl_object)
@@ -416,7 +418,7 @@ int gfs2_inode_refresh(struct gfs2_inode *ip)
416418
static int inode_go_lock(struct gfs2_holder *gh)
417419
{
418420
struct gfs2_glock *gl = gh->gh_gl;
419-
struct gfs2_sbd *sdp = gl->gl_sbd;
421+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
420422
struct gfs2_inode *ip = gl->gl_object;
421423
int error = 0;
422424

@@ -477,7 +479,7 @@ static void inode_go_dump(struct seq_file *seq, const struct gfs2_glock *gl)
477479
static void freeze_go_sync(struct gfs2_glock *gl)
478480
{
479481
int error = 0;
480-
struct gfs2_sbd *sdp = gl->gl_sbd;
482+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
481483

482484
if (gl->gl_state == LM_ST_SHARED &&
483485
test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
@@ -500,7 +502,7 @@ static void freeze_go_sync(struct gfs2_glock *gl)
500502

501503
static int freeze_go_xmote_bh(struct gfs2_glock *gl, struct gfs2_holder *gh)
502504
{
503-
struct gfs2_sbd *sdp = gl->gl_sbd;
505+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
504506
struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode);
505507
struct gfs2_glock *j_gl = ip->i_gl;
506508
struct gfs2_log_header_host head;
@@ -545,7 +547,7 @@ static int freeze_go_demote_ok(const struct gfs2_glock *gl)
545547
static void iopen_go_callback(struct gfs2_glock *gl, bool remote)
546548
{
547549
struct gfs2_inode *ip = (struct gfs2_inode *)gl->gl_object;
548-
struct gfs2_sbd *sdp = gl->gl_sbd;
550+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
549551

550552
if (!remote || (sdp->sd_vfs->s_flags & MS_RDONLY))
551553
return;

fs/gfs2/incore.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,15 @@ enum {
203203
};
204204

205205
struct lm_lockname {
206+
struct gfs2_sbd *ln_sbd;
206207
u64 ln_number;
207208
unsigned int ln_type;
208209
};
209210

210211
#define lm_name_equal(name1, name2) \
211-
(((name1)->ln_number == (name2)->ln_number) && \
212-
((name1)->ln_type == (name2)->ln_type))
212+
(((name1)->ln_number == (name2)->ln_number) && \
213+
((name1)->ln_type == (name2)->ln_type) && \
214+
((name1)->ln_sbd == (name2)->ln_sbd))
213215

214216

215217
struct gfs2_glock_operations {
@@ -327,7 +329,6 @@ enum {
327329

328330
struct gfs2_glock {
329331
struct hlist_bl_node gl_list;
330-
struct gfs2_sbd *gl_sbd;
331332
unsigned long gl_flags; /* GLF_... */
332333
struct lm_lockname gl_name;
333334

@@ -835,7 +836,7 @@ static inline void gfs2_glstats_inc(struct gfs2_glock *gl, int which)
835836

836837
static inline void gfs2_sbstats_inc(const struct gfs2_glock *gl, int which)
837838
{
838-
const struct gfs2_sbd *sdp = gl->gl_sbd;
839+
const struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
839840
preempt_disable();
840841
this_cpu_ptr(sdp->sd_lkstats)->lkstats[gl->gl_name.ln_type].stats[which]++;
841842
preempt_enable();

fs/gfs2/lock_dlm.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static inline void gfs2_update_reply_times(struct gfs2_glock *gl)
8080

8181
preempt_disable();
8282
rtt = ktime_to_ns(ktime_sub(ktime_get_real(), gl->gl_dstamp));
83-
lks = this_cpu_ptr(gl->gl_sbd->sd_lkstats);
83+
lks = this_cpu_ptr(gl->gl_name.ln_sbd->sd_lkstats);
8484
gfs2_update_stats(&gl->gl_stats, index, rtt); /* Local */
8585
gfs2_update_stats(&lks->lkstats[gltype], index, rtt); /* Global */
8686
preempt_enable();
@@ -108,7 +108,7 @@ static inline void gfs2_update_request_times(struct gfs2_glock *gl)
108108
dstamp = gl->gl_dstamp;
109109
gl->gl_dstamp = ktime_get_real();
110110
irt = ktime_to_ns(ktime_sub(gl->gl_dstamp, dstamp));
111-
lks = this_cpu_ptr(gl->gl_sbd->sd_lkstats);
111+
lks = this_cpu_ptr(gl->gl_name.ln_sbd->sd_lkstats);
112112
gfs2_update_stats(&gl->gl_stats, GFS2_LKS_SIRT, irt); /* Local */
113113
gfs2_update_stats(&lks->lkstats[gltype], GFS2_LKS_SIRT, irt); /* Global */
114114
preempt_enable();
@@ -253,7 +253,7 @@ static void gfs2_reverse_hex(char *c, u64 value)
253253
static int gdlm_lock(struct gfs2_glock *gl, unsigned int req_state,
254254
unsigned int flags)
255255
{
256-
struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct;
256+
struct lm_lockstruct *ls = &gl->gl_name.ln_sbd->sd_lockstruct;
257257
int req;
258258
u32 lkf;
259259
char strname[GDLM_STRNAME_BYTES] = "";
@@ -281,7 +281,7 @@ static int gdlm_lock(struct gfs2_glock *gl, unsigned int req_state,
281281

282282
static void gdlm_put_lock(struct gfs2_glock *gl)
283283
{
284-
struct gfs2_sbd *sdp = gl->gl_sbd;
284+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
285285
struct lm_lockstruct *ls = &sdp->sd_lockstruct;
286286
int lvb_needs_unlock = 0;
287287
int error;
@@ -319,7 +319,7 @@ static void gdlm_put_lock(struct gfs2_glock *gl)
319319

320320
static void gdlm_cancel(struct gfs2_glock *gl)
321321
{
322-
struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct;
322+
struct lm_lockstruct *ls = &gl->gl_name.ln_sbd->sd_lockstruct;
323323
dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, DLM_LKF_CANCEL, NULL, gl);
324324
}
325325

fs/gfs2/lops.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static bool buffer_is_rgrp(const struct gfs2_bufdata *bd)
7070
static void maybe_release_space(struct gfs2_bufdata *bd)
7171
{
7272
struct gfs2_glock *gl = bd->bd_gl;
73-
struct gfs2_sbd *sdp = gl->gl_sbd;
73+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
7474
struct gfs2_rgrpd *rgd = gl->gl_object;
7575
unsigned int index = bd->bd_bh->b_blocknr - gl->gl_name.ln_number;
7676
struct gfs2_bitmap *bi = rgd->rd_bits + index;
@@ -585,7 +585,7 @@ static int buf_lo_scan_elements(struct gfs2_jdesc *jd, unsigned int start,
585585
static void gfs2_meta_sync(struct gfs2_glock *gl)
586586
{
587587
struct address_space *mapping = gfs2_glock2aspace(gl);
588-
struct gfs2_sbd *sdp = gl->gl_sbd;
588+
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
589589
int error;
590590

591591
if (mapping == NULL)
@@ -595,7 +595,7 @@ static void gfs2_meta_sync(struct gfs2_glock *gl)
595595
error = filemap_fdatawait(mapping);
596596

597597
if (error)
598-
gfs2_io_error(gl->gl_sbd);
598+
gfs2_io_error(gl->gl_name.ln_sbd);
599599
}
600600

601601
static void buf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass)

0 commit comments

Comments
 (0)