[CRIU] [PATCH 2/4] kerndat: Make fs-virtualized check report yes/no
Pavel Emelyanov
xemul at parallels.com
Sun Nov 9 22:47:56 PST 2014
Right now it returns the whole struct stat which is excessive.
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
include/kerndat.h | 8 +++++++-
kerndat.c | 13 ++++++++++++-
mount.c | 26 ++++++++++----------------
3 files changed, 29 insertions(+), 18 deletions(-)
diff --git a/include/kerndat.h b/include/kerndat.h
index cfd6639..1f511cf 100644
--- a/include/kerndat.h
+++ b/include/kerndat.h
@@ -33,6 +33,12 @@ enum {
KERNDAT_FS_STAT_MAX
};
-extern struct stat *kerndat_get_fs_stat(unsigned int which);
+/*
+ * Check whether the fs @which with kdevice @kdev
+ * is the same as host's. If yes, this means that
+ * the fs mount is shared with host, if no -- it's
+ * a new (likely virtuzlized) fs instance.
+ */
+extern int kerndat_fs_virtualized(unsigned int which, u32 kdev);
#endif /* __CR_KERNDAT_H__ */
diff --git a/kerndat.c b/kerndat.c
index 4612ce9..d6f3921 100644
--- a/kerndat.c
+++ b/kerndat.c
@@ -57,7 +57,7 @@ static int kerndat_get_shmemdev(void)
return 0;
}
-struct stat *kerndat_get_fs_stat(unsigned int which)
+static struct stat *kerndat_get_fs_stat(unsigned int which)
{
static struct {
const char *name;
@@ -103,6 +103,17 @@ struct stat *kerndat_get_fs_stat(unsigned int which)
return &kstat[which].st;
}
+int kerndat_fs_virtualized(unsigned int which, u32 kdev)
+{
+ struct stat *host_fs_stat;
+
+ host_fs_stat = kerndat_get_fs_stat(which);
+ if (host_fs_stat == NULL)
+ return -1;
+
+ return (kdev_to_odev(kdev) == host_fs_stat->st_dev) ? 0 : 1;
+}
+
/*
* Check whether pagemap reports soft dirty bit. Kernel has
* this functionality under CONFIG_MEM_SOFT_DIRTY option.
diff --git a/mount.c b/mount.c
index fac1b35..c8ba2fd 100644
--- a/mount.c
+++ b/mount.c
@@ -690,15 +690,17 @@ static int attach_option(struct mount_info *pm, char *opt)
/* Is it mounted w or w/o the newinstance option */
static int devpts_parse(struct mount_info *pm)
{
- struct stat *host_st;
-
- host_st = kerndat_get_fs_stat(KERNDAT_FS_STAT_DEVPTS);
- if (host_st == NULL)
- return -1;
+ int ret;
- if (host_st->st_dev == kdev_to_odev(pm->s_dev))
- return 0;
+ ret = kerndat_fs_virtualized(KERNDAT_FS_STAT_DEVPTS, pm->s_dev);
+ if (ret <= 0)
+ return ret;
+ /*
+ * Kernel hides this option, but if the fs instance
+ * is new (virtualized) we know that it was created
+ * with -o newinstance.
+ */
return attach_option(pm, "newinstance");
}
@@ -745,15 +747,7 @@ out:
static bool rt_detmpfs_match(struct mount_info *pm)
{
- struct stat *host_st;
-
- host_st = kerndat_get_fs_stat(KERNDAT_FS_STAT_DEVTMPFS);
- if (host_st) {
- if (host_st->st_dev == kdev_to_odev(pm->s_dev))
- return true;
- }
-
- return false;
+ return kerndat_fs_virtualized(KERNDAT_FS_STAT_DEVTMPFS, pm->s_dev) == 0;
}
static int devtmpfs_dump(struct mount_info *pm)
--
1.8.4.2
More information about the CRIU
mailing list