Skip to content

Commit 56535dc

Browse files
author
Andreas Gruenbacher
committed
gfs2: Add flocks to glockfd debugfs file
Include flock glocks in the "glockfd" debugfs file. Those are similar to the iopen glocks; while an open file is holding an flock, it is holding the file's flock glock. We cannot take f_fl_mutex in gfs2_glockfd_seq_show_flock() or else dumping the "glockfd" file would block on flock operations. Instead, use the file->f_lock spin lock to protect the f_fl_gh.gh_gl glock pointer. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
1 parent 4480c27 commit 56535dc

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

fs/gfs2/file.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,22 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
14441444
return dlm_posix_lock(ls->ls_dlm, ip->i_no_addr, file, cmd, fl);
14451445
}
14461446

1447+
static void __flock_holder_uninit(struct file *file, struct gfs2_holder *fl_gh)
1448+
{
1449+
struct gfs2_glock *gl = fl_gh->gh_gl;
1450+
1451+
/*
1452+
* Make sure gfs2_glock_put() won't sleep under the file->f_lock
1453+
* spinlock.
1454+
*/
1455+
1456+
gfs2_glock_hold(gl);
1457+
spin_lock(&file->f_lock);
1458+
gfs2_holder_uninit(fl_gh);
1459+
spin_unlock(&file->f_lock);
1460+
gfs2_glock_put(gl);
1461+
}
1462+
14471463
static int do_flock(struct file *file, int cmd, struct file_lock *fl)
14481464
{
14491465
struct gfs2_file *fp = file->private_data;
@@ -1475,7 +1491,9 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl)
14751491
&gfs2_flock_glops, CREATE, &gl);
14761492
if (error)
14771493
goto out;
1494+
spin_lock(&file->f_lock);
14781495
gfs2_holder_init(gl, state, flags, fl_gh);
1496+
spin_unlock(&file->f_lock);
14791497
gfs2_glock_put(gl);
14801498
}
14811499
for (sleeptime = 1; sleeptime <= 4; sleeptime <<= 1) {
@@ -1486,7 +1504,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl)
14861504
msleep(sleeptime);
14871505
}
14881506
if (error) {
1489-
gfs2_holder_uninit(fl_gh);
1507+
__flock_holder_uninit(file, fl_gh);
14901508
if (error == GLR_TRYFAILED)
14911509
error = -EAGAIN;
14921510
} else {
@@ -1508,7 +1526,7 @@ static void do_unflock(struct file *file, struct file_lock *fl)
15081526
locks_lock_file_wait(file, fl);
15091527
if (gfs2_holder_initialized(fl_gh)) {
15101528
gfs2_glock_dq(fl_gh);
1511-
gfs2_holder_uninit(fl_gh);
1529+
__flock_holder_uninit(file, fl_gh);
15121530
}
15131531
mutex_unlock(&fp->f_fl_mutex);
15141532
}

fs/gfs2/glock.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,6 +2846,28 @@ static void gfs2_glockfd_seq_stop(struct seq_file *seq, void *iter_ptr)
28462846
put_task_struct(i->task);
28472847
}
28482848

2849+
static void gfs2_glockfd_seq_show_flock(struct seq_file *seq,
2850+
struct gfs2_glockfd_iter *i)
2851+
{
2852+
struct gfs2_file *fp = i->file->private_data;
2853+
struct gfs2_holder *fl_gh = &fp->f_fl_gh;
2854+
struct lm_lockname gl_name = { .ln_type = LM_TYPE_RESERVED };
2855+
2856+
if (!READ_ONCE(fl_gh->gh_gl))
2857+
return;
2858+
2859+
spin_lock(&i->file->f_lock);
2860+
if (gfs2_holder_initialized(fl_gh))
2861+
gl_name = fl_gh->gh_gl->gl_name;
2862+
spin_unlock(&i->file->f_lock);
2863+
2864+
if (gl_name.ln_type != LM_TYPE_RESERVED) {
2865+
seq_printf(seq, "%d %u %u/%llx\n",
2866+
i->tgid, i->fd, gl_name.ln_type,
2867+
(unsigned long long)gl_name.ln_number);
2868+
}
2869+
}
2870+
28492871
static int gfs2_glockfd_seq_show(struct seq_file *seq, void *iter_ptr)
28502872
{
28512873
struct gfs2_glockfd_iter *i = seq->private;
@@ -2859,6 +2881,7 @@ static int gfs2_glockfd_seq_show(struct seq_file *seq, void *iter_ptr)
28592881
i->tgid, i->fd, gl->gl_name.ln_type,
28602882
(unsigned long long)gl->gl_name.ln_number);
28612883
}
2884+
gfs2_glockfd_seq_show_flock(seq, i);
28622885
inode_unlock_shared(inode);
28632886
return 0;
28642887
}

0 commit comments

Comments
 (0)