本文主要是介绍pstore 从oops发生到保存dmesg的过程,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
./kernel/panic.c:13:#include<linux/kmsg_dump.h>
./kernel/panic.c:136: kmsg_dump(KMSG_DUMP_PANIC);
./kernel/panic.c:411: kmsg_dump(KMSG_DUMP_OOPS);
linux/kmsg_dump.h的内容
enumkmsg_dump_reason {
KMSG_DUMP_UNDEF,
KMSG_DUMP_PANIC,
KMSG_DUMP_OOPS,
KMSG_DUMP_EMERG,
KMSG_DUMP_RESTART,
KMSG_DUMP_HALT,
KMSG_DUMP_POWEROFF,
};
/**
*struct kmsg_dumper - kernel crash message dumper structure
*@list: Entry in the dumper list (private)
*@dump: Call into dumping code which will retrieve the data with
*through the record iterator
*@max_reason: filter for highest reason number that should be dumped
*@registered: Flag that specifies if this is already registered
*/
structkmsg_dumper {
structlist_head list;
void(*dump)(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason);
enumkmsg_dump_reason max_reason;
boolactive;
boolregistered;
/*private state of the kmsg iterator */
u32cur_idx;
u32next_idx;
u64cur_seq;
u64next_seq;
};
#ifdefCONFIG_PRINTK
voidkmsg_dump(enum kmsg_dump_reason reason);
boolkmsg_dump_get_line_nolock(struct kmsg_dumper *dumper, bool syslog,
char *line, size_t size, size_t *len);
boolkmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
char*line, size_t size, size_t *len);
boolkmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
char *buf, size_t size, size_t *len);
voidkmsg_dump_rewind_nolock(struct kmsg_dumper *dumper);
voidkmsg_dump_rewind(struct kmsg_dumper *dumper);
intkmsg_dump_register(struct kmsg_dumper *dumper);
intkmsg_dump_unregister(struct kmsg_dumper *dumper);
注册kmsg_dump_register的实现在printk文件中
pstore是注册的是什么样的函数?
./fs/pstore/platform.c:445: kmsg_dump_register(&pstore_dumper);
staticstruct kmsg_dumper pstore_dumper = {
.dump= pstore_dump,
};
pstore_dump->psinfo->write(PSTORE_TYPE_DMESG, reason, &id,part,
oopscount, compressed, total_len, psinfo);
structpstore_info *psinfo;
staticchar *backend;
./ram.c:503: err= pstore_register(&cxt->pstore);
staticint ramoops_probe(struct platform_device *pdev)
{
structdevice *dev = &pdev->dev;
structramoops_platform_data *pdata = pdev->dev.platform_data;
structramoops_context *cxt = &oops_cxt;
size_tdump_mem_sz;
phys_addr_tpaddr;
interr = -
=====
}
./pstore.h:47:structpstore_info {
/*types */
enumpstore_type_id {
PSTORE_TYPE_DMESG =0,
PSTORE_TYPE_MCE =1,
PSTORE_TYPE_CONSOLE =2,
PSTORE_TYPE_FTRACE =3,
/*PPC64 partition types */
PSTORE_TYPE_PPC_RTAS =4,
PSTORE_TYPE_PPC_OF =5,
PSTORE_TYPE_PPC_COMMON =6,
PSTORE_TYPE_UNKNOWN =255
};
structmodule;
structpstore_info {
structmodule *owner;
char *name;
spinlock_t buf_lock; /*serialize access to 'buf' */
char *buf;
size_t bufsize;
structmutex read_mutex; /* serialize open/read/close */
int flags;
int (*open)(structpstore_info *psi);
int (*close)(structpstore_info *psi);
ssize_t (*read)(u64*id, enum pstore_type_id *type,
int*count, struct timespec *time, char **buf,
bool*compressed, struct pstore_info *psi);
int (*write)(enumpstore_type_id type,
enumkmsg_dump_reason reason, u64 *id,
unsignedint part, int count, bool compressed,
size_tsize, struct pstore_info *psi);
int (*write_buf)(enumpstore_type_id type,
enumkmsg_dump_reason reason, u64 *id,
unsignedint part, const char *buf, bool compressed,
size_tsize, struct pstore_info *psi);
int (*erase)(enumpstore_type_id type, u64 id,
intcount, struct timespec time,
structpstore_info *psi);
void *data;
};
#define PSTORE_FLAGS_FRAGILE 1
#ifdefCONFIG_PSTORE
externint pstore_register(struct pstore_info *);
externbool pstore_cannot_block_path(enum kmsg_dump_reason reason);
staticstruct ramoops_context oops_cxt = {
.pstore= {
.owner =THIS_MODULE,
.name ="ramoops",
.open =ramoops_pstore_open,
.read =ramoops_pstore_read,
.write_buf =ramoops_pstore_write_buf,
.erase =ramoops_pstore_erase,
},
};
platform.c
intpstore_register(struct pstore_info *psi)
{
structmodule *owner = psi->owner;
if(backend && strcmp(backend, psi->name))
return-EPERM;
spin_lock(&pstore_lock);
if(psinfo) {
spin_unlock(&pstore_lock);
return-EBUSY;
}
if(!psi->write)
psi->write= pstore_write_compat;
psinfo= psi;
下一步,哪里通过 pstore文件系统,把保存的数据读出的?
这篇关于pstore 从oops发生到保存dmesg的过程的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!