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>
This commit is contained in:
parent
ad8ad79f4f
commit
cdab6ba866
29
fs/nsfs.c
29
fs/nsfs.c
|
@ -103,14 +103,14 @@ static void *__ns_get_path(struct path *path, struct ns_common *ns)
|
||||||
goto got_it;
|
goto got_it;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *ns_get_path(struct path *path, struct task_struct *task,
|
void *ns_get_path_cb(struct path *path, ns_get_path_helper_t *ns_get_cb,
|
||||||
const struct proc_ns_operations *ns_ops)
|
void *private_data)
|
||||||
{
|
{
|
||||||
struct ns_common *ns;
|
struct ns_common *ns;
|
||||||
void *ret;
|
void *ret;
|
||||||
|
|
||||||
again:
|
again:
|
||||||
ns = ns_ops->get(task);
|
ns = ns_get_cb(private_data);
|
||||||
if (!ns)
|
if (!ns)
|
||||||
return ERR_PTR(-ENOENT);
|
return ERR_PTR(-ENOENT);
|
||||||
|
|
||||||
|
@ -120,6 +120,29 @@ void *ns_get_path(struct path *path, struct task_struct *task,
|
||||||
return ret;
|
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,
|
int open_related_ns(struct ns_common *ns,
|
||||||
struct ns_common *(*get_ns)(struct ns_common *ns))
|
struct ns_common *(*get_ns)(struct ns_common *ns))
|
||||||
{
|
{
|
||||||
|
|
|
@ -78,6 +78,9 @@ extern struct file *proc_ns_fget(int fd);
|
||||||
#define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)
|
#define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)
|
||||||
extern void *ns_get_path(struct path *path, struct task_struct *task,
|
extern void *ns_get_path(struct path *path, struct task_struct *task,
|
||||||
const struct proc_ns_operations *ns_ops);
|
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,
|
extern int ns_get_name(char *buf, size_t size, struct task_struct *task,
|
||||||
const struct proc_ns_operations *ns_ops);
|
const struct proc_ns_operations *ns_ops);
|
||||||
|
|
Loading…
Reference in New Issue