[CRIU] [PATCH 1/2] proc: Add parse_mountinfo helper
Cyrill Gorcunov
gorcunov at openvz.org
Mon Apr 9 09:28:28 EDT 2012
Need it for inotify restore (to lookup
mount points).
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
include/proc_parse.h | 8 ++++++++
include/util.h | 1 +
proc_parse.c | 42 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/include/proc_parse.h b/include/proc_parse.h
index 14608f7..1d1e107 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -83,6 +83,14 @@ struct proc_status_creds {
unsigned int cap_bnd[PROC_CAP_SIZE];
};
+struct proc_mountinfo {
+ int mnt_id;
+ int parent_mnt_id;
+ unsigned int s_dev;
+ char mnt_root[64];
+};
+
+extern int parse_mountinfo(pid_t pid, struct proc_mountinfo *mi, int nr_elems);
extern int parse_pid_stat(pid_t pid, struct proc_pid_stat *s);
extern int parse_pid_stat_small(pid_t pid, struct proc_pid_stat_small *s);
extern int parse_maps(pid_t pid, struct list_head *vma_area_list, bool use_map_files);
diff --git a/include/util.h b/include/util.h
index e4c80bc..e5ae7ab 100644
--- a/include/util.h
+++ b/include/util.h
@@ -256,6 +256,7 @@ int do_open_proc(pid_t pid, int flags, const char *fmt, ...);
#define KDEV_MINORBITS 20
#define KDEV_MINORMASK ((1UL << KDEV_MINORBITS) - 1)
+#define MKKDEV(ma,mi) (((ma) << KDEV_MINORBITS) | (mi))
static inline u32 kdev_major(u32 kdev)
{
diff --git a/proc_parse.c b/proc_parse.c
index f416567..06a489f 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -389,3 +389,45 @@ err_parse:
fclose(f);
return 0;
}
+
+int parse_mountinfo(pid_t pid, struct proc_mountinfo *mi, int nr_elems)
+{
+ FILE *f;
+ char str[256];
+ int i = 0;
+
+ f = fopen_proc(pid, "mountinfo");
+ if (f == NULL) {
+ pr_perror("Can't open %d mountinfo", pid);
+ return -1;
+ }
+
+ while (fgets(str, sizeof(str), f)) {
+ unsigned int kmaj, kmin, parent_mnt_id;
+ char parent_mnt_root[63];
+ int ret;
+
+ if ((i + 1) >= nr_elems) {
+ i = -ENOMEM;
+ goto out_close;
+ }
+
+ ret = sscanf(str, "%i %i %u:%u %63s %63s",
+ &mi[i].mnt_id, &parent_mnt_id,
+ &kmaj, &kmin, parent_mnt_root,
+ mi[i].mnt_root);
+ if (ret != 6) {
+ pr_err("Bad format in %d mountinfo\n", pid);
+ i = -1;
+ goto out_close;
+ }
+
+ mi[i].s_dev = MKKDEV(kmaj, kmin);
+ i++;
+ }
+
+out_close:
+ fclose(f);
+out:
+ return i;
+}
--
1.7.7.6
More information about the CRIU
mailing list