disk_link.c revision efc44fd77cb81028389b8598b063646228f9e1d0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2012 Nexenta Systems, Inc. All rights reserved.
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <devfsadm.h>
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include <sys/int_fmtio.h>
#include <bsm/devalloc.h>
#include <sys/libdevid.h>
#define DISK_SUBPATH_MAX 100
#define RM_STALE 0x01
#define DISK_LINK_RE "^r?dsk/c[0-9]+(t[0-9A-F]+)?d[0-9]+(((s|p))[0-9]+)?$"
#define DISK_LINK_TO_UPPER(ch)\
#define SLICE_SMI "s7"
#define SLICE_EFI ""
#define MN_SMI "h"
#define MN_EFI "wd"
#define ASCIIWWNSIZE 255
/*
* The number of minor nodes per LUN is defined by the disk drivers.
* Currently it is set to 64. Refer CMLBUNIT_SHIFT (cmlb_impl.h)
*/
#define NUM_MINORS_PER_INSTANCE 64
#endif
extern int system_labeled;
int flags);
static devfsadm_create_t disk_cbt[] = {
},
},
},
},
},
},
},
},
},
};
/*
* HOT auto cleanup of disks not desired.
*/
static devfsadm_remove_t disk_remove_cbt[] = {
}
};
static devlink_re_t disks_re_array[] = {
{"^r?dsk/c([0-9]+)", 1},
{"^cfg/c([0-9]+)$", 1},
{"^scsi/.+/c([0-9]+)", 1},
{NULL}
};
static char *disk_mid = "disk_mid";
static char *modname = "disk_link";
int
{
"%s: minor_init(): Creating disks reserved ID cache\n",
modname);
}
static int
{
char *addr;
char disk[20];
return (DEVFSADM_CONTINUE);
}
static int
{
char *addr;
char disk[10];
return (DEVFSADM_CONTINUE);
}
static int
{
char disk[10];
int lun;
int targ;
int *intp;
&intp) <= 0) {
return (DEVFSADM_CONTINUE);
}
&intp) <= 0) {
lun = 0;
} else {
}
return (DEVFSADM_CONTINUE);
}
static int
{
char disk[DISK_SUBPATH_MAX];
int lun;
int count;
int *intp;
"client-guid", (char **)&wwn) > 0) {
devfsadm_errprint("SUNW_disk_link: GUID too long:%d",
return (DEVFSADM_CONTINUE);
}
lun = 0;
"port-wwn", &wwn) > 0) {
SCSI_ADDR_PROP_LUN, &intp) > 0) {
} else {
lun = 0;
}
}
*str = '\0';
} else {
return (DEVFSADM_CONTINUE);
}
}
return (DEVFSADM_CONTINUE);
}
static int
{
char disk[DISK_SUBPATH_MAX];
int lun64_found = 0;
int *intp;
char *tgt_port;
/* Get lun property */
SCSI_ADDR_PROP_LUN64, &lun64p) > 0) {
if (*lun64p != SCSI_LUN64_ILLEGAL) {
lun64_found = 1;
}
}
SCSI_ADDR_PROP_LUN, &intp) > 0)) {
}
SCSI_ADDR_PROP_TARGET_PORT, &tgt_port) > 0) {
if ((addr_method == SCSI_LUN_AM_PDEV) &&
} else if ((addr_method == SCSI_LUN_AM_FLAT) &&
} else {
}
SCSI_ADDR_PROP_SATA_PHY, &intp) > 0) {
/* Use phy format naming, for SATA devices without wwn */
if ((addr_method == SCSI_LUN_AM_PDEV) &&
} else if ((addr_method == SCSI_LUN_AM_FLAT) &&
} else {
}
} else {
return (DEVFSADM_CONTINUE);
}
return (DEVFSADM_CONTINUE);
}
/*
* xVM virtual block device
*
* Xen passes device number in next format:
*
* 1 << 28 | disk << 8 | partition xvd, disks or partitions 16 onwards
* 202 << 8 | disk << 4 | partition xvd, disks and partitions up to 15
* 8 << 8 | disk << 4 | partition sd, disks and partitions up to 15
* 3 << 8 | disk << 6 | partition hd, disks 0..1, partitions 0..63
* 22 << 8 | (disk-2) << 6 | partition hd, disks 2..3, partitions 0..63
* 2 << 28 onwards reserved for future use
* other values less than 1 << 28 deprecated / reserved
*
*
* c0tYdXsN
*
* where Y,X >= 0.
*
* For PV guests using the legacy naming (0, 1, 2, ...)
* the Solaris disk names created will be c0d[0..767]sN
*/
#define XEN_EXT_SHIFT (28)
/*
* Return: Number of parsed and written parameters
*/
static int
{
int ret = 1;
return (0);
/* legacy device address */
goto end;
}
ret = 2;
/* extended */
goto end;
}
switch (device >> 8) {
case 202: /* xvd */
break;
case 8: /* sd */
break;
case 3: /* hd, disk 0..1 */
break;
case 22: /* hd, disk 2..3 */
break;
default:
return (0);
}
end:
return (ret);
}
static int
{
char *addr;
char disk[16];
int res;
/* HVM device names are generated using the standard generator */
if (res == 1)
else if (res == 2)
else {
devfsadm_errprint("%s: invalid disk device number (%s)\n",
return (DEVFSADM_CONTINUE);
}
return (DEVFSADM_CONTINUE);
}
/*
* This function is called for every disk minor node.
* Calls enumerate to assign a logical controller number, and
* then devfsadm_mklink to make the link.
*/
static void
{
char stale_re[DISK_SUBPATH_MAX];
char *dir;
char slice[4];
char *mn;
char *ctrl;
int *int_prop;
int nflags = 0;
char mn_copy[4];
char *part;
int part_num;
#endif
dir = "rdsk";
#endif
} else {
dir = "dsk";
#endif
}
/*
* The following is a table describing the allocation of
* and slices on x86 systems.
*
* ---------------------------------------------
* 0 to 15 "a" to "p" s0 to s15
* 16 "q" p0
* 17 to 20 "r" to "u" p1 to p4
* 21 to 52 "p5" to "p36" p5 to p36
*
*/
/* logical drive */
} else {
#endif
if (mn[0] < 'q') {
} else {
/* For EFI label */
}
}
#endif
nflags = 0;
if (system_labeled) {
}
}
"creating links for slice %s\n", slice);
return;
}
return;
/*
* If switching between SMI and EFI label or vice versa
* cleanup the previous label's devlinks.
*/
/*
* Attempt the remove only if the stale link exists
*/
devfsadm_root_path(), l_path);
*s = '\0';
}
/* secondary links for removable and hotpluggable devices */
&int_prop) >= 0) {
}
&int_prop) >= 0) {
}
/*
* optimizations are made inside of devfsadm_rm_stale_links
* instead of before calling the function, as it always
* needs to add the valid link to the cache.
*/
}
}
/* index of enumeration rule applicable to this module */
#define RULE_INDEX 0
static char *
{
char *devfspath;
};
return (NULL);
}
/*
* Use controller component of disk path
*/
/*
* We failed because there are multiple logical controller
* numbers for a single physical controller. If we use node
* name also in the match it should fix this and only find one
* logical controller. (See 4045879).
* NOTE: Rules for controllers are not changed, as there is
* no unique controller number for them in this case.
*
* MATCH_UNCACHED flag is private to the "disks" and "sgen"
* modules. NOT to be used by other modules.
*/
return (NULL);
}
}
return (buf);
}
typedef struct dvlist {
char *dv_link;
} dvlist_t;
static void
{
while (*pp) {
}
}
static int
{
char *path;
char *can_path;
goto error;
}
devfsadm_errprint("%s: di_devlink_path() returned NULL\n",
modname);
goto error;
}
/*
* Return linkname in canonical form i.e. without the
* "/dev/" prefix
*/
devfsadm_errprint("%s: devlink path %s has no /dev/\n",
goto error;
}
return (DI_WALK_CONTINUE);
return (DI_WALK_TERMINATE);
}
/*
* Returns success only if all goes well. If there is no matching reserved link
* or if there is an error, we assume no match. It is better to err on the side
* of caution by creating extra links than to miss out creating a required link.
*/
static int
{
char *minor_path;
char *s;
char l[PATH_MAX];
int switch_link = 0;
return (DEVFSADM_FAILURE);
}
if (!devfsadm_have_reserved()) {
return (DEVFSADM_FAILURE);
}
if (minor_path == NULL) {
return (DEVFSADM_FAILURE);
}
/*
* We may be switching between EFI label and SMI label in which case
* we only have minors of the other type.
*/
if (s == NULL) {
devfsadm_errprint("%s: invalid minor path: %s\n",
return (DEVFSADM_FAILURE);
}
}
/* no links on disk */
return (DEVFSADM_FAILURE);
}
/*
* It suffices to use 1 link to this minor, since
* we are matching with reserved IDs on the basis of
* the controller number which will be the same for
* all links to this minor.
*/
/* not reserved links */
free_dvlist(&head);
return (DEVFSADM_FAILURE);
}
/*
* Switch between SMI and EFI labels if required
*/
switch_link = 0;
assert(s);
if (s == NULL) {
devfsadm_errprint("%s: disk link %s has no "
continue;
}
(void) snprintf(l, sizeof (l), "%s%s",
switch_link = 1;
"reserved link from EFI to SMI label. "
"New link is %s\n", modname, l);
(s = strchr(s, 's'))) {
*s = '\0';
(void) snprintf(l, sizeof (l), "%s",
*s = 's';
switch_link = 1;
"reserved link from SMI to EFI label. "
"New link is %s\n", modname, l);
}
if (switch_link) {
"link: deleting %s and creating %s\n",
}
}
}
free_dvlist(&head);
/*
* return SUCCESS to indicate that new links to this minor should not
* be created so that only compatibility links to this minor remain.
*/
return (DEVFSADM_SUCCESS);
}