/*ARGSUSED*/ int delete_lu(int operandLen, char *operands[], cmdOptions_t *options, void *callData) { int i, j; int ret = 0; int stmfRet; unsigned int inGuid[sizeof (stmfGuid)]; stmfGuid delGuid; boolean_t keepViews = B_FALSE; boolean_t viewEntriesRemoved = B_FALSE; boolean_t noLunFound = B_FALSE; boolean_t views = B_FALSE; boolean_t notValidHexNumber = B_FALSE; char sGuid[GUID_INPUT + 1]; stmfViewEntryList *viewEntryList = NULL; for (; options->optval; options++) { switch (options->optval) { /* Keep views for logical unit */ case 'k': keepViews = B_TRUE; break; default: (void) fprintf(stderr, "%s: %c: %s\n", cmdName, options->optval, gettext("unknown option")); return (1); } } for (i = 0; i < operandLen; i++) { for (j = 0; j < GUID_INPUT; j++) { if (!isxdigit(operands[i][j])) { notValidHexNumber = B_TRUE; break; } sGuid[j] = tolower(operands[i][j]); } if ((notValidHexNumber == B_TRUE) || (strlen(operands[i]) != GUID_INPUT)) { (void) fprintf(stderr, "%s: %s: %s%d%s\n", cmdName, operands[i], gettext("must be "), GUID_INPUT, gettext(" hexadecimal digits long")); notValidHexNumber = B_FALSE; ret++; continue; } sGuid[j] = 0; (void) sscanf(sGuid, "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", &inGuid[0], &inGuid[1], &inGuid[2], &inGuid[3], &inGuid[4], &inGuid[5], &inGuid[6], &inGuid[7], &inGuid[8], &inGuid[9], &inGuid[10], &inGuid[11], &inGuid[12], &inGuid[13], &inGuid[14], &inGuid[15]); for (j = 0; j < sizeof (stmfGuid); j++) { delGuid.guid[j] = inGuid[j]; } stmfRet = stmfDeleteLu(&delGuid); switch (stmfRet) { case STMF_STATUS_SUCCESS: break; case STMF_ERROR_NOT_FOUND: noLunFound = B_TRUE; break; case STMF_ERROR_BUSY: (void) fprintf(stderr, "%s: %s\n", cmdName, gettext("resource busy")); ret++; break; case STMF_ERROR_PERM: (void) fprintf(stderr, "%s: %s\n", cmdName, gettext("permission denied")); ret++; break; default: (void) fprintf(stderr, "%s: %s\n", cmdName, gettext("unknown error")); ret++; break; } if (!keepViews) { stmfRet = stmfGetViewEntryList(&delGuid, &viewEntryList); if (stmfRet == STMF_STATUS_SUCCESS) { for (j = 0; j < viewEntryList->cnt; j++) { (void) stmfRemoveViewEntry(&delGuid, viewEntryList->ve[j].veIndex); } /* check if viewEntryList is empty */ if (viewEntryList->cnt != 0) viewEntriesRemoved = B_TRUE; stmfFreeMemory(viewEntryList); } else { (void) fprintf(stderr, "%s: %s\n", cmdName, gettext("unable to remove view entries\n")); ret++; } } if (keepViews) { stmfRet = stmfGetViewEntryList(&delGuid, &viewEntryList); if (stmfRet == STMF_STATUS_SUCCESS) { views = B_TRUE; stmfFreeMemory(viewEntryList); } } if ((!viewEntriesRemoved && noLunFound && !views) || (!views && keepViews && noLunFound)) { (void) fprintf(stderr, "%s: %s: %s\n", cmdName, sGuid, gettext("not found")); ret++; } noLunFound = viewEntriesRemoved = views = B_FALSE; } return (ret); }
static int stmfRemoveViewEntry001() { int ret = 0; int i; boolean_t found = B_FALSE; stmfViewEntry viewEntry; stmfGuidList *luList; stmfLogicalUnitProperties luProps; stmfViewEntryList *viewEntryList; char sbdadmDeleteLu[MAXPATHLEN]; char guidAsciiBuf[33]; int stmfRet; bzero(&viewEntry, sizeof (viewEntry)); (void) system("touch /tmp/stmfRemoveViewEntry.lu"); (void) system("sbdadm create-lu -s 10g /tmp/stmfRemoveViewEntry.lu"); stmfRet = stmfGetLogicalUnitList(&luList); if (stmfRet != STMF_STATUS_SUCCESS) { ret = 1; goto cleanup1; } for (i = 0; i < luList->cnt; i++) { stmfRet = stmfGetLogicalUnitProperties(&(luList->guid[i]), &luProps); if (strncmp(luProps.alias, "/tmp/stmfRemoveViewEntry.lu", sizeof (luProps.alias)) == 0) { found = B_TRUE; break; } } if (!found) { ret = 2; goto cleanup1; } guidToAscii(&luList->guid[i], guidAsciiBuf); (void) snprintf(sbdadmDeleteLu, sizeof (sbdadmDeleteLu), "%s %s", "sbdadm delete-lu", guidAsciiBuf); viewEntry.allHosts = B_TRUE; viewEntry.allTargets = B_TRUE; viewEntry.luNbrValid = B_FALSE; stmfRet = stmfAddViewEntry(&(luList->guid[i]), &viewEntry); if (stmfRet != STMF_STATUS_SUCCESS) { ret = 3; goto cleanup2; } stmfRet = stmfGetViewEntryList(&(luList->guid[i]), &viewEntryList); if (stmfRet != STMF_STATUS_SUCCESS) { ret = 4; goto cleanup2; } if (viewEntryList->cnt > 0) { if ((viewEntryList->ve[0].allHosts != B_TRUE) || (viewEntryList->ve[0].allTargets != B_TRUE)) { ret = 5; goto cleanup2; } if (viewEntryList->ve[0].luNbrValid != B_TRUE) { ret = 6; goto cleanup2; } } stmfRet = stmfRemoveViewEntry(&(luList->guid[i]), viewEntryList->ve[0].veIndex); if (stmfRet != STMF_STATUS_SUCCESS) { ret = 7; goto cleanup2; } stmfFreeMemory(viewEntryList); stmfRet = stmfGetViewEntryList(&(luList->guid[i]), &viewEntryList); if (stmfRet != STMF_ERROR_NOT_FOUND) { ret = 8; goto cleanup2; } cleanup2: (void) system(sbdadmDeleteLu); cleanup1: (void) system("rm /tmp/stmfRemoveViewEntry.lu"); return (ret); }