Commit 125cc42b authored by Kees Cook's avatar Kees Cook

pstore: Replace arguments for read() API

The argument list for the pstore_read() interface is unwieldy. This changes
passes the new struct pstore_record instead. The erst backend was already
doing something similar internally.
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent 1edd1aa3
...@@ -442,10 +442,7 @@ static int nvram_pstore_write(enum pstore_type_id type, ...@@ -442,10 +442,7 @@ static int nvram_pstore_write(enum pstore_type_id type,
* Returns the length of the data we read from each partition. * Returns the length of the data we read from each partition.
* Returns 0 if we've been called before. * Returns 0 if we've been called before.
*/ */
static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type, static ssize_t nvram_pstore_read(struct pstore_record *record)
int *count, struct timespec *time, char **buf,
bool *compressed, ssize_t *ecc_notice_size,
struct pstore_info *psi)
{ {
struct oops_log_info *oops_hdr; struct oops_log_info *oops_hdr;
unsigned int err_type, id_no, size = 0; unsigned int err_type, id_no, size = 0;
...@@ -459,40 +456,40 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type, ...@@ -459,40 +456,40 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type,
switch (nvram_type_ids[read_type]) { switch (nvram_type_ids[read_type]) {
case PSTORE_TYPE_DMESG: case PSTORE_TYPE_DMESG:
part = &oops_log_partition; part = &oops_log_partition;
*type = PSTORE_TYPE_DMESG; record->type = PSTORE_TYPE_DMESG;
break; break;
case PSTORE_TYPE_PPC_COMMON: case PSTORE_TYPE_PPC_COMMON:
sig = NVRAM_SIG_SYS; sig = NVRAM_SIG_SYS;
part = &common_partition; part = &common_partition;
*type = PSTORE_TYPE_PPC_COMMON; record->type = PSTORE_TYPE_PPC_COMMON;
*id = PSTORE_TYPE_PPC_COMMON; record->id = PSTORE_TYPE_PPC_COMMON;
time->tv_sec = 0; record->time.tv_sec = 0;
time->tv_nsec = 0; record->time.tv_nsec = 0;
break; break;
#ifdef CONFIG_PPC_PSERIES #ifdef CONFIG_PPC_PSERIES
case PSTORE_TYPE_PPC_RTAS: case PSTORE_TYPE_PPC_RTAS:
part = &rtas_log_partition; part = &rtas_log_partition;
*type = PSTORE_TYPE_PPC_RTAS; record->type = PSTORE_TYPE_PPC_RTAS;
time->tv_sec = last_rtas_event; record->time.tv_sec = last_rtas_event;
time->tv_nsec = 0; record->time.tv_nsec = 0;
break; break;
case PSTORE_TYPE_PPC_OF: case PSTORE_TYPE_PPC_OF:
sig = NVRAM_SIG_OF; sig = NVRAM_SIG_OF;
part = &of_config_partition; part = &of_config_partition;
*type = PSTORE_TYPE_PPC_OF; record->type = PSTORE_TYPE_PPC_OF;
*id = PSTORE_TYPE_PPC_OF; record->id = PSTORE_TYPE_PPC_OF;
time->tv_sec = 0; record->time.tv_sec = 0;
time->tv_nsec = 0; record->time.tv_nsec = 0;
break; break;
#endif #endif
#ifdef CONFIG_PPC_POWERNV #ifdef CONFIG_PPC_POWERNV
case PSTORE_TYPE_PPC_OPAL: case PSTORE_TYPE_PPC_OPAL:
sig = NVRAM_SIG_FW; sig = NVRAM_SIG_FW;
part = &skiboot_partition; part = &skiboot_partition;
*type = PSTORE_TYPE_PPC_OPAL; record->type = PSTORE_TYPE_PPC_OPAL;
*id = PSTORE_TYPE_PPC_OPAL; record->id = PSTORE_TYPE_PPC_OPAL;
time->tv_sec = 0; record->time.tv_sec = 0;
time->tv_nsec = 0; record->time.tv_nsec = 0;
break; break;
#endif #endif
default: default:
...@@ -520,10 +517,10 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type, ...@@ -520,10 +517,10 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type,
return 0; return 0;
} }
*count = 0; record->count = 0;
if (part->os_partition) if (part->os_partition)
*id = id_no; record->id = id_no;
if (nvram_type_ids[read_type] == PSTORE_TYPE_DMESG) { if (nvram_type_ids[read_type] == PSTORE_TYPE_DMESG) {
size_t length, hdr_size; size_t length, hdr_size;
...@@ -533,28 +530,28 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type, ...@@ -533,28 +530,28 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type,
/* Old format oops header had 2-byte record size */ /* Old format oops header had 2-byte record size */
hdr_size = sizeof(u16); hdr_size = sizeof(u16);
length = be16_to_cpu(oops_hdr->version); length = be16_to_cpu(oops_hdr->version);
time->tv_sec = 0; record->time.tv_sec = 0;
time->tv_nsec = 0; record->time.tv_nsec = 0;
} else { } else {
hdr_size = sizeof(*oops_hdr); hdr_size = sizeof(*oops_hdr);
length = be16_to_cpu(oops_hdr->report_length); length = be16_to_cpu(oops_hdr->report_length);
time->tv_sec = be64_to_cpu(oops_hdr->timestamp); record->time.tv_sec = be64_to_cpu(oops_hdr->timestamp);
time->tv_nsec = 0; record->time.tv_nsec = 0;
} }
*buf = kmemdup(buff + hdr_size, length, GFP_KERNEL); record->buf = kmemdup(buff + hdr_size, length, GFP_KERNEL);
kfree(buff); kfree(buff);
if (*buf == NULL) if (record->buf == NULL)
return -ENOMEM; return -ENOMEM;
*ecc_notice_size = 0; record->ecc_notice_size = 0;
if (err_type == ERR_TYPE_KERNEL_PANIC_GZ) if (err_type == ERR_TYPE_KERNEL_PANIC_GZ)
*compressed = true; record->compressed = true;
else else
*compressed = false; record->compressed = false;
return length; return length;
} }
*buf = buff; record->buf = buff;
return part->size; return part->size;
} }
......
...@@ -925,10 +925,7 @@ static int erst_check_table(struct acpi_table_erst *erst_tab) ...@@ -925,10 +925,7 @@ static int erst_check_table(struct acpi_table_erst *erst_tab)
static int erst_open_pstore(struct pstore_info *psi); static int erst_open_pstore(struct pstore_info *psi);
static int erst_close_pstore(struct pstore_info *psi); static int erst_close_pstore(struct pstore_info *psi);
static ssize_t erst_reader(u64 *id, enum pstore_type_id *type, int *count, static ssize_t erst_reader(struct pstore_record *record);
struct timespec *time, char **buf,
bool *compressed, ssize_t *ecc_notice_size,
struct pstore_info *psi);
static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason, static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason,
u64 *id, unsigned int part, int count, bool compressed, u64 *id, unsigned int part, int count, bool compressed,
size_t size, struct pstore_info *psi); size_t size, struct pstore_info *psi);
...@@ -986,10 +983,7 @@ static int erst_close_pstore(struct pstore_info *psi) ...@@ -986,10 +983,7 @@ static int erst_close_pstore(struct pstore_info *psi)
return 0; return 0;
} }
static ssize_t erst_reader(u64 *id, enum pstore_type_id *type, int *count, static ssize_t erst_reader(struct pstore_record *record)
struct timespec *time, char **buf,
bool *compressed, ssize_t *ecc_notice_size,
struct pstore_info *psi)
{ {
int rc; int rc;
ssize_t len = 0; ssize_t len = 0;
...@@ -1027,33 +1021,33 @@ static ssize_t erst_reader(u64 *id, enum pstore_type_id *type, int *count, ...@@ -1027,33 +1021,33 @@ static ssize_t erst_reader(u64 *id, enum pstore_type_id *type, int *count,
if (uuid_le_cmp(rcd->hdr.creator_id, CPER_CREATOR_PSTORE) != 0) if (uuid_le_cmp(rcd->hdr.creator_id, CPER_CREATOR_PSTORE) != 0)
goto skip; goto skip;
*buf = kmalloc(len, GFP_KERNEL); record->buf = kmalloc(len, GFP_KERNEL);
if (*buf == NULL) { if (record->buf == NULL) {
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
} }
memcpy(*buf, rcd->data, len - sizeof(*rcd)); memcpy(record->buf, rcd->data, len - sizeof(*rcd));
*id = record_id; record->id = record_id;
*compressed = false; record->compressed = false;
*ecc_notice_size = 0; record->ecc_notice_size = 0;
if (uuid_le_cmp(rcd->sec_hdr.section_type, if (uuid_le_cmp(rcd->sec_hdr.section_type,
CPER_SECTION_TYPE_DMESG_Z) == 0) { CPER_SECTION_TYPE_DMESG_Z) == 0) {
*type = PSTORE_TYPE_DMESG; record->type = PSTORE_TYPE_DMESG;
*compressed = true; record->compressed = true;
} else if (uuid_le_cmp(rcd->sec_hdr.section_type, } else if (uuid_le_cmp(rcd->sec_hdr.section_type,
CPER_SECTION_TYPE_DMESG) == 0) CPER_SECTION_TYPE_DMESG) == 0)
*type = PSTORE_TYPE_DMESG; record->type = PSTORE_TYPE_DMESG;
else if (uuid_le_cmp(rcd->sec_hdr.section_type, else if (uuid_le_cmp(rcd->sec_hdr.section_type,
CPER_SECTION_TYPE_MCE) == 0) CPER_SECTION_TYPE_MCE) == 0)
*type = PSTORE_TYPE_MCE; record->type = PSTORE_TYPE_MCE;
else else
*type = PSTORE_TYPE_UNKNOWN; record->type = PSTORE_TYPE_UNKNOWN;
if (rcd->hdr.validation_bits & CPER_VALID_TIMESTAMP) if (rcd->hdr.validation_bits & CPER_VALID_TIMESTAMP)
time->tv_sec = rcd->hdr.timestamp; record->time.tv_sec = rcd->hdr.timestamp;
else else
time->tv_sec = 0; record->time.tv_sec = 0;
time->tv_nsec = 0; record->time.tv_nsec = 0;
out: out:
kfree(rcd); kfree(rcd);
......
...@@ -28,26 +28,16 @@ static int efi_pstore_close(struct pstore_info *psi) ...@@ -28,26 +28,16 @@ static int efi_pstore_close(struct pstore_info *psi)
return 0; return 0;
} }
struct pstore_read_data {
u64 *id;
enum pstore_type_id *type;
int *count;
struct timespec *timespec;
bool *compressed;
ssize_t *ecc_notice_size;
char **buf;
};
static inline u64 generic_id(unsigned long timestamp, static inline u64 generic_id(unsigned long timestamp,
unsigned int part, int count) unsigned int part, int count)
{ {
return ((u64) timestamp * 100 + part) * 1000 + count; return ((u64) 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,
struct pstore_record *record)
{ {
efi_guid_t vendor = LINUX_EFI_CRASH_GUID; efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
struct pstore_read_data *cb_data = data;
char name[DUMP_NAME_LEN], data_type; char name[DUMP_NAME_LEN], data_type;
int i; int i;
int cnt; int cnt;
...@@ -61,37 +51,37 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data) ...@@ -61,37 +51,37 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data)
name[i] = entry->var.VariableName[i]; name[i] = entry->var.VariableName[i];
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) { &record->type, &part, &cnt, &time, &data_type) == 5) {
*cb_data->id = generic_id(time, part, cnt); record->id = generic_id(time, part, cnt);
*cb_data->count = cnt; record->count = cnt;
cb_data->timespec->tv_sec = time; record->time.tv_sec = time;
cb_data->timespec->tv_nsec = 0; record->time.tv_nsec = 0;
if (data_type == 'C') if (data_type == 'C')
*cb_data->compressed = true; record->compressed = true;
else else
*cb_data->compressed = false; record->compressed = false;
*cb_data->ecc_notice_size = 0; record->ecc_notice_size = 0;
} 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) { &record->type, &part, &cnt, &time) == 4) {
*cb_data->id = generic_id(time, part, cnt); record->id = generic_id(time, part, cnt);
*cb_data->count = cnt; record->count = cnt;
cb_data->timespec->tv_sec = time; record->time.tv_sec = time;
cb_data->timespec->tv_nsec = 0; record->time.tv_nsec = 0;
*cb_data->compressed = false; record->compressed = false;
*cb_data->ecc_notice_size = 0; record->ecc_notice_size = 0;
} else if (sscanf(name, "dump-type%u-%u-%lu", } else if (sscanf(name, "dump-type%u-%u-%lu",
cb_data->type, &part, &time) == 3) { &record->type, &part, &time) == 3) {
/* /*
* Check if an old format, * Check if an old format,
* which doesn't support holding * which doesn't support holding
* multiple logs, remains. * multiple logs, remains.
*/ */
*cb_data->id = generic_id(time, part, 0); record->id = generic_id(time, part, 0);
*cb_data->count = 0; record->count = 0;
cb_data->timespec->tv_sec = time; record->time.tv_sec = time;
cb_data->timespec->tv_nsec = 0; record->time.tv_nsec = 0;
*cb_data->compressed = false; record->compressed = false;
*cb_data->ecc_notice_size = 0; record->ecc_notice_size = 0;
} else } else
return 0; return 0;
...@@ -99,7 +89,7 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data) ...@@ -99,7 +89,7 @@ static int efi_pstore_read_func(struct efivar_entry *entry, void *data)
__efivar_entry_get(entry, &entry->var.Attributes, __efivar_entry_get(entry, &entry->var.Attributes,
&entry->var.DataSize, entry->var.Data); &entry->var.DataSize, entry->var.Data);
size = entry->var.DataSize; size = entry->var.DataSize;
memcpy(*cb_data->buf, entry->var.Data, memcpy(record->buf, entry->var.Data,
(size_t)min_t(unsigned long, EFIVARS_DATA_SIZE_MAX, size)); (size_t)min_t(unsigned long, EFIVARS_DATA_SIZE_MAX, size));
return size; return size;
...@@ -164,7 +154,7 @@ static int efi_pstore_scan_sysfs_exit(struct efivar_entry *pos, ...@@ -164,7 +154,7 @@ static int efi_pstore_scan_sysfs_exit(struct efivar_entry *pos,
/** /**
* efi_pstore_sysfs_entry_iter * efi_pstore_sysfs_entry_iter
* *
* @data: function-specific data to pass to callback * @record: pstore record to pass to callback
* @pos: entry to begin iterating from * @pos: entry to begin iterating from
* *
* You MUST call efivar_enter_iter_begin() before this function, and * You MUST call efivar_enter_iter_begin() before this function, and
...@@ -175,7 +165,8 @@ static int efi_pstore_scan_sysfs_exit(struct efivar_entry *pos, ...@@ -175,7 +165,8 @@ static int efi_pstore_scan_sysfs_exit(struct efivar_entry *pos,
* the next entry of the last one passed to efi_pstore_read_func(). * the next entry of the last one passed to efi_pstore_read_func().
* To begin iterating from the beginning of the list @pos must be %NULL. * To begin iterating from the beginning of the list @pos must be %NULL.
*/ */
static int efi_pstore_sysfs_entry_iter(void *data, struct efivar_entry **pos) static int efi_pstore_sysfs_entry_iter(struct pstore_record *record,
struct efivar_entry **pos)
{ {
struct efivar_entry *entry, *n; struct efivar_entry *entry, *n;
struct list_head *head = &efivar_sysfs_list; struct list_head *head = &efivar_sysfs_list;
...@@ -186,7 +177,7 @@ static int efi_pstore_sysfs_entry_iter(void *data, struct efivar_entry **pos) ...@@ -186,7 +177,7 @@ static int efi_pstore_sysfs_entry_iter(void *data, struct efivar_entry **pos)
list_for_each_entry_safe(entry, n, head, list) { list_for_each_entry_safe(entry, n, head, list) {
efi_pstore_scan_sysfs_enter(entry, n, head); efi_pstore_scan_sysfs_enter(entry, n, head);
size = efi_pstore_read_func(entry, data); size = efi_pstore_read_func(entry, record);
ret = efi_pstore_scan_sysfs_exit(entry, n, head, ret = efi_pstore_scan_sysfs_exit(entry, n, head,
size < 0); size < 0);
if (ret) if (ret)
...@@ -201,7 +192,7 @@ static int efi_pstore_sysfs_entry_iter(void *data, struct efivar_entry **pos) ...@@ -201,7 +192,7 @@ static int efi_pstore_sysfs_entry_iter(void *data, struct efivar_entry **pos)
list_for_each_entry_safe_from((*pos), n, head, list) { list_for_each_entry_safe_from((*pos), n, head, list) {
efi_pstore_scan_sysfs_enter((*pos), n, head); efi_pstore_scan_sysfs_enter((*pos), n, head);
size = efi_pstore_read_func((*pos), data); size = efi_pstore_read_func((*pos), record);
ret = efi_pstore_scan_sysfs_exit((*pos), n, head, size < 0); ret = efi_pstore_scan_sysfs_exit((*pos), n, head, size < 0);
if (ret) if (ret)
return ret; return ret;
...@@ -225,36 +216,27 @@ static int efi_pstore_sysfs_entry_iter(void *data, struct efivar_entry **pos) ...@@ -225,36 +216,27 @@ static int efi_pstore_sysfs_entry_iter(void *data, struct efivar_entry **pos)
* size < 0: Failed to get data of entry logging via efi_pstore_write(), * size < 0: Failed to get data of entry logging via efi_pstore_write(),
* and pstore will stop reading entry. * and pstore will stop reading entry.
*/ */
static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type, static ssize_t efi_pstore_read(struct pstore_record *record)
int *count, struct timespec *timespec,
char **buf, bool *compressed,
ssize_t *ecc_notice_size,
struct pstore_info *psi)
{ {
struct pstore_read_data data; struct efivar_entry *entry = (struct efivar_entry *)record->psi->data;
ssize_t size; ssize_t size;
data.id = id; record->buf = kzalloc(EFIVARS_DATA_SIZE_MAX, GFP_KERNEL);
data.type = type; if (!record->buf)
data.count = count;
data.timespec = timespec;
data.compressed = compressed;
data.ecc_notice_size = ecc_notice_size;
data.buf = buf;
*data.buf = kzalloc(EFIVARS_DATA_SIZE_MAX, GFP_KERNEL);
if (!*data.buf)
return -ENOMEM; return -ENOMEM;
if (efivar_entry_iter_begin()) { if (efivar_entry_iter_begin()) {
kfree(*data.buf); size = -EINTR;
return -EINTR; goto out;
} }
size = efi_pstore_sysfs_entry_iter(&data, size = efi_pstore_sysfs_entry_iter(record, &entry);
(struct efivar_entry **)&psi->data);
efivar_entry_iter_end(); efivar_entry_iter_end();
if (size <= 0)
kfree(*data.buf); out:
if (size <= 0) {
kfree(record->buf);
record->buf = NULL;
}
return size; return size;
} }
......
...@@ -807,12 +807,7 @@ void pstore_get_records(int quiet) ...@@ -807,12 +807,7 @@ void pstore_get_records(int quiet)
if (psi->open && psi->open(psi)) if (psi->open && psi->open(psi))
goto out; goto out;
while ((record.size = psi->read(&record.id, &record.type, while ((record.size = psi->read(&record)) > 0) {
&record.count, &record.time,
&record.buf, &record.compressed,
&record.ecc_notice_size,
record.psi)) > 0) {
decompress_record(&record); decompress_record(&record);
rc = pstore_mkfile(&record); rc = pstore_mkfile(&record);
......
...@@ -235,35 +235,34 @@ static ssize_t ftrace_log_combine(struct persistent_ram_zone *dest, ...@@ -235,35 +235,34 @@ static ssize_t ftrace_log_combine(struct persistent_ram_zone *dest,
return 0; return 0;
} }
static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, static ssize_t ramoops_pstore_read(struct pstore_record *record)
int *count, struct timespec *time,
char **buf, bool *compressed,
ssize_t *ecc_notice_size,
struct pstore_info *psi)
{ {
ssize_t size = 0; ssize_t size = 0;
struct ramoops_context *cxt = psi->data; struct ramoops_context *cxt = record->psi->data;
struct persistent_ram_zone *prz = NULL; struct persistent_ram_zone *prz = NULL;
int header_length = 0; int header_length = 0;
bool free_prz = false; bool free_prz = false;
/* Ramoops headers provide time stamps for PSTORE_TYPE_DMESG, but /*
* Ramoops headers provide time stamps for PSTORE_TYPE_DMESG, but
* PSTORE_TYPE_CONSOLE and PSTORE_TYPE_FTRACE don't currently have * PSTORE_TYPE_CONSOLE and PSTORE_TYPE_FTRACE don't currently have
* valid time stamps, so it is initialized to zero. * valid time stamps, so it is initialized to zero.
*/ */
time->tv_sec = 0; record->time.tv_sec = 0;
time->tv_nsec = 0; record->time.tv_nsec = 0;
*compressed = false; record->compressed = false;
/* Find the next valid persistent_ram_zone for DMESG */ /* Find the next valid persistent_ram_zone for DMESG */
while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) { while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) {
prz = ramoops_get_next_prz(cxt->dprzs, &cxt->dump_read_cnt, prz = ramoops_get_next_prz(cxt->dprzs, &cxt->dump_read_cnt,
cxt->max_dump_cnt, id, type, cxt->max_dump_cnt, &record->id,
&record->type,
PSTORE_TYPE_DMESG, 1); PSTORE_TYPE_DMESG, 1);
if (!prz_ok(prz)) if (!prz_ok(prz))
continue; continue;
header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz), header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz),
time, compressed); &record->time,
&record->compressed);
/* Clear and skip this DMESG record if it has no valid header */ /* Clear and skip this DMESG record if it has no valid header */
if (!header_length) { if (!header_length) {
persistent_ram_free_old(prz); persistent_ram_free_old(prz);
...@@ -274,18 +273,20 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, ...@@ -274,18 +273,20 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
if (!prz_ok(prz)) if (!prz_ok(prz))
prz = ramoops_get_next_prz(&cxt->cprz, &cxt->console_read_cnt, prz = ramoops_get_next_prz(&cxt->cprz, &cxt->console_read_cnt,
1, id, type, PSTORE_TYPE_CONSOLE, 0); 1, &record->id, &record->type,
PSTORE_TYPE_CONSOLE, 0);
if (!prz_ok(prz)) if (!prz_ok(prz))
prz = ramoops_get_next_prz(&cxt->mprz, &cxt->pmsg_read_cnt, prz = ramoops_get_next_prz(&cxt->mprz, &cxt->pmsg_read_cnt,
1, id, type, PSTORE_TYPE_PMSG, 0); 1, &record->id, &record->type,
PSTORE_TYPE_PMSG, 0);
/* ftrace is last since it may want to dynamically allocate memory. */ /* ftrace is last since it may want to dynamically allocate memory. */
if (!prz_ok(prz)) { if (!prz_ok(prz)) {
if (!(cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU)) { if (!(cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU)) {
prz = ramoops_get_next_prz(cxt->fprzs, prz = ramoops_get_next_prz(cxt->fprzs,
&cxt->ftrace_read_cnt, 1, id, type, &cxt->ftrace_read_cnt, 1, &record->id,
PSTORE_TYPE_FTRACE, 0); &record->type, PSTORE_TYPE_FTRACE, 0);
} else { } else {
/* /*
* Build a new dummy record which combines all the * Build a new dummy record which combines all the
...@@ -302,8 +303,10 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, ...@@ -302,8 +303,10 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
while (cxt->ftrace_read_cnt < cxt->max_ftrace_cnt) { while (cxt->ftrace_read_cnt < cxt->max_ftrace_cnt) {
prz_next = ramoops_get_next_prz(cxt->fprzs, prz_next = ramoops_get_next_prz(cxt->fprzs,
&cxt->ftrace_read_cnt, &cxt->ftrace_read_cnt,
cxt->max_ftrace_cnt, id, cxt->max_ftrace_cnt,
type, PSTORE_TYPE_FTRACE, 0); &record->id,
&record->type,
PSTORE_TYPE_FTRACE, 0);
if (!prz_ok(prz_next)) if (!prz_ok(prz_next))
continue; continue;
...@@ -316,7 +319,7 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, ...@@ -316,7 +319,7 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
if (size) if (size)
goto out; goto out;
} }
*id = 0; record->id = 0;
prz = tmp_prz; prz = tmp_prz;
} }
} }
...@@ -329,17 +332,19 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, ...@@ -329,17 +332,19 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
size = persistent_ram_old_size(prz) - header_length; size = persistent_ram_old_size(prz) - header_length;
/* ECC correction notice */ /* ECC correction notice */
*ecc_notice_size = persistent_ram_ecc_string(prz, NULL, 0); record->ecc_notice_size = persistent_ram_ecc_string(prz, NULL, 0);
*buf = kmalloc(size + *ecc_notice_size + 1, GFP_KERNEL); record->buf = kmalloc(size + record->ecc_notice_size + 1, GFP_KERNEL);
if (*buf == NULL) { if (record->buf == NULL) {
size = -ENOMEM; size = -ENOMEM;
goto out; goto out;
} }
memcpy(*buf, (char *)persistent_ram_old(prz) + header_length, size); memcpy(record->buf, (char *)persistent_ram_old(prz) + header_length,
size);
persistent_ram_ecc_string(prz, *buf + size, *ecc_notice_size + 1); persistent_ram_ecc_string(prz, record->buf + size,
record->ecc_notice_size + 1);
out: out:
if (free_prz) { if (free_prz) {
......
...@@ -111,16 +111,11 @@ struct pstore_record { ...@@ -111,16 +111,11 @@ struct pstore_record {
* Read next available backend record. Called after a successful * Read next available backend record. Called after a successful
* @open. * @open.
* *
* @id: out: unique identifier for the record * @record:
* @type: out: pstore record type * pointer to record to populate. @buf should be allocated
* @count: out: for PSTORE_TYPE_DMESG, the Oops count. * by the backend and filled. At least @type and @id should
* @time: out: timestamp for the record * be populated, since these are used when creating pstorefs
* @buf: out: kmalloc copy of record contents, to be freed by pstore * file names.
* @compressed:
* out: if the record contents are compressed
* @ecc_notice_size:
* out: ECC information
* @psi: in: pointer to the struct pstore_info for the backend
* *
* Returns record size on success, zero when no more records are * Returns record size on success, zero when no more records are
* available, or negative on error. * available, or negative on error.
...@@ -207,10 +202,7 @@ struct pstore_info { ...@@ -207,10 +202,7 @@ struct pstore_info {
int (*open)(struct pstore_info *psi); int (*open)(struct pstore_info *psi);
int (*close)(struct pstore_info *psi); int (*close)(struct pstore_info *psi);
ssize_t (*read)(u64 *id, enum pstore_type_id *type, ssize_t (*read)(struct pstore_record *record);
int *count, struct timespec *time, char **buf,
bool *compressed, ssize_t *ecc_notice_size,
struct pstore_info *psi);
int (*write)(enum pstore_type_id type, int (*write)(enum pstore_type_id type,
enum kmsg_dump_reason reason, u64 *id, enum kmsg_dump_reason reason, u64 *id,
unsigned int part, int count, bool compressed, unsigned int part, int count, bool compressed,
......
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