2 * Copyright (c) 2004, 2005, 2006 Christophe Varoqui
3 * Copyright (c) 2005 Stefan Bader, IBM
4 * Copyright (c) 2005 Mike Anderson
11 #include <sys/ioctl.h>
24 #include "blacklist.h"
28 #include "sg_include.h"
30 #include "discovery.h"
33 #include "unaligned.h"
34 #include "prioritizers/alua_rtpg.h"
38 alloc_path_with_pathinfo (struct config *conf, struct udev_device *udevice,
39 const char *wwid, int flag, struct path **pp_ptr)
41 int err = PATHINFO_FAILED;
48 devname = udev_device_get_sysname(udevice);
50 return PATHINFO_FAILED;
55 return PATHINFO_FAILED;
58 strlcpy(pp->wwid, wwid, sizeof(pp->wwid));
60 if (safe_sprintf(pp->dev, "%s", devname)) {
61 condlog(0, "pp->dev too small");
63 pp->udev = udev_device_ref(udevice);
64 err = pathinfo(pp, conf, flag | DI_BLACKLIST);
75 store_pathinfo (vector pathvec, struct config *conf,
76 struct udev_device *udevice, int flag, struct path **pp_ptr)
78 int err = PATHINFO_FAILED;
85 devname = udev_device_get_sysname(udevice);
87 return PATHINFO_FAILED;
92 return PATHINFO_FAILED;
94 if(safe_sprintf(pp->dev, "%s", devname)) {
95 condlog(0, "pp->dev too small");
98 pp->udev = udev_device_ref(udevice);
99 err = pathinfo(pp, conf, flag);
103 err = store_path(pathvec, pp);
116 path_discover (vector pathvec, struct config * conf,
117 struct udev_device *udevice, int flag)
120 const char * devname;
122 devname = udev_device_get_sysname(udevice);
124 return PATHINFO_FAILED;
126 pp = find_path_by_dev(pathvec, devname);
128 char devt[BLK_DEV_SIZE];
129 dev_t devnum = udev_device_get_devnum(udevice);
131 snprintf(devt, BLK_DEV_SIZE, "%d:%d",
132 major(devnum), minor(devnum));
133 pp = find_path_by_devt(pathvec, devt);
135 return store_pathinfo(pathvec, conf,
136 udevice, flag, NULL);
138 return pathinfo(pp, conf, flag);
142 path_discovery (vector pathvec, int flag)
144 struct udev_enumerate *udev_iter;
145 struct udev_list_entry *entry;
146 struct udev_device *udevice;
149 int num_paths = 0, total_paths = 0;
151 udev_iter = udev_enumerate_new(udev);
155 udev_enumerate_add_match_subsystem(udev_iter, "block");
156 udev_enumerate_add_match_is_initialized(udev_iter);
157 udev_enumerate_scan_devices(udev_iter);
159 udev_list_entry_foreach(entry,
160 udev_enumerate_get_list_entry(udev_iter)) {
162 devpath = udev_list_entry_get_name(entry);
163 condlog(4, "Discover device %s", devpath);
164 udevice = udev_device_new_from_syspath(udev, devpath);
166 condlog(4, "%s: no udev information", devpath);
169 devtype = udev_device_get_devtype(udevice);
170 if(devtype && !strncmp(devtype, "disk", 4)) {
172 conf = get_multipath_config();
173 pthread_cleanup_push(put_multipath_config, conf);
174 if (path_discover(pathvec, conf,
175 udevice, flag) == PATHINFO_OK)
177 pthread_cleanup_pop(1);
179 udev_device_unref(udevice);
181 udev_enumerate_unref(udev_iter);
182 condlog(4, "Discovered %d/%d paths", num_paths, total_paths);
183 return (total_paths - num_paths);
186 #define declare_sysfs_get_str(fname) \
188 sysfs_get_##fname (struct udev_device * udev, char * buff, size_t len) \
192 const char * devname; \
197 devname = udev_device_get_sysname(udev); \
199 attr = udev_device_get_sysattr_value(udev, #fname); \
201 condlog(3, "%s: attribute %s not found in sysfs", \
205 for (l = strlen(attr); l >= 1 && isspace(attr[l-1]); l--); \
207 condlog(3, "%s: overflow in attribute %s", \
211 strlcpy(buff, attr, len); \
212 return strchop(buff); \
215 declare_sysfs_get_str(devtype);
216 declare_sysfs_get_str(vendor);
217 declare_sysfs_get_str(model);
218 declare_sysfs_get_str(rev);
221 sysfs_get_vpd (struct udev_device * udev, int pg,
222 unsigned char * buff, size_t len)
226 const char * devname;
229 condlog(3, "No udev device given\n");
233 devname = udev_device_get_sysname(udev);
234 sprintf(attrname, "vpd_pg%02x", pg);
235 attr_len = sysfs_bin_attr_get_value(udev, attrname, buff, len);
237 condlog(3, "%s: attribute %s not found in sysfs",
245 sysfs_get_timeout(struct path *pp, unsigned int *timeout)
247 const char *attr = NULL;
249 struct udev_device *parent;
253 if (!pp->udev || pp->bus != SYSFS_BUS_SCSI)
258 subsys = udev_device_get_subsystem(parent);
259 attr = udev_device_get_sysattr_value(parent, "timeout");
262 parent = udev_device_get_parent(parent);
265 condlog(3, "%s: No timeout value in sysfs", pp->dev);
269 t = strtoul(attr, &eptr, 0);
270 if (attr == eptr || t == ULONG_MAX) {
271 condlog(3, "%s: Cannot parse timeout attribute '%s'",
276 condlog(3, "%s: Overflow in timeout value '%s'",
286 sysfs_get_tgt_nodename (struct path *pp, char * node)
288 const char *tgtname, *value;
289 struct udev_device *parent, *tgtdev;
290 int host, channel, tgtid = -1;
292 parent = udev_device_get_parent_with_subsystem_devtype(pp->udev, "scsi", "scsi_device");
296 value = udev_device_get_sysattr_value(parent, "sas_address");
298 tgtdev = udev_device_get_parent(parent);
300 tgtname = udev_device_get_sysname(tgtdev);
301 if (sscanf(tgtname, "end_device-%d:%d",
304 tgtdev = udev_device_get_parent(tgtdev);
308 pp->sg_id.proto_id = SCSI_PROTOCOL_SAS;
309 pp->sg_id.transport_id = tgtid;
310 strncpy(node, value, NODE_NAME_SIZE);
316 tgtdev = udev_device_get_parent(parent);
318 value = udev_device_get_subsystem(tgtdev);
319 if (value && !strcmp(value, "usb")) {
320 pp->sg_id.proto_id = SCSI_PROTOCOL_UNSPEC;
321 tgtname = udev_device_get_sysname(tgtdev);
322 strncpy(node, tgtname, strlen(tgtname));
323 condlog(3, "%s: skip USB device %s", pp->dev, node);
326 tgtdev = udev_device_get_parent(tgtdev);
328 parent = udev_device_get_parent_with_subsystem_devtype(pp->udev, "scsi", "scsi_target");
331 /* Check for FibreChannel */
332 tgtdev = udev_device_get_parent(parent);
333 value = udev_device_get_sysname(tgtdev);
334 if (sscanf(value, "rport-%d:%d-%d",
335 &host, &channel, &tgtid) == 3) {
336 tgtdev = udev_device_new_from_subsystem_sysname(udev,
337 "fc_remote_ports", value);
339 condlog(3, "SCSI target %d:%d:%d -> "
341 pp->sg_id.host_no, pp->sg_id.channel,
342 pp->sg_id.scsi_id, host, channel,
344 value = udev_device_get_sysattr_value(tgtdev,
347 pp->sg_id.proto_id = SCSI_PROTOCOL_FCP;
348 pp->sg_id.transport_id = tgtid;
349 strncpy(node, value, NODE_NAME_SIZE);
350 udev_device_unref(tgtdev);
353 udev_device_unref(tgtdev);
357 /* Check for iSCSI */
361 tgtname = udev_device_get_sysname(parent);
362 if (tgtname && sscanf(tgtname , "session%d", &tgtid) == 1)
364 parent = udev_device_get_parent(parent);
368 if (parent && tgtname) {
369 tgtdev = udev_device_new_from_subsystem_sysname(udev,
370 "iscsi_session", tgtname);
374 value = udev_device_get_sysattr_value(tgtdev, "targetname");
376 pp->sg_id.proto_id = SCSI_PROTOCOL_ISCSI;
377 pp->sg_id.transport_id = tgtid;
378 strncpy(node, value, NODE_NAME_SIZE);
379 udev_device_unref(tgtdev);
383 udev_device_unref(tgtdev);
386 /* Check for libata */
390 tgtname = udev_device_get_sysname(parent);
391 if (tgtname && sscanf(tgtname, "ata%d", &tgtid) == 1)
393 parent = udev_device_get_parent(parent);
397 pp->sg_id.proto_id = SCSI_PROTOCOL_ATA;
398 pp->sg_id.transport_id = tgtid;
399 snprintf(node, NODE_NAME_SIZE, "ata-%d.00", tgtid);
402 /* Unknown SCSI transport. Keep fingers crossed */
403 pp->sg_id.proto_id = SCSI_PROTOCOL_UNSPEC;
407 int sysfs_get_host_adapter_name(const struct path *pp, char *adapter_name)
411 if (!pp || !adapter_name)
414 proto_id = pp->sg_id.proto_id;
416 if (proto_id != SCSI_PROTOCOL_FCP &&
417 proto_id != SCSI_PROTOCOL_SAS &&
418 proto_id != SCSI_PROTOCOL_ISCSI &&
419 proto_id != SCSI_PROTOCOL_SRP) {
422 /* iscsi doesn't have adapter info in sysfs
423 * get ip_address for grouping paths
425 if (pp->sg_id.proto_id == SCSI_PROTOCOL_ISCSI)
426 return sysfs_get_iscsi_ip_address(pp, adapter_name);
428 /* fetch adapter pci name for other protocols
430 return sysfs_get_host_pci_name(pp, adapter_name);
433 int sysfs_get_host_pci_name(const struct path *pp, char *pci_name)
435 struct udev_device *hostdev, *parent;
436 char host_name[HOST_NAME_LEN];
437 const char *driver_name, *value;
439 if (!pp || !pci_name)
442 sprintf(host_name, "host%d", pp->sg_id.host_no);
443 hostdev = udev_device_new_from_subsystem_sysname(udev,
444 "scsi_host", host_name);
448 parent = udev_device_get_parent(hostdev);
450 driver_name = udev_device_get_driver(parent);
452 parent = udev_device_get_parent(parent);
455 if (!strcmp(driver_name, "pcieport"))
457 parent = udev_device_get_parent(parent);
462 value = udev_device_get_sysname(parent);
464 strncpy(pci_name, value, SLOT_NAME_SIZE);
465 udev_device_unref(hostdev);
468 udev_device_unref(hostdev);
472 int sysfs_get_iscsi_ip_address(const struct path *pp, char *ip_address)
474 struct udev_device *hostdev;
475 char host_name[HOST_NAME_LEN];
478 sprintf(host_name, "host%d", pp->sg_id.host_no);
479 hostdev = udev_device_new_from_subsystem_sysname(udev,
480 "iscsi_host", host_name);
482 value = udev_device_get_sysattr_value(hostdev,
485 strncpy(ip_address, value, SLOT_NAME_SIZE);
486 udev_device_unref(hostdev);
489 udev_device_unref(hostdev);
495 sysfs_get_asymmetric_access_state(struct path *pp, char *buff, int buflen)
497 struct udev_device *parent = pp->udev;
498 char value[16], *eptr;
499 unsigned long preferred;
502 const char *subsys = udev_device_get_subsystem(parent);
503 if (subsys && !strncmp(subsys, "scsi", 4))
505 parent = udev_device_get_parent(parent);
511 if (sysfs_attr_get_value(parent, "access_state", buff, buflen) <= 0)
514 if (sysfs_attr_get_value(parent, "preferred_path", value, 16) <= 0)
517 preferred = strtoul(value, &eptr, 0);
518 if (value == eptr || preferred == ULONG_MAX) {
519 /* Parse error, ignore */
526 sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp)
528 struct udev_device *rport_dev = NULL;
529 char value[16], *eptr;
531 unsigned long long tmo = 0;
534 sprintf(rport_id, "rport-%d:%d-%d",
535 pp->sg_id.host_no, pp->sg_id.channel, pp->sg_id.transport_id);
536 rport_dev = udev_device_new_from_subsystem_sysname(udev,
537 "fc_remote_ports", rport_id);
539 condlog(1, "%s: No fc_remote_port device for '%s'", pp->dev,
543 condlog(4, "target%d:%d:%d -> %s", pp->sg_id.host_no,
544 pp->sg_id.channel, pp->sg_id.scsi_id, rport_id);
547 * read the current dev_loss_tmo value from sysfs
549 ret = sysfs_attr_get_value(rport_dev, "dev_loss_tmo", value, 16);
551 condlog(0, "%s: failed to read dev_loss_tmo value, "
552 "error %d", rport_id, -ret);
555 tmo = strtoull(value, &eptr, 0);
556 if (value == eptr || tmo == ULLONG_MAX) {
557 condlog(0, "%s: Cannot parse dev_loss_tmo "
558 "attribute '%s'", rport_id, value);
564 * dev_loss_tmo will be limited to 600 if fast_io_fail
566 * fast_io_fail will be limited by the current dev_loss_tmo
568 * So to get everything right we first need to increase
569 * dev_loss_tmo to the fast_io_fail setting (if present),
570 * then set fast_io_fail, and _then_ set dev_loss_tmo
571 * to the correct value.
573 if (mpp->fast_io_fail != MP_FAST_IO_FAIL_UNSET &&
574 mpp->fast_io_fail != MP_FAST_IO_FAIL_ZERO &&
575 mpp->fast_io_fail != MP_FAST_IO_FAIL_OFF) {
576 /* Check if we need to temporarily increase dev_loss_tmo */
577 if (mpp->fast_io_fail >= tmo) {
578 /* Increase dev_loss_tmo temporarily */
579 snprintf(value, 16, "%u", mpp->fast_io_fail + 1);
580 ret = sysfs_attr_set_value(rport_dev, "dev_loss_tmo",
581 value, strlen(value));
584 condlog(3, "%s: rport blocked",
587 condlog(0, "%s: failed to set "
588 "dev_loss_tmo to %s, error %d",
589 rport_id, value, -ret);
593 } else if (mpp->dev_loss > DEFAULT_DEV_LOSS_TMO &&
594 mpp->no_path_retry != NO_PATH_RETRY_QUEUE) {
595 condlog(3, "%s: limiting dev_loss_tmo to %d, since "
596 "fast_io_fail is not set",
597 rport_id, DEFAULT_DEV_LOSS_TMO);
598 mpp->dev_loss = DEFAULT_DEV_LOSS_TMO;
600 if (mpp->fast_io_fail != MP_FAST_IO_FAIL_UNSET) {
601 if (mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF)
602 sprintf(value, "off");
603 else if (mpp->fast_io_fail == MP_FAST_IO_FAIL_ZERO)
606 snprintf(value, 16, "%u", mpp->fast_io_fail);
607 ret = sysfs_attr_set_value(rport_dev, "fast_io_fail_tmo",
608 value, strlen(value));
611 condlog(3, "%s: rport blocked", rport_id);
613 condlog(0, "%s: failed to set fast_io_fail_tmo to %s, error %d",
614 rport_id, value, -ret);
617 if (mpp->dev_loss > 0) {
618 snprintf(value, 16, "%u", mpp->dev_loss);
619 ret = sysfs_attr_set_value(rport_dev, "dev_loss_tmo",
620 value, strlen(value));
623 condlog(3, "%s: rport blocked", rport_id);
625 condlog(0, "%s: failed to set dev_loss_tmo to %s, error %d",
626 rport_id, value, -ret);
630 udev_device_unref(rport_dev);
634 sysfs_set_session_tmo(struct multipath *mpp, struct path *pp)
636 struct udev_device *session_dev = NULL;
640 sprintf(session_id, "session%d", pp->sg_id.transport_id);
641 session_dev = udev_device_new_from_subsystem_sysname(udev,
642 "iscsi_session", session_id);
644 condlog(1, "%s: No iscsi session for '%s'", pp->dev,
648 condlog(4, "target%d:%d:%d -> %s", pp->sg_id.host_no,
649 pp->sg_id.channel, pp->sg_id.scsi_id, session_id);
652 condlog(3, "%s: ignoring dev_loss_tmo on iSCSI", pp->dev);
654 if (mpp->fast_io_fail != MP_FAST_IO_FAIL_UNSET) {
655 if (mpp->fast_io_fail == MP_FAST_IO_FAIL_OFF) {
656 condlog(3, "%s: can't switch off fast_io_fail_tmo "
657 "on iSCSI", pp->dev);
658 } else if (mpp->fast_io_fail == MP_FAST_IO_FAIL_ZERO) {
659 condlog(3, "%s: can't set fast_io_fail_tmo to '0'"
660 "on iSCSI", pp->dev);
662 snprintf(value, 11, "%u", mpp->fast_io_fail);
663 if (sysfs_attr_set_value(session_dev, "recovery_tmo",
665 condlog(3, "%s: Failed to set recovery_tmo, "
666 " error %d", pp->dev, errno);
670 udev_device_unref(session_dev);
675 sysfs_set_nexus_loss_tmo(struct multipath *mpp, struct path *pp)
677 struct udev_device *sas_dev = NULL;
681 sprintf(end_dev_id, "end_device-%d:%d",
682 pp->sg_id.host_no, pp->sg_id.transport_id);
683 sas_dev = udev_device_new_from_subsystem_sysname(udev,
684 "sas_end_device", end_dev_id);
686 condlog(1, "%s: No SAS end device for '%s'", pp->dev,
690 condlog(4, "target%d:%d:%d -> %s", pp->sg_id.host_no,
691 pp->sg_id.channel, pp->sg_id.scsi_id, end_dev_id);
694 snprintf(value, 11, "%u", mpp->dev_loss);
695 if (sysfs_attr_set_value(sas_dev, "I_T_nexus_loss_timeout",
697 condlog(3, "%s: failed to update "
698 "I_T Nexus loss timeout, error %d",
701 udev_device_unref(sas_dev);
706 sysfs_set_scsi_tmo (struct multipath *mpp, int checkint)
710 int dev_loss_tmo = mpp->dev_loss;
712 if (mpp->no_path_retry > 0) {
713 uint64_t no_path_retry_tmo = mpp->no_path_retry * checkint;
715 if (no_path_retry_tmo > MAX_DEV_LOSS_TMO)
716 no_path_retry_tmo = MAX_DEV_LOSS_TMO;
717 if (no_path_retry_tmo > dev_loss_tmo)
718 dev_loss_tmo = no_path_retry_tmo;
719 condlog(3, "%s: update dev_loss_tmo to %u",
720 mpp->alias, dev_loss_tmo);
721 } else if (mpp->no_path_retry == NO_PATH_RETRY_QUEUE) {
722 dev_loss_tmo = MAX_DEV_LOSS_TMO;
723 condlog(3, "%s: update dev_loss_tmo to %u",
724 mpp->alias, dev_loss_tmo);
726 mpp->dev_loss = dev_loss_tmo;
727 if (mpp->dev_loss && mpp->fast_io_fail >= (int)mpp->dev_loss) {
728 condlog(3, "%s: turning off fast_io_fail (%d is not smaller than dev_loss_tmo)",
729 mpp->alias, mpp->fast_io_fail);
730 mpp->fast_io_fail = MP_FAST_IO_FAIL_OFF;
732 if (!mpp->dev_loss && mpp->fast_io_fail == MP_FAST_IO_FAIL_UNSET)
735 vector_foreach_slot(mpp->paths, pp, i) {
736 if (pp->sg_id.proto_id == SCSI_PROTOCOL_FCP)
737 sysfs_set_rport_tmo(mpp, pp);
738 if (pp->sg_id.proto_id == SCSI_PROTOCOL_ISCSI)
739 sysfs_set_session_tmo(mpp, pp);
740 if (pp->sg_id.proto_id == SCSI_PROTOCOL_SAS)
741 sysfs_set_nexus_loss_tmo(mpp, pp);
747 do_inq(int sg_fd, int cmddt, int evpd, unsigned int pg_op,
748 void *resp, int mx_resp_len)
750 unsigned char inqCmdBlk[INQUIRY_CMDLEN] =
751 { INQUIRY_CMD, 0, 0, 0, 0, 0 };
752 unsigned char sense_b[SENSE_BUFF_LEN];
753 struct sg_io_hdr io_hdr;
759 inqCmdBlk[2] = (unsigned char) pg_op;
760 inqCmdBlk[3] = (unsigned char)((mx_resp_len >> 8) & 0xff);
761 inqCmdBlk[4] = (unsigned char) (mx_resp_len & 0xff);
762 memset(&io_hdr, 0, sizeof (struct sg_io_hdr));
763 memset(sense_b, 0, SENSE_BUFF_LEN);
764 io_hdr.interface_id = 'S';
765 io_hdr.cmd_len = sizeof (inqCmdBlk);
766 io_hdr.mx_sb_len = sizeof (sense_b);
767 io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
768 io_hdr.dxfer_len = mx_resp_len;
769 io_hdr.dxferp = resp;
770 io_hdr.cmdp = inqCmdBlk;
771 io_hdr.sbp = sense_b;
772 io_hdr.timeout = DEF_TIMEOUT * 1000;
774 if (ioctl(sg_fd, SG_IO, &io_hdr) < 0)
777 /* treat SG_ERR here to get rid of sg_err.[ch] */
778 io_hdr.status &= 0x7e;
779 if ((0 == io_hdr.status) && (0 == io_hdr.host_status) &&
780 (0 == io_hdr.driver_status))
782 if ((SCSI_CHECK_CONDITION == io_hdr.status) ||
783 (SCSI_COMMAND_TERMINATED == io_hdr.status) ||
784 (SG_ERR_DRIVER_SENSE == (0xf & io_hdr.driver_status))) {
785 if (io_hdr.sbp && (io_hdr.sb_len_wr > 2)) {
787 unsigned char * sense_buffer = io_hdr.sbp;
788 if (sense_buffer[0] & 0x2)
789 sense_key = sense_buffer[1] & 0xf;
791 sense_key = sense_buffer[2] & 0xf;
792 if(RECOVERED_ERROR == sense_key)
800 get_serial (char * str, int maxlen, int fd)
803 char buff[MX_ALLOC_LEN + 1] = {0};
808 if (0 == do_inq(fd, 0, 1, 0x80, buff, MX_ALLOC_LEN)) {
813 memcpy(str, buff + 4, len);
822 detect_alua(struct path * pp, struct config *conf)
826 unsigned int timeout = conf->checker_timeout;
828 if ((tpgs = get_target_port_group_support(pp->fd, timeout)) <= 0) {
829 pp->tpgs = TPGS_NONE;
832 ret = get_target_port_group(pp, timeout);
833 if (ret < 0 || get_asymmetric_access_state(pp->fd, ret, timeout) < 0) {
834 pp->tpgs = TPGS_NONE;
840 #define DEFAULT_SGIO_LEN 254
842 /* Query VPD page @pg. Returns number of INQUIRY bytes
843 upon success and -1 upon failure. */
845 sgio_get_vpd (unsigned char * buff, int maxlen, int fd, int pg)
847 int len = DEFAULT_SGIO_LEN;
854 if (0 == do_inq(fd, 0, 1, pg, buff, len)) {
855 len = get_unaligned_be16(&buff[2]) + 4;
858 if (len > DEFAULT_SGIO_LEN)
866 get_geometry(struct path *pp)
871 if (ioctl(pp->fd, HDIO_GETGEO, &pp->geom)) {
872 condlog(2, "%s: HDIO_GETGEO failed with %d", pp->dev, errno);
873 memset(&pp->geom, 0, sizeof(pp->geom));
876 condlog(3, "%s: %u cyl, %u heads, %u sectors/track, start at %lu",
877 pp->dev, pp->geom.cylinders, pp->geom.heads,
878 pp->geom.sectors, pp->geom.start);
883 parse_vpd_pg80(const unsigned char *in, char *out, size_t out_len)
886 int len = get_unaligned_be16(&in[2]);
888 if (len >= out_len) {
889 condlog(2, "vpd pg80 overflow, %d/%d bytes required",
894 memcpy(out, in + 4, len);
898 * Strip trailing whitspaces
901 while (p > out && *p == ' ') {
910 parse_vpd_pg83(const unsigned char *in, size_t in_len,
911 char *out, size_t out_len)
913 const unsigned char *d;
914 const unsigned char *vpd = NULL;
915 int len = -ENODATA, vpd_type, vpd_len, prio = -1, i, naa_prio;
918 while (d < in + in_len) {
919 /* Select 'association: LUN' */
920 if ((d[1] & 0x30) != 0) {
924 switch (d[1] & 0xf) {
929 /* IEEE Registered Extended: Prio 8 */
933 /* IEEE Registered: Prio 7 */
937 /* IEEE Extended: Prio 6 */
941 /* IEEE Locally assigned: Prio 1 */
945 /* Default: no priority */
949 if (prio < naa_prio) {
955 /* SCSI Name: Prio 4 */
956 if (memcmp(d + 4, "eui.", 4) &&
957 memcmp(d + 4, "naa.", 4) &&
958 memcmp(d + 4, "iqn.", 4))
973 /* T-10 Vendor ID: Prio 2 */
983 vpd_type = vpd[1] & 0xf;
986 if (vpd_type == 0x2 || vpd_type == 0x3) {
989 len = sprintf(out, "%d", vpd_type);
990 for (i = 0; i < vpd_len; i++) {
991 len += sprintf(out + len,
996 } else if (vpd_type == 0x8) {
997 if (!memcmp("eui.", vpd, 4)) {
1002 for (i = 0; i < vpd_len; i++) {
1003 len += sprintf(out + len, "%c",
1010 } else if (!memcmp("naa.", vpd, 4)) {
1015 for (i = 0; i < vpd_len; i++) {
1016 len += sprintf(out + len, "%c",
1028 if (vpd_len > out_len + 2)
1029 vpd_len = out_len - 2;
1030 memcpy(out, vpd, vpd_len);
1034 } else if (vpd_type == 0x1) {
1035 const unsigned char *p;
1041 while ((p = memchr(vpd, ' ', vpd_len))) {
1043 if (len + p_len > out_len - 1)
1044 p_len = out_len - len - 2;
1045 memcpy(out + len, vpd, p_len);
1047 if (len >= out_len - 1) {
1055 while (vpd && *vpd == ' ') {
1060 if (len > 1 && out[len - 1] == '_') {
1061 out[len - 1] = '\0';
1070 get_vpd_sysfs (struct udev_device *parent, int pg, char * str, int maxlen)
1073 unsigned char buff[4096];
1075 memset(buff, 0x0, 4096);
1076 if (!parent || sysfs_get_vpd(parent, pg, buff, 4096) <= 0) {
1077 condlog(3, "failed to read sysfs vpd pg%02x", pg);
1081 if (buff[1] != pg) {
1082 condlog(3, "vpd pg%02x error, invalid vpd page %02x",
1086 buff_len = get_unaligned_be16(&buff[2]) + 4;
1087 if (buff_len > 4096)
1088 condlog(3, "vpd pg%02x page truncated", pg);
1091 len = parse_vpd_pg80(buff, str, maxlen);
1092 else if (pg == 0x83)
1093 len = parse_vpd_pg83(buff, buff_len, str, maxlen);
1101 get_vpd_sgio (int fd, int pg, char * str, int maxlen)
1104 unsigned char buff[4096];
1106 memset(buff, 0x0, 4096);
1107 if (sgio_get_vpd(buff, 4096, fd, pg) < 0) {
1108 condlog(3, "failed to issue vpd inquiry for pg%02x",
1113 if (buff[1] != pg) {
1114 condlog(3, "vpd pg%02x error, invalid vpd page %02x",
1118 buff_len = get_unaligned_be16(&buff[2]) + 4;
1119 if (buff_len > 4096) {
1120 condlog(3, "vpd pg%02x page truncated", pg);
1124 len = parse_vpd_pg80(buff, str, maxlen);
1125 else if (pg == 0x83)
1126 len = parse_vpd_pg83(buff, buff_len, str, maxlen);
1127 else if (pg == 0xc9 && maxlen >= 8) {
1131 len = (buff_len <= maxlen)? buff_len : maxlen;
1132 memcpy (str, buff, len);
1141 scsi_sysfs_pathinfo (struct path * pp, vector hwtable)
1143 struct udev_device *parent;
1144 const char *attr_path = NULL;
1148 const char *subsys = udev_device_get_subsystem(parent);
1149 if (subsys && !strncmp(subsys, "scsi", 4)) {
1150 attr_path = udev_device_get_sysname(parent);
1153 if (sscanf(attr_path, "%i:%i:%i:%i",
1157 &pp->sg_id.lun) == 4)
1160 parent = udev_device_get_parent(parent);
1162 if (!attr_path || pp->sg_id.host_no == -1)
1163 return PATHINFO_FAILED;
1165 if (sysfs_get_vendor(parent, pp->vendor_id, SCSI_VENDOR_SIZE) <= 0)
1166 return PATHINFO_FAILED;;
1168 condlog(3, "%s: vendor = %s", pp->dev, pp->vendor_id);
1170 if (sysfs_get_model(parent, pp->product_id, PATH_PRODUCT_SIZE) <= 0)
1171 return PATHINFO_FAILED;;
1173 condlog(3, "%s: product = %s", pp->dev, pp->product_id);
1175 if (sysfs_get_rev(parent, pp->rev, PATH_REV_SIZE) < 0)
1176 return PATHINFO_FAILED;;
1178 condlog(3, "%s: rev = %s", pp->dev, pp->rev);
1181 * set the hwe configlet pointer
1183 find_hwe(hwtable, pp->vendor_id, pp->product_id, pp->rev, pp->hwe);
1186 * host / bus / target / lun
1188 condlog(3, "%s: h:b:t:l = %i:%i:%i:%i",
1198 if(sysfs_get_tgt_nodename(pp, pp->tgt_node_name))
1199 return PATHINFO_FAILED;
1201 condlog(3, "%s: tgt_node_name = %s",
1202 pp->dev, pp->tgt_node_name);
1208 nvme_sysfs_pathinfo (struct path * pp, vector hwtable)
1210 struct udev_device *parent;
1211 const char *attr_path = NULL;
1214 attr_path = udev_device_get_sysname(pp->udev);
1216 return PATHINFO_FAILED;
1218 if (sscanf(attr_path, "nvme%dn%d",
1220 &pp->sg_id.scsi_id) != 2)
1221 return PATHINFO_FAILED;
1223 parent = udev_device_get_parent_with_subsystem_devtype(pp->udev,
1226 return PATHINFO_SKIPPED;
1228 attr = udev_device_get_sysattr_value(pp->udev, "nsid");
1229 pp->sg_id.lun = attr ? atoi(attr) : 0;
1231 attr = udev_device_get_sysattr_value(parent, "cntlid");
1232 pp->sg_id.channel = attr ? atoi(attr) : 0;
1234 snprintf(pp->vendor_id, SCSI_VENDOR_SIZE, "NVME");
1235 snprintf(pp->product_id, PATH_PRODUCT_SIZE, "%s",
1236 udev_device_get_sysattr_value(parent, "model"));
1237 snprintf(pp->serial, SERIAL_SIZE, "%s",
1238 udev_device_get_sysattr_value(parent, "serial"));
1239 snprintf(pp->rev, PATH_REV_SIZE, "%s",
1240 udev_device_get_sysattr_value(parent, "firmware_rev"));
1242 condlog(3, "%s: vendor = %s", pp->dev, pp->vendor_id);
1243 condlog(3, "%s: product = %s", pp->dev, pp->product_id);
1244 condlog(3, "%s: serial = %s", pp->dev, pp->serial);
1245 condlog(3, "%s: rev = %s", pp->dev, pp->rev);
1247 find_hwe(hwtable, pp->vendor_id, pp->product_id, NULL, pp->hwe);
1253 ccw_sysfs_pathinfo (struct path * pp, vector hwtable)
1255 struct udev_device *parent;
1256 char attr_buff[NAME_SIZE];
1257 const char *attr_path;
1261 const char *subsys = udev_device_get_subsystem(parent);
1262 if (subsys && !strncmp(subsys, "ccw", 3))
1264 parent = udev_device_get_parent(parent);
1267 return PATHINFO_FAILED;
1269 sprintf(pp->vendor_id, "IBM");
1271 condlog(3, "%s: vendor = %s", pp->dev, pp->vendor_id);
1273 if (sysfs_get_devtype(parent, attr_buff, FILE_NAME_SIZE) <= 0)
1274 return PATHINFO_FAILED;
1276 if (!strncmp(attr_buff, "3370", 4)) {
1277 sprintf(pp->product_id,"S/390 DASD FBA");
1278 } else if (!strncmp(attr_buff, "9336", 4)) {
1279 sprintf(pp->product_id,"S/390 DASD FBA");
1281 sprintf(pp->product_id,"S/390 DASD ECKD");
1284 condlog(3, "%s: product = %s", pp->dev, pp->product_id);
1287 * set the hwe configlet pointer
1289 find_hwe(hwtable, pp->vendor_id, pp->product_id, NULL, pp->hwe);
1292 * host / bus / target / lun
1294 attr_path = udev_device_get_sysname(parent);
1296 if (sscanf(attr_path, "%i.%i.%x",
1299 &pp->sg_id.scsi_id) == 3) {
1300 condlog(3, "%s: h:b:t:l = %i:%i:%i:%i",
1312 cciss_sysfs_pathinfo (struct path * pp, vector hwtable)
1314 const char * attr_path = NULL;
1315 struct udev_device *parent;
1319 const char *subsys = udev_device_get_subsystem(parent);
1320 if (subsys && !strncmp(subsys, "cciss", 5)) {
1321 attr_path = udev_device_get_sysname(parent);
1324 if (sscanf(attr_path, "c%id%i",
1326 &pp->sg_id.scsi_id) == 2)
1329 parent = udev_device_get_parent(parent);
1331 if (!attr_path || pp->sg_id.host_no == -1)
1332 return PATHINFO_FAILED;
1334 if (sysfs_get_vendor(parent, pp->vendor_id, SCSI_VENDOR_SIZE) <= 0)
1335 return PATHINFO_FAILED;
1337 condlog(3, "%s: vendor = %s", pp->dev, pp->vendor_id);
1339 if (sysfs_get_model(parent, pp->product_id, PATH_PRODUCT_SIZE) <= 0)
1340 return PATHINFO_FAILED;
1342 condlog(3, "%s: product = %s", pp->dev, pp->product_id);
1344 if (sysfs_get_rev(parent, pp->rev, PATH_REV_SIZE) <= 0)
1345 return PATHINFO_FAILED;
1347 condlog(3, "%s: rev = %s", pp->dev, pp->rev);
1350 * set the hwe configlet pointer
1352 find_hwe(hwtable, pp->vendor_id, pp->product_id, pp->rev, pp->hwe);
1355 * host / bus / target / lun
1358 pp->sg_id.channel = 0;
1359 condlog(3, "%s: h:b:t:l = %i:%i:%i:%i",
1370 common_sysfs_pathinfo (struct path * pp)
1375 return PATHINFO_FAILED;
1378 condlog(4, "%s: udev not initialised", pp->dev);
1379 return PATHINFO_FAILED;
1381 devt = udev_device_get_devnum(pp->udev);
1382 snprintf(pp->dev_t, BLK_DEV_SIZE, "%d:%d", major(devt), minor(devt));
1384 condlog(3, "%s: dev_t = %s", pp->dev, pp->dev_t);
1386 if (sysfs_get_size(pp, &pp->size))
1387 return PATHINFO_FAILED;
1389 condlog(3, "%s: size = %llu", pp->dev, pp->size);
1395 path_offline (struct path * pp)
1397 struct udev_device * parent;
1398 char buff[SCSI_STATE_SIZE];
1400 const char *subsys_type;
1402 if (pp->bus == SYSFS_BUS_SCSI) {
1403 subsys_type = "scsi";
1405 else if (pp->bus == SYSFS_BUS_NVME) {
1406 subsys_type = "nvme";
1414 const char *subsys = udev_device_get_subsystem(parent);
1415 if (subsys && !strncmp(subsys, subsys_type, 4))
1417 parent = udev_device_get_parent(parent);
1421 condlog(1, "%s: failed to get sysfs information", pp->dev);
1422 return PATH_REMOVED;
1425 memset(buff, 0x0, SCSI_STATE_SIZE);
1426 err = sysfs_attr_get_value(parent, "state", buff, SCSI_STATE_SIZE);
1429 return PATH_REMOVED;
1435 condlog(3, "%s: path state = %s", pp->dev, buff);
1437 if (pp->bus == SYSFS_BUS_SCSI) {
1438 if (!strncmp(buff, "offline", 7)) {
1443 if (!strncmp(buff, "blocked", 7) ||
1444 !strncmp(buff, "quiesce", 7))
1445 return PATH_PENDING;
1446 else if (!strncmp(buff, "running", 7))
1450 else if (pp->bus == SYSFS_BUS_NVME) {
1451 if (!strncmp(buff, "dead", 4)) {
1456 if (!strncmp(buff, "new", 3) ||
1457 !strncmp(buff, "deleting", 8))
1458 return PATH_PENDING;
1459 else if (!strncmp(buff, "live", 4))
1467 sysfs_pathinfo(struct path * pp, vector hwtable)
1469 int r = common_sysfs_pathinfo(pp);
1471 if (r != PATHINFO_OK)
1474 pp->bus = SYSFS_BUS_UNDEF;
1475 if (!strncmp(pp->dev,"cciss",5))
1476 pp->bus = SYSFS_BUS_CCISS;
1477 if (!strncmp(pp->dev,"dasd", 4))
1478 pp->bus = SYSFS_BUS_CCW;
1479 if (!strncmp(pp->dev,"sd", 2))
1480 pp->bus = SYSFS_BUS_SCSI;
1481 if (!strncmp(pp->dev,"nvme", 4))
1482 pp->bus = SYSFS_BUS_NVME;
1485 case SYSFS_BUS_SCSI:
1486 return scsi_sysfs_pathinfo(pp, hwtable);
1488 return ccw_sysfs_pathinfo(pp, hwtable);
1489 case SYSFS_BUS_CCISS:
1490 return cciss_sysfs_pathinfo(pp, hwtable);
1491 case SYSFS_BUS_NVME:
1492 return nvme_sysfs_pathinfo(pp, hwtable);
1493 case SYSFS_BUS_UNDEF:
1500 scsi_ioctl_pathinfo (struct path * pp, struct config *conf, int mask)
1502 struct udev_device *parent;
1503 const char *attr_path = NULL;
1505 if (pp->tpgs == TPGS_UNDEF)
1506 detect_alua(pp, conf);
1508 if (!(mask & DI_SERIAL))
1513 const char *subsys = udev_device_get_subsystem(parent);
1514 if (subsys && !strncmp(subsys, "scsi", 4)) {
1515 attr_path = udev_device_get_sysname(parent);
1518 if (sscanf(attr_path, "%i:%i:%i:%i",
1522 &pp->sg_id.lun) == 4)
1525 parent = udev_device_get_parent(parent);
1527 if (!attr_path || pp->sg_id.host_no == -1)
1530 if (get_vpd_sysfs(parent, 0x80, pp->serial, SERIAL_SIZE) <= 0) {
1531 if (get_serial(pp->serial, SERIAL_SIZE, pp->fd)) {
1532 condlog(3, "%s: fail to get serial", pp->dev);
1537 condlog(3, "%s: serial = %s", pp->dev, pp->serial);
1542 cciss_ioctl_pathinfo (struct path * pp, int mask)
1544 if (mask & DI_SERIAL) {
1545 get_serial(pp->serial, SERIAL_SIZE, pp->fd);
1546 condlog(3, "%s: serial = %s", pp->dev, pp->serial);
1552 get_state (struct path * pp, struct config *conf, int daemon, int oldstate)
1554 struct checker * c = &pp->checker;
1557 condlog(3, "%s: get_state", pp->dev);
1559 if (!checker_selected(c)) {
1561 if (pathinfo(pp, conf, DI_SYSFS) != PATHINFO_OK) {
1562 condlog(3, "%s: couldn't get sysfs pathinfo",
1564 return PATH_UNCHECKED;
1567 select_detect_checker(conf, pp);
1568 select_checker(conf, pp);
1569 if (!checker_selected(c)) {
1570 condlog(3, "%s: No checker selected", pp->dev);
1571 return PATH_UNCHECKED;
1573 checker_set_fd(c, pp->fd);
1574 if (checker_init(c, pp->mpp?&pp->mpp->mpcontext:NULL)) {
1576 condlog(3, "%s: checker init failed", pp->dev);
1577 return PATH_UNCHECKED;
1580 checker_clear_message(c);
1582 if (conf->force_sync == 0)
1583 checker_set_async(c);
1585 checker_set_sync(c);
1587 if (!conf->checker_timeout &&
1588 sysfs_get_timeout(pp, &(c->timeout)) <= 0)
1589 c->timeout = DEF_TIMEOUT;
1590 state = checker_check(c, oldstate);
1591 condlog(3, "%s: %s state = %s", pp->dev,
1592 checker_name(c), checker_state_name(state));
1593 if (state != PATH_UP && state != PATH_GHOST &&
1594 strlen(checker_message(c)))
1595 condlog(3, "%s: checker msg is \"%s\"",
1596 pp->dev, checker_message(c));
1601 get_prio (struct path * pp)
1604 struct config *conf;
1605 int checker_timeout;
1611 if (!prio_selected(p)) {
1612 conf = get_multipath_config();
1613 pthread_cleanup_push(put_multipath_config, conf);
1614 select_detect_prio(conf, pp);
1615 select_prio(conf, pp);
1616 pthread_cleanup_pop(1);
1617 if (!prio_selected(p)) {
1618 condlog(3, "%s: no prio selected", pp->dev);
1619 pp->priority = PRIO_UNDEF;
1623 conf = get_multipath_config();
1624 checker_timeout = conf->checker_timeout;
1625 put_multipath_config(conf);
1626 pp->priority = prio_getprio(p, pp, checker_timeout);
1627 if (pp->priority < 0) {
1628 condlog(3, "%s: %s prio error", pp->dev, prio_name(p));
1629 pp->priority = PRIO_UNDEF;
1632 condlog(3, "%s: %s prio = %u",
1633 pp->dev, prio_name(p), pp->priority);
1638 * Mangle string of length *len starting at start
1639 * by removing character sequence "00" (hex for a 0 byte),
1640 * starting at end, backwards.
1641 * Changes the value of *len if characters were removed.
1642 * Returns a pointer to the position where "end" was moved to.
1645 *skip_zeroes_backward(char* start, int *len, char *end)
1649 while (p >= start + 2 && *(p - 1) == '0' && *(p - 2) == '0')
1655 memmove(p, end, start + *len + 1 - end);
1662 * Fix for NVME wwids looking like this:
1663 * nvme.0000-3163653363666438366239656630386200-4c696e75780000000000000000000000000000000000000000000000000000000000000000000000-00000002
1664 * which are encountered in some combinations of Linux NVME host and target.
1665 * The '00' are hex-encoded 0-bytes which are forbidden in the serial (SN)
1666 * and model (MN) fields. Discard them.
1667 * If a WWID of the above type is found, sets pp->wwid and returns a value > 0.
1668 * Otherwise, returns 0.
1671 fix_broken_nvme_wwid(struct path *pp, const char *value, int size)
1673 static const char _nvme[] = "nvme.";
1678 len = strlen(value);
1679 if (len >= sizeof(mangled))
1682 /* Check that value starts with "nvme.%04x-" */
1683 if (memcmp(value, _nvme, sizeof(_nvme) - 1) || value[9] != '-')
1685 for (i = 5; i < 9; i++)
1686 if (!isxdigit(value[i]))
1689 memcpy(mangled, value, len + 1);
1691 /* search end of "model" part and strip trailing '00' */
1692 p = memrchr(mangled, '-', len);
1696 p = skip_zeroes_backward(mangled, &len, p);
1698 /* search end of "serial" part */
1699 p = memrchr(mangled, '-', p - mangled);
1700 if (p == NULL || memrchr(mangled, '-', p - mangled) != mangled + 9)
1701 /* We expect exactly 3 '-' in the value */
1704 p = skip_zeroes_backward(mangled, &len, p);
1708 memcpy(pp->wwid, mangled, len + 1);
1709 condlog(2, "%s: over-long WWID shortened to %s", pp->dev, pp->wwid);
1714 get_udev_uid(struct path * pp, char *uid_attribute, struct udev_device *udev)
1719 value = udev_device_get_property_value(udev, uid_attribute);
1720 if (!value || strlen(value) == 0)
1721 value = getenv(uid_attribute);
1722 if (value && strlen(value)) {
1723 len = strlcpy(pp->wwid, value, WWID_SIZE);
1724 if (len >= WWID_SIZE) {
1725 len = fix_broken_nvme_wwid(pp, value, WWID_SIZE);
1728 condlog(0, "%s: wwid overflow", pp->dev);
1732 condlog(3, "%s: no %s attribute", pp->dev,
1740 get_vpd_uid(struct path * pp)
1742 struct udev_device *parent = pp->udev;
1745 const char *subsys = udev_device_get_subsystem(parent);
1746 if (subsys && !strncmp(subsys, "scsi", 4))
1748 parent = udev_device_get_parent(parent);
1754 return get_vpd_sysfs(parent, 0x83, pp->wwid, WWID_SIZE);
1757 static ssize_t scsi_uid_fallback(struct path *pp, int path_state,
1758 const char **origin)
1762 struct config *conf;
1764 conf = get_multipath_config();
1765 retrigger = conf->retrigger_tries;
1766 put_multipath_config(conf);
1767 if (pp->retriggers >= retrigger &&
1768 !strcmp(pp->uid_attribute, DEFAULT_UID_ATTRIBUTE)) {
1769 len = get_vpd_uid(pp);
1771 pp->uid_attribute = NULL;
1772 if (len < 0 && path_state == PATH_UP) {
1773 condlog(1, "%s: failed to get sysfs uid: %s",
1774 pp->dev, strerror(-len));
1775 len = get_vpd_sgio(pp->fd, 0x83, pp->wwid,
1784 get_uid (struct path * pp, int path_state, struct udev_device *udev)
1787 const char *origin = "unknown";
1789 struct config *conf;
1791 if (!pp->uid_attribute && !pp->getuid) {
1792 conf = get_multipath_config();
1793 pthread_cleanup_push(put_multipath_config, conf);
1794 select_getuid(conf, pp);
1795 pthread_cleanup_pop(1);
1798 memset(pp->wwid, 0, WWID_SIZE);
1800 char buff[CALLOUT_MAX_SIZE];
1802 /* Use 'getuid' callout, deprecated */
1803 condlog(1, "%s: using deprecated getuid callout", pp->dev);
1804 if (path_state != PATH_UP) {
1805 condlog(3, "%s: path inaccessible", pp->dev);
1807 } else if (apply_format(pp->getuid, &buff[0], pp)) {
1808 condlog(0, "error formatting uid callout command");
1810 } else if (execute_program(buff, pp->wwid, WWID_SIZE)) {
1811 condlog(3, "error calling out %s", buff);
1814 len = strlen(pp->wwid);
1818 if (udev && pp->uid_attribute) {
1819 len = get_udev_uid(pp, pp->uid_attribute, udev);
1823 "%s: failed to get udev uid: %s",
1824 pp->dev, strerror(-len));
1826 } else if (pp->bus == SYSFS_BUS_SCSI) {
1827 len = get_vpd_uid(pp);
1830 if (len <= 0 && pp->bus == SYSFS_BUS_SCSI)
1831 len = scsi_uid_fallback(pp, path_state, &origin);
1834 condlog(1, "%s: failed to get %s uid: %s",
1835 pp->dev, origin, strerror(-len));
1836 memset(pp->wwid, 0x0, WWID_SIZE);
1839 /* Strip any trailing blanks */
1840 c = strchr(pp->wwid, '\0');
1842 while (c && c >= pp->wwid && *c == ' ') {
1847 condlog(3, "%s: uid = %s (%s)", pp->dev,
1848 *pp->wwid == '\0' ? "<empty>" : pp->wwid, origin);
1852 int pathinfo(struct path *pp, struct config *conf, int mask)
1857 return PATHINFO_FAILED;
1860 * For behavior backward-compatibility with multipathd,
1861 * the blacklisting by filter_property|devnode() is not
1862 * limited by DI_BLACKLIST and occurs before this debug
1863 * message with the mask value.
1866 const char *hidden =
1867 udev_device_get_sysattr_value(pp->udev, "hidden");
1869 if (hidden && !strcmp(hidden, "1")) {
1870 condlog(3, "%s: hidden", pp->dev);
1871 return PATHINFO_SKIPPED;
1873 if (is_claimed_by_foreign(pp->udev) ||
1874 filter_property(conf, pp->udev) > 0)
1875 return PATHINFO_SKIPPED;
1878 if (filter_devnode(conf->blist_devnode,
1879 conf->elist_devnode,
1881 return PATHINFO_SKIPPED;
1883 condlog(3, "%s: mask = 0x%x", pp->dev, mask);
1886 * Sanity check: we need the device number to
1887 * avoid inconsistent information in
1888 * find_path_by_dev()/find_path_by_devt()
1890 if (!strlen(pp->dev_t) && !(mask & DI_SYSFS)) {
1891 condlog(1, "%s: empty device number", pp->dev);
1896 * fetch info available in sysfs
1898 if (mask & DI_SYSFS) {
1899 int rc = sysfs_pathinfo(pp, conf->hwtable);
1901 if (rc != PATHINFO_OK)
1905 if (mask & DI_BLACKLIST && mask & DI_SYSFS) {
1906 if (filter_device(conf->blist_device, conf->elist_device,
1907 pp->vendor_id, pp->product_id, pp->dev) > 0 ||
1908 filter_protocol(conf->blist_protocol, conf->elist_protocol,
1910 return PATHINFO_SKIPPED;
1913 path_state = path_offline(pp);
1914 if (path_state == PATH_REMOVED)
1916 else if (mask & DI_NOIO) {
1918 * Avoid any IO on the device itself.
1919 * Behave like DI_CHECKER in the "path unavailable" case.
1921 pp->chkrstate = pp->state = path_state;
1926 * fetch info not available through sysfs
1929 pp->fd = open(udev_device_get_devnode(pp->udev), O_RDONLY);
1932 condlog(4, "Couldn't open node for %s: %s",
1933 pp->dev, strerror(errno));
1937 if (mask & DI_SERIAL)
1940 if (path_state == PATH_UP && pp->bus == SYSFS_BUS_SCSI)
1941 scsi_ioctl_pathinfo(pp, conf, mask);
1943 if (pp->bus == SYSFS_BUS_CCISS &&
1944 cciss_ioctl_pathinfo(pp, mask))
1947 if (mask & DI_CHECKER) {
1948 if (path_state == PATH_UP) {
1949 pp->chkrstate = pp->state = get_state(pp, conf, 0,
1951 if (pp->state == PATH_UNCHECKED ||
1952 pp->state == PATH_WILD)
1954 if (pp->state == PATH_TIMEOUT)
1955 pp->state = PATH_DOWN;
1956 if (pp->state == PATH_UP && !pp->size) {
1957 condlog(3, "%s: device size is 0, "
1958 "path unusable", pp->dev);
1959 pp->state = PATH_GHOST;
1962 condlog(3, "%s: path inaccessible", pp->dev);
1963 pp->chkrstate = pp->state = path_state;
1964 if (path_state == PATH_PENDING ||
1965 path_state == PATH_DOWN)
1970 if ((mask & DI_WWID) && !strlen(pp->wwid)) {
1971 get_uid(pp, path_state, pp->udev);
1972 if (!strlen(pp->wwid)) {
1973 pp->initialized = INIT_MISSING_UDEV;
1974 pp->tick = conf->retrigger_delay;
1981 if (mask & DI_BLACKLIST && mask & DI_WWID) {
1982 if (filter_wwid(conf->blist_wwid, conf->elist_wwid,
1983 pp->wwid, pp->dev) > 0) {
1984 return PATHINFO_SKIPPED;
1989 * Retrieve path priority, even for PATH_DOWN paths if it has never
1990 * been successfully obtained before.
1992 if ((mask & DI_PRIO) && path_state == PATH_UP && strlen(pp->wwid)) {
1993 if (pp->state != PATH_DOWN || pp->priority == PRIO_UNDEF) {
1998 if ((mask & DI_ALL) == DI_ALL)
1999 pp->initialized = INIT_OK;
2004 * Recoverable error, for example faulty or offline path
2006 pp->chkrstate = pp->state = PATH_DOWN;
2007 if (pp->initialized == INIT_FAILED)
2008 memset(pp->wwid, 0, WWID_SIZE);