mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Weiping Zhang <zhangweiping@didiglobal.com>
To: <mingo@redhat.com>, <peterz@infradead.org>,
	<juri.lelli@redhat.com>, <vincent.guittot@linaro.org>,
	<dietmar.eggemann@arm.com>, <rostedt@goodmis.org>,
	<bsegall@google.com>, <mgorman@suse.de>
Cc: <linux-kernel@vger.kernel.org>
Subject: [RFC PATCH] proc: add support detach proccess's autogroup
Date: Thu, 2 Jul 2020 13:20:43 +0800	[thread overview]
Message-ID: <20200702052039.GA2824@192.168.3.9> (raw)

Since setid will create a autogroup for that process, there is no
way to detach a process from that autogroup, this patch add a new interface
to detach a process from its autogroup. You can write anything to
/proc/<pid>/autogroup_detach to do that.

Signed-off-by: Weiping Zhang <zhangweiping@didiglobal.com>
---
 fs/proc/base.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index d86c0afc8a85..a210cab8b52d 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1541,6 +1541,55 @@ static const struct file_operations proc_pid_sched_autogroup_operations = {
 	.release	= single_release,
 };
 
+static int sched_autogroup_detach_show(struct seq_file *m, void *v)
+{
+	struct inode *inode = m->private;
+
+	seq_printf(m, "write any data to detach this task from a autogroup\n");
+
+	return 0;
+}
+
+static int sched_autogroup_detach_open(struct inode *inode, struct file *filp)
+{
+	int ret;
+
+	ret = single_open(filp, sched_autogroup_detach_show, NULL);
+	if (!ret) {
+		struct seq_file *m = filp->private_data;
+
+		m->private = inode;
+	}
+	return ret;
+}
+
+static ssize_t
+sched_autogroup_detach_write(struct file *file, const char __user *buf,
+	    size_t count, loff_t *offset)
+{
+	struct inode *inode = file_inode(file);
+	struct task_struct *p;
+	int ret;
+
+	p = get_proc_task(inode);
+	if (!p)
+		return -ESRCH;
+
+	sched_autogroup_detach(p);
+
+	put_task_struct(p);
+
+	return count;
+}
+
+static const struct file_operations proc_pid_sched_autogroup_detach_operations = {
+	.open		= sched_autogroup_detach_open,
+	.read		= seq_read,
+	.write		= sched_autogroup_detach_write,
+	.llseek		= seq_lseek,
+	.release	= single_release,
+};
+
 #endif /* CONFIG_SCHED_AUTOGROUP */
 
 #ifdef CONFIG_TIME_NS
@@ -3161,6 +3210,7 @@ static const struct pid_entry tgid_base_stuff[] = {
 #endif
 #ifdef CONFIG_SCHED_AUTOGROUP
 	REG("autogroup",  S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
+	REG("autogroup_detach",  S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_detach_operations),
 #endif
 #ifdef CONFIG_TIME_NS
 	REG("timens_offsets",  S_IRUGO|S_IWUSR, proc_timens_offsets_operations),
-- 
2.14.1


             reply	other threads:[~2020-07-02  7:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-02  5:20 Weiping Zhang [this message]
2020-07-02  8:14 ` Peter Zijlstra
2020-07-02 10:21   ` Weiping Zhang
2020-07-07  9:34     ` Weiping Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200702052039.GA2824@192.168.3.9 \
    --to=zhangweiping@didiglobal.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®