From: jeffm@suse.com
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: Al Viro <viro@zeniv.linux.org.uk>,
"Eric W . Biederman" <ebiederm@xmission.com>,
Alexey Dobriyan <adobriyan@gmail.com>,
Oleg Nesterov <oleg@redhat.com>, Jeff Mahoney <jeffm@suse.com>
Subject: [PATCH 1/5] procfs: factor out a few helpers
Date: Mon, 23 Apr 2018 22:21:02 -0400 [thread overview]
Message-ID: <20180424022106.16952-2-jeffm@suse.com> (raw)
In-Reply-To: <20180424022106.16952-1-jeffm@suse.com>
From: Jeff Mahoney <jeffm@suse.com>
In order to make the following series easier to review, this patch
factors out a few helpers:
- proc_fill_cache_entry: proc_fill_cache that takes an entry instead of
an entry, a name, and a name length
- pident_lookup_task: proc_pident_lookup that takes a task, allowing the
caller to do the task validation
- pid_entry_match_dentry: the comparison between a dentry's name and
a pid_entry
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
fs/proc/base.c | 60 ++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 40 insertions(+), 20 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 9298324325ed..e9876a89a5ad 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2453,19 +2453,28 @@ static int proc_pident_instantiate(struct inode *dir,
return -ENOENT;
}
-static struct dentry *proc_pident_lookup(struct inode *dir,
- struct dentry *dentry,
- const struct pid_entry *ents,
- unsigned int nents)
+static bool proc_fill_cache_entry(struct file *file, struct dir_context *ctx,
+ const struct pid_entry *entry,
+ struct task_struct *task)
{
- int error;
- struct task_struct *task = get_proc_task(dir);
- const struct pid_entry *p, *last;
+ return proc_fill_cache(file, ctx, entry->name, entry->len,
+ proc_pident_instantiate, task, entry);
+}
- error = -ENOENT;
+static bool pid_entry_match_dentry(const struct pid_entry *entry,
+ const struct dentry *dentry)
+{
+ if (entry->len != dentry->d_name.len)
+ return false;
+ return !memcmp(dentry->d_name.name, entry->name, entry->len);
+}
- if (!task)
- goto out_no_task;
+static int proc_pident_lookup_task(struct inode *dir, struct dentry *dentry,
+ const struct pid_entry *ents,
+ unsigned int nents,
+ struct task_struct *task)
+{
+ const struct pid_entry *p, *last;
/*
* Yes, it does not scale. And it should not. Don't add
@@ -2473,18 +2482,30 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
*/
last = &ents[nents];
for (p = ents; p < last; p++) {
- if (p->len != dentry->d_name.len)
- continue;
- if (!memcmp(dentry->d_name.name, p->name, p->len))
+ if (pid_entry_match_dentry(p, dentry))
break;
}
if (p >= last)
- goto out;
+ return -ENOENT;
+
+ return proc_pident_instantiate(dir, dentry, task, p);
+}
+
+static struct dentry *proc_pident_lookup(struct inode *dir,
+ struct dentry *dentry,
+ const struct pid_entry *ents,
+ unsigned int nents)
+{
+ struct task_struct *task;
+ int error = -ENOENT;
+
+ task = get_proc_task(dir);
+ if (task) {
+ error = proc_pident_lookup_task(dir, dentry, ents,
+ nents, task);
+ put_task_struct(task);
+ }
- error = proc_pident_instantiate(dir, dentry, task, p);
-out:
- put_task_struct(task);
-out_no_task:
return ERR_PTR(error);
}
@@ -2504,8 +2525,7 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
goto out;
for (p = ents + (ctx->pos - 2); p < ents + nents; p++) {
- if (!proc_fill_cache(file, ctx, p->name, p->len,
- proc_pident_instantiate, task, p))
+ if (!proc_fill_cache_entry(file, ctx, p, task))
break;
ctx->pos++;
}
--
2.12.3
next prev parent reply other threads:[~2018-04-24 2:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-24 2:21 [RFC] [PATCH 0/5] procfs: reduce duplication by using symlinks jeffm
2018-04-24 2:21 ` jeffm [this message]
2018-04-24 2:21 ` [PATCH 2/5] procfs: factor out inode revalidation work from pid_revalidation jeffm
2018-04-24 2:21 ` [PATCH 3/5] procfs: use symlinks for /proc/<pid>/task when not thread group leader jeffm
2018-04-24 2:21 ` [PATCH 4/5] procfs: share common directories between /proc/tgid and /proc/tgid/task/tgid jeffm
2018-04-24 2:21 ` [PATCH 5/5] procfs: share fd/fdinfo with thread group leader when files are shared jeffm
2018-04-24 15:41 ` kbuild test robot
2018-04-24 15:41 ` [RFC PATCH] procfs: proc_pid_files_link_dentry_operations can be static kbuild test robot
2018-04-24 6:17 ` [RFC] [PATCH 0/5] procfs: reduce duplication by using symlinks Alexey Dobriyan
2018-04-25 18:04 ` Jeff Mahoney
2018-04-24 14:14 ` Eric W. Biederman
2018-04-26 21:03 ` Jeff Mahoney
2019-03-21 18:30 ` Jeff Mahoney
2019-03-23 15:56 ` Eric W. Biederman
2019-03-24 3:01 ` Jeff Mahoney
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=20180424022106.16952-2-jeffm@suse.com \
--to=jeffm@suse.com \
--cc=adobriyan@gmail.com \
--cc=ebiederm@xmission.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).