[libmultipath] simplify the blacklist handling
authorroot <root@potab.(none)>
Wed, 10 Aug 2005 16:38:11 +0000 (18:38 +0200)
committerroot <root@potab.(none)>
Wed, 10 Aug 2005 16:38:11 +0000 (18:38 +0200)
No need to carry along the regex string.
So no need for a "struct blentry".
Now a blist vector directly holds regex_t entries.

libmultipath/blacklist.c
libmultipath/blacklist.h

index c0f5aa9..066f527 100644 (file)
 static int
 store_ble (vector blist, char * str)
 {
-       struct blentry * ble;
+       regex_t * ble;
        
        if (!str)
                return 0;
 
-       ble = (struct blentry *)MALLOC(sizeof(struct blentry));
+       ble = MALLOC(sizeof(regex_t));
 
        if (!ble)
                goto out;
 
-       ble->preg = MALLOC(sizeof(regex_t));
-
-       if (!ble->preg)
+       if (regcomp(ble, str, REG_EXTENDED|REG_NOSUB))
                goto out1;
 
-       ble->str = (char *)MALLOC(strlen(str) + 1);
-
-       if (!ble->str)
-               goto out2;
-
-       strcpy(ble->str, str);
-
-       if (regcomp((regex_t *)ble->preg, ble->str, REG_EXTENDED|REG_NOSUB))
-               goto out3;
-
        if (!vector_alloc_slot(blist))
-               goto out3;
+               goto out1;
 
        vector_set_slot(blist, ble);
        return 0;
-out3:
-       FREE(ble->str);
-out2:
-       FREE(ble->preg);
 out1:
        FREE(ble);
 out:
@@ -66,10 +50,10 @@ int
 blacklist (vector blist, char * dev)
 {
        int i;
-       struct blentry *ble;
+       regex_t * ble;
 
        vector_foreach_slot (blist, ble, i) {
-               if (!regexec(ble->preg, dev, 0, NULL, 0)) {
+               if (!regexec(ble, dev, 0, NULL, 0)) {
                        condlog(3, "%s blacklisted", dev);
                        return 1;
                }
@@ -92,20 +76,15 @@ store_regex (vector blist, char * regex)
 void
 free_blacklist (vector blist)
 {
-       struct blentry * ble;
+       regex_t * ble;
        int i;
 
        if (!blist)
                return;
 
-       vector_foreach_slot (blist, ble, i) {
-               if (ble->str)
-                       FREE(ble->str);
-
-               if (ble->preg)
-                       FREE(ble->preg);
+       vector_foreach_slot (blist, ble, i)
+               if (ble)
+                       FREE(ble);
 
-               FREE(ble);
-       }
        vector_free(blist);
 }
index 1b0fc05..9817c9b 100644 (file)
@@ -3,11 +3,6 @@
 
 #define BLIST_ENTRY_SIZE 255
 
-struct blentry {
-       char * str;
-       void * preg;
-};
-
 int setup_default_blist (vector blist);
 int blacklist (vector blist, char * dev);
 int store_regex (vector blist, char * regex);