pstore: Replace arguments for erase() API

This removes the argument list for the erase() callback and replaces it
with a pointer to the backend record details to be removed.

Signed-off-by: Kees Cook <keescook@chromium.org>
This commit is contained in:
Kees Cook 2017-03-04 23:31:19 -08:00
parent 83f70f0769
commit a61072aae6
5 changed files with 31 additions and 46 deletions

View File

@ -927,8 +927,7 @@ static int erst_open_pstore(struct pstore_info *psi);
static int erst_close_pstore(struct pstore_info *psi);
static ssize_t erst_reader(struct pstore_record *record);
static int erst_writer(struct pstore_record *record);
static int erst_clearer(enum pstore_type_id type, u64 id, int count,
struct timespec time, struct pstore_info *psi);
static int erst_clearer(struct pstore_record *record);
static struct pstore_info erst_info = {
.owner = THIS_MODULE,
@ -1100,10 +1099,9 @@ static int erst_writer(struct pstore_record *record)
return ret;
}
static int erst_clearer(enum pstore_type_id type, u64 id, int count,
struct timespec time, struct pstore_info *psi)
static int erst_clearer(struct pstore_record *record)
{
return erst_clear(id);
return erst_clear(record->id);
}
static int __init erst_init(void)

View File

@ -266,10 +266,7 @@ static int efi_pstore_write(struct pstore_record *record)
};
struct pstore_erase_data {
u64 id;
enum pstore_type_id type;
int count;
struct timespec time;
struct pstore_record *record;
efi_char16_t *name;
};
@ -295,8 +292,9 @@ static int efi_pstore_erase_func(struct efivar_entry *entry, void *data)
* Check if an old format, which doesn't support
* holding multiple logs, remains.
*/
sprintf(name_old, "dump-type%u-%u-%lu", ed->type,
(unsigned int)ed->id, ed->time.tv_sec);
snprintf(name_old, sizeof(name_old), "dump-type%u-%u-%lu",
ed->record->type, (unsigned int)ed->record->id,
ed->record->time.tv_sec);
for (i = 0; i < DUMP_NAME_LEN; i++)
efi_name_old[i] = name_old[i];
@ -321,8 +319,7 @@ static int efi_pstore_erase_func(struct efivar_entry *entry, void *data)
return 1;
}
static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count,
struct timespec time, struct pstore_info *psi)
static int efi_pstore_erase(struct pstore_record *record)
{
struct pstore_erase_data edata;
struct efivar_entry *entry = NULL;
@ -331,17 +328,16 @@ static int efi_pstore_erase(enum pstore_type_id type, u64 id, int count,
int found, i;
unsigned int part;
do_div(id, 1000);
part = do_div(id, 100);
sprintf(name, "dump-type%u-%u-%d-%lu", type, part, count, time.tv_sec);
do_div(record->id, 1000);
part = do_div(record->id, 100);
snprintf(name, sizeof(name), "dump-type%u-%u-%d-%lu",
record->type, record->part, record->count,
record->time.tv_sec);
for (i = 0; i < DUMP_NAME_LEN; i++)
efi_name[i] = name[i];
edata.id = part;
edata.type = type;
edata.count = count;
edata.time = time;
edata.record = record;
edata.name = efi_name;
if (efivar_entry_iter_begin())

View File

@ -210,14 +210,12 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry)
if (err)
return err;
if (record->psi->erase) {
mutex_lock(&record->psi->read_mutex);
record->psi->erase(record->type, record->id, record->count,
d_inode(dentry)->i_ctime, record->psi);
mutex_unlock(&record->psi->read_mutex);
} else {
if (!record->psi->erase)
return -EPERM;
}
mutex_lock(&record->psi->read_mutex);
record->psi->erase(record);
mutex_unlock(&record->psi->read_mutex);
return simple_unlink(dir, dentry);
}

View File

@ -469,25 +469,24 @@ static int notrace ramoops_pstore_write_buf_user(enum pstore_type_id type,
return -EINVAL;
}
static int ramoops_pstore_erase(enum pstore_type_id type, u64 id, int count,
struct timespec time, struct pstore_info *psi)
static int ramoops_pstore_erase(struct pstore_record *record)
{
struct ramoops_context *cxt = psi->data;
struct ramoops_context *cxt = record->psi->data;
struct persistent_ram_zone *prz;
switch (type) {
switch (record->type) {
case PSTORE_TYPE_DMESG:
if (id >= cxt->max_dump_cnt)
if (record->id >= cxt->max_dump_cnt)
return -EINVAL;
prz = cxt->dprzs[id];
prz = cxt->dprzs[record->id];
break;
case PSTORE_TYPE_CONSOLE:
prz = cxt->cprz;
break;
case PSTORE_TYPE_FTRACE:
if (id >= cxt->max_ftrace_cnt)
if (record->id >= cxt->max_ftrace_cnt)
return -EINVAL;
prz = cxt->fprzs[id];
prz = cxt->fprzs[record->id];
break;
case PSTORE_TYPE_PMSG:
prz = cxt->mprz;

View File

@ -177,15 +177,11 @@ struct pstore_record {
*
* @erase:
* Delete a record from backend storage. Different backends
* identify records differently, so all possible methods of
* identification are included to help the backend locate the
* record to remove.
* identify records differently, so entire original record is
* passed back to assist in identification of what the backend
* should remove from storage.
*
* @type: in: pstore record type to write
* @id: in: per-type unique identifier for the record
* @count: in: Oops count
* @time: in: timestamp for the record
* @psi: in: pointer to the struct pstore_info for the backend
* @record: pointer to record metadata.
*
* Returns 0 on success, and non-zero on error.
*
@ -215,9 +211,7 @@ struct pstore_info {
enum kmsg_dump_reason reason, u64 *id,
unsigned int part, const char __user *buf,
bool compressed, 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);
int (*erase)(struct pstore_record *record);
};
/* Supported frontends */