From: Ankit Kumar <ankit@linux.vnet.ibm.com>
To: keescook@chromium.org, anton@enomsg.org, ccross@android.com,
tony.luck@intel.com
Cc: linux-kernel@vger.kernel.org, mahesh@linux.vnet.ibm.com,
Ankit Kumar <ankit@linux.vnet.ibm.com>
Subject: [PATCH] Save current timestamp while moving oops message to nvram
Date: Wed, 12 Apr 2017 20:02:44 +0530 [thread overview]
Message-ID: <1492007564-7593-1-git-send-email-ankit@linux.vnet.ibm.com> (raw)
Currently on panic or Oops, kernel saves the last few bytes from dmesg
buffer to nvram. Usually kdump does capture kernel memory and provide
dmesg logs as well. But in some cases where kdump fails to capture
vmcore, the dmesg buffer stored in nvram/pstore turns out to be very
helpful in analyzing root cause.
But currently there is no way to figure out when the last dmesg was
captured on pstore. Hence enhance the pstore to also capture and save
current timestamp in human readable format as initial few bytes while
capturing dmesg buffer.
This patch enhances pstore write code to also capture and save current
timestamp in human readable format as initial few bytes while capturing
dmesg buffer.
It saves timestamp in UTC format following ISO-8601 standard. As per
ISO-8601 the 'Z' suffix to timestamp indicates UTC timeoffset.
Ref: https://en.wikipedia.org/wiki/ISO_8601#UTC
We can use date -d <PSTORE_LOGGED_TIME> command to print time according
to local time zone.
Partial pstore dump after applying this patch:
Oops#1 Part1 [2017-04-12T14:14:56Z]
Above time can be printed in current time zone using date -d command.
#date -d 2017-04-12T14:14:56Z
Wed Apr 12 19:44:56 IST 2017
Signed-off-by: Ankit Kumar <ankit@linux.vnet.ibm.com>
---
Changelog since v3:
- Printed value in ISO 8601 standard.
- Replaced sprintf with snprintf.
- Reduced time buffer size to 32.
fs/pstore/platform.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index efab7b6..f4017c5 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -44,6 +44,7 @@
#include <linux/hardirq.h>
#include <linux/jiffies.h>
#include <linux/workqueue.h>
+#include <linux/time.h>
#include "internal.h"
@@ -475,6 +476,28 @@ static size_t copy_kmsg_to_buffer(int hsize, size_t len)
}
/*
+ * description: It fills buffer with current time(in ISO 8601 standard)
+ * @param : buffer needs to be filled.
+ * @param : size of buffer.
+ * return : void
+ */
+static void get_curr_time(char *loc_time, int time_buf_size)
+{
+ struct timeval now;
+ struct tm tm_val;
+
+ if (!loc_time)
+ return;
+
+ do_gettimeofday(&now);
+ time_to_tm(now.tv_sec, 0, &tm_val);
+
+ snprintf(loc_time, time_buf_size - 1, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2dZ",
+ (int)(1900 + tm_val.tm_year), tm_val.tm_mon + 1,
+ tm_val.tm_mday, tm_val.tm_hour, tm_val.tm_min, tm_val.tm_sec);
+}
+
+/*
* callback from kmsg_dump. (s2,l2) has the most recently
* written bytes, older bytes are in (s1,l1). Save as much
* as we can from the end of the buffer.
@@ -489,6 +512,7 @@ static void pstore_dump(struct kmsg_dumper *dumper,
unsigned long flags = 0;
int is_locked;
int ret;
+ char loc_time[32];
why = get_reason_str(reason);
@@ -521,7 +545,10 @@ static void pstore_dump(struct kmsg_dumper *dumper,
size = psinfo->bufsize;
}
- hsize = sprintf(dst, "%s#%d Part%u\n", why, oopscount, part);
+ memset(loc_time, 0, sizeof(loc_time));
+ get_curr_time(loc_time, sizeof(loc_time));
+ hsize = sprintf(dst, "%s#%d Part%u [%s]\n", why, oopscount,
+ part, loc_time);
size -= hsize;
if (!kmsg_dump_get_buffer(dumper, true, dst + hsize,
--
2.7.4
next reply other threads:[~2017-04-12 14:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-12 14:32 Ankit Kumar [this message]
2017-04-13 19:26 ` [PATCH] Save current timestamp while moving oops message to nvram Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1492007564-7593-1-git-send-email-ankit@linux.vnet.ibm.com \
--to=ankit@linux.vnet.ibm.com \
--cc=anton@enomsg.org \
--cc=ccross@android.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mahesh@linux.vnet.ibm.com \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.