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: 52926 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 80ACFB7D73 for ; Wed, 19 May 2010 10:05:30 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755754Ab0ESAE4 (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: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add a new kernel API to attach a task to current task's cgroup in all the active hierarchies. Signed-off-by: Sridhar Samudrala Reviewed-by: Paul Menage --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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