mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-18 00:58:31 +00:00
kerndat: Transform kerndat_get_devpts_stat into general form
We will need devtmpfs as well so make it general. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
eb214be2d0
commit
48d81eb48a
3 changed files with 46 additions and 18 deletions
|
|
@ -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,8 +23,14 @@ 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);
|
||||
|
||||
extern bool memfd_is_supported;
|
||||
|
||||
|
|
|
|||
50
kerndat.c
50
kerndat.c
|
|
@ -54,30 +54,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 (statfs("/dev/pts", &fst)) {
|
||||
pr_perror("Unable to statefs /dev/pts");
|
||||
return NULL;
|
||||
}
|
||||
if (fst.f_type != DEVPTS_SUPER_MAGIC) {
|
||||
pr_err("devpts isn't mount on the host\n");
|
||||
if (which >= KERNDAT_FS_STAT_MAX) {
|
||||
pr_err("Wrong fs type %u passed\n", which);
|
||||
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 (kstat[which].st.st_dev != 0)
|
||||
return &kstat[which].st;
|
||||
|
||||
if (statfs(kstat[which].path, &fst)) {
|
||||
pr_perror("Unable to statefs %s", kstat[which].path);
|
||||
return NULL;
|
||||
}
|
||||
if (fst.f_type != kstat[which].magic) {
|
||||
pr_err("%s isn't mount on the host\n", kstat[which].name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &st;
|
||||
if (stat(kstat[which].path, &kstat[which].st)) {
|
||||
pr_perror("Unable to stat %s", kstat[which].path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &kstat[which].st;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
2
mount.c
2
mount.c
|
|
@ -686,7 +686,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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue