From 48a00f1320a366bd5ec348b108b4660832f02b93 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Tue, 15 Jan 2002 23:34:13 +0000 Subject: [PATCH] o More comprehensive config parameter debugging messages. o Make /proc configurable. o Review hard-coded "/dev"s - made 2 more of them configurable. --- lib/config/config.c | 16 +++++++++++++--- lib/filters/filter.c | 26 +++++++++++++++++--------- man/lvm.conf.5 | 3 +++ tools/defaults.h | 1 + tools/lvm.c | 16 ++++++++++++---- 5 files changed, 46 insertions(+), 16 deletions(-) diff --git a/lib/config/config.c b/lib/config/config.c index 477cb0763..9100ffcc1 100644 --- a/lib/config/config.c +++ b/lib/config/config.c @@ -553,8 +553,10 @@ find_config_str(struct config_node *cn, { struct config_node *n = find_config_node(cn, path, sep); - if (n && n->v->type == CFG_STRING) + if (n && n->v->type == CFG_STRING) { + log_debug("Setting %s to %s", path, n->v->v.str); return n->v->v.str; + } if (fail) log_debug("%s not found in config: defaulting to %s", @@ -567,9 +569,12 @@ int find_config_int(struct config_node *cn, const char *path, { struct config_node *n = find_config_node(cn, path, sep); - if (n && n->v->type == CFG_INT) + if (n && n->v->type == CFG_INT) { + log_debug("Setting %s to %d", path, n->v->v.i); return n->v->v.i; + } + log_debug("%s not found in config: defaulting to %d", path, fail); return fail; } @@ -578,8 +583,13 @@ float find_config_float(struct config_node *cn, const char *path, { struct config_node *n = find_config_node(cn, path, sep); - if (n && n->v->type == CFG_FLOAT) + if (n && n->v->type == CFG_FLOAT) { + log_debug("Setting %s to %f", path, n->v->v.r); return n->v->v.r; + } + + log_debug("%s not found in config: defaulting to %f", + path, fail); return fail; diff --git a/lib/filters/filter.c b/lib/filters/filter.c index 2cb6434fc..fbf3ee6f6 100644 --- a/lib/filters/filter.c +++ b/lib/filters/filter.c @@ -22,6 +22,7 @@ #include "log.h" #include "dev-cache.h" #include "filter.h" +#include "lvm-string.h" #include #include @@ -53,7 +54,7 @@ static device_info_t device_info[] = { {NULL, 0} }; -static int *scan_proc_dev(void); +static int *scan_proc_dev(const char *proc); static int passes_lvm_type_device_filter(struct dev_filter *f, struct device *dev) @@ -76,7 +77,7 @@ static int passes_lvm_type_device_filter(struct dev_filter *f, return 1; } -struct dev_filter *lvm_type_filter_create() +struct dev_filter *lvm_type_filter_create(const char *proc) { struct dev_filter *f; @@ -88,7 +89,7 @@ struct dev_filter *lvm_type_filter_create() f->passes_filter = passes_lvm_type_device_filter; f->destroy = lvm_type_filter_destroy; - if (!(f->private = scan_proc_dev())) + if (!(f->private = scan_proc_dev(proc))) return NULL; return f; @@ -101,10 +102,11 @@ void lvm_type_filter_destroy(struct dev_filter *f) return; } -static int *scan_proc_dev(void) +static int *scan_proc_dev(const char *proc) { char line[80]; - FILE *procdevices = NULL; + char proc_devices[PATH_MAX]; + FILE *pd = NULL; int ret = 0; int i, j = 0; int line_maj = 0; @@ -118,13 +120,19 @@ static int *scan_proc_dev(void) return NULL; } - if (!(procdevices = fopen("/proc/devices", "r"))) { - log_error("Failed to open /proc/devices: %s", strerror(errno)); + if (lvm_snprintf(proc_devices, sizeof(proc_devices), + "%s/devices", proc) < 0) { + log_error("Failed to create /proc/devices string"); + return NULL; + } + + if (!(pd = fopen(proc_devices, "r"))) { + log_sys_error("fopen", proc_devices); return NULL; } memset(max_partitions_by_major, 0, sizeof (int) * NUMBER_OF_MAJORS); - while (fgets(line, 80, procdevices) != NULL) { + while (fgets(line, 80, pd) != NULL) { i = 0; while (line[i] == ' ' && line[i] != '\0') i++; @@ -161,6 +169,6 @@ static int *scan_proc_dev(void) } } } - fclose(procdevices); + fclose(pd); return max_partitions_by_major; } diff --git a/man/lvm.conf.5 b/man/lvm.conf.5 index 1579c5376..c3f049031 100644 --- a/man/lvm.conf.5 +++ b/man/lvm.conf.5 @@ -145,6 +145,9 @@ Defaults to 30. .TP \fBglobal\fP \(em Global settings .IP +\fBproc\fP \(em Mount point of proc filesystem. +Defaults to /proc. +.IP \fBumask\fP \(em File creation mask for any files and directories created. Interpreted as octal if the first digit is zero. Defaults to 077. diff --git a/tools/defaults.h b/tools/defaults.h index 4ae0051a3..c76019f18 100644 --- a/tools/defaults.h +++ b/tools/defaults.h @@ -20,6 +20,7 @@ #define DEFAULT_ARCHIVE_NUMBER 10 #define DEFAULT_DEV_DIR "/dev" +#define DEFAULT_PROC_DIR "/proc" #define DEFAULT_UMASK 0077 diff --git a/tools/lvm.c b/tools/lvm.c index 17a658c76..726e858b7 100644 --- a/tools/lvm.c +++ b/tools/lvm.c @@ -92,6 +92,7 @@ static struct config_info _current_settings; */ static char _sys_dir[PATH_MAX] = "/etc/lvm"; static char _dev_dir[PATH_MAX]; +static char _proc_dir[PATH_MAX]; /* static functions */ static void register_commands(void); @@ -705,12 +706,12 @@ static void __init_log(struct config_file *cf) find_config_int(cf->root, "log/verbose", '/', 0); _default_settings.test = find_config_int(cf->root, "log/test", '/', 0); - init_debug(_default_settings.debug); - init_verbose(_default_settings.verbose); - if (find_config_int(cf->root, "log/overwrite", '/', 0)) open_mode = "w"; + init_debug(_default_settings.debug); + init_verbose(_default_settings.verbose); + if (log_file) { /* set up the logging */ if (!(_log = fopen(log_file, open_mode))) @@ -826,7 +827,7 @@ static struct dev_filter *filter_components_setup(struct config_file *cf) struct config_node *cn; struct dev_filter *f1, *f2, *f3; - if (!(f2 = lvm_type_filter_create())) + if (!(f2 = lvm_type_filter_create(_proc_dir))) return 0; if (!(cn = find_config_node(cf->root, "devices/filter", '/'))) { @@ -999,6 +1000,13 @@ static int init(void) dm_log_init(print_log); + if (lvm_snprintf(_proc_dir, sizeof(_proc_dir), "%s", + find_config_str(cmd->cf->root, "global/proc", + '/', DEFAULT_PROC_DIR)) < 0) { + log_error("Device directory given in config file too long"); + return 0; + } + if (!_init_backup(cmd->cf)) return 0;