multipathd: fix reservation_key check
[multipath-tools/.git] / libmultipath / config.c
index ed51afb..085a3e1 100644 (file)
@@ -25,6 +25,7 @@
 #include "prio.h"
 #include "devmapper.h"
 #include "mpath_cmd.h"
+#include "propsel.h"
 
 static int
 hwe_strmatch (struct hwentry *hwe1, struct hwentry *hwe2)
@@ -80,7 +81,8 @@ hwe_regmatch (struct hwentry *hwe1, struct hwentry *hwe2)
            regcomp(&rre, hwe1->revision, REG_EXTENDED|REG_NOSUB))
                goto out_pre;
 
-       if ((!hwe1->vendor || !hwe2->vendor ||
+       if ((hwe2->vendor || hwe2->product || hwe2->revision) &&
+           (!hwe1->vendor || !hwe2->vendor ||
             !regexec(&vre, hwe2->vendor, 0, NULL, 0)) &&
            (!hwe1->product || !hwe2->product ||
             !regexec(&pre, hwe2->product, 0, NULL, 0)) &&
@@ -124,8 +126,7 @@ find_hwe (vector hwtable, char * vendor, char * product, char * revision)
        return ret;
 }
 
-extern struct mpentry *
-find_mpe (vector mptable, char * wwid)
+struct mpentry *find_mpe(vector mptable, char *wwid)
 {
        int i;
        struct mpentry * mpe;
@@ -140,8 +141,7 @@ find_mpe (vector mptable, char * wwid)
        return NULL;
 }
 
-extern char *
-get_mpe_wwid (vector mptable, char * alias)
+char *get_mpe_wwid(vector mptable, char *alias)
 {
        int i;
        struct mpentry * mpe;
@@ -319,6 +319,7 @@ set_param_str(char * str)
 static int
 merge_hwe (struct hwentry * dst, struct hwentry * src)
 {
+       char id[SCSI_VENDOR_SIZE+PATH_PRODUCT_SIZE];
        merge_str(vendor);
        merge_str(product);
        merge_str(revision);
@@ -344,19 +345,18 @@ merge_hwe (struct hwentry * dst, struct hwentry * src)
        merge_num(user_friendly_names);
        merge_num(retain_hwhandler);
        merge_num(detect_prio);
+       merge_num(detect_checker);
        merge_num(deferred_remove);
        merge_num(delay_watch_checks);
        merge_num(delay_wait_checks);
-
-       /*
-        * Make sure features is consistent with
-        * no_path_retry
-        */
-       if (dst->no_path_retry == NO_PATH_RETRY_FAIL)
-               remove_feature(&dst->features, "queue_if_no_path");
-       else if (dst->no_path_retry != NO_PATH_RETRY_UNDEF)
-               add_feature(&dst->features, "queue_if_no_path");
-
+       merge_num(skip_kpartx);
+       merge_num(max_sectors_kb);
+       merge_num(ghost_delay);
+
+       snprintf(id, sizeof(id), "%s/%s", dst->vendor, dst->product);
+       reconcile_features_with_options(id, &dst->features,
+                                       &dst->no_path_retry,
+                                       &dst->retain_hwhandler);
        return 0;
 }
 
@@ -419,6 +419,8 @@ store_hwe (vector hwtable, struct hwentry * dhwe)
        hwe->user_friendly_names = dhwe->user_friendly_names;
        hwe->retain_hwhandler = dhwe->retain_hwhandler;
        hwe->detect_prio = dhwe->detect_prio;
+       hwe->detect_checker = dhwe->detect_checker;
+       hwe->ghost_delay = dhwe->ghost_delay;
 
        if (dhwe->bl_product && !(hwe->bl_product = set_param_str(dhwe->bl_product)))
                goto out;
@@ -445,6 +447,13 @@ restart:
                        break;
                j = n;
                vector_foreach_slot_after(hw, hwe2, j) {
+                       /* drop invalid device configs */
+                       if (!hwe2->vendor || !hwe2->product) {
+                               condlog(0, "device config missing vendor or product parameter");
+                               vector_del_slot(hw, j--);
+                               free_hwe(hwe2);
+                               continue;
+                       }
                        if (hwe_regmatch(hwe1, hwe2))
                                continue;
                        /* dup */
@@ -487,6 +496,9 @@ free_config (struct config * conf)
        if (conf->uid_attribute)
                FREE(conf->uid_attribute);
 
+       if (conf->uid_attrs)
+               FREE(conf->uid_attrs);
+
        if (conf->getuid)
                FREE(conf->getuid);
 
@@ -502,6 +514,9 @@ free_config (struct config * conf)
        if (conf->wwids_file)
                FREE(conf->wwids_file);
 
+       if (conf->prkeys_file)
+               FREE(conf->prkeys_file);
+
        if (conf->prio_name)
                FREE(conf->prio_name);
 
@@ -519,9 +534,6 @@ free_config (struct config * conf)
        if (conf->config_dir)
                FREE(conf->config_dir);
 
-       if (conf->reservation_key)
-               FREE(conf->reservation_key);
-
        free_blacklist(conf->blist_devnode);
        free_blacklist(conf->blist_wwid);
        free_blacklist(conf->blist_property);
@@ -590,32 +602,26 @@ load_config (char * file)
        if (!conf->verbosity)
                conf->verbosity = DEFAULT_VERBOSITY;
 
-       conf->minio = DEFAULT_MINIO;
-       conf->minio_rq = DEFAULT_MINIO_RQ;
        get_sys_max_fds(&conf->max_fds);
        conf->bindings_file = set_default(DEFAULT_BINDINGS_FILE);
        conf->wwids_file = set_default(DEFAULT_WWIDS_FILE);
+       conf->prkeys_file = set_default(DEFAULT_PRKEYS_FILE);
        conf->multipath_dir = set_default(DEFAULT_MULTIPATHDIR);
-       conf->features = set_default(DEFAULT_FEATURES);
-       conf->flush_on_last_del = DEFAULT_FLUSH;
        conf->attribute_flags = 0;
        conf->reassign_maps = DEFAULT_REASSIGN_MAPS;
        conf->checkint = DEFAULT_CHECKINT;
        conf->max_checkint = 0;
-       conf->pgfailback = DEFAULT_FAILBACK;
-       conf->fast_io_fail = DEFAULT_FAST_IO_FAIL;
-       conf->retain_hwhandler = DEFAULT_RETAIN_HWHANDLER;
-       conf->detect_prio = DEFAULT_DETECT_PRIO;
        conf->force_sync = DEFAULT_FORCE_SYNC;
        conf->partition_delim = DEFAULT_PARTITION_DELIM;
        conf->processed_main_config = 0;
        conf->find_multipaths = DEFAULT_FIND_MULTIPATHS;
        conf->uxsock_timeout = DEFAULT_REPLY_TIMEOUT;
-       conf->uid_attribute = set_default(DEFAULT_UID_ATTRIBUTE);
        conf->retrigger_tries = DEFAULT_RETRIGGER_TRIES;
        conf->retrigger_delay = DEFAULT_RETRIGGER_DELAY;
        conf->uev_wait_timeout = DEFAULT_UEV_WAIT_TIMEOUT;
-       conf->deferred_remove = DEFAULT_DEFERRED_REMOVE;
+       conf->disable_changed_wwids = DEFAULT_DISABLE_CHANGED_WWIDS;
+       conf->remove_retries = 0;
+       conf->ghost_delay = DEFAULT_GHOST_DELAY;
 
        /*
         * preload default hwtable
@@ -726,7 +732,7 @@ load_config (char * file)
                conf->bindings_file = set_default(DEFAULT_BINDINGS_FILE);
 
        if (!conf->multipath_dir || !conf->bindings_file ||
-           !conf->wwids_file)
+           !conf->wwids_file || !conf->prkeys_file)
                goto out;
 
        return conf;