Skip to contentSkip to conversation

Move to libudev

PATCH New Hannes Reinecke 1 participant 13 messages Apr 19, 2012 Device mapper

lore
Share & tools
lore
#0 lore raw

cover Move to libudev

This patchset moves the entire sysfs handling in multipath-tools over to libudev. The hand-crafted sysfs access is removed, as is all the directory traversal through sysfs.

In doing so I've removed the former 'getuid' callout and replaced it by referencing an udev attribute 'uid_attribute'. Per default this is being set to 'ID_SERIAL', as this is an attribute which is being generated by udev for each device.
And handily has the same format as the output of getuid.

Hannes Reinecke (12):
Use devpath as argument for sysfs functions
multipathd: remove references to sysfs_device
multipathd: use struct path as argument for event processing Add global udev reference pointer to config
Use udev enumeration during discovery
use struct udev_device during discovery
Remove stale variable in sysfs_attr_get_value
Use struct udev_device instead of sysdev
discovery: Fixup cciss discovery
Use udev attribute instead of getuid_callout()
Use udev devices during discovery
Remove all references to hand-craftes sysfs code

 libmpathpersist/mpath_persist.c |    5 -
 libmultipath/config.c           |   28 +-
 libmultipath/config.h           |   10 +-
 libmultipath/defaults.h         |    2 +-
 libmultipath/dict.c             |   55 +---
 libmultipath/discovery.c        |  677 +++++++++++++++++----------------------
 libmultipath/discovery.h        |    8 +-
 libmultipath/hwtable.c          |  102 ++-----
 libmultipath/propsel.c          |   24 +-
 libmultipath/structs.c          |    6 +
 libmultipath/structs.h          |   10 +-
 libmultipath/structs_vec.c      |   13 +-
 libmultipath/sysfs.c            |  384 +++--------------------
 libmultipath/sysfs.h            |   22 +--
 libmultipath/uevent.c           |   16 +-
 libmultipath/uevent.h           |    1 +
 libmultipath/util.c             |   16 +-
 libmultipath/util.h             |    3 +-
 multipath/main.c                |    5 -
 multipath/multipath.conf.5      |   20 +-
 multipathd/Makefile             |    2 +-
 multipathd/cli_handlers.c       |   48 +++-
 multipathd/main.c               |  133 +++-----
 multipathd/main.h               |    4 +-
 24 files changed, 550 insertions(+), 1044 deletions(-)
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH 1/12 Use devpath as argument for sysfs functions

Whenever we pass in a sysfs structure to functions we're only ever interested in the devpath. So we can as well pass in the device path directly, without reference to the sysfs structure.

---
 libmultipath/discovery.c   |   67 +++++++++++++++++++++++---------------------
 libmultipath/discovery.h   |    4 +-
 libmultipath/propsel.c     |    2 +-
 libmultipath/structs_vec.c |    2 +-
 libmultipath/sysfs.h       |    2 +-
 libmultipath/util.c        |    6 ++--
 libmultipath/util.h        |    2 +-
 multipathd/cli_handlers.c  |    2 +-
 8 files changed, 45 insertions(+), 42 deletions(-)
libmultipath/discovery.c +35 -32
index 1b67e76..426c511 100644
@@ -128,19 +128,19 @@ path_discovery (vector pathvec, struct config * conf, int flag)
 
 #define declare_sysfs_get_str(fname) \
 extern int \
