[CRIU] [PATCH 1/2] kerndat: Transform kerndat_get_devpts_stat into general form
Cyrill Gorcunov
gorcunov at openvz.org
Mon Oct 20 10:01:02 PDT 2014
We will need devtmpfs as well so make it general.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
include/kerndat.h | 12 ++++++++++--
kerndat.c | 44 ++++++++++++++++++++++++++++++++------------
mount.c | 2 +-
3 files changed, 43 insertions(+), 15 deletions(-)
diff --git a/include/kerndat.h b/include/kerndat.h
index 6b9947fbddd0..3252cd106b8a 100644
--- a/include/kerndat.h
+++ b/include/kerndat.h
@@ -3,6 +3,8 @@
#include "asm/types.h"
+struct stat;
+
/*
* kerndat stands for "kernel data" and is a collection
* of run-time information about current kernel
@@ -21,7 +23,13 @@ extern int tcp_max_rshare;
extern int kern_last_cap;
extern u64 zero_page_pfn;
-struct stat;
-extern struct stat *kerndat_get_devpts_stat(void);
+enum {
+ KERNDAT_FS_STAT_DEVPTS,
+ KERNDAT_FS_STAT_DEVTMPFS,
+
+ KERNDAT_FS_STAT_MAX
+};
+
+extern struct stat *kerndat_get_fs_stat(unsigned int which);
#endif /* __CR_KERNDAT_H__ */
diff --git a/kerndat.c b/kerndat.c
index 3c87f6ceb34f..05837b9d00b0 100644
--- a/kerndat.c
+++ b/kerndat.c
@@ -53,30 +53,50 @@ static int kerndat_get_shmemdev(void)
return 0;
}
-struct stat *kerndat_get_devpts_stat()
+struct stat *kerndat_get_fs_stat(unsigned int which)
{
- static struct stat st = {};
+ static struct {
+ const char *name;
+ const char *path;
+ unsigned int magic;
+ struct stat st;
+ } kstat[KERNDAT_FS_STAT_MAX] = {
+ [KERNDAT_FS_STAT_DEVPTS] = {
+ .name = "devpts",
+ .path = "/dev/pts",
+ .magic = DEVPTS_SUPER_MAGIC,
+ },
+ [KERNDAT_FS_STAT_DEVTMPFS] = {
+ .name = "devtmpfs",
+ .path = "/dev",
+ .magic = TMPFS_MAGIC,
+ },
+ };
struct statfs fst;
- if (st.st_dev != 0)
- return &st;
+ if (which >= KERNDAT_FS_STAT_MAX) {
+ pr_err("Wrong fs type %u passed\n", which);
+ return NULL;
+ }
+
+ if (kstat[which].st.st_dev != 0)
+ return &kstat[which].st;
- if (statfs("/dev/pts", &fst)) {
- pr_perror("Unable to statefs /dev/pts");
+ if (statfs(kstat[which].path, &fst)) {
+ pr_perror("Unable to statefs %s", kstat[which].path);
return NULL;
}
- if (fst.f_type != DEVPTS_SUPER_MAGIC) {
- pr_err("devpts isn't mount on the host\n");
+ if (fst.f_type != kstat[which].magic) {
+ pr_err("%s isn't mount on the host\n", kstat[which].name);
return NULL;
}
- /* The root /dev/pts is mounted w/o newinstance, isn't it? */
- if (stat("/dev/pts", &st)) {
- pr_perror("Unable to stat /dev/pts");
+ if (stat(kstat[which].path, &kstat[which].st)) {
+ pr_perror("Unable to stat %s", kstat[which].path);
return NULL;
}
- return &st;
+ return &kstat[which].st;
}
/*
diff --git a/mount.c b/mount.c
index a60c86e0f97b..108ab07bd8b6 100644
--- a/mount.c
+++ b/mount.c
@@ -678,7 +678,7 @@ static int devpts_parse(struct mount_info *pm)
{
struct stat *host_st;
- host_st = kerndat_get_devpts_stat();
+ host_st = kerndat_get_fs_stat(KERNDAT_FS_STAT_DEVPTS);
if (host_st == NULL)
return -1;
--
1.9.3
More information about the CRIU
mailing list