]> sourceware.org Git - lvm2.git/commitdiff
filter integration into tools
authorAlasdair Kergon <agk@redhat.com>
Tue, 23 Oct 2001 11:50:49 +0000 (11:50 +0000)
committerAlasdair Kergon <agk@redhat.com>
Tue, 23 Oct 2001 11:50:49 +0000 (11:50 +0000)
include/.symlinks
lib/config/config.c
lib/device/dev-cache.c
lib/filters/filter-persistent.c
lib/filters/filter.c
lib/filters/filter.h
lib/mm/pool.c
tools/lvm.c
tools/tools.h

index a30c92b2e32e7a870d61fa900d5a7484f9ae47b3..be45176796521cb2f74e8fc5aead456b0a69e7cb 100644 (file)
@@ -7,6 +7,7 @@
 ../lib/device/dev-cache.h
 ../lib/device/device.h
 ../lib/display/display.h
+../lib/filters/filter-composite.h
 ../lib/filters/filter-persistent.h
 ../lib/filters/filter-regex.h
 ../lib/filters/filter.h
index 4c4c79fc0268edeaf29f0ba56f288ca317c77ae0..b225289db4c5b54b8bdd82a0aab3d76842a6744c 100644 (file)
@@ -54,8 +54,6 @@ static struct config_node *_file(struct parser *p);
 static struct config_node *_section(struct parser *p);
 static struct config_value *_value(struct parser *p);
 static struct config_value *_type(struct parser *p);
-static void _parse_error(struct parser *p, const char *file, int line,
-                        const char *mess);
 static int _match_aux(struct parser *p, int t);
 static struct config_value *_create_value(struct parser *p);
 static struct config_node *_create_node(struct parser *p);
@@ -66,7 +64,7 @@ static int _tok_match(const char *str, const char *b, const char *e);
 
 #define match(t) do {\
    if (!_match_aux(p, (t))) {\
-      _parse_error(p, __FILE__, __LINE__, "unexpected token"); \
+       log_error("Parse error at line %d: unexpected token", p->line); \
       return 0;\
    } \
 } while(0);
@@ -349,18 +347,12 @@ static struct config_value *_type(struct parser *p) {
                 break;
 
         default:
-                _parse_error(p, __FILE__, __LINE__, "expected a value");
+               log_error("Parse error at line %d: expected a value", p->line);
                 return 0;
         }
         return v;
 }
 
