lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210220063250.742164-1-luolongjun@huawei.com>
Date:   Sat, 20 Feb 2021 01:32:50 -0500
From:   Luo Longjun <luolongjun@...wei.com>
To:     <viro@...iv.linux.org.uk>, <jlayton@...nel.org>,
        <bfields@...ldses.org>
CC:     <linux-fsdevel@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        <sangyan@...wei.com>, <luchunhua@...wei.com>
Subject: [PATCH] fs/locks: print full locks information

Commit fd7732e033e3 ("fs/locks: create a tree of dependent requests.")
has put blocked locks into a tree.

So, with a for loop, we can't check all locks information.

To solve this problem, we should traverse the tree by DFS.

Signed-off-by: Luo Longjun <luolongjun@...wei.com>
---
 fs/locks.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/fs/locks.c b/fs/locks.c
index 99ca97e81b7a..1f7b6683ed54 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -2828,9 +2828,10 @@ struct locks_iterator {
 };
 
 static void lock_get_status(struct seq_file *f, struct file_lock *fl,
-			    loff_t id, char *pfx)
+			    loff_t id, char *pfx, int repeat)
 {
 	struct inode *inode = NULL;
+	int i;
 	unsigned int fl_pid;
 	struct pid_namespace *proc_pidns = proc_pid_ns(file_inode(f->file)->i_sb);
 
@@ -2844,7 +2845,13 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
 	if (fl->fl_file != NULL)
 		inode = locks_inode(fl->fl_file);
 
-	seq_printf(f, "%lld:%s ", id, pfx);
+	seq_printf(f, "%lld: ", id);
+	for (i = 1; i < repeat; i++)
+		seq_puts(f, " ");
+
+	if (repeat)
+		seq_printf(f, "%s", pfx);
+
 	if (IS_POSIX(fl)) {
 		if (fl->fl_flags & FL_ACCESS)
 			seq_puts(f, "ACCESS");
@@ -2906,6 +2913,19 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
 	}
 }
 
+static int __locks_show(struct seq_file *f, struct file_lock *fl, int level)
+{
+	struct locks_iterator *iter = f->private;
+	struct file_lock *bfl;
+
+	lock_get_status(f, fl, iter->li_pos, "-> ", level);
+
+	list_for_each_entry(bfl, &fl->fl_blocked_requests, fl_blocked_member)
+		__locks_show(f, bfl, level + 1);
+
+	return 0;
+}
+
 static int locks_show(struct seq_file *f, void *v)
 {
 	struct locks_iterator *iter = f->private;
@@ -2917,10 +2937,10 @@ static int locks_show(struct seq_file *f, void *v)
 	if (locks_translate_pid(fl, proc_pidns) == 0)
 		return 0;
 
-	lock_get_status(f, fl, iter->li_pos, "");
+	lock_get_status(f, fl, iter->li_pos, "", 0);
 
 	list_for_each_entry(bfl, &fl->fl_blocked_requests, fl_blocked_member)
-		lock_get_status(f, bfl, iter->li_pos, " ->");
+		__locks_show(f, bfl, 1);
 
 	return 0;
 }
@@ -2941,7 +2961,7 @@ static void __show_fd_locks(struct seq_file *f,
 
 		(*id)++;
 		seq_puts(f, "lock:\t");
-		lock_get_status(f, fl, *id, "");
+		lock_get_status(f, fl, *id, "", 0);
 	}
 }
 
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