linux-efi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Make efi-pstore return a unique id
@ 2013-11-01 16:14 Madper Xie
       [not found] ` <87ppqk6qvx.fsf-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Madper Xie @ 2013-11-01 16:14 UTC (permalink / raw)
  To: Tony Luck, Seiji Aguchi, matt.fleming@intel.com
  Cc: linux-kernel, Linux EFI, bbboson-Re5JQEeQqe8AvxtiuMwx3w


Pstore fs expects that backends provide a uniqued id which could avoid
pstore making entries as duplication or denominating entries the same
name. So I combine the timestamp, part and count into id.

Signed-off-by: Madper Xie <cxie-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 drivers/firmware/efi/efi-pstore.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c
index 5002d50..0de9179 100644
--- a/drivers/firmware/efi/efi-pstore.c
+++ b/drivers/firmware/efi/efi-pstore.c
@@ -39,6 +39,17 @@ struct pstore_read_data {
 	char **buf;
 };
 
+static u64 efi_generate_id(unsigned long timestamp, unsigned int part, int count)
+{
+	char id_str[64];
+	u64 id = 0;
+
+	sprintf(id_str, "%lu%u%d", timestamp, part, count);
+	if (kstrtoull(id_str, 10, &id))
+		pr_warn("efi-pstore: failed to generate id\n");
+	return id;
+}
+
 static int efi_pstore_read_func(struct efivar_entry *entry, void *data)
 {
 	efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
@@ -57,17 +68,18 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data)
 
 	if (sscanf(name, "dump-type%u-%u-%d-%lu-%c",
 		   cb_data->type, &part, &cnt, &time, &data_type) == 5) {
-		*cb_data->id = part;
+		*cb_data->id = efi_generate_id(time, part, cnt);
 		*cb_data->count = cnt;
 		cb_data->timespec->tv_sec = time;
 		cb_data->timespec->tv_nsec = 0;
+
 		if (data_type == 'C')
 			*cb_data->compressed = true;
 		else
 			*cb_data->compressed = false;
 	} else if (sscanf(name, "dump-type%u-%u-%d-%lu",
 		   cb_data->type, &part, &cnt, &time) == 4) {
-		*cb_data->id = part;
+		*cb_data->id = efi_generate_id(time, part, cnt);
 		*cb_data->count = cnt;
 		cb_data->timespec->tv_sec = time;
 		cb_data->timespec->tv_nsec = 0;
@@ -79,7 +91,7 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data)
 		 * which doesn't support holding
 		 * multiple logs, remains.
 		 */
-		*cb_data->id = part;
+		*cb_data->id = efi_generate_id(time, part, 0);
 		*cb_data->count = 0;
 		cb_data->timespec->tv_sec = time;
 		cb_data->timespec->tv_nsec = 0;
@@ -125,9 +137,11 @@ static int efi_pstore_write(enum pstore_type_id type,
 	efi_char16_t efi_name[DUMP_NAME_LEN];
 	efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
 	int i, ret = 0;
+	unsigned long timestamp;
 
+	timestamp = get_seconds();
 	sprintf(name, "dump-type%u-%u-%d-%lu-%c", type, part, count,
-		get_seconds(), compressed ? 'C' : 'D');
+		timestamp, compressed ? 'C' : 'D');
 
 	for (i = 0; i < DUMP_NAME_LEN; i++)
 		efi_name[i] = name[i];
-- 
1.8.4.2

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-11-21 13:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-01 16:14 [PATCH] Make efi-pstore return a unique id Madper Xie
     [not found] ` <87ppqk6qvx.fsf-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-11-01 16:28   ` Richard Weinberger
     [not found]     ` <CAFLxGvz3pCevxE43zGnrbX4MxPmwyb=9MVNpzFRpELt1+AmtrA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-11-01 18:58       ` Tony Luck
     [not found]         ` <CA+8MBbJefz7L-C-LnhAAXB5zf-8XoMPhESPU4yd0wnuZ_YqO1w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-11-01 19:22           ` Seiji Aguchi
     [not found]             ` <A5ED84D3BB3A384992CBB9C77DEDA4D47F9DD941-ohthHghroY0jroPwUH3sq+6wyyQG6/Uh@public.gmane.org>
2013-11-01 20:08               ` Richard Weinberger
2013-11-02  1:15                 ` Madper Xie
     [not found]                 ` <52740A3A.70202-/L3Ra7n9ekc@public.gmane.org>
2013-11-01 20:57                   ` Seiji Aguchi
     [not found]                     ` <A5ED84D3BB3A384992CBB9C77DEDA4D47F9DDA4D-ohthHghroY0jroPwUH3sq+6wyyQG6/Uh@public.gmane.org>
2013-11-02  0:17                       ` Tony Luck
     [not found]                         ` <CA+8MBbKMRw28Ubr5F8U=5SKuaeutR+KEVDgJC70Xebj4O5BzpA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-11-02 12:28                           ` Seiji Aguchi
2013-11-20  9:29                   ` Madper Xie
     [not found]                     ` <87r4abmnfb.fsf-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-11-20 15:17                       ` Seiji Aguchi
     [not found]                         ` <A5ED84D3BB3A384992CBB9C77DEDA4D47FA0B6EF-ohthHghroY0jroPwUH3sq+6wyyQG6/Uh@public.gmane.org>
2013-11-21 13:53                           ` Madper Xie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).