-sysfs_get_##fname (struct sysfs_device * dev, char * buff, size_t len) \
+sysfs_get_##fname (const char  * devpath, char * buff, size_t len) \
 {								       \
 	int size;						       \
 								       \
-	size = sysfs_attr_get_value(dev->devpath, #fname, buff, len);	\
+	size = sysfs_attr_get_value(devpath, #fname, buff, len);	\
 	if (!size) {							\
 		condlog(3, "%s: attribute %s not found in sysfs",	\
-			dev->kernel, #fname);				\
+			devpath, #fname);				\
 		return 1;						\
 	}								\
 	if (size == len) {						\
 		condlog(3, "%s: overflow in attribute %s",		\
-			dev->kernel, #fname);				\
+			devpath, #fname);				\
 		return 2;						\
 	}								\
 	strchop(buff);							\
@@ -156,19 +156,22 @@ declare_sysfs_get_str(state);
 declare_sysfs_get_str(dev);
 
 int
-sysfs_get_timeout(struct sysfs_device *dev, unsigned int *timeout)
+sysfs_get_timeout(const char *devpath, unsigned int *timeout)
 {
 	char attr_path[SYSFS_PATH_SIZE], attr[NAME_SIZE];
 	size_t len;
 	int r;
 	unsigned int t;
 
-	if (safe_sprintf(attr_path, "%s/device", dev->devpath))
+	if (!devpath)
+		return 1;
+
+	if (safe_sprintf(attr_path, "%s/device", devpath))
 		return 1;
 
 	len = sysfs_attr_get_value(attr_path, "timeout", attr, NAME_SIZE);
 	if (!len) {
-		condlog(3, "%s: No timeout value in sysfs", dev->devpath);
+		condlog(3, "%s: No timeout value in sysfs", devpath);
 		return 1;
 	}
 
@@ -176,7 +179,7 @@ sysfs_get_timeout(struct sysfs_device *dev, unsigned int *timeout)
 
 	if (r != 1) {
 		condlog(3, "%s: Cannot parse timeout attribute '%s'",
-			dev->devpath, attr);
+			devpath, attr);
 		return 1;
 	}
 
@@ -186,15 +189,15 @@ sysfs_get_timeout(struct sysfs_device *dev, unsigned int *timeout)
 }
 
 int
-sysfs_get_size (struct sysfs_device * dev, unsigned long long * size)
+sysfs_get_size (const char * devpath, unsigned long long * size)
 {
 	char attr[NAME_SIZE];
 	size_t len;
 	int r;
 
-	len = sysfs_attr_get_value(dev->devpath, "size", attr, NAME_SIZE);
+	len = sysfs_attr_get_value(devpath, "size", attr, NAME_SIZE);
 	if (!len) {
-		condlog(3, "%s: No size attribute in sysfs", dev->devpath);
+		condlog(3, "%s: No size attribute in sysfs", devpath);
 		return 1;
 	}
 
@@ -202,7 +205,7 @@ sysfs_get_size (struct sysfs_device * dev, unsigned long long * size)
 
 	if (r != 1) {
 		condlog(3, "%s: Cannot parse size attribute '%s'",
-			dev->devpath, attr);
+			devpath, attr);
 		return 1;
 	}
 
@@ -210,7 +213,7 @@ sysfs_get_size (struct sysfs_device * dev, unsigned long long * size)
 }
 
 int
-sysfs_get_tgt_nodename (struct sysfs_device * dev, char * node,
+sysfs_get_tgt_nodename (const char * devpath, char * node,
 		       unsigned int host, unsigned int channel,
 		       unsigned int target)
 {
@@ -229,8 +232,8 @@ sysfs_get_tgt_nodename (struct sysfs_device * dev, char * node,
 	if (len)
 		return 0;
 
-	if (sscanf(dev->devpath, "/devices/platform/host%u/session%u/",
-	           &checkhost, &session) != 2)
+	if (sscanf(devpath, "/devices/platform/host%u/session%u/",
+		   &checkhost, &session) != 2)
 		return 1;
 	if (checkhost != host)
 		return 1;
@@ -544,7 +547,7 @@ get_geometry(struct path *pp)
 }
 
 static int
-scsi_sysfs_pathinfo (struct path * pp, struct sysfs_device * parent)
+scsi_sysfs_pathinfo (struct path * pp, const char * parent)
 {
 	char attr_path[FILE_NAME_SIZE];
 
@@ -571,7 +574,7 @@ scsi_sysfs_pathinfo (struct path * pp, struct sysfs_device * parent)
 	/*
 	 * host / bus / target / lun
 	 */
-	basenamecpy(parent->devpath, attr_path, FILE_NAME_SIZE);
+	basenamecpy(parent, attr_path, FILE_NAME_SIZE);
 
 	sscanf(attr_path, "%i:%i:%i:%i",
 			&pp->sg_id.host_no,
@@ -600,7 +603,7 @@ scsi_sysfs_pathinfo (struct path * pp, struct sysfs_device * parent)
 }
 
 static int
-ccw_sysfs_pathinfo (struct path * pp, struct sysfs_device * parent)
+ccw_sysfs_pathinfo (struct path * pp, const char * parent)
 {
 	char attr_path[FILE_NAME_SIZE];
 	char attr_buff[FILE_NAME_SIZE];
@@ -630,7 +633,7 @@ ccw_sysfs_pathinfo (struct path * pp, struct sysfs_device * parent)
 	/*
 	 * host / bus / target / lun
 	 */
-	basenamecpy(parent->devpath, attr_path, FILE_NAME_SIZE);
+	basenamecpy(parent, attr_path, FILE_NAME_SIZE);
 	pp->sg_id.lun = 0;
 	sscanf(attr_path, "%i.%i.%x",
 			&pp->sg_id.host_no,
@@ -647,14 +650,14 @@ ccw_sysfs_pathinfo (struct path * pp, struct sysfs_device * parent)
 }
 
 static int
-cciss_sysfs_pathinfo (struct path * pp, struct sysfs_device * dev)
+cciss_sysfs_pathinfo (struct path * pp, const char * devpath)
 {
 	char attr_path[FILE_NAME_SIZE];
 
 	/*
 	 * host / bus / target / lun
 	 */
-	basenamecpy(dev->devpath, attr_path, FILE_NAME_SIZE);
+	basenamecpy(devpath, attr_path, FILE_NAME_SIZE);
 	pp->sg_id.lun = 0;
 	pp->sg_id.channel = 0;
 	sscanf(attr_path, "cciss!c%id%i",
@@ -670,12 +673,12 @@ cciss_sysfs_pathinfo (struct path * pp, struct sysfs_device * dev)
 }
 
 static int
-common_sysfs_pathinfo (struct path * pp, struct sysfs_device *dev)
+common_sysfs_pathinfo (struct path * pp, const char * devpath)
 {
 	size_t len;
 
-	len = sysfs_attr_get_value(dev->devpath, "dev",
-				    pp->dev_t, BLK_DEV_SIZE);
+	len = sysfs_attr_get_value(devpath, "dev",
+				   pp->dev_t, BLK_DEV_SIZE);
 	if (!len) {
 		condlog(3, "%s: no 'dev' attribute in sysfs", pp->dev);
 		return 1;
@@ -683,7 +686,7 @@ common_sysfs_pathinfo (struct path * pp, struct sysfs_device *dev)
 
 	condlog(3, "%s: dev_t = %s", pp->dev, pp->dev_t);
 
-	if (sysfs_get_size(dev, &pp->size))
+	if (sysfs_get_size(devpath, &pp->size))
 		return 1;
 
 	condlog(3, "%s: size = %llu", pp->dev, pp->size);
@@ -729,7 +732,7 @@ path_offline (struct path * pp)
 		return PATH_WILD;
 	}
 
-	if (sysfs_get_state(parent, buff, SCSI_STATE_SIZE))
+	if (sysfs_get_state(parent->devpath, buff, SCSI_STATE_SIZE))
 		return PATH_WILD;
 
 	condlog(3, "%s: path state = %s", pp->dev, buff);
@@ -758,7 +761,7 @@ sysfs_pathinfo(struct path * pp)
 		return 1;
 	}
 
-	if (common_sysfs_pathinfo(pp, pp->sysdev))
+	if (common_sysfs_pathinfo(pp, pp->sysdev->devpath))
 		return 1;
 
 	parent = sysfs_device_get_parent(pp->sysdev);
@@ -782,13 +785,13 @@ sysfs_pathinfo(struct path * pp)
 	if (pp->bus == SYSFS_BUS_UNDEF)
 		return 0;
 	else if (pp->bus == SYSFS_BUS_SCSI) {
-		if (scsi_sysfs_pathinfo(pp, parent))
+		if (scsi_sysfs_pathinfo(pp, parent->devpath))
 			return 1;
 	} else if (pp->bus == SYSFS_BUS_CCW) {
-		if (ccw_sysfs_pathinfo(pp, parent))
+		if (ccw_sysfs_pathinfo(pp, parent->devpath))
 			return 1;
 	} else if (pp->bus == SYSFS_BUS_CCISS) {
-		if (cciss_sysfs_pathinfo(pp, pp->sysdev))
+		if (cciss_sysfs_pathinfo(pp, pp->sysdev->devpath))
 			return 1;
 	}
 	return 0;
@@ -859,8 +862,8 @@ get_state (struct path * pp, int daemon)
 	checker_clear_message(c);
 	if (daemon)
 		checker_set_async(c);
-	if (!conf->checker_timeout)
-		sysfs_get_timeout(pp->sysdev, &(c->timeout));
+	if (!conf->checker_timeout && pp->sysdev)
+		sysfs_get_timeout(pp->sysdev->devpath, &(c->timeout));
 	state = checker_check(c);
 	condlog(3, "%s: state = %s", pp->dev, checker_state_name(state));
 	if (state == PATH_DOWN && strlen(checker_message(c)))
libmultipath/discovery.h +2 -2
index 0ba33d8..1b4d437 100644
@@ -24,7 +24,7 @@
 #define SCSI_COMMAND_TERMINATED 0x22
 #define SG_ERR_DRIVER_SENSE     0x08
 
-int sysfs_get_dev (struct sysfs_device * dev, char * buff, size_t len);
+int sysfs_get_dev (const char * dev, char * buff, size_t len);
 int path_discovery (vector pathvec, struct config * conf, int flag);
 
 int do_tur (char *);
@@ -34,7 +34,7 @@ int pathinfo (struct path *, vector hwtable, int mask);
 struct path * store_pathinfo (vector pathvec, vector hwtable,
 			      char * devname, int flag);
 int sysfs_set_scsi_tmo (struct multipath *mpp);
-int sysfs_get_timeout(struct sysfs_device *dev, unsigned int *timeout);
+int sysfs_get_timeout(const char * devpath, unsigned int *timeout);
 
 /*
  * discovery bitmask
libmultipath/propsel.c +1 -1
index 10aec29..50b0e8a 100644
@@ -335,7 +335,7 @@ out:
 		condlog(3, "%s: checker timeout = %u ms (config file default)",
 				pp->dev, c->timeout);
 	}
-	else if (sysfs_get_timeout(pp->sysdev, &c->timeout) == 0)
+	else if (pp->sysdev && sysfs_get_timeout(pp->sysdev->devpath, &c->timeout) == 0)
 		condlog(3, "%s: checker timeout = %u ms (sysfs setting)",
 				pp->dev, c->timeout);
 	else {
libmultipath/structs_vec.c +1 -1
index f4bae10..bbbe888 100644
@@ -445,7 +445,7 @@ verify_paths(struct multipath * mpp, struct vectors * vecs, vector rpvec)
 		/*
 		 * see if path is in sysfs
 		 */
-		if (!pp->sysdev || sysfs_get_dev(pp->sysdev,
+		if (!pp->sysdev || sysfs_get_dev(pp->sysdev->devpath,
 						 pp->dev_t, BLK_DEV_SIZE)) {
 			if (pp->state != PATH_DOWN) {
 				condlog(1, "%s: removing valid path %s in state %d",
libmultipath/sysfs.h +1 -1
index a84857d..22a4c5b 100644
@@ -23,6 +23,6 @@ size_t sysfs_attr_get_value(const char *devpath, const char *attr_name,
 ssize_t sysfs_attr_set_value(const char *devpath, const char *attr_name,
 			     const char *value, int value_len);
 int sysfs_resolve_link(char *path, size_t size);
-int sysfs_get_size (struct sysfs_device * dev, unsigned long long * size);
+int sysfs_get_size(const char * devpath, unsigned long long * size);
 int sysfs_check_holders(char * check_devt, char * new_devt);
 #endif
libmultipath/util.c +3 -3
index 62b1aa1..f6ee09c 100644
@@ -20,7 +20,7 @@ strchop(char *str)
 }
 
 int
-basenamecpy (char * str1, char * str2, int str2len)
+basenamecpy (const char * str1, char * str2, int str2len)
 {
 	char *p;
 
@@ -33,7 +33,7 @@ basenamecpy (char * str1, char * str2, int str2len)
 	if (!str2)
 		return 0;
 
-	p = str1 + (strlen(str1) - 1);
+	p = (char *)str1 + (strlen(str1) - 1);
 
 	while (*--p != '/' && p != str1)
 		continue;
@@ -231,6 +231,6 @@ skip_proc:
 		condlog(0, "sysfs entry %s is not a directory\n", block_path);
 		return 1;
 	}
-	basenamecpy(block_path, devname, devname_len);
+	basenamecpy((const char *)block_path, devname, devname_len);
 	return 0;
 }
libmultipath/util.h +1 -1
index 72de319..cb4ce1b 100644
@@ -2,7 +2,7 @@
 #define _UTIL_H
 
 void strchop(char *);
-int basenamecpy (char * src, char * dst, int);
+int basenamecpy (const char * src, char * dst, int);
 int filepresent (char * run);
 int get_word (char * sentence, char ** word);
 size_t strlcpy(char *dst, const char *src, size_t size);
multipathd/cli_handlers.c +1 -1
index 9e0e2ee..4c4295d 100644
@@ -571,7 +571,7 @@ cli_resize(void *v, char **reply, int *len, void *data)
 
 	pgp = VECTOR_SLOT(mpp->pg, 0);
 	pp = VECTOR_SLOT(pgp->paths, 0);
-	if (sysfs_get_size(pp->sysdev, &size)) {
+	if (!pp->sysdev || sysfs_get_size(pp->sysdev->devpath, &size)) {
 		condlog(0, "%s: couldn't get size for sysfs. cannot resize",
 			mapname);
 		return 1;
Signature · 1 line
1.7.3.4
#2 lore raw

PATCH 2/12 multipathd: remove references to sysfs_device

In reply to Hannes Reinecke

When processing events we don't need to take a reference to the sysfs_device; it will be done later on during pathinfo.

---
 multipathd/main.c |   30 ++----------------------------
 1 files changed, 2 insertions(+), 28 deletions(-)
multipathd/main.c +2 -28
index 9cf0a80..0667a2b 100644
@@ -372,14 +372,7 @@ ev_remove_map (char * devname, char * alias, int minor, struct vectors * vecs)
 static int
 uev_add_path (struct uevent *uev, struct vectors * vecs)
 {
-	struct sysfs_device * dev;
-
-	dev = sysfs_device_get(uev->devpath);
-	if (!dev) {
-		condlog(2, "%s: not found in sysfs", uev->devpath);
-		return 1;
-	}
-	condlog(2, "%s: add path (uevent)", dev->kernel);
+	condlog(2, "%s: add path (uevent)", uev->kernel);
 	return (ev_add_path(dev->kernel, vecs) != 1)? 0 : 1;
 }
 
@@ -556,21 +549,10 @@ fail:
 static int
 uev_remove_path (struct uevent *uev, struct vectors * vecs)
 {
-	struct sysfs_device * dev;
 	int retval;
 
-	dev = sysfs_device_get(uev->devpath);
-	if (!dev) {
-		condlog(2, "%s: not found in sysfs", uev->devpath);
-		return 1;
-	}
 	condlog(2, "%s: remove path (uevent)", uev->kernel);
-	retval = ev_remove_path(uev->kernel, vecs);
-
-	if (!retval)
-		sysfs_device_put(dev);
-
-	return retval;
+	return ev_remove_path(uev->kernel, vecs);
 }
 
 int
@@ -679,14 +661,8 @@ fail:
 static int
 uev_update_path (struct uevent *uev, struct vectors * vecs)
 {
-	struct sysfs_device * dev;
 	int retval, ro;
 
-	dev = sysfs_device_get(uev->devpath);
-	if (!dev) {
-		condlog(2, "%s: not found in sysfs", uev->devpath);
-		return 1;
-	}
 	ro = uevent_get_disk_ro(uev);
 
 	if (ro >= 0) {
@@ -708,8 +684,6 @@ uev_update_path (struct uevent *uev, struct vectors * vecs)
 
 	}
 
-	sysfs_device_put(dev);
-
 	return retval;
 }
 
Signature · 1 line
1.7.3.4
#3 lore raw

PATCH 3/12 multipathd: use struct path as argument for event processing

In reply to Hannes Reinecke

ev_add/remove_path should be using struct path as the argument, this makes transitioning to use libudev easier.

---
 libmultipath/discovery.h  |    2 +
 multipathd/cli_handlers.c |   39 ++++++++++++++---
 multipathd/main.c         |  100 ++++++++++++++++++++++-----------------------
 multipathd/main.h         |    4 +-
 4 files changed, 85 insertions(+), 60 deletions(-)
libmultipath/discovery.h +2 -0
index 1b4d437..c071026 100644
@@ -24,6 +24,8 @@
 #define SCSI_COMMAND_TERMINATED 0x22
 #define SG_ERR_DRIVER_SENSE     0x08
 
+struct config;
+
 int sysfs_get_dev (const char * dev, char * buff, size_t len);
 int path_discovery (vector pathvec, struct config * conf, int flag);
 
multipathd/cli_handlers.c +32 -7
index 4c4295d..5cf5f4b 100644
@@ -8,6 +8,7 @@
 #include <structs_vec.h>
 #include <libdevmapper.h>
 #include <devmapper.h>
+#include <discovery.h>
 #include <config.h>
 #include <configure.h>
 #include <blacklist.h>
@@ -410,18 +411,37 @@ cli_add_path (void * v, char ** reply, int * len, void * data)
 {
 	struct vectors * vecs = (struct vectors *)data;
 	char * param = get_keyparam(v, PATH);
+	struct path *pp;
 	int r;
 
 	condlog(2, "%s: add path (operator)", param);
 
 	if (filter_devnode(conf->blist_devnode, conf->elist_devnode,
-	    param) > 0 || (r = ev_add_path(param, vecs)) == 2) {
-		*reply = strdup("blacklisted\n");
-		*len = strlen(*reply) + 1;
-		condlog(2, "%s: path blacklisted", param);
-		return 0;
+			   param) > 0)
+		goto blacklisted;
+
+	pp = find_path_by_dev(vecs->pathvec, param);
+	if (pp) {
+		condlog(2, "%s: path already in pathvec", param);
+		if (pp->mpp)
+			return 0;
+	} else {
+		pp = store_pathinfo(vecs->pathvec, conf->hwtable,
+				    param, DI_ALL);
+		if (!pp) {
+			condlog(0, "%s: failed to store path info", param);
+			return 1;
+		}
 	}
+	r = ev_add_path(pp, vecs);
+	if (r == 2)
+		goto blacklisted;
 	return r;
+blacklisted:
+	*reply = strdup("blacklisted\n");
+	*len = strlen(*reply) + 1;
+	condlog(2, "%s: path blacklisted", param);
+	return 0;
 }
 
 int
@@ -429,10 +449,15 @@ cli_del_path (void * v, char ** reply, int * len, void * data)
 {
 	struct vectors * vecs = (struct vectors *)data;
 	char * param = get_keyparam(v, PATH);
+	struct path *pp;
 
 	condlog(2, "%s: remove path (operator)", param);
-
-	return ev_remove_path(param, vecs);
+	pp = find_path_by_dev(vecs->pathvec, param);
+	if (!pp) {
+		condlog(0, "%s: path already removed", param);
+		return 0;
+	}
+	return ev_remove_path(pp, vecs);
 }
 
 int
multipathd/main.c +49 -51

197 lines not on this page · raw message

multipathd/main.h +2 -2
index 0733299..242f5e1 100644
@@ -19,8 +19,8 @@ extern pid_t daemon_pid;
 int exit_daemon(int);
 const char * daemon_status(void);
 int reconfigure (struct vectors *);
-int ev_add_path (char *, struct vectors *);
-int ev_remove_path (char *, struct vectors *);
+int ev_add_path (struct path *, struct vectors *);
+int ev_remove_path (struct path *, struct vectors *);
 int ev_add_map (char *, char *, struct vectors *);
 int ev_remove_map (char *, char *, int, struct vectors *);
 void sync_map_state (struct multipath *);
Signature · 1 line
1.7.3.4
#4 lore raw

PATCH 4/12 Add global udev reference pointer to config

In reply to Hannes Reinecke

Instead of using a local reference to udev we should be moving it to the global config structure.

---
 libmultipath/config.c |    5 +++++
 libmultipath/config.h |    1 +
 libmultipath/uevent.c |   12 +++---------
 3 files changed, 9 insertions(+), 9 deletions(-)
libmultipath/config.c +5 -0
index f99465a..75eab38 100644
@@ -5,6 +5,7 @@
  */
 #include <stdio.h>
 #include <string.h>
+#include <libudev.h>
 
 #include "checkers.h"
 #include "memory.h"
@@ -427,6 +428,9 @@ free_config (struct config * conf)
 	if (conf->dev)
 		FREE(conf->dev);
 
+	if (conf->udev)
+		udev_unref(conf->udev);
+
 	if (conf->udev_dir)
 		FREE(conf->udev_dir);
 
@@ -491,6 +495,7 @@ load_config (char * file)
 	if (!conf->verbosity)
 		conf->verbosity = DEFAULT_VERBOSITY;
 
+	conf->udev = udev_new();
 	conf->dmrq = dm_drv_get_rq();
 	conf->dev_type = DEV_NONE;
 	conf->minio = DEFAULT_MINIO;
libmultipath/config.h +1 -0
index 6fcd45e..147eedf 100644
@@ -109,6 +109,7 @@ struct config {
 	int reassign_maps;
 
 	char * dev;
+	struct udev * udev;
 	char * sysfs_dir;
 	char * udev_dir;
 	char * multipath_dir;
libmultipath/uevent.c +3 -9
index 3e4c4ec..4e31d4f 100644
@@ -46,6 +46,8 @@
 #include "debug.h"
 #include "list.h"
 #include "uevent.h"
+#include "vector.h"
+#include "config.h"
 
 typedef int (uev_trigger)(struct uevent *, void * trigger_data);
 
@@ -375,7 +377,6 @@ exit:
 int uevent_listen(void)
 {
 	int err;
-	struct udev *udev = NULL;
 	struct udev_monitor *monitor = NULL;
 	int fd, socket_flags;
 	int need_failback = 1;
@@ -391,12 +392,7 @@ int uevent_listen(void)
 	pthread_cond_init(uev_condp, NULL);
 	pthread_cleanup_push(uevq_stop, NULL);
 
-	udev = udev_new();
-	if (!udev) {
-		condlog(2, "failed to create udev context");
-		goto out;
-	}
-	monitor = udev_monitor_new_from_netlink(udev, "udev");
+	monitor = udev_monitor_new_from_netlink(conf->udev, "udev");
 	if (!monitor) {
 		condlog(2, "failed to create udev monitor");
 		goto out;
@@ -500,8 +496,6 @@ int uevent_listen(void)
 out:
 	if (monitor)
 		udev_monitor_unref(monitor);
-	if (udev)
-		udev_unref(udev);
 	if (need_failback)
 		err = failback_listen();
 	pthread_cleanup_pop(1);
Signature · 1 line
1.7.3.4
#5 lore raw

PATCH 5/12 Use udev enumeration during discovery

In reply to Hannes Reinecke

Instead of scanning /sys/block by hand we should be using enumeration provided by udev.

---
 libmultipath/discovery.c |   40 ++++++++++++++++++----------------------
 1 files changed, 18 insertions(+), 22 deletions(-)
libmultipath/discovery.c +18 -22
index 426c511..d68324b 100644
@@ -11,6 +11,7 @@
 #include <dirent.h>
 #include <errno.h>
 #include <libgen.h>
+#include <libudev.h>
 
 #include "checkers.h"
 #include "vector.h"
@@ -91,37 +92,32 @@ path_discover (vector pathvec, struct config * conf, char * devname, int flag)
 int
 path_discovery (vector pathvec, struct config * conf, int flag)
 {
-	DIR *blkdir;
-	struct dirent *blkdev;
-	struct stat statbuf;
-	char devpath[PATH_MAX];
+	struct udev_enumerate *udev_iter;
+	struct udev_list_entry *entry;
+	char *devpath;
 	char *devptr;
 	int r = 0;
 
-	if (!(blkdir = opendir("/sys/block")))
+	udev_iter = udev_enumerate_new(conf->udev);
+	if (!udev_iter)
 		return 1;
 
-	strcpy(devpath,"/sys/block");
-	while ((blkdev = readdir(blkdir)) != NULL) {
-		if ((strcmp(blkdev->d_name,".") == 0) ||
-		    (strcmp(blkdev->d_name,"..") == 0))
-			continue;
-
-		devptr = devpath + 10;
-		*devptr = '\0';
-		strcat(devptr,"/");
-		strcat(devptr,blkdev->d_name);
-		if (stat(devpath, &statbuf) < 0)
-			continue;
-
-		if (S_ISDIR(statbuf.st_mode) == 0)
-			continue;
+	udev_enumerate_add_match_subsystem(udev_iter, "block");
+	udev_enumerate_scan_devices(udev_iter);
 
+	udev_list_entry_foreach(entry,
+				udev_enumerate_get_list_entry(udev_iter)) {
+		devpath = udev_list_entry_get_name(entry);
 		condlog(4, "Discover device %s", devpath);
+		devptr = strrchr(devpath, '/');
+		if (devptr)
+			devptr++;
+		else
+			devptr = devpath;
 
-		r += path_discover(pathvec, conf, blkdev->d_name, flag);
+		r += path_discover(pathvec, conf, devptr, flag);
 	}
-	closedir(blkdir);
+	udev_enumerate_unref(udev_iter);
 	condlog(4, "Discovery status %d", r);
 	return r;
 }
Signature · 1 line
1.7.3.4
#6 lore raw

PATCH 6/12 use struct udev_device during discovery

In reply to Hannes Reinecke

We can save quite some parsing etc. by just using struct udev_device.

---
 libmultipath/discovery.c |   44 ++++++++++++++++++--------------------------
 1 files changed, 18 insertions(+), 26 deletions(-)
libmultipath/discovery.c +18 -26
index d68324b..fd0f827 100644
@@ -56,34 +56,24 @@ out:
 }
 
 static int
-path_discover (vector pathvec, struct config * conf, char * devname, int flag)
+path_discover (vector pathvec, struct config * conf,
+	       struct udev_device *udevice, int flag)
 {
-	char path[FILE_NAME_SIZE];
 	struct path * pp;
+	const char * devname;
 
+	devname = udev_device_get_sysname(udevice);
 	if (!devname)
 		return 0;
 
 	if (filter_devnode(conf->blist_devnode, conf->elist_devnode,
-			   devname) > 0)
+			   (char *)devname) > 0)
 		return 0;
 
-	if(safe_sprintf(path, "%s/block/%s/device", sysfs_path,
-			devname)) {
-		condlog(0, "path too small");
-		return 1;
-	}
-
-	if (strncmp(devname,"cciss",5) && !filepresent(path)) {
-		condlog(4, "path %s not present", path);
-		return 0;
-	}
-
-	pp = find_path_by_dev(pathvec, devname);
-
+	pp = find_path_by_dev(pathvec, (char *)devname);
 	if (!pp) {
 		pp = store_pathinfo(pathvec, conf->hwtable,
-				    devname, flag);
+				    (char *)devname, flag);
 		return (pp ? 0 : 1);
 	}
 	return pathinfo(pp, conf->hwtable, flag);
@@ -94,8 +84,8 @@ path_discovery (vector pathvec, struct config * conf, int flag)
 {
 	struct udev_enumerate *udev_iter;
 	struct udev_list_entry *entry;
-	char *devpath;
-	char *devptr;
+	struct udev_device *udevice;
+	const char *devpath;
 	int r = 0;
 
 	udev_iter = udev_enumerate_new(conf->udev);
@@ -109,13 +99,15 @@ path_discovery (vector pathvec, struct config * conf, int flag)
 				udev_enumerate_get_list_entry(udev_iter)) {
 		devpath = udev_list_entry_get_name(entry);
 		condlog(4, "Discover device %s", devpath);
-		devptr = strrchr(devpath, '/');
-		if (devptr)
-			devptr++;
-		else
-			devptr = devpath;
-
-		r += path_discover(pathvec, conf, devptr, flag);
+		udevice = udev_device_new_from_syspath(conf->udev, devpath);
+		if (!udevice) {
+			condlog(4, "%s: no udev information", devpath);
+			r++;
+			continue;
+		}
+		if(!strncmp(udev_device_get_devtype(udevice), "disk", 4))
+			r += path_discover(pathvec, conf, udevice, flag);
+		udev_device_unref(udevice);
 	}
 	udev_enumerate_unref(udev_iter);
 	condlog(4, "Discovery status %d", r);
Signature · 1 line
1.7.3.4
#7 lore raw

PATCH 7/12 Remove stale variable in sysfs_attr_get_value

In reply to Hannes Reinecke
---
 libmultipath/sysfs.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
libmultipath/sysfs.c +1 -2
index 16dce4a..13af8a1 100644
@@ -287,7 +287,6 @@ size_t sysfs_attr_get_value(const char *devpath, const char *attr_name,
 			    char *attr_value, int attr_len)
 {
 	char path_full[PATH_SIZE];
-	const char *path;
 	struct stat statbuf;
 	int fd;
 	ssize_t size;
@@ -303,7 +302,7 @@ size_t sysfs_attr_get_value(const char *devpath, const char *attr_name,
 	sysfs_len = strlcpy(path_full, sysfs_path, sizeof(path_full));
 	if(sysfs_len >= sizeof(path_full))
 		sysfs_len = sizeof(path_full) - 1;
-	path = &path_full[sysfs_len];
+
 	strlcat(path_full, devpath, sizeof(path_full));
 	strlcat(path_full, "/", sizeof(path_full));
 	strlcat(path_full, attr_name, sizeof(path_full));
Signature · 1 line
1.7.3.4
#8 lore raw

PATCH 8/12 Use struct udev_device instead of sysdev

In reply to Hannes Reinecke

Remove hand-crafted sysdev and use struct udev_device instead.

---
 libmultipath/discovery.c   |  279 +++++++++++++++++++++++--------------------
 libmultipath/discovery.h   |    6 +-
 libmultipath/propsel.c     |    2 +-
 libmultipath/structs.c     |    6 +
 libmultipath/structs.h     |    8 +-
 libmultipath/structs_vec.c |   10 +-
 libmultipath/sysfs.c       |  200 -------------------------------
 libmultipath/sysfs.h       |    3 +-
 libmultipath/uevent.c      |    4 +-
 libmultipath/uevent.h      |    1 +
 libmultipath/util.c        |   10 ++
 libmultipath/util.h        |    1 +
 multipath/main.c           |    1 -
 multipathd/Makefile        |    2 +-
 multipathd/cli_handlers.c  |   11 ++-
 multipathd/main.c          |    9 +-
 16 files changed, 196 insertions(+), 357 deletions(-)
libmultipath/discovery.c +149 -130
index fd0f827..f45602a 100644
@@ -30,9 +30,15 @@
 #include "defaults.h"
 
 struct path *
-store_pathinfo (vector pathvec, vector hwtable, char * devname, int flag)
+store_pathinfo (vector pathvec, vector hwtable, struct udev_device *udevice,
+		int flag)
 {
 	struct path * pp;
+	const char * devname;
+
+	devname = udev_device_get_sysname(udevice);
+	if (!devname)
+		return NULL;
 
 	pp = alloc_path();
 
@@ -43,6 +49,7 @@ store_pathinfo (vector pathvec, vector hwtable, char * devname, int flag)
 		condlog(0, "pp->dev too small");
 		goto out;
 	}
+	pp->udev = udev_device_ref(udevice);
 	if (pathinfo(pp, hwtable, flag))
 		goto out;
 
@@ -73,7 +80,7 @@ path_discover (vector pathvec, struct config * conf,
 	pp = find_path_by_dev(pathvec, (char *)devname);
 	if (!pp) {
 		pp = store_pathinfo(pathvec, conf->hwtable,
-				    (char *)devname, flag);
+				    udevice, flag);
 		return (pp ? 0 : 1);
 	}
 	return pathinfo(pp, conf->hwtable, flag);
@@ -114,24 +121,27 @@ path_discovery (vector pathvec, struct config * conf, int flag)
 	return r;
 }
 
-#define declare_sysfs_get_str(fname) \
-extern int \
-sysfs_get_##fname (const char  * devpath, char * buff, size_t len) \
-{								       \
-	int size;						       \
-								       \
-	size = sysfs_attr_get_value(devpath, #fname, buff, len);	\
-	if (!size) {							\
+#define declare_sysfs_get_str(fname)					\
+extern int								\
+sysfs_get_##fname (struct udev_device * udev, char * buff, size_t len)	\
+{									\
+	const char * attr;						\
+	const char * devname;						\
+									\
+	devname = udev_device_get_sysname(udev);			\
+									\
+	attr = udev_device_get_sysattr_value(udev, #fname);		\
+	if (!attr) {							\
 		condlog(3, "%s: attribute %s not found in sysfs",	\
-			devpath, #fname);				\
+			devname, #fname);				\
 		return 1;						\
 	}								\
-	if (size == len) {						\
+	if (strlen(attr) > len) {					\
 		condlog(3, "%s: overflow in attribute %s",		\
-			devpath, #fname);				\
+			devname, #fname);				\
 		return 2;						\
 	}								\
-	strchop(buff);							\
+	strlcpy(buff, attr, len);					\
 	return 0;							\
 }
 
@@ -144,22 +154,27 @@ declare_sysfs_get_str(state);
 declare_sysfs_get_str(dev);
 
 int
-sysfs_get_timeout(const char *devpath, unsigned int *timeout)
+sysfs_get_timeout(struct path *pp, unsigned int *timeout)
 {
-	char attr_path[SYSFS_PATH_SIZE], attr[NAME_SIZE];
-	size_t len;
+	const char *attr = NULL;
+	const char *subsys;
+	struct udev_device *parent;
 	int r;
 	unsigned int t;
 
-	if (!devpath)
-		return 1;
-
-	if (safe_sprintf(attr_path, "%s/device", devpath))
+	if (!pp->udev)
 		return 1;
 
-	len = sysfs_attr_get_value(attr_path, "timeout", attr, NAME_SIZE);
-	if (!len) {
-		condlog(3, "%s: No timeout value in sysfs", devpath);
+	parent = pp->udev;
+	while (parent) {
+		subsys = udev_device_get_subsystem(parent);
+		attr = udev_device_get_sysattr_value(parent, "timeout");
+		if (subsys && attr)
+			break;
+		parent = udev_device_get_parent(parent);
+	}
+	if (!attr) {
+		condlog(3, "%s: No timeout value in sysfs", pp->dev);
 		return 1;
 	}
 
@@ -167,7 +182,7 @@ sysfs_get_timeout(const char *devpath, unsigned int *timeout)
 
 	if (r != 1) {
 		condlog(3, "%s: Cannot parse timeout attribute '%s'",
-			devpath, attr);
+			pp->dev, attr);
 		return 1;
 	}
 
@@ -177,15 +192,17 @@ sysfs_get_timeout(const char *devpath, unsigned int *timeout)
 }
 
 int
-sysfs_get_size (const char * devpath, unsigned long long * size)
+sysfs_get_size (struct path *pp, unsigned long long * size)
 {
-	char attr[NAME_SIZE];
-	size_t len;
+	const char * attr;
 	int r;
 
-	len = sysfs_attr_get_value(devpath, "size", attr, NAME_SIZE);
-	if (!len) {
-		condlog(3, "%s: No size attribute in sysfs", devpath);
+	if (!pp->udev)
+		return 1;
+
+	attr = udev_device_get_sysattr_value(pp->udev, "size");
+	if (!attr) {
+		condlog(3, "%s: No size attribute in sysfs", pp->dev);
 		return 1;
 	}
 
@@ -193,7 +210,7 @@ sysfs_get_size (const char * devpath, unsigned long long * size)
 
 	if (r != 1) {
 		condlog(3, "%s: Cannot parse size attribute '%s'",
-			devpath, attr);
+			pp->dev, attr);
 		return 1;
 	}
 
@@ -201,41 +218,56 @@ sysfs_get_size (const char * devpath, unsigned long long * size)
 }
 
 int
-sysfs_get_tgt_nodename (const char * devpath, char * node,
-		       unsigned int host, unsigned int channel,
-		       unsigned int target)
+sysfs_get_tgt_nodename (struct path *pp, char * node)
 {
-	unsigned int checkhost, session;
+	const char * targetid;
+	struct udev_device *parent;
 	char attr_path[SYSFS_PATH_SIZE];
 	size_t len;
 
+	parent = pp->udev;
+	while (parent) {
+		targetid = udev_device_get_sysname(parent);
+		if (!strncmp(targetid , "target", 6))
+			break;
+		parent = udev_device_get_parent(parent);
+	}
+	/* 'target' needs to exist */
+	if (!parent || !targetid)
+		return 1;
+	/* Check if it's FibreChannel */
 	if (safe_sprintf(attr_path,
-			 "/class/fc_transport/target%i:%i:%i",
-			 host, channel, target)) {
+			 "/class/fc_transport/%s", targetid)) {
 		condlog(0, "attr_path too small");
 		return 1;
 	}
 
-	len = sysfs_attr_get_value(attr_path, "node_name", node, NODE_NAME_SIZE);
+	len = sysfs_attr_get_value(attr_path, "node_name",
+				   node, NODE_NAME_SIZE);
 	if (len)
 		return 0;
 
-	if (sscanf(devpath, "/devices/platform/host%u/session%u/",
-		   &checkhost, &session) != 2)
-		return 1;
-	if (checkhost != host)
-		return 1;
-	if (safe_sprintf(attr_path, "/devices/platform/host%u/session%u/iscsi_session/session%u", host, session, session)) {
-		condlog(0, "attr_path too small");
-		return 1;
+	/* Check for iSCSI */
+	parent = pp->udev;
+	while (parent) {
+		targetid = udev_device_get_sysname(parent);
+		if (!strncmp(targetid , "session", 6))
+			break;
+		parent = udev_device_get_parent(parent);
+	}
+	if (parent) {
+		if (safe_sprintf(attr_path, "/class/iscsi_session/%s",
+				 targetid)) {
+			condlog(0, "attr_path too small");
+			return 1;
+		}
+		len = sysfs_attr_get_value(attr_path, "targetname", node,
+					   NODE_NAME_SIZE);
+		if (len)
+			return 0;
 	}
 
-	len = sysfs_attr_get_value(attr_path, "targetname", node,
-				   NODE_NAME_SIZE);
-	if (!len)
-		return 1;
-
-	return 0;
+	return 1;
 }
 
 static int
@@ -535,9 +567,28 @@ get_geometry(struct path *pp)
 }
 
 static int
-scsi_sysfs_pathinfo (struct path * pp, const char * parent)
+scsi_sysfs_pathinfo (struct path * pp)
 {
-	char attr_path[FILE_NAME_SIZE];
+	struct udev_device *parent;
+	const char *attr_path = NULL;
+
+	parent = pp->udev;
+	while (parent) {
+		if (!strncmp(udev_device_get_subsystem(parent), "scsi", 4)) {
+			attr_path = udev_device_get_sysname(parent);
+			if (!attr_path)
+				break;
+			if (sscanf(attr_path, "%i:%i:%i:%i",
+				   &pp->sg_id.host_no,
+				   &pp->sg_id.channel,
+				   &pp->sg_id.scsi_id,
+				   &pp->sg_id.lun) == 4)
+				break;
+		}
+		parent = udev_device_get_parent(parent);
+	}
+	if (!attr_path || pp->sg_id.host_no == -1)
+		return 1;
 
 	if (sysfs_get_vendor(parent, pp->vendor_id, SCSI_VENDOR_SIZE))
 		return 1;
@@ -562,13 +613,6 @@ scsi_sysfs_pathinfo (struct path * pp, const char * parent)
 	/*
 	 * host / bus / target / lun
 	 */
-	basenamecpy(parent, attr_path, FILE_NAME_SIZE);
-
-	sscanf(attr_path, "%i:%i:%i:%i",
-			&pp->sg_id.host_no,
-			&pp->sg_id.channel,
-			&pp->sg_id.scsi_id,
-			&pp->sg_id.lun);
 	condlog(3, "%s: h:b:t:l = %i:%i:%i:%i",
 			pp->dev,
 			pp->sg_id.host_no,
@@ -579,10 +623,7 @@ scsi_sysfs_pathinfo (struct path * pp, const char * parent)
 	/*
 	 * target node name
 	 */
-	if(!sysfs_get_tgt_nodename(parent, pp->tgt_node_name,
-				 pp->sg_id.host_no,
-				 pp->sg_id.channel,
-				 pp->sg_id.scsi_id)) {
+	if(!sysfs_get_tgt_nodename(pp, pp->tgt_node_name)) {
 		condlog(3, "%s: tgt_node_name = %s",
 			pp->dev, pp->tgt_node_name);
 	}
@@ -591,10 +632,20 @@ scsi_sysfs_pathinfo (struct path * pp, const char * parent)
 }
 
 static int
-ccw_sysfs_pathinfo (struct path * pp, const char * parent)
+ccw_sysfs_pathinfo (struct path * pp)
 {
-	char attr_path[FILE_NAME_SIZE];
-	char attr_buff[FILE_NAME_SIZE];
+	struct udev_device *parent;
+	char attr_buff[NAME_SIZE];
+	const char *attr_path;
+
+	parent = pp->udev;
+	while (parent) {
+		if (!strncmp(udev_device_get_subsystem(parent), "ccw", 3))
+			break;
+		parent = udev_device_get_parent(parent);
+	}
+	if (!parent)
+		return 1;
 
 	sprintf(pp->vendor_id, "IBM");
 
@@ -621,7 +672,7 @@ ccw_sysfs_pathinfo (struct path * pp, const char * parent)
 	/*
 	 * host / bus / target / lun
 	 */
-	basenamecpy(parent, attr_path, FILE_NAME_SIZE);
+	attr_path = udev_device_get_sysname(parent);
 	pp->sg_id.lun = 0;
 	sscanf(attr_path, "%i.%i.%x",
 			&pp->sg_id.host_no,
@@ -638,14 +689,17 @@ ccw_sysfs_pathinfo (struct path * pp, const char * parent)
 }
 
 static int
-cciss_sysfs_pathinfo (struct path * pp, const char * devpath)
+cciss_sysfs_pathinfo (struct path * pp)
 {
-	char attr_path[FILE_NAME_SIZE];
+	const char * attr_path;
 
 	/*
 	 * host / bus / target / lun
 	 */
-	basenamecpy(devpath, attr_path, FILE_NAME_SIZE);
+	attr_path = udev_device_get_devpath(pp->udev);
+	if (!attr_path)
+		return 1;
+
 	pp->sg_id.lun = 0;
 	pp->sg_id.channel = 0;
 	sscanf(attr_path, "cciss!c%id%i",
@@ -661,20 +715,20 @@ cciss_sysfs_pathinfo (struct path * pp, const char * devpath)
 }
 
 static int
-common_sysfs_pathinfo (struct path * pp, const char * devpath)
+common_sysfs_pathinfo (struct path * pp)
 {
-	size_t len;
-
-	len = sysfs_attr_get_value(devpath, "dev",
-				   pp->dev_t, BLK_DEV_SIZE);
-	if (!len) {
+	if (!pp->udev) {
+		condlog(4, "%s: udev not initialised", pp->dev);
+		return 1;
+	}
+	if (sysfs_get_dev(pp->udev, pp->dev_t, BLK_DEV_SIZE)) {
 		condlog(3, "%s: no 'dev' attribute in sysfs", pp->dev);
 		return 1;
 	}
 
 	condlog(3, "%s: dev_t = %s", pp->dev, pp->dev_t);
 
-	if (sysfs_get_size(devpath, &pp->size))
+	if (sysfs_get_size(pp, &pp->size))
 		return 1;
 
 	condlog(3, "%s: size = %llu", pp->dev, pp->size);
@@ -682,45 +736,28 @@ common_sysfs_pathinfo (struct path * pp, const char * devpath)
 	return 0;
 }
 
-struct sysfs_device *sysfs_device_from_path(struct path *pp)
-{
-	char sysdev[FILE_NAME_SIZE];
-
-	if (pp->sysdev && sysfs_device_verify(pp->sysdev))
-		return pp->sysdev;
-
-	strlcpy(sysdev,"/block/", FILE_NAME_SIZE);
-	strlcat(sysdev,pp->dev, FILE_NAME_SIZE);
-
-	return sysfs_device_get(sysdev);
-}
-
 int
 path_offline (struct path * pp)
 {
-	struct sysfs_device * parent;
+	struct udev_device * parent;
 	char buff[SCSI_STATE_SIZE];
 
 	if (pp->bus != SYSFS_BUS_SCSI)
 		return PATH_UP;
 
-	pp->sysdev = sysfs_device_from_path(pp);
-	if (!pp->sysdev) {
-		condlog(1, "%s: failed to get sysfs information", pp->dev);
-		return PATH_WILD;
+	parent = pp->udev;
+	while (parent) {
+		if (!strncmp(udev_device_get_subsystem(parent), "scsi", 4))
+			break;
+		parent = udev_device_get_parent(parent);
 	}
 
-	parent = sysfs_device_get_parent(pp->sysdev);
-	if (!parent)
-		parent = pp->sysdev;
-	if (parent && !strncmp(parent->kernel, "block",5))
-		parent = sysfs_device_get_parent(parent);
 	if (!parent) {
-		condlog(1, "%s: failed to get parent", pp->dev);
+		condlog(1, "%s: failed to get sysfs information", pp->dev);
 		return PATH_WILD;
 	}
 
-	if (sysfs_get_state(parent->devpath, buff, SCSI_STATE_SIZE))
+	if (sysfs_get_state(parent, buff, SCSI_STATE_SIZE))
 		return PATH_WILD;
 
 	condlog(3, "%s: path state = %s", pp->dev, buff);
@@ -741,26 +778,8 @@ path_offline (struct path * pp)
 extern int
 sysfs_pathinfo(struct path * pp)
 {
-	struct sysfs_device *parent;
-
-	pp->sysdev = sysfs_device_from_path(pp);
-	if (!pp->sysdev) {
-		condlog(1, "%s: failed to get sysfs information", pp->dev);
+	if (common_sysfs_pathinfo(pp))
 		return 1;
-	}
-
-	if (common_sysfs_pathinfo(pp, pp->sysdev->devpath))
-		return 1;
-
-	parent = sysfs_device_get_parent(pp->sysdev);
-	if (!parent)
-		parent = pp->sysdev;
-	if (parent && !strncmp(parent->kernel, "block",5))
-		parent = sysfs_device_get_parent(parent);
-	if (!parent) {
-		condlog(1, "%s: failed to get parent", pp->dev);
-		return 1;
-	}
 
 	pp->bus = SYSFS_BUS_UNDEF;
 	if (!strncmp(pp->dev,"cciss",5))
@@ -773,13 +792,13 @@ sysfs_pathinfo(struct path * pp)
 	if (pp->bus == SYSFS_BUS_UNDEF)
 		return 0;
 	else if (pp->bus == SYSFS_BUS_SCSI) {
-		if (scsi_sysfs_pathinfo(pp, parent->devpath))
+		if (scsi_sysfs_pathinfo(pp))
 			return 1;
 	} else if (pp->bus == SYSFS_BUS_CCW) {
-		if (ccw_sysfs_pathinfo(pp, parent->devpath))
+		if (ccw_sysfs_pathinfo(pp))
 			return 1;
 	} else if (pp->bus == SYSFS_BUS_CCISS) {
-		if (cciss_sysfs_pathinfo(pp, pp->sysdev->devpath))
+		if (cciss_sysfs_pathinfo(pp))
 			return 1;
 	}
 	return 0;
@@ -829,7 +848,7 @@ get_state (struct path * pp, int daemon)
 	condlog(3, "%s: get_state", pp->dev);
 
 	if (!checker_selected(c)) {
-		if (daemon || pp->sysdev == NULL) {
+		if (daemon) {
 			if (pathinfo(pp, conf->hwtable, DI_SYSFS) != 0) {
 				condlog(3, "%s: couldn't get sysfs pathinfo",
 					pp->dev);
@@ -850,8 +869,8 @@ get_state (struct path * pp, int daemon)
 	checker_clear_message(c);
 	if (daemon)
 		checker_set_async(c);
-	if (!conf->checker_timeout && pp->sysdev)
-		sysfs_get_timeout(pp->sysdev->devpath, &(c->timeout));
+	if (!conf->checker_timeout)
+		sysfs_get_timeout(pp, &(c->timeout));
 	state = checker_check(c);
 	condlog(3, "%s: state = %s", pp->dev, checker_state_name(state));
 	if (state == PATH_DOWN && strlen(checker_message(c)))
libmultipath/discovery.h +3 -3
index c071026..17108c7 100644
@@ -26,7 +26,7 @@
 
 struct config;
 
-int sysfs_get_dev (const char * dev, char * buff, size_t len);
+int sysfs_get_dev (struct udev_device *udev, char * buff, size_t len);
 int path_discovery (vector pathvec, struct config * conf, int flag);
 
 int do_tur (char *);
@@ -34,9 +34,9 @@ int path_offline (struct path *);
 int get_state (struct path * pp, int daemon);
 int pathinfo (struct path *, vector hwtable, int mask);
 struct path * store_pathinfo (vector pathvec, vector hwtable,
-			      char * devname, int flag);
+			      struct udev_device *udevice, int flag);
 int sysfs_set_scsi_tmo (struct multipath *mpp);
-int sysfs_get_timeout(const char * devpath, unsigned int *timeout);
+int sysfs_get_timeout(struct path *pp, unsigned int *timeout);
 
 /*
  * discovery bitmask
libmultipath/propsel.c +1 -1
index 50b0e8a..f38af86 100644
@@ -335,7 +335,7 @@ out:
 		condlog(3, "%s: checker timeout = %u ms (config file default)",
 				pp->dev, c->timeout);
 	}
-	else if (pp->sysdev && sysfs_get_timeout(pp->sysdev->devpath, &c->timeout) == 0)
+	else if (pp->udev && sysfs_get_timeout(pp, &c->timeout) == 0)
 		condlog(3, "%s: checker timeout = %u ms (sysfs setting)",
 				pp->dev, c->timeout);
 	else {
libmultipath/structs.c +6 -0
index 280d2eb..3c0fe90 100644
@@ -5,6 +5,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <libdevmapper.h>
+#include <libudev.h>
 
 #include "checkers.h"
 #include "memory.h"
@@ -47,6 +48,11 @@ free_path (struct path * pp)
 	if (pp->fd >= 0)
 		close(pp->fd);
 
+	if (pp->udev) {
+		udev_device_unref(pp->udev);
+		pp->udev = NULL;
+	}
+
 	FREE(pp);
 }
 
libmultipath/structs.h +1 -7
index 010be5d..16aa0ff 100644
@@ -115,12 +115,6 @@ struct scsi_dev {
 	int host_no;
 };
 
-struct sysfs_device {
-	struct sysfs_device *parent;		/* parent device */
-	char devpath[PATH_SIZE];
-	char kernel[NAME_SIZE];			/* device instance name */
-};
-
 # ifndef HDIO_GETGEO
 #  define HDIO_GETGEO	0x0301	/* get device geometry */
 
@@ -134,7 +128,7 @@ struct hd_geometry {
 struct path {
 	char dev[FILE_NAME_SIZE];
 	char dev_t[BLK_DEV_SIZE];
-	struct sysfs_device *sysdev;
+	struct udev_device *udev;
 	struct scsi_idlun scsi_id;
 	struct sg_id sg_id;
 	struct hd_geometry geom;
libmultipath/structs_vec.c +4 -6
index bbbe888..b7dd7c4 100644
@@ -445,16 +445,14 @@ verify_paths(struct multipath * mpp, struct vectors * vecs, vector rpvec)
 		/*
 		 * see if path is in sysfs
 		 */
-		if (!pp->sysdev || sysfs_get_dev(pp->sysdev->devpath,
-						 pp->dev_t, BLK_DEV_SIZE)) {
+		if (!pp->udev || sysfs_get_dev(pp->udev, pp->dev_t,
+					       BLK_DEV_SIZE)) {
 			if (pp->state != PATH_DOWN) {
 				condlog(1, "%s: removing valid path %s in state %d",
-					mpp->alias,
-					pp->sysdev?pp->sysdev->devpath:pp->dev_t, pp->state);
+					mpp->alias, pp->dev, pp->state);
 			} else {
 				condlog(3, "%s: failed to access path %s",
-					mpp->alias,
-					pp->sysdev ? pp->sysdev->devpath : pp->dev_t);
+					mpp->alias, pp->dev);
 			}
 			count++;
 			vector_del_slot(mpp->paths, i);
libmultipath/sysfs.c +0 -200

221 lines not on this page · raw message

libmultipath/sysfs.h +1 -2
index 22a4c5b..b5a3f21 100644
@@ -13,7 +13,6 @@
 
 int sysfs_init(char *path, size_t len);
 void sysfs_cleanup(void);
-void sysfs_device_set_values(struct sysfs_device *dev, const char *devpath);
 struct sysfs_device *sysfs_device_get(const char *devpath);
 struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev);
 void sysfs_device_put(struct sysfs_device *dev);
@@ -23,6 +22,6 @@ size_t sysfs_attr_get_value(const char *devpath, const char *attr_name,
 ssize_t sysfs_attr_set_value(const char *devpath, const char *attr_name,
 			     const char *value, int value_len);
 int sysfs_resolve_link(char *path, size_t size);
-int sysfs_get_size(const char * devpath, unsigned long long * size);
+int sysfs_get_size(struct path *pp, unsigned long long * size);
 int sysfs_check_holders(char * check_devt, char * new_devt);
 #endif
libmultipath/uevent.c +3 -1
index 4e31d4f..a29a43c 100644
@@ -117,6 +117,8 @@ service_uevq(struct list_head *tmpq)
 		if (my_uev_trigger && my_uev_trigger(uev, my_trigger_data))
 			condlog(0, "uevent trigger error");
 
+		if (uev->udev)
+			udev_device_unref(uev->udev);
 		FREE(uev);
 	}
 }
@@ -472,7 +474,7 @@ int uevent_listen(void)
 			if (i == HOTPLUG_NUM_ENVP - 1)
 				break;
 		}
-		udev_device_unref(dev);
+		uev->udev = dev;
 		uev->envp[i] = NULL;
 
 		condlog(3, "uevent '%s' from '%s'", uev->action, uev->devpath);
libmultipath/uevent.h +1 -0
index 46596fd..64f00b7 100644
@@ -15,6 +15,7 @@
 
 struct uevent {
 	struct list_head node;
+	struct udev_device *udev;
 	char buffer[HOTPLUG_BUFFER_SIZE + OBJECT_SIZE];
 	char *devpath;
 	char *action;
libmultipath/util.c +10 -0
index f6ee09c..70735e6 100644
@@ -234,3 +234,13 @@ skip_proc:
 	basenamecpy((const char *)block_path, devname, devname_len);
 	return 0;
 }
+
+dev_t parse_devt(const char *dev_t)
+{
+	int maj, min;
+
+	if (sscanf(dev_t,"%d:%d", &maj, &min) != 2)
+		return 0;
+
+	return makedev(maj, min);
+}
libmultipath/util.h +1 -0
index cb4ce1b..44184a1 100644
@@ -9,6 +9,7 @@ size_t strlcpy(char *dst, const char *src, size_t size);
 size_t strlcat(char *dst, const char *src, size_t size);
 void remove_trailing_chars(char *path, char c);
 int devt2devname (char *, int, char *);
+dev_t parse_devt(const char *dev_t);
 
 #define safe_sprintf(var, format, args...)	\
 	snprintf(var, sizeof(var), format, ##args) >= sizeof(var)
multipath/main.c +0 -1
index 2078fe3..9be52b5 100644
@@ -539,7 +539,6 @@ main (int argc, char *argv[])
 out:
 	udev_wait(conf->cookie);
 
-	sysfs_cleanup();
 	dm_lib_release();
 	dm_lib_exit();
 
multipathd/Makefile +1 -1
index 1d4ea14..9553251 100644
@@ -6,7 +6,7 @@ include ../Makefile.inc
 # basic flags setting
 #
 CFLAGS += -I$(multipathdir) -I$(mpathpersistdir)
-LDFLAGS += -lpthread -ldevmapper -lreadline -lncurses -ldl \
+LDFLAGS += -lpthread -ldevmapper -lreadline -lncurses -ludev -ldl \
 	   -L$(multipathdir) -lmultipath -L$(mpathpersistdir) -lmpathpersist
 
 #
multipathd/cli_handlers.c +9 -2
index 5cf5f4b..39b89bf 100644
@@ -16,6 +16,8 @@
 #include <print.h>
 #include <sysfs.h>
 #include <errno.h>
+#include <libudev.h>
+#include <util.h>
 
 #include "main.h"
 #include "cli.h"
@@ -426,10 +428,15 @@ cli_add_path (void * v, char ** reply, int * len, void * data)
 		if (pp->mpp)
 			return 0;
 	} else {
+		struct udev_device *udevice;
+
+		udevice = udev_device_new_from_devnum(conf->udev, 'b',
+						      parse_devt(pp->dev_t));
 		pp = store_pathinfo(vecs->pathvec, conf->hwtable,
-				    param, DI_ALL);
+				    udevice, DI_ALL);
 		if (!pp) {
 			condlog(0, "%s: failed to store path info", param);
+			udev_device_unref(udevice);
 			return 1;
 		}
 	}
@@ -596,7 +603,7 @@ cli_resize(void *v, char **reply, int *len, void *data)
 
 	pgp = VECTOR_SLOT(mpp->pg, 0);
 	pp = VECTOR_SLOT(pgp->paths, 0);
-	if (!pp->sysdev || sysfs_get_size(pp->sysdev->devpath, &size)) {
+	if (!pp->udev || sysfs_get_size(pp, &size)) {
 		condlog(0, "%s: couldn't get size for sysfs. cannot resize",
 			mapname);
 		return 1;
multipathd/main.c +6 -3
index e87375c..b54f6c6 100644
@@ -16,6 +16,7 @@
 #include <sys/resource.h>
 #include <limits.h>
 #include <linux/oom.h>
+#include <libudev.h>
 #include <mpath_persist.h>
 
 /*
@@ -390,13 +391,17 @@ uev_add_path (struct uevent *uev, struct vectors * vecs)
 		if (pp->mpp)
 			return 0;
 	} else {
+		struct udev_device *udevice;
+
 		/*
 		 * get path vital state
 		 */
+		udevice = udev_device_ref(uev->udev);
 		if (!(pp = store_pathinfo(vecs->pathvec, conf->hwtable,
-					  uev->kernel, DI_ALL))) {
+					  udevice, DI_ALL))) {
 			condlog(0, "%s: failed to store path info",
 				uev->kernel);
+			udev_device_unref(udevice);
 			return 1;
 		}
 		pp->checkint = conf->checkint;
@@ -1671,8 +1676,6 @@ child (void * param)
 	pthread_cancel(uxlsnr_thr);
 	pthread_cancel(uevq_thr);
 
-	sysfs_cleanup();
-
 	lock(vecs->lock);
 	free_pathvec(vecs->pathvec, FREE_PATHS);
 	vecs->pathvec = NULL;
Signature · 1 line
1.7.3.4
#9 lore raw

PATCH 9/12 discovery: Fixup cciss discovery

In reply to Hannes Reinecke

We can get the sysfs attributes directly from the parent.

---
 libmultipath/discovery.c |   78 +++++++++++++++++++++++++++------------------
 1 files changed, 47 insertions(+), 31 deletions(-)
libmultipath/discovery.c +47 -31
index f45602a..fa8cfa0 100644
@@ -162,7 +162,7 @@ sysfs_get_timeout(struct path *pp, unsigned int *timeout)
 	int r;
 	unsigned int t;
 
-	if (!pp->udev)
+	if (!pp->udev || pp->bus != SYSFS_BUS_SCSI)
 		return 1;
 
 	parent = pp->udev;
@@ -691,26 +691,56 @@ ccw_sysfs_pathinfo (struct path * pp)
 static int
 cciss_sysfs_pathinfo (struct path * pp)
 {
-	const char * attr_path;
+	const char * attr_path = NULL;
+	struct udev_device *parent;
+
+	parent = pp->udev;
+	while (parent) {
+		if (!strncmp(udev_device_get_subsystem(parent), "cciss", 5)) {
+			attr_path = udev_device_get_sysname(parent);
+			if (!attr_path)
+				break;
+			if (sscanf(attr_path, "c%id%i",
+				   &pp->sg_id.host_no,
+				   &pp->sg_id.scsi_id) == 2)
+				break;
+		}
+		parent = udev_device_get_parent(parent);
+	}
+	if (!attr_path || pp->sg_id.host_no == -1)
+		return 1;
+
+	if (sysfs_get_vendor(parent, pp->vendor_id, SCSI_VENDOR_SIZE))
+		return 1;
+
+	condlog(3, "%s: vendor = %s", pp->dev, pp->vendor_id);
+
+	if (sysfs_get_model(parent, pp->product_id, SCSI_PRODUCT_SIZE))
+		return 1;
+
+	condlog(3, "%s: product = %s", pp->dev, pp->product_id);
+
+	if (sysfs_get_rev(parent, pp->rev, SCSI_REV_SIZE))
+		return 1;
+
+	condlog(3, "%s: rev = %s", pp->dev, pp->rev);
 
 	/*
-	 * host / bus / target / lun
+	 * set the hwe configlet pointer
 	 */
-	attr_path = udev_device_get_devpath(pp->udev);
-	if (!attr_path)
-		return 1;
+	pp->hwe = find_hwe(conf->hwtable, pp->vendor_id, pp->product_id, pp->rev);
 
+	/*
+	 * host / bus / target / lun
+	 */
 	pp->sg_id.lun = 0;
 	pp->sg_id.channel = 0;
-	sscanf(attr_path, "cciss!c%id%i",
-			&pp->sg_id.host_no,
-			&pp->sg_id.scsi_id);
 	condlog(3, "%s: h:b:t:l = %i:%i:%i:%i",
-			pp->dev,
-			pp->sg_id.host_no,
-			pp->sg_id.channel,
-			pp->sg_id.scsi_id,
-			pp->sg_id.lun);
+		pp->dev,
+		pp->sg_id.host_no,
+		pp->sg_id.channel,
+		pp->sg_id.scsi_id,
+		pp->sg_id.lun);
 	return 0;
 }
 
@@ -818,23 +848,9 @@ scsi_ioctl_pathinfo (struct path * pp, int mask)
 static int
 cciss_ioctl_pathinfo (struct path * pp, int mask)
 {
-	int ret;
-
-	if (mask & DI_SYSFS) {
-		ret = get_inq(pp->dev, pp->vendor_id, pp->product_id,
-			      pp->rev, pp->fd);
-		if (ret)
-			return ret;
-
-		condlog(3, "%s: vendor = %s", pp->dev, pp->vendor_id);
-		condlog(3, "%s: product = %s", pp->dev, pp->product_id);
-		condlog(3, "%s: revision = %s", pp->dev, pp->rev);
-		/*
-		 * set the hwe configlet pointer
-		 */
-		pp->hwe = find_hwe(conf->hwtable, pp->vendor_id,
-				   pp->product_id, pp->rev);
-
+	if (mask & DI_SERIAL) {
+		get_serial(pp->serial, SERIAL_SIZE, pp->fd);
+		condlog(3, "%s: serial = %s", pp->dev, pp->serial);
 	}
 	return 0;
 }
Signature · 1 line
1.7.3.4
#10 lore raw

PATCH 10/12 Use udev attribute instead of getuid_callout()

In reply to Hannes Reinecke

By the time we're receiving an event udev already figured out a unique ID. So we can just use that and get rid of the callout.

---
 libmultipath/config.c      |   16 +++---
 libmultipath/config.h      |    6 +-
 libmultipath/defaults.h    |    2 +-
 libmultipath/dict.c        |   32 +++++++-------
 libmultipath/discovery.c   |   32 ++++++++++----
 libmultipath/hwtable.c     |  102 ++++++++-----------------------------------
 libmultipath/propsel.c     |   22 +++++-----
 libmultipath/structs.h     |    2 +-
 libmultipath/structs_vec.c |    2 +-
 multipath/multipath.conf.5 |   16 +++---
 10 files changed, 91 insertions(+), 141 deletions(-)
libmultipath/config.c +8 -8
index 75eab38..2263e19 100644
@@ -161,8 +161,8 @@ free_hwe (struct hwentry * hwe)
 	if (hwe->revision)
 		FREE(hwe->revision);
 
-	if (hwe->getuid)
-		FREE(hwe->getuid);
+	if (hwe->uid_attribute)
+		FREE(hwe->uid_attribute);
 
 	if (hwe->features)
 		FREE(hwe->features);
@@ -218,8 +218,8 @@ free_mpe (struct mpentry * mpe)
 	if (mpe->selector)
 		FREE(mpe->selector);
 
-	if (mpe->getuid)
-		FREE(mpe->getuid);
+	if (mpe->uid_attribute)
+		FREE(mpe->uid_attribute);
 
 	if (mpe->alias)
 		FREE(mpe->alias);
@@ -306,7 +306,7 @@ merge_hwe (struct hwentry * dst, struct hwentry * src)
 	merge_str(vendor);
 	merge_str(product);
 	merge_str(revision);
-	merge_str(getuid);
+	merge_str(uid_attribute);
 	merge_str(features);
 	merge_str(hwhandler);
 	merge_str(selector);
@@ -349,7 +349,7 @@ store_hwe (vector hwtable, struct hwentry * dhwe)
 	if (dhwe->revision && !(hwe->revision = set_param_str(dhwe->revision)))
 		goto out;
 
-	if (dhwe->getuid && !(hwe->getuid = set_param_str(dhwe->getuid)))
+	if (dhwe->uid_attribute && !(hwe->uid_attribute = set_param_str(dhwe->uid_attribute)))
 		goto out;
 
 	if (dhwe->features && !(hwe->features = set_param_str(dhwe->features)))
@@ -440,8 +440,8 @@ free_config (struct config * conf)
 	if (conf->selector)
 		FREE(conf->selector);
 
-	if (conf->getuid)
-		FREE(conf->getuid);
+	if (conf->uid_attribute)
+		FREE(conf->uid_attribute);
 
 	if (conf->features)
 		FREE(conf->features);
libmultipath/config.h +3 -3
index 147eedf..590dde2 100644
@@ -25,7 +25,7 @@ struct hwentry {
 	char * vendor;
 	char * product;
 	char * revision;
-	char * getuid;
+	char * uid_attribute;
 	char * features;
 	char * hwhandler;
 	char * selector;
@@ -50,7 +50,7 @@ struct hwentry {
 struct mpentry {
 	char * wwid;
 	char * alias;
-	char * getuid;
+	char * uid_attribute;
 	char * selector;
 	char * features;
 
@@ -114,7 +114,7 @@ struct config {
 	char * udev_dir;
 	char * multipath_dir;
 	char * selector;
-	char * getuid;
+	char * uid_attribute;
 	char * features;
 	char * hwhandler;
 	char * bindings_file;
libmultipath/defaults.h +1 -1
index 294646a..7697195 100644
@@ -1,4 +1,4 @@
-#define DEFAULT_GETUID		"/lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/%n"
+#define DEFAULT_UID_ATTRIBUTE	"ID_SERIAL"
 #define DEFAULT_UDEVDIR		"/dev"
 #define DEFAULT_MULTIPATHDIR	"/" LIB_STRING "/multipath"
 #define DEFAULT_SELECTOR	"round-robin 0"
libmultipath/dict.c +16 -16
index 4df3d9b..c51e005 100644
@@ -161,11 +161,11 @@ def_pgpolicy_handler(vector strvec)
 }
 
 static int
-def_getuid_callout_handler(vector strvec)
+def_uid_attribute_handler(vector strvec)
 {
-	conf->getuid = set_value(strvec);
+	conf->uid_attribute = set_value(strvec);
 
-	if (!conf->getuid)
+	if (!conf->uid_attribute)
 		return 1;
 
 	return 0;
@@ -923,13 +923,13 @@ hw_pgpolicy_handler(vector strvec)
 }
 
 static int
-hw_getuid_callout_handler(vector strvec)
+hw_uid_attribute_handler(vector strvec)
 {
 	struct hwentry * hwe = VECTOR_LAST_SLOT(conf->hwtable);
 
-	hwe->getuid = set_value(strvec);
+	hwe->uid_attribute = set_value(strvec);
 
-	if (!hwe->getuid)
+	if (!hwe->uid_attribute)
 		return 1;
 
 	return 0;
@@ -1970,14 +1970,14 @@ snprint_hw_bl_product (char * buff, int len, void * data)
 }
 
 static int
-snprint_hw_getuid_callout (char * buff, int len, void * data)
+snprint_hw_uid_attribute (char * buff, int len, void * data)
 {
 	struct hwentry * hwe = (struct hwentry *)data;
 
-	if (!hwe->getuid)
+	if (!hwe->uid_attribute)
 		return 0;
 
-	return snprintf(buff, len, "\"%s\"", hwe->getuid);
+	return snprintf(buff, len, "\"%s\"", hwe->uid_attribute);
 }
 
 static int
@@ -2278,12 +2278,12 @@ snprint_def_path_grouping_policy (char * buff, int len, void * data)
 }
 
 static int
-snprint_def_getuid_callout (char * buff, int len, void * data)
+snprint_def_uid_attribute (char * buff, int len, void * data)
 {
-	if (!conf->getuid)
-		return snprintf(buff, len, "\"%s\"", DEFAULT_GETUID);
+	if (!conf->uid_attribute)
+		return snprintf(buff, len, "\"%s\"", DEFAULT_UID_ATTRIBUTE);
 
-	return snprintf(buff, len, "\"%s\"", conf->getuid);
+	return snprintf(buff, len, "\"%s\"", conf->uid_attribute);
 }
 
 static int
@@ -2551,7 +2551,7 @@ init_keywords(void)
 	install_keyword("multipath_dir", &multipath_dir_handler, &snprint_def_multipath_dir);
 	install_keyword("path_selector", &def_selector_handler, &snprint_def_selector);
 	install_keyword("path_grouping_policy", &def_pgpolicy_handler, &snprint_def_path_grouping_policy);
-	install_keyword("getuid_callout", &def_getuid_callout_handler, &snprint_def_getuid_callout);
+	install_keyword("uid_attribute", &def_uid_attribute_handler, &snprint_def_uid_attribute);
 	install_keyword("prio", &def_prio_handler, &snprint_def_prio);
 	install_keyword("prio_args", &def_prio_args_handler, &snprint_def_prio_args);
 	install_keyword("features", &def_features_handler, &snprint_def_features);
@@ -2579,7 +2579,7 @@ init_keywords(void)
 	install_keyword("reservation_key", &def_reservation_key_handler, &snprint_def_reservation_key);
 	__deprecated install_keyword("default_selector", &def_selector_handler, NULL);
 	__deprecated install_keyword("default_path_grouping_policy", &def_pgpolicy_handler, NULL);
-	__deprecated install_keyword("default_getuid_callout", &def_getuid_callout_handler, NULL);
+	__deprecated install_keyword("default_uid_attribute", &def_uid_attribute_handler, NULL);
 	__deprecated install_keyword("default_features", &def_features_handler, NULL);
 	__deprecated install_keyword("default_path_checker", &def_path_checker_handler, NULL);
 
@@ -2619,7 +2619,7 @@ init_keywords(void)
 	install_keyword("revision", &revision_handler, &snprint_hw_revision);
 	install_keyword("product_blacklist", &bl_product_handler, &snprint_hw_bl_product);
 	install_keyword("path_grouping_policy", &hw_pgpolicy_handler, &snprint_hw_path_grouping_policy);
-	install_keyword("getuid_callout", &hw_getuid_callout_handler, &snprint_hw_getuid_callout);
+	install_keyword("uid_attribute", &hw_uid_attribute_handler, &snprint_hw_uid_attribute);
 	install_keyword("path_selector", &hw_selector_handler, &snprint_hw_selector);
 	install_keyword("path_checker", &hw_path_checker_handler, &snprint_hw_path_checker);
 	install_keyword("checker", &hw_path_checker_handler, NULL);
libmultipath/discovery.c +23 -9
index fa8cfa0..452c709 100644
@@ -922,19 +922,33 @@ get_prio (struct path * pp)
 static int
 get_uid (struct path * pp)
 {
-	char buff[CALLOUT_MAX_SIZE], *c;
+	char *c;
+	const char *value;
 
-	if (!pp->getuid)
+	if (!pp->uid_attribute)
 		select_getuid(pp);
 
-	if (apply_format(pp->getuid, &buff[0], pp)) {
-		condlog(0, "error formatting uid callout command");
-		memset(pp->wwid, 0, WWID_SIZE);
-	} else if (execute_program(buff, pp->wwid, WWID_SIZE)) {
-		condlog(3, "error calling out %s", buff);
-		memset(pp->wwid, 0, WWID_SIZE);
+	if (!pp->udev) {
+		condlog(1, "%s: no udev information", pp->dev);
 		return 1;
 	}
+
+	memset(pp->wwid, 0, WWID_SIZE);
+	value = udev_device_get_property_value(pp->udev, pp->uid_attribute);
+	if (value && strlen(value)) {
+		size_t len = WWID_SIZE;
+
+		if (strlen(value) + 1 > WWID_SIZE) {
+			condlog(0, "%s: wwid overflow", pp->dev);
+		} else {
+			len = strlen(value);
+		}
+		strncpy(pp->wwid, value, len);
+	} else {
+		condlog(3, "%s: no %s attribute", pp->dev,
+			pp->uid_attribute);
+	}
+
 	/* Strip any trailing blanks */
 	c = strchr(pp->wwid, '\0');
 	c--;
@@ -942,7 +956,7 @@ get_uid (struct path * pp)
 		*c = '\0';
 		c--;
 	}
-	condlog(3, "%s: uid = %s (callout)", pp->dev,
+	condlog(3, "%s: uid = %s (udev)", pp->dev,
 		*pp->wwid == '\0' ? "<empty>" : pp->wwid);
 	return 0;
 }
libmultipath/hwtable.c +19 -83

498 lines not on this page · raw message

libmultipath/propsel.c +11 -11
index f38af86..9c06203 100644
@@ -349,21 +349,21 @@ out:
 extern int
 select_getuid (struct path * pp)
 {
-	if (pp->hwe && pp->hwe->getuid) {
-		pp->getuid = pp->hwe->getuid;
-		condlog(3, "%s: getuid = %s (controller setting)",
-			pp->dev, pp->getuid);
+	if (pp->hwe && pp->hwe->uid_attribute) {
+		pp->uid_attribute = pp->hwe->uid_attribute;
+		condlog(3, "%s: uid_attribute = %s (controller setting)",
+			pp->dev, pp->uid_attribute);
 		return 0;
 	}
-	if (conf->getuid) {
-		pp->getuid = conf->getuid;
-		condlog(3, "%s: getuid = %s (config file default)",
-			pp->dev, pp->getuid);
+	if (conf->uid_attribute) {
+		pp->uid_attribute = conf->uid_attribute;
+		condlog(3, "%s: uid_attribute = %s (config file default)",
+			pp->dev, pp->uid_attribute);
 		return 0;
 	}
-	pp->getuid = STRDUP(DEFAULT_GETUID);
-	condlog(3, "%s: getuid = %s (internal default)",
-		pp->dev, pp->getuid);
+	pp->uid_attribute = STRDUP(DEFAULT_UID_ATTRIBUTE);
+	condlog(3, "%s: uid_attribute = %s (internal default)",
+		pp->dev, pp->uid_attribute);
 	return 0;
 }
 
libmultipath/structs.h +1 -1
index 16aa0ff..4f643ef 100644
@@ -148,7 +148,7 @@ struct path {
 	int failcount;
 	int priority;
 	int pgindex;
-	char * getuid;
+	char * uid_attribute;
 	struct prio * prio;
 	struct checker checker;
 	struct multipath * mpp;
libmultipath/structs_vec.c +1 -1
index b7dd7c4..e1fb4b1 100644
@@ -82,7 +82,7 @@ orphan_path (struct path * pp)
 {
 	pp->mpp = NULL;
 	pp->dmstate = PSTATE_UNDEF;
-	pp->getuid = NULL;
+	pp->uid_attribute = NULL;
 	pp->prio = NULL;
 	checker_put(&pp->checker);
 	if (pp->fd >= 0)
multipath/multipath.conf.5 +8 -8
index dfaf532..b04a2a9 100644
@@ -55,8 +55,9 @@ section.
 .TP
 .B multipaths
 This section defines the multipath topologies. They are indexed by a
-\fIWorld Wide Identifier\fR(wwid), which is the result of the
-\fIgetuid_callout\fR program.
+\fIWorld Wide Identifier\fR(wwid), which is taken to be the value of
+the udev attribute given by the
+\fIuid_attribute\fR keyword.
 .TP
 .B devices
 This section defines the device-specific settings.
@@ -142,11 +143,10 @@ in /sys/class/fc_transport/target*/node_name.
 Default value is \fImultibus\fR.
 .RE
 .TP
-.B getuid_callout
-The default program and args to callout to obtain a unique path
-identifier. Should be specified with an absolute path. Default value
-is
-.I /lib/udev/scsi_id --whitelisted --replace-whitespace --device=/dev/%n
+.B uid_attribute
+The udev attribute providing a unique path
+identifier. Default value is
+.I ID_SERIAL
 .TP
 .B prio
 The name of the path priority routine. The specified routine
@@ -520,7 +520,7 @@ section:
 .TP 18
 .B path_grouping_policy
 .TP
-.B getuid_callout
+.B uid_attribute
 .TP
 .B path_selector
 .TP
Signature · 1 line
1.7.3.4
#11 lore raw

PATCH 11/12 Use udev devices during discovery

In reply to Hannes Reinecke

Remove all hand-crafted sysfs access code and replace it with libudev functions.

---
 libmultipath/discovery.c |  309 +++++++++++++--------------------------------
 1 files changed, 89 insertions(+), 220 deletions(-)
libmultipath/discovery.c +89 -220
index 452c709..7adda2a 100644
@@ -192,127 +192,126 @@ sysfs_get_timeout(struct path *pp, unsigned int *timeout)
 }
 
 int
-sysfs_get_size (struct path *pp, unsigned long long * size)
+sysfs_get_tgt_nodename (struct path *pp, char * node)
 {
-	const char * attr;
-	int r;
-
-	if (!pp->udev)
-		return 1;
-
-	attr = udev_device_get_sysattr_value(pp->udev, "size");
-	if (!attr) {
-		condlog(3, "%s: No size attribute in sysfs", pp->dev);
-		return 1;
-	}
-
-	r = sscanf(attr, "%llu\n", size);
+	const char *targetid, *value;
+	struct udev_device *parent, *tgtdev;
 
-	if (r != 1) {
-		condlog(3, "%s: Cannot parse size attribute '%s'",
-			pp->dev, attr);
+	parent = udev_device_get_parent_with_subsystem_devtype(pp->udev, "scsi", "scsi_device");
+	if (!parent)
 		return 1;
+	/* Check for SAS */
+	value = udev_device_get_sysattr_value(parent, "sas_address");
+	if (value) {
+		strncpy(node, value, NODE_NAME_SIZE);
+		return 0;
 	}
 
-	return 0;
-}
-
-int
-sysfs_get_tgt_nodename (struct path *pp, char * node)
-{
-	const char * targetid;
-	struct udev_device *parent;
-	char attr_path[SYSFS_PATH_SIZE];
-	size_t len;
-
-	parent = pp->udev;
-	while (parent) {
-		targetid = udev_device_get_sysname(parent);
-		if (!strncmp(targetid , "target", 6))
-			break;
-		parent = udev_device_get_parent(parent);
-	}
-	/* 'target' needs to exist */
-	if (!parent || !targetid)
+	parent = udev_device_get_parent_with_subsystem_devtype(pp->udev, "scsi", "scsi_target");
+	if (!parent)
 		return 1;
+	tgtdev = udev_device_new_from_subsystem_sysname(conf->udev, "fc_transport", udev_device_get_sysname(parent));
 	/* Check if it's FibreChannel */
-	if (safe_sprintf(attr_path,
-			 "/class/fc_transport/%s", targetid)) {
-		condlog(0, "attr_path too small");
-		return 1;
-	}
+	if (tgtdev) {
+		const char *value;
 
-	len = sysfs_attr_get_value(attr_path, "node_name",
-				   node, NODE_NAME_SIZE);
-	if (len)
-		return 0;
+		value = udev_device_get_sysattr_value(tgtdev, "node_name");
+		if (value) {
+			strncpy(node, value, NODE_NAME_SIZE);
+			return 0;
+		}
+		udev_device_unref(tgtdev);
+	}
 
 	/* Check for iSCSI */
 	parent = pp->udev;
+	targetid = NULL;
 	while (parent) {
 		targetid = udev_device_get_sysname(parent);
 		if (!strncmp(targetid , "session", 6))
 			break;
 		parent = udev_device_get_parent(parent);
+		targetid = NULL;
 	}
 	if (parent) {
-		if (safe_sprintf(attr_path, "/class/iscsi_session/%s",
-				 targetid)) {
-			condlog(0, "attr_path too small");
-			return 1;
+		tgtdev = udev_device_new_from_subsystem_sysname(conf->udev, "iscsi_session", targetid);
+		if (node) {
+			const char *value;
+
+			value = udev_device_get_sysattr_value(tgtdev, "targetname");
+			if (value) {
+				strncpy(node, value, NODE_NAME_SIZE);
+				return 0;
+			}
+			udev_device_unref(tgtdev);
 		}
-		len = sysfs_attr_get_value(attr_path, "targetname", node,
-					   NODE_NAME_SIZE);
-		if (len)
-			return 0;
 	}
-
 	return 1;
 }
 
-static int
-find_rport_id(struct path *pp)
+static void
+sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp)
 {
-	char attr_path[SYSFS_PATH_SIZE];
-	char *dir, *base;
-	int host, channel, rport_id = -1;
-
-	if (safe_sprintf(attr_path,
-			 "/class/fc_transport/target%i:%i:%i",
-			 pp->sg_id.host_no, pp->sg_id.channel,
-			 pp->sg_id.scsi_id)) {
-		condlog(0, "attr_path too small for target");
-		return 1;
-	}
-
-	if (sysfs_resolve_link(attr_path, SYSFS_PATH_SIZE))
-		return -1;
-
-	condlog(4, "target%d:%d:%d -> path %s", pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.scsi_id, attr_path);
-	dir = attr_path;
-	do {
-		base = basename(dir);
-		dir = dirname(dir);
+	struct udev_device *parent = pp->udev;
+	struct udev_device *rport_dev = NULL;
+	char value[11];
+	const char *rport_id = NULL;
 
-		if (sscanf((const char *)base, "rport-%d:%d-%d", &host, &channel, &rport_id) == 3)
+	while (parent) {
+		rport_id = udev_device_get_sysname(parent);
+		if (!strncmp(rport_id, "rport-", 6))
 			break;
-	} while (strcmp((const char *)dir, "/"));
-
-	if (rport_id < 0)
-		return -1;
-
-	condlog(4, "target%d:%d:%d -> rport_id %d", pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.scsi_id, rport_id);
-	return rport_id;
+		parent = udev_device_get_parent(parent);
+		rport_id = NULL;
+	}
+	if (!parent || !rport_id) {
+		condlog(0, "%s: rport id not found", pp->dev);
+		return;
+	}
+	rport_dev = udev_device_new_from_subsystem_sysname(conf->udev, "fc_remote_ports", rport_id);
+	if (!rport_dev) {
+		condlog(3, "%s: No fc_remote_port device for '%s'", pp->dev,
+			rport_id);
+		return;
+	}
+	condlog(4, "target%d:%d:%d -> %s", pp->sg_id.host_no,
+		pp->sg_id.channel, pp->sg_id.scsi_id, rport_id);
+
+	snprintf(value, 11, "%u", mpp->dev_loss);
+	if (sysfs_attr_set_value(rport_dev, "dev_loss_tmo", value, 11) < 0) {
+		if ((!mpp->fast_io_fail ||
+		     mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF)
+		    && mpp->dev_loss > 600) {
+			condlog(3, "%s: limiting dev_loss_tmo to 600, since "
+				"fast_io_fail is not set", mpp->alias);
+			snprintf(value, 11, "%u", 600);
+			if (sysfs_attr_set_value(rport_dev, "dev_loss_tmo",
+						 value, 11) < 0)
+				condlog(0, "%s failed to set dev_loss_tmo",
+					mpp->alias);
+			return;
+		}
+	}
+	if (mpp->fast_io_fail){
+		if (mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF)
+			sprintf(value, "off");
+		else if (mpp->fast_io_fail == MP_FAST_IO_FAIL_ZERO)
+			sprintf(value, "0");
+		else
+			snprintf(value, 11, "%u", mpp->fast_io_fail);
+		if (sysfs_attr_set_value(rport_dev, "fast_io_fail_tmo",
+					 value, 11) < 0) {
+			condlog(0, "%s failed to set fast_io_fail_tmo",
+				mpp->alias);
+		}
+	}
 }
 
 int
 sysfs_set_scsi_tmo (struct multipath *mpp)
 {
-	char attr_path[SYSFS_PATH_SIZE];
 	struct path *pp;
 	int i;
-	char value[11];
-	int rport_id;
 	int dev_loss_tmo = mpp->dev_loss;
 
 	if (mpp->no_path_retry > 0) {
@@ -339,75 +338,11 @@ sysfs_set_scsi_tmo (struct multipath *mpp)
 		return 0;
 
 	vector_foreach_slot(mpp->paths, pp, i) {
-		rport_id = find_rport_id(pp);
-		if (rport_id < 0) {
-			condlog(3, "failed to find rport_id for target%d:%d:%d", pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.scsi_id);
-			return 1;
-		}
-
-		if (safe_snprintf(attr_path, SYSFS_PATH_SIZE,
-				  "/class/fc_remote_ports/rport-%d:%d-%d",
-				  pp->sg_id.host_no, pp->sg_id.channel,
-				  rport_id)) {
-			condlog(0, "attr_path '/class/fc_remote_ports/rport-%d:%d-%d' too large", pp->sg_id.host_no, pp->sg_id.channel, rport_id);
-			return 1;
-		}
-		if (mpp->dev_loss){
-			snprintf(value, 11, "%u", mpp->dev_loss);
-			if (sysfs_attr_set_value(attr_path, "dev_loss_tmo",
-						 value, 11) < 0) {
-				int err = 1;
-				if ((!mpp->fast_io_fail || mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF) && mpp->dev_loss > 600) {
-					strncpy(value, "600", 4);
-					condlog(3, "%s: limiting dev_loss_tmo to 600, since fast_io_fail is not set", mpp->alias);
-					if (sysfs_attr_set_value(attr_path, "dev_loss_tmo", value, 11) >= 0)
-						err = 0;
-				}
-				if (err) {
-					condlog(0, "%s failed to set %s/dev_loss_tmo", mpp->alias, attr_path);
-					return 1;
-				}
-			}
-		}
-		if (mpp->fast_io_fail){
-			if (mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF)
-				sprintf(value, "off");
-			else if (mpp->fast_io_fail == MP_FAST_IO_FAIL_ZERO)
-				sprintf(value, "0");
-			else
-				snprintf(value, 11, "%u", mpp->fast_io_fail);
-			if (sysfs_attr_set_value(attr_path, "fast_io_fail_tmo",
-						 value, 11) < 0) {
-				condlog(0,
-					"%s failed to set %s/fast_io_fail_tmo", 
-					mpp->alias, attr_path);
-				return 1;
-			}
-		}
+		sysfs_set_rport_tmo(mpp, pp);
 	}
 	return 0;
 }
 
-static int
-opennode (char * dev, int mode)
-{
-	char devpath[FILE_NAME_SIZE], *ptr;
-
-	if (safe_sprintf(devpath, "%s/%s", conf->udev_dir, dev)) {
-		condlog(0, "devpath too small");
-		return -1;
-	}
-	/*
-	 * Translate '!' into '/'
-	 */
-	ptr = devpath;
-	while ((ptr = strchr(ptr, '!'))) {
-		*ptr = '/';
-		ptr++;
-	}
-	return open(devpath, mode);
-}
-
 int
 do_inq(int sg_fd, int cmddt, int evpd, unsigned int pg_op,
        void *resp, int mx_resp_len)
@@ -484,72 +419,6 @@ get_serial (char * str, int maxlen, int fd)
 }
 
 static int
-get_inq (char * dev, char * vendor, char * product, char * rev, int fd)
-{
-	unsigned char buff[MX_ALLOC_LEN + 1] = {0};
-	int len;
-
-	if (fd < 0)
-		return 1;
-
-	if (0 != do_inq(fd, 0, 0, 0, buff, MX_ALLOC_LEN))
-		return 1;
-
-	/* Check peripheral qualifier */
-	if ((buff[0] >> 5) != 0) {
-		int pqual = (buff[0] >> 5);
-		switch (pqual) {
-		case 1:
-			condlog(3, "%s: INQUIRY failed, LU not connected", dev);
-			break;
-		case 3:
-			condlog(3, "%s: INQUIRY failed, LU not supported", dev);
-			break;
-		default:
-			condlog(3, "%s: INQUIRY failed, Invalid PQ %x",
-				dev, pqual);
-			break;
-		}
-
-		return 1;
-	}
-
-	len = buff[4] + 4;
-
-	if (len < 8) {
-		condlog(3, "%s: INQUIRY response too short (len %d)",
-			dev, len);
-		return 1;
-	}
-
-	len -= 8;
-	memset(vendor, 0x0, 8);
-	memcpy(vendor, buff + 8, len > 8 ? 8 : len);
-	vendor[8] = '\0';
-	strchop(vendor);
-	if (len <= 8)
-		return 0;
-
-	len -= 8;
-
-	memset(product, 0x0, 16);
-	memcpy(product, buff + 16, len > 16 ? 16 : len);
-	product[16] = '\0';
-	strchop(product);
-	if (len <= 16)
-		return 0;
-
-	len -= 16;
-
-	memset(rev, 0x0, 4);
-	memcpy(rev, buff + 32, 4);
-	rev[4] = '\0';
-	strchop(rev);
-
-	return 0;
-}
-
-static int
 get_geometry(struct path *pp)
 {
 	if (pp->fd < 0)
@@ -980,7 +849,7 @@ pathinfo (struct path *pp, vector hwtable, int mask)
 	 * fetch info not available through sysfs
 	 */
 	if (pp->fd < 0)
-		pp->fd = opennode(pp->dev, O_RDWR);
+		pp->fd = open(udev_device_get_devnode(pp->udev), O_RDWR);
 
 	if (pp->fd < 0) {
 		condlog(4, "Couldn't open node for %s: %s",
Signature · 1 line
1.7.3.4
#12 lore raw

PATCH 12/12 Remove all references to hand-craftes sysfs code

In reply to Hannes Reinecke

We've now converted everything to libudev, so we can get rid of all the variables etc.

---
 libmpathpersist/mpath_persist.c |    5 -
 libmultipath/config.c           |    9 +--
 libmultipath/config.h           |    3 -
 libmultipath/dict.c             |   23 +-----
 libmultipath/structs_vec.c      |    1 -
 libmultipath/sysfs.c            |  183 ++++++++++-----------------------------
 libmultipath/sysfs.h            |   21 +----
 multipath/main.c                |    4 -
 multipath/multipath.conf.5      |    4 -
 multipathd/main.c               |    4 -
 10 files changed, 50 insertions(+), 207 deletions(-)
libmpathpersist/mpath_persist.c +0 -5
index 302dd3f..d99c0da 100644
@@ -19,7 +19,6 @@
 #include <dmparser.h>
 #include <ctype.h>
 #include <propsel.h>
-#include <sysfs.h>
 
 #include "mpathpr.h"
 #include "mpath_pr_ioctl.h"
@@ -40,10 +39,6 @@ mpath_lib_init (void)
 		return 1;
 	}
 
-	if (sysfs_init(conf->sysfs_dir, FILE_NAME_SIZE)){
-		condlog(0, "Failed. mpathpersist needs sysfs mounted");
-		exit(1);
-	}
 	return 0;
 }
 
libmultipath/config.c +1 -8
index 2263e19..0f17f03 100644
@@ -431,9 +431,6 @@ free_config (struct config * conf)
 	if (conf->udev)
 		udev_unref(conf->udev);
 
-	if (conf->udev_dir)
-		FREE(conf->udev_dir);
-
 	if (conf->multipath_dir)
 		FREE(conf->multipath_dir);
 
@@ -597,14 +594,10 @@ load_config (char * file)
 		if (!conf->mptable)
 			goto out;
 	}
-	if (conf->udev_dir == NULL)
-		conf->udev_dir = set_default(DEFAULT_UDEVDIR);
-
 	if (conf->bindings_file == NULL)
 		conf->bindings_file = set_default(DEFAULT_BINDINGS_FILE);
 
-	if (!conf->udev_dir || !conf->multipath_dir ||
-	    !conf->bindings_file)
+	if (!conf->multipath_dir || !conf->bindings_file)
 		goto out;
 
 	return 0;
libmultipath/config.h +0 -3
index 590dde2..bcca7bd 100644
@@ -77,7 +77,6 @@ struct config {
 	int dry_run;
 	int list;
 	int pgpolicy_flag;
-	int with_sysfs;
 	int pgpolicy;
 	enum devtypes dev_type;
 	int minio;
@@ -110,8 +109,6 @@ struct config {
 
 	char * dev;
 	struct udev * udev;
-	char * sysfs_dir;
-	char * udev_dir;
 	char * multipath_dir;
 	char * selector;
 	char * uid_attribute;
libmultipath/dict.c +1 -22
index c51e005..7300b7e 100644
@@ -112,17 +112,6 @@ reassign_maps_handler(vector strvec)
 }
 
 static int
-udev_dir_handler(vector strvec)
-{
-	conf->udev_dir = set_value(strvec);
-
-	if (!conf->udev_dir)
-		return 1;
-
-	return 0;
-}
-
-static int
 multipath_dir_handler(vector strvec)
 {
 	conf->multipath_dir = set_value(strvec);
@@ -2237,18 +2226,9 @@ snprint_reassign_maps (char * buff, int len, void * data)
 }
 
 static int
-snprint_def_udev_dir (char * buff, int len, void * data)
-{
-	if (!conf->udev_dir)
-		return 0;
-
-	return snprintf(buff, len, "\"%s\"", conf->udev_dir);
-}
-
-static int
 snprint_def_multipath_dir (char * buff, int len, void * data)
 {
-	if (!conf->udev_dir)
+	if (!conf->multipath_dir)
 		return 0;
 
 	return snprintf(buff, len, "\"%s\"", conf->multipath_dir);
@@ -2547,7 +2527,6 @@ init_keywords(void)
 	install_keyword("polling_interval", &polling_interval_handler, &snprint_def_polling_interval);
 	install_keyword("max_polling_interval", &max_polling_interval_handler, &snprint_def_max_polling_interval);
 	install_keyword("reassign_maps", &reassign_maps_handler, &snprint_reassign_maps);
-	install_keyword("udev_dir", &udev_dir_handler, &snprint_def_udev_dir);
 	install_keyword("multipath_dir", &multipath_dir_handler, &snprint_def_multipath_dir);
 	install_keyword("path_selector", &def_selector_handler, &snprint_def_selector);
 	install_keyword("path_grouping_policy", &def_pgpolicy_handler, &snprint_def_path_grouping_policy);
libmultipath/structs_vec.c +0 -1
index e1fb4b1..6e70d63 100644
@@ -13,7 +13,6 @@
 #include "dmparser.h"
 #include "config.h"
 #include "propsel.h"
-#include "sysfs.h"
 #include "discovery.h"
 #include "prio.h"
 
libmultipath/sysfs.c +45 -138

222 lines not on this page · raw message

libmultipath/sysfs.h +3 -18
index b5a3f21..13d7545 100644
@@ -5,23 +5,8 @@
 #ifndef _LIBMULTIPATH_SYSFS_H
 #define _LIBMULTIPATH_SYSFS_H
 
-#ifdef DEBUG
-# define dbg(format, args...) condlog(4, format, ##args)
-#else
-# define dbg(format, args...) do {} while (0)
-#endif
-
-int sysfs_init(char *path, size_t len);
-void sysfs_cleanup(void);
-struct sysfs_device *sysfs_device_get(const char *devpath);
-struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev);
-void sysfs_device_put(struct sysfs_device *dev);
-struct sysfs_device *sysfs_device_verify(struct sysfs_device *dev);
-size_t sysfs_attr_get_value(const char *devpath, const char *attr_name,
-			    char *attr_value, int attr_len);
-ssize_t sysfs_attr_set_value(const char *devpath, const char *attr_name,
-			     const char *value, int value_len);
-int sysfs_resolve_link(char *path, size_t size);
-int sysfs_get_size(struct path *pp, unsigned long long * size);
+ssize_t sysfs_attr_set_value(struct udev_device *dev, const char *attr_name,
+			     char * value, size_t value_len);
+int sysfs_get_size (struct path *pp, unsigned long long * size);
 int sysfs_check_holders(char * check_devt, char * new_devt);
 #endif
multipath/main.c +0 -4
index 9be52b5..9ea2ae3 100644
@@ -412,10 +412,6 @@ main (int argc, char *argv[])
 	if (load_config(DEFAULT_CONFIGFILE))
 		exit(1);
 
-	if (sysfs_init(conf->sysfs_dir, FILE_NAME_SIZE)) {
-		condlog(0, "multipath tools need sysfs mounted");
-		exit(1);
-	}
 	while ((arg = getopt(argc, argv, ":dhl::FfM:v:p:b:Brtq")) != EOF ) {
 		switch(arg) {
 		case 1: printf("optarg : %s\n",optarg);
multipath/multipath.conf.5 +0 -4
index b04a2a9..8dd4a4b 100644
@@ -79,10 +79,6 @@ default is
 maximal interval between two path checks in seconds; default is
 .I 4 * polling_interval
 .TP
-.B udev_dir
-directory where udev creates its device nodes; default is
-.I /dev
-.TP
 .B multipath_dir
 directory where the dynamic shared objects are stored; default is system
 dependent, commonly
multipathd/main.c +0 -4
index b54f6c6..f7625ca 100644
@@ -1607,10 +1607,6 @@ child (void * param)
 	if (!vecs)
 		exit(1);
 
-	if (sysfs_init(conf->sysfs_dir, FILE_NAME_SIZE)) {
-		condlog(0, "can not find sysfs mount point");
-		exit(1);
-	}
 	conf->daemon = 1;
 	udev_set_sync_support(0);
 	/*
Signature · 1 line
1.7.3.4