[systemd-commits] 3 commits - Makefile.am TODO man/journalctl.xml man/journald.conf.xml man/sd-journal.xml man/sd_journal_get_usage.xml src/core src/journal src/systemd

Lennart Poettering lennart at kemper.freedesktop.org
Fri Sep 7 16:41:59 PDT 2012


 Makefile.am                        |    1 
 TODO                               |    2 
 man/journalctl.xml                 |    8 ++
 man/journald.conf.xml              |   30 ++++++++++
 man/sd-journal.xml                 |    4 +
 man/sd_journal_get_usage.xml       |  104 +++++++++++++++++++++++++++++++++++++
 src/core/main.c                    |    2 
 src/journal/journal-file.c         |    5 +
 src/journal/journalctl.c           |   25 ++++++++
 src/journal/journald-gperf.gperf   |    1 
 src/journal/journald.c             |   14 ++++
 src/journal/journald.conf          |    1 
 src/journal/journald.h             |   14 ++++
 src/journal/libsystemd-journal.sym |    5 +
 src/journal/sd-journal.c           |   23 ++++++++
 src/systemd/sd-journal.h           |    2 
 16 files changed, 234 insertions(+), 7 deletions(-)

New commits:
commit 182b858fc2e61e34cd9911c291580659b2cb72b4
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 7 23:40:00 2012 +0200

    journald: make splitting up of journal files per-user configurable

diff --git a/man/journald.conf.xml b/man/journald.conf.xml
index 2fa475c..942560c 100644
--- a/man/journald.conf.xml
+++ b/man/journald.conf.xml
@@ -136,6 +136,36 @@
                         </varlistentry>
 
                         <varlistentry>
+                                <term><varname>SplitMode=</varname></term>
+
+                                <listitem><para>Controls whether to
+                                split up journal files per user. One
+                                of <literal>login</literal>,
+                                <literal>uid</literal> and
+                                <literal>none</literal>. If
+                                <literal>login</literal> each logged
+                                in user will get his own journal
+                                files, but systemd user IDs will log
+                                into the system journal. If
+                                <literal>uid</literal> any user ID
+                                will get his own journal files
+                                regardless whether it belongs to a
+                                system service or refers to a real
+                                logged in user. If
+                                <literal>none</literal> journal files
+                                are not split up per-user and all
+                                messages are stored in the single
+                                system journal. Note that splitting
+                                up journal files per-user is only
+                                available of journals are stored
+                                persistently. If journals are stored
+                                on volatile storage (see above) only a
+                                single journal file for all user IDs
+                                is kept. Defaults to
+                                <literal>login</literal>.</para></listitem>
+                        </varlistentry>
+
+                        <varlistentry>
                                 <term><varname>RateLimitInterval=</varname></term>
                                 <term><varname>RateLimitBurst=</varname></term>
 
