]> sourceware.org Git - lvm2.git/commitdiff
o composite filter that allows us to merge filters. Think of it as &&'ing
authorJoe Thornber <thornber@redhat.com>
Mon, 22 Oct 2001 14:39:12 +0000 (14:39 +0000)
committerJoe Thornber <thornber@redhat.com>
Mon, 22 Oct 2001 14:39:12 +0000 (14:39 +0000)
  filters in order.

eg,

f = composite_filter_create(2, regex_filter, persistent_filter);

  ownership of the filters passes, they will be destroyed when f's
  destroy method is called.

lib/Makefile.in
lib/filters/filter-composite.c [new file with mode: 0644]
lib/filters/filter-composite.h [new file with mode: 0644]
lib/filters/filter-persistent.c
lib/filters/filter-persistent.h

index 58af73cc8d663820a7e8a259070f28456383037c..2e55bd08bcaf8536d4c4f5c18279c28bc926b8d6 100644 (file)
@@ -16,9 +16,10 @@ SOURCES=\
        device/dev-cache.c \
        device/dev-io.c \
        device/device.c \
+       display/display.c \
+       filters/filter-composite.c \
        filters/filter-persistent.c \
        filters/filter-regex.c \
-       display/display.c \
        filters/filter.c \
        format1/disk-rep.c \
        format1/format1.c \
diff --git a/lib/filters/filter-composite.c b/lib/filters/filter-composite.c
new file mode 100644 (file)
index 0000000..df6aa4c
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2001 Sistina Software (UK) Limited.
+ *
+ * This file is released under the GPL.
+ */
+
+#include "filter-composite.h"
+#include "dbg_malloc.h"
+#include "log.h"
+
+#include <stdarg.h>
+
+static int _and_p(struct dev_filter *f, struct device *dev)
+{
+       struct dev_filter **filters = (struct dev_filter **) f->private;
+
+       while (*filters) {
+               if (!(*filters)->passes_filter(*filters, dev))
+                       return 0;
+               filters++;
+       }
+
+       return 1;
+}
+
+void _destroy(struct dev_filter *f)
+{
+       struct dev_filter **filters = (struct dev_filter **) f->private;
+
+       while (*filters) {
+               (*filters)->destroy(*filters);
+               filters++;
+       }
+
+       dbg_free(f->private);
+}
+
+
+struct dev_filter *composite_filter_create(int n, ...)
+{
+       struct dev_filter **filters = dbg_malloc(sizeof(*filters) * (n + 1));
+       struct dev_filter *cf;
+       va_list ap;
+       int i;
+
+       if (!filters) {
+               stack;
+               return NULL;
+       }
+
+       if (!(cf = dbg_malloc(sizeof(*cf)))) {
+               stack;
+               dbg_free(filters);
+               return NULL;
+       }
+
+       va_start(ap, n);
+       for (i = 0; i < n; i++) {
+               struct dev_filter *f = va_arg(ap, struct dev_filter *);
+               filters[i] = f;
+       }
+       filters[i] = NULL;
+       va_end(ap);
+
+       cf->passes_filter = _and_p;
+       cf->destroy = _destroy;
+       cf->private = filters;
+
+       return cf;
+}
diff --git a/lib/filters/filter-composite.h b/lib/filters/filter-composite.h
new file mode 100644 (file)
index 0000000..7462e4e
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * Copyright (C) 2001 Sistina Software (UK) Limited.
+ *
+ * This file is released under the GPL.
+ */
+
+#ifndef _LVM_FILTER_COMPOSITE_H
+#define _LVM_FILTER_COMPOSITE_H
+
+#include "dev-cache.h"
+
+struct dev_filter *composite_filter_create(int n, ...);
+
+#endif
index b236e3be920f47a8831cd6d5fb170ac714373348..457c2cf218502019f5730808bbcb0b304952e778 100644 (file)
@@ -28,7 +28,7 @@ struct pfilter {
 #define PF_UNCHECKED ((void *) 1)
 #define PF_CHECKED ((void *) 2)
 
-int _init_hash(struct pfilter *pf)
+static int _init_hash(struct pfilter *pf)
 {
        if (pf->devices)
                hash_destroy(pf->devices);
@@ -37,7 +37,7 @@ int _init_hash(struct pfilter *pf)
        return pf ? 1 : 0;
 }
 
-int _load(struct pfilter *pf)
+static int _load(struct pfilter *pf)
 {
        int r = 0;
        struct config_file *cf;
@@ -82,7 +82,7 @@ int _load(struct pfilter *pf)
        return r;
 }
 
-int _dump(struct pfilter *pf)
+static int _dump(struct pfilter *pf)
 {
        int first = 1;
        struct hash_node *n;
@@ -112,7 +112,7 @@ int _dump(struct pfilter *pf)
        return 1;
 }
 
-int _check(const char *path)
+static int _check(const char *path)
 {
        int fd = open(path, O_RDONLY), r = 0;
 
@@ -123,7 +123,7 @@ int _check(const char *path)
        return r;
 }
 
-int _init_valid_p(struct dev_filter *f, struct device *dev)
+static int _init_valid_p(struct dev_filter *f, struct device *dev)
 {
        struct pfilter *pf = (struct pfilter *) f->private;
        void *l = hash_lookup(pf->devices, dev->name);
@@ -139,7 +139,7 @@ int _init_valid_p(struct dev_filter *f, struct device *dev)
        return 0;
 }
 
-int _valid_p(struct dev_filter *f, struct device *dev)
+static int _valid_p(struct dev_filter *f, struct device *dev)
 {
        struct pfilter *pf = (struct pfilter *) f->private;
        void *l = hash_lookup(pf->devices, dev->name);
@@ -155,7 +155,7 @@ int _valid_p(struct dev_filter *f, struct device *dev)
        return 1;
 }
 
-void _destroy(struct dev_filter *f)
+static void _destroy(struct dev_filter *f)
 {
        struct pfilter *pf = (struct pfilter *) f->private;
 
index 8f445762ba05afc3cb90591dfaa4bb5789bed6e8..6d68e1c4dcf2772b6b45d3d8c65684480e7632b8 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef _LVM_FILTER_PERSISTENT_H
-#define _LVM_FILTER_PERSISTENT_h
+#define _LVM_FILTER_PERSISTENT_H
 
 #include "dev-cache.h"
 
This page took 0.038295 seconds and 5 git commands to generate.