From b633ed5ee189f9772d3f8ec19f993271d5fc63fb Mon Sep 17 00:00:00 2001 From: William Dauchy Date: Thu, 5 Jan 2012 11:42:10 +0100 Subject: [PATCH 1/2] Add a function to retrieve the logical unit id from a name --- usr/src/lib/libstmf/common/libstmf.h | 1 + usr/src/lib/libstmf/common/mapfile-vers | 1 + usr/src/lib/libstmf/common/stmf.c | 112 ++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) diff --git a/usr/src/lib/libstmf/common/libstmf.h b/usr/src/lib/libstmf/common/libstmf.h index f9d05ad..f6e9496 100644 --- a/usr/src/lib/libstmf/common/libstmf.h +++ b/usr/src/lib/libstmf/common/libstmf.h @@ -381,6 +381,7 @@ int stmfSetProviderData(char *providerName, nvlist_t *nvl, int providerType); int stmfSetProviderDataProt(char *providerName, nvlist_t *nvl, int providerType, uint64_t *setToken); int stmfValidateView(stmfViewEntry *viewEntry); +int stmfGetLuGuidByName(const char *fname, char *luGuid, size_t luGuidLen); int stmfSetStmfProp(uint8_t propType, char *propVal); int stmfGetStmfProp(uint8_t propType, char *propVal, size_t *propLen); int stmfLoadStmfProps(void); diff --git a/usr/src/lib/libstmf/common/mapfile-vers b/usr/src/lib/libstmf/common/mapfile-vers index ade03df..0c37e0c 100644 --- a/usr/src/lib/libstmf/common/mapfile-vers +++ b/usr/src/lib/libstmf/common/mapfile-vers @@ -95,6 +95,7 @@ SYMBOL_VERSION SUNW_1.1 { stmfSetStmfProp; stmfGetStmfProp; stmfValidateView; + stmfGetLuGuidByName; local: *; }; diff --git a/usr/src/lib/libstmf/common/stmf.c b/usr/src/lib/libstmf/common/stmf.c index e12c189..0a25ec6 100644 --- a/usr/src/lib/libstmf/common/stmf.c +++ b/usr/src/lib/libstmf/common/stmf.c @@ -6947,3 +6947,115 @@ stmfValidateView(stmfViewEntry *viewEntry) return (ret); } + +/* + * getDiskAllPropsByName + * + * Purpose: load all disk properties from a sdb driver + * + * fname - name of the disk device for which properties are to be retrieved + * hdl - allocated luResource into which properties are to be copied + */ +static int +getDiskAllPropsByName(const char* fname, luResource *hdl) +{ + int ret = STMF_STATUS_SUCCESS; + int fd; + sbd_lu_props_t *sbdProps; + int ioctlRet; + int savedErrno; + int sbdPropsSize = sizeof (*sbdProps) + MAX_SBD_PROPS; + stmf_iocdata_t sbdIoctl = {0}; + + int fnameSize = 0; + int bufOffset = 0; + + if (fname) { + fnameSize = strlen(fname) + 1; + sbdPropsSize += fnameSize; + } + + if ((ret = openSbd(OPEN_SBD, &fd)) != STMF_STATUS_SUCCESS) + return (ret); + + sbdProps = calloc(1, sbdPropsSize); + if (sbdProps == NULL) { + free(*hdl); + (void) close(fd); + return (STMF_ERROR_NOMEM); + } + + sbdProps->slp_data_fname_valid = 1; + bcopy(fname, &(sbdProps->slp_buf[bufOffset]), fnameSize); + + sbdIoctl.stmf_version = STMF_VERSION_1; + sbdIoctl.stmf_ibuf_size = sbdPropsSize; + sbdIoctl.stmf_ibuf = (uint64_t)(unsigned long)sbdProps; + sbdIoctl.stmf_obuf_size = sbdPropsSize; + sbdIoctl.stmf_obuf = (uint64_t)(unsigned long)sbdProps; + ioctlRet = ioctl(fd, SBD_IOCTL_GET_LU_PROPS, &sbdIoctl); + if (ioctlRet != 0) { + savedErrno = errno; + switch (savedErrno) { + case EBUSY: + ret = STMF_ERROR_BUSY; + break; + case EPERM: + case EACCES: + ret = STMF_ERROR_PERM; + break; + case ENOENT: + ret = STMF_ERROR_NOT_FOUND; + break; + default: + syslog(LOG_DEBUG, + "getDiskAllProps:ioctl error(%d) (%d) (%d)", + ioctlRet, sbdIoctl.stmf_error, savedErrno); + ret = STMF_STATUS_ERROR; + break; + } + } + if (ret == STMF_STATUS_SUCCESS) { + ret = stmfCreateLuResource(STMF_DISK, hdl); + if (ret != STMF_STATUS_SUCCESS) { + hdl = NULL; + return (ret); + } + ret = loadDiskPropsFromDriver((luResourceImpl *)*hdl, sbdProps); + } + + free(sbdProps); + (void) close(fd); + return (ret); +} + +/* + * stmfGetLuGuidByName + * + * Purpose: Get a logical unit id from a logical unit name + * + * fname + */ +int +stmfGetLuGuidByName(const char *fname, char *luGuid, size_t luGuidSize) +{ + luResource hdl = NULL; + int ret; + + if (luGuidSize <= LU_ASCII_GUID_SIZE) { + return (STMF_ERROR_SIZE_OUT_OF_RANGE); + } + + ret = getDiskAllPropsByName(fname, &hdl); + if (ret != STMF_STATUS_SUCCESS) { + return (ret); + } + + ret = stmfGetLuProp(hdl, STMF_LU_PROP_GUID, luGuid, &luGuidSize); + if (ret != STMF_STATUS_SUCCESS) { + (void) stmfFreeLuResource(hdl); + return (ret); + } + (void) stmfFreeLuResource(hdl); + return (STMF_STATUS_SUCCESS); +} -- 2.4.6