Received: by 10.192.165.148 with SMTP id m20csp4105760imm; Mon, 23 Apr 2018 19:23:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx48IW8On1XQ32ec+0WBbHV+cF2n7lc7EwOKqGnc8d1kHp+v4poQGBEwKoqbo3SkKQjXvLsYp X-Received: by 10.99.110.199 with SMTP id j190mr18404907pgc.71.1524536623651; Mon, 23 Apr 2018 19:23:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524536623; cv=none; d=google.com; s=arc-20160816; b=NLIhr87lsW7MggLFsgtAiprH5ccOd5zESeG0CXFl36p1kZqRz0xGn+at47No8gQwHP 7Nv9JvKXOzfWz00CeWZWzSyNrQFvhcsBmpP62JYUmwRYf640NbKvpN7mEgXEEwIZS/Hk zuSwwKe/NU18EGE3KGm+Ln0dqCdrwyxUQNvrr9w8+zOH/29wV54zqVSex6lmTX5VZtjJ c6LT6kZULg3pItK15e2bW/MYc1DeUtClttqUwVe7+C3HRTSdjzf50fdV2Izyf1IaNYX1 NWkk69gU5YK+S+Q4O4YAYweAYMGDW5lptYjDSRz1TAqQI/dz2SLvNBS1hhlvcf9DQzkN 9vSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Vn2Ppzc0VtKBpwzeVku51AZMZhTMK3b+heXu4luWi8I=; b=SUC6fNmPwdzZKer/58GqoWiC16KqBN79U5fbO3tY49Yab+h50rNwujk+aKd0E9AKB+ dEhoi25L5GRvi2iZAdkRQyvlD3MU7Z3H/FOdtPvcOeCQlGPv4xdr4Tj9ZeibcrVbBv8Y 1wCwycA7yuF/zzAwITq6R6RNL/IN5dMFh+9j/726zDMAWrkOxc7YUxXYdj3PJZOOGk8d 6MX6wEZ0JN2gUdvJY7iSi7jwINSrFGTn41MqBTIKud8ZcPDHmWz6PBxmJKeUbzK5H7Tg uguayc8KW5J/+mSOUt1l98rYdqo8HQo4waFGkil3nI8nLiM+c6JgJ0qcN1hmS1shs2KI r83g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m2si7541798pgm.360.2018.04.23.19.23.28; Mon, 23 Apr 2018 19:23:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932816AbeDXCVz (ORCPT + 99 others); Mon, 23 Apr 2018 22:21:55 -0400 Received: from mx2.suse.de ([195.135.220.15]:36671 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932721AbeDXCVQ (ORCPT ); Mon, 23 Apr 2018 22:21:16 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9A40BAE80; Tue, 24 Apr 2018 02:21:13 +0000 (UTC) Received: from starscream.home.jeffm.io (starscream-1.home.jeffm.io [192.168.1.254]) by mail.home.jeffm.io (Postfix) with ESMTPS id 34E7381AD3E9; Mon, 23 Apr 2018 22:20:54 -0400 (EDT) Received: by starscream.home.jeffm.io (Postfix, from userid 1000) id E0F3C816A7; Mon, 23 Apr 2018 22:21:10 -0400 (EDT) From: jeffm@suse.com To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Al Viro , "Eric W . Biederman" , Alexey Dobriyan , Oleg Nesterov , Jeff Mahoney Subject: [PATCH 4/5] procfs: share common directories between /proc/tgid and /proc/tgid/task/tgid Date: Mon, 23 Apr 2018 22:21:05 -0400 Message-Id: <20180424022106.16952-5-jeffm@suse.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180424022106.16952-1-jeffm@suse.com> References: <20180424022106.16952-1-jeffm@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jeff Mahoney The contents of /proc/tgid and /proc/tgid/task/tgid are nearly identical but aren't. There are files (or directory) contained in only one or the other. Therefore, we can't replace one with a symbolic link. Creating links for the common files doesn't gain us anything since we'll still need the dentries and inodes for them. What we can do is create links for the common subdirectories so the files below them are shared. This patch converts the fd, fdinfo, ns, net, and attr directories at the /proc/tgid level to symbolic links that point to the directories in /proc/tgid/task/pid . Signed-off-by: Jeff Mahoney --- fs/proc/base.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index de12bd2137ac..005b4f8a19c2 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -140,6 +140,9 @@ struct pid_entry { NOD(NAME, (S_IFLNK|S_IRWXUGO), \ &proc_pid_link_inode_operations, NULL, \ { .proc_get_link = get_link } ) +#define TASKLNK(NAME) \ + NOD(NAME, (S_IFLNK|S_IRWXUGO), \ + &proc_tgid_to_pid_link_inode_operations, NULL, {}) #define REG(NAME, MODE, fops) \ NOD(NAME, (S_IFREG|(MODE)), NULL, &fops, {}) #define ONE(NAME, MODE, show) \ @@ -2941,6 +2944,37 @@ static int proc_pid_patch_state(struct seq_file *m, struct pid_namespace *ns, } #endif /* CONFIG_LIVEPATCH */ +static const char *proc_tgid_to_pid_symlink_get_link(struct dentry *dentry, + struct inode *inode, + struct delayed_call *done) +{ + struct task_struct *task; + char *link = ERR_PTR(-ENOENT); + + if (!dentry) + return ERR_PTR(-ECHILD); + + task = get_proc_task(inode); + if (task) { + struct pid_namespace *ns = inode->i_sb->s_fs_info; + + link = kasprintf(GFP_KERNEL, "task/%u/%.*s", + pid_nr_ns(PROC_I(inode)->pid, ns), + dentry->d_name.len, dentry->d_name.name); + if (link) + set_delayed_call(done, kfree_link, link); + else + link = ERR_PTR(-ENOMEM); + put_task_struct(task); + } + return link; +} + +static const struct inode_operations proc_tgid_to_pid_link_inode_operations = { + .get_link = proc_tgid_to_pid_symlink_get_link, + .setattr = proc_setattr, +}; + /* * Thread groups */ @@ -2948,12 +2982,12 @@ static const struct file_operations proc_task_operations; static const struct inode_operations proc_task_inode_operations; static const struct pid_entry tgid_base_stuff[] = { - DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations), + TASKLNK("fd"), DIR("map_files", S_IRUSR|S_IXUSR, proc_map_files_inode_operations, proc_map_files_operations), - DIR("fdinfo", S_IRUSR|S_IXUSR, proc_fdinfo_inode_operations, proc_fdinfo_operations), - DIR("ns", S_IRUSR|S_IXUGO, proc_ns_dir_inode_operations, proc_ns_dir_operations), + TASKLNK("fdinfo"), + TASKLNK("ns"), #ifdef CONFIG_NET - DIR("net", S_IRUGO|S_IXUGO, proc_net_inode_operations, proc_net_operations), + TASKLNK("net"), #endif REG("environ", S_IRUSR, proc_environ_operations), REG("auxv", S_IRUSR, proc_auxv_operations), @@ -2991,7 +3025,7 @@ static const struct pid_entry tgid_base_stuff[] = { REG("pagemap", S_IRUSR, proc_pagemap_operations), #endif #ifdef CONFIG_SECURITY - DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations), + TASKLNK("attr"), #endif #ifdef CONFIG_KALLSYMS ONE("wchan", S_IRUGO, proc_pid_wchan), -- 2.12.3