Re: [systemd-devel] [RFC] pstore: options to enable kernel writing into the pstore

2020-03-26 Thread Eric DeVolder

Hi, thought I would try again...
eric

On 3/11/20 2:37 PM, Eric DeVolder wrote:

Systemd-devel,

Below is a proposal for adding a couple of settings to the systemd pstore
service so that it can enable the kernel parameters that allow the
kernel to write into the pstore.

Regards,
eric


 From 837d716c6e7ed02518a399356df95bf7c47e1772 Mon Sep 17 00:00:00 2001
From: Eric DeVolder 
Date: Wed, 11 Mar 2020 14:11:03 -0500
Subject: [RFC] pstore: options to enable kernel writing into the pstore

The systemd pstore service archives the contents of /sys/fs/pstore
upon boot so that there is room for a subsequent dump. The pstore is
usually backed by flash memory typically in the vicinity of 64KB.  The
pstore can contain post-mortem debug information even if kdump fails
or is not enabld.

The issue is that while the service is present, the kernel still needs
to be configured to write data into the pstore. It has two parameters,
crash_kexec_post_notifiers and printk.always_kmsg_dump, that control
writes into pstore.

The crash_kexec_post_notifiers parameter enables the kernel to write
dmesg (including stack trace) into pstore upon a panic, and
printk.always_kmsg_dump parameter enables the kernel to write dmesg upon
a shutdown (shutdown, reboot, halt).

As it stands today, these parameters are not managed/manipulated by the
systemd pstore service, and are solely reliant upon the user [to have
the foresight] to set them on the kernel command line at boot, or post
boot via sysfs. Furthermore, the user would need to set these parameters
in a persistent fashion so that that they are enabled on subsequent
reboots.

This patch allows the user to set these parameters via the systemd
pstore service, and forget about it. This patch introduces two new
settings in the pstore.conf, 'kmsg' and 'crash'. If either of these
is set to true, then the corresponding parameter is enabled in the
kernel. If the setting is false, then the parameter is not touched,
thus preserving whatever behavior the user may have previously
chosen.
---
  src/pstore/pstore.c | 36 +++-
  1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c
