mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-26 02:39:48 +00:00
Patch series to allow EFI variable backend to pstore
to hold multiple records. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAABAgAGBQJQxjFJAAoJEKurIx+X31iBNssQAKCjiXe7dT8DigoKSPj3w1sJ 8xcuJKmlZ5ykgElfQ1Lcfuz0KuMT8SZfBHrRCL389Yvtxq71NL9pMX1OyCqyfVyO uuKWD/+jVc5d11F15hC2l8zIU7v2S3TXQ64rZEgDDFXIPlTbEcEBy92arpq6Avj3 6ioR+rf4jvOeC66keIcDOIl6r4tVn2f16B9Z6ffSOit0dVeRAOc7bB9LLaohETSY rCSKHgZLHBZRQv2yGKS3LB6KSL2DVm+lgNhzAVw4kEJNTJl04clK854L8EM7WfGj qREsvSUB4H4I2XMBW+HCU/6+4c4alSEr/2c8+xBeynL4+I2y+VLwySkwE+8DPgEV BjCuyjSmpZVuVz6R28hcJIbkK0sN1gntXitb2V157+89f3gVEMYwKaY787TuNl9g oWYjjeOk66r5xshdVvCnFIgZxgFItznn+kgRkNq0clGH+nWVsZfuYw/q2PLm9xoM TJR+ZZwMJC25TE99rh9CqVc0kuQi5SXfqjpd+fW8oJ2kSxj4/7SqmOpmK7oWLFNi kf0xS1yVsQB5mRx3nvERvA36lzNSiQRFXnMjh84be4NX8dYqiGoJQjOh/laemjxd 8hpoMVuUMtXLC4roejyyLwddtTLshWm2ByULAHJRJpuUKzichkaqhuvvkMUjKfDj NunMg/OfNs78sTlNSATf =NAdA -----END PGP SIGNATURE----- Merge tag 'please-pull-pstore_mevent' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux Pull pstore fixes from Tony Luck: "Patch series to allow EFI variable backend to pstore to hold multiple records." * tag 'please-pull-pstore_mevent' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux: efi_pstore: Add a format check for an existing variable name at erasing time efi_pstore: Add a format check for an existing variable name at reading time efi_pstore: Add a sequence counter to a variable name efi_pstore: Add ctime to argument of erase callback efi_pstore: Remove a logic erasing entries from a write callback to hold multiple logs efi_pstore: Add a logic erasing entries to an erase callback efi_pstore: Check remaining space with QueryVariableInfo() before writing data
This commit is contained in:
commit
251a8cfeda
8 changed files with 148 additions and 77 deletions
|
@ -931,14 +931,14 @@ static int erst_check_table(struct acpi_table_erst *erst_tab)
|
|||
|
||||
static int erst_open_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,
|
||||
static ssize_t erst_reader(u64 *id, enum pstore_type_id *type, int *count,
|
||||
struct timespec *time, char **buf,
|
||||
struct pstore_info *psi);
|
||||
static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason,
|
||||
u64 *id, unsigned int part,
|
||||
u64 *id, unsigned int part, int count,
|
||||
size_t size, struct pstore_info *psi);
|
||||
static int erst_clearer(enum pstore_type_id type, u64 id,
|
||||
struct pstore_info *psi);
|
||||
static int erst_clearer(enum pstore_type_id type, u64 id, int count,
|
||||
struct timespec time, struct pstore_info *psi);
|
||||
|
||||
static struct pstore_info erst_info = {
|
||||
.owner = THIS_MODULE,
|
||||
|
@ -987,7 +987,7 @@ static int erst_close_pstore(struct pstore_info *psi)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
|
||||
static ssize_t erst_reader(u64 *id, enum pstore_type_id *type, int *count,
|
||||
struct timespec *time, char **buf,
|
||||
struct pstore_info *psi)
|
||||
{
|
||||
|
@ -1055,7 +1055,7 @@ static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
|
|||
}
|
||||
|
||||
static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason,
|
||||
u64 *id, unsigned int part,
|
||||
u64 *id, unsigned int part, int count,
|
||||
size_t size, struct pstore_info *psi)
|
||||
{
|
||||
struct cper_pstore_record *rcd = (struct cper_pstore_record *)
|
||||
|
@ -1101,8 +1101,8 @@ static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int erst_clearer(enum pstore_type_id type, u64 id,
|
||||
struct pstore_info *psi)
|
||||
static int erst_clearer(enum pstore_type_id type, u64 id, int count,
|
||||
struct timespec time, struct pstore_info *psi)
|
||||
{
|
||||
return erst_clear(id);
|
||||
}
|
||||
|
|
|
@ -658,13 +658,14 @@ static int efi_pstore_close(struct pstore_info *psi)
|
|||
}
|
||||
|
||||
static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
|
||||
struct timespec *timespec,
|
||||
int *count, struct timespec *timespec,
|
||||
char **buf, struct pstore_info *psi)
|
||||
{
|
||||
efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
|
||||
struct efivars *efivars = psi->data;
|
||||
char name[DUMP_NAME_LEN];
|
||||
int i;
|
||||
int cnt;
|
||||
unsigned int part, size;
|
||||
unsigned long time;
|
||||
|
||||
|
@ -674,21 +675,41 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
|
|||
for (i = 0; i < DUMP_NAME_LEN; i++) {
|
||||
name[i] = efivars->walk_entry->var.VariableName[i];
|
||||
}
|
||||
if (sscanf(name, "dump-type%u-%u-%lu", type, &part, &time) == 3) {
|
||||
if (sscanf(name, "dump-type%u-%u-%d-%lu",
|
||||
type, &part, &cnt, &time) == 4) {
|
||||
*id = part;
|
||||
*count = cnt;
|
||||
timespec->tv_sec = time;
|
||||
timespec->tv_nsec = 0;
|
||||
get_var_data_locked(efivars, &efivars->walk_entry->var);
|
||||
size = efivars->walk_entry->var.DataSize;
|
||||
*buf = kmalloc(size, GFP_KERNEL);
|
||||
if (*buf == NULL)
|
||||
return -ENOMEM;
|
||||
memcpy(*buf, efivars->walk_entry->var.Data,
|
||||
size);
|
||||
efivars->walk_entry = list_entry(efivars->walk_entry->list.next,
|
||||
struct efivar_entry, list);
|
||||
return size;
|
||||
} else if (sscanf(name, "dump-type%u-%u-%lu",
|
||||
type, &part, &time) == 3) {
|
||||
/*
|
||||
* Check if an old format,
|
||||
* which doesn't support holding
|
||||
* multiple logs, remains.
|
||||
*/
|
||||
*id = part;
|
||||
*count = 0;
|
||||
timespec->tv_sec = time;
|
||||
timespec->tv_nsec = 0;
|
||||
} else {
|
||||
efivars->walk_entry = list_entry(
|
||||
efivars->walk_entry->list.next,
|
||||
struct efivar_entry, list);
|
||||
continue;
|
||||
}
|
||||
|
||||
get_var_data_locked(efivars, &efivars->walk_entry->var);
|
||||
size = efivars->walk_entry->var.DataSize;
|
||||
*buf = kmalloc(size, GFP_KERNEL);
|
||||
if (*buf == NULL)
|
||||
return -ENOMEM;
|
||||
memcpy(*buf, efivars->walk_entry->var.Data,
|
||||
size);
|
||||
efivars->walk_entry = list_entry(
|
||||
efivars->walk_entry->list.next,
|
||||
struct efivar_entry, list);
|
||||
return size;
|
||||
}
|
||||
efivars->walk_entry = list_entry(efivars->walk_entry->list.next,
|
||||
struct efivar_entry, list);
|
||||
|
@ -698,50 +719,36 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
|
|||
|
||||
static int efi_pstore_write(enum pstore_type_id type,
|
||||
enum kmsg_dump_reason reason, u64 *id,
|
||||
unsigned int part, size_t size, struct pstore_info *psi)
|
||||
unsigned int part, int count, size_t size,
|
||||
struct pstore_info *psi)
|
||||
{
|
||||
char name[DUMP_NAME_LEN];
|
||||
char stub_name[DUMP_NAME_LEN];
|
||||
efi_char16_t efi_name[DUMP_NAME_LEN];
|
||||
efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
|
||||
struct efivars *efivars = psi->data;
|
||||
struct efivar_entry *entry, *found = NULL;
|
||||
int i, ret = 0;
|
||||
|
||||
sprintf(stub_name, "dump-type%u-%u-", type, part);
|
||||
sprintf(name, "%s%lu", stub_name, get_seconds());
|
||||
u64 storage_space, remaining_space, max_variable_size;
|
||||
efi_status_t status = EFI_NOT_FOUND;
|
||||
|
||||
spin_lock(&efivars->lock);
|
||||
|
||||
for (i = 0; i < DUMP_NAME_LEN; i++)
|
||||
efi_name[i] = stub_name[i];
|
||||
|
||||
/*
|
||||
* Clean up any entries with the same name
|
||||
* Check if there is a space enough to log.
|
||||
* size: a size of logging data
|
||||
* DUMP_NAME_LEN * 2: a maximum size of variable name
|
||||
*/
|
||||
|
||||
list_for_each_entry(entry, &efivars->list, list) {
|
||||
get_var_data_locked(efivars, &entry->var);
|
||||
|
||||
if (efi_guidcmp(entry->var.VendorGuid, vendor))
|
||||
continue;
|
||||
if (utf16_strncmp(entry->var.VariableName, efi_name,
|
||||
utf16_strlen(efi_name)))
|
||||
continue;
|
||||
/* Needs to be a prefix */
|
||||
if (entry->var.VariableName[utf16_strlen(efi_name)] == 0)
|
||||
continue;
|
||||
|
||||
/* found */
|
||||
found = entry;
|
||||
efivars->ops->set_variable(entry->var.VariableName,
|
||||
&entry->var.VendorGuid,
|
||||
PSTORE_EFI_ATTRIBUTES,
|
||||
0, NULL);
|
||||
status = efivars->ops->query_variable_info(PSTORE_EFI_ATTRIBUTES,
|
||||
&storage_space,
|
||||
&remaining_space,
|
||||
&max_variable_size);
|
||||
if (status || remaining_space < size + DUMP_NAME_LEN * 2) {
|
||||
spin_unlock(&efivars->lock);
|
||||
*id = part;
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
if (found)
|
||||
list_del(&found->list);
|
||||
sprintf(name, "dump-type%u-%u-%d-%lu", type, part, count,
|
||||
get_seconds());
|
||||
|
||||
for (i = 0; i < DUMP_NAME_LEN; i++)
|
||||
efi_name[i] = name[i];
|
||||
|
@ -751,9 +758,6 @@ static int efi_pstore_write(enum pstore_type_id type,
|
|||
|
||||
spin_unlock(&efivars->lock);
|
||||
|
||||
if (found)
|
||||
efivar_unregister(found);
|
||||
|
||||
if (size)
|
||||
ret = efivar_create_sysfs_entry(efivars,
|
||||
utf16_strsize(efi_name,
|
||||
|
@ -764,10 +768,69 @@ static int efi_pstore_write(enum pstore_type_id type,
|
|||
return ret;
|
||||
};
|
||||
|
||||
static int efi_pstore_erase(enum pstore_type_id type, u64 id,
|
||||
struct pstore_info *psi)
|
||||
static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count,
|
||||
struct timespec time, struct pstore_info *psi)
|
||||
{
|
||||
efi_pstore_write(type, 0, &id, (unsigned int)id, 0, psi);
|
||||
char name[DUMP_NAME_LEN];
|
||||
efi_char16_t efi_name[DUMP_NAME_LEN];
|
||||
char name_old[DUMP_NAME_LEN];
|
||||
efi_char16_t efi_name_old[DUMP_NAME_LEN];
|
||||
efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
|
||||
struct efivars *efivars = psi->data;
|
||||
struct efivar_entry *entry, *found = NULL;
|
||||
int i;
|
||||
|
||||
sprintf(name, "dump-type%u-%u-%d-%lu", type, (unsigned int)id, count,
|
||||
time.tv_sec);
|
||||
|
||||
spin_lock(&efivars->lock);
|
||||
|
||||
for (i = 0; i < DUMP_NAME_LEN; i++)
|
||||
efi_name[i] = name[i];
|
||||
|
||||
/*
|
||||
* Clean up an entry with the same name
|
||||
*/
|
||||
|
||||
list_for_each_entry(entry, &efivars->list, list) {
|
||||
get_var_data_locked(efivars, &entry->var);
|
||||
|
||||
if (efi_guidcmp(entry->var.VendorGuid, vendor))
|
||||
continue;
|
||||
if (utf16_strncmp(entry->var.VariableName, efi_name,
|
||||
utf16_strlen(efi_name))) {
|
||||
/*
|
||||
* Check if an old format,
|
||||
* which doesn't support holding
|
||||
* multiple logs, remains.
|
||||
*/
|
||||
sprintf(name_old, "dump-type%u-%u-%lu", type,
|
||||
(unsigned int)id, time.tv_sec);
|
||||
|
||||
for (i = 0; i < DUMP_NAME_LEN; i++)
|
||||
efi_name_old[i] = name_old[i];
|
||||
|
||||
if (utf16_strncmp(entry->var.VariableName, efi_name_old,
|
||||
utf16_strlen(efi_name_old)))
|
||||
continue;
|
||||
}
|
||||
|
||||
/* found */
|
||||
found = entry;
|
||||
efivars->ops->set_variable(entry->var.VariableName,
|
||||
&entry->var.VendorGuid,
|
||||
PSTORE_EFI_ATTRIBUTES,
|
||||
0, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
if (found)
|
||||
list_del(&found->list);
|
||||
|
||||
spin_unlock(&efivars->lock);
|
||||
|
||||
if (found)
|
||||
efivar_unregister(found);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -782,7 +845,7 @@ static int efi_pstore_close(struct pstore_info *psi)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
|
||||
static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type, int *count,
|
||||
struct timespec *timespec,
|
||||
char **buf, struct pstore_info *psi)
|
||||
{
|
||||
|
@ -791,13 +854,14 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
|
|||
|
||||
static int efi_pstore_write(enum pstore_type_id type,
|
||||
enum kmsg_dump_reason reason, u64 *id,
|
||||
unsigned int part, size_t size, struct pstore_info *psi)
|
||||
unsigned int part, int count, size_t size,
|
||||
struct pstore_info *psi)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int efi_pstore_erase(enum pstore_type_id type, u64 id,
|
||||
struct pstore_info *psi)
|
||||
static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count,
|
||||
struct timespec time, struct pstore_info *psi)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -1237,6 +1301,7 @@ efivars_init(void)
|
|||
ops.get_variable = efi.get_variable;
|
||||
ops.set_variable = efi.set_variable;
|
||||
ops.get_next_variable = efi.get_next_variable;
|
||||
ops.query_variable_info = efi.query_variable_info;
|
||||
error = register_efivars(&__efivars, &ops, efi_kobj);
|
||||
if (error)
|
||||
goto err_put;
|
||||
|
|
|
@ -49,6 +49,7 @@ struct pstore_private {
|
|||
struct pstore_info *psi;
|
||||
enum pstore_type_id type;
|
||||
u64 id;
|
||||
int count;
|
||||
ssize_t size;
|
||||
char data[];
|
||||
};
|
||||
|
@ -175,7 +176,8 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
|
|||
struct pstore_private *p = dentry->d_inode->i_private;
|
||||
|
||||
if (p->psi->erase)
|
||||
p->psi->erase(p->type, p->id, p->psi);
|
||||
p->psi->erase(p->type, p->id, p->count,
|
||||
dentry->d_inode->i_ctime, p->psi);
|
||||
|
||||
return simple_unlink(dir, dentry);
|
||||
}
|
||||
|
@ -270,7 +272,7 @@ int pstore_is_mounted(void)
|
|||
* Load it up with "size" bytes of data from "buf".
|
||||
* Set the mtime & ctime to the date that this record was originally stored.
|
||||
*/
|
||||
int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
|
||||
int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count,
|
||||
char *data, size_t size, struct timespec time,
|
||||
struct pstore_info *psi)
|
||||
{
|
||||
|
@ -306,6 +308,7 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id,
|
|||
goto fail_alloc;
|
||||
private->type = type;
|
||||
private->id = id;
|
||||
private->count = count;
|
||||
private->psi = psi;
|
||||
|
||||
switch (type) {
|
||||
|
|
|
@ -50,7 +50,7 @@ extern struct pstore_info *psinfo;
|
|||
extern void pstore_set_kmsg_bytes(int);
|
||||
extern void pstore_get_records(int);
|
||||
extern int pstore_mkfile(enum pstore_type_id, char *psname, u64 id,
|
||||
char *data, size_t size,
|
||||
int count, char *data, size_t size,
|
||||
struct timespec time, struct pstore_info *psi);
|
||||
extern int pstore_is_mounted(void);
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ static void pstore_dump(struct kmsg_dumper *dumper,
|
|||
break;
|
||||
|
||||
ret = psinfo->write(PSTORE_TYPE_DMESG, reason, &id, part,
|
||||
hsize + len, psinfo);
|
||||
oopscount, hsize + len, psinfo);
|
||||
if (ret == 0 && reason == KMSG_DUMP_OOPS && pstore_is_mounted())
|
||||
pstore_new_entry = 1;
|
||||
|
||||
|
@ -173,7 +173,7 @@ static void pstore_console_write(struct console *con, const char *s, unsigned c)
|
|||
spin_lock_irqsave(&psinfo->buf_lock, flags);
|
||||
}
|
||||
memcpy(psinfo->buf, s, c);
|
||||
psinfo->write(PSTORE_TYPE_CONSOLE, 0, &id, 0, c, psinfo);
|
||||
psinfo->write(PSTORE_TYPE_CONSOLE, 0, &id, 0, 0, c, psinfo);
|
||||
spin_unlock_irqrestore(&psinfo->buf_lock, flags);
|
||||
s += c;
|
||||
c = e - s;
|
||||
|
@ -197,7 +197,7 @@ static void pstore_register_console(void) {}
|
|||
|
||||
static int pstore_write_compat(enum pstore_type_id type,
|
||||
enum kmsg_dump_reason reason,
|
||||
u64 *id, unsigned int part,
|
||||
u64 *id, unsigned int part, int count,
|
||||
size_t size, struct pstore_info *psi)
|
||||
{
|
||||
return psi->write_buf(type, reason, id, part, psinfo->buf, size, psi);
|
||||
|
@ -267,6 +267,7 @@ void pstore_get_records(int quiet)
|
|||
char *buf = NULL;
|
||||
ssize_t size;
|
||||
u64 id;
|
||||
int count;
|
||||
enum pstore_type_id type;
|
||||
struct timespec time;
|
||||
int failed = 0, rc;
|
||||
|
@ -278,9 +279,9 @@ void pstore_get_records(int quiet)
|
|||
if (psi->open && psi->open(psi))
|
||||
goto out;
|
||||
|
||||
while ((size = psi->read(&id, &type, &time, &buf, psi)) > 0) {
|
||||
rc = pstore_mkfile(type, psi->name, id, buf, (size_t)size,
|
||||
time, psi);
|
||||
while ((size = psi->read(&id, &type, &count, &time, &buf, psi)) > 0) {
|
||||
rc = pstore_mkfile(type, psi->name, id, count, buf,
|
||||
(size_t)size, time, psi);
|
||||
kfree(buf);
|
||||
buf = NULL;
|
||||
if (rc && (rc != -EEXIST || !quiet))
|
||||
|
|
|
@ -132,9 +132,8 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,
|
|||
}
|
||||
|
||||
static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
|
||||
struct timespec *time,
|
||||
char **buf,
|
||||
struct pstore_info *psi)
|
||||
int *count, struct timespec *time,
|
||||
char **buf, struct pstore_info *psi)
|
||||
{
|
||||
ssize_t size;
|
||||
struct ramoops_context *cxt = psi->data;
|
||||
|
@ -236,8 +235,8 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int ramoops_pstore_erase(enum pstore_type_id type, u64 id,
|
||||
struct pstore_info *psi)
|
||||
static int ramoops_pstore_erase(enum pstore_type_id type, u64 id, int count,
|
||||
struct timespec time, struct pstore_info *psi)
|
||||
{
|
||||
struct ramoops_context *cxt = psi->data;
|
||||
struct persistent_ram_zone *prz;
|
||||
|
|
|
@ -643,6 +643,7 @@ struct efivar_operations {
|
|||
efi_get_variable_t *get_variable;
|
||||
efi_get_next_variable_t *get_next_variable;
|
||||
efi_set_variable_t *set_variable;
|
||||
efi_query_variable_info_t *query_variable_info;
|
||||
};
|
||||
|
||||
struct efivars {
|
||||
|
|
|
@ -50,16 +50,18 @@ struct pstore_info {
|
|||
int (*open)(struct pstore_info *psi);
|
||||
int (*close)(struct pstore_info *psi);
|
||||
ssize_t (*read)(u64 *id, enum pstore_type_id *type,
|
||||
struct timespec *time, char **buf,
|
||||
int *count, struct timespec *time, char **buf,
|
||||
struct pstore_info *psi);
|
||||
int (*write)(enum pstore_type_id type,
|
||||
enum kmsg_dump_reason reason, u64 *id,
|
||||
unsigned int part, size_t size, struct pstore_info *psi);
|
||||
unsigned int part, int count, size_t size,
|
||||
struct pstore_info *psi);
|
||||
int (*write_buf)(enum pstore_type_id type,
|
||||
enum kmsg_dump_reason reason, u64 *id,
|
||||
unsigned int part, const char *buf, size_t size,
|
||||
struct pstore_info *psi);
|
||||
int (*erase)(enum pstore_type_id type, u64 id,
|
||||
int count, struct timespec time,
|
||||
struct pstore_info *psi);
|
||||
void *data;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue