Skip to content

Commit 0ec49e7

Browse files
author
Andreas Gruenbacher
committed
gfs2: Introduce glock_{type,number,sbd} helpers
Introduce glock_type(), glock_number(), and glock_sbd() helpers for accessing a glock's type, number, and super block pointer more easily. Created with Coccinelle using the following semantic patch: @@ struct gfs2_glock *gl; @@ - gl->gl_name.ln_type + glock_type(gl) @@ struct gfs2_glock *gl; @@ - gl->gl_name.ln_number + glock_number(gl) @@ struct gfs2_glock *gl; @@ - gl->gl_name.ln_sbd + glock_sbd(gl) glock_sbd() is a macro because it is used with const as well as non-const struct gfs2_glock * arguments. Instances in macro definitions, particularly in tracepoint definitions, replaced by hand. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
1 parent d3b39fc commit 0ec49e7

12 files changed

Lines changed: 124 additions & 112 deletions

File tree

fs/gfs2/glock.c

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ static void __gfs2_glock_free(struct gfs2_glock *gl)
147147
}
148148

149149
void gfs2_glock_free(struct gfs2_glock *gl) {
150-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
150+
struct gfs2_sbd *sdp = glock_sbd(gl);
151151

152152
__gfs2_glock_free(gl);
153153
if (atomic_dec_and_test(&sdp->sd_glock_disposal))
154154
wake_up(&sdp->sd_kill_wait);
155155
}
156156

