disk_link.c revision 97869ac5121a555decdf3080d02beef2af506da6
/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <devfsadm.h>
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
#include <bsm/devalloc.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
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;
return (DEVFSADM_CONTINUE);
}
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) {
"lun", &intp) > 0) {
} else {
lun = 0;
}
}
*str = '\0';
} else {
return (DEVFSADM_CONTINUE);
}
}
return (DEVFSADM_CONTINUE);
}
/*
* xVM virtual block device
*
* VBDs are enumerated into xenstore by xend and named using
* the linux dev_t values for 'hd' and 'xvd' devices. Linux
* dev_t's are 16-bit values. The upper 8 bits identify the major #
* of the device (hd, xvd) and the lower 8 bits the instance and partition
*
* For PV guests, VBDs are named by the virt-tools using
* created by this generator will be c0t[0-15]d[0-15]sN,
* were the target (t) value represents [a-p] and the
* disk (d) value is either 0 (e.g. xvda) or contains the partition
* information if it has been specified [1-15] (e.g. xvda1)
*
* For PV guests using the legacy naming (0, 1, 2, ...)
* the Solaris disk names created will be c0d[0..767]sN
* The Solaris version of virt-install based on virtinst.101
* named PV disks as sequential integers. With virtinst.300_1 and
* beyond, the virt-* tools will no longer create legacy disk
* names.
*/
static int
{
#define XVBDMAJ 202
char *addr;
char disk[16];
/* legacy device address */
/* PV VBD */
/* HVM device names are generated using the standard generator */
} 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;
dir = "rdsk";
} else {
dir = "dsk";
}
if (mn[0] < 113) {
} else {
/* For EFI label */
}
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);
}