index 5c812b5d5b..02bd94751f 100644
--- a/src/pstore/pstore.c
+++ b/src/pstore/pstore.c
@@ -68,6 +68,10 @@ static DEFINE_CONFIG_PARSE_ENUM(config_parse_pstore_storage, 
pstore_storage, PSt
  static PStoreStorage arg_storage = PSTORE_STORAGE_EXTERNAL;

  static bool arg_unlink = true;
+static bool arg_kmsg = false;
+static bool arg_crash = false;
+static const char *arg_kmsg_path = 
"/sys/module/printk/parameters/always_kmsg_dump";
+static const char *arg_crash_path = 
"/sys/module/kernel/parameters/crash_kexec_post_notifiers";
  static const char *arg_sourcedir = "/sys/fs/pstore";
  static const char *arg_archivedir = "/var/lib/systemd/pstore";

@@ -75,6 +79,8 @@ static int parse_config(void) {
  static const ConfigTableItem items[] = {
  { "PStore", "Unlink",  config_parse_bool,   0, 
_unlink },
  { "PStore", "Storage", config_parse_pstore_storage, 0, 
_storage },
+    { "PStore", "kmsg",    config_parse_bool,   0, 
_kmsg },
+    { "PStore", "crash",   config_parse_bool,   0, 
_crash },
  {}
  };

@@ -363,7 +369,7 @@ static int list_files(PStoreList *list, const char 
*sourcepath) {

  static int run(int argc, char *argv[]) {
  _cleanup_(pstore_entries_reset) PStoreList list = {};
-    int r;
+    int fd, r;

  log_setup_service();

@@ -380,6 +386,34 @@ static int run(int argc, char *argv[]) {
  log_debug("Selected storage: %s.", 
pstore_storage_to_string(arg_storage));
  log_debug("Selected unlink: %s.", yes_no(arg_unlink));

+    if (arg_kmsg) {
+    /* Only enable if requested; otherwise do not touch the 
parameter */
+    /* NOTE: These errors are not fatal */
+    fd = open(arg_kmsg_path, O_WRONLY|O_CLOEXEC);
+    if (fd < 0)
+    log_error_errno(r, "Failed to open %s: %m", 
arg_kmsg_path);
+    r = write(fd, "Y", 1);
+    if (r != 1)
+    log_error_errno(r, "Failed to write: %m");
+    else
+    log_debug("Set printk.always_kmsg_dump.");
+    close(fd);
+    }
+
+    if (arg_crash) {
+    /* Only enable if requested; otherwise do not touch the 
parameter */
+    /* NOTE: These errors are not fatal */
+    fd = open(arg_crash_path, O_WRONLY|O_CLOEXEC);
+    if (fd < 0)
+    log_error_errno(r, "Failed to open %s: %m", 
arg_crash_path);
+    r = write(fd

[systemd-devel] [RFC] pstore: options to enable kernel writing into the pstore

2020-03-11 Thread Eric DeVolder

Systemd-devel,

Below is a proposal for adding a couple of settings to the systemd pstore
service so that it can enable the kernel parameters that allow the
kernel to write into the pstore.

Regards,
eric


From 837d716c6e7ed02518a399356df95bf7c47e1772 Mon Sep 17 00:00:00 2001
From: Eric DeVolder 
Date: Wed, 11 Mar 2020 14:11:03 -0500
Subject: [RFC] pstore: options to enable kernel writing into the pstore

The systemd pstore service archives the contents of /sys/fs/pstore
upon boot so that there is room for a subsequent dump. The pstore is
usually backed by flash memory typically in the vicinity of 64KB.  The
pstore can contain post-mortem debug information even if kdump fails
or is not enabld.

The issue is that while the service is present, the kernel still needs
to be configured to write data into the pstore. It has two parameters,
crash_kexec_post_notifiers and printk.always_kmsg_dump, that control
writes into pstore.

The crash_kexec_post_notifiers parameter enables the kernel to write
dmesg (including stack trace) into pstore upon a panic, and
printk.always_kmsg_dump parameter enables the kernel to write dmesg upon
a shutdown (shutdown, reboot, halt).

As it stands today, these parameters are not managed/manipulated by the
systemd pstore service, and are solely reliant upon the user [to have
the foresight] to set them on the kernel command line at boot, or post
boot via sysfs. Furthermore, the user would need to set these parameters
in a persistent fashion so that that they are enabled on subsequent
reboots.

This patch allows the user to set these parameters via the systemd
pstore service, and forget about it. This patch introduces two new
settings in the pstore.conf, 'kmsg' and 'crash'. If either of these
is set to true, then the corresponding parameter is enabled in the
kernel. If the setting is false, then the parameter is not touched,
thus preserving whatever behavior the user may have previously
chosen.
---
 src/pstore/pstore.c | 36 +++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c
index 5c812b5d5b..02bd94751f 100644
--- a/src/pstore/pstore.c
+++ b/src/pstore/pstore.c
@@ -68,6 +68,10 @@ static DEFINE_CONFIG_PARSE_ENUM(config_parse_pstore_storage, 
pstore_storage, PSt
 static PStoreStorage arg_storage = PSTORE_STORAGE_EXTERNAL;

 static bool arg_unlink = true;
+static bool arg_kmsg = false;
+static bool arg_crash = false;
+static const char *arg_kmsg_path = 
"/sys/module/printk/parameters/always_kmsg_dump";
+static const char *arg_crash_path = 
"/sys/module/kernel/parameters/crash_kexec_post_notifiers";
 static const char *arg_sourcedir = "/sys/fs/pstore";
 static const char *arg_archivedir = "/var/lib/systemd/pstore";

@@ -75,6 +79,8 @@ static int parse_config(void) {
 static const ConfigTableItem items[] = {
 { "PStore", "Unlink",  config_parse_bool,   0, 
_unlink },
 { "PStore", "Storage", config_parse_pstore_storage, 0, 
_storage },
+{ "PStore", "kmsg",config_parse_bool,   0, 
_kmsg },
+{ "PStore", "crash",   config_parse_bool,   0, 
_crash },
 {}
 };

@@ -363,7 +369,7 @@ static int list_files(PStoreList *list, const char 
*sourcepath) {

 static int run(int argc, char *argv[]) {
 _cleanup_(pstore_entries_reset) PStoreList list = {};
-int r;
+int fd, r;

 log_setup_service();

@@ -380,6 +386,34 @@ static int run(int argc, char *argv[]) {
 log_debug("Selected storage: %s.", 
pstore_storage_to_string(arg_storage));
 log_debug("Selected unlink: %s.", yes_no(arg_unlink));

+if (arg_kmsg) {
+/* Only enable if requested; otherwise do not touch the 
parameter */
+/* NOTE: These errors are not fatal */
+fd = open(arg_kmsg_path, O_WRONLY|O_CLOEXEC);
+if (fd < 0)
+log_error_errno(r, "Failed to open %s: %m", 
arg_kmsg_path);
+r = write(fd, "Y", 1);
+if (r != 1)
+log_error_errno(r, "Failed to write: %m");
+else
+log_debug("Set printk.always_kmsg_dump.");
+close(fd);
+}
+
+if (arg_crash) {
+/* Only enable if requested; otherwise do not touch the 
parameter */
+/* NOTE: These errors are not fatal */
+fd = open(arg_crash_path, O_WRONLY|O_CLOEXEC);
+if (fd < 0)
+log_error_errno(r, "Failed to open %s: %m", 
arg_crash_path);
+r = write(fd, "Y", 1);
+if (r != 1)
+log_error_errno(r,

Re: [systemd-devel] [PATCH 0/6] pstore: Tool to archive contents of pstore upon boot/shutdown

2019-06-10 Thread Eric DeVolder

Hi Lennart,
I've applied the coding style guidelines, and created a pull request 
#12768 via GitHub. Let me know what I may have done wrong, my first 
attempt via GitHub.

Thanks,
eric

On 5/16/19 9:34 AM, Lennart Poettering wrote:

On Do, 16.05.19 09:28, Eric DeVolder (eric.devol...@oracle.com) wrote:

Could you please submit this via github as PR? Review is so much nicer
there, in particular for complex patch sets, and this qualifies as
complex I think. This also has the benefit that the code is
automatically analyzed by our CI tools.

https://github.com/systemd/systemd/pulls

Moreover, please make sure to to read our coding style guidelines
here:

https://systemd.io/CODING_STYLE

Form a very brief glance it appears the code doesn't follow formatting
rules for example.

Thanks!

Lennart

--
Lennart Poettering, Berlin


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

Re: [systemd-devel] [PATCH 0/6] pstore: Tool to archive contents of pstore upon boot/shutdown

2019-05-16 Thread Eric DeVolder

OK, will do!
eric

On 5/16/19 9:34 AM, Lennart Poettering wrote:

On Do, 16.05.19 09:28, Eric DeVolder (eric.devol...@oracle.com) wrote:

Could you please submit this via github as PR? Review is so much nicer
there, in particular for complex patch sets, and this qualifies as
complex I think. This also has the benefit that the code is
automatically analyzed by our CI tools.

https://github.com/systemd/systemd/pulls

Moreover, please make sure to to read our coding style guidelines
here:

https://systemd.io/CODING_STYLE

Form a very brief glance it appears the code doesn't follow formatting
rules for example.

Thanks!

Lennart

--
Lennart Poettering, Berlin


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

[systemd-devel] [PATCH 0/6] pstore: Tool to archive contents of pstore upon boot/shutdown

2019-05-16 Thread Eric DeVolder
  9 09:50 dmesg-efi-155741337607001
 -rw-r--r-- 1 root root  1811 May  9 09:50 dmesg-efi-155741337608001
 -rw-r--r-- 1 root root  1817 May  9 09:50 dmesg-efi-155741337609001
 -rw-r--r-- 1 root root  1795 May  9 09:50 dmesg-efi-155741337710001
 -rw-r--r-- 1 root root  1770 May  9 09:50 dmesg-efi-155741337711001
 -rw-r--r-- 1 root root  1796 May  9 09:50 dmesg-efi-155741337712001
 -rw-r--r-- 1 root root  1787 May  9 09:50 dmesg-efi-155741337713001
 -rw-r--r-- 1 root root  1808 May  9 09:50 dmesg-efi-155741337714001
 -rw-r--r-- 1 root root  1754 May  9 09:50 dmesg-efi-155741337715001
 -rw-r--r-- 1 root root 26754 May  9 09:50 dmesg.txt

where dmesg.txt is reconstructed from the group of related
dmesg-efi-155741337* files.

Configuration file:
The pstore.conf configuration file has four settings, described below.
 - Storage : one of "none", "archive", or "journal". With "none", this
   tool leaves the contents of pstore untouched. With "archive", the
   contents of the pstore are moved into the ArchiveDir. With "journal",
   the contents of the pstore are recorded in the systemd journal. The
   default is "archive".
 - SourceDir : contains a path to the pstore. The default is
   "/sys/fs/pstore".
 - ArchiveDir : contains a path to archive pstore contents. The default
   is "/var/lib/systemd/pstore".
 - AllowUnlink : is one of "yes" or "no". When "yes", the default, then
   files in the pstore are removed once processed. When "no", processing
   of the pstore occurs normally, but the pstore files remain.

References:
[1] "Persistent storage for a kernel's dying breath",
March 23, 2011.
https://lwn.net/Articles/434821/

[2] "Advanced Configuration and Power Interface Specification",
version 6.2, May 2017.
https://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf

[3] "Unified Extensible Firmware Interface Specification",
version 2.8, March 2019.
https://uefi.org/sites/default/files/resources/UEFI_Spec_2_8_final.pdf

[4] "The kernel’s command-line parameters",
https://static.lwn.net/kerneldoc/admin-guide/kernel-parameters.html

REVIEW NOTES:
 - My experience with systemd is minimal, this code may reflect that.
 - No attempt at conforming to systemd coding style yet
 - User manual/documentation not done yet.
 - No pstore tests at this time
 - This intended to be an early look/review to ensure I'm headed down
   the desired path per maintainers.
---
v1 16may2019
 - sent to systemd-devel@lists.freedesktop.org for early/initial review


Eric DeVolder (6):
  pstore: Add new pstore tool/service to the build
  pstore: Add new pstore tool/service to the build
  pstore: The new systemd-pstore tool to archive pstore contents
  pstore: The new configuration file for systemd-pstore tool
  pstore: The new pstore archive service file
  pstore: The new documentation for the pstore configuration file

 man/pstore.conf.xml | 100 ++
 meson.build |  29 ++
 meson_options.txt   |   2 +
 src/pstore/meson.build  |  21 ++
 src/pstore/pstore.c | 736 
 src/pstore/pstore.conf  |  19 ++
 units/meson.build   |   1 +
 units/systemd-pstore.service.in |  32 ++
 8 files changed, 940 insertions(+)
 create mode 100644 man/pstore.conf.xml
 create mode 100644 src/pstore/meson.build
 create mode 100644 src/pstore/pstore.c
 create mode 100644 src/pstore/pstore.conf
 create mode 100644 units/systemd-pstore.service.in

-- 
2.7.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

[systemd-devel] [PATCH 4/6] pstore: The new configuration file for systemd-pstore tool

2019-05-16 Thread Eric DeVolder
The pstore.conf configuration file has four settings, described below.
 - Storage : one of "none", "archive", or "journal". With "none", this
   tool leaves the contents of pstore untouched. With "archive", the
   contents of the pstore are moved into the ArchiveDir. With "journal",
   the contents of the pstore are recorded in the systemd journal. The
   default is "archive".
 - SourceDir : contains a path to the pstore. The default is
   "/sys/fs/pstore".
 - ArchiveDir : contains a path to archive pstore contents. The default
   is "/var/lib/systemd/pstore".
 - AllowUnlink : is one of "yes" or "no". When "yes", the default, then
   files in the pstore are removed once processed. When "no", processing
   of the pstore occurs normally, but the pstore files remain.

Signed-off-by: Eric DeVolder 
---
 src/pstore/pstore.conf | 19 +++
 1 file changed, 19 insertions(+)
 create mode 100644 src/pstore/pstore.conf

diff --git a/src/pstore/pstore.conf b/src/pstore/pstore.conf
new file mode 100644
index 000..985a953
--- /dev/null
+++ b/src/pstore/pstore.conf
@@ -0,0 +1,19 @@
+#  This file is part of systemd.
+#
+#  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.
+#
+# Entries in this file show the compile time defaults.
+# You can change settings by editing this file.
+# Defaults can be restored by simply deleting this file.
+#
+# See pstore.conf(5) for details.
+
+[Pstore]
+#Storage=archive
+#SourceDir=/sys/fs/pstore
+#ArchiveDir=/var/lib/systemd/pstore
+#AllowUnlink=yes
+
-- 
2.7.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

[systemd-devel] [PATCH 3/6] pstore: The new systemd-pstore tool to archive pstore contents

2019-05-16 Thread Eric DeVolder
The systemd-pstore which is a tool that performs the following:
 - reads the pstore.conf configuration file
 - lists the files in the pstore (eg. /sys/fs/pstore)
 - for each file, locates a handler for the type of file (eg. dmesg, MCE, etc)
 - invokes the handler for the file (eg. the handler appends file to a list)
 - when the list of files is exhausted, all handlers are notified; in the case
   of the dmesg handler, final processing of the files occurs:
   - files sorted in reverse lexigraphical order to faciliate reconstruction
 of original dmesg
   - the filename is examined to determine which dmesg it is a part
   - the file is either moved to archive storage or recorded in the journal
   - the file is appended to the reconstructed dmesg

Signed-off-by: Eric DeVolder 
---
 src/pstore/pstore.c | 736 
 1 file changed, 736 insertions(+)
 create mode 100644 src/pstore/pstore.c

diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c
new file mode 100644
index 000..f2e9845
--- /dev/null
+++ b/src/pstore/pstore.c
@@ -0,0 +1,736 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+/*
+ * Generally speaking, the pstore contains a small number of files
+ * that in turn contain a small amount of data.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "sd-daemon.h"
+#include "sd-journal.h"
+#include "sd-login.h"
+#include "sd-messages.h"
+
+#include "acl-util.h"
+#include "alloc-util.h"
+#include "capability-util.h"
+#include "cgroup-util.h"
+#include "compress.h"
+#include "conf-parser.h"
+#include "copy.h"
+#include "dirent-util.h"
+#include "escape.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "fs-util.h"
+#include "io-util.h"
+#include "journal-importer.h"
+#include "log.h"
+#include "macro.h"
+#include "main-func.h"
+#include "missing.h"
+#include "mkdir.h"
+#include "parse-util.h"
+#include "process-util.h"
+#include "signal-util.h"
+#include "socket-util.h"
+#include "special.h"
+#include "string-table.h"
+#include "string-util.h"
+#include "strv.h"
+#include "tmpfile-util.h"
+#include "user-util.h"
+#include "util.h"
+
+#define ARRAY_SIZE(ARRAY) (sizeof(ARRAY)/sizeof(ARRAY[0]))
+
+#define PATHSZ 1024
+#define ARG_SOURCEDIR_DEFAULT "/sys/fs/pstore"
+#define ARG_ARCHIVEDIR_DEFAULT "/var/lib/systemd/pstore"
+
+/*
+ * Command line argument handling
+ */
+typedef enum PstoreStorage {
+PSTORE_STORAGE_NONE,
+PSTORE_STORAGE_ARCHIVE,
+PSTORE_STORAGE_JOURNAL,
+_PSTORE_STORAGE_MAX,
+_PSTORE_STORAGE_INVALID = -1
+} PstoreStorage;
+
+static const char* const pstore_storage_table[_PSTORE_STORAGE_MAX] = {
+[PSTORE_STORAGE_NONE] = "none",
+[PSTORE_STORAGE_ARCHIVE] = "archive",
+[PSTORE_STORAGE_JOURNAL] = "journal",
+};
+
+DEFINE_PRIVATE_STRING_TABLE_LOOKUP(pstore_storage, PstoreStorage);
+static DEFINE_CONFIG_PARSE_ENUM(config_parse_pstore_storage, pstore_storage, 
PstoreStorage, "Failed to parse storage setting");
+
+static PstoreStorage arg_storage = PSTORE_STORAGE_ARCHIVE;
+
+static bool arg_allowunlink = true;
+static char *arg_sourcedir = NULL;
+static char *arg_archivedir = NULL;
+STATIC_DESTRUCTOR_REGISTER(arg_sourcedir, freep);
+STATIC_DESTRUCTOR_REGISTER(arg_archivedir, freep);
+
+static int parse_config(void) {
+int rc;
+static const ConfigTableItem items[] = {
+{ "Pstore", "AllowUnlink",  config_parse_bool,  0, 
_allowunlink },
+{ "Pstore", "Storage",  config_parse_pstore_storage,0, 
_storage },
+{ "Pstore", "SourceDir",config_parse_path,  0, 
_sourcedir   },
+{ "Pstore", "ArchiveDir",   config_parse_path,  0, 
_archivedir  },
+{}
+};
+
+rc = config_parse_many_nulstr(PKGSYSCONFDIR "/pstore.conf",
+CONF_PATHS_NULSTR("systemd/pstore.conf.d"),
+"Pstore\0",
+config_item_table_lookup, items,
+CONFIG_PARSE_WARN, NULL);
+if (NULL == arg_sourcedir)
+{
+arg_sourcedir = (char *)malloc(sizeof(ARG_SOURCEDIR_DEFAULT)+1);
+if (NULL != arg_sourcedir)
+strcpy(arg_sourcedir, ARG_SOURCEDIR_DEFAULT);
+}
+if (NULL == arg_archivedir)
+{
+arg_archivedir = (char *)malloc(sizeof(ARG_ARCHIVEDIR_DEFAULT)+1);
+if (NULL != arg_ar

[systemd-devel] [PATCH 2/6] pstore: Add new pstore tool/service to the build

2019-05-16 Thread Eric DeVolder
This new file is invoked by the build system to build pstore.

Signed-off-by: Eric DeVolder 
---
 src/pstore/meson.build | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 src/pstore/meson.build

diff --git a/src/pstore/meson.build b/src/pstore/meson.build
new file mode 100644
index 000..911eb0f
--- /dev/null
+++ b/src/pstore/meson.build
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: LGPL-2.1+
+
+systemd_pstore_sources = files('''
+pstore.c
+'''.split())
+
+#pstorectl_sources = files('pstorectl.c')
+
+if conf.get('ENABLE_PSTORE') == 1
+install_data('pstore.conf',
+ install_dir : pkgsysconfdir)
+endif
+
+#tests += [
+#[['src/pstore/test-pstore.c',
+#  'src/pstore/pstore.c',
+#  'src/pstore/pstore.h'],
+# [],
+# [],
+# 'ENABLE_PSTORE', 'manual'],
+#]
-- 
2.7.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

[systemd-devel] [PATCH 6/6] pstore: The new documentation for the pstore configuration file

2019-05-16 Thread Eric DeVolder
The xml file for the systemd pstore tool configuration file.

Signed-off-by: Eric DeVolder 
---
 man/pstore.conf.xml | 100 
 1 file changed, 100 insertions(+)
 create mode 100644 man/pstore.conf.xml

diff --git a/man/pstore.conf.xml b/man/pstore.conf.xml
new file mode 100644
index 000..307727a
--- /dev/null
+++ b/man/pstore.conf.xml
@@ -0,0 +1,100 @@
+
+http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd;>
+
+
+http://www.w3.org/2001/XInclude;>
+  
+pstore.conf
+systemd
+  
+
+  
+pstore.conf
+5
+  
+
+  
+pstore.conf
+Pstore configuration file
+  
+
+  
+/etc/systemd/pstore.conf
+  
+
+  
+Description
+
+This file configures the behavior of
+
systemd-pstore8,
+a handler for archiving the contents of the persistent storage filesystem, 
pstore.
+
+  
+
+  
+
+  
+Options
+
+All options are configured in the
+[Pstore] section:
+
+
+
+  
+Storage=
+
+Controls where to archive files in the pstore 
filesystem. One of none,
+archive, and journal. When
+none, the files in pstore are untouched. When 
archive (the
+default), files are archived in 
/var/lib/systemd/pstore/.
+When journal, pstore file contents are recorded in 
the journal.
+
+
+  
+
+  
+SourceDir=
+
+Specifies the path to the persistent storage 
filesystem.
+The default location is /sys/fs/pstore.
+
+  
+
+  
+ArchiveDir=
+
+Specifies the path where pstore files are to be 
archived, when
+Storage is archive.
+
+  
+
+  
+AllowUnlink=
+
+Controls whether or not pstore files are removed. One 
of
+yes or no. When 
yes,
+a pstore file is removed from the pstore once it has been archived 
(either to
+disk or into the journal). When no, processing of 
pstore files
+occurs normally, but the files remain in the pstore.
+The default is yes in order to maintain the pstore 
in a
+nearly empty state, so that it has storage available for the next 
kernel error event.
+
+  
+
+
+The defaults for all values are listed as comments in the
+template /etc/systemd/pstore.conf file that
+is installed by default.
+  
+
+  
+See Also
+
+  
systemd-journald.service8,
+
+  
+
+
-- 
2.7.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

[systemd-devel] [PATCH 5/6] pstore: The new pstore archive service file

2019-05-16 Thread Eric DeVolder
The necessary systemd service file which invokes the pstore
archival tool upon boot as well as shutdown (poweroff, reboot).

Signed-off-by: Eric DeVolder 
---
 units/systemd-pstore.service.in | 32 
 1 file changed, 32 insertions(+)
 create mode 100644 units/systemd-pstore.service.in

diff --git a/units/systemd-pstore.service.in b/units/systemd-pstore.service.in
new file mode 100644
index 000..4672d81
--- /dev/null
+++ b/units/systemd-pstore.service.in
@@ -0,0 +1,32 @@
+#  SPDX-License-Identifier: LGPL-2.1+
+#
+#  This file is part of systemd.
+#
+#  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.
+
+[Unit]
+Description=Pstore archive service
+#Documentation=man:systemd-pstore(8)
+#DefaultDependencies=no
+#Conflicts=shutdown.target
+#After=systemd-remount-fs.service systemd-journald.socket
+#Requires=systemd-journald.socket
+#Before=shutdown.target
+Wants=network-online.target local-fs.target remote-fs.target
+After=network-online.target local-fs.target
+
+[Service]
+Type=oneshot
+StandardOutput=syslog+console
+#EnvironmentFile=/etc/default/kdump-tools
+ExecStart=/usr/lib/systemd/systemd-pstore start
+ExecStop=/usr/lib/systemd/systemd-pstore stop
+RemainAfterExit=no
+
+[Install]
+#WantedBy=multi-user.target
+WantedBy=local-fs.target
+
-- 
2.7.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

[systemd-devel] [PATCH 1/6] pstore: Add new pstore tool/service to the build

2019-05-16 Thread Eric DeVolder
This change adds the src/pstore directory to the build files.

Signed-off-by: Eric DeVolder 
---
 meson.build   | 29 +
 meson_options.txt |  2 ++
 units/meson.build |  1 +
 3 files changed, 32 insertions(+)

diff --git a/meson.build b/meson.build
index eaf0edd..4a9ebc1 100644
--- a/meson.build
+++ b/meson.build
@@ -1258,6 +1258,7 @@ foreach term : ['utmp',
 'environment-d',
 'binfmt',
 'coredump',
+'pstore',
 'resolve',
 'logind',
 'hostnamed',
@@ -1469,6 +1470,7 @@ subdir('src/network')
 subdir('src/analyze')
 subdir('src/journal-remote')
 subdir('src/coredump')
+subdir('src/pstore')
 subdir('src/hostname')
 subdir('src/import')
 subdir('src/kernel-install')
@@ -2240,6 +2242,32 @@ if conf.get('ENABLE_COREDUMP') == 1
 public_programs += exe
 endif
 
+if conf.get('ENABLE_PSTORE') == 1
+executable('systemd-pstore',
+   systemd_pstore_sources,
+   include_directories : includes,
+   link_with : [libshared],
+   dependencies : [threads,
+   libacl,
+   libdw,
+   libxz,
+   liblz4],
+   install_rpath : rootlibexecdir,
+   install : true,
+   install_dir : rootlibexecdir)
+
+#   exe = executable('pstorectl',
+#pstorectl_sources,
+#include_directories : includes,
+#link_with : [libshared],
+#dependencies : [threads,
+#libxz,
+#liblz4],
+#install_rpath : rootlibexecdir,
+#install : true)
+public_programs += exe
+endif
+
 if conf.get('ENABLE_BINFMT') == 1
 exe = executable('systemd-binfmt',
  'src/binfmt/binfmt.c',
@@ -3143,6 +3171,7 @@ foreach tuple : [
 ['DNS-over-TLS(gnutls)',  conf.get('DNS_OVER_TLS_USE_GNUTLS') == 1],
 ['DNS-over-TLS(openssl)', conf.get('DNS_OVER_TLS_USE_OPENSSL') == 1],
 ['coredump'],
+['pstore'],
 ['polkit'],
 ['legacy pkla',  install_polkit_pkla],
 ['efi'],
diff --git a/meson_options.txt b/meson_options.txt
index c1cb461..564250a 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -79,6 +79,8 @@ option('binfmt', type : 'boolean',
description : 'support for custom binary formats')
 option('coredump', type : 'boolean',
description : 'install the coredump handler')
+option('pstore', type : 'boolean',
+   description : 'install the pstore handler')
 option('logind', type : 'boolean',
description : 'install the systemd-logind stack')
 option('hostnamed', type : 'boolean',
diff --git a/units/meson.build b/units/meson.build
index a561050..3365e8d 100644
--- a/units/meson.build
+++ b/units/meson.build
@@ -136,6 +136,7 @@ in_units = [
 ['systemd-bless-boot.service',   'ENABLE_EFI HAVE_BLKID'],
 ['systemd-boot-check-no-failures.service', ''],
 ['systemd-coredump@.service','ENABLE_COREDUMP'],
+['systemd-pstore.service',   'ENABLE_PSTORE'],
 ['systemd-firstboot.service','ENABLE_FIRSTBOOT',
  'sysinit.target.wants/'],
 ['systemd-fsck-root.service',''],
-- 
2.7.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

Re: [systemd-devel] RFC: idea for a pstore systemd service

2019-02-21 Thread Eric DeVolder


On 1/16/19 12:30 PM, Lennart Poettering wrote:

On Di, 15.01.19 23:39, Jóhann B. Guðmundsson (johan...@gmail.com) wrote:



[Service]
ExecStart=/bin/bash -c '/usr/bin/mv -t /var/lib/pstore /sys/fs/pstore/*'
Restart=on-success


While this would certainly work, I think I'd prefer a version in C
and not depend on an installed shell for this. I mean, so far systemd
has been an excercise in keeping shell out of the default codepaths in
the boot process...

Moreover, we want a recognizable journal message (i.e. one with
MESSAGE_ID) to be generated when we move a file out of pstore, much
like we have it for coredumps and so on, and as soon as you do more
than just the basic "mv" it gets nastier and nastier to do this from
shell, while it is easy from C.

Lennart

--
Lennart Poettering, Red Hat



Lennart,
As this is my first venture into systemd, I've spent some time looking 
into the source for coredump. I chose this as it was mentioned in this 
thread. As a I look at this source, I see how to create the journal 
entries (ie. when we move a file out of pstore), and other things are 
unclear. Some questions:


- if I were to start by copying and then modifying an existing systemd 
utility, would you recommend coredump, or something else?
- do you anticipate this pstore utility needing to handling the likes of 
acls, xattrs, fields, etc?

- would there be a need for the server that is in coredump?

I admit to these being really newbie questions, I apologize. If there is 
a recommended developer reading (my google searches turned up mostly 
user-perspective hits), I'd greatly appreciate a pointer.


Also, I have other tasks on my plate, so I am working on this but not as 
my sole priority. I ask for patience.


Thanks,
eric
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

Re: [systemd-devel] RFC: idea for a pstore systemd service

2019-01-17 Thread Eric DeVolder

Lennart,
I've some homework to do based on your feedback and will report back. As 
I understand it, I need to do this in C as well.

Regards,
eric


On 1/15/19 12:49 PM, Lennart Poettering wrote:

On Di, 15.01.19 11:23, Eric DeVolder (eric.devol...@oracle.com) wrote:


Systemd-devel,

Below is a write-up I've done to explain a new service for archiving pstore
contents. I've attached the pstore.service files
(/lib/systemd/system/pstore.service and bin/pstore-tool). These are trivial
right now, but easy to build upon if periodic, rather than just on-boot,
examination of the pstore is desirable.


If you look at the TODO list in our git tree, you'll find that
importing and flushing pstore has been a long-time TODO list item for
us. Our original idea was to make this another input for the journal,
but as I understand these days the pstore files are not necessarily in
log format, hence maybe handling it similar to coredumps is an option
too. i.e. drop it into some directory in /var like we do it for
/var/lib/coredump/, and then link that up with the journal through
some structured log message.

So yeah, it appears to me that you have similar ideas there. And yes,
we'd welcome such work. ACPI is generic and standard enough to make
this generically useful, and the code for this is simple enough hence
I think this sounds like something acceptable for our tree.

That said, I wonder what else is generally found in pstore these days,
besides the dmesg stuff? i.e. is there well-known other stuff, such as
firmware stuff?


The questions I have for you are:

- Is a new unit pstore.service the right approach for this? If not, what
unit do you recommend augmenting with these actions?


Well, our own code is usually placed in service units whose name
begins with "systemd-", hence systemd-pstore.service sounds more systematic.

But yeah, by all means, please submit a proposal as PR.

Lennart

--
Lennart Poettering, Red Hat


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] RFC: idea for a pstore systemd service

2019-01-15 Thread Eric DeVolder

Systemd-devel,

Below is a write-up I've done to explain a new service for archiving 
pstore contents. I've attached the pstore.service files 
(/lib/systemd/system/pstore.service and bin/pstore-tool). These are 
trivial right now, but easy to build upon if periodic, rather than just 
on-boot, examination of the pstore is desirable.


The questions I have for you are:

- Is a new unit pstore.service the right approach for this? If not, what 
unit do you recommend augmenting with these actions?


- What are your thoughts/comments/feedback on such a service?

Thank you in advance for your time,
Eric

 Oracle ERST usage 
The BIOS ACPI error record serialization table, ERST, is an API for 
storing data into non-volatile storage, such as hardware errors [1, 
Section 18.5 Error Serialization]. The ERST non-volatile storage on 
Oracle servers tends to be small, on the order of 64KiB.


The Linux persistent storage subsystem, pstore, supports using the ERST 
as a backend for persistent storage [2].


The kernel, with the crash_kexec_post_notifiers command line option, 
stores the dmesg into pstore on a panic [3]. This action is available 
independent of kdump; as such, the crash backtrace is captured into 
pstore for post mortem analysis, regardless of whether kdump is enabled 
or working properly.


Since the ERST area is typically small, it is easily filled with the 
contents of dmesg upon a kernel panic. As such, there is a need to 
archive the contents of kernel dmesg items in the pstore to a normal 
filesystem, and then free the dmesg items in the pstore in order to make 
room for the dmesg of a subsequent kernel panic.


Therefore, this is a proposal for a new service, pstore.service, that 
will archive the dmesg contents in the pstore to a regular filesystem, 
and remove those dmesg entries from the pstore.  Since Linux exposes the 
persistent storage subsystem as a filesystem [2], and the items in the 
pstore are available as regular files, this makes archiving and removal 
of the entries trivial. This proposal is for a new service instead of 
augmenting kdump.service since this is independent of kdump, though both 
are related to a kernel crash. Conceivably other items that are stored 
in pstore, like hardware errors, could have their own rules for 
archiving. The goal of the pstore.service is to attempt to keep the 
pstore empty and available for emergent events like hardware errors and 
kernel crashes.


Initially the service could be as simple as looking for items upon boot, 
but I could see it being extended to periodically check for events like 
hardware errors in the pstore. Kernel crash dmesg items are named in a 
regular fashion, such as:


-r--r--r-- 1 root root 17716 Nov 20 11:08 dmesg-erst-6625975467788730369
-r--r--r-- 1 root root 17731 Nov 20 11:08 dmesg-erst-6625975467788730370
-r--r--r-- 1 root root 17679 Nov 20 11:08 dmesg-erst-6625975467788730371

And a simple bit of filename manipulation can be used to create archive 
sub-directories, say in /var/pstore, with the archived data.


[1] "Advanced Configuration and Power Interface Specification",
 version 6.2, May 2017.
 https://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf

[2] "Persistent storage for a kernel's dying breath",
 March 23, 2011.
 https://lwn.net/Articles/434821/

[3] "The kernel’s command-line parameters",
 https://static.lwn.net/kerneldoc/admin-guide/kernel-parameters.html

[Unit]
Description=pstore archive service
Wants=network-online.target local-fs.target remote-fs.target
After=network-online.target

[Service]
Type=oneshot
StandardOutput=syslog+console
#EnvironmentFile=/etc/default/kdump-tools
#ExecStart=/etc/init.d/pstore-tools start
#ExecStop=/etc/init.d/pstore-tools stop
ExecStart=/root/pstore-tool start
ExecStop=/root/pstore-tool stop
#RemainAfterExit=yes
RemainAfterExit=no

[Install]
#WantedBy=multi-user.target
WantedBy=local-fs.target

#!/bin/sh
# Utility script to archive contents of pstore

#-r--r--r--. 1 root root 1826 Dec 17 10:44 dmesg-efi-154506148323001
#-r--r--r--. 1 root root 1826 Dec 17 10:44 dmesg-efi-154506148324001

pstorefs=/sys/fs/pstore
archivedir=/var/pstore/`date +"%Y-%m-%d-%H:%M"`

pstore_start()
{
echo "PSTORE manager started wtf"
# Note: The -r is essential for dmesg reconstruction
files=`ls -r $pstorefs/dmesg-* 2>/dev/null`
if [ "$files" != "" ];
then
# Archive files
mkdir -p $archivedir
for f in $files;
do
# Reconstruct dmesg
cat $f >> $archivedir/dmesg.txt
mv -f $f $archivedir
done
fi
}

pstore_stop()
{
echo "PSTORE manager stopped"
}

while [[ $# -gt 0 ]]
do
case $1 in
start)
pstore_start
;;
stop)
pstore_stop
;;
*)
echo "pstore-tool: unrecognized option: $1"
;;
esac
shift # on to next argument
done