Skip to content

Commit

Permalink
fcoe-utils: Use enum fcoe_status for all status codes
Browse files Browse the repository at this point in the history
There are multiple enums used for error and status
codes. This causes problems when converting error codes
from fcoemon to fcoeadm. This patch makes it so that
only one enum is used for error and status codes.

checkpatch.pl returns a few WARNINGS due to
non-negative error codes. This should be fine.

Signed-off-by: Robert Love <robert.w.love@intel.com>
Tested-by: Ross Brattain <ross.b.brattain@intel.com>
  • Loading branch information
Robert Love committed Mar 8, 2011
1 parent 22acd27 commit 7575678
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
6 changes: 0 additions & 6 deletions fcoe_clif.h
Expand Up @@ -36,12 +36,6 @@
#define CLIF_CMD_RESPONSE_TIMEOUT 5
#define MAX_MSGBUF 512

enum clif_status {
CLI_SUCCESS = 0,
CLI_FAIL,
CLI_NO_ACTION
};

enum clif_action {
CLIF_NONE = 0,
CLIF_CREATE_CMD,
Expand Down
10 changes: 9 additions & 1 deletion fcoeadm.c
Expand Up @@ -349,6 +349,14 @@ int main(int argc, char *argv[])
err:
if (rc) {
switch (rc) {
case EFAIL:
FCOE_LOG_ERR("Command failed\n");
break;

case ENOACTION:
FCOE_LOG_ERR("No action was taken\n");
break;

case EFCOECONN:
FCOE_LOG_ERR("Connection already created on "
"interface %s\n", ifname);
Expand Down Expand Up @@ -406,7 +414,7 @@ int main(int argc, char *argv[])
/*
* This will catch EOPNOTSUPP which should never happen
*/
FCOE_LOG_ERR("Unknown error\n");
FCOE_LOG_ERR("Unknown error code %d\n", rc);
break;
}

Expand Down
53 changes: 25 additions & 28 deletions fcoemon.c
Expand Up @@ -89,12 +89,6 @@
#define FCM_VLAN_DISC_MAX 10 /* stop after 10 attempts */
void fcm_vlan_disc_timeout(void *arg);

enum fcm_srv_status {
fcm_success = 0,
fcm_fail,
fcm_no_action
};

/*
* fcoe service configuration data
* Note: These information are read in from the fcoe service
Expand Down Expand Up @@ -142,7 +136,7 @@ static void fcm_dcbd_event(char *, size_t);
static void fcm_dcbd_cmd_resp(char *, cmd_status);
static void fcm_netif_advance(struct fcm_netif *);
static void fcm_fcoe_action(struct fcm_netif *, struct fcoe_port *);
static int fcm_fcoe_if_action(char *, char *);
static enum fcoe_err fcm_fcoe_if_action(char *, char *);

struct fcm_clif {
int cl_fd;
Expand Down Expand Up @@ -1958,10 +1952,10 @@ static void fcm_cli_reply(struct sock_info *r, int status)
r->fromlen);
}

static int fcm_fcoe_if_action(char *path, char *ifname)
static enum fcoe_err fcm_fcoe_if_action(char *path, char *ifname)
{
FILE *fp = NULL;
int ret = fcm_fail;
enum fcoe_err ret = EFAIL;

fp = fopen(path, "w");
if (!fp) {
Expand All @@ -1976,7 +1970,7 @@ static int fcm_fcoe_if_action(char *path, char *ifname)
goto out;
}

ret = fcm_success;
ret = NOERR;
out:
fclose(fp);
err_out:
Expand Down Expand Up @@ -2028,9 +2022,9 @@ static void fcm_fcoe_action(struct fcm_netif *ff, struct fcoe_port *p)
char *ifname = p->ifname;
char fchost[FCHOSTBUFLEN];
char path[256];
int rc;
enum fcoe_err rc;

rc = fcm_success;
rc = NOERR;
switch (p->action) {
case FCP_CREATE_IF:
FCM_LOG_DBG("OP: CREATE %s\n", p->ifname);
Expand All @@ -2046,7 +2040,7 @@ static void fcm_fcoe_action(struct fcm_netif *ff, struct fcoe_port *p)
fcp_set_next_action(vp, FCP_DESTROY_IF);
vp = fcm_find_next_fcoe_port(vp, p->ifname);
}
rc = fcm_success;
rc = NOERR;
break;
}
rc = fcm_fcoe_if_action(FCOE_DESTROY, ifname);
Expand Down Expand Up @@ -2077,7 +2071,7 @@ static void fcm_fcoe_action(struct fcm_netif *ff, struct fcoe_port *p)
* the fc_host in sysfs.
*/
if (fcoe_find_fchost(ifname, fchost, FCHOSTBUFLEN)) {
fcm_cli_reply(p->sock_reply, CLI_FAIL);
fcm_cli_reply(p->sock_reply, EFAIL);
return;
}

Expand All @@ -2092,7 +2086,7 @@ static void fcm_fcoe_action(struct fcm_netif *ff, struct fcoe_port *p)
* the fc_host in sysfs.
*/
if (fcoe_find_fchost(ifname, fchost, FCHOSTBUFLEN)) {
fcm_cli_reply(p->sock_reply, CLI_FAIL);
fcm_cli_reply(p->sock_reply, EFAIL);
return;
}

Expand Down Expand Up @@ -2256,7 +2250,7 @@ static void fcm_handle_changes()
if (!ff) {
FCM_LOG_DBG("no fcoe_action.\n");
if (p->sock_reply) {
fcm_cli_reply(p->sock_reply, CLI_FAIL);
fcm_cli_reply(p->sock_reply, EFAIL);
free(p->sock_reply);
p->sock_reply = NULL;
p->action = FCP_WAIT;
Expand Down Expand Up @@ -2374,14 +2368,15 @@ static struct fcoe_port *fcm_port_create(char *ifname, int cmd)
return p;
}

static int fcm_cli_create(char *ifname, int cmd, struct sock_info **r)
static enum fcoe_err fcm_cli_create(char *ifname, int cmd,
struct sock_info **r)
{
struct fcoe_port *p, *vp;

p = fcm_find_fcoe_port(ifname, FCP_CFG_IFNAME);
if (p && p->fcoe_enable) {
/* no action needed */
return CLI_NO_ACTION;
return ENOACTION;
}
/* re-enable previous VLANs */
if (p && p->auto_vlan) {
Expand All @@ -2394,12 +2389,13 @@ static int fcm_cli_create(char *ifname, int cmd, struct sock_info **r)
}
p = fcm_port_create(ifname, cmd);
if (!p)
return fcm_fail;
return EFAIL;
p->sock_reply = *r;
return fcm_success;
return NOERR;
}

static int fcm_cli_destroy(char *ifname, int cmd, struct sock_info **r)
static enum fcoe_err fcm_cli_destroy(char *ifname, int cmd,
struct sock_info **r)
{
struct fcoe_port *p;

Expand All @@ -2409,30 +2405,31 @@ static int fcm_cli_destroy(char *ifname, int cmd, struct sock_info **r)
p->fcoe_enable = 0;
fcp_set_next_action(p, cmd);
p->sock_reply = *r;
return fcm_success;
return NOERR;
} else {
/* no action needed */
return CLI_NO_ACTION;
return ENOACTION;
}
}

FCM_LOG_ERR(errno, "%s is not in port list.\n", ifname);
return fcm_fail;
return EFAIL;
}

static int fcm_cli_action(char *ifname, int cmd, struct sock_info **r)
static enum fcoe_err fcm_cli_action(char *ifname, int cmd,
struct sock_info **r)
{
struct fcoe_port *p;

p = fcm_find_fcoe_port(ifname, FCP_CFG_IFNAME);
if (p) {
fcp_set_next_action(p, cmd);
p->sock_reply = *r;
return fcm_success;
return NOERR;
}

FCM_LOG_ERR(errno, "%s is not in port list.\n", ifname);
return fcm_fail;
return EFAIL;
}

static struct sock_info *fcm_alloc_reply(struct sockaddr_un *f,
Expand Down Expand Up @@ -2521,7 +2518,7 @@ static void fcm_srv_receive(void *arg)
free(ifname);
free(reply);
err:
snprintf(rbuf, MSG_RBUF, "%d", CLI_FAIL);
snprintf(rbuf, MSG_RBUF, "%d", EFAIL);
sendto(snum, rbuf, MSG_RBUF, 0, (struct sockaddr *)&from, fromlen);
}

Expand Down
2 changes: 2 additions & 0 deletions include/fcoe_utils.h
Expand Up @@ -61,6 +61,8 @@

enum fcoe_err {
NOERR = 0, /* No error */
EFAIL, /* Command Failed */
ENOACTION, /* No action was taken */
EFCOECONN, /* FCoE connection already exists */
ENOFCOECONN, /* No FCoE connection on interface */
EINTERR, /* Internal error */
Expand Down

0 comments on commit 7575678

Please sign in to comment.