2 * Copyright (c) 2004, 2005, 2006 Christophe Varoqui
3 * Copyright (c) 2005 Stefan Bader, IBM
4 * Copyright (c) 2005 Mike Anderson
22 #include "blacklist.h"
26 #include "sg_include.h"
28 #include "discovery.h"
33 store_pathinfo (vector pathvec, vector hwtable, struct udev_device *udevice,
34 int flag, struct path **pp_ptr)
43 devname = udev_device_get_sysname(udevice);
52 if(safe_sprintf(pp->dev, "%s", devname)) {
53 condlog(0, "pp->dev too small");
56 pp->udev = udev_device_ref(udevice);
57 err = pathinfo(pp, hwtable,
58 (conf->dry_run == 3)? flag : (flag | DI_BLACKLIST));
62 err = store_path(pathvec, pp);
75 path_discover (vector pathvec, struct config * conf,
76 struct udev_device *udevice, int flag)
81 devname = udev_device_get_sysname(udevice);
85 if (filter_property(conf, udevice) > 0)
88 if (filter_devnode(conf->blist_devnode, conf->elist_devnode,
92 pp = find_path_by_dev(pathvec, (char *)devname);
94 if (store_pathinfo(pathvec, conf->hwtable,
95 udevice, flag, NULL) != 1)
100 return pathinfo(pp, conf->hwtable, flag);
104 path_discovery (vector pathvec, struct config * conf, int flag)
106 struct udev_enumerate *udev_iter;
107 struct udev_list_entry *entry;
108 struct udev_device *udevice;
112 udev_iter = udev_enumerate_new(conf->udev);
116 udev_enumerate_add_match_subsystem(udev_iter, "block");
117 udev_enumerate_scan_devices(udev_iter);
119 udev_list_entry_foreach(entry,
120 udev_enumerate_get_list_entry(udev_iter)) {
122 devpath = udev_list_entry_get_name(entry);
123 condlog(4, "Discover device %s", devpath);
124 udevice = udev_device_new_from_syspath(conf->udev, devpath);
126 condlog(4, "%s: no udev information", devpath);
130 devtype = udev_device_get_devtype(udevice);
131 if(devtype && !strncmp(devtype, "disk", 4)) {
132 r += path_discover(pathvec, conf,
135 udev_device_unref(udevice);
137 udev_enumerate_unref(udev_iter);
138 condlog(4, "Discovery status %d", r);
142 #define declare_sysfs_get_str(fname) \
144 sysfs_get_##fname (struct udev_device * udev, char * buff, size_t len) \
147 const char * devname; \
149 devname = udev_device_get_sysname(udev); \
151 attr = udev_device_get_sysattr_value(udev, #fname); \
153 condlog(3, "%s: attribute %s not found in sysfs", \
157 if (strlen(attr) > len) { \
158 condlog(3, "%s: overflow in attribute %s", \
162 strlcpy(buff, attr, len); \
166 declare_sysfs_get_str(devtype);
167 declare_sysfs_get_str(cutype);
168 declare_sysfs_get_str(vendor);
169 declare_sysfs_get_str(model);
170 declare_sysfs_get_str(rev);
171 declare_sysfs_get_str(dev);
174 sysfs_get_timeout(struct path *pp, unsigned int *timeout)
176 const char *attr = NULL;
178 struct udev_device *parent;
182 if (!pp->udev || pp->bus != SYSFS_BUS_SCSI)
187 subsys = udev_device_get_subsystem(parent);
188 attr = udev_device_get_sysattr_value(parent, "timeout");
191 parent = udev_device_get_parent(parent);
194 condlog(3, "%s: No timeout value in sysfs", pp->dev);
198 r = sscanf(attr, "%u\n", &t);
201 condlog(3, "%s: Cannot parse timeout attribute '%s'",
212 sysfs_get_tgt_nodename (struct path *pp, char * node)
214 const char *tgtname, *value;
215 struct udev_device *parent, *tgtdev;
216 int host, channel, tgtid = -1;
218 parent = udev_device_get_parent_with_subsystem_devtype(pp->udev, "scsi", "scsi_device");
222 value = udev_device_get_sysattr_value(parent, "sas_address");
224 tgtdev = udev_device_get_parent(parent);
226 tgtname = udev_device_get_sysname(tgtdev);
227 if (sscanf(tgtname, "end_device-%d:%d",
230 tgtdev = udev_device_get_parent(tgtdev);
234 pp->sg_id.proto_id = SCSI_PROTOCOL_SAS;
235 pp->sg_id.transport_id = tgtid;
236 strncpy(node, value, NODE_NAME_SIZE);
241 parent = udev_device_get_parent_with_subsystem_devtype(pp->udev, "scsi", "scsi_target");
244 /* Check for FibreChannel */
245 tgtdev = udev_device_get_parent(parent);
246 value = udev_device_get_sysname(tgtdev);
247 if (sscanf(value, "rport-%d:%d-%d",
248 &host, &channel, &tgtid) == 3) {
249 tgtdev = udev_device_new_from_subsystem_sysname(conf->udev,
250 "fc_remote_ports", value);
252 condlog(3, "SCSI target %d:%d:%d -> "
254 pp->sg_id.host_no, pp->sg_id.channel,
255 pp->sg_id.scsi_id, host, channel,
257 value = udev_device_get_sysattr_value(tgtdev,
260 pp->sg_id.proto_id = SCSI_PROTOCOL_FCP;
261 pp->sg_id.transport_id = tgtid;
262 strncpy(node, value, NODE_NAME_SIZE);
263 udev_device_unref(tgtdev);
266 udev_device_unref(tgtdev);
270 /* Check for iSCSI */
274 tgtname = udev_device_get_sysname(parent);
275 if (tgtname && sscanf(tgtname , "session%d", &tgtid) == 1)
277 parent = udev_device_get_parent(parent);
281 if (parent && tgtname) {
282 tgtdev = udev_device_new_from_subsystem_sysname(conf->udev,
283 "iscsi_session", tgtname);
287 value = udev_device_get_sysattr_value(tgtdev, "tgtname");
289 pp->sg_id.proto_id = SCSI_PROTOCOL_ISCSI;
290 pp->sg_id.transport_id = tgtid;
291 strncpy(node, value, NODE_NAME_SIZE);
292 udev_device_unref(tgtdev);
296 udev_device_unref(tgtdev);
299 /* Check for libata */
303 tgtname = udev_device_get_sysname(parent);
304 if (tgtname && sscanf(tgtname, "ata%d", &tgtid) == 1)
306 parent = udev_device_get_parent(parent);
310 pp->sg_id.proto_id = SCSI_PROTOCOL_ATA;
311 pp->sg_id.transport_id = tgtid;
312 snprintf(node, NODE_NAME_SIZE, "ata-%d.00", tgtid);
315 pp->sg_id.proto_id = SCSI_PROTOCOL_UNSPEC;
320 sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp)
322 struct udev_device *rport_dev = NULL;
325 unsigned long long tmo = 0;
328 sprintf(rport_id, "rport-%d:%d-%d",
329 pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.transport_id);
330 rport_dev = udev_device_new_from_subsystem_sysname(conf->udev,
331 "fc_remote_ports", rport_id);
333 condlog(1, "%s: No fc_remote_port device for '%s'", pp->dev,
337 condlog(4, "target%d:%d:%d -> %s", pp->sg_id.host_no,
338 pp->sg_id.channel, pp->sg_id.scsi_id, rport_id);
342 * dev_loss_tmo will be limited to 600 if fast_io_fail
344 * fast_io_fail will be limited by the current dev_loss_tmo
346 * So to get everything right we first need to increase
347 * dev_loss_tmo to the fast_io_fail setting (if present),
348 * then set fast_io_fail, and _then_ set dev_loss_tmo
349 * to the correct value.
352 if (mpp->fast_io_fail != MP_FAST_IO_FAIL_UNSET &&
353 mpp->fast_io_fail != MP_FAST_IO_FAIL_ZERO &&
354 mpp->fast_io_fail != MP_FAST_IO_FAIL_OFF) {
355 /* Check if we need to temporarily increase dev_loss_tmo */
356 ret = sysfs_attr_get_value(rport_dev, "dev_loss_tmo",
359 condlog(0, "%s: failed to read dev_loss_tmo value, "
360 "error %d", rport_id, -ret);
363 if (sscanf(value, "%llu\n", &tmo) != 1) {
364 condlog(0, "%s: Cannot parse dev_loss_tmo "
365 "attribute '%s'", rport_id, value);
368 if (mpp->fast_io_fail >= tmo) {
369 snprintf(value, 11, "%u", mpp->fast_io_fail);
371 } else if (mpp->dev_loss > 600) {
372 condlog(3, "%s: limiting dev_loss_tmo to 600, since "
373 "fast_io_fail is not set", rport_id);
374 snprintf(value, 11, "%u", 600);
376 snprintf(value, 11, "%u", mpp->dev_loss);
379 ret = sysfs_attr_set_value(rport_dev, "dev_loss_tmo", value, 11);
382 condlog(3, "%s: rport blocked", rport_id);
384 condlog(0, "%s: failed to set dev_loss_tmo to %s, error %d",
385 rport_id, value, -ret);
389 if (mpp->fast_io_fail != MP_FAST_IO_FAIL_UNSET) {
390 if (mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF)
391 sprintf(value, "off");
392 else if (mpp->fast_io_fail == MP_FAST_IO_FAIL_ZERO)
395 snprintf(value, 11, "%u", mpp->fast_io_fail);
396 ret = sysfs_attr_set_value(rport_dev, "fast_io_fail_tmo",
400 condlog(3, "%s: rport blocked", rport_id);
402 condlog(0, "%s: failed to set fast_io_fail_tmo to %s, error %d",
403 rport_id, value, -ret);
407 snprintf(value, 11, "%u", mpp->dev_loss);
408 ret = sysfs_attr_set_value(rport_dev, "dev_loss_tmo",
412 condlog(3, "%s: rport blocked", rport_id);
414 condlog(0, "%s: failed to set dev_loss_tmo to %s, error %d",
415 rport_id, value, -ret);
419 udev_device_unref(rport_dev);
423 sysfs_set_session_tmo(struct multipath *mpp, struct path *pp)
425 struct udev_device *session_dev = NULL;
429 sprintf(session_id, "session%d", pp->sg_id.transport_id);
430 session_dev = udev_device_new_from_subsystem_sysname(conf->udev,
431 "iscsi_session", session_id);
433 condlog(1, "%s: No iscsi session for '%s'", pp->dev,
437 condlog(4, "target%d:%d:%d -> %s", pp->sg_id.host_no,
438 pp->sg_id.channel, pp->sg_id.scsi_id, session_id);
441 condlog(3, "%s: ignoring dev_loss_tmo on iSCSI", pp->dev);
443 if (mpp->fast_io_fail != MP_FAST_IO_FAIL_UNSET) {
444 if (mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF) {
445 condlog(3, "%s: can't switch off fast_io_fail_tmo "
446 "on iSCSI", pp->dev);
447 } else if (mpp->fast_io_fail == MP_FAST_IO_FAIL_ZERO) {
448 condlog(3, "%s: can't set fast_io_fail_tmo to '0'"
449 "on iSCSI", pp->dev);
451 snprintf(value, 11, "%u", mpp->fast_io_fail);
452 if (sysfs_attr_set_value(session_dev, "recovery_tmo",
454 condlog(3, "%s: Failed to set recovery_tmo, "
455 " error %d", pp->dev, errno);
459 udev_device_unref(session_dev);
464 sysfs_set_nexus_loss_tmo(struct multipath *mpp, struct path *pp)
466 struct udev_device *sas_dev = NULL;
470 sprintf(end_dev_id, "end_device-%d:%d",
471 pp->sg_id.host_no, pp->sg_id.transport_id);
472 sas_dev = udev_device_new_from_subsystem_sysname(conf->udev,
473 "sas_end_device", end_dev_id);
475 condlog(1, "%s: No SAS end device for '%s'", pp->dev,
479 condlog(4, "target%d:%d:%d -> %s", pp->sg_id.host_no,
480 pp->sg_id.channel, pp->sg_id.scsi_id, end_dev_id);
483 snprintf(value, 11, "%u", mpp->dev_loss);
484 if (sysfs_attr_set_value(sas_dev, "I_T_nexus_loss_timeout",
486 condlog(3, "%s: failed to update "
487 "I_T Nexus loss timeout, error %d",
490 udev_device_unref(sas_dev);
495 sysfs_set_scsi_tmo (struct multipath *mpp)
499 int dev_loss_tmo = mpp->dev_loss;
501 if (mpp->no_path_retry > 0) {
502 int no_path_retry_tmo = mpp->no_path_retry * conf->checkint;
504 if (no_path_retry_tmo > MAX_DEV_LOSS_TMO)
505 no_path_retry_tmo = MAX_DEV_LOSS_TMO;
506 if (no_path_retry_tmo > dev_loss_tmo)
507 dev_loss_tmo = no_path_retry_tmo;
508 condlog(3, "%s: update dev_loss_tmo to %d",
509 mpp->alias, dev_loss_tmo);
510 } else if (mpp->no_path_retry == NO_PATH_RETRY_QUEUE) {
511 dev_loss_tmo = MAX_DEV_LOSS_TMO;
512 condlog(3, "%s: update dev_loss_tmo to %d",
513 mpp->alias, dev_loss_tmo);
515 mpp->dev_loss = dev_loss_tmo;
516 if (mpp->dev_loss && mpp->fast_io_fail >= (int)mpp->dev_loss) {
517 condlog(3, "%s: turning off fast_io_fail (%d is not smaller than dev_loss_tmo)",
518 mpp->alias, mpp->fast_io_fail);
519 mpp->fast_io_fail = MP_FAST_IO_FAIL_OFF;
521 if (!mpp->dev_loss && mpp->fast_io_fail == MP_FAST_IO_FAIL_UNSET)
524 vector_foreach_slot(mpp->paths, pp, i) {
525 if (pp->sg_id.proto_id == SCSI_PROTOCOL_FCP)
526 sysfs_set_rport_tmo(mpp, pp);
527 if (pp->sg_id.proto_id == SCSI_PROTOCOL_ISCSI)
528 sysfs_set_session_tmo(mpp, pp);
529 if (pp->sg_id.proto_id == SCSI_PROTOCOL_SAS)
530 sysfs_set_nexus_loss_tmo(mpp, pp);
536 do_inq(int sg_fd, int cmddt, int evpd, unsigned int pg_op,
537 void *resp, int mx_resp_len)
539 unsigned char inqCmdBlk[INQUIRY_CMDLEN] =
540 { INQUIRY_CMD, 0, 0, 0, 0, 0 };
541 unsigned char sense_b[SENSE_BUFF_LEN];
542 struct sg_io_hdr io_hdr;
548 inqCmdBlk[2] = (unsigned char) pg_op;
549 inqCmdBlk[3] = (unsigned char)((mx_resp_len >> 8) & 0xff);
550 inqCmdBlk[4] = (unsigned char) (mx_resp_len & 0xff);
551 memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
552 memset(sense_b, 0, SENSE_BUFF_LEN);
553 io_hdr.interface_id = 'S';
554 io_hdr.cmd_len = sizeof (inqCmdBlk);
555 io_hdr.mx_sb_len = sizeof (sense_b);
556 io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
557 io_hdr.dxfer_len = mx_resp_len;
558 io_hdr.dxferp = resp;
559 io_hdr.cmdp = inqCmdBlk;
560 io_hdr.sbp = sense_b;
561 io_hdr.timeout = DEF_TIMEOUT;
563 if (ioctl(sg_fd, SG_IO, &io_hdr) < 0)
566 /* treat SG_ERR here to get rid of sg_err.[ch] */
567 io_hdr.status &= 0x7e;
568 if ((0 == io_hdr.status) && (0 == io_hdr.host_status) &&
569 (0 == io_hdr.driver_status))
571 if ((SCSI_CHECK_CONDITION == io_hdr.status) ||
572 (SCSI_COMMAND_TERMINATED == io_hdr.status) ||
573 (SG_ERR_DRIVER_SENSE == (0xf & io_hdr.driver_status))) {
574 if (io_hdr.sbp && (io_hdr.sb_len_wr > 2)) {
576 unsigned char * sense_buffer = io_hdr.sbp;
577 if (sense_buffer[0] & 0x2)
578 sense_key = sense_buffer[1] & 0xf;
580 sense_key = sense_buffer[2] & 0xf;
581 if(RECOVERED_ERROR == sense_key)
589 get_serial (char * str, int maxlen, int fd)
592 char buff[MX_ALLOC_LEN + 1] = {0};
597 if (0 == do_inq(fd, 0, 1, 0x80, buff, MX_ALLOC_LEN)) {
602 memcpy(str, buff + 4, len);
611 get_geometry(struct path *pp)
616 if (ioctl(pp->fd, HDIO_GETGEO, &pp->geom)) {
617 condlog(2, "%s: HDIO_GETGEO failed with %d", pp->dev, errno);
618 memset(&pp->geom, 0, sizeof(pp->geom));
621 condlog(3, "%s: %u cyl, %u heads, %u sectors/track, start at %lu",
622 pp->dev, pp->geom.cylinders, pp->geom.heads,
623 pp->geom.sectors, pp->geom.start);
628 scsi_sysfs_pathinfo (struct path * pp)
630 struct udev_device *parent;
631 const char *attr_path = NULL;
635 const char *subsys = udev_device_get_subsystem(parent);
636 if (subsys && !strncmp(subsys, "scsi", 4)) {
637 attr_path = udev_device_get_sysname(parent);
640 if (sscanf(attr_path, "%i:%i:%i:%i",
644 &pp->sg_id.lun) == 4)
647 parent = udev_device_get_parent(parent);
649 if (!attr_path || pp->sg_id.host_no == -1)
652 if (sysfs_get_vendor(parent, pp->vendor_id, SCSI_VENDOR_SIZE))
655 condlog(3, "%s: vendor = %s", pp->dev, pp->vendor_id);
657 if (sysfs_get_model(parent, pp->product_id, SCSI_PRODUCT_SIZE))
660 condlog(3, "%s: product = %s", pp->dev, pp->product_id);
662 if (sysfs_get_rev(parent, pp->rev, SCSI_REV_SIZE))
665 condlog(3, "%s: rev = %s", pp->dev, pp->rev);
668 * set the hwe configlet pointer
670 pp->hwe = find_hwe(conf->hwtable, pp->vendor_id, pp->product_id, pp->rev);
673 * host / bus / target / lun
675 condlog(3, "%s: h:b:t:l = %i:%i:%i:%i",
685 if(!sysfs_get_tgt_nodename(pp, pp->tgt_node_name)) {
686 condlog(3, "%s: tgt_node_name = %s",
687 pp->dev, pp->tgt_node_name);
694 ccw_sysfs_pathinfo (struct path * pp)
696 struct udev_device *parent;
697 char attr_buff[NAME_SIZE];
698 const char *attr_path;
702 const char *subsys = udev_device_get_subsystem(parent);
703 if (subsys && !strncmp(subsys, "ccw", 3))
705 parent = udev_device_get_parent(parent);
710 sprintf(pp->vendor_id, "IBM");
712 condlog(3, "%s: vendor = %s", pp->dev, pp->vendor_id);
714 if (sysfs_get_devtype(parent, attr_buff, FILE_NAME_SIZE))
717 if (!strncmp(attr_buff, "3370", 4)) {
718 sprintf(pp->product_id,"S/390 DASD FBA");
719 } else if (!strncmp(attr_buff, "9336", 4)) {
720 sprintf(pp->product_id,"S/390 DASD FBA");
722 sprintf(pp->product_id,"S/390 DASD ECKD");
725 condlog(3, "%s: product = %s", pp->dev, pp->product_id);
728 * set the hwe configlet pointer
730 pp->hwe = find_hwe(conf->hwtable, pp->vendor_id, pp->product_id, NULL);
733 * host / bus / target / lun
735 attr_path = udev_device_get_sysname(parent);
737 sscanf(attr_path, "%i.%i.%x",
741 condlog(3, "%s: h:b:t:l = %i:%i:%i:%i",
752 cciss_sysfs_pathinfo (struct path * pp)
754 const char * attr_path = NULL;
755 struct udev_device *parent;
759 const char *subsys = udev_device_get_subsystem(parent);
760 if (subsys && !strncmp(subsys, "cciss", 5)) {
761 attr_path = udev_device_get_sysname(parent);
764 if (sscanf(attr_path, "c%id%i",
766 &pp->sg_id.scsi_id) == 2)
769 parent = udev_device_get_parent(parent);
771 if (!attr_path || pp->sg_id.host_no == -1)
774 if (sysfs_get_vendor(parent, pp->vendor_id, SCSI_VENDOR_SIZE))
777 condlog(3, "%s: vendor = %s", pp->dev, pp->vendor_id);
779 if (sysfs_get_model(parent, pp->product_id, SCSI_PRODUCT_SIZE))
782 condlog(3, "%s: product = %s", pp->dev, pp->product_id);
784 if (sysfs_get_rev(parent, pp->rev, SCSI_REV_SIZE))
787 condlog(3, "%s: rev = %s", pp->dev, pp->rev);
790 * set the hwe configlet pointer
792 pp->hwe = find_hwe(conf->hwtable, pp->vendor_id, pp->product_id, pp->rev);
795 * host / bus / target / lun
798 pp->sg_id.channel = 0;
799 condlog(3, "%s: h:b:t:l = %i:%i:%i:%i",
809 common_sysfs_pathinfo (struct path * pp)
812 condlog(4, "%s: udev not initialised", pp->dev);
815 if (sysfs_get_dev(pp->udev, pp->dev_t, BLK_DEV_SIZE)) {
816 condlog(3, "%s: no 'dev' attribute in sysfs", pp->dev);
820 condlog(3, "%s: dev_t = %s", pp->dev, pp->dev_t);
822 if (sysfs_get_size(pp, &pp->size))
825 condlog(3, "%s: size = %llu", pp->dev, pp->size);
831 path_offline (struct path * pp)
833 struct udev_device * parent;
834 char buff[SCSI_STATE_SIZE];
836 if (pp->bus != SYSFS_BUS_SCSI)
841 const char *subsys = udev_device_get_subsystem(parent);
842 if (subsys && !strncmp(subsys, "scsi", 4))
844 parent = udev_device_get_parent(parent);
848 condlog(1, "%s: failed to get sysfs information", pp->dev);
852 memset(buff, 0x0, SCSI_STATE_SIZE);
853 if (sysfs_attr_get_value(parent, "state", buff, SCSI_STATE_SIZE) <= 0)
856 condlog(3, "%s: path state = %s", pp->dev, buff);
858 if (!strncmp(buff, "offline", 7) ||
859 !strncmp(buff, "quiesce", 7) ||
860 !strncmp(buff, "transport-offline", 17)) {
865 if (!strncmp(buff, "blocked", 7) || !strncmp(buff, "quiesce", 7))
867 else if (!strncmp(buff, "running", 7))
874 sysfs_pathinfo(struct path * pp)
876 if (common_sysfs_pathinfo(pp))
879 pp->bus = SYSFS_BUS_UNDEF;
880 if (!strncmp(pp->dev,"cciss",5))
881 pp->bus = SYSFS_BUS_CCISS;
882 if (!strncmp(pp->dev,"dasd", 4))
883 pp->bus = SYSFS_BUS_CCW;
884 if (!strncmp(pp->dev,"sd", 2))
885 pp->bus = SYSFS_BUS_SCSI;
887 if (pp->bus == SYSFS_BUS_UNDEF)
889 else if (pp->bus == SYSFS_BUS_SCSI) {
890 if (scsi_sysfs_pathinfo(pp))
892 } else if (pp->bus == SYSFS_BUS_CCW) {
893 if (ccw_sysfs_pathinfo(pp))
895 } else if (pp->bus == SYSFS_BUS_CCISS) {
896 if (cciss_sysfs_pathinfo(pp))
903 scsi_ioctl_pathinfo (struct path * pp, int mask)
905 if (mask & DI_SERIAL) {
906 get_serial(pp->serial, SERIAL_SIZE, pp->fd);
907 condlog(3, "%s: serial = %s", pp->dev, pp->serial);
914 cciss_ioctl_pathinfo (struct path * pp, int mask)
916 if (mask & DI_SERIAL) {
917 get_serial(pp->serial, SERIAL_SIZE, pp->fd);
918 condlog(3, "%s: serial = %s", pp->dev, pp->serial);
924 get_state (struct path * pp, int daemon)
926 struct checker * c = &pp->checker;
929 condlog(3, "%s: get_state", pp->dev);
931 if (!checker_selected(c)) {
933 if (pathinfo(pp, conf->hwtable, DI_SYSFS) != 0) {
934 condlog(3, "%s: couldn't get sysfs pathinfo",
936 return PATH_UNCHECKED;
940 if (!checker_selected(c)) {
941 condlog(3, "%s: No checker selected", pp->dev);
942 return PATH_UNCHECKED;
944 checker_set_fd(c, pp->fd);
945 if (checker_init(c, pp->mpp?&pp->mpp->mpcontext:NULL)) {
946 memset(c, 0x0, sizeof(struct checker));
947 condlog(3, "%s: checker init failed", pp->dev);
948 return PATH_UNCHECKED;
951 checker_clear_message(c);
953 checker_set_async(c);
954 if (!conf->checker_timeout &&
955 (pp->bus != SYSFS_BUS_SCSI ||
956 sysfs_get_timeout(pp, &(c->timeout))))
957 c->timeout = DEF_TIMEOUT;
958 state = checker_check(c);
959 condlog(3, "%s: state = %s", pp->dev, checker_state_name(state));
960 if (state != PATH_UP && state != PATH_GHOST &&
961 strlen(checker_message(c)))
962 condlog(3, "%s: checker msg is \"%s\"",
963 pp->dev, checker_message(c));
968 get_prio (struct path * pp)
973 struct prio * p = &pp->prio;
975 if (!prio_selected(p)) {
976 select_detect_prio(pp);
978 if (!prio_selected(p)) {
979 condlog(3, "%s: no prio selected", pp->dev);
980 pp->priority = PRIO_UNDEF;
984 pp->priority = prio_getprio(p, pp);
985 if (pp->priority < 0) {
986 condlog(3, "%s: %s prio error", pp->dev, prio_name(p));
987 pp->priority = PRIO_UNDEF;
990 condlog(3, "%s: %s prio = %u",
991 pp->dev, prio_name(p), pp->priority);
996 get_uid (struct path * pp)
1001 if (!pp->uid_attribute && !pp->getuid)
1005 condlog(1, "%s: no udev information", pp->dev);
1009 memset(pp->wwid, 0, WWID_SIZE);
1011 char buff[CALLOUT_MAX_SIZE];
1013 /* Use 'getuid' callout, deprecated */
1014 condlog(1, "%s: using deprecated getuid callout", pp->dev);
1015 if (apply_format(pp->getuid, &buff[0], pp)) {
1016 condlog(0, "error formatting uid callout command");
1017 memset(pp->wwid, 0, WWID_SIZE);
1018 } else if (execute_program(buff, pp->wwid, WWID_SIZE)) {
1019 condlog(3, "error calling out %s", buff);
1020 memset(pp->wwid, 0, WWID_SIZE);
1026 value = udev_device_get_property_value(pp->udev,
1028 if ((!value || strlen(value) == 0) && conf->dry_run == 2)
1029 value = getenv(pp->uid_attribute);
1030 if (value && strlen(value)) {
1031 size_t len = WWID_SIZE;
1033 if (strlen(value) + 1 > WWID_SIZE) {
1034 condlog(0, "%s: wwid overflow", pp->dev);
1036 len = strlen(value);
1038 strncpy(pp->wwid, value, len);
1040 condlog(3, "%s: no %s attribute", pp->dev,
1045 /* Strip any trailing blanks */
1046 c = strchr(pp->wwid, '\0');
1048 while (c && c >= pp->wwid && *c == ' ') {
1052 condlog(3, "%s: uid = %s (%s)", pp->dev,
1053 *pp->wwid == '\0' ? "<empty>" : pp->wwid, origin);
1058 pathinfo (struct path *pp, vector hwtable, int mask)
1062 condlog(3, "%s: mask = 0x%x", pp->dev, mask);
1065 * fetch info available in sysfs
1067 if (mask & DI_SYSFS && sysfs_pathinfo(pp))
1070 if (mask & DI_BLACKLIST && mask & DI_SYSFS) {
1071 if (filter_device(conf->blist_device, conf->elist_device,
1072 pp->vendor_id, pp->product_id) > 0) {
1077 path_state = path_offline(pp);
1080 * fetch info not available through sysfs
1083 pp->fd = open(udev_device_get_devnode(pp->udev), O_RDONLY);
1086 condlog(4, "Couldn't open node for %s: %s",
1087 pp->dev, strerror(errno));
1091 if (mask & DI_SERIAL)
1094 if (path_state == PATH_UP && pp->bus == SYSFS_BUS_SCSI &&
1095 scsi_ioctl_pathinfo(pp, mask))
1098 if (pp->bus == SYSFS_BUS_CCISS &&
1099 cciss_ioctl_pathinfo(pp, mask))
1102 if (mask & DI_CHECKER) {
1103 if (path_state == PATH_UP) {
1104 pp->chkrstate = pp->state = get_state(pp, 0);
1105 if (pp->state == PATH_UNCHECKED ||
1106 pp->state == PATH_WILD)
1108 if (pp->state == PATH_TIMEOUT)
1109 pp->state = PATH_DOWN;
1111 condlog(3, "%s: path inaccessible", pp->dev);
1112 pp->chkrstate = pp->state = path_state;
1116 if ((mask & DI_WWID) && !strlen(pp->wwid))
1118 if (mask & DI_BLACKLIST && mask & DI_WWID) {
1119 if (filter_wwid(conf->blist_wwid, conf->elist_wwid,
1126 * Retrieve path priority, even for PATH_DOWN paths if it has never
1127 * been successfully obtained before.
1129 if ((mask & DI_PRIO) && path_state == PATH_UP) {
1130 if (pp->state != PATH_DOWN || pp->priority == PRIO_UNDEF) {
1131 if (!strlen(pp->wwid))
1135 pp->priority = PRIO_UNDEF;
1143 * Recoverable error, for example faulty or offline path
1145 memset(pp->wwid, 0, WWID_SIZE);
1146 pp->chkrstate = pp->state = PATH_DOWN;