157157
void gfs2_glock_free_later(struct gfs2_glock *gl) {
158-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
158+
struct gfs2_sbd *sdp = glock_sbd(gl);
159159

160160
spin_lock(&lru_lock);
161161
list_add(&gl->gl_lru, &sdp->sd_dead_glocks);
@@ -219,7 +219,7 @@ static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl)
219219
* work queue.
220220
*/
221221
static void gfs2_glock_queue_work(struct gfs2_glock *gl, unsigned long delay) {
222-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
222+
struct gfs2_sbd *sdp = glock_sbd(gl);
223223

224224
if (!queue_delayed_work(sdp->sd_glock_wq, &gl->gl_work, delay)) {
225225
/*
@@ -235,7 +235,7 @@ static void gfs2_glock_queue_work(struct gfs2_glock *gl, unsigned long delay) {
235235

236236
static void __gfs2_glock_put(struct gfs2_glock *gl)
237237
{
238-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
238+
struct gfs2_sbd *sdp = glock_sbd(gl);
239239
struct address_space *mapping = gfs2_glock2aspace(gl);
240240

241241
lockref_mark_dead(&gl->gl_lockref);
@@ -357,7 +357,7 @@ static void gfs2_holder_wake(struct gfs2_holder *gh)
357357
smp_mb__after_atomic();
358358
wake_up_bit(&gh->gh_iflags, HIF_WAIT);
359359
if (gh->gh_flags & GL_ASYNC) {
360-
struct gfs2_sbd *sdp = gh->gh_gl->gl_name.ln_sbd;
360+
struct gfs2_sbd *sdp = glock_sbd(gh->gh_gl);
361361

362362
wake_up(&sdp->sd_async_glock_wait);
363363
}
@@ -459,7 +459,7 @@ int gfs2_instantiate(struct gfs2_holder *gh)
459459

460460
static void do_promote(struct gfs2_glock *gl)
461461
{
462-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
462+
struct gfs2_sbd *sdp = glock_sbd(gl);
463463
struct gfs2_holder *gh, *current_gh;
464464

465465
if (gfs2_withdrawn(sdp)) {
@@ -539,7 +539,7 @@ static void state_change(struct gfs2_glock *gl, unsigned int new_state)
539539

540540
static void gfs2_set_demote(int nr, struct gfs2_glock *gl)
541541
{
542-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
542+
struct gfs2_sbd *sdp = glock_sbd(gl);
543543

544544
set_bit(nr, &gl->gl_flags);
545545
smp_mb();
@@ -611,9 +611,9 @@ static void finish_xmote(struct gfs2_glock *gl, unsigned int ret)
611611
do_xmote(gl, gh, LM_ST_UNLOCKED, false);
612612
break;
613613
default: /* Everything else */
614-
fs_err(gl->gl_name.ln_sbd,
614+
fs_err(glock_sbd(gl),
615615
"glock %u:%llu requested=%u ret=%u\n",
616-
gl->gl_name.ln_type, gl->gl_name.ln_number,
616+
glock_type(gl), glock_number(gl),
617617
gl->gl_req, ret);
618618
GLOCK_BUG_ON(gl, 1);
619619
}
@@ -659,7 +659,7 @@ __releases(&gl->gl_lockref.lock)
659659
__acquires(&gl->gl_lockref.lock)
660660
{
661661
const struct gfs2_glock_operations *glops = gl->gl_ops;
662-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
662+
struct gfs2_sbd *sdp = glock_sbd(gl);
663663
struct lm_lockstruct *ls = &sdp->sd_lockstruct;
664664
int ret;
665665

@@ -819,7 +819,7 @@ void glock_set_object(struct gfs2_glock *gl, void *object)
819819
prev_object = gl->gl_object;
820820
gl->gl_object = object;
821821
spin_unlock(&gl->gl_lockref.lock);
822-
if (gfs2_assert_warn(gl->gl_name.ln_sbd, prev_object == NULL))
822+
if (gfs2_assert_warn(glock_sbd(gl), prev_object == NULL))
823823
gfs2_dump_glock(NULL, gl, true);
824824
}
825825

@@ -836,7 +836,7 @@ void glock_clear_object(struct gfs2_glock *gl, void *object)
836836
prev_object = gl->gl_object;
837837
gl->gl_object = NULL;
838838
spin_unlock(&gl->gl_lockref.lock);
839-
if (gfs2_assert_warn(gl->gl_name.ln_sbd, prev_object == object))
839+
if (gfs2_assert_warn(glock_sbd(gl), prev_object == object))
840840
gfs2_dump_glock(NULL, gl, true);
841841
}
842842

@@ -926,7 +926,7 @@ static void gfs2_try_to_evict(struct gfs2_glock *gl)
926926

927927
bool gfs2_queue_try_to_evict(struct gfs2_glock *gl)
928928
{
929-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
929+
struct gfs2_sbd *sdp = glock_sbd(gl);
930930

931931
if (test_and_set_bit(GLF_TRY_TO_EVICT, &gl->gl_flags))
932932
return false;
@@ -935,7 +935,7 @@ bool gfs2_queue_try_to_evict(struct gfs2_glock *gl)
935935

936936
bool gfs2_queue_verify_delete(struct gfs2_glock *gl, bool later)
937937
{
938-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
938+
struct gfs2_sbd *sdp = glock_sbd(gl);
939939
unsigned long delay;
940940

941941
if (test_and_set_bit(GLF_VERIFY_DELETE, &gl->gl_flags))
@@ -948,7 +948,7 @@ static void delete_work_func(struct work_struct *work)
948948
{
949949
struct delayed_work *dwork = to_delayed_work(work);
950950
struct gfs2_glock *gl = container_of(dwork, struct gfs2_glock, gl_delete);
951-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
951+
struct gfs2_sbd *sdp = glock_sbd(gl);
952952
bool verify_delete = test_and_clear_bit(GLF_VERIFY_DELETE, &gl->gl_flags);
953953

954954
/*
@@ -961,7 +961,7 @@ static void delete_work_func(struct work_struct *work)
961961
gfs2_try_to_evict(gl);
962962

963963
if (verify_delete) {
964-
u64 no_addr = gl->gl_name.ln_number;
964+
u64 no_addr = glock_number(gl);
965965
struct inode *inode;
966966

967967
inode = gfs2_lookup_by_inum(sdp, no_addr, gl->gl_no_formal_ino,
@@ -995,7 +995,7 @@ static void glock_work_func(struct work_struct *work)
995995
if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
996996
gl->gl_state != LM_ST_UNLOCKED &&
997997
gl->gl_demote_state != LM_ST_EXCLUSIVE) {
998-
if (gl->gl_name.ln_type == LM_TYPE_INODE) {
998+
if (glock_type(gl) == LM_TYPE_INODE) {
999999
unsigned long holdtime, now = jiffies;
10001000

10011001
holdtime = gl->gl_tchange + gl->gl_hold_time;
@@ -1137,7 +1137,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
11371137
gl->gl_object = NULL;
11381138
gl->gl_hold_time = GL_GLOCK_DFT_HOLD;
11391139
INIT_DELAYED_WORK(&gl->gl_work, glock_work_func);
1140-
if (gl->gl_name.ln_type == LM_TYPE_IOPEN)
1140+
if (glock_type(gl) == LM_TYPE_IOPEN)
11411141
INIT_DELAYED_WORK(&gl->gl_delete, delete_work_func);
11421142

11431143
mapping = gfs2_glock2aspace(gl);
@@ -1295,7 +1295,7 @@ static int glocks_pending(unsigned int num_gh, struct gfs2_holder *ghs)
12951295
int gfs2_glock_async_wait(unsigned int num_gh, struct gfs2_holder *ghs,
12961296
unsigned int retries)
12971297
{
1298-
struct gfs2_sbd *sdp = ghs[0].gh_gl->gl_name.ln_sbd;
1298+
struct gfs2_sbd *sdp = glock_sbd(ghs[0].gh_gl);
12991299
unsigned long start_time = jiffies;
13001300
int i, ret = 0;
13011301
long timeout;
@@ -1437,7 +1437,7 @@ static inline bool pid_is_meaningful(const struct gfs2_holder *gh)
14371437
static inline void add_to_queue(struct gfs2_holder *gh)
14381438
{
14391439
struct gfs2_glock *gl = gh->gh_gl;
1440-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
1440+
struct gfs2_sbd *sdp = glock_sbd(gl);
14411441
struct gfs2_holder *gh2;
14421442

14431443
GLOCK_BUG_ON(gl, gh->gh_owner_pid == NULL);
@@ -1470,11 +1470,11 @@ static inline void add_to_queue(struct gfs2_holder *gh)
14701470
fs_err(sdp, "original: %pSR\n", (void *)gh2->gh_ip);
14711471
fs_err(sdp, "pid: %d\n", pid_nr(gh2->gh_owner_pid));
14721472
fs_err(sdp, "lock type: %d req lock state : %d\n",
1473-
gh2->gh_gl->gl_name.ln_type, gh2->gh_state);
1473+
glock_type(gh2->gh_gl), gh2->gh_state);
14741474
fs_err(sdp, "new: %pSR\n", (void *)gh->gh_ip);
14751475
fs_err(sdp, "pid: %d\n", pid_nr(gh->gh_owner_pid));
14761476
fs_err(sdp, "lock type: %d req lock state : %d\n",
1477-
gh->gh_gl->gl_name.ln_type, gh->gh_state);
1477+
glock_type(gh->gh_gl), gh->gh_state);
14781478
gfs2_dump_glock(NULL, gl, true);
14791479
BUG();
14801480
}
@@ -1491,7 +1491,7 @@ static inline void add_to_queue(struct gfs2_holder *gh)
14911491
int gfs2_glock_nq(struct gfs2_holder *gh)
14921492
{
14931493
struct gfs2_glock *gl = gh->gh_gl;
1494-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
1494+
struct gfs2_sbd *sdp = glock_sbd(gl);
14951495
int error;
14961496

14971497
if (gfs2_withdrawn(sdp))
@@ -1580,7 +1580,7 @@ static void __gfs2_glock_dq(struct gfs2_holder *gh)
15801580
gl->gl_lockref.count++;
15811581
if (test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
15821582
!test_bit(GLF_DEMOTE, &gl->gl_flags) &&
1583-
gl->gl_name.ln_type == LM_TYPE_INODE)
1583+
glock_type(gl) == LM_TYPE_INODE)
15841584
delay = gl->gl_hold_time;
15851585
gfs2_glock_queue_work(gl, delay);
15861586
}
@@ -1624,7 +1624,7 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
16241624

16251625
set_bit(GLF_CANCELING, &gl->gl_flags);
16261626
spin_unlock(&gl->gl_lockref.lock);
1627-
gl->gl_name.ln_sbd->sd_lockstruct.ls_ops->lm_cancel(gl);
1627+
glock_sbd(gl)->sd_lockstruct.ls_ops->lm_cancel(gl);
16281628
wait_on_bit(&gh->gh_iflags, HIF_WAIT, TASK_UNINTERRUPTIBLE);
16291629
spin_lock(&gl->gl_lockref.lock);
16301630
clear_bit(GLF_CANCELING, &gl->gl_flags);
@@ -1798,7 +1798,7 @@ void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
17981798
gfs2_glock_hold(gl);
17991799
spin_lock(&gl->gl_lockref.lock);
18001800
if (!list_empty(&gl->gl_holders) &&
1801-
gl->gl_name.ln_type == LM_TYPE_INODE) {
1801+
glock_type(gl) == LM_TYPE_INODE) {
18021802
unsigned long now = jiffies;
18031803
unsigned long holdtime;
18041804

@@ -1855,7 +1855,7 @@ static int gfs2_should_freeze(const struct gfs2_glock *gl)
18551855

18561856
void gfs2_glock_complete(struct gfs2_glock *gl, int ret)
18571857
{
1858-
struct lm_lockstruct *ls = &gl->gl_name.ln_sbd->sd_lockstruct;
1858+
struct lm_lockstruct *ls = &glock_sbd(gl)->sd_lockstruct;
18591859

18601860
spin_lock(&gl->gl_lockref.lock);
18611861
clear_bit(GLF_MAY_CANCEL, &gl->gl_flags);
@@ -1883,17 +1883,17 @@ static int glock_cmp(void *priv, const struct list_head *a,
18831883
gla = list_entry(a, struct gfs2_glock, gl_lru);
18841884
glb = list_entry(b, struct gfs2_glock, gl_lru);
18851885

1886-
if (gla->gl_name.ln_number > glb->gl_name.ln_number)
1886+
if (glock_number(gla) > glock_number(glb))
18871887
return 1;
1888-
if (gla->gl_name.ln_number < glb->gl_name.ln_number)
1888+
if (glock_number(gla) < glock_number(glb))
18891889
return -1;
18901890

18911891
return 0;
18921892
}
18931893

18941894
static bool can_free_glock(struct gfs2_glock *gl)
18951895
{
1896-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
1896+
struct gfs2_sbd *sdp = glock_sbd(gl);
18971897

18981898
return !test_bit(GLF_LOCK, &gl->gl_flags) &&
18991899
!gl->gl_lockref.count &&
@@ -2015,7 +2015,7 @@ static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
20152015
rhashtable_walk_start(&iter);
20162016

20172017
while ((gl = rhashtable_walk_next(&iter)) && !IS_ERR(gl)) {
2018-
if (gl->gl_name.ln_sbd == sdp)
2018+
if (glock_sbd(gl) == sdp)
20192019
examiner(gl);
20202020
}
20212021

@@ -2035,8 +2035,8 @@ void gfs2_cancel_delete_work(struct gfs2_glock *gl)
20352035

20362036
static void flush_delete_work(struct gfs2_glock *gl)
20372037
{
2038-
if (gl->gl_name.ln_type == LM_TYPE_IOPEN) {
2039-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
2038+
if (glock_type(gl) == LM_TYPE_IOPEN) {
2039+
struct gfs2_sbd *sdp = glock_sbd(gl);
20402040

20412041
if (cancel_delayed_work(&gl->gl_delete)) {
20422042
queue_delayed_work(sdp->sd_delete_wq,
@@ -2321,7 +2321,7 @@ void gfs2_dump_glock(struct seq_file *seq, struct gfs2_glock *gl, bool fsid)
23212321
unsigned long long dtime;
23222322
const struct gfs2_holder *gh;
23232323
char gflags_buf[32];
2324-
struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
2324+
struct gfs2_sbd *sdp = glock_sbd(gl);
23252325
char fs_id_buf[sizeof(sdp->sd_fsname) + 7];
23262326
unsigned long nrpages = 0;
23272327

@@ -2340,8 +2340,8 @@ void gfs2_dump_glock(struct seq_file *seq, struct gfs2_glock *gl, bool fsid)
23402340
gfs2_print_dbg(seq, "%sG: s:%s n:%u/%llx f:%s t:%s d:%s/%llu a:%d "
23412341
"v:%d r:%d m:%ld p:%lu\n",
23422342
fs_id_buf, state2str(gl->gl_state),
2343-
gl->gl_name.ln_type,
2344-
(unsigned long long)gl->gl_name.ln_number,
2343+
glock_type(gl),
2344+
(unsigned long long) glock_number(gl),
23452345
gflags2str(gflags_buf, gl),
23462346
state2str(gl->gl_target),
23472347
state2str(gl->gl_demote_state), dtime,
@@ -2361,8 +2361,8 @@ static int gfs2_glstats_seq_show(struct seq_file *seq, void *iter_ptr)
23612361
struct gfs2_glock *gl = iter_ptr;
23622362

23632363
seq_printf(seq, "G: n:%u/%llx rtt:%llu/%llu rttb:%llu/%llu irt:%llu/%llu dcnt: %llu qcnt: %llu\n",
2364-
gl->gl_name.ln_type,
2365-
(unsigned long long)gl->gl_name.ln_number,
2364+
glock_type(gl),
2365+
(unsigned long long) glock_number(gl),
23662366
(unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTT],
23672367
(unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTTVAR],
23682368
(unsigned long long)gl->gl_stats.stats[GFS2_LKS_SRTTB],
@@ -2478,7 +2478,7 @@ static void gfs2_glock_iter_next(struct gfs2_glock_iter *gi, loff_t n)
24782478
gl = NULL;
24792479
break;
24802480
}
2481-
if (gl->gl_name.ln_sbd != gi->sdp)
2481+
if (glock_sbd(gl) != gi->sdp)
24822482
continue;
24832483
if (n <= 1) {
24842484
if (!lockref_get_not_dead(&gl->gl_lockref))
@@ -2774,8 +2774,8 @@ static int gfs2_glockfd_seq_show(struct seq_file *seq, void *iter_ptr)
27742774
gl = GFS2_I(inode)->i_iopen_gh.gh_gl;
27752775
if (gl) {
27762776
seq_printf(seq, "%d %u %u/%llx\n",
2777-
i->tgid, i->fd, gl->gl_name.ln_type,
2778-
(unsigned long long)gl->gl_name.ln_number);
2777+
i->tgid, i->fd, glock_type(gl),
2778+
(unsigned long long) glock_number(gl));
27792779
}
27802780
gfs2_glockfd_seq_show_flock(seq, i);
27812781
inode_unlock_shared(inode);

fs/gfs2/glock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ void gfs2_dump_glock(struct seq_file *seq, struct gfs2_glock *gl,
222222
BUG(); } } while(0)
223223
#define gfs2_glock_assert_warn(gl, x) do { if (unlikely(!(x))) { \
224224
gfs2_dump_glock(NULL, gl, true); \
225-
gfs2_assert_warn((gl)->gl_name.ln_sbd, (x)); } } \
225+
gfs2_assert_warn(glock_sbd(gl), (x)); } } \
226226
while (0)
227227
#define gfs2_glock_assert_withdraw(gl, x) do { if (unlikely(!(x))) { \
228228
gfs2_dump_glock(NULL, gl, true); \
229-
gfs2_assert_withdraw((gl)->gl_name.ln_sbd, (x)); } } \
229+
gfs2_assert_withdraw(glock_sbd(gl), (x)); } } \
230230
while (0)
231231

232232
__printf(2, 3)

0 commit comments

Comments
 (0)