mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-07 18:00:49 +03:00
persistent filter & some log message changes
This commit is contained in:
parent
68c14b47aa
commit
4790fce2ad
@ -544,6 +544,9 @@ find_config_str(struct config_node *cn,
|
||||
if (n && n->v->type == CFG_STRING)
|
||||
return n->v->v.str;
|
||||
|
||||
if (fail)
|
||||
log_debug("%s not found in config: defaulting to %s",
|
||||
path, fail);
|
||||
return fail;
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,11 @@ static int _insert(const char *path, int recurse)
|
||||
struct stat info;
|
||||
struct device *dev;
|
||||
|
||||
//log_very_verbose("dev-cache adding %s", path);
|
||||
/* If entry already exists, replace it */
|
||||
if ((dev = (struct device *)hash_lookup(_cache.devices, path))) {
|
||||
log_debug("dev-cache: removing %s", path);
|
||||
hash_remove(_cache.devices, path);
|
||||
}
|
||||
|
||||
if (stat(path, &info) < 0) {
|
||||
log_sys_very_verbose("stat", path);
|
||||
@ -138,7 +142,7 @@ static int _insert(const char *path, int recurse)
|
||||
}
|
||||
|
||||
if (S_ISLNK(info.st_mode)) {
|
||||
//log_debug("%s is a symbolic link, following", path);
|
||||
log_debug("%s: Following symbolic link", path);
|
||||
if (!(path = _follow_link(path, &info))) {
|
||||
stack;
|
||||
return 0;
|
||||
@ -146,16 +150,18 @@ static int _insert(const char *path, int recurse)
|
||||
}
|
||||
|
||||
if (!S_ISBLK(info.st_mode)) {
|
||||
//log_debug("%s is not a block device", path);
|
||||
log_debug("%s: Not a block device", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(dev = _create_dev(path, &info))) {
|
||||
stack;
|
||||
log_debug("%s: Creation of device cache entry failed!", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_debug("dev-cache: adding %s", path);
|
||||
hash_insert(_cache.devices, path, dev);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ static int _read_array(struct pfilter *pf, struct config_file *cf,
|
||||
struct config_value *cv;
|
||||
|
||||
if (!(cn = find_config_node(cf->root, path, '/'))) {
|
||||
log_info("Couldn't find 'valid_devices' array in '%s'",
|
||||
log_verbose("Couldn't find 'valid_devices' array in '%s'",
|
||||
pf->file);
|
||||
return 0;
|
||||
}
|
||||
@ -64,13 +64,13 @@ static int _read_array(struct pfilter *pf, struct config_file *cf,
|
||||
*/
|
||||
for (cv = cn->v; cv; cv = cv->next) {
|
||||
if (cv->type != CFG_STRING) {
|
||||
log_info("Valid_devices array contains a value "
|
||||
log_verbose("Valid_devices array contains a value "
|
||||
"which is not a string ... ignoring");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!hash_insert(pf->devices, cv->v.str, data))
|
||||
log_info("Couldn't add '%s' to filter ... ignoring",
|
||||
log_verbose("Couldn't add '%s' to filter ... ignoring",
|
||||
cv->v.str);
|
||||
}
|
||||
return 1;
|
||||
@ -137,7 +137,7 @@ int persistent_filter_dump(struct dev_filter *f)
|
||||
log_very_verbose("Dumping persistent device cache to %s", pf->file);
|
||||
|
||||
if (!fp) {
|
||||
log_info("Couldn't open '%s' for to hold valid devices.",
|
||||
log_error("Couldn't open '%s' for to hold valid devices.",
|
||||
pf->file);
|
||||
return 0;
|
||||
}
|
||||
@ -197,7 +197,7 @@ struct dev_filter *persistent_filter_create(struct dev_filter *real,
|
||||
pf->real = real;
|
||||
|
||||
if (!(_init_hash(pf))) {
|
||||
log_err("Couldn't create hash table for persistent filter.");
|
||||
log_error("Couldn't create hash table for persistent filter.");
|
||||
goto bad;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,28 @@
|
||||
#ifndef _LVM_LOG_H
|
||||
#define _LVM_LOG_H
|
||||
|
||||
/*
|
||||
* printf()-style macros to use for messages:
|
||||
*
|
||||
* log_error - always print to stderr.
|
||||
* log_print - always print to stdout. Use this instead of printf.
|
||||
* log_verbose - print to stdout if verbose is set (-v)
|
||||
* log_very_verbose - print to stdout if verbose is set twice (-vv)
|
||||
* log_debug - print to stdout if verbose is set three times (-vvv)
|
||||
* (suppressed if single-character string such as with 'stack')
|
||||
*
|
||||
* In addition, messages will be logged to file or syslog if they
|
||||
* are more serious than the log level specified with the log/debug_level
|
||||
* parameter in the configuration file. These messages get the file
|
||||
* and line number prepended. 'stack' (without arguments) can be used
|
||||
* to log this information at debug level.
|
||||
*
|
||||
* log_sys_error and log_sys_very_verbose are for errors from system calls
|
||||
* e.g. log_sys_error("stat", filename);
|
||||
* /dev/fd/7: stat failed: No such file or directory
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
@ -45,26 +67,12 @@ void print_log(int level, const char *file, int line, const char *format, ...)
|
||||
|
||||
#define stack log_debug( "s" )
|
||||
|
||||
/*
|
||||
* Macros to use for messages:
|
||||
*
|
||||
* log_error - always print to stderr
|
||||
* log_print - always print to stdout
|
||||
* log_verbose - print to stdout if verbose is set (-v)
|
||||
* log_very_verbose - print to stdout if verbose is set twice (-vv)
|
||||
* log_debug - print to stdout if verbose is set three times (-vvv)
|
||||
* (suppressed if single-character string such as with 'stack')
|
||||
*
|
||||
* In addition, messages will be logged to file or syslog if they
|
||||
* are more serious than the log level specified with -d.
|
||||
*/
|
||||
|
||||
#define log_error(fmt, args...) log_err(fmt , ## args)
|
||||
#define log_print(fmt, args...) log_warn(fmt , ## args)
|
||||
#define log_verbose(fmt, args...) log_notice(fmt , ## args)
|
||||
#define log_very_verbose(fmt, args...) log_info(fmt , ## args)
|
||||
|
||||
/* System call equivalents */
|
||||
/* Two System call equivalents */
|
||||
#define log_sys_error(x, y) \
|
||||
log_err("%s: %s failed: %s", y, x, strerror(errno))
|
||||
#define log_sys_very_verbose(x, y) \
|
||||
|
@ -50,7 +50,9 @@ endif
|
||||
SUFFIXES=
|
||||
SUFFIXES=.c .d .o
|
||||
|
||||
CFLAGS+=-g -Wall -DDEBUG_MEM -DBOUNDS_CHECK -DDEBUG
|
||||
CFLAGS+=-g -Wall
|
||||
CFLAGS+=-DDEBUG_MEM -DDEBUG
|
||||
#CFLAGS+=-DBOUNDS_CHECK
|
||||
INCLUDES+=-I. -I$(top_srcdir)/include
|
||||
INC_LNS=$(top_srcdir)/include/.symlinks_created
|
||||
|
||||
|
42
tools/lvm.c
42
tools/lvm.c
@ -555,10 +555,11 @@ struct dev_filter *active_filter(void)
|
||||
static void __init_log(struct config_file *cf)
|
||||
{
|
||||
const char *log_file = find_config_str(cf->root, "log/file", '/', 0);
|
||||
int verbose_level;
|
||||
|
||||
if (log_file) {
|
||||
/* set up the logging */
|
||||
if (!(_log = fopen(log_file, "w")))
|
||||
if (!(_log = fopen(log_file, "a")))
|
||||
log_error("Couldn't open log file %s", log_file);
|
||||
else
|
||||
init_log(_log);
|
||||
@ -566,6 +567,9 @@ static void __init_log(struct config_file *cf)
|
||||
|
||||
_debug_level = find_config_int(cf->root, "log/level", '/', 0);
|
||||
init_debug(_debug_level);
|
||||
|
||||
verbose_level = find_config_int(cf->root, "log/verbose", '/', 0);
|
||||
init_verbose(verbose_level);
|
||||
}
|
||||
|
||||
static int dev_cache_setup(void)
|
||||
@ -584,6 +588,8 @@ static int dev_cache_setup(void)
|
||||
"device cache");
|
||||
return 0;
|
||||
}
|
||||
log_verbose("device/scan not in config file: Defaulting to /dev");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (cv = cn->v; cv; cv = cv->next) {
|
||||
@ -603,16 +609,17 @@ static int dev_cache_setup(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct dev_filter *filter_setup(void)
|
||||
static struct dev_filter *filter_components_setup(void)
|
||||
{
|
||||
struct config_node *cn;
|
||||
struct dev_filter *f1, *f2, *f3, *f4;
|
||||
struct dev_filter *f1, *f2, *f3;
|
||||
|
||||
if (!(f2 = lvm_type_filter_create()))
|
||||
return 0;
|
||||
|
||||
if (!(cn = find_config_node(_cf->root, "devices/filter", '/'))) {
|
||||
log_debug("devices/filter not found in config file");
|
||||
log_debug("devices/filter not found in config file: no regex "
|
||||
"filter installed");
|
||||
return f2;
|
||||
}
|
||||
|
||||
@ -621,11 +628,35 @@ static struct dev_filter *filter_setup(void)
|
||||
return f2;
|
||||
}
|
||||
|
||||
if (!(f4 = composite_filter_create(2, f1, f2))) {
|
||||
if (!(f3 = composite_filter_create(2, f1, f2))) {
|
||||
log_error("Failed to create composite device filter");
|
||||
return f2;
|
||||
}
|
||||
|
||||
return f3;
|
||||
}
|
||||
|
||||
static struct dev_filter *filter_setup(void)
|
||||
{
|
||||
const char *lvm_cache;
|
||||
struct dev_filter *f3, *f4;
|
||||
struct stat st;
|
||||
|
||||
if (!(f3 = filter_components_setup()))
|
||||
return 0;
|
||||
|
||||
lvm_cache = find_config_str(_cf->root, "devices/cache", '/',
|
||||
"/etc/lvm/.cache");
|
||||
|
||||
if (!(f4 = persistent_filter_create(f3, lvm_cache))) {
|
||||
log_error("Failed to create persistent device filter");
|
||||
return f3;
|
||||
}
|
||||
|
||||
if (!stat(lvm_cache, &st) && !persistent_filter_load(f4))
|
||||
log_verbose("Failed to load existing device cache from %s",
|
||||
lvm_cache);
|
||||
|
||||
return f4;
|
||||
}
|
||||
|
||||
@ -661,7 +692,6 @@ static int init(void)
|
||||
__init_log(_cf);
|
||||
}
|
||||
|
||||
|
||||
if (!dev_cache_setup()) {
|
||||
goto out;
|
||||
}
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "display.h"
|
||||
#include "errors.h"
|
||||
#include "filter.h"
|
||||
#include "filter-persistent.h"
|
||||
#include "filter-composite.h"
|
||||
#include "filter-regex.h"
|
||||
#include "format1.h"
|
||||
|
Loading…
Reference in New Issue
Block a user