#include "cfga_fp.h"
int cfga_version = CFGA_HSL_V2;
cfga_err_t
cfga_change_state(
cfga_cmd_t state_change_cmd,
const char *ap_id,
const char *options,
struct cfga_confirm *confp,
struct cfga_msg *msgp,
char **errstring,
cfga_flags_t flags)
{
apid_t apidt = {NULL};
fpcfga_ret_t ret;
la_wwn_t pwwn;
char *value, *hw_option, *hw_option_p;
char *fp_cs_hw_opts[] = {"disable_rcm", "force_update",
"no_update", "unusable_SCSI_LUN", "unusable_FCP_dev", NULL};
HBA_HANDLE handle;
HBA_PORTATTRIBUTES portAttrs;
int portIndex;
if (errstring != NULL) {
*errstring = NULL;
}
if (geteuid() != 0) {
return (CFGA_PRIV);
}
if (state_change_cmd != CFGA_CMD_CONFIGURE &&
state_change_cmd != CFGA_CMD_UNCONFIGURE) {
return (CFGA_OPNOTSUPP);
}
if ((ret = apidt_create(ap_id, &apidt, errstring)) != FPCFGA_OK) {
return (err_cvt(ret));
}
if (options != NULL) {
hw_option = calloc(1, strlen(options) + 1);
(void) snprintf(hw_option, strlen(options) + 1, "%s", options);
hw_option_p = hw_option;
while (*hw_option_p != '\0') {
switch (getsubopt(&hw_option_p, fp_cs_hw_opts,
&value)) {
case OPT_DISABLE_RCM :
apidt.flags |= FLAG_DISABLE_RCM;
break;
case OPT_FORCE_UPDATE_REP :
apidt.flags |= FLAG_FORCE_UPDATE_REP;
break;
case OPT_NO_UPDATE_REP :
apidt.flags |= FLAG_NO_UPDATE_REP;
break;
case OPT_REMOVE_UNUSABLE_FCP_DEV :
case OPT_REMOVE_UNUSABLE_SCSI_LUN:
if (state_change_cmd != CFGA_CMD_UNCONFIGURE) {
cfga_err(errstring, 0, ERRARG_OPT_INVAL,
options, 0);
S_FREE(hw_option);
apidt_free(&apidt);
return (CFGA_ERROR);
}
apidt.flags |= FLAG_REMOVE_UNUSABLE_FCP_DEV;
break;
default :
cfga_err(errstring, 0, ERRARG_OPT_INVAL,
options, 0);
S_FREE(hw_option);
apidt_free(&apidt);
return (CFGA_ERROR);
}
}
S_FREE(hw_option);
}
if (options != NULL && apidt.flags == 0) {
cfga_err(errstring, 0, ERRARG_OPT_INVAL, options, 0);
apidt_free(&apidt);
return (CFGA_ERROR);
}
if (apidt.dyncomp != NULL) {
if (cvt_dyncomp_to_lawwn(apidt.dyncomp, &pwwn)) {
cfga_err(errstring, 0, ERR_APID_INVAL, 0);
return (err_cvt(FPCFGA_LIB_ERR));
}
if ((ret = findMatchingAdapterPort(apidt.xport_phys,
&handle, &portIndex, &portAttrs, errstring)) ==
FPCFGA_OK) {
ret = dev_change_state(state_change_cmd, &apidt, &pwwn,
flags, errstring, handle, portAttrs);
HBA_CloseAdapter(handle);
HBA_FreeLibrary();
}
} else {
ret = fca_change_state(state_change_cmd, &apidt,
flags, errstring);
}
apidt_free(&apidt);
return (err_cvt(ret));
}
cfga_err_t
cfga_private_func(
const char *func,
const char *ap_id,
const char *options,
struct cfga_confirm *confp,
struct cfga_msg *msgp,
char **errstring,
cfga_flags_t flags)
{
if (errstring != NULL) {
*errstring = NULL;
}
if (geteuid() != 0) {
return (CFGA_PRIV);
}
return (CFGA_OPNOTSUPP);
}
cfga_err_t
cfga_test(
const char *ap_id,
const char *options,
struct cfga_msg *msgp,
char **errstring,
cfga_flags_t flags)
{
if (errstring != NULL) {
*errstring = NULL;
}
if (geteuid() != 0) {
return (CFGA_PRIV);
}
return (CFGA_OPNOTSUPP);
}
cfga_err_t
cfga_list_ext(
const char *ap_id,
cfga_list_data_t **ap_id_list,
int *nlistp,
const char *options,
const char *listopts,
char **errstring,
cfga_flags_t flags)
{
int fca, expand, nelem;
ldata_list_t *ldatalistp = NULL;
apid_t apidt = {NULL};
fpcfga_cmd_t cmd;
fpcfga_ret_t ret;
char *value, *hw_option, *hw_option_p;
uint_t fp_flags = 0;
char *fp_list_hw_opts[] = {"devinfo_force", "show_SCSI_LUN",
"show_FCP_dev", NULL};
if (errstring != NULL) {
*errstring = NULL;
}
if (geteuid() != 0) {
return (CFGA_PRIV);
}
if (ap_id_list == NULL || nlistp == NULL) {
return (CFGA_ERROR);
}
*ap_id_list = NULL;
*nlistp = 0;
if (options != NULL) {
hw_option = calloc(1, strlen(options) + 1);
(void) snprintf(hw_option, strlen(options) + 1, "%s", options);
hw_option_p = hw_option;
while (*hw_option_p != '\0') {
switch (getsubopt(&hw_option_p, fp_list_hw_opts,
&value)) {
case OPT_DEVINFO_FORCE :
fp_flags |= FLAG_DEVINFO_FORCE;
break;
case OPT_FCP_DEV :
case OPT_SHOW_SCSI_LUN:
fp_flags |= FLAG_FCP_DEV;
break;
default :
cfga_err(errstring, 0, ERRARG_OPT_INVAL,
options, 0);
S_FREE(hw_option);
return (CFGA_ERROR);
}
}
S_FREE(hw_option);
}
if (((fp_flags & FLAG_DEVINFO_FORCE) == FLAG_DEVINFO_FORCE) &&
(geteuid() != 0)) {
return (CFGA_PRIV);
}
fca = 0;
if (GET_DYN(ap_id) == NULL) {
fca = 1;
}
expand = 0;
if ((flags & CFGA_FLAG_LIST_ALL) == CFGA_FLAG_LIST_ALL) {
expand = 1;
}
if (!fca) {
cmd = FPCFGA_STAT_FC_DEV;
} else if (!expand) {
cmd = FPCFGA_STAT_FCA_PORT;
} else {
cmd = FPCFGA_STAT_ALL;
}
ldatalistp = NULL;
nelem = 0;
if ((fp_flags & FLAG_FCP_DEV) == FLAG_FCP_DEV) {
ret = do_list_FCP_dev(ap_id, fp_flags, cmd, &ldatalistp, &nelem,
errstring);
if (ret != FPCFGA_OK) {
list_free(&ldatalistp);
return (err_cvt(ret));
}
} else {
if ((ret = apidt_create(ap_id, &apidt, errstring))
!= FPCFGA_OK) {
return (err_cvt(ret));
}
if (options != NULL) {
apidt.flags |= fp_flags;
}
ret = do_list(&apidt, cmd, &ldatalistp, &nelem, errstring);
if (ret != FPCFGA_OK) {
list_free(&ldatalistp);
apidt_free(&apidt);
return (err_cvt(ret));
}
apidt_free(&apidt);
}
assert(ldatalistp != NULL);
if (list_ext_postprocess(&ldatalistp, nelem, ap_id_list, nlistp,
errstring) != FPCFGA_OK) {
assert(*ap_id_list == NULL && *nlistp == 0);
ret = FPCFGA_LIB_ERR;
} else {
assert(*ap_id_list != NULL && *nlistp == nelem);
ret = FPCFGA_OK;
}
list_free(&ldatalistp);
return (err_cvt(ret));
}
cfga_err_t
cfga_help(struct cfga_msg *msgp, const char *options, cfga_flags_t flags)
{
cfga_msg(msgp, MSG_HELP_HDR, MSG_HELP_USAGE, 0);
return (CFGA_OK);
}
int
cfga_ap_id_cmp(const cfga_ap_log_id_t ap_id1, const cfga_ap_log_id_t ap_id2)
{
int i = 0;
long long ret;
if (ap_id1 == ap_id2) {
return (0);
}
if (ap_id1 == NULL || ap_id2 == NULL) {
if (ap_id1 == NULL) {
return (0 - (uchar_t)ap_id2[0]);
} else {
return ((uchar_t)ap_id1[0]);
}
}
while (ap_id1[i] == ap_id2[i] && ap_id1[i] != '\0')
i++;
if ((ap_id1[i] == '\0') &&
!(strncmp(&ap_id2[i], LUN_COMP_SEP, strlen(LUN_COMP_SEP)))) {
return (0);
} else if ((ap_id2[i] == '\0') &&
!(strncmp(&ap_id1[i], LUN_COMP_SEP, strlen(LUN_COMP_SEP)))) {
return (0);
}
if (isxdigit(ap_id1[i]) || isxdigit(ap_id2[i])) {
while ((i > 0) && isxdigit(ap_id1[i - 1]))
i--;
if (isxdigit(ap_id1[i]) && isxdigit(ap_id2[i])) {
ret = (strtoll((ap_id1 + i), NULL, 16)) -
(strtoll((ap_id2 + i), NULL, 16));
if (ret > 0) {
return (1);
} else if (ret < 0) {
return (-1);
} else {
return (0);
}
}
}
return (ap_id1[i] - ap_id2[i]);
}