Netdev List
 help / color / mirror / Atom feed
From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: netdev@vger.kernel.org, daniel@iogearbox.net,
	alexei.starovoitov@gmail.com
Cc: oss-drivers@netronome.com,
	Jakub Kicinski <jakub.kicinski@netronome.com>,
	"Eric W . Biederman" <ebiederm@xmission.com>
Subject: [PATCH bpf-next v3 6/9] nsfs: generalize ns_get_path() for path resolution with a task
Date: Wed, 27 Dec 2017 18:39:08 -0800	[thread overview]
Message-ID: <20171228023911.4251-7-jakub.kicinski@netronome.com> (raw)
In-Reply-To: <20171228023911.4251-1-jakub.kicinski@netronome.com>

ns_get_path() takes struct task_struct and proc_ns_ops as its
parameters.  For path resolution directly from a namespace,
e.g. based on a networking device's net name space, we need
more flexibility.  Add a ns_get_path_cb() helper which will
allow callers to use any method of obtaining the name space
reference.  Convert ns_get_path() to use ns_get_path_cb().

Following patches will bring a networking user.

CC: Eric W. Biederman <ebiederm@xmission.com>
Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 fs/nsfs.c               | 29 ++++++++++++++++++++++++++---
 include/linux/proc_ns.h |  3 +++
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/fs/nsfs.c b/fs/nsfs.c
index 7c6f76d29f56..36b0772701a0 100644
--- a/fs/nsfs.c
+++ b/fs/nsfs.c
@@ -103,14 +103,14 @@ static void *__ns_get_path(struct path *path, struct ns_common *ns)
 	goto got_it;
 }
 
-void *ns_get_path(struct path *path, struct task_struct *task,
-			const struct proc_ns_operations *ns_ops)
+void *ns_get_path_cb(struct path *path, ns_get_path_helper_t *ns_get_cb,
+		     void *private_data)
 {
 	struct ns_common *ns;
 	void *ret;
 
 again:
-	ns = ns_ops->get(task);
+	ns = ns_get_cb(private_data);
 	if (!ns)
 		return ERR_PTR(-ENOENT);
 
@@ -120,6 +120,29 @@ void *ns_get_path(struct path *path, struct task_struct *task,
 	return ret;
 }
 
+struct ns_get_path_task_args {
+	const struct proc_ns_operations *ns_ops;
+	struct task_struct *task;
+};
+
+static struct ns_common *ns_get_path_task(void *private_data)
+{
+	struct ns_get_path_task_args *args = private_data;
+
+	return args->ns_ops->get(args->task);
+}
+
+void *ns_get_path(struct path *path, struct task_struct *task,
+		  const struct proc_ns_operations *ns_ops)
+{
+	struct ns_get_path_task_args args = {
+		.ns_ops	= ns_ops,
+		.task	= task,
+	};
+
+	return ns_get_path_cb(path, ns_get_path_task, &args);
+}
+
 int open_related_ns(struct ns_common *ns,
 		   struct ns_common *(*get_ns)(struct ns_common *ns))
 {
diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
index 2ff18c9840a7..d31cb6215905 100644
--- a/include/linux/proc_ns.h
+++ b/include/linux/proc_ns.h
@@ -78,6 +78,9 @@ extern struct file *proc_ns_fget(int fd);
 #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)
 extern void *ns_get_path(struct path *path, struct task_struct *task,
 			const struct proc_ns_operations *ns_ops);
+typedef struct ns_common *ns_get_path_helper_t(void *);
+extern void *ns_get_path_cb(struct path *path, ns_get_path_helper_t ns_get_cb,
+			    void *private_data);
 
 extern int ns_get_name(char *buf, size_t size, struct task_struct *task,
 			const struct proc_ns_operations *ns_ops);
-- 
2.15.1

  parent reply	other threads:[~2017-12-28  2:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-28  2:39 [PATCH bpf-next v3 0/9] bpf: offload: report device back to user space (take 2) Jakub Kicinski
2017-12-28  2:39 ` [PATCH bpf-next v3 1/9] bpf: offload: don't require rtnl for dev list manipulation Jakub Kicinski
2017-12-28  2:39 ` [PATCH bpf-next v3 2/9] bpf: offload: don't use prog->aux->offload as boolean Jakub Kicinski
2017-12-28  2:39 ` [PATCH bpf-next v3 3/9] bpf: offload: allow netdev to disappear while verifier is running Jakub Kicinski
2017-12-28  2:39 ` [PATCH bpf-next v3 4/9] bpf: offload: free prog->aux->offload when device disappears Jakub Kicinski
2017-12-28  2:39 ` [PATCH bpf-next v3 5/9] bpf: offload: free program id " Jakub Kicinski
2017-12-28  2:39 ` Jakub Kicinski [this message]
2017-12-28  2:39 ` [PATCH bpf-next v3 7/9] bpf: offload: report device information for offloaded programs Jakub Kicinski
2017-12-28  2:39 ` [PATCH bpf-next v3 8/9] tools: bpftool: " Jakub Kicinski
2017-12-28  2:39 ` [PATCH bpf-next v3 9/9] selftests/bpf: test device info reporting for bound progs Jakub Kicinski
2017-12-31 16:01 ` [PATCH bpf-next v3 0/9] bpf: offload: report device back to user space (take 2) Daniel Borkmann

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=20171228023911.4251-7-jakub.kicinski@netronome.com \
    --to=jakub.kicinski@netronome.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=daniel@iogearbox.net \
    --cc=ebiederm@xmission.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    /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