On 09/24, Konstantin Khlebnikov wrote: > > On Thu, Sep 24, 2015 at 5:56 PM, Oleg Nesterov <oleg@xxxxxxxxxx> wrote: > > On 09/24, Konstantin Khlebnikov wrote: > >> > >> +SYSCALL_DEFINE3(getvpid, pid_t, pid, int, source, int, target) > >> +{ > >> + struct file *source_file = NULL, *target_file = NULL; > >> + struct pid_namespace *source_ns, *target_ns; > >> + struct pid *struct_pid; > >> + struct ns_common *ns; > >> + pid_t result; > >> + > >> + if (source >= 0) { > >> + source_file = proc_ns_fget(source); > >> + result = PTR_ERR(source_file); > >> + if (IS_ERR(source_file)) > >> + goto out; > >> + ns = get_proc_ns(file_inode(source_file)); > >> + result = -EINVAL; > >> + if (ns->ops->type != CLONE_NEWPID) > >> + goto out; > >> + source_ns = container_of(ns, struct pid_namespace, ns); > >> + } else > >> + source_ns = task_active_pid_ns(current); > >> + > >> + if (target >= 0) { > >> + target_file = proc_ns_fget(target); > >> + result = PTR_ERR(target_file); > >> + if (IS_ERR(target_file)) > >> + goto out; > >> + ns = get_proc_ns(file_inode(target_file)); > >> + result = -EINVAL; > >> + if (ns->ops->type != CLONE_NEWPID) > >> + goto out; > >> + target_ns = container_of(ns, struct pid_namespace, ns); > >> + } else > >> + target_ns = task_active_pid_ns(current); > >> + > > > > Hmm. Eric, Konstantin, how about (uncompiled/untested) patch below > > in a preparation? The code above doesn't look very readable. > > I've tried to do something like that but that comes too far so send patch as is. OK, I won't insist. The code above asks for cleanup/factorization, but we can do this later. > Actually we can go deeper and replace struct file* with struct fd: this saves > couple atomic ops for singlethreaded task. it's not about performance... But yes, we can do more and create get_pid_ns_by_fd() similar to get_net_ns_by_fd(). We do not need file at all, we need pid_ns. Oleg. -- To unsubscribe from this list: send the line "unsubscribe linux-api" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html