summaryrefslogtreecommitdiff
path: root/src/journal
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-10-26 20:05:19 +0200
committerLennart Poettering <lennart@poettering.net>2012-10-26 20:07:33 +0200
commit85210bffd8363e491b4c31f2d09404f9869ad0c7 (patch)
tree8afc2d12f00925280a63dac7ef6e1eeeeb90edd7 /src/journal
parente9f600f2fb4b0df55c7a8fb4b4d09f9979997223 (diff)
journal: provide an API that allows client to figure out whether they need to recheck the journal manually for changes in regular intervals
Network file systems generally do not offer inotify() that would work across the network. We hence cannot rely on inotify() exclusiely in those case. Provide an API to determine these cases, and suggest doing manual regular rechecks. Note that this is not complete yet, as we need to rescan journal dirs on network file systems explicitly to find new/removed files
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/journal-internal.h2
-rw-r--r--src/journal/libsystemd-journal.sym5
-rw-r--r--src/journal/sd-journal.c45
3 files changed, 52 insertions, 0 deletions
diff --git a/src/journal/journal-internal.h b/src/journal/journal-internal.h
index f68ca996a8..75a4129e5b 100644
--- a/src/journal/journal-internal.h
+++ b/src/journal/journal-internal.h
@@ -119,6 +119,8 @@ struct sd_journal {
char *unique_field;
JournalFile *unique_file;
uint64_t unique_offset;
+
+ bool on_network;
};
char *journal_make_match_string(sd_journal *j);
diff --git a/src/journal/libsystemd-journal.sym b/src/journal/libsystemd-journal.sym
index 96293b8a29..ad78fcc74d 100644
--- a/src/journal/libsystemd-journal.sym
+++ b/src/journal/libsystemd-journal.sym
@@ -80,3 +80,8 @@ global:
sd_journal_enumerate_unique;
sd_journal_restart_unique;
} LIBSYSTEMD_JOURNAL_190;
+
+LIBSYSTEMD_JOURNAL_196 {
+global:
+ sd_journal_fd_reliable;
+} LIBSYSTEMD_JOURNAL_195;
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index d5d2d78f1c..a346691e21 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -25,6 +25,8 @@
#include <unistd.h>
#include <sys/inotify.h>
#include <sys/poll.h>
+#include <sys/vfs.h>
+#include <linux/magic.h>
#include "sd-journal.h"
#include "journal-def.h"
@@ -35,9 +37,12 @@
#include "lookup3.h"
#include "compress.h"
#include "journal-internal.h"
+#include "missing.h"
#define JOURNAL_FILES_MAX 1024
+#define JOURNAL_FILES_RECHECK_USEC (2 * USEC_PER_SEC)
+
static void detach_location(sd_journal *j) {
Iterator i;
JournalFile *f;
@@ -1184,6 +1189,25 @@ _public_ int sd_journal_seek_tail(sd_journal *j) {
return 0;
}
+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 =
+ sfs.f_type == CIFS_MAGIC_NUMBER ||
+ sfs.f_type == CODA_SUPER_MAGIC ||
+ sfs.f_type == NCP_SUPER_MAGIC ||
+ sfs.f_type == NFS_SUPER_MAGIC ||
+ sfs.f_type == SMB_SUPER_MAGIC;
+}
+
static int add_file(sd_journal *j, const char *prefix, const char *filename) {
char *path;
int r;
@@ -1233,6 +1257,8 @@ static int add_file(sd_journal *j, const char *prefix, const char *filename) {
return r;
}
+ check_network(j, f->fd);
+
j->current_invalidate_counter ++;
log_debug("File %s got added.", f->path);
@@ -1366,6 +1392,8 @@ static int add_directory(sd_journal *j, const char *prefix, const char *dirname)
}
}
+ check_network(j, dirfd(d));
+
closedir(d);
return 0;
@@ -1453,6 +1481,8 @@ static int add_root_directory(sd_journal *j, const char *p) {
}
}
+ check_network(j, dirfd(d));
+
closedir(d);
return 0;
@@ -2079,6 +2109,14 @@ _public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) {
return determine_change(j);
}
+ if (j->on_network) {
+ /* If we are on the network we need to regularly check
+ * for changes manually */
+
+ if (timeout_usec == (uint64_t) -1 || timeout_usec > JOURNAL_FILES_RECHECK_USEC)
+ timeout_usec = JOURNAL_FILES_RECHECK_USEC;
+ }
+
do {
r = fd_wait_for_event(j->inotify_fd, POLLIN, timeout_usec);
} while (r == -EINTR);
@@ -2344,3 +2382,10 @@ _public_ void sd_journal_restart_unique(sd_journal *j) {
j->unique_file = NULL;
j->unique_offset = 0;
}
+
+_public_ int sd_journal_reliable_fd(sd_journal *j) {
+ if (!j)
+ return -EINVAL;
+
+ return !j->on_network;
+}