Skip to content

Commit 1525fb3

Browse files
WeiXiong Liaokees
authored andcommitted
pstore/blk: Provide way to query pstore configuration
In order to configure itself, the MTD backend needs to be able to query the current pstore configuration. Introduce pstore_blk_get_config() for this purpose. Signed-off-by: WeiXiong Liao <[email protected]> Link: https://lore.kernel.org/lkml/[email protected]/ Co-developed-by: Kees Cook <[email protected]> Signed-off-by: Kees Cook <[email protected]>
1 parent 335426c commit 1525fb3

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

fs/pstore/blk.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ struct bdev_info {
9494
sector_t start_sect;
9595
};
9696

97+
#define check_size(name, alignsize) ({ \
98+
long _##name_ = (name); \
99+
_##name_ = _##name_ <= 0 ? 0 : (_##name_ * 1024); \
100+
if (_##name_ & ((alignsize) - 1)) { \
101+
pr_info(#name " must align to %d\n", \
102+
(alignsize)); \
103+
_##name_ = ALIGN(name, (alignsize)); \
104+
} \
105+
_##name_; \
106+
})
107+
97108
/**
98109
* struct pstore_device_info - back-end pstore/blk driver structure.
99110
*
@@ -149,13 +160,11 @@ static int psblk_register_do(struct pstore_device_info *dev)
149160
dev->flags = UINT_MAX;
150161

151162
#define verify_size(name, alignsize, enabled) { \
152-
long _##name_ = (enabled) ? (name) : 0; \
153-
_##name_ = _##name_ <= 0 ? 0 : (_##name_ * 1024); \
154-
if (_##name_ & ((alignsize) - 1)) { \
155-
pr_info(#name " must align to %d\n", \
156-
(alignsize)); \
157-
_##name_ = ALIGN(name, (alignsize)); \
158-
} \
163+
long _##name_; \
164+
if (enabled) \
165+
_##name_ = check_size(name, alignsize); \
166+
else \
167+
_##name_ = 0; \
159168
name = _##name_ / 1024; \
160169
pstore_zone_info->name = _##name_; \
161170
}
@@ -453,6 +462,20 @@ void unregister_pstore_blk(unsigned int major)
453462
}
454463
EXPORT_SYMBOL_GPL(unregister_pstore_blk);
455464

465+
/* get information of pstore/blk */
466+
int pstore_blk_get_config(struct pstore_blk_config *info)
467+
{
468+
strncpy(info->device, blkdev, 80);
469+
info->max_reason = max_reason;
470+
info->kmsg_size = check_size(kmsg_size, 4096);
471+
info->pmsg_size = check_size(pmsg_size, 4096);
472+
info->ftrace_size = check_size(ftrace_size, 4096);
473+
info->console_size = check_size(console_size, 4096);
474+
475+
return 0;
476+
}
477+
EXPORT_SYMBOL_GPL(pstore_blk_get_config);
478+
456479
static void __exit pstore_blk_exit(void)
457480
{
458481
mutex_lock(&pstore_blk_lock);

include/linux/pstore_blk.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,32 @@ struct pstore_blk_info {
4949
int register_pstore_blk(struct pstore_blk_info *info);
5050
void unregister_pstore_blk(unsigned int major);
5151

52+
/**
53+
* struct pstore_blk_config - the pstore_blk backend configuration
54+
*
55+
* @device: Name of the desired block device
56+
* @max_reason: Maximum kmsg dump reason to store to block device
57+
* @kmsg_size: Total size of for kmsg dumps
58+
* @pmsg_size: Total size of the pmsg storage area
59+
* @console_size: Total size of the console storage area
60+
* @ftrace_size: Total size for ftrace logging data (for all CPUs)
61+
*/
62+
struct pstore_blk_config {
63+
char device[80];
64+
enum kmsg_dump_reason max_reason;
65+
unsigned long kmsg_size;
66+
unsigned long pmsg_size;
67+
unsigned long console_size;
68+
unsigned long ftrace_size;
69+
};
70+
71+
/**
72+
* pstore_blk_get_config - get a copy of the pstore_blk backend configuration
73+
*
74+
* @info: The sturct pstore_blk_config to be filled in
75+
*
76+
* Failure returns negative error code, and success returns 0.
77+
*/
78+
int pstore_blk_get_config(struct pstore_blk_config *info);
79+
5280
#endif

0 commit comments

Comments
 (0)