diff --git a/src/journal/journald-gperf.gperf b/src/journal/journald-gperf.gperf
index 32474df..4c021ed 100644
--- a/src/journal/journald-gperf.gperf
+++ b/src/journal/journald-gperf.gperf
@@ -36,3 +36,4 @@ Journal.MaxLevelStore,      config_parse_level,     0, offsetof(Server, max_leve
 Journal.MaxLevelSyslog,     config_parse_level,     0, offsetof(Server, max_level_syslog)
 Journal.MaxLevelKMsg,       config_parse_level,     0, offsetof(Server, max_level_kmsg)
 Journal.MaxLevelConsole,    config_parse_level,     0, offsetof(Server, max_level_console)
+Journal.SplitMode,          config_parse_split_mode,0, offsetof(Server, split_mode)
diff --git a/src/journal/journald.c b/src/journal/journald.c
index 5d0d203..a316771 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -87,6 +87,15 @@ static const char* const storage_table[] = {
 DEFINE_STRING_TABLE_LOOKUP(storage, Storage);
 DEFINE_CONFIG_PARSE_ENUM(config_parse_storage, storage, Storage, "Failed to parse storage setting");
 
+static const char* const split_mode_table[] = {
+        [SPLIT_NONE] = "none",
+        [SPLIT_UID] = "uid",
+        [SPLIT_LOGIN] = "login"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(split_mode, SplitMode);
+DEFINE_CONFIG_PARSE_ENUM(config_parse_split_mode, split_mode, SplitMode, "Failed to parse split mode setting");
+
 static uint64_t available_space(Server *s) {
         char ids[33], *p;
         const char *f;
@@ -659,7 +668,10 @@ static void dispatch_message_real(
 
         assert(n <= m);
 
-        write_to_journal(s, realuid == 0 ? 0 : loginuid, iovec, n);
+        write_to_journal(s,
+                         s->split_mode == SPLIT_NONE ? 0 :
+                         (s->split_mode == SPLIT_UID ? realuid :
+                          (realuid == 0 ? 0 : loginuid)), iovec, n);
 
         free(pid);
         free(uid);
diff --git a/src/journal/journald.conf b/src/journal/journald.conf
index 677f48b..e5f3b76 100644
--- a/src/journal/journald.conf
+++ b/src/journal/journald.conf
@@ -11,6 +11,7 @@
 #Storage=auto
 #Compress=yes
 #Seal=yes
+#SplitMode=login
 #RateLimitInterval=10s
 #RateLimitBurst=200
 #SystemMaxUse=
diff --git a/src/journal/journald.h b/src/journal/journald.h
index 7f621ae..c126d19 100644
--- a/src/journal/journald.h
+++ b/src/journal/journald.h
@@ -41,6 +41,14 @@ typedef enum Storage {
         _STORAGE_INVALID = -1
 } Storage;
 
+typedef enum SplitMode {
+        SPLIT_LOGIN,
+        SPLIT_UID,
+        SPLIT_NONE,
+        _SPLIT_MAX,
+        _SPLIT_INVALID = -1
+} SplitMode;
+
 typedef struct StdoutStream StdoutStream;
 
 typedef struct Server {
@@ -93,6 +101,7 @@ typedef struct Server {
         int max_level_console;
 
         Storage storage;
+        SplitMode split_mode;
 
         MMapCache *mmap;
 
@@ -117,3 +126,8 @@ int config_parse_storage(const char *filename, unsigned line, const char *sectio
 
 const char *storage_to_string(Storage s);
 Storage storage_from_string(const char *s);
+
+int config_parse_split_mode(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
+
+const char *split_mode_to_string(SplitMode s);
+SplitMode split_mode_from_string(const char *s);

commit a1a03e3075316e2376176fc54c74e071adc9d71a
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 7 23:20:28 2012 +0200

    journal: add call to determine current journal file disk usage

diff --git a/Makefile.am b/Makefile.am
index f88d193..7ccec67 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -513,6 +513,7 @@ MANPAGES = \
 	man/sd_journal_get_cutoff_realtime_usec.3 \
 	man/sd_journal_get_cursor.3 \
 	man/sd_journal_get_fd.3 \
+	man/sd_journal_get_usage.3 \
 	man/sd_journal_add_match.3 \
 	man/sd_journal_seek_head.3
 
diff --git a/TODO b/TODO
index 30e2f8e..de7639e 100644
--- a/TODO
+++ b/TODO
@@ -126,8 +126,6 @@ Features:
 
 * add _SYSTEMD_USER_UNIT= field to journal entries
 
-* journal: expose current disk usage
-
 * dracut-shutdown needs to be ordered before unmounting /boot
 
 * wiki: document new logind LockSessions() call
diff --git a/man/journalctl.xml b/man/journalctl.xml
index 296e3fd..9800cf3 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -321,6 +321,14 @@
                         </varlistentry>
 
                         <varlistentry>
+                                <term><option>--disk-usage</option></term>
+
+                                <listitem><para>Shows the current disk
+                                usage of all
+                                journal files.</para></listitem>
+                        </varlistentry>
+
+                        <varlistentry>
                                 <term><option>--setup-keys</option></term>
 
                                 <listitem><para>Instead of showing
diff --git a/man/sd-journal.xml b/man/sd-journal.xml
index b6241a1..773689c 100644
--- a/man/sd-journal.xml
+++ b/man/sd-journal.xml
@@ -78,7 +78,8 @@
                 <citerefentry><refentrytitle>sd_journal_add_match</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
                 <citerefentry><refentrytitle>sd_journal_seek_head</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
                 <citerefentry><refentrytitle>sd_journal_get_cursor</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
-                <citerefentry><refentrytitle>sd_journal_cutoff_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>
+                <citerefentry><refentrytitle>sd_journal_cutoff_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+                <citerefentry><refentrytitle>sd_journal_get_usage</refentrytitle><manvolnum>3</manvolnum></citerefentry>
                 and
                 <citerefentry><refentrytitle>sd_journal_get_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>
                 for more information about the functions
@@ -116,6 +117,7 @@
                         <citerefentry><refentrytitle>sd_journal_seek_head</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
                         <citerefentry><refentrytitle>sd_journal_get_cursor</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
                         <citerefentry><refentrytitle>sd_journal_cutoff_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>sd_journal_get_usage</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
                         <citerefentry><refentrytitle>journalctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
                         <citerefentry><refentrytitle>sd-id128</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
                         <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
diff --git a/man/sd_journal_get_usage.xml b/man/sd_journal_get_usage.xml
new file mode 100644
index 0000000..14eb1e2
--- /dev/null
+++ b/man/sd_journal_get_usage.xml
@@ -0,0 +1,104 @@
+<?xml version='1.0'?> <!--*-nxml-*-->
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
+        "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+
+<!--
+  This file is part of systemd.
+
+  Copyright 2012 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+-->
+
+<refentry id="sd_journal_get_usage">
+
+        <refentryinfo>
+                <title>sd_journal_get_usage</title>
+                <productname>systemd</productname>
+
+                <authorgroup>
+                        <author>
+                                <contrib>Developer</contrib>
+                                <firstname>Lennart</firstname>
+                                <surname>Poettering</surname>
+                                <email>lennart at poettering.net</email>
+                        </author>
+                </authorgroup>
+        </refentryinfo>
+
+        <refmeta>
+                <refentrytitle>sd_journal_get_usage</refentrytitle>
+                <manvolnum>3</manvolnum>
+        </refmeta>
+
+        <refnamediv>
+                <refname>sd_journal_get_usage</refname>
+                <refpurpose>Journal disk usage</refpurpose>
+        </refnamediv>
+
+        <refsynopsisdiv>
+                <funcsynopsis>
+                        <funcsynopsisinfo>#include <systemd/sd-journal.h></funcsynopsisinfo>
+
+                        <funcprototype>
+                                <funcdef>int <function>sd_journal_get_usage</function></funcdef>
+                                <paramdef>sd_journal* <parameter>j</parameter></paramdef>
+                                <paramdef>uint64_t* <parameter>bytes</parameter></paramdef>
+                        </funcprototype>
+
+                </funcsynopsis>
+        </refsynopsisdiv>
+
+        <refsect1>
+                <title>Description</title>
+
+                <para><function>sd_journal_get_usage()</function>
+                determines the total disk space currently used up by
+                journal files. If
+                <literal>SD_JOURNAL_LOCAL_ONLY</literal> has been
+                passed when opening the journal files this value will
+                only reflect the size of journal files of the local
+                host, otherwise of all hosts.</para>
+        </refsect1>
+
+        <refsect1>
+                <title>Return Value</title>
+
+                <para><function>sd_journal_get_usage()</function>
+                returns 0 on success or a negative errno-style error
+                code.</para>
+        </refsect1>
+
+        <refsect1>
+                <title>Notes</title>
+
+                <para>The <function>sd_journal_get_usage()</function>
+                interface is available as shared library, which can be
+                compiled and linked to with the
+                <literal>libsystemd-journal</literal>
+                <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+                file.</para>
+        </refsect1>
+
+        <refsect1>
+                <title>See Also</title>
+
+                <para>
+                        <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+                        <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+                </para>
+        </refsect1>
+
+</refentry>
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 697e7f3..06de2ac 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -1906,6 +1906,8 @@ fail:
 void journal_file_print_header(JournalFile *f) {
         char a[33], b[33], c[33];
         char x[FORMAT_TIMESTAMP_MAX], y[FORMAT_TIMESTAMP_MAX];
+        struct stat st;
+        char bytes[FORMAT_BYTES_MAX];
 
         assert(f);
 
@@ -1970,6 +1972,9 @@ void journal_file_print_header(JournalFile *f) {
         if (JOURNAL_HEADER_CONTAINS(f->header, n_entry_arrays))
                 printf("Entry Array Objects: %llu\n",
                        (unsigned long long) le64toh(f->header->n_entry_arrays));
+
+        if (fstat(f->fd, &st) >= 0)
+                printf("Disk usage: %s\n", format_bytes(bytes, sizeof(bytes), (off_t) st.st_blocks * 512ULL));
 }
 
 int journal_file_open(
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 1a6464d..e260054 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -72,7 +72,8 @@ static enum {
         ACTION_NEW_ID128,
         ACTION_PRINT_HEADER,
         ACTION_SETUP_KEYS,
-        ACTION_VERIFY
+        ACTION_VERIFY,
+        ACTION_DISK_USAGE,
 } arg_action = ACTION_SHOW;
 
 static int help(void) {
@@ -96,6 +97,7 @@ static int help(void) {
                "Commands:\n"
                "     --new-id128         Generate a new 128 Bit ID\n"
                "     --header            Show journal header information\n"
+               "     --disk-usage        Show total disk usage\n"
 #ifdef HAVE_GCRYPT
                "     --setup-keys        Generate new FSS key pair\n"
                "       --interval=TIME   Time interval for changing the FSS sealing key\n"
@@ -118,7 +120,8 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_SETUP_KEYS,
                 ARG_INTERVAL,
                 ARG_VERIFY,
-                ARG_VERIFY_KEY
+                ARG_VERIFY_KEY,
+                ARG_DISK_USAGE
         };
 
         static const struct option options[] = {
@@ -141,6 +144,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "interval",     required_argument, NULL, ARG_INTERVAL     },
                 { "verify",       no_argument,       NULL, ARG_VERIFY       },
                 { "verify-key",   required_argument, NULL, ARG_VERIFY_KEY   },
+                { "disk-usage",   no_argument,       NULL, ARG_DISK_USAGE   },
                 { NULL,           0,                 NULL, 0                }
         };
 
@@ -224,6 +228,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_action = ACTION_VERIFY;
                         break;
 
+                case ARG_DISK_USAGE:
+                        arg_action = ACTION_DISK_USAGE;
+                        break;
+
 #ifdef HAVE_GCRYPT
                 case ARG_SETUP_KEYS:
                         arg_action = ACTION_SETUP_KEYS;
@@ -746,6 +754,19 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
+        if (arg_action == ACTION_DISK_USAGE) {
+                uint64_t bytes;
+                char sbytes[FORMAT_BYTES_MAX];
+
+                r = sd_journal_get_usage(j, &bytes);
+                if (r < 0)
+                        goto finish;
+
+                printf("Journals take up %s on disk.\n", format_bytes(sbytes, sizeof(sbytes), bytes));
+                r = 0;
+                goto finish;
+        }
+
 #ifdef HAVE_ACL
         if (access("/var/log/journal", F_OK) < 0 && geteuid() != 0 && in_group("adm") <= 0) {
                 log_error("Unprivileged users can't see messages unless persistent log storage is enabled. Users in the group 'adm' can always see messages.");
diff --git a/src/journal/libsystemd-journal.sym b/src/journal/libsystemd-journal.sym
index 27fdcdd..7dfae26 100644
--- a/src/journal/libsystemd-journal.sym
+++ b/src/journal/libsystemd-journal.sym
@@ -70,3 +70,8 @@ global:
         sd_journal_perror;
         sd_journal_perror_with_location;
 } LIBSYSTEMD_JOURNAL_187;
+
+LIBSYSTEMD_JOURNAL_190 {
+global:
+        sd_journal_get_usage;
+} LIBSYSTEMD_JOURNAL_188;
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 0f7c02c..b4d35ee 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -2062,6 +2062,29 @@ void journal_print_header(sd_journal *j) {
         }
 }
 
+_public_ int sd_journal_get_usage(sd_journal *j, uint64_t *bytes) {
+        Iterator i;
+        JournalFile *f;
+        uint64_t sum = 0;
+
+        if (!j)
+                return -EINVAL;
+        if (!bytes)
+                return -EINVAL;
+
+        HASHMAP_FOREACH(f, j->files, i) {
+                struct stat st;
+
+                if (fstat(f->fd, &st) < 0)
+                        return -errno;
+
+                sum += (uint64_t) st.st_blocks * 512ULL;
+        }
+
+        *bytes = sum;
+        return 0;
+}
+
 /* _public_ int sd_journal_query_unique(sd_journal *j, const char *field) { */
 /*         if (!j) */
 /*                 return -EINVAL; */
diff --git a/src/systemd/sd-journal.h b/src/systemd/sd-journal.h
index de1c8f3..6c18c89 100644
--- a/src/systemd/sd-journal.h
+++ b/src/systemd/sd-journal.h
@@ -108,6 +108,8 @@ int sd_journal_get_cursor(sd_journal *j, char **cursor);
 int sd_journal_get_cutoff_realtime_usec(sd_journal *j, uint64_t *from, uint64_t *to);
 int sd_journal_get_cutoff_monotonic_usec(sd_journal *j, const sd_id128_t boot_id, uint64_t *from, uint64_t *to);
 
+int sd_journal_get_usage(sd_journal *j, uint64_t *bytes);
+
 /* int sd_journal_query_unique(sd_journal *j, const char *field);      /\* missing *\/ */
 /* int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_t *l); /\* missing *\/ */
 /* void sd_journal_restart_unique(sd_journal *j);                      /\* missing *\/ */

commit ac59a798f2e9e616872e5c571219374c6d8f010d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Sep 7 22:22:15 2012 +0200

    main: fix syntax of net_prio cgroup controller

diff --git a/src/core/main.c b/src/core/main.c
index 7b5c861..33c0692 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1310,7 +1310,7 @@ int main(int argc, char *argv[]) {
                 goto finish;
 
         arg_join_controllers[0] = strv_new("cpu", "cpuacct", "cpuset", NULL);
-        arg_join_controllers[1] = strv_new("net_cls", "netprio", NULL);
+        arg_join_controllers[1] = strv_new("net_cls", "net_prio", NULL);
         arg_join_controllers[2] = NULL;
 
         if (!arg_join_controllers[0])



More information about the systemd-commits mailing list