[CRIU] Re: [PATCH kernel] fdinfo: Show sigmask for signalfd fd

Pavel Emelyanov xemul at parallels.com
Thu Aug 2 04:19:12 EDT 2012


On 08/02/2012 12:04 PM, Pavel Emelyanov wrote:
> Dump only the sigmask value, as the pending state should be read from
> the task's proc files (later).
> 
> Cyrill, pick this up (AFTER THE VACATION IS OVER) this into our kernel
> and your set that you're pushing upstream.
> 
> I will push the crtools support for signalfd shortly.
> 
> Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
> 
> ---

Added lost patch %)


diff --git a/fs/proc/array.c b/fs/proc/array.c
index c1c207c..c5db89c 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -220,7 +220,7 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
 	seq_putc(m, '\n');
 }
 
-static void render_sigset_t(struct seq_file *m, const char *header,
+void render_sigset_t(struct seq_file *m, const char *header,
 				sigset_t *set)
 {
 	int i;
diff --git a/fs/signalfd.c b/fs/signalfd.c
index 9f35a37..c8c6882 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -29,6 +29,7 @@
 #include <linux/anon_inodes.h>
 #include <linux/signalfd.h>
 #include <linux/syscalls.h>
+#include <linux/proc_fs.h>
 
 void signalfd_cleanup(struct sighand_struct *sighand)
 {
@@ -46,6 +47,7 @@ void signalfd_cleanup(struct sighand_struct *sighand)
 }
 
 struct signalfd_ctx {
+	seqcount_t cnt;
 	sigset_t sigmask;
 };
 
@@ -259,6 +261,7 @@ SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask,
 			return -ENOMEM;
 
 		ctx->sigmask = sigmask;
+		seqcount_init(&ctx->cnt);
 
 		/*
 		 * When we call this, the initialization must be complete, since
@@ -279,7 +282,9 @@ SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask,
 			return -EINVAL;
 		}
 		spin_lock_irq(&current->sighand->siglock);
+		write_seqcount_begin(&ctx->cnt);
 		ctx->sigmask = sigmask;
+		write_seqcount_end(&ctx->cnt);
 		spin_unlock_irq(&current->sighand->siglock);
 
 		wake_up(&current->sighand->signalfd_wqh);
@@ -294,3 +299,61 @@ SYSCALL_DEFINE3(signalfd, int, ufd, sigset_t __user *, user_mask,
 {
 	return sys_signalfd4(ufd, user_mask, sizemask, 0);
 }
+
+#if defined(CONFIG_PROC_FS) && defined(CONFIG_CHECKPOINT_RESTORE)
+
+static void *seq_start(struct seq_file *m, loff_t *pos)
+{
+	struct proc_fdinfo_extra *extra = m->private;
+	return *pos == 0 ? extra->f_file : NULL;
+}
+
+static void *seq_next(struct seq_file *m, void *p, loff_t *pos)
+{
+	++*pos;
+	return NULL;
+}
+
+static int seq_show(struct seq_file *m, void *v)
+{
+	struct signalfd_ctx *ctx = ((struct file *)v)->private_data;
+	sigset_t sigmask;
+	unsigned seq;
+
+	do {
+		seq = read_seqcount_begin(&ctx->cnt);
+		sigmask = ctx->sigmask;
+	} while (read_seqcount_retry(&ctx->cnt, seq));
+
+	signotset(&sigmask);
+	render_sigset_t(m, "sigmask:\t", &sigmask);
+	return 0;
+}
+
+static void seq_stop(struct seq_file *p, void *v) { }
+
+static const struct seq_operations signalfd_fdinfo_ops = {
+	.start	= seq_start,
+	.next	= seq_next,
+	.stop	= seq_stop,
+	.show	= seq_show,
+};
+
+static int is_signalfd_file(struct file *file)
+{
+	return file->f_op == &signalfd_fops;
+}
+
+static struct proc_fdinfo_driver signalfd_fdinfo = {
+	.name	= "signalfd",
+	.ops	= &signalfd_fdinfo_ops,
+	.probe	= is_signalfd_file,
+};
+
+static int __init signalfd_init(void)
+{
+	return proc_register_fdinfo_driver(&signalfd_fdinfo);
+}
+fs_initcall(signalfd_init);
+
+#endif /* CONFIG_PROC_FS && CONFIG_CHECKPOINT_RESTORE */
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 25d305d..26d441b 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -318,4 +318,7 @@ static inline struct net *PDE_NET(struct proc_dir_entry *pde)
 	return pde->parent->data;
 }
 
+#include <asm/signal.h>
+
+void render_sigset_t(struct seq_file *m, const char *header, sigset_t *set);
 #endif /* _LINUX_PROC_FS_H */


More information about the CRIU mailing list