Skip to content

Instantly share code, notes, and snippets.

@avagin
Created February 26, 2015 09:10
Show Gist options
  • Save avagin/de5c788a8551c9b89450 to your computer and use it in GitHub Desktop.
Save avagin/de5c788a8551c9b89450 to your computer and use it in GitHub Desktop.
show locks in fdinfo
diff --git a/fs/locks.c b/fs/locks.c
index 59e2f90..ebbf686 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -2563,6 +2563,27 @@ static int locks_show(struct seq_file *f, void *v)
return 0;
}
+void show_fd_locks(struct seq_file *f, struct file *filp)
+{
+ struct inode * inode = file_inode(filp);
+ struct file_lock **before;
+ loff_t id = 0;
+
+ for_each_lock(inode, before) {
+ struct file_lock *fl = *before;
+
+ if (filp != fl->fl_file)
+ continue;
+ if (fl->fl_owner != current->files &&
+ fl->fl_owner != filp)
+ continue;
+
+ id++;
+ seq_printf(f, "lock:\t");
+ lock_get_status(f, fl, id, "");
+ }
+}
+
static void *locks_start(struct seq_file *f, loff_t *pos)
__acquires(&blocked_lock_lock)
{
diff --git a/fs/proc/fd.c b/fs/proc/fd.c
index 8e5ad83..0d5f2e9 100644
--- a/fs/proc/fd.c
+++ b/fs/proc/fd.c
@@ -8,6 +8,7 @@
#include <linux/security.h>
#include <linux/file.h>
#include <linux/seq_file.h>
+#include <linux/fs.h>
#include <linux/proc_fs.h>
@@ -52,6 +53,7 @@ static int seq_show(struct seq_file *m, void *v)
seq_printf(m, "pos:\t%lli\nflags:\t0%o\nmnt_id:\t%i\n",
(long long)file->f_pos, f_flags,
real_mount(file->f_path.mnt)->mnt_id);
+ show_fd_locks(m, file);
if (file->f_op->show_fdinfo)
file->f_op->show_fdinfo(m, file);
ret = seq_has_overflowed(m);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 42efe13..f22323a 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1011,6 +1011,7 @@ extern void lease_get_mtime(struct inode *, struct timespec *time);
extern int generic_setlease(struct file *, long, struct file_lock **, void **priv);
extern int vfs_setlease(struct file *, long, struct file_lock **, void **);
extern int lease_modify(struct file_lock **, int, struct list_head *);
+extern void show_fd_locks(struct seq_file *f, struct file *filp);
#else /* !CONFIG_FILE_LOCKING */
static inline int fcntl_getlk(struct file *file, unsigned int cmd,
struct flock __user *user)
@@ -1142,6 +1143,8 @@ static inline int lease_modify(struct file_lock **before, int arg,
{
return -EINVAL;
}
+
+static inline void show_fd_locks(struct seq_file *f, struct file *filp) { }
#endif /* !CONFIG_FILE_LOCKING */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment