static int stmfOfflineTarget001() { int stmfRet; int ret = 0; int retries = 0; stmfDevidList *targetList; stmfTargetProperties targetProps; struct timespec rqtp; bzero(&rqtp, sizeof (rqtp)); rqtp.tv_nsec = 10000000; /* 10 ms sleep */ stmfRet = stmfGetTargetList(&targetList); if (stmfRet != STMF_STATUS_SUCCESS) { ret = 1; goto cleanup; } if (targetList->cnt > 0) { stmfRet = stmfOfflineTarget(&(targetList->devid[0])); if (stmfRet != STMF_STATUS_SUCCESS) { ret = 2; goto cleanup; } } else { ret = 3; goto cleanup; } targetProps.status = STMF_TARGET_PORT_ONLINE; while (targetProps.status != STMF_TARGET_PORT_OFFLINE && retries++ < 600) { stmfRet = stmfGetTargetProperties(&(targetList->devid[0]), &targetProps); if (stmfRet != STMF_STATUS_SUCCESS) { ret = 4; goto cleanup1; } if (targetProps.status != STMF_TARGET_PORT_OFFLINE) { (void) nanosleep(&rqtp, NULL); } } if (targetProps.status != STMF_TARGET_PORT_OFFLINE) { ret = 5; goto cleanup1; } cleanup1: (void) stmfOnlineTarget(&(targetList->devid[0])); cleanup: return (ret); }
static int stmfGetTargetProperties004() { int ret = 0; int stmfRet; stmfTargetProperties targetProps; stmfRet = stmfGetTargetProperties(NULL, &targetProps); if (stmfRet != STMF_ERROR_INVALID_ARG) { ret = 2; } return (ret); }
/* * Function: it_tgt_delete() * * Delete target represented by 'tgt', where 'tgt' is an existing * it_tgt_structure within the configuration 'cfg'. The target removal * will not take effect until the modified configuration is committed * by calling it_config_commit(). * * Parameters: * cfg The current iSCSI configuration obtained from * it_config_load() * tgt Pointer to an iSCSI target structure * * force Set the target to offline before removing it from * the config. If not specified, the operation will * fail if the target is determined to be online. * Return Values: * 0 Success * EBUSY Target is online */ int it_tgt_delete(it_config_t *cfg, it_tgt_t *tgt, boolean_t force) { int ret; it_tgt_t *ptgt; it_tgt_t *prev = NULL; stmfDevid devid; stmfTargetProperties props; if (!cfg || !tgt) { return (0); } ptgt = cfg->config_tgt_list; while (ptgt != NULL) { if (strcasecmp(tgt->tgt_name, ptgt->tgt_name) == 0) { break; } prev = ptgt; ptgt = ptgt->tgt_next; } if (!ptgt) { return (0); } /* * check to see if this target is offline. If it is not, * and the 'force' flag is TRUE, tell STMF to offline it * before removing from the configuration. */ ret = stmfDevidFromIscsiName(ptgt->tgt_name, &devid); if (ret != STMF_STATUS_SUCCESS) { /* can't happen? */ return (EINVAL); } ret = stmfGetTargetProperties(&devid, &props); if (ret == STMF_STATUS_SUCCESS) { /* * only other return is STMF_ERROR_NOT_FOUND, which * means we don't have to offline it. */ if (props.status == STMF_TARGET_PORT_ONLINE) { if (!force) { return (EBUSY); } ret = stmfOfflineTarget(&devid); if (ret != 0) { return (EBUSY); } } } if (prev) { prev->tgt_next = ptgt->tgt_next; } else { /* first one on the list */ cfg->config_tgt_list = ptgt->tgt_next; } ptgt->tgt_next = NULL; /* Only free this target */ cfg->config_tgt_count--; it_tgt_free(ptgt); return (0); }