Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp518679imb; Fri, 1 Mar 2019 06:56:18 -0800 (PST) X-Google-Smtp-Source: APXvYqxSy7jYe+ei06GaLHJxrk6hX1nx3fGbWRi4x8fZTsE3yGJ2ElVztw5XkR+H51QbLgNDyCUI X-Received: by 2002:a17:902:4545:: with SMTP id m63mr5745560pld.71.1551452178583; Fri, 01 Mar 2019 06:56:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551452178; cv=none; d=google.com; s=arc-20160816; b=vHpOSzbAfWjDaGkiu27FqDSaXuI8Xhk6Wrl+N/6xJ+ZoARvwJrVNcrQWnD2VDRvctY uRmg6x7/JJbRYBtHMXkB1zBwZehjsp5fwFHA7mouQ5p1ioHfaLMR9KSAhacXztBk9An0 2UtqAVNxql6aaziKKMPiWnzuBShrBI3nTLz+dW95PejZWnwDMNyzuhNRfEa8sU5QU/PV n2oio1Xd1aCVLFVguG003k07sOPPs9/1AU6sOPTjjJQgbtY/EGeUyXe/kqvQg7S7PM2c dUi1JkyMhzsp9ytkvoAdk7RG4Eu5rBzXzYVNizq5P7vACupUhGj+yJ41POTiG7FqNA1r Tf2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=DJhQduHJ/BIxhyzZh4Kcm32Vp4u2p9ETqaAwiKm1W4c=; b=OVlKRIVGr7Znys5CpFBx86eXSaamIi9syZOd4ISm7Nk2CmvVHOzOBPddknQKx+Q5Jq 3T26EJm9GA9hxR2G3zy8XNTx5x62yqRnlo2gjWKeVFFzQ+vyR59EMrl8bnPvLv38U9DX 5Z8onfOvo3llCgHsBGonOPKnUUAA+FdKME4/ztCP2twHPQAq3IQXjg6MMKLfh3yWbgaH g2Lj1gPtyJDUu9XAq6lerUaBlNDO+eU+R605VqqCeVy5YOOz1oVO3fwgUWjXIaMzg4sG CDDtlAhWjtgAKL/XZcn4z5+SbfMKdahQJnDUssWjlZFrx/eOSHQC25JqRQgwwjJFZ5Bd Labg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w8si8931313pgl.587.2019.03.01.06.56.02; Fri, 01 Mar 2019 06:56:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388887AbfCAOx3 (ORCPT + 99 others); Fri, 1 Mar 2019 09:53:29 -0500 Received: from mx2.suse.de ([195.135.220.15]:38690 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728171AbfCAOx2 (ORCPT ); Fri, 1 Mar 2019 09:53:28 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 04BE7B118; Fri, 1 Mar 2019 14:53:26 +0000 (UTC) From: Thomas Renninger To: keescook@chromium.org Cc: joel@joelfernandes.org, tony.luck@intel.com, ccross@android.com, anton@enomsg.org, duwe@suse.de, linux-kernel@vger.kernel.org Subject: [PATCH] pstore: automatically dump and clean dmesg entries Date: Fri, 01 Mar 2019 15:53:25 +0100 Message-ID: <35267159.Lyx5QdZ5Rb@house> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Torsten Duwe Dump a previous oops or panic, which has made it to pstore, to the new syslog after reboot, optionally deleting it. This can happen automatically, without user land interaction. Signed-off-by: Torsten Duwe CC: Thomas Renninger --- fs/pstore/inode.c | 6 +++--- fs/pstore/internal.h | 11 +++++++++-- fs/pstore/platform.c | 33 +++++++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 11 deletions(-) Index: test_pstore/fs/pstore/inode.c =================================================================== --- test_pstore.orig/fs/pstore/inode.c 2019-03-01 13:55:50.561322896 +0100 +++ test_pstore/fs/pstore/inode.c 2019-03-01 13:56:05.349323693 +0100 @@ -374,7 +374,7 @@ fail: * when we are re-scanning the backing store looking to add new * error records. */ -void pstore_get_records(int quiet) +void pstore_get_records(unsigned flags) { struct pstore_info *psi = psinfo; struct dentry *root; @@ -385,7 +385,7 @@ void pstore_get_records(int quiet) root = pstore_sb->s_root; inode_lock(d_inode(root)); - pstore_get_backend_records(psi, root, quiet); + pstore_get_backend_records(psi, root, flags); inode_unlock(d_inode(root)); } @@ -415,7 +415,7 @@ static int pstore_fill_super(struct supe if (!sb->s_root) return -ENOMEM; - pstore_get_records(0); + pstore_get_records(PGR_VERBOSE|PGR_POPULATE); return 0; } Index: test_pstore/fs/pstore/internal.h =================================================================== --- test_pstore.orig/fs/pstore/internal.h 2019-03-01 13:55:50.565322897 +0100 +++ test_pstore/fs/pstore/internal.h 2019-03-01 13:56:05.349323693 +0100 @@ -28,9 +28,16 @@ static inline void pstore_unregister_pms extern struct pstore_info *psinfo; extern void pstore_set_kmsg_bytes(int); -extern void pstore_get_records(int); +extern void pstore_get_records(unsigned); +/* Flags for the pstore iterator pstore_get_records() */ +#define PGR_QUIET 0 +#define PGR_VERBOSE 1 +#define PGR_POPULATE 2 +#define PGR_SYSLOG 4 +#define PGR_CLEAR 8 + extern void pstore_get_backend_records(struct pstore_info *psi, - struct dentry *root, int quiet); + struct dentry *root, unsigned flags); extern int pstore_mkfile(struct dentry *root, struct pstore_record *record); extern bool pstore_is_mounted(void); Index: test_pstore/fs/pstore/platform.c =================================================================== --- test_pstore.orig/fs/pstore/platform.c 2019-03-01 13:55:50.565322897 +0100 +++ test_pstore/fs/pstore/platform.c 2019-03-01 13:59:06.077333431 +0100 @@ -87,6 +87,11 @@ static DECLARE_WORK(pstore_work, pstore_ static DEFINE_SPINLOCK(pstore_lock); struct pstore_info *psinfo; +static int auto_action=0; +module_param(auto_action, int, 0664); +MODULE_PARM_DESC(auto_action, "action to take on backend " + "registration: 0=nothing, 1=print, 2=print+clear"); + static char *backend; static char *compress = #ifdef CONFIG_PSTORE_COMPRESS_DEFAULT @@ -108,6 +113,8 @@ static size_t big_oops_buf_sz; /* How much of the console log to snapshot */ unsigned long kmsg_bytes = PSTORE_DEFAULT_KMSG_BYTES; +module_param(kmsg_bytes, ulong, 0644); +MODULE_PARM_DESC(kmsg_bytes, "maximum size to save of a crash dump"); void pstore_set_kmsg_bytes(int bytes) { @@ -606,7 +613,11 @@ int pstore_register(struct pstore_info * allocate_buf_for_compression(); if (pstore_is_mounted()) - pstore_get_records(0); + pstore_get_records(PGR_VERBOSE|PGR_POPULATE); + + if (auto_action) + pstore_get_records(PGR_SYSLOG| + ((auto_action>1)?PGR_CLEAR:0)); if (psi->flags & PSTORE_FLAGS_DMESG) pstore_register_kmsg(); @@ -723,7 +734,7 @@ static void decompress_record(struct pst * error records. */ void pstore_get_backend_records(struct pstore_info *psi, - struct dentry *root, int quiet) + struct dentry *root, unsigned flags) { int failed = 0; unsigned int stop_loop = 65536; @@ -742,7 +753,7 @@ void pstore_get_backend_records(struct p */ for (; stop_loop; stop_loop--) { struct pstore_record *record; - int rc; + int rc = 0; record = kzalloc(sizeof(*record), GFP_KERNEL); if (!record) { @@ -760,12 +771,23 @@ void pstore_get_backend_records(struct p } decompress_record(record); - rc = pstore_mkfile(root, record); + if (flags & PGR_POPULATE) + rc = pstore_mkfile(root, record); + if (record->type == PSTORE_TYPE_DMESG) { + if (flags & PGR_SYSLOG) { + pr_notice("---------- pstore: ----------\n"); + pr_notice("%.*s\n", (int)record->size, + record->buf); + pr_notice("-----------------------------\n"); + } + if (flags & PGR_CLEAR && psi->erase) + psi->erase(record); + } if (rc) { /* pstore_mkfile() did not take record, so free it. */ kfree(record->buf); kfree(record); - if (rc != -EEXIST || !quiet) + if (rc != -EEXIST || (flags & PGR_VERBOSE)) failed++; } } @@ -784,7 +806,7 @@ out: static void pstore_dowork(struct work_struct *work) { - pstore_get_records(1); + pstore_get_records(PGR_QUIET|PGR_POPULATE); } static void pstore_timefunc(struct timer_list *unused)