Skip to content

Commit cbe6d25

Browse files
author
Andreas Gruenbacher
committed
gfs2: Add GL_NOPID flag for process-independent glock holders
Add a GL_NOPID flag to indicate that once a glock holder has been acquired, it won't be associated with the current process anymore. This is useful for iopen and flock glocks which are associated with open files, as well as journal glock holders and similar which are associated with the filesystem. Once GL_NOPID is used for all applicable glocks (see the next patches), processes will no longer be falsely reported as holding glocks which they are not actually holding in the glocks dump file. Unlike before, when a process is reported as having "(ended)", this will indicate an actual bug. Signed-off-by: Andreas Gruenbacher <[email protected]>
1 parent 56535dc commit cbe6d25

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

fs/gfs2/glock.c

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,15 @@ void gfs2_print_dbg(struct seq_file *seq, const char *fmt, ...)
14671467
va_end(args);
14681468
}
14691469

1470+
static inline bool pid_is_meaningful(const struct gfs2_holder *gh)
1471+
{
1472+
if (!(gh->gh_flags & GL_NOPID))
1473+
return true;
1474+
if (gh->gh_state == LM_ST_UNLOCKED)
1475+
return true;
1476+
return false;
1477+
}
1478+
14701479
/**
14711480
* add_to_queue - Add a holder to the wait queue (but look for recursion)
14721481
* @gh: the holder structure to add
@@ -1503,10 +1512,17 @@ __acquires(&gl->gl_lockref.lock)
15031512
}
15041513

15051514
list_for_each_entry(gh2, &gl->gl_holders, gh_list) {
1506-
if (unlikely(gh2->gh_owner_pid == gh->gh_owner_pid &&
1507-
(gh->gh_gl->gl_ops->go_type != LM_TYPE_FLOCK) &&
1508-
!test_bit(HIF_MAY_DEMOTE, &gh2->gh_iflags)))
1509-
goto trap_recursive;
1515+
if (likely(gh2->gh_owner_pid != gh->gh_owner_pid))
1516+
continue;
1517+
if (gh->gh_gl->gl_ops->go_type == LM_TYPE_FLOCK)
1518+
continue;
1519+
if (test_bit(HIF_MAY_DEMOTE, &gh2->gh_iflags))
1520+
continue;
1521+
if (!pid_is_meaningful(gh2))
1522+
continue;
1523+
goto trap_recursive;
1524+
}
1525+
list_for_each_entry(gh2, &gl->gl_holders, gh_list) {
15101526
if (try_futile &&
15111527
!(gh2->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) {
15121528
fail:
@@ -2321,19 +2337,24 @@ static const char *hflags2str(char *buf, u16 flags, unsigned long iflags)
23212337
static void dump_holder(struct seq_file *seq, const struct gfs2_holder *gh,
23222338
const char *fs_id_buf)
23232339
{
2324-
struct task_struct *gh_owner = NULL;
2340+
const char *comm = "(none)";
2341+
pid_t owner_pid = 0;
23252342
char flags_buf[32];
23262343

23272344
rcu_read_lock();
2328-
if (gh->gh_owner_pid)
2345+
if (pid_is_meaningful(gh)) {
2346+
struct task_struct *gh_owner;
2347+
2348+
comm = "(ended)";
2349+
owner_pid = pid_nr(gh->gh_owner_pid);
23292350
gh_owner = pid_task(gh->gh_owner_pid, PIDTYPE_PID);
2351+
if (gh_owner)
2352+
comm = gh_owner->comm;
2353+
}
23302354
gfs2_print_dbg(seq, "%s H: s:%s f:%s e:%d p:%ld [%s] %pS\n",
23312355
fs_id_buf, state2str(gh->gh_state),
23322356
hflags2str(flags_buf, gh->gh_flags, gh->gh_iflags),
2333-
gh->gh_error,
2334-
gh->gh_owner_pid ? (long)pid_nr(gh->gh_owner_pid) : -1,
2335-
gh_owner ? gh_owner->comm : "(ended)",
2336-
(void *)gh->gh_ip);
2357+
gh->gh_error, (long)owner_pid, comm, (void *)gh->gh_ip);
23372358
rcu_read_unlock();
23382359
}
23392360

fs/gfs2/glock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ enum {
9191
#define GL_ASYNC 0x0040
9292
#define GL_EXACT 0x0080
9393
#define GL_SKIP 0x0100
94+
#define GL_NOPID 0x0200
9495
#define GL_NOCACHE 0x0400
9596

9697
/*

0 commit comments

Comments
 (0)