summaryrefslogtreecommitdiff
path: root/libmultipath
diff options
context:
space:
mode:
authorBenjamin Marzinski <bmarzins@redhat.com>2012-06-05 18:04:36 -0500
committerChristophe Varoqui <christophe.varoqui@opensvc.com>2012-06-06 20:09:01 +0200
commita00088a0162fe96d647c42902a9f86c4950b907f (patch)
tree98d16c72c9c30baf93113111e84da129956a3eac /libmultipath
parentac25859c3e58bae0471f6c28bd1af67d49d78406 (diff)
downloadmultipath-tools-a00088a0162fe96d647c42902a9f86c4950b907f.tar.gz
multipath-tools-a00088a0162fe96d647c42902a9f86c4950b907f.tar.bz2
multipath-tools-a00088a0162fe96d647c42902a9f86c4950b907f.zip
multipath: libudev cleanup and bugfixes
get_refwwid wasn't working anymore, since it wasn't setting the path's udevice. Also, cli_add_path was dereferencing a NULL pointer (pp). Finally, there were a number of places where udev devices weren't getting dereferenced when they should have been, causing memory leaks. This patch cleans these up. Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
Diffstat (limited to 'libmultipath')
-rw-r--r--libmultipath/configure.c42
-rw-r--r--libmultipath/discovery.c10
-rw-r--r--libmultipath/uevent.c1
3 files changed, 26 insertions, 27 deletions
diff --git a/libmultipath/configure.c b/libmultipath/configure.c
index 001c1f0..46910f3 100644
--- a/libmultipath/configure.c
+++ b/libmultipath/configure.c
@@ -13,6 +13,7 @@
#include <sys/file.h>
#include <errno.h>
#include <libdevmapper.h>
+#include <libudev.h>
#include "checkers.h"
#include "vector.h"
@@ -680,18 +681,17 @@ get_refwwid (char * dev, enum devtypes dev_type, vector pathvec)
pp = find_path_by_dev(pathvec, buff);
if (!pp) {
- pp = alloc_path();
+ struct udev_device *udevice = udev_device_new_from_subsystem_sysname(conf->udev, "block", buff);
- if (!pp)
+ if (!udevice) {
+ condlog(2, "%s: can't get udev device", buff);
return NULL;
-
- strncpy(pp->dev, buff, FILE_NAME_SIZE);
-
- if (pathinfo(pp, conf->hwtable, DI_SYSFS | DI_WWID))
- return NULL;
-
- if (store_path(pathvec, pp)) {
- free_path(pp);
+ }
+ pp = store_pathinfo(pathvec, conf->hwtable, udevice,
+ DI_SYSFS | DI_WWID);
+ udev_device_unref(udevice);
+ if (!pp) {
+ condlog(0, "%s can't store path info", buff);
return NULL;
}
}
@@ -703,21 +703,17 @@ get_refwwid (char * dev, enum devtypes dev_type, vector pathvec)
strchop(dev);
pp = find_path_by_devt(pathvec, dev);
if (!pp) {
- if (devt2devname(buff, FILE_NAME_SIZE, dev))
- return NULL;
+ struct udev_device *udevice = udev_device_new_from_devnum(conf->udev, 'b', parse_devt(dev));
- pp = alloc_path();
-
- if (!pp)
- return NULL;
-
- strncpy(pp->dev, buff, FILE_NAME_SIZE);
-
- if (pathinfo(pp, conf->hwtable, DI_SYSFS | DI_WWID))
+ if (!udevice) {
+ condlog(2, "%s: can't get udev device", dev);
return NULL;
-
- if (store_path(pathvec, pp)) {
- free_path(pp);
+ }
+ pp = store_pathinfo(pathvec, conf->hwtable, udevice,
+ DI_SYSFS | DI_WWID);
+ udev_device_unref(udevice);
+ if (!pp) {
+ condlog(0, "%s can't store path info", buff);
return NULL;
}
}
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index c408721..25c7cda 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -216,11 +216,11 @@ sysfs_get_tgt_nodename (struct path *pp, char * node)
const char *value;
value = udev_device_get_sysattr_value(tgtdev, "node_name");
+ udev_device_unref(tgtdev);
if (value) {
strncpy(node, value, NODE_NAME_SIZE);
return 0;
}
- udev_device_unref(tgtdev);
}
/* Check for iSCSI */
@@ -235,15 +235,15 @@ sysfs_get_tgt_nodename (struct path *pp, char * node)
}
if (parent) {
tgtdev = udev_device_new_from_subsystem_sysname(conf->udev, "iscsi_session", targetid);
- if (node) {
+ if (tgtdev) {
const char *value;
value = udev_device_get_sysattr_value(tgtdev, "targetname");
+ udev_device_unref(tgtdev);
if (value) {
strncpy(node, value, NODE_NAME_SIZE);
return 0;
}
- udev_device_unref(tgtdev);
}
}
return 1;
@@ -289,7 +289,7 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp)
value, 11) < 0)
condlog(0, "%s failed to set dev_loss_tmo",
mpp->alias);
- return;
+ goto out;
}
}
if (mpp->fast_io_fail){
@@ -305,6 +305,8 @@ sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp)
mpp->alias);
}
}
+out:
+ udev_device_unref(rport_dev);
}
int
diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c
index 52b8aaf..0b7eb7a 100644
--- a/libmultipath/uevent.c
+++ b/libmultipath/uevent.c
@@ -443,6 +443,7 @@ int uevent_listen(void)
uev = alloc_uevent();
if (!uev) {
+ udev_device_unref(dev);
condlog(1, "lost uevent, oom");
continue;
}