Skip to content

ns: introduce proc_get_ns_by_fd()

Oleg Nesterov containers linux-api lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest1 patch 13 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/1ns: introduce proc_get_ns_by_fd()fs/nsfs.c include/linux/proc_ns.h kernel/pid_namespace.c +1 more+40 -160 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/1] ns: introduce proc_get_ns_by_fd()
Quoted 20 lines · Konstantin Khlebnikov
(quoted diff) +10 -4
+struct ns_common *proc_ns_fdget(int fd, int nstype, struct fd *fd_ref)
 {
-	struct file *file;
+	struct ns_common *ns;
+	struct fd f;
 
-	file = fget(fd);
-	if (!file)
+	f = fdget(fd);
+	if (!f.file)
 		return ERR_PTR(-EBADF);
 
-	if (file->f_op != &ns_file_operations)
+	if (f.file->f_op != &ns_file_operations)
+		goto out_invalid;
+
+	ns = get_proc_ns(file_inode(f.file));
+	if (nstype && (ns->ops->type != nstype))
 		goto out_invalid;

Review

Quoted 10 lines
(quoted diff) +3 -2
 
-	return file;
+	*fd_ref = f;
+	return ns;
 
 out_invalid:
-	fput(file);
+	fdput(f);
 	return ERR_PTR(-EINVAL);
 }

Well yes, fdget() makes sense but this is minor.

Honestly, I do not really like the new helper... I understand this is subjective, so I won't insist. But how about 1/1? We do not need fd/file at all. With this patch your sys_getvpid() can just use proc_get_ns_by_fd(fd, CLONE_NEWPID) and put_pid_ns().

Eric, what do you think?

See also "TODO" in the changelog.

Oleg.