[CRIU] [PATCH 3/6] Add mount.c file for mount helpers functions

Cyrill Gorcunov gorcunov at openvz.org
Tue Apr 17 09:22:28 EDT 2012


At moment only open_mnt_root is there, which is
needed for inotify restore.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 Makefile        |    1 +
 include/mount.h |    8 ++++++++
 mount.c         |   42 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 0 deletions(-)
 create mode 100644 include/mount.h
 create mode 100644 mount.c

diff --git a/Makefile b/Makefile
index 019623e..652c71a 100644
--- a/Makefile
+++ b/Makefile
@@ -48,6 +48,7 @@ OBJS		+= file-ids.o
 OBJS		+= namespaces.o
 OBJS		+= uts_ns.o
 OBJS		+= ipc_ns.o
+OBJS		+= mount.o
 
 OBJS-BLOB	+= parasite.o
 SRCS-BLOB	+= $(patsubst %.o,%.c,$(OBJS-BLOB))
diff --git a/include/mount.h b/include/mount.h
new file mode 100644
index 0000000..608c448
--- /dev/null
+++ b/include/mount.h
@@ -0,0 +1,8 @@
+#ifndef MOUNT_H__
+#define MOUNT_H__
+
+struct proc_mountinfo;
+
+extern int open_mnt_root(unsigned int s_dev, struct proc_mountinfo *mntinfo, int nr_mntinfo);
+
+#endif /* MOUNT_H__ */
diff --git a/mount.c b/mount.c
new file mode 100644
index 0000000..3db7d34
--- /dev/null
+++ b/mount.c
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <string.h>
+
+#include "types.h"
+#include "util.h"
+#include "mount.h"
+#include "proc_parse.h"
+
+/*
+ * Returns path for mount device @s_dev
+ *
+ * FIXME this is not sufficient in general
+ * since mount points can be overmounted but
+ * works for now.
+ */
+int open_mnt_root(unsigned int s_dev, struct proc_mountinfo *mntinfo, int nr_mntinfo)
+{
+	static int last = 0;
+	int i;
+
+again:
+	for (i = last; i < nr_mntinfo; i++) {
+		if (s_dev == mntinfo[i].s_dev) {
+			last = i;
+			return open(mntinfo[i].mnt_root, O_RDONLY);
+		}
+	}
+
+	if (last) {
+		last = 0;
+		goto again;
+	}
+
+	return -ENOENT;
+}
-- 
1.7.7.6



More information about the CRIU mailing list