Skip to content

Commit 366f7e7

Browse files
aegltorvalds
authored andcommitted
pstore: use mount option instead sysfs to tweak kmsg_bytes
/sys/fs is a somewhat strange way to tweak what could more obviously be tuned with a mount option. Suggested-by: Christoph Hellwig <hch@infradead.org> Signed-off-by: Tony Luck <tony.luck@intel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 10effcb commit 366f7e7

5 files changed

Lines changed: 59 additions & 47 deletions

File tree

‎Documentation/ABI/testing/pstore‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Where: /dev/pstore/...
2-
Date: January 2011
3-
Kernel Version: 2.6.38
2+
Date: March 2011
3+
Kernel Version: 2.6.39
44
Contact: tony.luck@intel.com
55
Description: Generic interface to platform dependent persistent storage.
66

@@ -11,7 +11,7 @@ Description: Generic interface to platform dependent persistent storage.
1111
of the console log is captured, but other interesting
1212
data can also be saved.
1313

14-
# mount -t pstore - /dev/pstore
14+
# mount -t pstore -o kmsg_bytes=8000 - /dev/pstore
1515

1616
$ ls -l /dev/pstore
1717
total 0
@@ -33,3 +33,9 @@ Description: Generic interface to platform dependent persistent storage.
3333
will be saved elsewhere and erased from persistent store
3434
soon after boot to free up space ready for the next
3535
catastrophe.
36+
37+
The 'kmsg_bytes' mount option changes the target amount of
38+
data saved on each oops/panic. Pstore saves (possibly
39+
multiple) files based on the record size of the underlying
40+
persistent storage until at least this amount is reached.
41+
Default is 10 Kbytes.

‎Documentation/ABI/testing/sysfs-fs-pstore‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎fs/pstore/inode.c‎

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/string.h>
2828
#include <linux/mount.h>
2929
#include <linux/ramfs.h>
30+
#include <linux/parser.h>
3031
#include <linux/sched.h>
3132
#include <linux/magic.h>
3233
#include <linux/pstore.h>
@@ -112,10 +113,52 @@ static struct inode *pstore_get_inode(struct super_block *sb,
112113
return inode;
113114
}
114115

116+
enum {
117+
Opt_kmsg_bytes, Opt_err
118+
};
119+
120+
static const match_table_t tokens = {
121+
{Opt_kmsg_bytes, "kmsg_bytes=%u"},
122+
{Opt_err, NULL}
123+
};
124+
125+
static void parse_options(char *options)
126+
{
127+
char *p;
128+
substring_t args[MAX_OPT_ARGS];
129+
int option;
130+
131+
if (!options)
132+
return;
133+
134+
while ((p = strsep(&options, ",")) != NULL) {
135+
int token;
136+
137+
if (!*p)
138+
continue;
139+
140+
token = match_token(p, tokens, args);
141+
switch (token) {
142+
case Opt_kmsg_bytes:
143+
if (!match_int(&args[0], &option))
144+
pstore_set_kmsg_bytes(option);
145+
break;
146+
}
147+
}
148+
}
149+
150+
static int pstore_remount(struct super_block *sb, int *flags, char *data)
151+
{
152+
parse_options(data);
153+
154+
return 0;
155+
}
156+
115157
static const struct super_operations pstore_ops = {
116158
.statfs = simple_statfs,
117159
.drop_inode = generic_delete_inode,
118160
.evict_inode = pstore_evict_inode,
161+
.remount_fs = pstore_remount,
119162
.show_options = generic_show_options,
120163
};
121164

@@ -215,6 +258,8 @@ int pstore_fill_super(struct super_block *sb, void *data, int silent)
215258
sb->s_op = &pstore_ops;
216259
sb->s_time_gran = 1;
217260

261+
parse_options(data);
262+
218263
inode = pstore_get_inode(sb, NULL, S_IFDIR | 0755, 0);
219264
if (!inode) {
220265
err = -ENOMEM;
@@ -258,28 +303,7 @@ static struct file_system_type pstore_fs_type = {
258303

259304
static int __init init_pstore_fs(void)
260305
{
261-
int rc = 0;
262-
struct kobject *pstorefs_kobj;
263-
264-
pstorefs_kobj = kobject_create_and_add("pstore", fs_kobj);
265-
if (!pstorefs_kobj) {
266-
rc = -ENOMEM;
267-
goto done;
268-
}
269-
270-
rc = sysfs_create_file(pstorefs_kobj, &pstore_kmsg_bytes_attr.attr);
271-
if (rc)
272-
goto done1;
273-
274-
rc = register_filesystem(&pstore_fs_type);
275-
if (rc == 0)
276-
goto done;
277-
278-
sysfs_remove_file(pstorefs_kobj, &pstore_kmsg_bytes_attr.attr);
279-
done1:
280-
kobject_put(pstorefs_kobj);
281-
done:
282-
return rc;
306+
return register_filesystem(&pstore_fs_type);
283307
}
284308
module_init(init_pstore_fs)
285309

‎fs/pstore/internal.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
extern void pstore_set_kmsg_bytes(int);
12
extern void pstore_get_records(void);
23
extern int pstore_mkfile(enum pstore_type_id, char *psname, u64 id,
34
char *data, size_t size,
45
struct timespec time, int (*erase)(u64));
56
extern int pstore_is_mounted(void);
6-
7-
extern struct kobj_attribute pstore_kmsg_bytes_attr;

‎fs/pstore/platform.c‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,14 @@
3737
static DEFINE_SPINLOCK(pstore_lock);
3838
static struct pstore_info *psinfo;
3939

40-
/* How much of the console log to snapshot. /sys/fs/pstore/kmsg_bytes */
40+
/* How much of the console log to snapshot */
4141
static unsigned long kmsg_bytes = 10240;
4242

43-
static ssize_t b_show(struct kobject *kobj,
44-
struct kobj_attribute *attr, char *buf)
43+
void pstore_set_kmsg_bytes(int bytes)
4544
{
46-
return snprintf(buf, PAGE_SIZE, "%lu\n", kmsg_bytes);
45+
kmsg_bytes = bytes;
4746
}
4847

49-
static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr,
50-
const char *buf, size_t count)
51-
{
52-
return (sscanf(buf, "%lu", &kmsg_bytes) > 0) ? count : 0;
53-
}
54-
55-
struct kobj_attribute pstore_kmsg_bytes_attr =
56-
__ATTR(kmsg_bytes, S_IRUGO | S_IWUSR, b_show, b_store);
57-
5848
/* Tag each group of saved records with a sequence number */
5949
static int oopscount;
6050

0 commit comments

Comments
 (0)