journal: move code that checks for network fs to stat-util.[ch]

We have similar code in stat-util.[ch] and managing this at a central
place almost definitely is the better choice.
This commit is contained in:
Lennart Poettering 2018-02-08 17:14:37 +01:00
parent b8e2400586
commit 77f9fa3b8e
4 changed files with 36 additions and 15 deletions

View File

@ -517,6 +517,10 @@ struct btrfs_ioctl_quota_ctl_args {
#define BPF_FS_MAGIC 0xcafe4a11
#endif
#ifndef OCFS2_SUPER_MAGIC
#define OCFS2_SUPER_MAGIC 0x7461636f
#endif
#ifndef MS_MOVE
#define MS_MOVE 8192
#endif

View File

@ -214,8 +214,19 @@ int path_is_fs_type(const char *path, statfs_f_type_t magic_value) {
}
bool is_temporary_fs(const struct statfs *s) {
return is_fs_type(s, TMPFS_MAGIC) ||
is_fs_type(s, RAMFS_MAGIC);
return is_fs_type(s, TMPFS_MAGIC) ||
is_fs_type(s, RAMFS_MAGIC);
}
bool is_network_fs(const struct statfs *s) {
return is_fs_type(s, CIFS_MAGIC_NUMBER) ||
is_fs_type(s, CODA_SUPER_MAGIC) ||
is_fs_type(s, NCP_SUPER_MAGIC) ||
is_fs_type(s, NFS_SUPER_MAGIC) ||
is_fs_type(s, SMB_SUPER_MAGIC) ||
is_fs_type(s, V9FS_MAGIC) ||
is_fs_type(s, AFS_SUPER_MAGIC) ||
is_fs_type(s, OCFS2_SUPER_MAGIC);
}
int fd_is_temporary_fs(int fd) {
@ -227,15 +238,25 @@ int fd_is_temporary_fs(int fd) {
return is_temporary_fs(&s);
}
int fd_is_network_fs(int fd) {
struct statfs s;
if (fstatfs(fd, &s) < 0)
return -errno;
return is_network_fs(&s);
}
int fd_is_network_ns(int fd) {
int r;
r = fd_is_fs_type(fd, NSFS_MAGIC);
if (r <= 0)
return r;
r = ioctl(fd, NS_GET_NSTYPE);
if (r < 0)
if (ioctl(fd, NS_GET_NSTYPE) < 0)
return -errno;
return r == CLONE_NEWNET;
}

View File

@ -61,8 +61,13 @@ int fd_is_fs_type(int fd, statfs_f_type_t magic_value);
int path_is_fs_type(const char *path, statfs_f_type_t magic_value);
bool is_temporary_fs(const struct statfs *s) _pure_;
bool is_network_fs(const struct statfs *s) _pure_;
int fd_is_temporary_fs(int fd);
int fd_is_network_fs(int fd);
int fd_is_network_ns(int fd);
int path_is_temporary_fs(const char *path);
/* Because statfs.t_type can be int on some architectures, we have to cast

View File

@ -51,6 +51,7 @@
#include "process-util.h"
#include "replace-var.h"
#include "stat-util.h"
#include "stat-util.h"
#include "stdio-util.h"
#include "string-util.h"
#include "strv.h"
@ -1186,22 +1187,12 @@ _public_ int sd_journal_seek_tail(sd_journal *j) {
}
static void check_network(sd_journal *j, int fd) {
struct statfs sfs;
assert(j);
if (j->on_network)
return;
if (fstatfs(fd, &sfs) < 0)
return;
j->on_network =
F_TYPE_EQUAL(sfs.f_type, CIFS_MAGIC_NUMBER) ||
F_TYPE_EQUAL(sfs.f_type, CODA_SUPER_MAGIC) ||
F_TYPE_EQUAL(sfs.f_type, NCP_SUPER_MAGIC) ||
F_TYPE_EQUAL(sfs.f_type, NFS_SUPER_MAGIC) ||
F_TYPE_EQUAL(sfs.f_type, SMB_SUPER_MAGIC);
j->on_network = fd_is_network_fs(fd);
}
static bool file_has_type_prefix(const char *prefix, const char *filename) {