4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2016 Toomas Soome <tsoome@me.com>
23 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
24 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
35 #include <sys/int_fmtio.h>
37 #include <bsm/devalloc.h>
38 #include <sys/scsi/scsi_address.h>
39 #include <sys/libdevid.h>
42 #define DISK_SUBPATH_MAX 100
44 #define DISK_LINK_RE "^r?dsk/c[0-9]+(t[0-9A-F]+)?d[0-9]+(((s|p))[0-9]+)?$"
45 #define DISK_LINK_TO_UPPER(ch)\
46 (((ch) >= 'a' && (ch) <= 'z') ? (ch - 'a' + 'A') : ch)
48 #define SLICE_SMI "s7"
53 #define ASCIIWWNSIZE 255
54 #if defined(__i386) || defined(__amd64)
56 * The number of minor nodes per LUN is defined by the disk drivers.
57 * Currently it is set to 64. Refer CMLBUNIT_SHIFT (cmlb_impl.h)
59 #define NUM_MINORS_PER_INSTANCE 64
63 extern int system_labeled
;
65 static int disk_callback_chan(di_minor_t minor
, di_node_t node
);
66 static int disk_callback_nchan(di_minor_t minor
, di_node_t node
);
67 static int disk_callback_blkdev(di_minor_t minor
, di_node_t node
);
68 static int disk_callback_wwn(di_minor_t minor
, di_node_t node
);
69 static int disk_callback_xvmd(di_minor_t minor
, di_node_t node
);
70 static int disk_callback_fabric(di_minor_t minor
, di_node_t node
);
71 static int disk_callback_sas(di_minor_t minor
, di_node_t node
);
72 static void disk_common(di_minor_t minor
, di_node_t node
, char *disk
,
74 static char *diskctrl(di_node_t node
, di_minor_t minor
);
75 static int reserved_links_exist(di_node_t node
, di_minor_t minor
, int nflags
);
76 static void disk_rm_lofi_all(char *file
);
79 static devfsadm_create_t disk_cbt
[] = {
80 { "disk", DDI_NT_BLOCK
, NULL
,
81 TYPE_EXACT
, ILEVEL_0
, disk_callback_nchan
83 { "disk", DDI_NT_BLOCK_CHAN
, NULL
,
84 TYPE_EXACT
, ILEVEL_0
, disk_callback_chan
86 { "disk", DDI_NT_BLOCK_BLKDEV
, NULL
,
87 TYPE_EXACT
, ILEVEL_0
, disk_callback_blkdev
89 { "disk", DDI_NT_BLOCK_FABRIC
, NULL
,
90 TYPE_EXACT
, ILEVEL_0
, disk_callback_fabric
92 { "disk", DDI_NT_BLOCK_WWN
, NULL
,
93 TYPE_EXACT
, ILEVEL_0
, disk_callback_wwn
95 { "disk", DDI_NT_BLOCK_SAS
, NULL
,
96 TYPE_EXACT
, ILEVEL_0
, disk_callback_sas
98 { "disk", DDI_NT_CD
, NULL
,
99 TYPE_EXACT
, ILEVEL_0
, disk_callback_nchan
101 { "disk", DDI_NT_CD_CHAN
, NULL
,
102 TYPE_EXACT
, ILEVEL_0
, disk_callback_chan
104 { "disk", DDI_NT_BLOCK_XVMD
, NULL
,
105 TYPE_EXACT
, ILEVEL_0
, disk_callback_xvmd
107 { "disk", DDI_NT_CD_XVMD
, NULL
,
108 TYPE_EXACT
, ILEVEL_0
, disk_callback_xvmd
112 DEVFSADM_CREATE_INIT_V0(disk_cbt
);
115 * HOT auto cleanup of disks is done for lofi devices only.
117 static devfsadm_remove_t disk_remove_cbt
[] = {
118 { "disk", DISK_LINK_RE
, RM_HOT
| RM_POST
| RM_ALWAYS
,
119 ILEVEL_0
, disk_rm_lofi_all
121 { "disk", DISK_LINK_RE
, RM_POST
,
122 ILEVEL_0
, devfsadm_rm_all
126 DEVFSADM_REMOVE_INIT_V0(disk_remove_cbt
);
128 static devlink_re_t disks_re_array
[] = {
129 {"^r?dsk/c([0-9]+)", 1},
130 {"^cfg/c([0-9]+)$", 1},
131 {"^scsi/.+/c([0-9]+)", 1},
135 static char *disk_mid
= "disk_mid";
136 static char *modname
= "disk_link";
139 * Check if link is from lofi by checking path from readlink().
142 is_lofi_disk(char *file
)
144 char buf
[PATH_MAX
+ 1];
145 char filepath
[PATH_MAX
];
149 size
= snprintf(filepath
, sizeof (filepath
), "%s/dev/%s",
150 devfsadm_root_path(), file
);
151 if (size
> sizeof (filepath
))
154 size
= readlink(filepath
, buf
, sizeof (buf
) - 1);
158 ptr
= strchr(buf
, '@');
162 if (strcmp(buf
, "../../devices/pseudo/lofi@") != 0)
168 * Wrapper around devfsadm_rm_link() for lofi devices.
170 static void disk_rm_lofi_all(char *file
)
172 if (is_lofi_disk(file
))
173 devfsadm_rm_link(file
);
179 devfsadm_print(disk_mid
,
180 "%s: minor_init(): Creating disks reserved ID cache\n",
182 return (devfsadm_reserve_id_cache(disks_re_array
, NULL
));
186 disk_callback_chan(di_minor_t minor
, di_node_t node
)
194 driver
= di_driver_name(node
);
195 if (strcmp(driver
, LOFI_DRIVER_NAME
) != 0) {
196 addr
= di_bus_addr(node
);
197 (void) sscanf(addr
, "%X,%X", &targ
, &lun
);
199 targ
= di_instance(node
);
202 (void) snprintf(disk
, sizeof (disk
), "t%dd%d", targ
, lun
);
203 disk_common(minor
, node
, disk
, 0);
204 return (DEVFSADM_CONTINUE
);
209 disk_callback_nchan(di_minor_t minor
, di_node_t node
)
215 addr
= di_bus_addr(node
);
216 (void) sscanf(addr
, "%X", &lun
);
217 (void) sprintf(disk
, "d%d", lun
);
218 disk_common(minor
, node
, disk
, 0);
219 return (DEVFSADM_CONTINUE
);
224 disk_callback_blkdev(di_minor_t minor
, di_node_t node
)
227 char disk
[DISK_SUBPATH_MAX
];
231 addr
= di_bus_addr(node
);
232 (void) sscanf(addr
, "w%016"PRIx64
",%X", &eui64
, &lun
);
233 (void) snprintf(disk
, DISK_SUBPATH_MAX
, "t%016"PRIX64
"d%d", eui64
, lun
);
234 disk_common(minor
, node
, disk
, RM_STALE
);
235 return (DEVFSADM_CONTINUE
);
239 disk_callback_wwn(di_minor_t minor
, di_node_t node
)
246 if (di_prop_lookup_ints(DDI_DEV_T_ANY
, node
, SCSI_ADDR_PROP_TARGET
,
248 return (DEVFSADM_CONTINUE
);
251 if (di_prop_lookup_ints(DDI_DEV_T_ANY
, node
, SCSI_ADDR_PROP_LUN
,
257 (void) sprintf(disk
, "t%dd%d", targ
, lun
);
259 disk_common(minor
, node
, disk
, RM_STALE
);
261 return (DEVFSADM_CONTINUE
);
265 disk_callback_fabric(di_minor_t minor
, di_node_t node
)
267 char disk
[DISK_SUBPATH_MAX
];
273 uchar_t ascii_wwn
[ASCIIWWNSIZE
];
275 if (di_prop_lookup_strings(DDI_DEV_T_ANY
, node
,
276 "client-guid", (char **)&wwn
) > 0) {
277 if (strlcpy((char *)ascii_wwn
, (char *)wwn
,
278 sizeof (ascii_wwn
)) >= sizeof (ascii_wwn
)) {
279 devfsadm_errprint("SUNW_disk_link: GUID too long:%d",
280 strlen((char *)wwn
));
281 return (DEVFSADM_CONTINUE
);
284 } else if (di_prop_lookup_bytes(DDI_DEV_T_ANY
, node
,
285 "port-wwn", &wwn
) > 0) {
286 if (di_prop_lookup_ints(DDI_DEV_T_ANY
, node
,
287 SCSI_ADDR_PROP_LUN
, &intp
) > 0) {
293 for (count
= 0, str
= ascii_wwn
; count
< 8; count
++, str
+= 2) {
294 (void) sprintf((caddr_t
)str
, "%02x", wwn
[count
]);
298 return (DEVFSADM_CONTINUE
);
301 for (str
= ascii_wwn
; *str
!= '\0'; str
++) {
302 *str
= DISK_LINK_TO_UPPER(*str
);
305 (void) snprintf(disk
, DISK_SUBPATH_MAX
, "t%sd%d", ascii_wwn
, lun
);
307 disk_common(minor
, node
, disk
, RM_STALE
);
309 return (DEVFSADM_CONTINUE
);
313 disk_callback_sas(di_minor_t minor
, di_node_t node
)
315 char disk
[DISK_SUBPATH_MAX
];
317 scsi_lun64_t lun64
, sl
;
325 /* Get lun property */
326 if (di_prop_lookup_int64(DDI_DEV_T_ANY
, node
,
327 SCSI_ADDR_PROP_LUN64
, &lun64p
) > 0) {
328 if (*lun64p
!= SCSI_LUN64_ILLEGAL
) {
330 lun64
= (uint64_t)*lun64p
;
333 if ((!lun64_found
) && (di_prop_lookup_ints(DDI_DEV_T_ANY
, node
,
334 SCSI_ADDR_PROP_LUN
, &intp
) > 0)) {
335 lun64
= (uint64_t)*intp
;
338 lun
= scsi_lun64_to_lun(lun64
);
340 addr_method
= (lun
.sl_lun1_msb
& SCSI_LUN_AM_MASK
);
342 if (di_prop_lookup_strings(DDI_DEV_T_ANY
, node
,
343 SCSI_ADDR_PROP_TARGET_PORT
, &tgt_port
) > 0) {
344 (void) scsi_wwnstr_to_wwn(tgt_port
, &wwn
);
345 if ((addr_method
== SCSI_LUN_AM_PDEV
) &&
346 (lun
.sl_lun2_msb
== 0) && (lun
.sl_lun2_lsb
== 0) &&
347 (lun
.sl_lun3_msb
== 0) && (lun
.sl_lun3_lsb
== 0) &&
348 (lun
.sl_lun4_msb
== 0) && (lun
.sl_lun4_lsb
== 0)) {
349 (void) snprintf(disk
, DISK_SUBPATH_MAX
,
350 "t%"PRIX64
"d%"PRId64
, wwn
, lun64
);
351 } else if ((addr_method
== SCSI_LUN_AM_FLAT
) &&
352 (lun
.sl_lun2_msb
== 0) && (lun
.sl_lun2_lsb
== 0) &&
353 (lun
.sl_lun3_msb
== 0) && (lun
.sl_lun3_lsb
== 0) &&
354 (lun
.sl_lun4_msb
== 0) && (lun
.sl_lun4_lsb
== 0)) {
355 sl
= (lun
.sl_lun1_msb
<< 8) | lun
.sl_lun1_lsb
;
356 (void) snprintf(disk
, DISK_SUBPATH_MAX
,
357 "t%"PRIX64
"d%"PRIX16
, wwn
, sl
);
359 (void) snprintf(disk
, DISK_SUBPATH_MAX
,
360 "t%"PRIX64
"d%"PRIX64
, wwn
, lun64
);
362 } else if (di_prop_lookup_ints(DDI_DEV_T_ANY
, node
,
363 SCSI_ADDR_PROP_SATA_PHY
, &intp
) > 0) {
364 /* Use phy format naming, for SATA devices without wwn */
365 if ((addr_method
== SCSI_LUN_AM_PDEV
) &&
366 (lun
.sl_lun2_msb
== 0) && (lun
.sl_lun2_lsb
== 0) &&
367 (lun
.sl_lun3_msb
== 0) && (lun
.sl_lun3_lsb
== 0) &&
368 (lun
.sl_lun4_msb
== 0) && (lun
.sl_lun4_lsb
== 0)) {
369 (void) snprintf(disk
, DISK_SUBPATH_MAX
,
370 "t%dd%"PRId64
, *intp
, lun64
);
371 } else if ((addr_method
== SCSI_LUN_AM_FLAT
) &&
372 (lun
.sl_lun2_msb
== 0) && (lun
.sl_lun2_lsb
== 0) &&
373 (lun
.sl_lun3_msb
== 0) && (lun
.sl_lun3_lsb
== 0) &&
374 (lun
.sl_lun4_msb
== 0) && (lun
.sl_lun4_lsb
== 0)) {
375 sl
= (lun
.sl_lun1_msb
<< 8) | lun
.sl_lun1_lsb
;
376 (void) snprintf(disk
, DISK_SUBPATH_MAX
,
377 "t%dd%"PRIX16
, *intp
, sl
);
379 (void) snprintf(disk
, DISK_SUBPATH_MAX
,
380 "t%dd%"PRIX64
, *intp
, lun64
);
383 return (DEVFSADM_CONTINUE
);
386 disk_common(minor
, node
, disk
, RM_STALE
);
388 return (DEVFSADM_CONTINUE
);
392 * xVM virtual block device
394 * Xen passes device number in next format:
396 * 1 << 28 | disk << 8 | partition xvd, disks or partitions 16 onwards
397 * 202 << 8 | disk << 4 | partition xvd, disks and partitions up to 15
398 * 8 << 8 | disk << 4 | partition sd, disks and partitions up to 15
399 * 3 << 8 | disk << 6 | partition hd, disks 0..1, partitions 0..63
400 * 22 << 8 | (disk-2) << 6 | partition hd, disks 2..3, partitions 0..63
401 * 2 << 28 onwards reserved for future use
402 * other values less than 1 << 28 deprecated / reserved
404 * The corresponding Solaris /dev/dsk name can be:
410 * For PV guests using the legacy naming (0, 1, 2, ...)
411 * the Solaris disk names created will be c0d[0..767]sN
414 #define HD_BASE (3 << 8)
415 #define XEN_EXT_SHIFT (28)
418 * Return: Number of parsed and written parameters
421 decode_xen_device(uint_t device
, uint_t
*disk
, uint_t
*plun
)
426 if ((device
>> XEN_EXT_SHIFT
) > 1)
429 if (device
< HD_BASE
) {
430 /* legacy device address */
436 if (device
& (1 << XEN_EXT_SHIFT
)) {
438 dsk
= device
& (~0xff);
443 switch (device
>> 8) {
445 dsk
= (device
>> 4) & 0xf;
449 dsk
= device
& (~0xf);
452 case 3: /* hd, disk 0..1 */
453 dsk
= device
& (~0x3f);
456 case 22: /* hd, disk 2..3 */
457 dsk
= device
& (~0x3f);
470 disk_callback_xvmd(di_minor_t minor
, di_node_t node
)
478 addr
= di_bus_addr(node
);
479 targ
= strtol(addr
, (char **)NULL
, 10);
481 res
= decode_xen_device(targ
, &dsk
, &lun
);
483 /* HVM device names are generated using the standard generator */
486 (void) snprintf(disk
, sizeof (disk
), "d%d", dsk
);
488 (void) snprintf(disk
, sizeof (disk
), "t%dd%d", dsk
, lun
);
490 devfsadm_errprint("%s: invalid disk device number (%s)\n",
492 return (DEVFSADM_CONTINUE
);
494 disk_common(minor
, node
, disk
, 0);
495 return (DEVFSADM_CONTINUE
);
500 * This function is called for every disk minor node.
501 * Calls enumerate to assign a logical controller number, and
502 * then devfsadm_mklink to make the link.
505 disk_common(di_minor_t minor
, di_node_t node
, char *disk
, int flags
)
507 char l_path
[PATH_MAX
+ 1];
508 char sec_path
[PATH_MAX
+ 1];
509 char stale_re
[DISK_SUBPATH_MAX
];
517 #if defined(__i386) || defined(__amd64)
523 mn
= di_minor_name(minor
);
524 if (strstr(mn
, ",raw")) {
526 #if defined(__i386) || defined(__amd64)
527 (void) strncpy(mn_copy
, mn
, 4);
528 part
= strtok(mn_copy
, ",");
532 #if defined(__i386) || defined(__amd64)
537 #if defined(__i386) || defined(__amd64)
539 * The following is a table describing the allocation of
540 * minor numbers, minor names and /dev/dsk names for partitions
541 * and slices on x86 systems.
543 * Minor Number Minor Name /dev/dsk name
544 * ---------------------------------------------
545 * 0 to 15 "a" to "p" s0 to s15
547 * 17 to 20 "r" to "u" p1 to p4
548 * 21 to 52 "p5" to "p36" p5 to p36
551 part_num
= atoi(part
+ 1);
553 if ((mn
[0] == 'p') && (part_num
>= 5)) {
555 (void) snprintf(slice
, 4, "%s", part
);
559 (void) sprintf(slice
, "s%d", mn
[0] - 'a');
560 } else if (strncmp(mn
, MN_EFI
, 2) != 0) {
561 (void) sprintf(slice
, "p%d", mn
[0] - 'q');
564 (void) sprintf(slice
, SLICE_EFI
);
566 #if defined(__i386) || defined(__amd64)
571 if (system_labeled
) {
572 nt
= di_minor_nodetype(minor
);
574 ((strcmp(nt
, DDI_NT_CD
) == 0) ||
575 (strcmp(nt
, DDI_NT_CD_CHAN
) == 0) ||
576 (strcmp(nt
, DDI_NT_BLOCK_CHAN
) == 0))) {
577 nflags
= DA_ADD
|DA_CD
;
581 if (reserved_links_exist(node
, minor
, nflags
) == DEVFSADM_SUCCESS
) {
582 devfsadm_print(disk_mid
, "Reserved link exists. Not "
583 "creating links for slice %s\n", slice
);
587 if (NULL
== (ctrl
= diskctrl(node
, minor
)))
590 (void) strcpy(l_path
, dir
);
591 (void) strcat(l_path
, "/c");
592 (void) strcat(l_path
, ctrl
);
593 (void) strcat(l_path
, disk
);
596 * If switching between SMI and EFI label or vice versa
597 * cleanup the previous label's devlinks.
599 if (*mn
== *(MN_SMI
) || (strncmp(mn
, MN_EFI
, 2) == 0)) {
600 char *s
, tpath
[PATH_MAX
+ 1];
603 s
= l_path
+ strlen(l_path
);
604 (void) strcat(l_path
, (*mn
== *(MN_SMI
))
605 ? SLICE_EFI
: SLICE_SMI
);
607 * Attempt the remove only if the stale link exists
609 (void) snprintf(tpath
, sizeof (tpath
), "%s/dev/%s",
610 devfsadm_root_path(), l_path
);
611 if (lstat(tpath
, &sb
) != -1)
612 devfsadm_rm_all(l_path
);
615 (void) strcat(l_path
, slice
);
617 (void) devfsadm_mklink(l_path
, node
, minor
, nflags
);
619 /* secondary links for removable and hotpluggable devices */
620 if (di_prop_lookup_ints(DDI_DEV_T_ANY
, node
, "removable-media",
622 (void) strcpy(sec_path
, "removable-media/");
623 (void) strcat(sec_path
, l_path
);
624 (void) devfsadm_secondary_link(sec_path
, l_path
, 0);
626 if (di_prop_lookup_ints(DDI_DEV_T_ANY
, node
, "hotpluggable",
628 (void) strcpy(sec_path
, "hotpluggable/");
629 (void) strcat(sec_path
, l_path
);
630 (void) devfsadm_secondary_link(sec_path
, l_path
, 0);
633 if ((flags
& RM_STALE
) == RM_STALE
) {
634 (void) strcpy(stale_re
, "^");
635 (void) strcat(stale_re
, dir
);
636 (void) strcat(stale_re
, "/c");
637 (void) strcat(stale_re
, ctrl
);
638 (void) strcat(stale_re
, "t[0-9A-F]+d[0-9]+(s[0-9]+)?$");
640 * optimizations are made inside of devfsadm_rm_stale_links
641 * instead of before calling the function, as it always
642 * needs to add the valid link to the cache.
644 devfsadm_rm_stale_links(stale_re
, l_path
, node
, minor
);
651 /* index of enumeration rule applicable to this module */
655 diskctrl(di_node_t node
, di_minor_t minor
)
657 char path
[PATH_MAX
+ 1];
662 devfsadm_enumerate_t rules
[3] = {
663 {"^r?dsk$/^c([0-9]+)", 1, MATCH_PARENT
},
664 {"^cfg$/^c([0-9]+)$", 1, MATCH_ADDR
},
665 {"^scsi$/^.+$/^c([0-9]+)", 1, MATCH_PARENT
}
668 mn
= di_minor_name(minor
);
670 if ((devfspath
= di_devfs_path(node
)) == NULL
) {
673 (void) strcpy(path
, devfspath
);
674 (void) strcat(path
, ":");
675 (void) strcat(path
, mn
);
676 di_devfs_path_free(devfspath
);
679 * Use controller component of disk path
681 is_vhci
= (strncmp(path
, "/scsi_vhci/", 11) == 0);
683 if (ctrl_enumerate_int(path
, RULE_INDEX
, &buf
, rules
, 3, 1, is_vhci
) ==
686 * We failed because there are multiple logical controller
687 * numbers for a single physical controller. If we use node
688 * name also in the match it should fix this and only find one
689 * logical controller. (See 4045879).
690 * NOTE: Rules for controllers are not changed, as there is
691 * no unique controller number for them in this case.
693 * MATCH_UNCACHED flag is private to the "disks" and "sgen"
694 * modules. NOT to be used by other modules.
697 rules
[0].flags
= MATCH_NODE
| MATCH_UNCACHED
; /* disks */
698 rules
[2].flags
= MATCH_NODE
| MATCH_UNCACHED
; /* generic scsi */
699 if (ctrl_enumerate_int(path
, RULE_INDEX
, &buf
, rules
, 3, 0,
708 typedef struct dvlist
{
710 struct dvlist
*dv_next
;
714 free_dvlist(dvlist_t
**pp
)
720 *pp
= entry
->dv_next
;
721 assert(entry
->dv_link
);
722 free(entry
->dv_link
);
727 dvlink_cb(di_devlink_t devlink
, void *arg
)
731 dvlist_t
**pp
= (dvlist_t
**)arg
;
732 dvlist_t
*entry
= NULL
;
734 entry
= calloc(1, sizeof (dvlist_t
));
736 devfsadm_errprint("%s: calloc failed\n", modname
);
740 path
= (char *)di_devlink_path(devlink
);
743 devfsadm_errprint("%s: di_devlink_path() returned NULL\n",
748 devfsadm_print(disk_mid
, "%s: found link %s in reverse link cache\n",
752 * Return linkname in canonical form i.e. without the
755 can_path
= strstr(path
, "/dev/");
756 if (can_path
== NULL
) {
757 devfsadm_errprint("%s: devlink path %s has no /dev/\n",
762 entry
->dv_link
= s_strdup(can_path
+ strlen("/dev/"));
763 entry
->dv_next
= *pp
;
766 return (DI_WALK_CONTINUE
);
772 return (DI_WALK_TERMINATE
);
776 * Returns success only if all goes well. If there is no matching reserved link
777 * or if there is an error, we assume no match. It is better to err on the side
778 * of caution by creating extra links than to miss out creating a required link.
781 reserved_links_exist(di_node_t node
, di_minor_t minor
, int nflags
)
783 di_devlink_handle_t dvlink_cache
= devfsadm_devlink_cache();
784 char phys_path
[PATH_MAX
];
791 char *mn
= di_minor_name(minor
);
793 if (dvlink_cache
== NULL
|| mn
== NULL
) {
794 devfsadm_errprint("%s: No minor or devlink cache\n", modname
);
795 return (DEVFSADM_FAILURE
);
798 if (!devfsadm_have_reserved()) {
799 devfsadm_print(disk_mid
, "%s: No reserved links\n", modname
);
800 return (DEVFSADM_FAILURE
);
803 minor_path
= di_devfs_minor_path(minor
);
804 if (minor_path
== NULL
) {
805 devfsadm_errprint("%s: di_devfs_minor_path failed\n", modname
);
806 return (DEVFSADM_FAILURE
);
809 (void) strlcpy(phys_path
, minor_path
, sizeof (phys_path
));
811 di_devfs_path_free(minor_path
);
814 (void) di_devlink_cache_walk(dvlink_cache
, DISK_LINK_RE
, phys_path
,
815 DI_PRIMARY_LINK
, &head
, dvlink_cb
);
818 * We may be switching between EFI label and SMI label in which case
819 * we only have minors of the other type.
821 if (head
== NULL
&& (*mn
== *(MN_SMI
) ||
822 (strncmp(mn
, MN_EFI
, 2) == 0))) {
823 devfsadm_print(disk_mid
, "%s: No links for minor %s in /dev. "
824 "Trying another label\n", modname
, mn
);
825 s
= strrchr(phys_path
, ':');
827 devfsadm_errprint("%s: invalid minor path: %s\n",
829 return (DEVFSADM_FAILURE
);
831 (void) snprintf(s
+1, sizeof (phys_path
) - (s
+ 1 - phys_path
),
832 "%s%s", *mn
== *(MN_SMI
) ? MN_EFI
: MN_SMI
,
833 strstr(s
, ",raw") ? ",raw" : "");
834 (void) di_devlink_cache_walk(dvlink_cache
, DISK_LINK_RE
,
835 phys_path
, DI_PRIMARY_LINK
, &head
, dvlink_cb
);
839 devfsadm_print(disk_mid
, "%s: minor %s has no links in /dev\n",
841 /* no links on disk */
842 return (DEVFSADM_FAILURE
);
846 * It suffices to use 1 link to this minor, since
847 * we are matching with reserved IDs on the basis of
848 * the controller number which will be the same for
849 * all links to this minor.
851 if (!devfsadm_is_reserved(disks_re_array
, head
->dv_link
)) {
852 /* not reserved links */
853 devfsadm_print(disk_mid
, "%s: devlink %s and its minor "
854 "are NOT reserved\n", modname
, head
->dv_link
);
856 return (DEVFSADM_FAILURE
);
859 devfsadm_print(disk_mid
, "%s: devlink %s and its minor are on "
860 "reserved list\n", modname
, head
->dv_link
);
863 * Switch between SMI and EFI labels if required
866 if (*mn
== *(MN_SMI
) || (strncmp(mn
, MN_EFI
, 2) == 0)) {
867 for (entry
= head
; entry
; entry
= entry
->dv_next
) {
868 s
= strrchr(entry
->dv_link
, '/');
871 devfsadm_errprint("%s: disk link %s has no "
872 "directory\n", modname
, entry
->dv_link
);
875 if (*mn
== *(MN_SMI
) && strchr(s
, 's') == NULL
) {
876 (void) snprintf(l
, sizeof (l
), "%s%s",
877 entry
->dv_link
, SLICE_SMI
);
879 devfsadm_print(disk_mid
, "%s: switching "
880 "reserved link from EFI to SMI label. "
881 "New link is %s\n", modname
, l
);
882 } else if (strncmp(mn
, MN_EFI
, 2) == 0 &&
883 (s
= strchr(s
, 's'))) {
885 (void) snprintf(l
, sizeof (l
), "%s",
889 devfsadm_print(disk_mid
, "%s: switching "
890 "reserved link from SMI to EFI label. "
891 "New link is %s\n", modname
, l
);
894 devfsadm_print(disk_mid
, "%s: switching "
895 "link: deleting %s and creating %s\n",
896 modname
, entry
->dv_link
, l
);
897 devfsadm_rm_link(entry
->dv_link
);
898 (void) devfsadm_mklink(l
, node
, minor
, nflags
);
905 * return SUCCESS to indicate that new links to this minor should not
906 * be created so that only compatibility links to this minor remain.
908 return (DEVFSADM_SUCCESS
);