Commit fdeadb43 authored by Madper Xie's avatar Madper Xie Committed by Matt Fleming

efi-pstore: Make efi-pstore return a unique id

Pstore fs expects that backends provide a unique 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: default avatarMadper Xie <cxie@redhat.com>
Cc: Seiji Aguchi <seiji.aguchi@hds.com>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarMatt Fleming <matt.fleming@intel.com>
parent 1f3a8bae
...@@ -37,6 +37,12 @@ struct pstore_read_data { ...@@ -37,6 +37,12 @@ struct pstore_read_data {
char **buf; char **buf;
}; };
static inline u64 generic_id(unsigned long timestamp,
unsigned int part, int count)
{
return (timestamp * 100 + part) * 1000 + count;
}
static int efi_pstore_read_func(struct efivar_entry *entry, void *data) static int efi_pstore_read_func(struct efivar_entry *entry, void *data)
{ {
efi_guid_t vendor = LINUX_EFI_CRASH_GUID; efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
...@@ -55,7 +61,7 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data) ...@@ -55,7 +61,7 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data)
if (sscanf(name, "dump-type%u-%u-%d-%lu-%c", if (sscanf(name, "dump-type%u-%u-%d-%lu-%c",
cb_data->type, &part, &cnt, &time, &data_type) == 5) { cb_data->type, &part, &cnt, &time, &data_type) == 5) {
*cb_data->id = part; *cb_data->id = generic_id(time, part, cnt);
*cb_data->count = cnt; *cb_data->count = cnt;
cb_data->timespec->tv_sec = time; cb_data->timespec->tv_sec = time;
cb_data->timespec->tv_nsec = 0; cb_data->timespec->tv_nsec = 0;
...@@ -65,7 +71,7 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data) ...@@ -65,7 +71,7 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data)
*cb_data->compressed = false; *cb_data->compressed = false;
} else if (sscanf(name, "dump-type%u-%u-%d-%lu", } else if (sscanf(name, "dump-type%u-%u-%d-%lu",
cb_data->type, &part, &cnt, &time) == 4) { cb_data->type, &part, &cnt, &time) == 4) {
*cb_data->id = part; *cb_data->id = generic_id(time, part, cnt);
*cb_data->count = cnt; *cb_data->count = cnt;
cb_data->timespec->tv_sec = time; cb_data->timespec->tv_sec = time;
cb_data->timespec->tv_nsec = 0; cb_data->timespec->tv_nsec = 0;
...@@ -77,7 +83,7 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data) ...@@ -77,7 +83,7 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data)
* which doesn't support holding * which doesn't support holding
* multiple logs, remains. * multiple logs, remains.
*/ */
*cb_data->id = part; *cb_data->id = generic_id(time, part, 0);
*cb_data->count = 0; *cb_data->count = 0;
cb_data->timespec->tv_sec = time; cb_data->timespec->tv_sec = time;
cb_data->timespec->tv_nsec = 0; cb_data->timespec->tv_nsec = 0;
...@@ -320,14 +326,16 @@ static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count, ...@@ -320,14 +326,16 @@ static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count,
char name[DUMP_NAME_LEN]; char name[DUMP_NAME_LEN];
efi_char16_t efi_name[DUMP_NAME_LEN]; efi_char16_t efi_name[DUMP_NAME_LEN];
int found, i; int found, i;
unsigned int part;
sprintf(name, "dump-type%u-%u-%d-%lu", type, (unsigned int)id, count, do_div(id, 1000);
time.tv_sec); part = do_div(id, 100);
sprintf(name, "dump-type%u-%u-%d-%lu", type, part, count, time.tv_sec);
for (i = 0; i < DUMP_NAME_LEN; i++) for (i = 0; i < DUMP_NAME_LEN; i++)
efi_name[i] = name[i]; efi_name[i] = name[i];
edata.id = id; edata.id = part;
edata.type = type; edata.type = type;
edata.count = count; edata.count = count;
edata.time = time; edata.time = time;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment