diff options
| author | Jakub Kicinski <jakub.kicinski@netronome.com> | 2017-12-27 21:39:08 -0500 |
|---|---|---|
| committer | Daniel Borkmann <daniel@iogearbox.net> | 2017-12-31 10:12:23 -0500 |
| commit | cdab6ba8668d68f031bfd5d237b4586ec4f8cd88 (patch) | |
| tree | 8e996972f0cfbccd3334d7e12490c5d5cbdb2d24 | |
| parent | ad8ad79f4f6078f456792f7f8d344da2be9bc74f (diff) | |
nsfs: generalize ns_get_path() for path resolution with a task
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>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
| -rw-r--r-- | fs/nsfs.c | 29 | ||||
| -rw-r--r-- | include/linux/proc_ns.h | 3 |
2 files changed, 29 insertions, 3 deletions
| @@ -103,14 +103,14 @@ slow: | |||
| 103 | goto got_it; | 103 | goto got_it; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | void *ns_get_path(struct path *path, struct task_struct *task, | 106 | void *ns_get_path_cb(struct path *path, ns_get_path_helper_t *ns_get_cb, |
| 107 | const struct proc_ns_operations *ns_ops) | 107 | void *private_data) |
| 108 | { | 108 | { |
| 109 | struct ns_common *ns; | 109 | struct ns_common *ns; |
| 110 | void *ret; | 110 | void *ret; |
| 111 | 111 | ||
| 112 | again: | 112 | again: |
| 113 | ns = ns_ops->get(task); | 113 | ns = ns_get_cb(private_data); |
| 114 | if (!ns) | 114 | if (!ns) |
| 115 | return ERR_PTR(-ENOENT); | 115 | return ERR_PTR(-ENOENT); |
| 116 | 116 | ||
| @@ -120,6 +120,29 @@ again: | |||
| 120 | return ret; | 120 | return ret; |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | struct ns_get_path_task_args { | ||
| 124 | const struct proc_ns_operations *ns_ops; | ||
| 125 | struct task_struct *task; | ||
| 126 | }; | ||
| 127 | |||
| 128 | static struct ns_common *ns_get_path_task(void *private_data) | ||
| 129 | { | ||
| 130 | struct ns_get_path_task_args *args = private_data; | ||
| 131 | |||
| 132 | return args->ns_ops->get(args->task); | ||
| 133 | } | ||
| 134 | |||
| 135 | void *ns_get_path(struct path *path, struct task_struct *task, | ||
| 136 | const struct proc_ns_operations *ns_ops) | ||
| 137 | { | ||
| 138 | struct ns_get_path_task_args args = { | ||
| 139 | .ns_ops = ns_ops, | ||
| 140 | .task = task, | ||
| 141 | }; | ||
| 142 | |||
| 143 | return ns_get_path_cb(path, ns_get_path_task, &args); | ||
| 144 | } | ||
| 145 | |||
| 123 | int open_related_ns(struct ns_common *ns, | 146 | int open_related_ns(struct ns_common *ns, |
| 124 | struct ns_common *(*get_ns)(struct ns_common *ns)) | 147 | struct ns_common *(*get_ns)(struct ns_common *ns)) |
| 125 | { | 148 | { |
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); | |||
| 78 | #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private) | 78 | #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private) |
| 79 | extern void *ns_get_path(struct path *path, struct task_struct *task, | 79 | extern void *ns_get_path(struct path *path, struct task_struct *task, |
| 80 | const struct proc_ns_operations *ns_ops); | 80 | const struct proc_ns_operations *ns_ops); |
| 81 | typedef struct ns_common *ns_get_path_helper_t(void *); | ||
| 82 | extern void *ns_get_path_cb(struct path *path, ns_get_path_helper_t ns_get_cb, | ||
| 83 | void *private_data); | ||
| 81 | 84 | ||
| 82 | extern int ns_get_name(char *buf, size_t size, struct task_struct *task, | 85 | extern int ns_get_name(char *buf, size_t size, struct task_struct *task, |
| 83 | const struct proc_ns_operations *ns_ops); | 86 | const struct proc_ns_operations *ns_ops); |
