mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
o composite filter that allows us to merge filters. Think of it as &&'ing
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.
This commit is contained in:
parent
5f16718b19
commit
12eabe3031
@ -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 \
|
||||
|
70
lib/filters/filter-composite.c
Normal file
70
lib/filters/filter-composite.c
Normal file
@ -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;
|
||||
}
|
14
lib/filters/filter-composite.h
Normal file
14
lib/filters/filter-composite.h
Normal file
@ -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
|
@ -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;
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
#ifndef _LVM_FILTER_PERSISTENT_H
|
||||
#define _LVM_FILTER_PERSISTENT_h
|
||||
#define _LVM_FILTER_PERSISTENT_H
|
||||
|
||||
#include "dev-cache.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user