[CRIU] [PATCH RFC 1/2] mount: fs type helpers introduced
Stanislav Kinsburskiy
skinsbursky at virtuozzo.com
Wed Feb 24 02:54:51 PST 2016
This helpers just hide statfs syscall, which is used only for one purpose: get
file system magic number.
Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
---
files.c | 10 ++++------
include/mount.h | 3 +++
kerndat.c | 8 +++-----
mount.c | 33 ++++++++++++++++++++++++++++-----
4 files changed, 38 insertions(+), 16 deletions(-)
diff --git a/files.c b/files.c
index f605a51..3a96985 100644
--- a/files.c
+++ b/files.c
@@ -269,7 +269,7 @@ static int fill_fd_params(struct parasite_ctl *ctl, int fd, int lfd,
struct fd_opts *opts, struct fd_parms *p)
{
int ret;
- struct statfs fsbuf;
+ unsigned int fs_type;
struct fdinfo_common fdinfo = { .mnt_id = -1, .owner = ctl->pid.virt };
if (fstat(lfd, &p->stat) < 0) {
@@ -277,15 +277,13 @@ static int fill_fd_params(struct parasite_ctl *ctl, int fd, int lfd,
return -1;
}
- if (fstatfs(lfd, &fsbuf) < 0) {
- pr_perror("Can't statfs fd %d", lfd);
+ if (parse_fdinfo_pid(ctl->pid.real, fd, FD_TYPES__UND, NULL, &fdinfo))
return -1;
- }
- if (parse_fdinfo_pid(ctl->pid.real, fd, FD_TYPES__UND, NULL, &fdinfo))
+ if (get_fstype_by_fd(lfd, &fs_type))
return -1;
- p->fs_type = fsbuf.f_type;
+ p->fs_type = fs_type;
p->ctl = ctl;
p->fd = fd;
p->pos = fdinfo.pos;
diff --git a/include/mount.h b/include/mount.h
index b3bbdce..4989b41 100644
--- a/include/mount.h
+++ b/include/mount.h
@@ -126,4 +126,7 @@ extern int mntns_maybe_create_roots(void);
extern int read_mnt_ns_img(void);
extern void cleanup_mnt_ns(void);
+extern int get_fstype_by_fd(int fd, unsigned int *type);
+extern int get_fstype_by_path(const char *path, unsigned int *type);
+
#endif /* __CR_MOUNT_H__ */
diff --git a/kerndat.c b/kerndat.c
index 696701d..af84902 100644
--- a/kerndat.c
+++ b/kerndat.c
@@ -198,13 +198,11 @@ static dev_t get_host_dev(unsigned int which)
}
if (kstat[which].fs_dev == 0) {
- struct statfs fst;
+ unsigned int fs_type;
struct stat st;
- if (statfs(kstat[which].path, &fst)) {
- pr_perror("Unable to statefs %s", kstat[which].path);
+ if (get_fstype_by_path(kstat[which].path, &fs_type))
return 0;
- }
/*
* XXX: If the fs we need is not there, it still
@@ -212,7 +210,7 @@ static dev_t get_host_dev(unsigned int which)
* mounted on the host.
*/
- if (fst.f_type != kstat[which].magic) {
+ if (fs_type != kstat[which].magic) {
pr_err("%s isn't mount on the host\n", kstat[which].name);
return 0;
}
diff --git a/mount.c b/mount.c
index 747488b..f5d8773 100644
--- a/mount.c
+++ b/mount.c
@@ -213,6 +213,30 @@ struct mount_info *lookup_mnt_id(unsigned int id)
return __lookup_mnt_id(mntinfo, id);
}
+int get_fstype_by_fd(int fd, unsigned int *type)
+{
+ struct statfs fst;
+
+ if (fstatfs(fd, &fst)) {
+ pr_perror("Unable to statfs fd %d", fd);
+ return -errno;
+ }
+ *type = fst.f_type;
+ return 0;
+}
+
+int get_fstype_by_path(const char *path, unsigned int *type)
+{
+ struct statfs fst;
+
+ if (statfs(path, &fst)) {
+ pr_perror("Unable to statfs %s", path);
+ return -errno;
+ }
+ *type = fst.f_type;
+ return 0;
+}
+
struct mount_info *lookup_mnt_sdev(unsigned int s_dev)
{
struct mount_info *m;
@@ -2607,13 +2631,12 @@ static int do_mount_one(struct mount_info *mi)
return -1;
if (mi->fstype->code == FSTYPE__UNSUPPORTED) {
- struct statfs st;
+ unsigned int fs_type;
- if (statfs(mi->mountpoint, &st)) {
- pr_perror("Unable to statfs %s", mi->mountpoint);
+ if (get_fstype_by_path(mi->mountpoint, &fs_type))
return -1;
- }
- if (st.f_type == BTRFS_SUPER_MAGIC)
+
+ if (fstype == BTRFS_SUPER_MAGIC)
mi->fstype = find_fstype_by_name("btrfs");
}
More information about the CRIU
mailing list