-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proc: bootconfig: Add /proc/bootconfig to show boot config list
Add /proc/bootconfig which shows the list of key-value pairs in boot config. Since after boot, all boot configs and tree are removed, this interface just keep a copy of key-value pairs in text. Link: http://lkml.kernel.org/r/157867225967.17873.12155805787236073787.stgit@devnote2 Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
- Loading branch information
Masami Hiramatsu
authored and
Steven Rostedt (VMware)
committed
Jan 13, 2020
1 parent
081c653
commit c1a3c36
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* | ||
* /proc/bootconfig - Extra boot configuration | ||
*/ | ||
#include <linux/fs.h> | ||
#include <linux/init.h> | ||
#include <linux/printk.h> | ||
#include <linux/proc_fs.h> | ||
#include <linux/seq_file.h> | ||
#include <linux/bootconfig.h> | ||
#include <linux/slab.h> | ||
|
||
static char *saved_boot_config; | ||
|
||
static int boot_config_proc_show(struct seq_file *m, void *v) | ||
{ | ||
if (saved_boot_config) | ||
seq_puts(m, saved_boot_config); | ||
return 0; | ||
} | ||
|
||
/* Rest size of buffer */ | ||
#define rest(dst, end) ((end) > (dst) ? (end) - (dst) : 0) | ||
|
||
/* Return the needed total length if @size is 0 */ | ||
static int __init copy_xbc_key_value_list(char *dst, size_t size) | ||
{ | ||
struct xbc_node *leaf, *vnode; | ||
const char *val; | ||
char *key, *end = dst + size; | ||
int ret = 0; | ||
|
||
key = kzalloc(XBC_KEYLEN_MAX, GFP_KERNEL); | ||
|
||
xbc_for_each_key_value(leaf, val) { | ||
ret = xbc_node_compose_key(leaf, key, XBC_KEYLEN_MAX); | ||
if (ret < 0) | ||
break; | ||
ret = snprintf(dst, rest(dst, end), "%s = ", key); | ||
if (ret < 0) | ||
break; | ||
dst += ret; | ||
vnode = xbc_node_get_child(leaf); | ||
if (vnode && xbc_node_is_array(vnode)) { | ||
xbc_array_for_each_value(vnode, val) { | ||
ret = snprintf(dst, rest(dst, end), "\"%s\"%s", | ||
val, vnode->next ? ", " : "\n"); | ||
if (ret < 0) | ||
goto out; | ||
dst += ret; | ||
} | ||
} else { | ||
ret = snprintf(dst, rest(dst, end), "\"%s\"\n", val); | ||
if (ret < 0) | ||
break; | ||
dst += ret; | ||
} | ||
} | ||
out: | ||
kfree(key); | ||
|
||
return ret < 0 ? ret : dst - (end - size); | ||
} | ||
|
||
static int __init proc_boot_config_init(void) | ||
{ | ||
int len; | ||
|
||
len = copy_xbc_key_value_list(NULL, 0); | ||
if (len < 0) | ||
return len; | ||
|
||
if (len > 0) { | ||
saved_boot_config = kzalloc(len + 1, GFP_KERNEL); | ||
if (!saved_boot_config) | ||
return -ENOMEM; | ||
|
||
len = copy_xbc_key_value_list(saved_boot_config, len + 1); | ||
if (len < 0) { | ||
kfree(saved_boot_config); | ||
return len; | ||
} | ||
} | ||
|
||
proc_create_single("bootconfig", 0, NULL, boot_config_proc_show); | ||
|
||
return 0; | ||
} | ||
fs_initcall(proc_boot_config_init); |