-static void _parse_error(struct parser *p, const char *file, int line,
-                        const char *mess)
-{
-        plog(_LOG_ERR, file, line, "parse error at %d: %s", p->line, mess);
-}
-
 static int _match_aux(struct parser *p, int t)
 {
        if (p->t != t)
index 4cda83f6fa0d27d0b792b71a36e6b47055cb4e25..974751f0808c05c9536c8d0dd025e27cf64c2eca 100644 (file)
@@ -238,6 +238,18 @@ void dev_cache_exit(void)
 int dev_cache_add_dir(const char *path)
 {
        struct dir_list *dl;
+       struct stat st;
+
+       if (stat(path, &st)) {
+               log_error("Ignoring %s: %s", path, strerror(errno));
+               /* But don't fail */
+               return 1;
+       }
+
+       if (!S_ISDIR(st.st_mode)) {
+               log_error("Ignoring %s: Not a directory", path);
+               return 1;
+       }
 
        if (!(dl = _alloc(sizeof(*dl) + strlen(path) + 1)))
                return 0;
index 457c2cf218502019f5730808bbcb0b304952e778..6fd2c6337cf798b6ed53c57914eac0359e962927 100644 (file)
@@ -55,7 +55,7 @@ static int _load(struct pfilter *pf)
        }
 
        if (!(cn = find_config_node(cf->root, "/valid_devices", '/'))) {
-               log_info("couldn't find 'valid_devices' array in '%s'",
+               log_info("Couldn't find 'valid_devices' array in '%s'",
                         pf->file);
                goto out;
        }
@@ -66,13 +66,13 @@ static int _load(struct pfilter *pf)
         */
        for (cv = cn->v; cv; cv = cv->next) {
                if (cv->type != CFG_STRING) {
-                       log_info("valid_devices array contains a value "
+                       log_info("Valid_devices array contains a value "
                                 "which is not a string ... ignoring");
                        continue;
                }
 
                if (!hash_insert(pf->devices, cv->v.str, PF_UNCHECKED))
-                       log_info("couldn't add '%s' to filter ... ignoring",
+                       log_info("Couldn't add '%s' to filter ... ignoring",
                                 cv->v.str);
        }
        r = 1;
@@ -88,6 +88,8 @@ static int _dump(struct pfilter *pf)
        struct hash_node *n;
        FILE *fp = fopen(pf->file, "w");
 
+       log_very_verbose("Dumping persistent device cache to %s", pf->file);
+
        if (!fp) {
                log_info("Couldn't open '%s' for to hold valid devices.",
                         pf->file);
@@ -118,6 +120,8 @@ static int _check(const char *path)
 
        if (fd >= 0)
                r = 1;
+       else
+               log_debug("Unable to open %s: %s", path, strerror(errno));
 
        close(fd);
        return r;
index 0d1766a2a30aefb87dd6224920913692c3c32c7f..f25744c6427149cfc310299837f7d466c0e78fbb 100644 (file)
@@ -54,10 +54,8 @@ static device_info_t device_info[] = {
 
 static int *scan_proc_dev(void);
 
-static int passes_config_device_filter(struct dev_filter *f, struct device *dev)
+static int passes_lvm_type_device_filter(struct dev_filter *f, struct device *dev)
 {
-       /* FIXME Check against config file scan/reject entries */
-
        /* Is this a recognised device type? */
        if (!(((int *) f->private)[MAJOR(dev->dev)]))
                return 0;
@@ -65,7 +63,7 @@ static int passes_config_device_filter(struct dev_filter *f, struct device *dev)
                return 1;
 }
 
-struct dev_filter *config_filter_create()
+struct dev_filter *lvm_type_filter_create()
 {
        struct dev_filter *f;
 
@@ -74,7 +72,7 @@ struct dev_filter *config_filter_create()
                return NULL;
        }
 
-       f->passes_filter = passes_config_device_filter;
+       f->passes_filter = passes_lvm_type_device_filter;
 
        if (!(f->private = scan_proc_dev()))
                return NULL;
@@ -82,7 +80,7 @@ struct dev_filter *config_filter_create()
        return f;
 }
 
-void config_filter_destroy(struct dev_filter *f)
+void lvm_type_filter_destroy(struct dev_filter *f)
 {
        dbg_free(f->private);
        dbg_free(f);
index 582a4432791169fd6d1263f9e9ab78e74ebb3be4..e655599bf4ce152d2a032bac4380b1c478e396b6 100644 (file)
@@ -21,9 +21,9 @@
 #ifndef _LVM_FILTER_H
 #define _LVM_FILTER_H
 
-struct dev_filter *config_filter_create();
+struct dev_filter *lvm_type_filter_create();
 
-void config_filter_destroy(struct dev_filter *f);
+void lvm_type_filter_destroy(struct dev_filter *f);
 
 #endif
 
index 53cc8f7ee079d196892c69a4702ebac09a97fc18..65fb3f6bd80f4ede080a7986616769cc8d054c11 100644 (file)
@@ -36,7 +36,7 @@ struct pool *pool_create(size_t chunk_hint)
        struct pool *p = dbg_malloc(sizeof(*p));
 
        if (!p) {
-               log_err("couldn't create pool");
+               log_error("Couldn't create memory pool");
                return 0;
        }
        memset(p, 0, sizeof(*p));
@@ -115,7 +115,7 @@ void pool_free(struct pool *p, void *ptr)
        }
 
        if (!c)
-               log_warn("pool_free asked to free a pointer "
+               log_debug("pool_free asked to free a pointer "
                         "that wasn't in the pool, doing nothing");
        else
                p->chunk = c;
index 30a1a83e963d9b72c77f47e7e083e2b1c5e39784..080fe4abc4e6f222211f0d6d3f602fe3fa5029d3 100644 (file)
@@ -559,7 +559,7 @@ static void __init_log(struct config_file *cf)
        if (log_file) {
                /* set up the logging */
                if (!(_log = fopen(log_file, "w")))
-                       log_error("couldn't open log file %s\n", log_file);
+                       log_error("Couldn't open log file %s", log_file);
                else
                        init_log(_log);
        }
@@ -568,6 +568,67 @@ static void __init_log(struct config_file *cf)
        init_debug(_debug_level);
 }
 
+static int dev_cache_setup(void)
+{
+       struct config_node *cn;
+       struct config_value *cv;
+
+       if (!dev_cache_init()) {
+               stack;
+               return 0;
+       }
+
+       if (!(cn = find_config_node(_cf->root, "devices/scan", '/'))) {
+               if (!dev_cache_add_dir("/dev")) {
+                       log_error("Failed to add /dev to internal "
+                                 "device cache");
+                       return 0;
+               }
+       }
+
+       for (cv = cn->v; cv; cv = cv->next) {
+               if (cv->type != CFG_STRING) {
+                       log_error("Invalid string in config file: "
+                                 "devices/scan");
+                       return 0;
+               }
+       
+               if (!dev_cache_add_dir(cv->v.str)) {
+                       log_error("Failed to add %s to internal device cache", 
+                                 cv->v.str);
+                       return 0;
+               }
+       } 
+               
+       return 1;
+}
+
+static struct dev_filter *filter_setup(void)
+{
+       struct config_node *cn;
+       struct dev_filter *f1, *f2, *f3, *f4;
+
+       if (!(f1 = lvm_type_filter_create()))
+               return 0;
+
+       if (!(cn = find_config_node(_cf->root, "devices/filter", '/'))) {
+               log_debug("devices/filter not found in config file");
+               return f1;
+       }
+
+       if (!(f2 = regex_filter_create(cn->v))) {
+               log_error("Failed to create regex device filter");
+               return f1;
+       }
+
+       if (!(f4 = composite_filter_create(2, f1, f2))) {
+               log_error("Failed to create composite device filter");
+               return f1;
+       }
+
+       return f4;
+}
+
 static int init(void)
 {
        int ret = 0;
@@ -593,25 +654,20 @@ static int init(void)
        if (stat(e, &info) != -1) {
                /* we've found a config file */
                if (!read_config(_cf, e)) {
-                       stack;
+                       log_error("Failed to load config file %s", e);
                        goto out;
                }
 
                __init_log(_cf);
        }
 
-       if (!dev_cache_init()) {
-               stack;
-               goto out;
-       }
 
-       if (!dev_cache_add_dir("/dev")) {
-               log_error("Failed to add %s to internal device cache", prefix);
+       if (!dev_cache_setup()) {
                goto out;
        }
 
-       if (!(_filter = config_filter_create())) {
-               /* Add scan & rejects from _cf->root */
+       if (!(_filter = filter_setup())) {
+               log_error("Failed to set up internal device filters");
                goto out;
        }
 
@@ -643,7 +699,7 @@ static void __fin_commands(void)
 static void fin(void)
 {
        ios->destroy(ios);
-       config_filter_destroy(_filter);
+       lvm_type_filter_destroy(_filter);
        dev_cache_exit();
        destroy_config_file(_cf);
        __fin_commands();
index aab155f70cfbf488336272561013870ce86f43b2..d3caf1245cb5b30123722e636f27a7de743989fd 100644 (file)
@@ -38,6 +38,8 @@
 #include "display.h"
 #include "errors.h"
 #include "filter.h"
+#include "filter-composite.h"
+#include "filter-regex.h"
 #include "format1.h"
 #include "toollib.h"
 #include "activate.h"
This page took 0.047982 seconds and 5 git commands to generate.