From patchwork Wed May 19 00:04:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sridhar Samudrala X-Patchwork-Id: 100646 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4J06F9D026332 for ; Wed, 19 May 2010 00:06:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755514Ab0ESAE4 (ORCPT ); Tue, 18 May 2010 20:04:56 -0400 Received: from mail-qy0-f183.google.com ([209.85.221.183]:63552 "EHLO mail-qy0-f183.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755189Ab0ESAEx (ORCPT ); Tue, 18 May 2010 20:04:53 -0400 Received: by qyk13 with SMTP id 13so10177164qyk.1 for ; Tue, 18 May 2010 17:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:content-type :date:message-id:mime-version:x-mailer:content-transfer-encoding; bh=Y+U9q4+OIH62RJCB+mnb/8zvFKK6gnRipbyZHdieNEc=; b=NK5NHjb7zqxSQjH43fScfcL8Nu4dHLicZThHEJXNcRsJrvian8+23TVcb65zplZlKL 9y8G6NYELoL4l5IUclNEOIVc8lO6dI7Ggv4/lTzRSnuCjeHDizZJ4QdhK5IHneL+dSc4 tKeKyId5DiF+zeEAfo61jofgXhGqY7UXq3d+s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; b=oVYxzIT1JFHe2trD5w4Fp4acEdYxjcMAPoGn3dbE5C2gqYceAQDPbUQ8C9bGuDnirP 18iOiKSi1rLoAy5dIT4mPNGc21BOr3fzYuWmhMRdx69p1UshAP6a3xBasvLoBI0faVsz 0hNHJN5IBSSzX087S5qj5z6gEN/fPfJnlMUm0= Received: by 10.229.227.10 with SMTP id iy10mr1648140qcb.48.1274227492204; Tue, 18 May 2010 17:04:52 -0700 (PDT) Received: from [9.47.18.19] ([32.97.110.52]) by mx.google.com with ESMTPS id v37sm1544455qce.12.2010.05.18.17.04.50 (version=SSLv3 cipher=RC4-MD5); Tue, 18 May 2010 17:04:51 -0700 (PDT) Subject: [PATCH 1/3] cgroups: Add an API to attach a task to current task's cgroup From: Sridhar Samudrala To: "Michael S. Tsirkin" , netdev , "kvm@vger.kernel.org" , lkml Date: Tue, 18 May 2010 17:04:48 -0700 Message-Id: <1274227488.2370.107.camel@w-sridhar.beaverton.ibm.com> Mime-Version: 1.0 X-Mailer: Evolution 2.26.3 (2.26.3-1.fc11) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 19 May 2010 00:06:15 +0000 (UTC) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -570,6 +570,7 @@ struct task_struct *cgroup_iter_next(struct cgroup *cgrp, void cgroup_iter_end(struct cgroup *cgrp, struct cgroup_iter *it); int cgroup_scan_tasks(struct cgroup_scanner *scan); int cgroup_attach_task(struct cgroup *, struct task_struct *); +int cgroup_attach_task_current_cg(struct task_struct *); /* * CSS ID is ID for cgroup_subsys_state structs under subsys. This only works diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 6d870f2..6cfeb06 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -1788,6 +1788,29 @@ out: return retval; } +/** + * cgroup_attach_task_current_cg - attach task 'tsk' to current task's cgroup + * @tsk: the task to be attached + */ +int cgroup_attach_task_current_cg(struct task_struct *tsk) +{ + struct cgroupfs_root *root; + struct cgroup *cur_cg; + int retval = 0; + + cgroup_lock(); + for_each_active_root(root) { + cur_cg = task_cgroup_from_root(current, root); + retval = cgroup_attach_task(cur_cg, tsk); + if (retval) + break; + } + cgroup_unlock(); + + return retval; +} +EXPORT_SYMBOL_GPL(cgroup_attach_task_current_cg); + /* * Attach task with pid 'pid' to cgroup 'cgrp'. Call with cgroup_mutex * held. May take task_lock of task