/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include "cfga_ib.h"
#include "cfga_conf.h"
/*
*
*/
/*
* function prototypes:
*/
static ib_service_type_t ib_get_var_type(char *);
static ib_token_t ib_lex(char *, char **);
static void ib_find_eol();
static int ib_get_string(char **, char *);
static int ib_service_record_add(char *,
static ib_token_t ib_get_services(char **);
static boolean_t ib_cmp_service();
static void ib_free_service_recs(void);
static int ib_cleanup_file(int);
static int ib_init_file(char **);
int ib_add_service(char **);
int ib_delete_service(char **);
int ib_list_services(struct cfga_msg *, char **);
static int ib_service_record_valid(char *);
/* Global variables */
/*
* supported "name=value" pairs from IBCONF_FILE
*/
{ "name", IB_NAME },
{ "class", IB_CLASS },
{ "port-svc-list", IB_PORT_SERVICE },
{ "vppa-svc-list", IB_VPPA_SERVICE },
{ "hca-svc-list", IB_HCASVC_SERVICE },
};
/* progress indicator */
extern char *service_name; /* service name */
/*
* Function:
* ib_get_var_type
* Input:
* str - A parsed string from IBCONF_FILE
* Output:
* NONE
* Returns:
* Service type
* Description:
* Returns the field from the token
*/
static ib_service_type_t
{
cfgvar = &ibcfg_varlist[0];
break;
else
cfgvar++;
}
}
/*
* Function:
* ib_lex
* Input:
* NONE
* Output:
* val - value just read
* errmsg - pointer to error message string, if there are any errors
* Returns:
* valid IB token
* Description:
* Read tokens from the IBCONF_FILE and parse them
*/
/* ARGSUSED */
static ib_token_t
{
;
/* make a note of the beginning of token */
switch (ch) {
case '=':
break;
case '&':
break;
case '|':
break;
case '*':
break;
case '#':
break;
case ':':
break;
case ';':
break;
case ',':
break;
case '/':
break;
case ' ':
case '\t':
case '\f':
(void) UNGETC(ibcfg_cntr);
token = WHITE_SPACE;
break;
case '\n':
case '\r':
break;
case '"':
cp--;
badquote = 0;
switch (ch) {
case '\n':
case -1:
"Missing \"");
*cp++ = '\n';
badquote = 1;
(void) UNGETC(ibcfg_cntr);
break;
case '\\':
/* escape the character */
break;
}
oval = 0;
ch -= '0';
}
(void) UNGETC(ibcfg_cntr);
/* check for character overflow? */
if (oval > 127) {
"Character overflow detected.\n");
}
break;
default:
break;
}
}
break;
default:
if (ch == -1) {
break;
}
/*
* detect a lone '-' (including at the end of a line), and
* identify it as a 'name'
*/
if (ch == '-') {
(void) UNGETC(ibcfg_cntr);
cp--;
break;
}
}
if (ch == '0') {
}
(void) UNGETC(ibcfg_cntr);
} else {
goto digit;
}
} else {
}
(void) UNGETC(ibcfg_cntr);
}
if (ch != '\\') {
} else {
/*
* if the character was a backslash,
* back up so we can overwrite it with
* the next (i.e. escaped) character.
*/
cp--;
}
if (ch == '\\')
}
(void) UNGETC(ibcfg_cntr);
} else
return (-1);
break;
}
*cp = '\0';
return (token);
}
/*
* Function:
* ib_find_eol
* Input:
* NONE
* Output:
* NONE
* Returns:
* NONE
* Description:
* Leave NEWLINE as the next character.
*/
static void
{
int ch;
(void) UNGETC(ibcfg_cntr);
break;
}
}
}
/*
* Function:
* ib_get_string
* Input:
* tchar - name of the string
* Output:
* llptr - Valid string
* Returns:
* 1 for success, NULL for errors.
* Description:
* The next item on the line is a string value. Allocate memory for
* it and copy the string. Return 1, and set arg ptr to newly allocated
* and initialized buffer, or NULL if an error occurs.
*/
static int
{
char *cp;
char *start = (char *)0;
/* copy string */
return (0);
}
/* convert some common escape sequences */
if (*start == '\\') {
switch (*(start + 1)) {
case 't':
/* tab */
*cp++ = '\t';
tlen--;
start += 2;
break;
case 'n':
/* new line */
*cp++ = '\n';
tlen--;
start += 2;
break;
case 'b':
/* back space */
*cp++ = '\b';
tlen--;
start += 2;
break;
default:
/* simply copy it */
break;
}
} else {
}
}
*cp = '\0';
return (1);
}
/*
* Function:
* ib_service_record_add
* Input:
* service - name of the service
* type - type of the service
* Output:
* rec - one valid service record
* Returns:
* CFGA_IB_OK on success or an appropriate error
* Description:
* Add one record to internal data structures
*/
static int
{
DPRINTF("ib_service_record_add: (%x, %s) "
return (CFGA_IB_ALLOC_FAIL);
if (type == IB_PORT_SERVICE) {
if (ibcfg_port_head) {
} else
} else if (type == IB_VPPA_SERVICE) {
if (ibcfg_vppa_head) {
} else
} else if (type == IB_HCASVC_SERVICE) {
if (ibcfg_hca_head) {
} else
}
return (CFGA_IB_OK);
}
/*
* Function:
* ib_get_services
* Input:
* errmsg - Error message filled in case of a failure
* Output:
* rec - one valid service record
* Returns:
* CFGA_IB_OK on success or an appropriate error
* Description:
* Fetch one record from the IBCONF_FILE
*/
static ib_token_t
{
char *llptr;
/* skip comments */
ib_find_eol();
if (parse_state == IB_NEWVAR) {
"Syntax Error: Invalid type %s",
tokval);
} else {
/* Note the beginning of the entry */
if (sor) {
}
if (cfgvar == IB_PORT_SERVICE)
else if (cfgvar == IB_VPPA_SERVICE)
else if (cfgvar == IB_HCASVC_SERVICE)
}
} else if (parse_state == IB_VAR_VALUE) {
if ((cfgvar == IB_PORT_SERVICE) ||
(cfgvar == IB_VPPA_SERVICE) ||
(cfgvar == IB_HCASVC_SERVICE)) {
llptr) &&
CFGA_IB_OK) {
return (E_O_F);
} else {
}
} else {
}
} else {
"Syntax Error: Invalid value %s "
"for type: %s\n", tokval,
}
} else if (parse_state == IB_ERROR) {
/* just skip */
DPRINTF("ib_get_services: ERROR\n");
} else {
"Syntax Error: at %s", tokval);
}
if (parse_state == IB_CONFIG_VAR) {
"Syntax Error: unexpected '='");
} else {
}
} else if (parse_state != IB_ERROR) {
"Syntax Error: unexpected '='");
}
} else {
"Syntax Error: at: %s", tokval);
}
}
return (token);
}
/*
* Function:
* ib_cmp_service
* Input:
* NONE
* Output:
* NONE
* Returns:
* B_TRUE if this service is already seen. B_FALSE if not.
* Description:
* Compare the service just read from the services already seen.
* Check if this service was already seen or not.
*/
static boolean_t
{
DPRINTF("ib_cmp_service: (%x, %s) "
"(#port = %d #vppa = %d #hca = %d)\n", service_type,
DPRINTF("ib_cmp_service:P usvc = %s, usvc_name = %s\n",
return (B_TRUE);
}
DPRINTF("ib_cmp_service:V utype = %x, usvc_name = %s\n",
return (B_TRUE);
}
DPRINTF("ib_cmp_service:V utype = %x, usvc_name = %s\n",
return (B_TRUE);
}
return (B_FALSE);
}
/*
* Function:
* ib_free_service_recs
* Input:
* NONE
* Output:
* NONE
* Returns:
* CFGA_IB_OK on success or an appropriate error
* Description:
* Free the service records allocated in ib_get_services
*/
static void
ib_free_service_recs(void)
{
DPRINTF("ib_free_service_recs: "
"#port_services = %d, #vppa_services = %d, #hca_services = %d\n",
}
}
}
}
/*
* Function:
* ib_cleanup_file
* Input:
* rval - error return value
* Output:
* NONE
* Returns:
* CFGA_IB_OK on success or an appropriate error
* Description:
* Cleanup IBCONF_FILE etc.
*/
static int
{
DPRINTF("ib_cleanup_file: unlock file %s failed\n",
}
ibcfg_fd = -1;
DPRINTF("ib_cleanup_file: tmpfile %s being renamed to %s\n",
}
(void) mutex_unlock(&ibcfg_lock);
return (rv);
}
/*
* Function:
* ib_init_file
* Input:
* NONE
* Output:
* errmsg - Error message filled in case of a failure
* Returns:
* CFGA_IB_OK on success or an appropriate error
* Description:
* Initialize IBCONF_FILE for reading
*/
static int
{
(void) mutex_lock(&ibcfg_lock);
(void) mutex_unlock(&ibcfg_lock);
DPRINTF("ib_init_file: calloc errmsg failed\n");
return (CFGA_IB_CONFIG_FILE_ERR);
}
}
/* Open the .conf file */
"failed to open %s file\n", ibconf_file);
(void) mutex_unlock(&ibcfg_lock);
return (CFGA_IB_CONFIG_FILE_ERR);
}
/* Lock the file so that another cfgadm instance doesn't modify it */
"failed to lock %s file\n", ibconf_file);
ibcfg_fd = -1;
(void) mutex_unlock(&ibcfg_lock);
return (CFGA_IB_LOCK_FILE_ERR);
}
return (ib_cleanup_file(CFGA_IB_CONFIG_FILE_ERR));
}
/* Allocate a buffer for the file */
DPRINTF("ib_init_file: failed to fstat %s file\n",
return (ib_cleanup_file(CFGA_IB_ALLOC_FAIL));
}
/* Check if size matches */
return (ib_cleanup_file(CFGA_IB_CONFIG_FILE_ERR));
}
/*
* These variables need to be reinitialized here as they may
* have been modified by a previous thread that called this
* function
*/
ibcfg_linenum = 1;
ibcfg_cntr = 0;
ibcfg_brec = 0;
ibcfg_btoken = 0;
ibcfg_nport_services = 0;
ibcfg_nvppa_services = 0;
ibcfg_nhca_services = 0;
return (CFGA_IB_OK);
}
/*
* Function:
* ib_add_service
* Input:
* NONE
* Output:
* errmsg - Error message filled in case of a failure
* Returns:
* CFGA_IB_OK on success or an appropriate error
* Description:
* open IBCONF_FILE and add "service_name".
*/
int
{
int rval;
char *sbuf;
DPRINTF("ib_add_service: initializing file failed\n");
return (rval);
}
/* Start reading the file */
found = ib_cmp_service();
DPRINTF("ib_add_service: token=%x, found=%x\n",
break;
}
}
/* Service shouldn't already exist while adding */
if (found) {
DPRINTF("ib_add_service: invalid add operation\n");
return (ib_cleanup_file(CFGA_IB_SVC_EXISTS_ERR));
}
DPRINTF("!FOUND and adding\n");
switch (service_type) {
case IB_PORT_SERVICE :
break;
case IB_VPPA_SERVICE :
break;
case IB_HCASVC_SERVICE :
break;
default :
DPRINTF("ib_add_service: invalid add operation\n");
return (ib_cleanup_file(CFGA_IB_SVC_INVAL_ERR));
}
DPRINTF("ib_add_service: failed to calloc sbuf %s file\n",
return (ib_cleanup_file(CFGA_IB_ALLOC_FAIL));
}
ibcfg_brec += 1;
} else
/* Seek to the beginning of the file */
return (ib_cleanup_file(CFGA_IB_CONFIG_FILE_ERR));
}
/* Add service to w/ IBNEX */
"%s service incore ", service_name);
return (ib_cleanup_file(CFGA_IB_SVC_EXISTS_ERR));
}
/* Write the modified file */
return (ib_cleanup_file(CFGA_IB_CONFIG_FILE_ERR));
}
/* Write the rest of the file as it was */
DPRINTF("ib_add_service: write %s file failed 2\n",
return (ib_cleanup_file(CFGA_IB_CONFIG_FILE_ERR));
}
return (ib_cleanup_file(rval));
}
/*
* Function:
* ib_delete_service
* Input:
* NONE
* Output:
* errmsg - Error message filled in case of a failure
* Returns:
* CFGA_IB_OK on success or an appropriate error
* Description:
* open ib.conf file and delete "service_name"
*/
int
{
int rval;
int num_svcs;
int skip_len;
int sbuf_len;
int tot_len;
DPRINTF("ib_delete_service: type = %x, service_name=%s\n",
DPRINTF("ib_delete_service: initializing file failed\n");
return (rval);
}
/* Start reading the file */
DPRINTF("ib_delete_service: token=%x, found=%x\n",
break;
}
}
/* No service found, return */
if (!found) {
DPRINTF("ib_delete_service: invalid delete operation\n");
"does not exist ", service_name);
return (ib_cleanup_file(CFGA_IB_SVC_NO_EXIST_ERR));
}
DPRINTF("FOUND and deleting \n");
switch (service_type) {
case IB_PORT_SERVICE :
break;
case IB_VPPA_SERVICE :
break;
case IB_HCASVC_SERVICE :
break;
default :
DPRINTF("ib_delete_service: invalid delete "
"operation\n");
return (ib_cleanup_file(CFGA_IB_SVC_INVAL_ERR));
}
DPRINTF("ib_delete_service: sbuf alloc failed %s\n",
return (ib_cleanup_file(CFGA_IB_ALLOC_FAIL));
}
if (num_svcs == 1) {
sbuf_len = 2;
skip_len = 0;
} else {
if (service_type == IB_PORT_SERVICE) {
continue;
}
} else if (service_type == IB_VPPA_SERVICE) {
continue;
}
} else {
continue;
}
}
skip_len = 4;
sbuf_len -= 2;
}
"failed to creat %s file\n", ibconf_file);
DPRINTF("ib_delete_service: failed to creat tmpnamef\n");
return (ib_cleanup_file(CFGA_IB_ALLOC_FAIL));
}
/* Delete service from IBNEX */
"in core %s entry ", service_name);
return (ib_cleanup_file(CFGA_IB_SVC_EXISTS_ERR));
}
/* write till ibcfg_brec */
DPRINTF("ib_delete_service: write %s file failed 1\n",
return (ib_cleanup_file(CFGA_IB_CONFIG_FILE_ERR));
}
/* write modified buffer */
DPRINTF("ib_delete_service: write %s file failed 2\n",
return (ib_cleanup_file(CFGA_IB_CONFIG_FILE_ERR));
}
/* Write the rest of the file as it was */
DPRINTF("ib_delete_service: write %s file failed 3\n",
return (ib_cleanup_file(CFGA_IB_CONFIG_FILE_ERR));
}
/* No error encountered */
return (ib_cleanup_file(rval));
}
/*
* Function:
* ib_list_services
* Input:
* msgp - CFGADM message pointer
* Output:
* errmsg - Error message filled in case of a failure
* Returns:
* CFGA_IB_OK on success or an appropriate error
* Description:
* open IBCONF_FILE and list services.
*/
int
{
DPRINTF("ib_list_services:\n");
DPRINTF("ib_list_services: initializing file failed\n");
return (rval);
}
/* start reading the file */
DPRINTF("ib_list_services: #port_services = %d, #vppa_services = %d,"
" #hca_services = %d\n", ibcfg_nport_services,
if (ibcfg_nport_services) {
DPRINTF("ib_list_services: svc_name = %s\n",
}
}
if (ibcfg_nvppa_services) {
DPRINTF("ib_list_services: svc_name = %s\n",
}
}
if (ibcfg_nhca_services) {
DPRINTF("ib_list_services: svc_name = %s\n",
}
}
return (ib_cleanup_file(CFGA_IB_OK));
}
/*
* Function:
* ib_conf_control_ioctl
* Input:
* cmd - Command to DEVCTL_AP_CONTROL devctl
* Output:
* NONE
* Returns:
* CFGA_IB_OK if it succeeds or an appropriate error.
* Description:
* Issues DEVCTL_AP_CONTROL devctl with cmd
*/
static cfga_ib_ret_t
{
/* try to open the static IB ap_id */
DPRINTF("ib_conf_control_ioctl: open failed: errno = %d\n",
errno);
/* Provides a more useful error msg */
return (rv);
}
DPRINTF("ib_conf_control_ioctl: size ioctl ERR, errno: %d\n",
errno);
}
return (rv);
}
/*
* This functions checks if the service name is valid. Valid
* service names have :
* 0 < strlen(name) <= 4
* Service name is unique
* Returns: 0 - Name is not valid, 1 - Name is valid
*/
static int
{
char *tmp_service_name;
return (0);
}
if (ib_cmp_service() == B_TRUE)
rc = 0;
return (rc);
}