]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: move code that checks for network fs to stat-util.[ch]
authorLennart Poettering <lennart@poettering.net>
Thu, 8 Feb 2018 16:14:37 +0000 (17:14 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 12 Feb 2018 10:07:55 +0000 (11:07 +0100)
We have similar code in stat-util.[ch] and managing this at a central
place almost definitely is the better choice.

src/basic/missing.h
src/basic/stat-util.c
src/basic/stat-util.h
src/journal/sd-journal.c

index 9d4d08e7a9f0c5cb41e3451737efa763ea3d639d..327e6ea67f883fec6ed68f7365fb960b412271dc 100644 (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
index 3a54103f1beb46bbbf7d565509d2962e5fa6ba17..0fb6750a0750ebdc379aae0082e0ca519303a5d0 100644 (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;
 }
 
index d8d3c204960921e006a9cf9c8130fc2ea7394aca..da33e68db251338d9ace9b1667573460157c3a6c 100644 (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
index a8812c9af83c0f4710f5dab33788ee8bb1c67457..46e2b47344b2eceaafe04cdeeaa073a6a40490ba 100644 (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) {