Commit 48d81eb4 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

kerndat: Transform kerndat_get_devpts_stat into general form

We will need devtmpfs as well so make it general.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent eb214be2
......@@ -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;
......
......@@ -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 (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;
}
/*
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment