9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * CDDL HEADER START
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * The contents of this file are subject to the terms of the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Common Development and Distribution License (the "License").
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * You may not use this file except in compliance with the License.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * See the License for the specific language governing permissions
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * and limitations under the License.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * When distributing Covered Code, include this CDDL HEADER in each
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If applicable, add the following below this CDDL HEADER, with the
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * fields enclosed by brackets "[]" replaced with your own identifying
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * information: Portions Copyright [yyyy] [name of copyright owner]
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * CDDL HEADER END
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Use is subject to license terms.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * structure for di_devlink_walk
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * callback funtion for di_devlink_walk
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Find matching /dev link for the given path argument.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * devlink element and callback function argument.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * The input path is expected to not have "/devices".
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * When path is specified, it doesn't have minor
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * name. Therefore, the ../.. prefixes needs to be stripped.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim char *content = (char *)di_devlink_content(devlink);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* make it sure the device path has minor name */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim *(warg->linkpp) = strdup(di_devlink_path(devlink));
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Convert /devices paths to /dev sym-link paths.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * The mapping buffer OSDeviceName paths will be
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * converted to short names.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * mappings The target mappings data to convert to short names
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * If no link is found, the long path is left as is.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Note: The NumberOfEntries field MUST not be greater than the size
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * of the array passed in.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon KimconvertDevpathToDevlink(PSMHBA_TARGETMAPPING mappings)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim log(LOG_DEBUG, ROUTINE, "di_devlink failed: errno:%d",
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim if (strchr(mappings->entry[j].ScsiId.OSDeviceName, ':')) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim /* search link for minor node */
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim minor_path = mappings->entry[j].ScsiId.OSDeviceName;
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void) di_devlink_walk(hdl, NULL, minor_path, DI_PRIMARY_LINK,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void) snprintf(mappings->entry[j].ScsiId.OSDeviceName,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Finds controller path for a give device path.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return value: /dev link for dir and minor name.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon KimlookupLink(char *path, char *link, const char *dir, const char *mname)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim "Unable to open %s to find controller number.", dir);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim "Invalid argument for storing the link.");
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * dirplen is large enough to fit the largest path-
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * struct dirent includes one byte (the terminator)
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * so we don't add 1 to the calculation here.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim dirplen = ((dirplen <= 0) ? MAXNAMELEN : dirplen) +
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim sizeof (struct dirent);
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim while ((readdir_r(dp, dirp, &newdirp)) == 0 && newdirp != NULL) {
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * set to another pointer since dirp->d_name length is 1
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * that will store only the first char 'c' from the name.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim (void) snprintf(node, strlen(charptr) + strlen(dir) + 2,
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * if device path has substring of path
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * and exactally matching with :scsi suffix
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Finds controller path for a give device path.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return vale:i smp devlink.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Finds smp devlink for a give smp path.
9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bbHyon Kim * Return vale: smp devlink.