|
|
4ae388 |
---
|
|
|
4ae388 |
libmultipath/discovery.c | 109 +++++++++++++++++++++++++++++++++++++----------
|
|
|
4ae388 |
libmultipath/sysfs.c | 86 +++++++++++++++++++++++++++++++------
|
|
|
4ae388 |
libmultipath/sysfs.h | 2
|
|
|
4ae388 |
3 files changed, 161 insertions(+), 36 deletions(-)
|
|
|
4ae388 |
|
|
|
4ae388 |
Index: multipath-tools-130222/libmultipath/discovery.c
|
|
|
4ae388 |
===================================================================
|
|
|
4ae388 |
--- multipath-tools-130222.orig/libmultipath/discovery.c
|
|
|
4ae388 |
+++ multipath-tools-130222/libmultipath/discovery.c
|
|
|
4ae388 |
@@ -162,7 +162,6 @@ declare_sysfs_get_str(cutype);
|
|
|
4ae388 |
declare_sysfs_get_str(vendor);
|
|
|
4ae388 |
declare_sysfs_get_str(model);
|
|
|
4ae388 |
declare_sysfs_get_str(rev);
|
|
|
4ae388 |
-declare_sysfs_get_str(state);
|
|
|
4ae388 |
declare_sysfs_get_str(dev);
|
|
|
4ae388 |
|
|
|
4ae388 |
int
|
|
|
4ae388 |
@@ -315,9 +314,14 @@ static void
|
|
|
4ae388 |
sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp)
|
|
|
4ae388 |
{
|
|
|
4ae388 |
struct udev_device *rport_dev = NULL;
|
|
|
4ae388 |
- char value[11];
|
|
|
4ae388 |
+ char value[16];
|
|
|
4ae388 |
char rport_id[32];
|
|
|
4ae388 |
+ int delay_fast_io_fail = 0;
|
|
|
4ae388 |
+ int current_dev_loss = 0;
|
|
|
4ae388 |
+ int ret;
|
|
|
4ae388 |
|
|
|
4ae388 |
+ if (!mpp->dev_loss && mpp->fast_io_fail == MP_FAST_IO_FAIL_UNSET)
|
|
|
4ae388 |
+ return;
|
|
|
4ae388 |
sprintf(rport_id, "rport-%d:%d-%d",
|
|
|
4ae388 |
pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.transport_id);
|
|
|
4ae388 |
rport_dev = udev_device_new_from_subsystem_sysname(conf->udev,
|
|
|
4ae388 |
@@ -330,33 +334,85 @@ sysfs_set_rport_tmo(struct multipath *mp
|
|
|
4ae388 |
condlog(4, "target%d:%d:%d -> %s", pp->sg_id.host_no,
|
|
|
4ae388 |
pp->sg_id.channel, pp->sg_id.scsi_id, rport_id);
|
|
|
4ae388 |
|
|
|
4ae388 |
- snprintf(value, 11, "%u", mpp->dev_loss);
|
|
|
4ae388 |
- if (mpp->dev_loss &&
|
|
|
4ae388 |
- sysfs_attr_set_value(rport_dev, "dev_loss_tmo", value, 11) <= 0) {
|
|
|
4ae388 |
- if ((mpp->fast_io_fail == MP_FAST_IO_FAIL_UNSET ||
|
|
|
4ae388 |
- mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF)
|
|
|
4ae388 |
- && mpp->dev_loss > 600) {
|
|
|
4ae388 |
- condlog(3, "%s: limiting dev_loss_tmo to 600, since "
|
|
|
4ae388 |
- "fast_io_fail is not set", mpp->alias);
|
|
|
4ae388 |
- snprintf(value, 11, "%u", 600);
|
|
|
4ae388 |
- if (sysfs_attr_set_value(rport_dev, "dev_loss_tmo",
|
|
|
4ae388 |
- value, 11) <= 0)
|
|
|
4ae388 |
- condlog(0, "%s failed to set dev_loss_tmo",
|
|
|
4ae388 |
- mpp->alias);
|
|
|
4ae388 |
+ memset(value, 0, 16);
|
|
|
4ae388 |
+ if (mpp->fast_io_fail != MP_FAST_IO_FAIL_UNSET) {
|
|
|
4ae388 |
+ ret = sysfs_attr_get_value(rport_dev, "dev_loss_tmo",
|
|
|
4ae388 |
+ value, 16);
|
|
|
4ae388 |
+ if (ret <= 0) {
|
|
|
4ae388 |
+ condlog(0, "%s: failed to read dev_loss_tmo value, "
|
|
|
4ae388 |
+ "error %d", rport_id, -ret);
|
|
|
4ae388 |
goto out;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
+ if (sscanf(value, "%u\n", ¤t_dev_loss) != 1) {
|
|
|
4ae388 |
+ condlog(0, "%s: Cannot parse dev_loss_tmo "
|
|
|
4ae388 |
+ "attribute '%s'", rport_id, value);
|
|
|
4ae388 |
+ goto out;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ if ((mpp->dev_loss &&
|
|
|
4ae388 |
+ mpp->fast_io_fail >= (int)mpp->dev_loss) ||
|
|
|
4ae388 |
+ (!mpp->dev_loss &&
|
|
|
4ae388 |
+ mpp->fast_io_fail >= (int)current_dev_loss)) {
|
|
|
4ae388 |
+ condlog(3, "%s: limiting fast_io_fail_tmo to %d, since "
|
|
|
4ae388 |
+ "it must be less than dev_loss_tmo",
|
|
|
4ae388 |
+ rport_id, mpp->dev_loss - 1);
|
|
|
4ae388 |
+ if (mpp->dev_loss)
|
|
|
4ae388 |
+ mpp->fast_io_fail = mpp->dev_loss - 1;
|
|
|
4ae388 |
+ else
|
|
|
4ae388 |
+ mpp->fast_io_fail = current_dev_loss - 1;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ if (mpp->fast_io_fail >= (int)current_dev_loss)
|
|
|
4ae388 |
+ delay_fast_io_fail = 1;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ if (mpp->dev_loss > 600 &&
|
|
|
4ae388 |
+ (mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF ||
|
|
|
4ae388 |
+ mpp->fast_io_fail == MP_FAST_IO_FAIL_UNSET)) {
|
|
|
4ae388 |
+ condlog(3, "%s: limiting dev_loss_tmo to 600, since "
|
|
|
4ae388 |
+ "fast_io_fail is unset or off", rport_id);
|
|
|
4ae388 |
+ mpp->dev_loss = 600;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
- if (mpp->fast_io_fail != MP_FAST_IO_FAIL_UNSET){
|
|
|
4ae388 |
+ if (mpp->fast_io_fail != MP_FAST_IO_FAIL_UNSET) {
|
|
|
4ae388 |
if (mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF)
|
|
|
4ae388 |
sprintf(value, "off");
|
|
|
4ae388 |
else if (mpp->fast_io_fail == MP_FAST_IO_FAIL_ZERO)
|
|
|
4ae388 |
sprintf(value, "0");
|
|
|
4ae388 |
+ else if (delay_fast_io_fail)
|
|
|
4ae388 |
+ snprintf(value, 16, "%u", current_dev_loss - 1);
|
|
|
4ae388 |
else
|
|
|
4ae388 |
- snprintf(value, 11, "%u", mpp->fast_io_fail);
|
|
|
4ae388 |
- if (sysfs_attr_set_value(rport_dev, "fast_io_fail_tmo",
|
|
|
4ae388 |
- value, 11) <= 0) {
|
|
|
4ae388 |
- condlog(0, "%s failed to set fast_io_fail_tmo",
|
|
|
4ae388 |
- mpp->alias);
|
|
|
4ae388 |
+ snprintf(value, 16, "%u", mpp->fast_io_fail);
|
|
|
4ae388 |
+ ret = sysfs_attr_set_value(rport_dev, "fast_io_fail_tmo",
|
|
|
4ae388 |
+ value, strlen(value));
|
|
|
4ae388 |
+ if (ret <= 0) {
|
|
|
4ae388 |
+ if (ret == -EBUSY)
|
|
|
4ae388 |
+ condlog(3, "%s: rport blocked", rport_id);
|
|
|
4ae388 |
+ else
|
|
|
4ae388 |
+ condlog(0, "%s: failed to set fast_io_fail_tmo to %s, error %d",
|
|
|
4ae388 |
+ rport_id, value, -ret);
|
|
|
4ae388 |
+ goto out;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ if (mpp->dev_loss) {
|
|
|
4ae388 |
+ snprintf(value, 16, "%u", mpp->dev_loss);
|
|
|
4ae388 |
+ ret = sysfs_attr_set_value(rport_dev, "dev_loss_tmo",
|
|
|
4ae388 |
+ value, strlen(value));
|
|
|
4ae388 |
+ if (ret <= 0) {
|
|
|
4ae388 |
+ if (ret == -EBUSY)
|
|
|
4ae388 |
+ condlog(3, "%s: rport blocked", rport_id);
|
|
|
4ae388 |
+ else
|
|
|
4ae388 |
+ condlog(0, "%s: failed to set dev_loss_tmo to %s, error %d",
|
|
|
4ae388 |
+ rport_id, value, -ret);
|
|
|
4ae388 |
+ goto out;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ if (delay_fast_io_fail) {
|
|
|
4ae388 |
+ snprintf(value, 16, "%u", mpp->fast_io_fail);
|
|
|
4ae388 |
+ ret = sysfs_attr_set_value(rport_dev, "fast_io_fail_tmo",
|
|
|
4ae388 |
+ value, strlen(value));
|
|
|
4ae388 |
+ if (ret <= 0) {
|
|
|
4ae388 |
+ if (ret == -EBUSY)
|
|
|
4ae388 |
+ condlog(3, "%s: rport blocked", rport_id);
|
|
|
4ae388 |
+ else
|
|
|
4ae388 |
+ condlog(0, "%s: failed to set fast_io_fail_tmo to %s, error %d",
|
|
|
4ae388 |
+ rport_id, value, -ret);
|
|
|
4ae388 |
}
|
|
|
4ae388 |
}
|
|
|
4ae388 |
out:
|
|
|
4ae388 |
@@ -394,7 +450,7 @@ sysfs_set_session_tmo(struct multipath *
|
|
|
4ae388 |
} else {
|
|
|
4ae388 |
snprintf(value, 11, "%u", mpp->fast_io_fail);
|
|
|
4ae388 |
if (sysfs_attr_set_value(session_dev, "recovery_tmo",
|
|
|
4ae388 |
- value, 11)) {
|
|
|
4ae388 |
+ value, 11) <= 0) {
|
|
|
4ae388 |
condlog(3, "%s: Failed to set recovery_tmo, "
|
|
|
4ae388 |
" error %d", pp->dev, errno);
|
|
|
4ae388 |
}
|
|
|
4ae388 |
@@ -752,6 +808,9 @@ cciss_sysfs_pathinfo (struct path * pp)
|
|
|
4ae388 |
static int
|
|
|
4ae388 |
common_sysfs_pathinfo (struct path * pp)
|
|
|
4ae388 |
{
|
|
|
4ae388 |
+ if (!pp)
|
|
|
4ae388 |
+ return 1;
|
|
|
4ae388 |
+
|
|
|
4ae388 |
if (!pp->udev) {
|
|
|
4ae388 |
condlog(4, "%s: udev not initialised", pp->dev);
|
|
|
4ae388 |
return 1;
|
|
|
4ae388 |
@@ -793,7 +852,8 @@ path_offline (struct path * pp)
|
|
|
4ae388 |
return PATH_DOWN;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
|
|
|
4ae388 |
- if (sysfs_get_state(parent, buff, SCSI_STATE_SIZE))
|
|
|
4ae388 |
+ memset(buff, 0x0, SCSI_STATE_SIZE);
|
|
|
4ae388 |
+ if (sysfs_attr_get_value(parent, "state", buff, SCSI_STATE_SIZE) <= 0)
|
|
|
4ae388 |
return PATH_DOWN;
|
|
|
4ae388 |
|
|
|
4ae388 |
condlog(3, "%s: path state = %s", pp->dev, buff);
|
|
|
4ae388 |
@@ -983,6 +1043,9 @@ pathinfo (struct path *pp, vector hwtabl
|
|
|
4ae388 |
{
|
|
|
4ae388 |
int path_state;
|
|
|
4ae388 |
|
|
|
4ae388 |
+ if (!pp)
|
|
|
4ae388 |
+ return 1;
|
|
|
4ae388 |
+
|
|
|
4ae388 |
condlog(3, "%s: mask = 0x%x", pp->dev, mask);
|
|
|
4ae388 |
|
|
|
4ae388 |
/*
|
|
|
4ae388 |
Index: multipath-tools-130222/libmultipath/sysfs.c
|
|
|
4ae388 |
===================================================================
|
|
|
4ae388 |
--- multipath-tools-130222.orig/libmultipath/sysfs.c
|
|
|
4ae388 |
+++ multipath-tools-130222/libmultipath/sysfs.c
|
|
|
4ae388 |
@@ -38,7 +38,12 @@
|
|
|
4ae388 |
#include "debug.h"
|
|
|
4ae388 |
#include "devmapper.h"
|
|
|
4ae388 |
|
|
|
4ae388 |
-ssize_t sysfs_attr_set_value(struct udev_device *dev, const char *attr_name,
|
|
|
4ae388 |
+/*
|
|
|
4ae388 |
+ * When we modify an attribute value we cannot rely on libudev for now,
|
|
|
4ae388 |
+ * as libudev lacks the capability to update an attribute value.
|
|
|
4ae388 |
+ * So for modified attributes we need to implement our own function.
|
|
|
4ae388 |
+ */
|
|
|
4ae388 |
+ssize_t sysfs_attr_get_value(struct udev_device *dev, const char *attr_name,
|
|
|
4ae388 |
char * value, size_t value_len)
|
|
|
4ae388 |
{
|
|
|
4ae388 |
char devpath[PATH_SIZE];
|
|
|
4ae388 |
@@ -54,28 +59,83 @@ ssize_t sysfs_attr_set_value(struct udev
|
|
|
4ae388 |
condlog(4, "open '%s'", devpath);
|
|
|
4ae388 |
if (stat(devpath, &statbuf) != 0) {
|
|
|
4ae388 |
condlog(4, "stat '%s' failed: %s", devpath, strerror(errno));
|
|
|
4ae388 |
- return 0;
|
|
|
4ae388 |
+ return -errno;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
|
|
|
4ae388 |
/* skip directories */
|
|
|
4ae388 |
- if (S_ISDIR(statbuf.st_mode))
|
|
|
4ae388 |
- return 0;
|
|
|
4ae388 |
+ if (S_ISDIR(statbuf.st_mode)) {
|
|
|
4ae388 |
+ condlog(4, "%s is a directory", devpath);
|
|
|
4ae388 |
+ return -EISDIR;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
|
|
|
4ae388 |
/* skip non-writeable files */
|
|
|
4ae388 |
- if ((statbuf.st_mode & S_IWUSR) == 0)
|
|
|
4ae388 |
+ if ((statbuf.st_mode & S_IRUSR) == 0) {
|
|
|
4ae388 |
+ condlog(4, "%s is not readable", devpath);
|
|
|
4ae388 |
+ return -EPERM;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+ /* read attribute value */
|
|
|
4ae388 |
+ fd = open(devpath, O_RDONLY);
|
|
|
4ae388 |
+ if (fd < 0) {
|
|
|
4ae388 |
+ condlog(4, "attribute '%s' can not be opened: %s",
|
|
|
4ae388 |
+ devpath, strerror(errno));
|
|
|
4ae388 |
+ return -errno;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+ size = read(fd, value, value_len);
|
|
|
4ae388 |
+ if (size < 0) {
|
|
|
4ae388 |
+ condlog(4, "read from %s failed: %s", devpath, strerror(errno));
|
|
|
4ae388 |
+ size = -errno;
|
|
|
4ae388 |
+ } else if (size == value_len) {
|
|
|
4ae388 |
+ condlog(4, "overflow while reading from %s", devpath);
|
|
|
4ae388 |
+ size = 0;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+ close(fd);
|
|
|
4ae388 |
+ return size;
|
|
|
4ae388 |
+}
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+ssize_t sysfs_attr_set_value(struct udev_device *dev, const char *attr_name,
|
|
|
4ae388 |
+ char * value, size_t value_len)
|
|
|
4ae388 |
+{
|
|
|
4ae388 |
+ char devpath[PATH_SIZE];
|
|
|
4ae388 |
+ struct stat statbuf;
|
|
|
4ae388 |
+ int fd;
|
|
|
4ae388 |
+ ssize_t size = -1;
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+ if (!dev || !attr_name || !value || !value_len)
|
|
|
4ae388 |
return 0;
|
|
|
4ae388 |
|
|
|
4ae388 |
+ snprintf(devpath, PATH_SIZE, "%s/%s", udev_device_get_syspath(dev),
|
|
|
4ae388 |
+ attr_name);
|
|
|
4ae388 |
+ condlog(4, "open '%s'", devpath);
|
|
|
4ae388 |
+ if (stat(devpath, &statbuf) != 0) {
|
|
|
4ae388 |
+ condlog(4, "stat '%s' failed: %s", devpath, strerror(errno));
|
|
|
4ae388 |
+ return -errno;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+ /* skip directories */
|
|
|
4ae388 |
+ if (S_ISDIR(statbuf.st_mode)) {
|
|
|
4ae388 |
+ condlog(4, "%s is a directory", devpath);
|
|
|
4ae388 |
+ return -EISDIR;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+
|
|
|
4ae388 |
+ /* skip non-writeable files */
|
|
|
4ae388 |
+ if ((statbuf.st_mode & S_IWUSR) == 0) {
|
|
|
4ae388 |
+ condlog(4, "%s is not writeable", devpath);
|
|
|
4ae388 |
+ return -EPERM;
|
|
|
4ae388 |
+ }
|
|
|
4ae388 |
+
|
|
|
4ae388 |
/* write attribute value */
|
|
|
4ae388 |
fd = open(devpath, O_WRONLY);
|
|
|
4ae388 |
if (fd < 0) {
|
|
|
4ae388 |
condlog(4, "attribute '%s' can not be opened: %s",
|
|
|
4ae388 |
devpath, strerror(errno));
|
|
|
4ae388 |
- return 0;
|
|
|
4ae388 |
+ return -errno;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
size = write(fd, value, value_len);
|
|
|
4ae388 |
if (size < 0) {
|
|
|
4ae388 |
condlog(4, "write to %s failed: %s", devpath, strerror(errno));
|
|
|
4ae388 |
- size = 0;
|
|
|
4ae388 |
+ size = -errno;
|
|
|
4ae388 |
} else if (size < value_len) {
|
|
|
4ae388 |
condlog(4, "tried to write %ld to %s. Wrote %ld",
|
|
|
4ae388 |
(long)value_len, devpath, (long)size);
|
|
|
4ae388 |
@@ -89,14 +149,14 @@ ssize_t sysfs_attr_set_value(struct udev
|
|
|
4ae388 |
int
|
|
|
4ae388 |
sysfs_get_size (struct path *pp, unsigned long long * size)
|
|
|
4ae388 |
{
|
|
|
4ae388 |
- const char * attr;
|
|
|
4ae388 |
+ char attr[255];
|
|
|
4ae388 |
int r;
|
|
|
4ae388 |
|
|
|
4ae388 |
- if (!pp->udev)
|
|
|
4ae388 |
+ if (!pp->udev || !size)
|
|
|
4ae388 |
return 1;
|
|
|
4ae388 |
|
|
|
4ae388 |
- attr = udev_device_get_sysattr_value(pp->udev, "size");
|
|
|
4ae388 |
- if (!attr) {
|
|
|
4ae388 |
+ attr[0] = '\0';
|
|
|
4ae388 |
+ if (sysfs_attr_get_value(pp->udev, "size", attr, 255) == 0) {
|
|
|
4ae388 |
condlog(3, "%s: No size attribute in sysfs", pp->dev);
|
|
|
4ae388 |
return 1;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
@@ -104,8 +164,8 @@ sysfs_get_size (struct path *pp, unsigne
|
|
|
4ae388 |
r = sscanf(attr, "%llu\n", size);
|
|
|
4ae388 |
|
|
|
4ae388 |
if (r != 1) {
|
|
|
4ae388 |
- condlog(3, "%s: Cannot parse size attribute '%s'",
|
|
|
4ae388 |
- pp->dev, attr);
|
|
|
4ae388 |
+ condlog(3, "%s: Cannot parse size attribute", pp->dev);
|
|
|
4ae388 |
+ *size = 0;
|
|
|
4ae388 |
return 1;
|
|
|
4ae388 |
}
|
|
|
4ae388 |
|
|
|
4ae388 |
Index: multipath-tools-130222/libmultipath/sysfs.h
|
|
|
4ae388 |
===================================================================
|
|
|
4ae388 |
--- multipath-tools-130222.orig/libmultipath/sysfs.h
|
|
|
4ae388 |
+++ multipath-tools-130222/libmultipath/sysfs.h
|
|
|
4ae388 |
@@ -7,6 +7,8 @@
|
|
|
4ae388 |
|
|
|
4ae388 |
ssize_t sysfs_attr_set_value(struct udev_device *dev, const char *attr_name,
|
|
|
4ae388 |
char * value, size_t value_len);
|
|
|
4ae388 |
+ssize_t sysfs_attr_get_value(struct udev_device *dev, const char *attr_name,
|
|
|
4ae388 |
+ char * value, size_t value_len);
|
|
|
4ae388 |
int sysfs_get_size (struct path *pp, unsigned long long * size);
|
|
|
4ae388 |
int sysfs_check_holders(char * check_devt, char * new_devt);
|
|
|
4ae388 |
#endif
|