10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51896Sjkennedy * Common Development and Distribution License (the "License"). 61896Sjkennedy * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*7563SPrasad.Singamsetty@Sun.COM 220Sstevel@tonic-gate /* 237464SAndrew.Balfour@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #include <dlfcn.h> 280Sstevel@tonic-gate #include <meta.h> 290Sstevel@tonic-gate #include <metadyn.h> 300Sstevel@tonic-gate #include <ctype.h> 310Sstevel@tonic-gate #include <dirent.h> 320Sstevel@tonic-gate #include <devid.h> 330Sstevel@tonic-gate #include <sys/param.h> 340Sstevel@tonic-gate #include <sys/scsi/impl/uscsi.h> 350Sstevel@tonic-gate #include <sys/scsi/generic/commands.h> 360Sstevel@tonic-gate #include <sys/scsi/generic/inquiry.h> 370Sstevel@tonic-gate #include <sys/efi_partition.h> 380Sstevel@tonic-gate 390Sstevel@tonic-gate typedef struct ctlr_cache { 400Sstevel@tonic-gate char *ctlr_nm; 410Sstevel@tonic-gate int ctlr_ty; 420Sstevel@tonic-gate struct ctlr_cache *ctlr_nx; 430Sstevel@tonic-gate } ctlr_cache_t; 440Sstevel@tonic-gate 450Sstevel@tonic-gate static ctlr_cache_t *ctlr_cache = NULL; 460Sstevel@tonic-gate 470Sstevel@tonic-gate 480Sstevel@tonic-gate /* 490Sstevel@tonic-gate * return set for a device 500Sstevel@tonic-gate */ 510Sstevel@tonic-gate mdsetname_t * 520Sstevel@tonic-gate metagetset( 530Sstevel@tonic-gate mdname_t *np, 540Sstevel@tonic-gate int bypass_daemon, 550Sstevel@tonic-gate md_error_t *ep 560Sstevel@tonic-gate ) 570Sstevel@tonic-gate { 580Sstevel@tonic-gate mdsetname_t *sp; 590Sstevel@tonic-gate 600Sstevel@tonic-gate /* metadevice */ 610Sstevel@tonic-gate if (metaismeta(np)) 620Sstevel@tonic-gate return (metasetnosetname(MD_MIN2SET(meta_getminor(np->dev)), 637464SAndrew.Balfour@Sun.COM ep)); 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* regular device */ 660Sstevel@tonic-gate if (meta_is_drive_in_anyset(np->drivenamep, &sp, bypass_daemon, 670Sstevel@tonic-gate ep) != 0) 680Sstevel@tonic-gate return (NULL); 690Sstevel@tonic-gate 700Sstevel@tonic-gate if (sp != NULL) 710Sstevel@tonic-gate return (sp); 720Sstevel@tonic-gate 730Sstevel@tonic-gate return (metasetnosetname(MD_LOCAL_SET, ep)); 740Sstevel@tonic-gate } 750Sstevel@tonic-gate 760Sstevel@tonic-gate /* 770Sstevel@tonic-gate * convert system to md types 780Sstevel@tonic-gate */ 790Sstevel@tonic-gate static void 800Sstevel@tonic-gate meta_geom_to_md( 810Sstevel@tonic-gate struct dk_geom *gp, 820Sstevel@tonic-gate mdgeom_t *mdgp 830Sstevel@tonic-gate ) 840Sstevel@tonic-gate { 850Sstevel@tonic-gate (void) memset(mdgp, '\0', sizeof (*mdgp)); 860Sstevel@tonic-gate mdgp->ncyl = gp->dkg_ncyl; 870Sstevel@tonic-gate mdgp->nhead = gp->dkg_nhead; 880Sstevel@tonic-gate mdgp->nsect = gp->dkg_nsect; 890Sstevel@tonic-gate mdgp->rpm = gp->dkg_rpm; 900Sstevel@tonic-gate mdgp->write_reinstruct = gp->dkg_write_reinstruct; 910Sstevel@tonic-gate mdgp->read_reinstruct = gp->dkg_read_reinstruct; 920Sstevel@tonic-gate mdgp->blk_sz = DEV_BSIZE; 930Sstevel@tonic-gate } 940Sstevel@tonic-gate 950Sstevel@tonic-gate /* 960Sstevel@tonic-gate * convert efi to md types 970Sstevel@tonic-gate */ 980Sstevel@tonic-gate static void 990Sstevel@tonic-gate meta_efi_to_mdgeom(struct dk_gpt *gpt, mdgeom_t *mdgp) 1000Sstevel@tonic-gate { 1010Sstevel@tonic-gate (void) memset(mdgp, '\0', sizeof (*mdgp)); 1020Sstevel@tonic-gate mdgp->ncyl = (gpt->efi_last_u_lba - gpt->efi_first_u_lba) / 1037464SAndrew.Balfour@Sun.COM (MD_EFI_FG_HEADS * MD_EFI_FG_SECTORS); 1040Sstevel@tonic-gate mdgp->nhead = MD_EFI_FG_HEADS; 1050Sstevel@tonic-gate mdgp->nsect = MD_EFI_FG_SECTORS; 1060Sstevel@tonic-gate mdgp->rpm = MD_EFI_FG_RPM; 1070Sstevel@tonic-gate mdgp->write_reinstruct = MD_EFI_FG_WRI; 1080Sstevel@tonic-gate mdgp->read_reinstruct = MD_EFI_FG_RRI; 1090Sstevel@tonic-gate mdgp->blk_sz = DEV_BSIZE; 1100Sstevel@tonic-gate } 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate static void 1130Sstevel@tonic-gate meta_efi_to_mdvtoc(struct dk_gpt *gpt, mdvtoc_t *mdvp) 1140Sstevel@tonic-gate { 1150Sstevel@tonic-gate char typename[EFI_PART_NAME_LEN]; 1160Sstevel@tonic-gate uint_t i; 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate (void) memset(mdvp, '\0', sizeof (*mdvp)); 1190Sstevel@tonic-gate mdvp->nparts = gpt->efi_nparts; 1200Sstevel@tonic-gate if (mdvp->nparts > MD_MAX_PARTS) 1210Sstevel@tonic-gate return; 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate mdvp->first_lba = gpt->efi_first_u_lba; 1240Sstevel@tonic-gate mdvp->last_lba = gpt->efi_last_u_lba; 1250Sstevel@tonic-gate mdvp->lbasize = gpt->efi_lbasize; 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate for (i = 0; (i < gpt->efi_nparts); ++i) { 1280Sstevel@tonic-gate mdvp->parts[i].start = gpt->efi_parts[i].p_start; 1290Sstevel@tonic-gate mdvp->parts[i].size = gpt->efi_parts[i].p_size; 1300Sstevel@tonic-gate mdvp->parts[i].tag = gpt->efi_parts[i].p_tag; 1310Sstevel@tonic-gate mdvp->parts[i].flag = gpt->efi_parts[i].p_flag; 1320Sstevel@tonic-gate /* 1331896Sjkennedy * It is possible to present an efi label but be using vtoc 1341896Sjkennedy * disks to create a > 1 TB metadevice. In case the first 1351896Sjkennedy * disk in the underlying metadevice is a vtoc disk and starts 1361896Sjkennedy * at the beginning of the disk it is necessary to convey this 1371896Sjkennedy * information to the user. 1381896Sjkennedy */ 1391896Sjkennedy if (mdvp->parts[i].size > 0 && 1401896Sjkennedy mdvp->parts[i].start != 0 && mdvp->nparts == 1) { 1411896Sjkennedy mdvp->parts[i].label = btodb(DK_LABEL_SIZE); 1421896Sjkennedy mdvp->parts[i].start = 0; 1431896Sjkennedy } 1441896Sjkennedy 1451896Sjkennedy /* 1460Sstevel@tonic-gate * Due to the lack of a label for the entire partition table, 1470Sstevel@tonic-gate * we use p_name of the reserved partition 1480Sstevel@tonic-gate */ 1490Sstevel@tonic-gate if ((gpt->efi_parts[i].p_tag == V_RESERVED) && 1500Sstevel@tonic-gate (gpt->efi_parts[i].p_name != NULL)) { 1510Sstevel@tonic-gate (void) strlcpy(typename, gpt->efi_parts[i].p_name, 1527464SAndrew.Balfour@Sun.COM EFI_PART_NAME_LEN); 1530Sstevel@tonic-gate /* Stop at first (if any) space or tab */ 1540Sstevel@tonic-gate (void) strtok(typename, " \t"); 1550Sstevel@tonic-gate mdvp->typename = Strdup(typename); 1560Sstevel@tonic-gate } 1570Sstevel@tonic-gate } 1580Sstevel@tonic-gate } 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate static void 1610Sstevel@tonic-gate meta_mdvtoc_to_efi(mdvtoc_t *mdvp, struct dk_gpt **gpt) 1620Sstevel@tonic-gate { 1630Sstevel@tonic-gate char typename[EFI_PART_NAME_LEN]; 1640Sstevel@tonic-gate uint_t i; 1650Sstevel@tonic-gate uint_t lastpart; 1660Sstevel@tonic-gate size_t size; 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate /* first we count how many partitions we have to send */ 1690Sstevel@tonic-gate for (i = 0; i < MD_MAX_PARTS; i++) { 1700Sstevel@tonic-gate if ((mdvp->parts[i].start == 0) && 1710Sstevel@tonic-gate (mdvp->parts[i].size == 0) && 1720Sstevel@tonic-gate (mdvp->parts[i].tag != V_RESERVED)) { 1730Sstevel@tonic-gate continue; 1740Sstevel@tonic-gate } 1750Sstevel@tonic-gate /* if we are here, we know the partition is really used */ 1760Sstevel@tonic-gate lastpart = i; 1770Sstevel@tonic-gate } 1780Sstevel@tonic-gate size = sizeof (struct dk_gpt) + (sizeof (struct dk_part) * lastpart); 1790Sstevel@tonic-gate *gpt = calloc(size, sizeof (char)); 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate (*gpt)->efi_nparts = lastpart + 1; 1820Sstevel@tonic-gate (*gpt)->efi_first_u_lba = mdvp->first_lba; 1830Sstevel@tonic-gate (*gpt)->efi_last_u_lba = mdvp->last_lba; 1840Sstevel@tonic-gate (*gpt)->efi_lbasize = mdvp->lbasize; 1850Sstevel@tonic-gate for (i = 0; (i < (*gpt)->efi_nparts); ++i) { 1860Sstevel@tonic-gate (*gpt)->efi_parts[i].p_start = mdvp->parts[i].start; 1870Sstevel@tonic-gate (*gpt)->efi_parts[i].p_size = mdvp->parts[i].size; 1880Sstevel@tonic-gate (*gpt)->efi_parts[i].p_tag = mdvp->parts[i].tag; 1890Sstevel@tonic-gate (*gpt)->efi_parts[i].p_flag = mdvp->parts[i].flag; 1900Sstevel@tonic-gate /* 1910Sstevel@tonic-gate * Due to the lack of a label for the entire partition table, 1920Sstevel@tonic-gate * we use p_name of the reserved partition 1930Sstevel@tonic-gate */ 1940Sstevel@tonic-gate if (((*gpt)->efi_parts[i].p_tag == V_RESERVED) && 1957464SAndrew.Balfour@Sun.COM (mdvp->typename != NULL)) { 1960Sstevel@tonic-gate (void) strlcpy((*gpt)->efi_parts[i].p_name, typename, 1977464SAndrew.Balfour@Sun.COM EFI_PART_NAME_LEN); 1980Sstevel@tonic-gate } 1990Sstevel@tonic-gate } 2000Sstevel@tonic-gate } 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate void 2040Sstevel@tonic-gate ctlr_cache_add(char *nm, int ty) 2050Sstevel@tonic-gate { 2060Sstevel@tonic-gate ctlr_cache_t **ccpp; 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate for (ccpp = &ctlr_cache; *ccpp != NULL; ccpp = &(*ccpp)->ctlr_nx) 2090Sstevel@tonic-gate if (strcmp((*ccpp)->ctlr_nm, nm) == 0) 2100Sstevel@tonic-gate return; 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate *ccpp = Zalloc(sizeof (ctlr_cache_t)); 2130Sstevel@tonic-gate (*ccpp)->ctlr_nm = Strdup(nm); 2140Sstevel@tonic-gate (*ccpp)->ctlr_ty = ty; 2150Sstevel@tonic-gate } 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate int 2180Sstevel@tonic-gate ctlr_cache_look(char *nm) 2190Sstevel@tonic-gate { 2200Sstevel@tonic-gate ctlr_cache_t *tcp; 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate for (tcp = ctlr_cache; tcp != NULL; tcp = tcp->ctlr_nx) 2230Sstevel@tonic-gate if (strcmp(tcp->ctlr_nm, nm) == 0) 2240Sstevel@tonic-gate return (tcp->ctlr_ty); 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate return (-1); 2270Sstevel@tonic-gate } 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate void 2310Sstevel@tonic-gate metaflushctlrcache(void) 2320Sstevel@tonic-gate { 2330Sstevel@tonic-gate ctlr_cache_t *cp, *np; 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate for (cp = ctlr_cache, np = NULL; cp != NULL; cp = np) { 2360Sstevel@tonic-gate np = cp->ctlr_nx; 2370Sstevel@tonic-gate Free(cp->ctlr_nm); 2380Sstevel@tonic-gate Free(cp); 2390Sstevel@tonic-gate } 2400Sstevel@tonic-gate ctlr_cache = NULL; 2410Sstevel@tonic-gate } 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate /* 2440Sstevel@tonic-gate * getdrvnode -- return the driver name based on mdname_t->bname 2450Sstevel@tonic-gate * Need to free pointer when finished. 2460Sstevel@tonic-gate */ 2470Sstevel@tonic-gate char * 2480Sstevel@tonic-gate getdrvnode(mdname_t *np, md_error_t *ep) 2490Sstevel@tonic-gate { 250*7563SPrasad.Singamsetty@Sun.COM char *devicespath; 251*7563SPrasad.Singamsetty@Sun.COM char *drvnode; 252*7563SPrasad.Singamsetty@Sun.COM char *cp; 2530Sstevel@tonic-gate 2540Sstevel@tonic-gate if ((devicespath = metagetdevicesname(np, ep)) == NULL) 2550Sstevel@tonic-gate return (NULL); 2560Sstevel@tonic-gate 2570Sstevel@tonic-gate /* 2580Sstevel@tonic-gate * At this point devicespath should be like the following 2590Sstevel@tonic-gate * "/devices/<unknow_and_dont_care>/xxxx@vvvv" 2600Sstevel@tonic-gate * 2610Sstevel@tonic-gate * There's a couple of 'if' statements below which could 2620Sstevel@tonic-gate * return an error condition, but I've decide to allow 2630Sstevel@tonic-gate * a more open approach regarding the mapping so as to 2640Sstevel@tonic-gate * not restrict possible future projects. 2650Sstevel@tonic-gate */ 2660Sstevel@tonic-gate if (drvnode = strrchr(devicespath, '/')) 2670Sstevel@tonic-gate /* 2680Sstevel@tonic-gate * drvnode now just "xxxx@vvvv" 2690Sstevel@tonic-gate */ 2700Sstevel@tonic-gate drvnode++; 2710Sstevel@tonic-gate 2720Sstevel@tonic-gate if (cp = strrchr(drvnode, '@')) 2730Sstevel@tonic-gate /* 2740Sstevel@tonic-gate * Now drvnode is just the driver name "xxxx" 2750Sstevel@tonic-gate */ 2760Sstevel@tonic-gate *cp = '\0'; 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate cp = Strdup(drvnode); 2790Sstevel@tonic-gate Free(devicespath); 2800Sstevel@tonic-gate np->devicesname = NULL; 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate return (cp); 2830Sstevel@tonic-gate } 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate /* 2860Sstevel@tonic-gate * meta_load_dl -- open dynamic library using LDLIBRARYPATH, a debug 2870Sstevel@tonic-gate * environment variable METALDPATH, or the default location. 2880Sstevel@tonic-gate */ 2890Sstevel@tonic-gate static void * 2900Sstevel@tonic-gate meta_load_dl(mdname_t *np, md_error_t *ep) 2910Sstevel@tonic-gate { 292*7563SPrasad.Singamsetty@Sun.COM char *drvnode; 293*7563SPrasad.Singamsetty@Sun.COM char newpath[MAXPATHLEN]; 294*7563SPrasad.Singamsetty@Sun.COM char *p; 2950Sstevel@tonic-gate void *cookie; 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate if ((drvnode = getdrvnode(np, ep)) != NULL) { 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate /* 3000Sstevel@tonic-gate * Library seach algorithm: 3010Sstevel@tonic-gate * 1) Use LDLIBRARYPATH which is implied when a non-absolute 3020Sstevel@tonic-gate * path name is passed to dlopen() 3030Sstevel@tonic-gate * 2) Use the value of METALDPATH as the directory. Mainly 3040Sstevel@tonic-gate * used for debugging 3050Sstevel@tonic-gate * 3) Last search the default location of "/usr/lib" 3060Sstevel@tonic-gate */ 3070Sstevel@tonic-gate (void) snprintf(newpath, sizeof (newpath), "lib%s.so.1", 3080Sstevel@tonic-gate drvnode); 3090Sstevel@tonic-gate if ((cookie = dlopen(newpath, RTLD_LAZY)) == NULL) { 3100Sstevel@tonic-gate if ((p = getenv("METALDPATH")) == NULL) 3110Sstevel@tonic-gate p = METALDPATH_DEFAULT; 3120Sstevel@tonic-gate (void) snprintf(newpath, sizeof (newpath), 3130Sstevel@tonic-gate "%s/lib%s.so.1", p, drvnode); 3140Sstevel@tonic-gate Free(drvnode); 3150Sstevel@tonic-gate if ((cookie = dlopen(newpath, RTLD_LAZY)) != NULL) { 3160Sstevel@tonic-gate /* 3170Sstevel@tonic-gate * Common failure here would be failing to 3180Sstevel@tonic-gate * find a libXX.so.1 such as libsd.so.1 3190Sstevel@tonic-gate * Some controllers will not have a library 3200Sstevel@tonic-gate * because there's no enclosure or name 3210Sstevel@tonic-gate * translation required. 3220Sstevel@tonic-gate */ 3230Sstevel@tonic-gate return (cookie); 3240Sstevel@tonic-gate } 3250Sstevel@tonic-gate } else { 3260Sstevel@tonic-gate Free(drvnode); 3270Sstevel@tonic-gate return (cookie); 3280Sstevel@tonic-gate } 3290Sstevel@tonic-gate } 3300Sstevel@tonic-gate return (NULL); 3310Sstevel@tonic-gate } 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate /* 3340Sstevel@tonic-gate * meta_match_names -- possibly convert the driver names returned by CINFO 3350Sstevel@tonic-gate */ 3360Sstevel@tonic-gate static void 3370Sstevel@tonic-gate meta_match_names(mdname_t *np, struct dk_cinfo *cp, mdcinfo_t *mdcp, 3380Sstevel@tonic-gate md_error_t *ep) 3390Sstevel@tonic-gate { 3400Sstevel@tonic-gate void *cookie; 3410Sstevel@tonic-gate meta_convert_e ((*fptr)(mdname_t *, struct dk_cinfo *, mdcinfo_t *, 3427464SAndrew.Balfour@Sun.COM md_error_t *)); 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate if ((cookie = meta_load_dl(np, ep)) != NULL) { 3450Sstevel@tonic-gate fptr = (meta_convert_e (*)(mdname_t *, struct dk_cinfo *, 3460Sstevel@tonic-gate mdcinfo_t *, md_error_t *))dlsym(cookie, "convert_path"); 3470Sstevel@tonic-gate if (fptr != NULL) 3480Sstevel@tonic-gate (void) (*fptr)(np, cp, mdcp, ep); 3490Sstevel@tonic-gate (void) dlclose(cookie); 3500Sstevel@tonic-gate } 3510Sstevel@tonic-gate } 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate /* 3540Sstevel@tonic-gate * meta_match_enclosure -- return any enclosure info if found 3550Sstevel@tonic-gate */ 3560Sstevel@tonic-gate int 3570Sstevel@tonic-gate meta_match_enclosure(mdname_t *np, mdcinfo_t *mdcp, md_error_t *ep) 3580Sstevel@tonic-gate { 359*7563SPrasad.Singamsetty@Sun.COM meta_enclosure_e e; 360*7563SPrasad.Singamsetty@Sun.COM meta_enclosure_e ((*fptr)(mdname_t *, mdcinfo_t *, 3617464SAndrew.Balfour@Sun.COM md_error_t *)); 3620Sstevel@tonic-gate void *cookie; 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate if ((cookie = meta_load_dl(np, ep)) != NULL) { 3650Sstevel@tonic-gate fptr = (meta_enclosure_e (*)(mdname_t *, mdcinfo_t *, 3660Sstevel@tonic-gate md_error_t *))dlsym(cookie, "get_enclosure"); 3670Sstevel@tonic-gate if (fptr != NULL) { 3680Sstevel@tonic-gate e = (*fptr)(np, mdcp, ep); 3690Sstevel@tonic-gate switch (e) { 3700Sstevel@tonic-gate case Enclosure_Error: 3710Sstevel@tonic-gate /* 3720Sstevel@tonic-gate * Looks like this library wanted to handle 3730Sstevel@tonic-gate * our device and had an internal error. 3740Sstevel@tonic-gate */ 3750Sstevel@tonic-gate return (1); 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate case Enclosure_Okay: 3780Sstevel@tonic-gate /* 3790Sstevel@tonic-gate * Found a library to handle the request so 3800Sstevel@tonic-gate * just return with data provided. 3810Sstevel@tonic-gate */ 3820Sstevel@tonic-gate return (0); 3830Sstevel@tonic-gate 3840Sstevel@tonic-gate case Enclosure_Noop: 3850Sstevel@tonic-gate /* 3860Sstevel@tonic-gate * Need to continue the search 3870Sstevel@tonic-gate */ 3880Sstevel@tonic-gate break; 3890Sstevel@tonic-gate } 3900Sstevel@tonic-gate } 3910Sstevel@tonic-gate (void) dlclose(cookie); 3920Sstevel@tonic-gate } 3930Sstevel@tonic-gate return (0); 3940Sstevel@tonic-gate } 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate static int 3970Sstevel@tonic-gate meta_cinfo_to_md(mdname_t *np, struct dk_cinfo *cp, mdcinfo_t *mdcp, 3980Sstevel@tonic-gate md_error_t *ep) 3990Sstevel@tonic-gate { 4000Sstevel@tonic-gate /* default */ 4010Sstevel@tonic-gate (void) memset(mdcp, '\0', sizeof (*mdcp)); 4020Sstevel@tonic-gate (void) strncpy(mdcp->cname, cp->dki_cname, 4030Sstevel@tonic-gate min((sizeof (mdcp->cname) - 1), sizeof (cp->dki_cname))); 4040Sstevel@tonic-gate mdcp->ctype = MHD_CTLR_GENERIC; 4050Sstevel@tonic-gate mdcp->cnum = cp->dki_cnum; 4060Sstevel@tonic-gate (void) strncpy(mdcp->dname, cp->dki_dname, 4070Sstevel@tonic-gate min((sizeof (mdcp->dname) - 1), sizeof (cp->dki_dname))); 4080Sstevel@tonic-gate mdcp->unit = cp->dki_unit; 4090Sstevel@tonic-gate mdcp->maxtransfer = cp->dki_maxtransfer; 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate /* 4120Sstevel@tonic-gate * See if the driver name returned from DKIOCINFO 4130Sstevel@tonic-gate * is valid or not. In somecases, such as the ap_dmd 4140Sstevel@tonic-gate * driver, we need to modify the name that's return 4150Sstevel@tonic-gate * for everything to work. 4160Sstevel@tonic-gate */ 4170Sstevel@tonic-gate meta_match_names(np, cp, mdcp, ep); 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate if (meta_match_enclosure(np, mdcp, ep)) 4200Sstevel@tonic-gate return (-1); 4210Sstevel@tonic-gate 4220Sstevel@tonic-gate /* return success */ 4230Sstevel@tonic-gate return (0); 4240Sstevel@tonic-gate } 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate static void 4270Sstevel@tonic-gate meta_vtoc_to_md( 428*7563SPrasad.Singamsetty@Sun.COM struct extvtoc *vp, 4290Sstevel@tonic-gate mdvtoc_t *mdvp 4300Sstevel@tonic-gate ) 4310Sstevel@tonic-gate { 4320Sstevel@tonic-gate char typename[sizeof (vp->v_asciilabel) + 1]; 4330Sstevel@tonic-gate uint_t i; 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate (void) memset(mdvp, '\0', sizeof (*mdvp)); 4360Sstevel@tonic-gate (void) strncpy(typename, vp->v_asciilabel, 4370Sstevel@tonic-gate sizeof (vp->v_asciilabel)); 4380Sstevel@tonic-gate typename[sizeof (typename) - 1] = '\0'; 4390Sstevel@tonic-gate for (i = 0; ((i < sizeof (typename)) && (typename[i] != '\0')); ++i) { 4400Sstevel@tonic-gate if ((typename[i] == ' ') || (typename[i] == '\t')) { 4410Sstevel@tonic-gate typename[i] = '\0'; 4420Sstevel@tonic-gate break; 4430Sstevel@tonic-gate } 4440Sstevel@tonic-gate } 4450Sstevel@tonic-gate mdvp->typename = Strdup(typename); 4460Sstevel@tonic-gate mdvp->nparts = vp->v_nparts; 4470Sstevel@tonic-gate for (i = 0; (i < vp->v_nparts); ++i) { 4480Sstevel@tonic-gate mdvp->parts[i].start = vp->v_part[i].p_start; 4490Sstevel@tonic-gate mdvp->parts[i].size = vp->v_part[i].p_size; 4500Sstevel@tonic-gate mdvp->parts[i].tag = vp->v_part[i].p_tag; 4510Sstevel@tonic-gate mdvp->parts[i].flag = vp->v_part[i].p_flag; 4520Sstevel@tonic-gate if (vp->v_part[i].p_start == 0 && vp->v_part[i].p_size > 0) 4530Sstevel@tonic-gate mdvp->parts[i].label = btodb(DK_LABEL_SIZE); 4540Sstevel@tonic-gate } 4550Sstevel@tonic-gate } 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate /* 4580Sstevel@tonic-gate * free allocations in vtoc 4590Sstevel@tonic-gate */ 4600Sstevel@tonic-gate void 4610Sstevel@tonic-gate metafreevtoc( 4620Sstevel@tonic-gate mdvtoc_t *vtocp 4630Sstevel@tonic-gate ) 4640Sstevel@tonic-gate { 4650Sstevel@tonic-gate if (vtocp->typename != NULL) 4660Sstevel@tonic-gate Free(vtocp->typename); 4670Sstevel@tonic-gate (void) memset(vtocp, 0, sizeof (*vtocp)); 4680Sstevel@tonic-gate } 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate /* 4710Sstevel@tonic-gate * return md types 4720Sstevel@tonic-gate */ 4730Sstevel@tonic-gate mdvtoc_t * 4740Sstevel@tonic-gate metagetvtoc( 4750Sstevel@tonic-gate mdname_t *np, /* only rname, drivenamep, are setup */ 4760Sstevel@tonic-gate int nocache, 4770Sstevel@tonic-gate uint_t *partnop, 4780Sstevel@tonic-gate md_error_t *ep 4790Sstevel@tonic-gate ) 4800Sstevel@tonic-gate { 4810Sstevel@tonic-gate mddrivename_t *dnp = np->drivenamep; 4820Sstevel@tonic-gate struct dk_geom geom; 4830Sstevel@tonic-gate char *minor_name = NULL; 4840Sstevel@tonic-gate char *rname = np->rname; 4850Sstevel@tonic-gate int fd; 4860Sstevel@tonic-gate int partno; 4870Sstevel@tonic-gate int err = 0; /* saves errno from ioctl */ 4880Sstevel@tonic-gate ddi_devid_t devid; 4890Sstevel@tonic-gate char *p; 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate /* short circuit */ 4920Sstevel@tonic-gate if ((! nocache) && (dnp->vtoc.nparts != 0)) { 4930Sstevel@tonic-gate if (partnop != NULL) { 4940Sstevel@tonic-gate /* 4950Sstevel@tonic-gate * the following assigment works because the 4960Sstevel@tonic-gate * mdname_t structs are always created as part 4970Sstevel@tonic-gate * of the drivenamep struct. When a user 4980Sstevel@tonic-gate * creates an mdname_t struct it either 4990Sstevel@tonic-gate * uses an existing drivenamep struct or creates 5000Sstevel@tonic-gate * a new one and then adds the mdname_t struct 5010Sstevel@tonic-gate * as part of its parts_val array. So what is 5020Sstevel@tonic-gate * being computed below is the slice offset in 5030Sstevel@tonic-gate * the parts_val array. 5040Sstevel@tonic-gate */ 5050Sstevel@tonic-gate *partnop = np - np->drivenamep->parts.parts_val; 5060Sstevel@tonic-gate assert(*partnop < dnp->parts.parts_len); 5070Sstevel@tonic-gate } 5080Sstevel@tonic-gate return (&dnp->vtoc); 5090Sstevel@tonic-gate } 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate /* can't get vtoc */ 5120Sstevel@tonic-gate if (! nocache) { 5130Sstevel@tonic-gate switch (dnp->type) { 5140Sstevel@tonic-gate case MDT_ACCES: 5150Sstevel@tonic-gate case MDT_UNKNOWN: 5160Sstevel@tonic-gate (void) mdsyserror(ep, dnp->errnum, rname); 5170Sstevel@tonic-gate return (NULL); 5180Sstevel@tonic-gate } 5190Sstevel@tonic-gate } 5200Sstevel@tonic-gate 5210Sstevel@tonic-gate /* get all the info */ 5220Sstevel@tonic-gate if ((fd = open(rname, (O_RDONLY|O_NDELAY), 0)) < 0) { 5230Sstevel@tonic-gate (void) mdsyserror(ep, errno, rname); 5240Sstevel@tonic-gate return (NULL); 5250Sstevel@tonic-gate } 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate /* 5280Sstevel@tonic-gate * The disk is open so this is a good point to get the devid 5290Sstevel@tonic-gate * otherwise it will need to be done at another time which 5300Sstevel@tonic-gate * means reopening it. 5310Sstevel@tonic-gate */ 5320Sstevel@tonic-gate if (devid_get(fd, &devid) != 0) { 5330Sstevel@tonic-gate /* there is no devid for the disk */ 5340Sstevel@tonic-gate if (((p = getenv("MD_DEBUG")) != NULL) && 5350Sstevel@tonic-gate (strstr(p, "DEVID") != NULL)) { 5360Sstevel@tonic-gate (void) fprintf(stderr, dgettext(TEXT_DOMAIN, 5370Sstevel@tonic-gate "%s has no device id\n"), np->rname); 5380Sstevel@tonic-gate } 5390Sstevel@tonic-gate np->minor_name = (char *)NULL; 5400Sstevel@tonic-gate dnp->devid = NULL; 5410Sstevel@tonic-gate } else { 5420Sstevel@tonic-gate (void) devid_get_minor_name(fd, &minor_name); 5430Sstevel@tonic-gate /* 5440Sstevel@tonic-gate * The minor name could be NULL if the underlying 5450Sstevel@tonic-gate * device driver does not support 'minor names'. 5460Sstevel@tonic-gate * This means we do not use devid's for this device. 5470Sstevel@tonic-gate * SunCluster did driver does not support minor names. 5480Sstevel@tonic-gate */ 5490Sstevel@tonic-gate if (minor_name != NULL) { 5500Sstevel@tonic-gate np->minor_name = Strdup(minor_name); 5510Sstevel@tonic-gate devid_str_free(minor_name); 5520Sstevel@tonic-gate dnp->devid = devid_str_encode(devid, NULL); 5530Sstevel@tonic-gate } else { 5540Sstevel@tonic-gate np->minor_name = (char *)NULL; 5550Sstevel@tonic-gate dnp->devid = NULL; 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate if (((p = getenv("MD_DEBUG")) != NULL) && 5580Sstevel@tonic-gate (strstr(p, "DEVID") != NULL)) { 5590Sstevel@tonic-gate (void) fprintf(stderr, dgettext(TEXT_DOMAIN, 5600Sstevel@tonic-gate "%s no minor name (no devid)\n"), 5610Sstevel@tonic-gate np->rname); 5620Sstevel@tonic-gate } 5630Sstevel@tonic-gate } 5640Sstevel@tonic-gate devid_free(devid); 5650Sstevel@tonic-gate } 5660Sstevel@tonic-gate 5670Sstevel@tonic-gate /* 5680Sstevel@tonic-gate * if our drivenamep points to a device not supporting DKIOCGGEOM, 5690Sstevel@tonic-gate * it's likely to have an EFI label. 5700Sstevel@tonic-gate */ 5710Sstevel@tonic-gate (void) memset(&geom, 0, sizeof (geom)); 5720Sstevel@tonic-gate if (ioctl(fd, DKIOCGGEOM, &geom) != 0) { 5730Sstevel@tonic-gate err = errno; 5740Sstevel@tonic-gate if (err == ENOTTY) { 5750Sstevel@tonic-gate (void) mddeverror(ep, MDE_NOT_DISK, NODEV, rname); 5760Sstevel@tonic-gate (void) close(fd); 5770Sstevel@tonic-gate return (NULL); 5780Sstevel@tonic-gate } else if (err != ENOTSUP) { 5790Sstevel@tonic-gate (void) mdsyserror(ep, err, rname); 5800Sstevel@tonic-gate (void) close(fd); 5810Sstevel@tonic-gate return (NULL); 5820Sstevel@tonic-gate } 5830Sstevel@tonic-gate 5840Sstevel@tonic-gate } 5850Sstevel@tonic-gate /* 5860Sstevel@tonic-gate * If we are here, there was either no failure on DKIOCGGEOM or 5870Sstevel@tonic-gate * the failure was ENOTSUP 5880Sstevel@tonic-gate */ 5890Sstevel@tonic-gate if (err == ENOTSUP) { 5900Sstevel@tonic-gate /* DKIOCGGEOM yielded ENOTSUP => try efi_alloc_and_read */ 5910Sstevel@tonic-gate struct dk_gpt *gpt; 5920Sstevel@tonic-gate int save_errno; 5930Sstevel@tonic-gate 5940Sstevel@tonic-gate /* this also sets errno */ 5950Sstevel@tonic-gate partno = efi_alloc_and_read(fd, &gpt); 5960Sstevel@tonic-gate save_errno = errno; 5970Sstevel@tonic-gate (void) close(fd); 5980Sstevel@tonic-gate if (partno < 0) { 5990Sstevel@tonic-gate efi_free(gpt); 6000Sstevel@tonic-gate (void) mdsyserror(ep, save_errno, rname); 6010Sstevel@tonic-gate return (NULL); 6020Sstevel@tonic-gate } 6030Sstevel@tonic-gate if (partno >= gpt->efi_nparts) { 6040Sstevel@tonic-gate efi_free(gpt); 6050Sstevel@tonic-gate (void) mddeverror(ep, MDE_INVALID_PART, NODEV64, 6067464SAndrew.Balfour@Sun.COM rname); 6070Sstevel@tonic-gate return (NULL); 6080Sstevel@tonic-gate } 6090Sstevel@tonic-gate 6100Sstevel@tonic-gate /* convert to our format */ 6110Sstevel@tonic-gate metafreevtoc(&dnp->vtoc); 6120Sstevel@tonic-gate meta_efi_to_mdvtoc(gpt, &dnp->vtoc); 6130Sstevel@tonic-gate if (dnp->vtoc.nparts > MD_MAX_PARTS) { 6140Sstevel@tonic-gate (void) mddeverror(ep, MDE_TOO_MANY_PARTS, NODEV64, 6150Sstevel@tonic-gate rname); 6160Sstevel@tonic-gate return (NULL); 6170Sstevel@tonic-gate } 6180Sstevel@tonic-gate /* 6190Sstevel@tonic-gate * libmeta needs at least V_NUMPAR partitions. 6200Sstevel@tonic-gate * If we have an EFI partition with less than V_NUMPAR slices, 6210Sstevel@tonic-gate * we nevertheless reserve space for V_NUMPAR 6220Sstevel@tonic-gate */ 6230Sstevel@tonic-gate 6240Sstevel@tonic-gate if (dnp->vtoc.nparts < V_NUMPAR) { 6250Sstevel@tonic-gate dnp->vtoc.nparts = V_NUMPAR; 6260Sstevel@tonic-gate } 6270Sstevel@tonic-gate meta_efi_to_mdgeom(gpt, &dnp->geom); 6280Sstevel@tonic-gate efi_free(gpt); 6290Sstevel@tonic-gate } else { 6300Sstevel@tonic-gate /* no error on DKIOCGGEOM, try meta_getvtoc */ 631*7563SPrasad.Singamsetty@Sun.COM struct extvtoc vtoc; 6320Sstevel@tonic-gate 6330Sstevel@tonic-gate if (meta_getvtoc(fd, np->cname, &vtoc, &partno, ep) < 0) { 6340Sstevel@tonic-gate (void) close(fd); 6350Sstevel@tonic-gate return (NULL); 6360Sstevel@tonic-gate } 6370Sstevel@tonic-gate (void) close(fd); 6380Sstevel@tonic-gate 6390Sstevel@tonic-gate /* convert to our format */ 6400Sstevel@tonic-gate meta_geom_to_md(&geom, &dnp->geom); 6410Sstevel@tonic-gate metafreevtoc(&dnp->vtoc); 6420Sstevel@tonic-gate meta_vtoc_to_md(&vtoc, &dnp->vtoc); 6430Sstevel@tonic-gate } 6440Sstevel@tonic-gate 6450Sstevel@tonic-gate /* fix up any drives which are now accessible */ 6460Sstevel@tonic-gate if ((nocache) && (dnp->type == MDT_ACCES) && 6470Sstevel@tonic-gate (dnp->vtoc.nparts == dnp->parts.parts_len)) { 6480Sstevel@tonic-gate dnp->type = MDT_COMP; 6490Sstevel@tonic-gate dnp->errnum = 0; 6500Sstevel@tonic-gate } 6510Sstevel@tonic-gate 6520Sstevel@tonic-gate /* save partno */ 6530Sstevel@tonic-gate assert(partno < dnp->vtoc.nparts); 6540Sstevel@tonic-gate if (partnop != NULL) 6550Sstevel@tonic-gate *partnop = partno; 6560Sstevel@tonic-gate 6570Sstevel@tonic-gate /* return info */ 6580Sstevel@tonic-gate return (&dnp->vtoc); 6590Sstevel@tonic-gate } 6600Sstevel@tonic-gate 6610Sstevel@tonic-gate static void 6620Sstevel@tonic-gate meta_mdvtoc_to_vtoc( 6630Sstevel@tonic-gate mdvtoc_t *mdvp, 664*7563SPrasad.Singamsetty@Sun.COM struct extvtoc *vp 6650Sstevel@tonic-gate ) 6660Sstevel@tonic-gate { 6670Sstevel@tonic-gate uint_t i; 6680Sstevel@tonic-gate 6690Sstevel@tonic-gate (void) memset(&vp->v_part, '\0', sizeof (vp->v_part)); 6700Sstevel@tonic-gate vp->v_nparts = (ushort_t)mdvp->nparts; 6710Sstevel@tonic-gate for (i = 0; (i < mdvp->nparts); ++i) { 672*7563SPrasad.Singamsetty@Sun.COM vp->v_part[i].p_start = mdvp->parts[i].start; 673*7563SPrasad.Singamsetty@Sun.COM vp->v_part[i].p_size = mdvp->parts[i].size; 6740Sstevel@tonic-gate vp->v_part[i].p_tag = mdvp->parts[i].tag; 6750Sstevel@tonic-gate vp->v_part[i].p_flag = mdvp->parts[i].flag; 6760Sstevel@tonic-gate } 6770Sstevel@tonic-gate } 6780Sstevel@tonic-gate 6790Sstevel@tonic-gate /* 6800Sstevel@tonic-gate * Set the vtoc, but use the cached copy to get the info from. 6810Sstevel@tonic-gate * We write np->drivenamep->vtoc to disk. 6820Sstevel@tonic-gate * Before we can do this we read the vtoc in. 6830Sstevel@tonic-gate * if we're dealing with a metadevice and this metadevice is a 64 bit device 6840Sstevel@tonic-gate * we can use meta_getmdvtoc/meta_setmdvtoc 6850Sstevel@tonic-gate * else 6860Sstevel@tonic-gate * we use meta_getvtoc/meta_setvtoc but than we first have to convert 6870Sstevel@tonic-gate * dnp->vtoc (actually being a mdvtoc_t) into a vtoc_t 6880Sstevel@tonic-gate */ 6890Sstevel@tonic-gate int 6900Sstevel@tonic-gate metasetvtoc( 6910Sstevel@tonic-gate mdname_t *np, 6920Sstevel@tonic-gate md_error_t *ep 6930Sstevel@tonic-gate ) 6940Sstevel@tonic-gate { 6950Sstevel@tonic-gate char *rname = np->rname; 6960Sstevel@tonic-gate mddrivename_t *dnp = np->drivenamep; 6970Sstevel@tonic-gate int fd; 6980Sstevel@tonic-gate int err; 6990Sstevel@tonic-gate int save_errno; 7000Sstevel@tonic-gate struct dk_geom geom; 7010Sstevel@tonic-gate 7020Sstevel@tonic-gate if ((fd = open(rname, (O_RDONLY | O_NDELAY), 0)) < 0) 7030Sstevel@tonic-gate return (mdsyserror(ep, errno, rname)); 7040Sstevel@tonic-gate 7050Sstevel@tonic-gate err = ioctl(fd, DKIOCGGEOM, &geom); 7060Sstevel@tonic-gate save_errno = errno; 7070Sstevel@tonic-gate if (err == 0) { 708*7563SPrasad.Singamsetty@Sun.COM struct extvtoc vtoc; 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate if (meta_getvtoc(fd, np->cname, &vtoc, NULL, ep) < 0) { 7110Sstevel@tonic-gate (void) close(fd); 7120Sstevel@tonic-gate return (-1); 7130Sstevel@tonic-gate } 7140Sstevel@tonic-gate 7150Sstevel@tonic-gate meta_mdvtoc_to_vtoc(&dnp->vtoc, &vtoc); 7160Sstevel@tonic-gate 7170Sstevel@tonic-gate if (meta_setvtoc(fd, np->cname, &vtoc, ep) < 0) { 7180Sstevel@tonic-gate (void) close(fd); 7190Sstevel@tonic-gate return (-1); 7200Sstevel@tonic-gate } 7210Sstevel@tonic-gate } else if (save_errno == ENOTSUP) { 7220Sstevel@tonic-gate struct dk_gpt *gpt; 7230Sstevel@tonic-gate int ret; 7240Sstevel@tonic-gate 7250Sstevel@tonic-gate /* allocation of gpt is done in meta_mdvtoc_to_efi */ 7260Sstevel@tonic-gate meta_mdvtoc_to_efi(&dnp->vtoc, &gpt); 7270Sstevel@tonic-gate 7280Sstevel@tonic-gate ret = efi_write(fd, gpt); 7290Sstevel@tonic-gate save_errno = errno; 7300Sstevel@tonic-gate free(gpt); 7310Sstevel@tonic-gate if (ret != 0) { 7320Sstevel@tonic-gate (void) close(fd); 7330Sstevel@tonic-gate return (mdsyserror(ep, save_errno, rname)); 7340Sstevel@tonic-gate } else { 7350Sstevel@tonic-gate (void) close(fd); 7360Sstevel@tonic-gate return (0); 7370Sstevel@tonic-gate } 7380Sstevel@tonic-gate 7390Sstevel@tonic-gate } else { 7400Sstevel@tonic-gate (void) close(fd); 7410Sstevel@tonic-gate return (mdsyserror(ep, save_errno, rname)); 7420Sstevel@tonic-gate } 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate (void) close(fd); 7450Sstevel@tonic-gate 7460Sstevel@tonic-gate return (0); 7470Sstevel@tonic-gate } 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate mdgeom_t * 7500Sstevel@tonic-gate metagetgeom( 7510Sstevel@tonic-gate mdname_t *np, /* only rname, drivenamep, are setup */ 7520Sstevel@tonic-gate md_error_t *ep 7530Sstevel@tonic-gate ) 7540Sstevel@tonic-gate { 7550Sstevel@tonic-gate if (metagetvtoc(np, FALSE, NULL, ep) == NULL) 7560Sstevel@tonic-gate return (NULL); 7570Sstevel@tonic-gate return (&np->drivenamep->geom); 7580Sstevel@tonic-gate } 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate mdcinfo_t * 7610Sstevel@tonic-gate metagetcinfo( 7620Sstevel@tonic-gate mdname_t *np, /* only rname, drivenamep, are setup */ 7630Sstevel@tonic-gate md_error_t *ep 7640Sstevel@tonic-gate ) 7650Sstevel@tonic-gate { 7660Sstevel@tonic-gate char *rname = np->rname; 7670Sstevel@tonic-gate mddrivename_t *dnp = np->drivenamep; 7680Sstevel@tonic-gate int fd; 7690Sstevel@tonic-gate struct dk_cinfo cinfo; 7700Sstevel@tonic-gate 7710Sstevel@tonic-gate /* short circuit */ 7720Sstevel@tonic-gate if (dnp->cinfo.cname[0] != '\0') 7730Sstevel@tonic-gate return (&dnp->cinfo); 7740Sstevel@tonic-gate 7750Sstevel@tonic-gate /* get controller info */ 7760Sstevel@tonic-gate if ((fd = open(rname, (O_RDONLY|O_NDELAY), 0)) < 0) { 7770Sstevel@tonic-gate (void) mdsyserror(ep, errno, rname); 7780Sstevel@tonic-gate return (NULL); 7790Sstevel@tonic-gate } 7800Sstevel@tonic-gate if (ioctl(fd, DKIOCINFO, &cinfo) != 0) { 7810Sstevel@tonic-gate int save = errno; 7820Sstevel@tonic-gate 7830Sstevel@tonic-gate (void) close(fd); 7840Sstevel@tonic-gate if (save == ENOTTY) { 7850Sstevel@tonic-gate (void) mddeverror(ep, MDE_NOT_DISK, NODEV64, rname); 7860Sstevel@tonic-gate } else { 7870Sstevel@tonic-gate (void) mdsyserror(ep, save, rname); 7880Sstevel@tonic-gate } 7890Sstevel@tonic-gate return (NULL); 7900Sstevel@tonic-gate } 7910Sstevel@tonic-gate (void) close(fd); /* sd/ssd bug */ 7920Sstevel@tonic-gate 7930Sstevel@tonic-gate /* convert to our format */ 7940Sstevel@tonic-gate if (meta_cinfo_to_md(np, &cinfo, &dnp->cinfo, ep) != 0) 7950Sstevel@tonic-gate return (NULL); 7960Sstevel@tonic-gate 7970Sstevel@tonic-gate /* return info */ 7980Sstevel@tonic-gate return (&dnp->cinfo); 7990Sstevel@tonic-gate } 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate /* 8020Sstevel@tonic-gate * get partition number 8030Sstevel@tonic-gate */ 8040Sstevel@tonic-gate int 8050Sstevel@tonic-gate metagetpartno( 8060Sstevel@tonic-gate mdname_t *np, 8070Sstevel@tonic-gate md_error_t *ep 8080Sstevel@tonic-gate ) 8090Sstevel@tonic-gate { 8100Sstevel@tonic-gate mdvtoc_t *vtocp; 8110Sstevel@tonic-gate uint_t partno; 8120Sstevel@tonic-gate 8130Sstevel@tonic-gate if ((vtocp = metagetvtoc(np, FALSE, &partno, ep)) == NULL) 8140Sstevel@tonic-gate return (-1); 8150Sstevel@tonic-gate assert(partno < vtocp->nparts); 8160Sstevel@tonic-gate return (partno); 8170Sstevel@tonic-gate } 8180Sstevel@tonic-gate 8190Sstevel@tonic-gate /* 8200Sstevel@tonic-gate * get size of device 8210Sstevel@tonic-gate */ 8220Sstevel@tonic-gate diskaddr_t 8230Sstevel@tonic-gate metagetsize( 8240Sstevel@tonic-gate mdname_t *np, 8250Sstevel@tonic-gate md_error_t *ep 8260Sstevel@tonic-gate ) 8270Sstevel@tonic-gate { 8280Sstevel@tonic-gate mdvtoc_t *vtocp; 8290Sstevel@tonic-gate uint_t partno; 8300Sstevel@tonic-gate 8310Sstevel@tonic-gate if ((vtocp = metagetvtoc(np, FALSE, &partno, ep)) == NULL) 8320Sstevel@tonic-gate return (MD_DISKADDR_ERROR); 8330Sstevel@tonic-gate assert(partno < vtocp->nparts); 8340Sstevel@tonic-gate return (vtocp->parts[partno].size); 8350Sstevel@tonic-gate } 8360Sstevel@tonic-gate 8370Sstevel@tonic-gate /* 8380Sstevel@tonic-gate * get label of device 8390Sstevel@tonic-gate */ 8400Sstevel@tonic-gate diskaddr_t 8410Sstevel@tonic-gate metagetlabel( 8420Sstevel@tonic-gate mdname_t *np, 8430Sstevel@tonic-gate md_error_t *ep 8440Sstevel@tonic-gate ) 8450Sstevel@tonic-gate { 8460Sstevel@tonic-gate mdvtoc_t *vtocp; 8470Sstevel@tonic-gate uint_t partno; 8480Sstevel@tonic-gate 8490Sstevel@tonic-gate if ((vtocp = metagetvtoc(np, FALSE, &partno, ep)) == NULL) 8500Sstevel@tonic-gate return (MD_DISKADDR_ERROR); 8510Sstevel@tonic-gate assert(partno < vtocp->nparts); 8520Sstevel@tonic-gate return (vtocp->parts[partno].label); 8530Sstevel@tonic-gate } 8540Sstevel@tonic-gate 8550Sstevel@tonic-gate /* 8560Sstevel@tonic-gate * find out where database replicas end 8570Sstevel@tonic-gate */ 8580Sstevel@tonic-gate static int 8590Sstevel@tonic-gate mddb_getendblk( 8600Sstevel@tonic-gate mdsetname_t *sp, 8610Sstevel@tonic-gate mdname_t *np, 8620Sstevel@tonic-gate diskaddr_t *endblkp, 8630Sstevel@tonic-gate md_error_t *ep 8640Sstevel@tonic-gate ) 8650Sstevel@tonic-gate { 8660Sstevel@tonic-gate md_replicalist_t *rlp = NULL; 8670Sstevel@tonic-gate md_replicalist_t *rl; 8680Sstevel@tonic-gate 8690Sstevel@tonic-gate /* make sure we have a component */ 8700Sstevel@tonic-gate *endblkp = 0; 8710Sstevel@tonic-gate if (metaismeta(np)) 8720Sstevel@tonic-gate return (0); 8730Sstevel@tonic-gate 8740Sstevel@tonic-gate /* get replicas, quit if none */ 8750Sstevel@tonic-gate if (metareplicalist(sp, MD_BASICNAME_OK | PRINT_FAST, &rlp, ep) < 0) { 8760Sstevel@tonic-gate if (! mdismddberror(ep, MDE_DB_NODB)) 8770Sstevel@tonic-gate return (-1); 8780Sstevel@tonic-gate mdclrerror(ep); 8790Sstevel@tonic-gate return (0); 8800Sstevel@tonic-gate } else if (rlp == NULL) 8810Sstevel@tonic-gate return (0); 8820Sstevel@tonic-gate 8830Sstevel@tonic-gate /* go through all the replicas */ 8840Sstevel@tonic-gate for (rl = rlp; (rl != NULL); rl = rl->rl_next) { 8850Sstevel@tonic-gate md_replica_t *rp = rl->rl_repp; 8860Sstevel@tonic-gate mdname_t *repnamep = rp->r_namep; 8870Sstevel@tonic-gate diskaddr_t dbend; 8880Sstevel@tonic-gate 8890Sstevel@tonic-gate if (np->dev != repnamep->dev) 8900Sstevel@tonic-gate continue; 8910Sstevel@tonic-gate dbend = rp->r_blkno + rp->r_nblk - 1; 8920Sstevel@tonic-gate if (dbend > *endblkp) 8930Sstevel@tonic-gate *endblkp = dbend; 8940Sstevel@tonic-gate } 8950Sstevel@tonic-gate 8960Sstevel@tonic-gate /* cleanup, return success */ 8970Sstevel@tonic-gate metafreereplicalist(rlp); 8980Sstevel@tonic-gate return (0); 8990Sstevel@tonic-gate } 9000Sstevel@tonic-gate 9010Sstevel@tonic-gate /* 9020Sstevel@tonic-gate * return cached start block 9030Sstevel@tonic-gate */ 9040Sstevel@tonic-gate static diskaddr_t 9050Sstevel@tonic-gate metagetend( 9060Sstevel@tonic-gate mdsetname_t *sp, 9070Sstevel@tonic-gate mdname_t *np, 9080Sstevel@tonic-gate md_error_t *ep 9090Sstevel@tonic-gate ) 9100Sstevel@tonic-gate { 9110Sstevel@tonic-gate diskaddr_t end_blk = MD_DISKADDR_ERROR; 9120Sstevel@tonic-gate 9130Sstevel@tonic-gate /* short circuit */ 9140Sstevel@tonic-gate if (np->end_blk != MD_DISKADDR_ERROR) 9150Sstevel@tonic-gate return (np->end_blk); 9160Sstevel@tonic-gate 9170Sstevel@tonic-gate /* look for database locations */ 9180Sstevel@tonic-gate if (mddb_getendblk(sp, np, &end_blk, ep) != 0) 9190Sstevel@tonic-gate return (MD_DISKADDR_ERROR); 9200Sstevel@tonic-gate 9210Sstevel@tonic-gate /* success */ 9220Sstevel@tonic-gate np->end_blk = end_blk; 9230Sstevel@tonic-gate return (end_blk); 9240Sstevel@tonic-gate } 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate /* 9270Sstevel@tonic-gate * does device have a metadb 9280Sstevel@tonic-gate */ 9290Sstevel@tonic-gate int 9300Sstevel@tonic-gate metahasmddb( 9310Sstevel@tonic-gate mdsetname_t *sp, 9320Sstevel@tonic-gate mdname_t *np, 9330Sstevel@tonic-gate md_error_t *ep 9340Sstevel@tonic-gate ) 9350Sstevel@tonic-gate { 9360Sstevel@tonic-gate if (metagetend(sp, np, ep) == MD_DISKADDR_ERROR) 9370Sstevel@tonic-gate return (-1); 9380Sstevel@tonic-gate else if (np->end_blk > 0) 9390Sstevel@tonic-gate return (1); 9400Sstevel@tonic-gate else 9410Sstevel@tonic-gate return (0); 9420Sstevel@tonic-gate } 9430Sstevel@tonic-gate 9440Sstevel@tonic-gate /* 9450Sstevel@tonic-gate * return cached start block 9460Sstevel@tonic-gate */ 9470Sstevel@tonic-gate diskaddr_t 9480Sstevel@tonic-gate metagetstart( 9490Sstevel@tonic-gate mdsetname_t *sp, 9500Sstevel@tonic-gate mdname_t *np, 9510Sstevel@tonic-gate md_error_t *ep 9520Sstevel@tonic-gate ) 9530Sstevel@tonic-gate { 9540Sstevel@tonic-gate diskaddr_t start_blk = MD_DISKADDR_ERROR; 9550Sstevel@tonic-gate 9560Sstevel@tonic-gate /* short circuit */ 9570Sstevel@tonic-gate if (np->start_blk != MD_DISKADDR_ERROR) 9580Sstevel@tonic-gate return (np->start_blk); 9590Sstevel@tonic-gate 9600Sstevel@tonic-gate /* look for database locations */ 9610Sstevel@tonic-gate if ((start_blk = metagetend(sp, np, ep)) == MD_DISKADDR_ERROR) 9620Sstevel@tonic-gate return (MD_DISKADDR_ERROR); 9630Sstevel@tonic-gate 9640Sstevel@tonic-gate /* check for label */ 9650Sstevel@tonic-gate if (start_blk == 0) { 9660Sstevel@tonic-gate start_blk = metagetlabel(np, ep); 9670Sstevel@tonic-gate if (start_blk == MD_DISKADDR_ERROR) { 9680Sstevel@tonic-gate return (MD_DISKADDR_ERROR); 9690Sstevel@tonic-gate } 9700Sstevel@tonic-gate } 9710Sstevel@tonic-gate 9720Sstevel@tonic-gate /* roundup to next cylinder */ 9730Sstevel@tonic-gate if (start_blk != 0) { 9740Sstevel@tonic-gate mdgeom_t *geomp; 9750Sstevel@tonic-gate 9760Sstevel@tonic-gate if ((geomp = metagetgeom(np, ep)) == NULL) 9770Sstevel@tonic-gate return (MD_DISKADDR_ERROR); 9780Sstevel@tonic-gate start_blk = roundup(start_blk, (geomp->nhead * geomp->nsect)); 9790Sstevel@tonic-gate } 9800Sstevel@tonic-gate 9810Sstevel@tonic-gate /* success */ 9820Sstevel@tonic-gate np->start_blk = start_blk; 9830Sstevel@tonic-gate return (start_blk); 9840Sstevel@tonic-gate } 9850Sstevel@tonic-gate 9860Sstevel@tonic-gate /* 9870Sstevel@tonic-gate * return cached devices name 9880Sstevel@tonic-gate */ 9890Sstevel@tonic-gate char * 9900Sstevel@tonic-gate metagetdevicesname( 9910Sstevel@tonic-gate mdname_t *np, 9920Sstevel@tonic-gate md_error_t *ep 9930Sstevel@tonic-gate ) 9940Sstevel@tonic-gate { 9950Sstevel@tonic-gate char path[MAXPATHLEN + 1]; 9960Sstevel@tonic-gate int len; 9970Sstevel@tonic-gate 9980Sstevel@tonic-gate /* short circuit */ 9990Sstevel@tonic-gate if (np->devicesname != NULL) 10000Sstevel@tonic-gate return (np->devicesname); 10010Sstevel@tonic-gate 10020Sstevel@tonic-gate /* follow symlink */ 10030Sstevel@tonic-gate if ((len = readlink(np->bname, path, (sizeof (path) - 1))) < 0) { 10040Sstevel@tonic-gate (void) mdsyserror(ep, errno, np->bname); 10050Sstevel@tonic-gate return (NULL); 10060Sstevel@tonic-gate } else if (len >= sizeof (path)) { 10070Sstevel@tonic-gate (void) mdsyserror(ep, ENAMETOOLONG, np->bname); 10080Sstevel@tonic-gate return (NULL); 10090Sstevel@tonic-gate } 10100Sstevel@tonic-gate path[len] = '\0'; 10110Sstevel@tonic-gate if ((len = strfind(path, "/devices/")) < 0) { 10120Sstevel@tonic-gate (void) mddeverror(ep, MDE_DEVICES_NAME, np->dev, np->bname); 10130Sstevel@tonic-gate return (NULL); 10140Sstevel@tonic-gate } 10150Sstevel@tonic-gate 10160Sstevel@tonic-gate /* return name */ 10170Sstevel@tonic-gate np->devicesname = Strdup(path + len + strlen("/devices")); 10180Sstevel@tonic-gate return (np->devicesname); 10190Sstevel@tonic-gate } 10200Sstevel@tonic-gate 10210Sstevel@tonic-gate /* 10220Sstevel@tonic-gate * get metadevice misc name 10230Sstevel@tonic-gate */ 10240Sstevel@tonic-gate char * 10250Sstevel@tonic-gate metagetmiscname( 10260Sstevel@tonic-gate mdname_t *np, 10270Sstevel@tonic-gate md_error_t *ep 10280Sstevel@tonic-gate ) 10290Sstevel@tonic-gate { 10300Sstevel@tonic-gate mddrivename_t *dnp = np->drivenamep; 10310Sstevel@tonic-gate md_i_driverinfo_t mid; 10320Sstevel@tonic-gate 10330Sstevel@tonic-gate /* short circuit */ 10340Sstevel@tonic-gate if (dnp->miscname != NULL) 10350Sstevel@tonic-gate return (dnp->miscname); 10360Sstevel@tonic-gate if (metachkmeta(np, ep) != 0) 10370Sstevel@tonic-gate return (NULL); 10380Sstevel@tonic-gate 10390Sstevel@tonic-gate /* get misc module from driver */ 10400Sstevel@tonic-gate (void) memset(&mid, 0, sizeof (mid)); 10410Sstevel@tonic-gate mid.mnum = meta_getminor(np->dev); 10420Sstevel@tonic-gate if (metaioctl(MD_IOCGET_DRVNM, &mid, &mid.mde, np->cname) != 0) { 10430Sstevel@tonic-gate (void) mdstealerror(ep, &mid.mde); 10440Sstevel@tonic-gate return (NULL); 10450Sstevel@tonic-gate } 10460Sstevel@tonic-gate 10470Sstevel@tonic-gate /* return miscname */ 10480Sstevel@tonic-gate dnp->miscname = Strdup(MD_PNTDRIVERNAME(&mid)); 10490Sstevel@tonic-gate return (dnp->miscname); 10500Sstevel@tonic-gate } 10510Sstevel@tonic-gate 10520Sstevel@tonic-gate /* 10530Sstevel@tonic-gate * get unit structure from driver 10540Sstevel@tonic-gate */ 10550Sstevel@tonic-gate md_unit_t * 10560Sstevel@tonic-gate meta_get_mdunit( 10570Sstevel@tonic-gate mdsetname_t *sp, 10580Sstevel@tonic-gate mdname_t *np, 10590Sstevel@tonic-gate md_error_t *ep 10600Sstevel@tonic-gate ) 10610Sstevel@tonic-gate { 10620Sstevel@tonic-gate md_i_get_t mig; 10630Sstevel@tonic-gate char *miscname = NULL; 10640Sstevel@tonic-gate 10650Sstevel@tonic-gate /* should have a set */ 10660Sstevel@tonic-gate assert(sp != NULL); 10670Sstevel@tonic-gate assert(sp->setno == MD_MIN2SET(meta_getminor(np->dev))); 10680Sstevel@tonic-gate 10690Sstevel@tonic-gate /* get size of unit structure */ 10700Sstevel@tonic-gate if (metachkmeta(np, ep) != 0) 10710Sstevel@tonic-gate return (NULL); 10720Sstevel@tonic-gate if ((miscname = metagetmiscname(np, ep)) == NULL) 10730Sstevel@tonic-gate return (NULL); 10740Sstevel@tonic-gate (void) memset(&mig, '\0', sizeof (mig)); 10750Sstevel@tonic-gate MD_SETDRIVERNAME(&mig, miscname, sp->setno); 10760Sstevel@tonic-gate mig.id = meta_getminor(np->dev); 10770Sstevel@tonic-gate if (metaioctl(MD_IOCGET, &mig, &mig.mde, np->cname) != 0) { 10780Sstevel@tonic-gate (void) mdstealerror(ep, &mig.mde); 10790Sstevel@tonic-gate return (NULL); 10800Sstevel@tonic-gate } 10810Sstevel@tonic-gate 10820Sstevel@tonic-gate /* get actual unit structure */ 10830Sstevel@tonic-gate assert(mig.size > 0); 10840Sstevel@tonic-gate mig.mdp = (uintptr_t)Zalloc(mig.size); 10850Sstevel@tonic-gate if (metaioctl(MD_IOCGET, &mig, &mig.mde, np->cname) != 0) { 10860Sstevel@tonic-gate (void) mdstealerror(ep, &mig.mde); 108762Sjeanm Free((void *)(uintptr_t)mig.mdp); 10880Sstevel@tonic-gate return (NULL); 10890Sstevel@tonic-gate } 10900Sstevel@tonic-gate 109162Sjeanm return ((md_unit_t *)(uintptr_t)mig.mdp); 10920Sstevel@tonic-gate } 10930Sstevel@tonic-gate 10940Sstevel@tonic-gate /* 10950Sstevel@tonic-gate * free metadevice unit 10960Sstevel@tonic-gate */ 10970Sstevel@tonic-gate void 10980Sstevel@tonic-gate meta_free_unit( 10990Sstevel@tonic-gate mddrivename_t *dnp 11000Sstevel@tonic-gate ) 11010Sstevel@tonic-gate { 11020Sstevel@tonic-gate if (dnp->unitp != NULL) { 11030Sstevel@tonic-gate switch (dnp->unitp->type) { 11040Sstevel@tonic-gate case MD_DEVICE: 11050Sstevel@tonic-gate meta_free_stripe((md_stripe_t *)dnp->unitp); 11060Sstevel@tonic-gate break; 11070Sstevel@tonic-gate case MD_METAMIRROR: 11080Sstevel@tonic-gate meta_free_mirror((md_mirror_t *)dnp->unitp); 11090Sstevel@tonic-gate break; 11100Sstevel@tonic-gate case MD_METATRANS: 11110Sstevel@tonic-gate meta_free_trans((md_trans_t *)dnp->unitp); 11120Sstevel@tonic-gate break; 11130Sstevel@tonic-gate case MD_METARAID: 11140Sstevel@tonic-gate meta_free_raid((md_raid_t *)dnp->unitp); 11150Sstevel@tonic-gate break; 11160Sstevel@tonic-gate case MD_METASP: 11170Sstevel@tonic-gate meta_free_sp((md_sp_t *)dnp->unitp); 11180Sstevel@tonic-gate break; 11190Sstevel@tonic-gate default: 11200Sstevel@tonic-gate assert(0); 11210Sstevel@tonic-gate break; 11220Sstevel@tonic-gate } 11230Sstevel@tonic-gate dnp->unitp = NULL; 11240Sstevel@tonic-gate } 11250Sstevel@tonic-gate } 11260Sstevel@tonic-gate 11270Sstevel@tonic-gate /* 11280Sstevel@tonic-gate * free metadevice name info 11290Sstevel@tonic-gate */ 11300Sstevel@tonic-gate void 11310Sstevel@tonic-gate meta_invalidate_name( 11320Sstevel@tonic-gate mdname_t *namep 11330Sstevel@tonic-gate ) 11340Sstevel@tonic-gate { 11350Sstevel@tonic-gate mddrivename_t *dnp = namep->drivenamep; 11360Sstevel@tonic-gate 11370Sstevel@tonic-gate /* get rid of cached name info */ 11380Sstevel@tonic-gate if (namep->devicesname != NULL) { 11390Sstevel@tonic-gate Free(namep->devicesname); 11400Sstevel@tonic-gate namep->devicesname = NULL; 11410Sstevel@tonic-gate } 11420Sstevel@tonic-gate namep->key = MD_KEYBAD; 11430Sstevel@tonic-gate namep->start_blk = -1; 11440Sstevel@tonic-gate namep->end_blk = -1; 11450Sstevel@tonic-gate 11460Sstevel@tonic-gate /* get rid of cached drivename info */ 11470Sstevel@tonic-gate (void) memset(&dnp->geom, 0, sizeof (dnp->geom)); 11480Sstevel@tonic-gate (void) memset(&dnp->cinfo, 0, sizeof (dnp->cinfo)); 11490Sstevel@tonic-gate metafreevtoc(&dnp->vtoc); 11500Sstevel@tonic-gate metaflushsidenames(dnp); 11510Sstevel@tonic-gate dnp->side_names_key = MD_KEYBAD; 11520Sstevel@tonic-gate if (dnp->miscname != NULL) { 11530Sstevel@tonic-gate Free(dnp->miscname); 11540Sstevel@tonic-gate dnp->miscname = NULL; 11550Sstevel@tonic-gate } 11560Sstevel@tonic-gate meta_free_unit(dnp); 11570Sstevel@tonic-gate } 11580Sstevel@tonic-gate 11590Sstevel@tonic-gate /* 11600Sstevel@tonic-gate * get metadevice unit 11610Sstevel@tonic-gate */ 11620Sstevel@tonic-gate md_common_t * 11630Sstevel@tonic-gate meta_get_unit( 11640Sstevel@tonic-gate mdsetname_t *sp, 11650Sstevel@tonic-gate mdname_t *np, 11660Sstevel@tonic-gate md_error_t *ep 11670Sstevel@tonic-gate ) 11680Sstevel@tonic-gate { 11690Sstevel@tonic-gate char *miscname; 11700Sstevel@tonic-gate 11710Sstevel@tonic-gate /* short circuit */ 11720Sstevel@tonic-gate if (np->drivenamep->unitp != NULL) 11730Sstevel@tonic-gate return (np->drivenamep->unitp); 11740Sstevel@tonic-gate if (metachkmeta(np, ep) != 0) 11750Sstevel@tonic-gate return (NULL); 11760Sstevel@tonic-gate 11770Sstevel@tonic-gate /* dispatch */ 11780Sstevel@tonic-gate if ((miscname = metagetmiscname(np, ep)) == NULL) 11790Sstevel@tonic-gate return (NULL); 11800Sstevel@tonic-gate else if (strcmp(miscname, MD_STRIPE) == 0) 11810Sstevel@tonic-gate return ((md_common_t *)meta_get_stripe(sp, np, ep)); 11820Sstevel@tonic-gate else if (strcmp(miscname, MD_MIRROR) == 0) 11830Sstevel@tonic-gate return ((md_common_t *)meta_get_mirror(sp, np, ep)); 11840Sstevel@tonic-gate else if (strcmp(miscname, MD_TRANS) == 0) 11850Sstevel@tonic-gate return ((md_common_t *)meta_get_trans(sp, np, ep)); 11860Sstevel@tonic-gate else if (strcmp(miscname, MD_RAID) == 0) 11870Sstevel@tonic-gate return ((md_common_t *)meta_get_raid(sp, np, ep)); 11880Sstevel@tonic-gate else if (strcmp(miscname, MD_SP) == 0) 11890Sstevel@tonic-gate return ((md_common_t *)meta_get_sp(sp, np, ep)); 11900Sstevel@tonic-gate else { 11910Sstevel@tonic-gate (void) mdmderror(ep, MDE_UNKNOWN_TYPE, meta_getminor(np->dev), 11920Sstevel@tonic-gate np->cname); 11930Sstevel@tonic-gate return (NULL); 11940Sstevel@tonic-gate } 11950Sstevel@tonic-gate } 11960Sstevel@tonic-gate 11970Sstevel@tonic-gate 11980Sstevel@tonic-gate int 11990Sstevel@tonic-gate meta_isopen( 12000Sstevel@tonic-gate mdsetname_t *sp, 12010Sstevel@tonic-gate mdname_t *np, 12020Sstevel@tonic-gate md_error_t *ep, 12030Sstevel@tonic-gate mdcmdopts_t options 12040Sstevel@tonic-gate ) 12050Sstevel@tonic-gate { 12060Sstevel@tonic-gate md_isopen_t d; 12070Sstevel@tonic-gate 12080Sstevel@tonic-gate if (metachkmeta(np, ep) != 0) 12090Sstevel@tonic-gate return (-1); 12100Sstevel@tonic-gate 12110Sstevel@tonic-gate (void) memset(&d, '\0', sizeof (d)); 12120Sstevel@tonic-gate d.dev = np->dev; 12130Sstevel@tonic-gate if (metaioctl(MD_IOCISOPEN, &d, &d.mde, np->cname) != 0) 12140Sstevel@tonic-gate return (mdstealerror(ep, &d.mde)); 12150Sstevel@tonic-gate 12160Sstevel@tonic-gate /* 12170Sstevel@tonic-gate * shortcut: if the device is open, no need to check on other nodes, 12180Sstevel@tonic-gate * even in case of a mn metadevice 12190Sstevel@tonic-gate * Also return in case we're told not to check on other nodes. 12200Sstevel@tonic-gate */ 12210Sstevel@tonic-gate if ((d.isopen != 0) || ((options & MDCMD_MN_OPEN_CHECK) == 0)) { 12220Sstevel@tonic-gate return (d.isopen); 12230Sstevel@tonic-gate } 12240Sstevel@tonic-gate 12250Sstevel@tonic-gate /* 12260Sstevel@tonic-gate * If the device is closed locally, but it's a mn device, 12270Sstevel@tonic-gate * check on all other nodes, too 12280Sstevel@tonic-gate */ 12290Sstevel@tonic-gate if (sp->setno != MD_LOCAL_SET) { 12300Sstevel@tonic-gate (void) metaget_setdesc(sp, ep); /* not supposed to fail */ 12310Sstevel@tonic-gate if (sp->setdesc->sd_flags & MD_SR_MN) { 12320Sstevel@tonic-gate int err = 0; 12330Sstevel@tonic-gate md_mn_result_t *resp; 12340Sstevel@tonic-gate /* 12350Sstevel@tonic-gate * This message is never directly issued. 12360Sstevel@tonic-gate * So we launch it with a suspend override flag. 12370Sstevel@tonic-gate * If the commd is suspended, and this message comes 12380Sstevel@tonic-gate * along it must be sent due to replaying a metainit or 12390Sstevel@tonic-gate * similar. In that case we don't want this message to 12400Sstevel@tonic-gate * be blocked. 12410Sstevel@tonic-gate * If the commd is not suspended, the flag does no harm. 12420Sstevel@tonic-gate * Additionally we don't want the result of the message 12430Sstevel@tonic-gate * cached in the MCT, because we want uptodate results, 12440Sstevel@tonic-gate * and the message doesn't need being logged either. 12450Sstevel@tonic-gate * Hence NO_LOG and NO_MCT 12460Sstevel@tonic-gate */ 12470Sstevel@tonic-gate err = mdmn_send_message( 1248*7563SPrasad.Singamsetty@Sun.COM sp->setno, MD_MN_MSG_CLU_CHECK, 12497464SAndrew.Balfour@Sun.COM MD_MSGF_NO_MCT | MD_MSGF_STOP_ON_ERROR | 12507464SAndrew.Balfour@Sun.COM MD_MSGF_NO_LOG | MD_MSGF_OVERRIDE_SUSPEND, 1251*7563SPrasad.Singamsetty@Sun.COM (char *)&d, sizeof (md_isopen_t), &resp, ep); 12520Sstevel@tonic-gate if (err == 0) { 12530Sstevel@tonic-gate d.isopen = resp->mmr_exitval; 12540Sstevel@tonic-gate } else { 12550Sstevel@tonic-gate /* 12560Sstevel@tonic-gate * in case some error occurred, 12570Sstevel@tonic-gate * we better say the device is open 12580Sstevel@tonic-gate */ 12590Sstevel@tonic-gate d.isopen = 1; 12600Sstevel@tonic-gate } 12610Sstevel@tonic-gate if (resp != (md_mn_result_t *)NULL) { 12620Sstevel@tonic-gate free_result(resp); 12630Sstevel@tonic-gate } 12640Sstevel@tonic-gate 12650Sstevel@tonic-gate } 12660Sstevel@tonic-gate } 12670Sstevel@tonic-gate 12680Sstevel@tonic-gate return (d.isopen); 12690Sstevel@tonic-gate } 1270