libmultipath: separate out 'udev' config entry
authorHannes Reinecke <hare@suse.de>
Mon, 6 Jun 2016 12:40:05 +0000 (14:40 +0200)
committerHannes Reinecke <hare@suse.de>
Mon, 4 Jul 2016 06:38:39 +0000 (08:38 +0200)
Rather than add the 'udev' structure to the config entry we should
be using a separate global variable here. Otherwise we run into
a risk of udev getting out-of-sync internally when recreating
the udev structure.

Signed-off-by: Hannes Reinecke <hare@suse.com>
libmpathpersist/mpath_persist.c
libmultipath/config.c
libmultipath/config.h
libmultipath/configure.c
libmultipath/discovery.c
libmultipath/print.c
multipath/main.c
multipathd/cli_handlers.c
multipathd/main.c

index af2374f..dc11d4f 100644 (file)
 
 #define __STDC_FORMAT_MACROS 1
 
+struct udev *udev;
 
 int
 mpath_lib_init (struct udev *udev)
 {
-       if (load_config(DEFAULT_CONFIGFILE, udev)){
+       if (load_config(DEFAULT_CONFIGFILE)){
                condlog(0, "Failed to initialize multipath config.");
                return 1;
        }
index 137ff6a..3e59205 100644 (file)
@@ -577,7 +577,7 @@ process_config_dir(vector keywords, char *dir)
 }
 
 int
-load_config (char * file, struct udev *udev)
+load_config (char * file)
 {
        if (!conf)
                conf = alloc_config();
@@ -591,7 +591,6 @@ load_config (char * file, struct udev *udev)
        if (!conf->verbosity)
                conf->verbosity = DEFAULT_VERBOSITY;
 
-       conf->udev = udev;
        conf->minio = DEFAULT_MINIO;
        conf->minio_rq = DEFAULT_MINIO_RQ;
        get_sys_max_fds(&conf->max_fds);
index 8ebc43f..4a043b9 100644 (file)
@@ -141,7 +141,6 @@ struct config {
        int uev_wait_timeout;
        unsigned int version[3];
 
-       struct udev * udev;
        char * multipath_dir;
        char * selector;
        char * uid_attribute;
@@ -174,6 +173,7 @@ struct config {
 };
 
 struct config * conf;
+extern struct udev * udev;
 
 struct hwentry * find_hwe (vector hwtable, char * vendor, char * product, char *revision);
 struct mpentry * find_mpe (vector mptable, char * wwid);
@@ -189,7 +189,7 @@ void free_mptable (vector mptable);
 
 int store_hwe (vector hwtable, struct hwentry *);
 
-int load_config (char * file, struct udev * udev);
+int load_config (char * file);
 struct config * alloc_config (void);
 void free_config (struct config * conf);
 
index ab53af2..ce07741 100644 (file)
@@ -953,7 +953,7 @@ get_refwwid (enum mpath_cmds cmd, char * dev, enum devtypes dev_type,
 
                pp = find_path_by_dev(pathvec, buff);
                if (!pp) {
-                       struct udev_device *udevice = udev_device_new_from_subsystem_sysname(conf->udev, "block", buff);
+                       struct udev_device *udevice = udev_device_new_from_subsystem_sysname(udev, "block", buff);
 
                        if (!udevice) {
                                condlog(2, "%s: can't get udev device", buff);
@@ -985,7 +985,7 @@ get_refwwid (enum mpath_cmds cmd, char * dev, enum devtypes dev_type,
                }
                pp = find_path_by_dev(pathvec, buff);
                if (!pp) {
-                       struct udev_device *udevice = udev_device_new_from_devnum(conf->udev, 'b', parse_devt(dev));
+                       struct udev_device *udevice = udev_device_new_from_devnum(udev, 'b', parse_devt(dev));
 
                        if (!udevice) {
                                condlog(2, "%s: can't get udev device", dev);
@@ -1010,7 +1010,7 @@ get_refwwid (enum mpath_cmds cmd, char * dev, enum devtypes dev_type,
        }
 
        if (dev_type == DEV_UEVENT) {
-               struct udev_device *udevice = udev_device_new_from_environment(conf->udev);
+               struct udev_device *udevice = udev_device_new_from_environment(udev);
 
                if (!udevice) {
                        condlog(2, "%s: can't get udev device", dev);
index 019faef..d850aba 100644 (file)
@@ -141,7 +141,7 @@ path_discovery (vector pathvec, struct config * conf, int flag)
        const char *devpath;
        int num_paths = 0, total_paths = 0;
 
-       udev_iter = udev_enumerate_new(conf->udev);
+       udev_iter = udev_enumerate_new(udev);
        if (!udev_iter)
                return -ENOMEM;
 
@@ -154,7 +154,7 @@ path_discovery (vector pathvec, struct config * conf, int flag)
                const char *devtype;
                devpath = udev_list_entry_get_name(entry);
                condlog(4, "Discover device %s", devpath);
-               udevice = udev_device_new_from_syspath(conf->udev, devpath);
+               udevice = udev_device_new_from_syspath(udev, devpath);
                if (!udevice) {
                        condlog(4, "%s: no udev information", devpath);
                        continue;
@@ -323,7 +323,7 @@ sysfs_get_tgt_nodename (struct path *pp, char * node)
        value = udev_device_get_sysname(tgtdev);
        if (sscanf(value, "rport-%d:%d-%d",
                   &host, &channel, &tgtid) == 3) {
-               tgtdev = udev_device_new_from_subsystem_sysname(conf->udev,
+               tgtdev = udev_device_new_from_subsystem_sysname(udev,
                                "fc_remote_ports", value);
                if (tgtdev) {
                        condlog(3, "SCSI target %d:%d:%d -> "
@@ -356,7 +356,7 @@ sysfs_get_tgt_nodename (struct path *pp, char * node)
                tgtid = -1;
        }
        if (parent && tgtname) {
-               tgtdev = udev_device_new_from_subsystem_sysname(conf->udev,
+               tgtdev = udev_device_new_from_subsystem_sysname(udev,
                                "iscsi_session", tgtname);
                if (tgtdev) {
                        const char *value;
@@ -430,7 +430,7 @@ int sysfs_get_host_pci_name(struct path *pp, char *pci_name)
                return 1;
 
        sprintf(host_name, "host%d", pp->sg_id.host_no);
-       hostdev = udev_device_new_from_subsystem_sysname(conf->udev,
+       hostdev = udev_device_new_from_subsystem_sysname(udev,
                        "scsi_host", host_name);
        if (!hostdev)
                return 1;
@@ -466,7 +466,7 @@ int sysfs_get_iscsi_ip_address(struct path *pp, char *ip_address)
        const char *value;
 
        sprintf(host_name, "host%d", pp->sg_id.host_no);
-       hostdev = udev_device_new_from_subsystem_sysname(conf->udev,
+       hostdev = udev_device_new_from_subsystem_sysname(udev,
                        "iscsi_host", host_name);
        if (hostdev) {
                value = udev_device_get_sysattr_value(hostdev,
@@ -492,7 +492,7 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp)
 
        sprintf(rport_id, "rport-%d:%d-%d",
                pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.transport_id);
-       rport_dev = udev_device_new_from_subsystem_sysname(conf->udev,
+       rport_dev = udev_device_new_from_subsystem_sysname(udev,
                                "fc_remote_ports", rport_id);
        if (!rport_dev) {
                condlog(1, "%s: No fc_remote_port device for '%s'", pp->dev,
@@ -596,7 +596,7 @@ sysfs_set_session_tmo(struct multipath *mpp, struct path *pp)
        char value[11];
 
        sprintf(session_id, "session%d", pp->sg_id.transport_id);
-       session_dev = udev_device_new_from_subsystem_sysname(conf->udev,
+       session_dev = udev_device_new_from_subsystem_sysname(udev,
                                "iscsi_session", session_id);
        if (!session_dev) {
                condlog(1, "%s: No iscsi session for '%s'", pp->dev,
@@ -638,7 +638,7 @@ sysfs_set_nexus_loss_tmo(struct multipath *mpp, struct path *pp)
 
        sprintf(end_dev_id, "end_device-%d:%d",
                pp->sg_id.host_no, pp->sg_id.transport_id);
-       sas_dev = udev_device_new_from_subsystem_sysname(conf->udev,
+       sas_dev = udev_device_new_from_subsystem_sysname(udev,
                                "sas_end_device", end_dev_id);
        if (!sas_dev) {
                condlog(1, "%s: No SAS end device for '%s'", pp->dev,
index e3c14b6..03c7859 100644 (file)
@@ -530,7 +530,7 @@ snprint_host_attr (char * buff, size_t len, struct path * pp, char *attr)
        if (pp->sg_id.proto_id != SCSI_PROTOCOL_FCP)
                return snprintf(buff, len, "[undef]");
        sprintf(host_id, "host%d", pp->sg_id.host_no);
-       host_dev = udev_device_new_from_subsystem_sysname(conf->udev, "fc_host",
+       host_dev = udev_device_new_from_subsystem_sysname(udev, "fc_host",
                                                          host_id);
        if (!host_dev) {
                condlog(1, "%s: No fc_host device for '%s'", pp->dev, host_id);
@@ -570,7 +570,7 @@ snprint_tgt_wwpn (char * buff, size_t len, struct path * pp)
                return snprintf(buff, len, "[undef]");
        sprintf(rport_id, "rport-%d:%d-%d",
                pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.transport_id);
-       rport_dev = udev_device_new_from_subsystem_sysname(conf->udev,
+       rport_dev = udev_device_new_from_subsystem_sysname(udev,
                                "fc_remote_ports", rport_id);
        if (!rport_dev) {
                condlog(1, "%s: No fc_remote_port device for '%s'", pp->dev,
index 2825c8e..df6a7ca 100644 (file)
@@ -60,6 +60,7 @@
 #include <mpath_cmd.h>
 
 int logsink;
+struct udev *udev;
 
 static int
 filter_pathvec (vector pathvec, char * refwwid)
@@ -474,7 +475,6 @@ get_dev_type(char *dev) {
 int
 main (int argc, char *argv[])
 {
-       struct udev *udev;
        int arg;
        extern char *optarg;
        extern int optind;
@@ -485,7 +485,7 @@ main (int argc, char *argv[])
 
        udev = udev_new();
        logsink = 0;
-       if (load_config(DEFAULT_CONFIGFILE, udev))
+       if (load_config(DEFAULT_CONFIGFILE))
                exit(1);
        while ((arg = getopt(argc, argv, ":adchl::FfM:v:p:b:BritquwW")) != EOF ) {
                switch(arg) {
index 05dcb41..c8c712a 100644 (file)
@@ -637,7 +637,7 @@ cli_add_path (void * v, char ** reply, int * len, void * data)
        } else {
                struct udev_device *udevice;
 
-               udevice = udev_device_new_from_subsystem_sysname(conf->udev,
+               udevice = udev_device_new_from_subsystem_sysname(udev,
                                                                 "block",
                                                                 param);
                r = store_pathinfo(vecs->pathvec, conf->hwtable,
index 6230798..9a44390 100644 (file)
@@ -1877,7 +1877,7 @@ reconfigure (struct vectors * vecs)
        /* Re-read any timezone changes */
        tzset();
 
-       if (!load_config(DEFAULT_CONFIGFILE, udev)) {
+       if (!load_config(DEFAULT_CONFIGFILE)) {
                dm_drv_version(conf->version, TGT_MPATH);
                conf->verbosity = old->verbosity;
                conf->bindings_read_only = old->bindings_read_only;
@@ -2081,8 +2081,6 @@ child (void * param)
        mlockall(MCL_CURRENT | MCL_FUTURE);
        signal_init();
 
-       udev = udev_new();
-
        setup_thread_attr(&misc_attr, 64 * 1024, 1);
        setup_thread_attr(&uevent_attr, DEFAULT_UEVENT_STACKSIZE * 1024, 1);
        setup_thread_attr(&waiter_attr, 32 * 1024, 1);
@@ -2105,7 +2103,7 @@ child (void * param)
        condlog(2, "--------start up--------");
        condlog(2, "read " DEFAULT_CONFIGFILE);
 
-       if (load_config(DEFAULT_CONFIGFILE, udev))
+       if (load_config(DEFAULT_CONFIGFILE))
                goto failed;
 
        uxsock_timeout = conf->uxsock_timeout;
@@ -2384,6 +2382,8 @@ main (int argc, char *argv[])
        if (!conf)
                exit(1);
 
+       udev = udev_new();
+
        while ((arg = getopt(argc, argv, ":dsv:k::Bn")) != EOF ) {
        switch(arg) {
                case 'd':
@@ -2403,7 +2403,7 @@ main (int argc, char *argv[])
                        logsink = -1;
                        break;
                case 'k':
-                       if (load_config(DEFAULT_CONFIGFILE, udev_new()))
+                       if (load_config(DEFAULT_CONFIGFILE))
                                exit(1);
                        uxclnt(optarg, uxsock_timeout + 100);
                        exit(0);
@@ -2424,7 +2424,7 @@ main (int argc, char *argv[])
                char * s = cmd;
                char * c = s;
 
-               if (load_config(DEFAULT_CONFIGFILE, udev_new()))
+               if (load_config(DEFAULT_CONFIGFILE))
                        exit(1);
                memset(cmd, 0x0, CMDSIZE);
                while (optind < argc) {