[Patch 13/21] Freeze / Thaw threads

From: Suzuki K. Poulose
Date: Tue Dec 14 2010 - 05:15:01 EST


All the threads in the target process are issued a freeze request on an "open()".
They are woken up when we release the fd.

Signed-off-by: Suzuki K. Poulose <suzuki@xxxxxxxxxx>
Signed-off-by: Ananth N.Mavinakayanahalli <ananth@xxxxxxxxxx>
---
fs/proc/gencore.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

Index: linux-2.6.36-rc7/fs/proc/gencore.c
===================================================================
--- linux-2.6.36-rc7.orig/fs/proc/gencore.c
+++ linux-2.6.36-rc7/fs/proc/gencore.c
@@ -24,6 +24,7 @@

#include <linux/seq_file.h>
#include <linux/elf.h>
+#include <linux/freezer.h>

#include "internal.h"
#include "gencore.h"
@@ -70,11 +71,20 @@ out:
static int release_gencore(struct inode *inode, struct file *file)
{
struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
+ struct task_struct *t;
struct core_proc *cp;

if (!task)
return -EIO;

+ /* Thaw all frozen threads */
+ t = task;
+ read_lock(&tasklist_lock);
+ do {
+ thaw_process(t);
+ } while ((t = next_thread(t)) != task);
+ read_unlock(&tasklist_lock);
+
mutex_lock(&core_mutex);
cp = get_core_proc(task);
if (cp) {
@@ -117,6 +127,7 @@ static int get_elf_class(struct task_str
static int open_gencore(struct inode *inode, struct file *filp)
{
struct task_struct *task = get_proc_task(inode);
+ struct task_struct *t;
struct core_proc *cp;
int ret = 0;
int elf_class;
@@ -148,6 +159,21 @@ static int open_gencore(struct inode *in
list_add(&cp->list, &core_list);
mutex_unlock(&core_mutex);

+ /* freeze the processes */
+ t = task;
+ read_lock(&tasklist_lock);
+ do {
+ if (frozen(t) || !freezeable(t) || freezing(t))
+ continue;
+
+ if (freeze_task(t, true))
+ continue;
+
+ if (task_is_stopped_or_traced(t))
+ continue;
+ } while ((t = next_thread(t)) != task);
+ read_unlock(&tasklist_lock);
+
out:
put_task_struct(task);
return ret;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/