namespaces: use fstatat instead of readlink to get a namespace kernel id

Submitted by Andrei Vagin on July 30, 2016, 3:34 a.m.

Details

Message ID 1469849681-11642-1-git-send-email-avagin@openvz.org
State Rejected
Series "namespaces: use fstatat instead of readlink to get a namespace kernel id"
Headers show

Commit Message

Andrei Vagin July 30, 2016, 3:34 a.m.
From: Andrew Vagin <avagin@virtuozzo.com>

It should be faster and we don't need to parse a string.

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
---
 criu/namespaces.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/namespaces.c b/criu/namespaces.c
index 47bb861..9be4e6f 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -428,28 +428,27 @@  found:
 
 static unsigned int __get_ns_id(int pid, struct ns_desc *nd, protobuf_c_boolean *supported, struct ns_id **ns)
 {
-	int proc_dir, ret;
+	int proc_dir;
 	unsigned int kid;
-	char ns_path[10], ns_id[32];
+	char ns_path[10];
+	struct stat st;
 
 	proc_dir = open_pid_proc(pid);
 	if (proc_dir < 0)
 		return 0;
 
 	sprintf(ns_path, "ns/%s", nd->str);
-	ret = readlinkat(proc_dir, ns_path, ns_id, sizeof(ns_id) - 1);
-	if (ret < 0) {
+
+	if (fstatat(proc_dir, ns_path, &st, 0)) {
 		if (errno == ENOENT) {
 			/* The namespace is unsupported */
 			kid = 0;
 			goto out;
 		}
-		pr_perror("Can't readlink ns link");
-		return 0;
+		pr_perror("Unable to stat %s", ns_path);
+		return -1;
 	}
-	ns_id[ret] = '\0';
-
-	kid = parse_ns_link(ns_id, ret, nd);
+	kid = st.st_ino;
 	BUG_ON(!kid);
 
 out:

Comments

Cyrill Gorcunov July 30, 2016, 9:32 a.m.
On Sat, Jul 30, 2016 at 06:34:41AM +0300, Andrey Vagin wrote:
> From: Andrew Vagin <avagin@virtuozzo.com>
> 
> It should be faster and we don't need to parse a string.
> 
> Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Pavel Emelianov Aug. 4, 2016, 1:50 p.m.
Applied