btrfs-progs: add support for generic global parameters
./btrfs --param key=value command ... ./btrfs --param key command ... To pass various tuning data for testing and debugging, undocumented for regular users. To add support add reading of the parameter value after option parsing bconf_param_value("key") and convert to what you need. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
04d9e13461
commit
12b1b03974
4
btrfs.c
4
btrfs.c
|
@ -287,6 +287,7 @@ static int handle_global_options(int argc, char **argv)
|
|||
{ "verbose", no_argument, NULL, 'v' },
|
||||
{ "quiet", no_argument, NULL, 'q' },
|
||||
{ "log", required_argument, NULL, OPT_LOG },
|
||||
{ "param", required_argument, NULL, GETOPT_VAL_PARAM },
|
||||
{ NULL, 0, NULL, 0}
|
||||
};
|
||||
int shift;
|
||||
|
@ -312,6 +313,9 @@ static int handle_global_options(int argc, char **argv)
|
|||
case OPT_LOG:
|
||||
handle_log_level(optarg);
|
||||
break;
|
||||
case GETOPT_VAL_PARAM:
|
||||
bconf_save_param(optarg);
|
||||
break;
|
||||
case 'v':
|
||||
bconf_be_verbose();
|
||||
break;
|
||||
|
|
|
@ -36,6 +36,7 @@ struct cmd_group;
|
|||
#define GETOPT_VAL_TBYTES 519
|
||||
|
||||
#define GETOPT_VAL_HELP 520
|
||||
#define GETOPT_VAL_PARAM 521
|
||||
|
||||
#define ARGV0_BUF_SIZE PATH_MAX
|
||||
|
||||
|
|
|
@ -944,6 +944,7 @@ void btrfs_config_init(void)
|
|||
{
|
||||
bconf.output_format = CMD_FORMAT_TEXT;
|
||||
bconf.verbose = BTRFS_BCONF_UNSET;
|
||||
INIT_LIST_HEAD(&bconf.params);
|
||||
}
|
||||
|
||||
void bconf_be_verbose(void)
|
||||
|
@ -959,6 +960,47 @@ void bconf_be_quiet(void)
|
|||
bconf.verbose = BTRFS_BCONF_QUIET;
|
||||
}
|
||||
|
||||
void bconf_add_param(const char *key, const char *value)
|
||||
{
|
||||
struct config_param *param;
|
||||
|
||||
param = calloc(sizeof(*param), 1);
|
||||
if (!param)
|
||||
return;
|
||||
param->key = strdup(key);
|
||||
if (value)
|
||||
param->value = strdup(value);
|
||||
list_add(¶m->list, &bconf.params);
|
||||
}
|
||||
|
||||
const char *bconf_param_value(const char *key)
|
||||
{
|
||||
struct config_param *param;
|
||||
|
||||
list_for_each_entry(param, &bconf.params, list) {
|
||||
if (strcmp(key, param->key) == 0)
|
||||
return param->value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void bconf_save_param(const char *str)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
tmp = strchr(str, '=');
|
||||
if (!tmp) {
|
||||
bconf_add_param(str, NULL);
|
||||
printf("Global param: %s\n", str);
|
||||
} else {
|
||||
*tmp = 0;
|
||||
bconf_add_param(str, tmp + 1);
|
||||
printf("Global param: %s=%s\n", str, tmp + 1);
|
||||
*tmp = '=';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Returns total size of main memory in bytes, -1UL if error. */
|
||||
unsigned long total_memory(void)
|
||||
{
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "kerncompat.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include "kernel-lib/list.h"
|
||||
#include "kernel-shared/volumes.h"
|
||||
#include "common/fsfeatures.h"
|
||||
|
||||
|
@ -86,12 +87,22 @@ struct btrfs_config {
|
|||
* > 0: verbose level
|
||||
*/
|
||||
int verbose;
|
||||
struct list_head params;
|
||||
};
|
||||
extern struct btrfs_config bconf;
|
||||
|
||||
struct config_param {
|
||||
struct list_head list;
|
||||
const char *key;
|
||||
const char *value;
|
||||
};
|
||||
|
||||
void btrfs_config_init(void);
|
||||
void bconf_be_verbose(void);
|
||||
void bconf_be_quiet(void);
|
||||
void bconf_add_param(const char *key, const char *value);
|
||||
void bconf_save_param(const char *str);
|
||||
const char *bconf_param_value(const char *key);
|
||||
|
||||
/* Pseudo random number generator wrappers */
|
||||
int rand_int(void);
|
||||
|
|
Loading…
Reference in New Issue