2 libmultipath/discovery.c | 109 +++++++++++++++++++++++++++++++++++++----------
3 libmultipath/sysfs.c | 86 +++++++++++++++++++++++++++++++------
4 libmultipath/sysfs.h | 2
5 3 files changed, 161 insertions(+), 36 deletions(-)
7 Index: multipath-tools-130222/libmultipath/discovery.c
8 ===================================================================
9 --- multipath-tools-130222.orig/libmultipath/discovery.c
10 +++ multipath-tools-130222/libmultipath/discovery.c
11 @@ -162,7 +162,6 @@ declare_sysfs_get_str(cutype);
12 declare_sysfs_get_str(vendor);
13 declare_sysfs_get_str(model);
14 declare_sysfs_get_str(rev);
15 -declare_sysfs_get_str(state);
16 declare_sysfs_get_str(dev);
19 @@ -315,9 +314,14 @@ static void
20 sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp)
22 struct udev_device *rport_dev = NULL;
26 + int delay_fast_io_fail = 0;
27 + int current_dev_loss = 0;
30 + if (!mpp->dev_loss && mpp->fast_io_fail == MP_FAST_IO_FAIL_UNSET)
32 sprintf(rport_id, "rport-%d:%d-%d",
33 pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.transport_id);
34 rport_dev = udev_device_new_from_subsystem_sysname(conf->udev,
35 @@ -330,33 +334,85 @@ sysfs_set_rport_tmo(struct multipath *mp
36 condlog(4, "target%d:%d:%d -> %s", pp->sg_id.host_no,
37 pp->sg_id.channel, pp->sg_id.scsi_id, rport_id);
39 - snprintf(value, 11, "%u", mpp->dev_loss);
40 - if (mpp->dev_loss &&
41 - sysfs_attr_set_value(rport_dev, "dev_loss_tmo", value, 11) <= 0) {
42 - if ((mpp->fast_io_fail == MP_FAST_IO_FAIL_UNSET ||
43 - mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF)
44 - && mpp->dev_loss > 600) {
45 - condlog(3, "%s: limiting dev_loss_tmo to 600, since "
46 - "fast_io_fail is not set", mpp->alias);
47 - snprintf(value, 11, "%u", 600);
48 - if (sysfs_attr_set_value(rport_dev, "dev_loss_tmo",
50 - condlog(0, "%s failed to set dev_loss_tmo",
52 + memset(value, 0, 16);
53 + if (mpp->fast_io_fail != MP_FAST_IO_FAIL_UNSET) {
54 + ret = sysfs_attr_get_value(rport_dev, "dev_loss_tmo",
57 + condlog(0, "%s: failed to read dev_loss_tmo value, "
58 + "error %d", rport_id, -ret);
61 + if (sscanf(value, "%u\n", ¤t_dev_loss) != 1) {
62 + condlog(0, "%s: Cannot parse dev_loss_tmo "
63 + "attribute '%s'", rport_id, value);
66 + if ((mpp->dev_loss &&
67 + mpp->fast_io_fail >= (int)mpp->dev_loss) ||
69 + mpp->fast_io_fail >= (int)current_dev_loss)) {
70 + condlog(3, "%s: limiting fast_io_fail_tmo to %d, since "
71 + "it must be less than dev_loss_tmo",
72 + rport_id, mpp->dev_loss - 1);
74 + mpp->fast_io_fail = mpp->dev_loss - 1;
76 + mpp->fast_io_fail = current_dev_loss - 1;
78 + if (mpp->fast_io_fail >= (int)current_dev_loss)
79 + delay_fast_io_fail = 1;
81 + if (mpp->dev_loss > 600 &&
82 + (mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF ||
83 + mpp->fast_io_fail == MP_FAST_IO_FAIL_UNSET)) {
84 + condlog(3, "%s: limiting dev_loss_tmo to 600, since "
85 + "fast_io_fail is unset or off", rport_id);
86 + mpp->dev_loss = 600;
88 - if (mpp->fast_io_fail != MP_FAST_IO_FAIL_UNSET){
89 + if (mpp->fast_io_fail != MP_FAST_IO_FAIL_UNSET) {
90 if (mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF)
91 sprintf(value, "off");
92 else if (mpp->fast_io_fail == MP_FAST_IO_FAIL_ZERO)
94 + else if (delay_fast_io_fail)
95 + snprintf(value, 16, "%u", current_dev_loss - 1);
97 - snprintf(value, 11, "%u", mpp->fast_io_fail);
98 - if (sysfs_attr_set_value(rport_dev, "fast_io_fail_tmo",
100 - condlog(0, "%s failed to set fast_io_fail_tmo",
102 + snprintf(value, 16, "%u", mpp->fast_io_fail);
103 + ret = sysfs_attr_set_value(rport_dev, "fast_io_fail_tmo",
104 + value, strlen(value));
107 + condlog(3, "%s: rport blocked", rport_id);
109 + condlog(0, "%s: failed to set fast_io_fail_tmo to %s, error %d",
110 + rport_id, value, -ret);
114 + if (mpp->dev_loss) {
115 + snprintf(value, 16, "%u", mpp->dev_loss);
116 + ret = sysfs_attr_set_value(rport_dev, "dev_loss_tmo",
117 + value, strlen(value));
120 + condlog(3, "%s: rport blocked", rport_id);
122 + condlog(0, "%s: failed to set dev_loss_tmo to %s, error %d",
123 + rport_id, value, -ret);
127 + if (delay_fast_io_fail) {
128 + snprintf(value, 16, "%u", mpp->fast_io_fail);
129 + ret = sysfs_attr_set_value(rport_dev, "fast_io_fail_tmo",
130 + value, strlen(value));
133 + condlog(3, "%s: rport blocked", rport_id);
135 + condlog(0, "%s: failed to set fast_io_fail_tmo to %s, error %d",
136 + rport_id, value, -ret);
140 @@ -394,7 +450,7 @@ sysfs_set_session_tmo(struct multipath *
142 snprintf(value, 11, "%u", mpp->fast_io_fail);
143 if (sysfs_attr_set_value(session_dev, "recovery_tmo",
146 condlog(3, "%s: Failed to set recovery_tmo, "
147 " error %d", pp->dev, errno);
149 @@ -752,6 +808,9 @@ cciss_sysfs_pathinfo (struct path * pp)
151 common_sysfs_pathinfo (struct path * pp)
157 condlog(4, "%s: udev not initialised", pp->dev);
159 @@ -793,7 +852,8 @@ path_offline (struct path * pp)
163 - if (sysfs_get_state(parent, buff, SCSI_STATE_SIZE))
164 + memset(buff, 0x0, SCSI_STATE_SIZE);
165 + if (sysfs_attr_get_value(parent, "state", buff, SCSI_STATE_SIZE) <= 0)
168 condlog(3, "%s: path state = %s", pp->dev, buff);
169 @@ -983,6 +1043,9 @@ pathinfo (struct path *pp, vector hwtabl
176 condlog(3, "%s: mask = 0x%x", pp->dev, mask);
179 Index: multipath-tools-130222/libmultipath/sysfs.c
180 ===================================================================
181 --- multipath-tools-130222.orig/libmultipath/sysfs.c
182 +++ multipath-tools-130222/libmultipath/sysfs.c
185 #include "devmapper.h"
187 -ssize_t sysfs_attr_set_value(struct udev_device *dev, const char *attr_name,
189 + * When we modify an attribute value we cannot rely on libudev for now,
190 + * as libudev lacks the capability to update an attribute value.
191 + * So for modified attributes we need to implement our own function.
193 +ssize_t sysfs_attr_get_value(struct udev_device *dev, const char *attr_name,
194 char * value, size_t value_len)
196 char devpath[PATH_SIZE];
197 @@ -54,28 +59,83 @@ ssize_t sysfs_attr_set_value(struct udev
198 condlog(4, "open '%s'", devpath);
199 if (stat(devpath, &statbuf) != 0) {
200 condlog(4, "stat '%s' failed: %s", devpath, strerror(errno));
205 /* skip directories */
206 - if (S_ISDIR(statbuf.st_mode))
208 + if (S_ISDIR(statbuf.st_mode)) {
209 + condlog(4, "%s is a directory", devpath);
213 /* skip non-writeable files */
214 - if ((statbuf.st_mode & S_IWUSR) == 0)
215 + if ((statbuf.st_mode & S_IRUSR) == 0) {
216 + condlog(4, "%s is not readable", devpath);
220 + /* read attribute value */
221 + fd = open(devpath, O_RDONLY);
223 + condlog(4, "attribute '%s' can not be opened: %s",
224 + devpath, strerror(errno));
227 + size = read(fd, value, value_len);
229 + condlog(4, "read from %s failed: %s", devpath, strerror(errno));
231 + } else if (size == value_len) {
232 + condlog(4, "overflow while reading from %s", devpath);
240 +ssize_t sysfs_attr_set_value(struct udev_device *dev, const char *attr_name,
241 + char * value, size_t value_len)
243 + char devpath[PATH_SIZE];
244 + struct stat statbuf;
248 + if (!dev || !attr_name || !value || !value_len)
251 + snprintf(devpath, PATH_SIZE, "%s/%s", udev_device_get_syspath(dev),
253 + condlog(4, "open '%s'", devpath);
254 + if (stat(devpath, &statbuf) != 0) {
255 + condlog(4, "stat '%s' failed: %s", devpath, strerror(errno));
259 + /* skip directories */
260 + if (S_ISDIR(statbuf.st_mode)) {
261 + condlog(4, "%s is a directory", devpath);
265 + /* skip non-writeable files */
266 + if ((statbuf.st_mode & S_IWUSR) == 0) {
267 + condlog(4, "%s is not writeable", devpath);
271 /* write attribute value */
272 fd = open(devpath, O_WRONLY);
274 condlog(4, "attribute '%s' can not be opened: %s",
275 devpath, strerror(errno));
279 size = write(fd, value, value_len);
281 condlog(4, "write to %s failed: %s", devpath, strerror(errno));
284 } else if (size < value_len) {
285 condlog(4, "tried to write %ld to %s. Wrote %ld",
286 (long)value_len, devpath, (long)size);
287 @@ -89,14 +149,14 @@ ssize_t sysfs_attr_set_value(struct udev
289 sysfs_get_size (struct path *pp, unsigned long long * size)
296 + if (!pp->udev || !size)
299 - attr = udev_device_get_sysattr_value(pp->udev, "size");
302 + if (sysfs_attr_get_value(pp->udev, "size", attr, 255) == 0) {
303 condlog(3, "%s: No size attribute in sysfs", pp->dev);
306 @@ -104,8 +164,8 @@ sysfs_get_size (struct path *pp, unsigne
307 r = sscanf(attr, "%llu\n", size);
310 - condlog(3, "%s: Cannot parse size attribute '%s'",
312 + condlog(3, "%s: Cannot parse size attribute", pp->dev);
317 Index: multipath-tools-130222/libmultipath/sysfs.h
318 ===================================================================
319 --- multipath-tools-130222.orig/libmultipath/sysfs.h
320 +++ multipath-tools-130222/libmultipath/sysfs.h
323 ssize_t sysfs_attr_set_value(struct udev_device *dev, const char *attr_name,
324 char * value, size_t value_len);
325 +ssize_t sysfs_attr_get_value(struct udev_device *dev, const char *attr_name,
326 + char * value, size_t value_len);
327 int sysfs_get_size (struct path *pp, unsigned long long * size);
328 int sysfs_check_holders(char * check_devt, char * new_devt);