From patchwork Sat Jan 14 14:15:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 9517049 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 789DC60762 for ; Sat, 14 Jan 2017 14:15:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68C0428515 for ; Sat, 14 Jan 2017 14:15:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D87928553; Sat, 14 Jan 2017 14:15:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A85E028515 for ; Sat, 14 Jan 2017 14:15:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751303AbdANOPN (ORCPT ); Sat, 14 Jan 2017 09:15:13 -0500 Received: from mail-eopbgr20103.outbound.protection.outlook.com ([40.107.2.103]:32010 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751291AbdANOPL (ORCPT ); Sat, 14 Jan 2017 09:15:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=8KJquIGiCxDGKQPQifWhwzlC8KCwkdg9Lafltu81A7U=; b=aES5EhIlFu0xgRDf+E9Up6hOv2+QDEHVoRHMy5dJtFv009DadjqkxzPM8ICqr6BhJ4OPVEXS7z0H4P0v/ubJ/khlA7woFUUvTtaYJEQqphTTT3M1cRdaIZqsB1fE0X7AJKEppB50cmTKfHehVqj3hXhwPM/RhviX+8bow7r5KaY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from localhost.localdomain (195.214.232.6) by DB6PR0802MB2277.eurprd08.prod.outlook.com (10.172.227.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.845.12; Sat, 14 Jan 2017 14:15:07 +0000 Subject: [PATCH 2/2] pidns: Expose task pid_ns_for_children to userspace From: Kirill Tkhai To: , , , , , , Date: Sat, 14 Jan 2017 17:15:04 +0300 Message-ID: <148440329770.30622.16593902895676160550.stgit@localhost.localdomain> In-Reply-To: <148440326011.30622.12833059348082223242.stgit@localhost.localdomain> References: <148440326011.30622.12833059348082223242.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: VI1PR0501CA0016.eurprd05.prod.outlook.com (10.172.9.154) To DB6PR0802MB2277.eurprd08.prod.outlook.com (10.172.227.150) X-MS-Office365-Filtering-Correlation-Id: fa058723-2db2-4dbc-1e10-08d43c87bea2 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DB6PR0802MB2277; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2277; 3:dMMbkOou++PEd+8zyf8lY9h435bEB7f3zgE1TaS3c2rV2mWnrRUS2dCrcixKTWpXPVwY15zbCql2mcZHH0z+ks5bG0P43MSe+uyD72NC5/3nMF8KzUE4cbJb9sNW4WC8VbEjwTvz7B4QR2A929iKjgBji1A2krqYA1wOpm50JE7bpfyDnxxjxsYdtgcLYLww49GQK3AxOjWgnJqa1diMctFK0RkZ+NElF1H7p/FVbUtu6hLnLingCF37nOd4eel3AyPTR78anSskDEnG09xSkg== X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2277; 25:AIlaIpFsztmSwfn0WRH9/NR7aUfsp/g0zn+71e/sE/+XSrX2bpaLlA8dHkH465j4PglEbWjzq4x6YKEQ8gNlD0ATTvtKeF8EOofX834/byjvLctenhSJsKfqxwpRqMeeX4Fv0WNnt4H3YKgwyJ4MGGZ5qSkR9hpRukrGPeL7/fTWIQN1Q8uGfh+Hoit8g7IkjnnuTl+83GUxC+VIMejvXdYUEWcBI+N7WLdrdEfRsp+ELmasYddrR0JTT6p8TiugIuJ3waJLRALkdSjeKa0KadZIqj4fzHShPt7lMHrky91Jxn1y0NNEKSJ6m/y3eHVe+ziGloNjrTiCuoTtR1ejuL+7NUAGC1QqWtGuUKJGRLeM1pHpAL2AM/vixyeNDy3GZc2NfJSMtmi+ojIEW+l4vkKwKJjESGkhDe9lZDa/D3hPCOHtvVQJaXYqU5tBx37gUn2kNRCcZAufgPPl8gPl0mN3vRknXyxhmI493l3L6JOLWpk/evqFv2Wru4piAzsW0eatJvigeH13KzVnoLxRpPzelX2fhAaHyMPeyMYU73guviSECLTVuh3nKCxBiv2xWX/PPHQs7aDzQe7Yy1M2N0s9otX/gvJEBSshCox+n7ZAtYAFVJb7Fza16eo69r5W93MNqKClt9OAjQasacEVCiJRPUfQXt27lFvfYOxtexUhh76gle3yQOXDGB5aeW+h7gGwTcHtScsr5K+j5KgGxwYYgIPw6BlJOWEMpCtq6bBWjcjlQDD1A6UPK6KXAAh8 X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2277; 31:aDF7evgq6hCerACZ63yjbsN9L11A1m3AflapnfuiUjXyE/12GDwP4gBgR51/s0YwgpHi+I4+DWn+uFx8hbF2Dh6RZvORWBxcEjvcVxU4aWa1ZUm7FVyPtBpdSkpVJorPdw2+Uci0ktqANYjMNmincWi3UIV69A+Ngddeqw762/4qmitv8A3Y3QxbRF1QXzfmpymEixwqR19C7ODthqOpEYdECeeNP8Oy++3KQc5wdHlU5soUrFTKzD0HDndftZ4/; 20:1rSRr/zjvR0rhVIVEm/b7T4RpFe5Xa2NXsLCW4wCX9VpCIH85U9CPex2OdyHSG5S2IsztVggndYu3OQBcDRTc6H+e5bRV+G/Hz316YxjiXYHkz2lUwaQVXZiAPSfFYlW1kFEFCg0WbT6hIaTsAXHWpOx5FG32lfji/ju52qB5A1R/DAhVn5axHJswywb3DHxFnjDtp2Iq6TXmUOoCyJHDHyM74uPGs3ImR5Ey/P75lh6/9Xf/cgu9sCn0Ysdn3pS X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123562025)(20161123555025)(20161123564025)(20161123560025)(6072148); SRVR:DB6PR0802MB2277; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0802MB2277; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2277; 4:d+YY+AuSadCUTzgWbQb7yKtZMUEnGaqn7IPczBqVhtvQl7X2udL9XLJ8YAphjT91dGZN6G/DQTdEVEngMEHyymwDAF2pmqsMP4PWMiVt9ki2m+zWehRTVnvTdlOKLvTDq/FsgrPyiWsMPklMKfXeJeOJWpjbxdeTV190D/mM9jxMPmWW8LPSQpLiOqCh0a5HpOZAWUJsWQf8/XQ0bo69jpu3iE4ZZw3TvZ1ykKcbgTuwc+3QAYgPOumyNi75iMrPo7LmiOlHYak4F8ezkwyg1tycfDuhRiJOSm032Z3liwFyK4W1X0hCokmQIjaCsmYpzTF4i6Kq+sv6hP2AwQk/C4BdvAfKKRR3FRijSXFiJP1leY8J46SR1gGLsMjPCMogeZ4jJq6ZpySA3Uu9KhmZVfONlFSBpyu90UAyi5GlkpzfQ+rqcXoaffwBF31/JMjkkEcvK3i9mIiuyIW/QWkSdRAbEf6a8JYx5fnF/bQ/x1MV1KtW30PAvGb7nBOiQKWBGoj1b5yaQ2D5Gm81YFdwM+OXVe1mbNMMCoqHB7jLcYQnGzVEUQ46M2z9nE6dpadCBdi3mU/N5u078t8u7Q3Flw== X-Forefront-PRVS: 0187F3EA14 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(7916002)(39450400003)(189002)(199003)(5660300001)(8676002)(81166006)(105586002)(106356001)(81156014)(3846002)(76176999)(83506001)(4001350100001)(5001770100001)(230700001)(97736004)(6116002)(68736007)(54356999)(50986999)(6666003)(2950100002)(103116003)(33646002)(50466002)(9686003)(101416001)(92566002)(107886002)(189998001)(42186005)(27001)(2906002)(23676002)(66066001)(55016002)(47776003)(6506006)(38730400001)(25786008)(305945005)(7736002)(2201001)(575784001)(61506002)(86362001); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0802MB2277; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtEQjZQUjA4MDJNQjIyNzc7MjM6ZmEzeS9ycWxBbFhhMndydFcySENJRXhK?= =?utf-8?B?UG1tMU53ampKUzMySVdIUmliYTZJTlNZOFNlSmY3SDd0eGVlMkJtZmhqd3Ry?= =?utf-8?B?c1paUUowZHZETHBjeW5XbVl6NTIxOFBFNUI2UVNTb3kxaEJlNGEvQXpsc2JN?= =?utf-8?B?MmRZNktpZ0xSUmtJZjRtZEtGd2Y1S1BkRXJMemtJam92QmRHUGxKQVNMVHJQ?= =?utf-8?B?WjBuMkRWdGt3Z01GU1VSWDRtcmlQeXEyVmtDOEJvd1dFa3ZzeVU3bEhZdFZj?= =?utf-8?B?L09zb0grRW1UVlpQSEVXc1FFR1gwb21nNGJLempwUm5OWXdkcmlWSHdNaHFz?= =?utf-8?B?bkUvTGY4cUs0L3pML09IL1dtNmViVjVYY2dpclhkMU13WCt1MW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mc3tFBum74AKk4jMxrJ+e9tBs3AvA/yuI87UBU6GXGyvC2/LYrlAuKpoDyXBEyqgnbMoy/3MG6njGrbRoYrUxkDYGKVJoV5Bo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2277; 7:BChU/IkX1opfITOIf99ltWTEJ2wPqPhFJvJh3sXYE4BDnEA5kiK+6it1IOhBDxpK28pZCy9xMPhbturHn8uy22wK5mdAi0F5IVv5fOq41+Cm+hGJLsCUNfa3qEKeSMR/ITBMkzlXANjdiVRNJcphs7Fj2Dx1h/n6pHY5dq3y9E9zMPw2d8+tZEoDt1IkyFEGmbXxI7UaqOY3ZMl3pWWeDSGGEc6kutTjoXWWGzjwwD82mJu1wwrZLNWBcgz8siFl+1XJ+lJ48vzc8pvT1E+O9eDhD1/H7CChMWoE+SNUrNFRyPYSA4SBrAgE+ffMGhyYTcx9UBFkctI18kpcQSRW7QzTyerlxrT+FCWOfkbWTXxdGjr4wJYNLCnudslZ8Ui24ZNoAZOu7NDGYvYUMJ7FMjoP9GlOyeOiB/mZ1Cgvh5NsY6C4iVXwcmUMeaodnxjpHgejjtxXUMiT4k44Fj98Fw==; 20:TVCx98y2ZkAh4plOWpqJahyFsbWSyiyEOA3ajzAe4EgIfVCUmi02qLJH4QqZNaknz/c8D3xMabkBmRYIXctruBAodA32pR2v+YQE8NmH5KaZ+iyWRHuY+gA4o84qVGRRxmmqkeBsIZ1WFWlGxqwb8EIwlZ204+RWm3/h7PPUbW4= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jan 2017 14:15:07.4302 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2277 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For correct checkpointing/restoring of a task from userspace it's need to know the task's pid_ns_for_children. Currently, there is no a sane way to do that (the only possible trick is to force the task create a new child and to analize the child's /proc/[pid]/ns/pid link, that is performance-stupid). The patch exposes pid_ns_for_children to ns directory in standard way with the name "pid_for_children": ~# ls /proc/5531/ns -l | grep pid lrwxrwxrwx 1 root root 0 Jan 14 16:38 pid -> pid:[4026531836] lrwxrwxrwx 1 root root 0 Jan 14 16:38 pid_for_children -> pid:[4026532286] Signed-off-by: Kirill Tkhai Acked-by: Andrei Vagin --- fs/proc/namespaces.c | 1 + include/linux/proc_ns.h | 1 + kernel/pid_namespace.c | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" 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/fs/proc/namespaces.c b/fs/proc/namespaces.c index 766f0c637ad1..3803b24ca220 100644 --- a/fs/proc/namespaces.c +++ b/fs/proc/namespaces.c @@ -23,6 +23,7 @@ static const struct proc_ns_operations *ns_entries[] = { #endif #ifdef CONFIG_PID_NS &pidns_operations, + &pidns_for_children_operations, #endif #ifdef CONFIG_USER_NS &userns_operations, diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h index 88dba3b53375..58ab28d81fc2 100644 --- a/include/linux/proc_ns.h +++ b/include/linux/proc_ns.h @@ -27,6 +27,7 @@ extern const struct proc_ns_operations netns_operations; extern const struct proc_ns_operations utsns_operations; extern const struct proc_ns_operations ipcns_operations; extern const struct proc_ns_operations pidns_operations; +extern const struct proc_ns_operations pidns_for_children_operations; extern const struct proc_ns_operations userns_operations; extern const struct proc_ns_operations mntns_operations; extern const struct proc_ns_operations cgroupns_operations; diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index df9e8e9e0be7..cbe950d4a11e 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -369,6 +369,20 @@ static struct ns_common *pidns_get(struct task_struct *task) return ns ? &ns->ns : NULL; } +static struct ns_common *pidns_for_children_get(struct task_struct *task) +{ + struct pid_namespace *ns = NULL; + + task_lock(task); + if (task->nsproxy) { + ns = task->nsproxy->pid_ns_for_children; + get_pid_ns(ns); + } + task_unlock(task); + + return ns ? &ns->ns : NULL; +} + static void pidns_put(struct ns_common *ns) { put_pid_ns(to_pid_ns(ns)); @@ -438,6 +452,17 @@ const struct proc_ns_operations pidns_operations = { .get_parent = pidns_get_parent, }; +const struct proc_ns_operations pidns_for_children_operations = { + .name = "pid_for_children", + .real_ns_name = "pid", + .type = CLONE_NEWPID, + .get = pidns_for_children_get, + .put = pidns_put, + .install = pidns_install, + .owner = pidns_owner, + .get_parent = pidns_get_parent, +}; + static __init int pid_namespaces_init(void) { pid_ns_cachep = KMEM_CACHE(pid_namespace, SLAB_PANIC);