apply the same treatment to prioritizer than Ben applied to checkers
authorChristophe Varoqui <christophe.varoqui@free.fr>
Sun, 18 May 2008 15:48:37 +0000 (17:48 +0200)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Wed, 21 May 2008 20:01:18 +0000 (22:01 +0200)
ie:
o don't so prio shared object if not used
o error if prioritizer lib is not found instead of falling back to default

I also had to move up the multipath_dir initialization in load_config()
because add_prio/add_checker need the var to load the shared object.
Also realize the multpath_dir keyword has to be  set before default:prio
and default:checker in the config file.

A correct solution would be to defer the loads to the end of the config
file processing. Contribution welcome.

libmultipath/config.c
libmultipath/config.h
libmultipath/dict.c
libmultipath/hwtable.c
libmultipath/prio.c
libmultipath/prio.h
libmultipath/propsel.c

index 0518e3a..86c9a4b 100644 (file)
@@ -274,12 +274,14 @@ store_hwe (vector hwtable, struct hwentry * dhwe)
        if (dhwe->checker_name && !(hwe->checker_name = set_param_str(dhwe->checker_name)))
                goto out;
                                
+       if (dhwe->prio_name && !(hwe->prio_name = set_param_str(dhwe->prio_name)))
+               goto out;
+                               
        hwe->pgpolicy = dhwe->pgpolicy;
        hwe->pgfailback = dhwe->pgfailback;
        hwe->rr_weight = dhwe->rr_weight;
        hwe->no_path_retry = dhwe->no_path_retry;
        hwe->minio = dhwe->minio;
-       hwe->prio = dhwe->prio;
 
        if (dhwe->bl_product && !(hwe->bl_product = set_param_str(dhwe->bl_product)))
                goto out;
@@ -360,6 +362,7 @@ load_config (char * file)
        conf->minio = 1000;
        conf->max_fds = 0;
        conf->bindings_file = DEFAULT_BINDINGS_FILE;
+       conf->multipath_dir = set_default(DEFAULT_MULTIPATHDIR);
 
        /*
         * read the config file
@@ -375,9 +378,6 @@ load_config (char * file)
        /*
         * fill the voids left in the config file
         */
-       if (conf->multipath_dir == NULL)
-               conf->multipath_dir = set_default(DEFAULT_MULTIPATHDIR);
-
        if (conf->hwtable == NULL) {
                conf->hwtable = vector_alloc();
 
@@ -454,8 +454,8 @@ load_config (char * file)
            !conf->hwhandler)
                goto out;
 
-       if (!conf->prio)
-               conf->prio = prio_default();
+       if (!conf->prio_name)
+               conf->prio_name = set_default(DEFAULT_PRIO);
 
        if (!conf->checker_name)
                conf->checker_name = set_default(DEFAULT_CHECKER);
index 3483d6d..fb917f4 100644 (file)
@@ -28,7 +28,6 @@ struct hwentry {
        int no_path_retry;
        int minio;
        int pg_timeout;
-       struct prio * prio;
        char * bl_product;
 };
 
@@ -53,7 +52,6 @@ struct config {
        int pgpolicy_flag;
        int with_sysfs;
        int pgpolicy;
-       struct prio * prio;
        enum devtypes dev_type;
        int minio;
        int checkint;
@@ -76,6 +74,7 @@ struct config {
        char * features;
        char * hwhandler;
        char * bindings_file;
+       char * prio_name;
        char * checker_name;
 
        vector keywords;
index ac5851a..f851890 100644 (file)
@@ -95,14 +95,11 @@ def_getuid_callout_handler(vector strvec)
 static int
 def_prio_handler(vector strvec)
 {
-       char * buff;
+       conf->prio_name = set_value(strvec);
 
-       buff = set_value(strvec);
-       if (!buff)
+       if (!conf->prio_name)
                return 1;
 
-       conf->prio = prio_lookup(buff);
-       FREE(buff);
        return 0;
 }
 
@@ -593,17 +590,15 @@ static int
 hw_prio_handler(vector strvec)
 {
        struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
-       char * buff;
-       
+
        if (!hwe)
                return 1;
 
-       buff = set_value(strvec);
-       if (!buff)
+       hwe->prio_name = set_value(strvec);
+
+       if (!hwe->prio_name)
                return 1;
-       
-       hwe->prio = prio_lookup(buff);
-       FREE(buff);
+
        return 0;
 }
 
@@ -1135,12 +1130,12 @@ snprint_hw_prio (char * buff, int len, void * data)
 {
        struct hwentry * hwe = (struct hwentry *)data;
 
-       if (!hwe->prio)
+       if (!hwe->prio_name)
                return 0;
-       if (hwe->prio == conf->prio)
+       if (!strcmp(hwe->prio_name, conf->prio_name))
                return 0;
        
-       return snprintf(buff, len, "%s", prio_name(hwe->prio));
+       return snprintf(buff, len, "%s", hwe->prio_name);
 }
 
 static int
@@ -1385,10 +1380,14 @@ snprint_def_getuid_callout (char * buff, int len, void * data)
 static int
 snprint_def_prio (char * buff, int len, void * data)
 {
-       if (!conf->prio)
+       if (!conf->prio_name)
                return 0;
 
-       return snprintf(buff, len, "%s", prio_name(conf->prio));
+       if (strlen(conf->prio_name) == strlen(DEFAULT_PRIO) &&
+           !strcmp(conf->prio_name, DEFAULT_PRIO))
+               return 0;
+       
+       return snprintf(buff, len, "%s", conf->prio_name);
 }
 
 static int
index d879cb1..2afed20 100644 (file)
@@ -732,7 +732,6 @@ setup_default_hwtable (vector hw)
        struct hwentry * hwe = default_hw;
 
        while (hwe->vendor) {
-               hwe->prio = prio_lookup(hwe->prio_name);
                r += store_hwe(hw, hwe);
                hwe++;
        }
index 54393f2..c9d2873 100644 (file)
@@ -46,10 +46,7 @@ struct prio * prio_lookup (char * name)
                if (!strncmp(name, p->name, PRIO_NAME_LEN))
                        return p;
        }
-       p = add_prio(name);
-       if (p)
-               return p;
-       return prio_default();
+       return add_prio(name);
 }
 
 struct prio * add_prio (char * name)
@@ -94,8 +91,3 @@ char * prio_name (struct prio * p)
 {
        return p->name;
 }
-
-struct prio * prio_default (void)
-{
-       return prio_lookup(DEFAULT_PRIO);
-}
index 6bf6d4b..491e6fc 100644 (file)
@@ -46,6 +46,5 @@ struct prio * add_prio (char *);
 struct prio * prio_lookup (char *);
 int prio_getprio (struct prio *, struct path *);
 char * prio_name (struct prio *);
-struct prio * prio_default (void);
 
 #endif /* _PRIO_H */
index 071c913..bd85cb9 100644 (file)
@@ -259,21 +259,21 @@ select_getuid (struct path * pp)
 extern int
 select_prio (struct path * pp)
 {
-       if (pp->hwe && pp->hwe->prio) {
-               pp->prio = pp->hwe->prio;
+       if (pp->hwe && pp->hwe->prio_name) {
+               pp->prio = prio_lookup(pp->hwe->prio_name);
                condlog(3, "%s: prio = %s (controller setting)",
-                       pp->dev, prio_name(pp->prio));
+                       pp->dev, pp->hwe->prio_name);
                return 0;
        }
-       if (conf->prio) {
-               pp->prio = conf->prio;
+       if (conf->prio_name) {
+               pp->prio = prio_lookup(conf->prio_name);
                condlog(3, "%s: prio = %s (config file default)",
-                       pp->dev, prio_name(pp->prio));
+                       pp->dev, conf->prio_name);
                return 0;
        }
-       pp->prio = prio_default();
+       pp->prio = prio_lookup(DEFAULT_PRIO);
        condlog(3, "%s: prio = %s (internal default)",
-               pp->dev, prio_name(pp->prio));
+               pp->dev, DEFAULT_PRIO);
        return 0;
 }