diff options
author | Mike Christie <michaelc@cs.wisc.edu> | 2011-01-28 21:53:22 -0600 |
---|---|---|
committer | Mike Christie <michaelc@cs.wisc.edu> | 2011-01-31 21:52:18 -0600 |
commit | 39d4ceb04f051c208ae7509d268a3871ffa194c5 (patch) | |
tree | 3ca883cb4c5cceba1436c4f495aef1edb65ef2a1 | |
parent | 9dca10af955255f9806942cb3370d4a86660a655 (diff) | |
download | open-iscsi-39d4ceb04f051c208ae7509d268a3871ffa194c5.tar.gz |
Add userspace/tools iscsi error code defs
This patch moves the mgmt ipc errs to iscsi_err.h. iscsid
now returns these instead of the mgmt ipc ones. In the next
patches these errors will be expanded and they will be returned
by the iscsi tools.
-rw-r--r-- | usr/event_poll.c | 3 | ||||
-rw-r--r-- | usr/initiator.c | 135 | ||||
-rw-r--r-- | usr/initiator.h | 4 | ||||
-rw-r--r-- | usr/initiator_common.c | 3 | ||||
-rw-r--r-- | usr/iscsi_err.h | 51 | ||||
-rw-r--r-- | usr/iscsid.c | 3 | ||||
-rw-r--r-- | usr/iscsid_req.c | 29 | ||||
-rw-r--r-- | usr/iscsistart.c | 3 | ||||
-rw-r--r-- | usr/mgmt_ipc.c | 102 | ||||
-rw-r--r-- | usr/mgmt_ipc.h | 30 | ||||
-rw-r--r-- | usr/session_mgmt.c | 5 |
11 files changed, 200 insertions, 168 deletions
diff --git a/usr/event_poll.c b/usr/event_poll.c index bfcdcf3..f36fec1 100644 --- a/usr/event_poll.c +++ b/usr/event_poll.c @@ -35,6 +35,7 @@ #include "iscsi_ipc.h" #include "actor.h" #include "initiator.h" +#include "iscsi_err.h" static int reap_count; @@ -174,5 +175,5 @@ void event_loop(struct iscsi_ipc *ipc, int control_fd, int mgmt_ipc_fd) sysfs_cleanup(); } if (shutdown_qtask) - mgmt_ipc_write_rsp(shutdown_qtask, MGMT_IPC_OK); + mgmt_ipc_write_rsp(shutdown_qtask, ISCSI_SUCCESS); } diff --git a/usr/initiator.c b/usr/initiator.c index 81e407f..70a2c8e 100644 --- a/usr/initiator.c +++ b/usr/initiator.c @@ -46,6 +46,7 @@ #include "iscsi_settings.h" #include "iface.h" #include "sysdeps.h" +#include "iscsi_err.h" #define ISCSI_CONN_ERR_REOPEN_DELAY 3 #define ISCSI_INTERNAL_ERR_REOPEN_DELAY 5 @@ -245,7 +246,7 @@ __session_conn_create(iscsi_session_t *session, int cid) if (iscsi_ev_context_alloc(conn)) { log_error("cannot allocate context_pool for conn cid %d", cid); - return ENOMEM; + return ISCSI_ERR_NOMEM; } conn->state = STATE_FREE; @@ -442,9 +443,9 @@ conn_delete_timers(iscsi_conn_t *conn) actor_delete(&conn->nop_out_timer); } -static mgmt_ipc_err_e +static int session_conn_shutdown(iscsi_conn_t *conn, queue_task_t *qtask, - mgmt_ipc_err_e err) + int err) { iscsi_session_t *session = conn->session; @@ -466,7 +467,7 @@ session_conn_shutdown(iscsi_conn_t *conn, queue_task_t *qtask, conn->id, STOP_CONN_TERM)) { log_error("can't stop connection %d:%d (%d)", session->id, conn->id, errno); - return MGMT_IPC_ERR_INTERNAL; + return ISCSI_ERR_INTERNAL; } } @@ -474,7 +475,7 @@ session_conn_shutdown(iscsi_conn_t *conn, queue_task_t *qtask, if (ipc->destroy_conn(session->t->handle, session->id, conn->id)) { log_error("can not safely destroy connection %d", conn->id); - return MGMT_IPC_ERR_INTERNAL; + return ISCSI_ERR_INTERNAL; } cleanup: @@ -483,7 +484,7 @@ cleanup: if (ipc->destroy_session(session->t->handle, session->id)) { log_error("can not safely destroy session %d", session->id); - return MGMT_IPC_ERR_INTERNAL; + return ISCSI_ERR_INTERNAL; } } @@ -497,7 +498,7 @@ cleanup: mgmt_ipc_write_rsp(qtask, err); conn_delete_timers(conn); __session_destroy(session); - return MGMT_IPC_OK; + return ISCSI_SUCCESS; } static void @@ -654,7 +655,7 @@ static int iscsi_retry_initial_login(struct iscsi_conn *conn) } static void iscsi_login_eh(struct iscsi_conn *conn, struct queue_task *qtask, - mgmt_ipc_err_e err) + int err) { struct iscsi_session *session = conn->session; @@ -672,7 +673,7 @@ static void iscsi_login_eh(struct iscsi_conn *conn, struct queue_task *qtask, "R_STAGE_NO_CHANGE"); /* timeout during initial connect. * clean connection. write ipc rsp or retry */ - if (err == MGMT_IPC_ERR_FATAL_LOGIN_FAILURE || + if (err == ISCSI_ERR_FATAL_LOGIN || !iscsi_retry_initial_login(conn)) session_conn_shutdown(conn, qtask, err); else { @@ -688,7 +689,7 @@ static void iscsi_login_eh(struct iscsi_conn *conn, struct queue_task *qtask, "R_STAGE_SESSION_REDIRECT"); /* timeout during initial redirect connect * clean connection. write ipc rsp or retry */ - if (err == MGMT_IPC_ERR_FATAL_LOGIN_FAILURE || + if (err == ISCSI_ERR_FATAL_LOGIN || !iscsi_retry_initial_login(conn)) session_conn_shutdown(conn, qtask, err); else @@ -721,7 +722,7 @@ static void iscsi_login_eh(struct iscsi_conn *conn, struct queue_task *qtask, * initial redirected connect. Clean connection * and write rsp or retry. */ - if (err == MGMT_IPC_ERR_FATAL_LOGIN_FAILURE || + if (err == ISCSI_ERR_FATAL_LOGIN || !iscsi_retry_initial_login(conn)) session_conn_shutdown(conn, qtask, err); else @@ -736,7 +737,7 @@ static void iscsi_login_eh(struct iscsi_conn *conn, struct queue_task *qtask, break; case R_STAGE_SESSION_CLEANUP: session_conn_shutdown(conn, qtask, - MGMT_IPC_ERR_PDU_TIMEOUT); + ISCSI_ERR_PDU_TIMEOUT); break; default: break; @@ -760,7 +761,7 @@ __conn_error_handle(iscsi_session_t *session, iscsi_conn_t *conn) * just cleanup and return to the user. */ if (conn->logout_qtask) { - session_conn_shutdown(conn, conn->logout_qtask, MGMT_IPC_OK); + session_conn_shutdown(conn, conn->logout_qtask, ISCSI_SUCCESS); return; } @@ -801,7 +802,7 @@ __conn_error_handle(iscsi_session_t *session, iscsi_conn_t *conn) qtask = session->sync_qtask; else qtask = &session->reopen_qtask; - iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_TRANS_FAILURE); + iscsi_login_eh(conn, qtask, ISCSI_ERR_TRANS); return; } log_debug(1, "ignoring conn error in login. " @@ -841,7 +842,7 @@ static void session_conn_error(void *data) switch (error) { case ISCSI_ERR_INVALID_HOST: - if (session_conn_shutdown(conn, NULL, MGMT_IPC_OK)) + if (session_conn_shutdown(conn, NULL, ISCSI_SUCCESS)) log_error("BUG: Could not shutdown session."); break; default: @@ -856,13 +857,13 @@ static void iscsi_login_timedout(void *data) switch (conn->state) { case STATE_XPT_WAIT: - iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_TRANS_TIMEOUT); + iscsi_login_eh(conn, qtask, ISCSI_ERR_TRANS_TIMEOUT); break; case STATE_IN_LOGIN: - iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_PDU_TIMEOUT); + iscsi_login_eh(conn, qtask, ISCSI_ERR_PDU_TIMEOUT); break; default: - iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_INTERNAL); + iscsi_login_eh(conn, qtask, ISCSI_ERR_INTERNAL); break; } } @@ -968,7 +969,7 @@ static void session_scan_host(struct iscsi_session *session, int hostno, pid = iscsi_sysfs_scan_host(hostno, 1); if (pid == 0) { - mgmt_ipc_write_rsp(qtask, MGMT_IPC_OK); + mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS); if (session) iscsi_sysfs_for_each_device( @@ -983,7 +984,7 @@ static void session_scan_host(struct iscsi_session *session, int hostno, free(qtask); } } else - mgmt_ipc_write_rsp(qtask, MGMT_IPC_ERR_INTERNAL); + mgmt_ipc_write_rsp(qtask, ISCSI_ERR_INTERNAL); } static void @@ -996,12 +997,12 @@ setup_full_feature_phase(iscsi_conn_t *conn) actor_delete(&conn->login_timer); if (iscsi_session_set_params(conn)) { - iscsi_login_eh(conn, c->qtask, MGMT_IPC_ERR_LOGIN_FAILURE); + iscsi_login_eh(conn, c->qtask, ISCSI_ERR_LOGIN); return; } if (iscsi_host_set_params(session)) { - iscsi_login_eh(conn, c->qtask, MGMT_IPC_ERR_LOGIN_FAILURE); + iscsi_login_eh(conn, c->qtask, ISCSI_ERR_LOGIN); return; } @@ -1009,7 +1010,7 @@ setup_full_feature_phase(iscsi_conn_t *conn) &rc) || rc) { log_error("can't start connection %d:%d retcode %d (%d)", session->id, conn->id, rc, errno); - iscsi_login_eh(conn, c->qtask, MGMT_IPC_ERR_INTERNAL); + iscsi_login_eh(conn, c->qtask, ISCSI_ERR_INTERNAL); return; } @@ -1033,7 +1034,7 @@ setup_full_feature_phase(iscsi_conn_t *conn) session->sync_qtask = NULL; session_online_devs(session->hostno, session->id); - mgmt_ipc_write_rsp(c->qtask, MGMT_IPC_OK); + mgmt_ipc_write_rsp(c->qtask, ISCSI_SUCCESS); log_warning("connection%d:%d is operational after recovery " "(%d attempts)", session->id, conn->id, session->reopen_cnt); @@ -1113,7 +1114,7 @@ static void iscsi_stop(void *data) if (!iscsi_send_logout(conn)) return; - rc = session_conn_shutdown(conn, conn->logout_qtask, MGMT_IPC_OK); + rc = session_conn_shutdown(conn, conn->logout_qtask, ISCSI_SUCCESS); if (rc) log_error("BUG: Could not shutdown session."); } @@ -1249,8 +1250,7 @@ static void iscsi_recv_login_rsp(struct iscsi_conn *conn) /* more nego. needed! */ conn->state = STATE_IN_LOGIN; if (iscsi_login_req(session, c)) { - iscsi_login_eh(conn, c->qtask, - MGMT_IPC_ERR_LOGIN_FAILURE); + iscsi_login_eh(conn, c->qtask, ISCSI_ERR_LOGIN); return; } } else @@ -1259,12 +1259,12 @@ static void iscsi_recv_login_rsp(struct iscsi_conn *conn) return; retry: /* retry if not initial login or initial login has not timed out */ - iscsi_login_eh(conn, c->qtask, MGMT_IPC_ERR_LOGIN_FAILURE); + iscsi_login_eh(conn, c->qtask, ISCSI_ERR_LOGIN); return; failed: /* force failure if initial login */ session->reopen_cnt = session->nrec.session.initial_login_retry_max; - iscsi_login_eh(conn, c->qtask, MGMT_IPC_ERR_FATAL_LOGIN_FAILURE); + iscsi_login_eh(conn, c->qtask, ISCSI_ERR_FATAL_LOGIN); return; } @@ -1441,7 +1441,7 @@ static void session_conn_poll(void *data) struct iscsi_ev_context *ev_context = data; iscsi_conn_t *conn = ev_context->conn; struct iscsi_session *session = conn->session; - mgmt_ipc_err_e err = MGMT_IPC_OK; + int err = ISCSI_SUCCESS; queue_task_t *qtask = ev_context->data; iscsi_login_context_t *c = &conn->login_context; int rc; @@ -1460,7 +1460,7 @@ static void session_conn_poll(void *data) /* while polling the recv pool should be full */ log_error("BUG: session_conn_poll could not get conn " "context."); - iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_INTERNAL); + iscsi_login_eh(conn, qtask, ISCSI_ERR_INTERNAL); return; } ev_context->data = qtask; @@ -1473,7 +1473,7 @@ static void session_conn_poll(void *data) if (session->id == -1) { if (conn->id == 0 && session_ipc_create(session)) { log_error("Can't create session."); - err = MGMT_IPC_ERR_INTERNAL; + err = ISCSI_ERR_INTERNAL; goto cleanup; } log_debug(3, "created new iSCSI session sid %d host " @@ -1482,7 +1482,7 @@ static void session_conn_poll(void *data) if (ipc->create_conn(session->t->handle, session->id, conn->id, &conn->id)) { log_error("Can't create connection."); - err = MGMT_IPC_ERR_INTERNAL; + err = ISCSI_ERR_INTERNAL; goto cleanup; } log_debug(3, "created new iSCSI connection " @@ -1504,7 +1504,7 @@ static void session_conn_poll(void *data) log_error("can't bind conn %d:%d to session %d, " "retcode %d (%d)", session->id, conn->id, session->id, rc, errno); - iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_LOGIN_FAILURE); + iscsi_login_eh(conn, qtask, ISCSI_ERR_LOGIN); return; } log_debug(3, "bound iSCSI connection %d:%d to session %d", @@ -1518,13 +1518,13 @@ static void session_conn_poll(void *data) conn->exp_statsn = iscsi_sysfs_get_exp_statsn(session->id); if (iscsi_login_begin(session, c)) { - iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_LOGIN_FAILURE); + iscsi_login_eh(conn, qtask, ISCSI_ERR_LOGIN); return; } conn->state = STATE_IN_LOGIN; if (iscsi_login_req(session, c)) { - iscsi_login_eh(conn, qtask, MGMT_IPC_ERR_LOGIN_FAILURE); + iscsi_login_eh(conn, qtask, ISCSI_ERR_LOGIN); return; } } else { @@ -1629,13 +1629,14 @@ session_login_task(node_rec_t *rec, queue_task_t *qtask) iscsi_session_t *session; iscsi_conn_t *conn; struct iscsi_transport *t; + int rc; if (session_is_running(rec)) - return MGMT_IPC_ERR_EXISTS; + return ISCSI_ERR_SESS_EXISTS; t = iscsi_sysfs_get_transport_by_name(rec->iface.transport_name); if (!t) - return MGMT_IPC_ERR_TRANS_NOT_FOUND; + return ISCSI_ERR_TRANS_NOT_FOUND; if ((!(t->caps & CAP_RECOVERY_L0) && rec->session.iscsi.ERL != 0) || @@ -1688,27 +1689,28 @@ session_login_task(node_rec_t *rec, queue_task_t *qtask) session = __session_create(rec, t); if (!session) - return MGMT_IPC_ERR_LOGIN_FAILURE; + return ISCSI_ERR_LOGIN; /* FIXME: login all connections! marked as "automatic" */ /* create leading connection */ - if (__session_conn_create(session, 0)) { + rc = __session_conn_create(session, 0); + if (rc) { __session_destroy(session); - return MGMT_IPC_ERR_LOGIN_FAILURE; + return rc; } conn = &session->conn[0]; qtask->conn = conn; if (iscsi_host_set_net_params(&rec->iface, session)) { __session_destroy(session); - return MGMT_IPC_ERR_LOGIN_FAILURE; + return ISCSI_ERR_LOGIN; } conn->state = STATE_XPT_WAIT; if (iscsi_conn_connect(conn, qtask)) { __session_destroy(session); - return MGMT_IPC_ERR_TRANS_FAILURE; + return ISCSI_ERR_TRANS; } if (gettimeofday(&conn->initial_connect_time, NULL)) @@ -1717,17 +1719,19 @@ session_login_task(node_rec_t *rec, queue_task_t *qtask) "login early. You should manually login."); qtask->rsp.command = MGMT_IPC_SESSION_LOGIN; - qtask->rsp.err = MGMT_IPC_OK; - return MGMT_IPC_OK; + qtask->rsp.err = ISCSI_SUCCESS; + return ISCSI_SUCCESS; } static int sync_conn(iscsi_session_t *session, uint32_t cid) { iscsi_conn_t *conn; + int rc; - if (__session_conn_create(session, cid)) - return ENOMEM; + rc = __session_conn_create(session, cid); + if (rc) + return rc; conn = &session->conn[cid]; /* TODO: must export via sysfs so we can pick this up */ @@ -1735,7 +1739,7 @@ sync_conn(iscsi_session_t *session, uint32_t cid) return 0; } -mgmt_ipc_err_e +int iscsi_sync_session(node_rec_t *rec, queue_task_t *qtask, uint32_t sid) { iscsi_session_t *session; @@ -1744,30 +1748,25 @@ iscsi_sync_session(node_rec_t *rec, queue_task_t *qtask, uint32_t sid) t = iscsi_sysfs_get_transport_by_name(rec->iface.transport_name); if (!t) - return MGMT_IPC_ERR_TRANS_NOT_FOUND; + return ISCSI_ERR_TRANS_NOT_FOUND; session = __session_create(rec, t); if (!session) - return MGMT_IPC_ERR_LOGIN_FAILURE; + return ISCSI_ERR_LOGIN; session->id = sid; session->hostno = iscsi_sysfs_get_host_no_from_sid(sid, &err); if (err) { log_error("Could not get hostno for session %d\n", sid); - err = MGMT_IPC_ERR_NOT_FOUND; + err = ISCSI_ERR_INTERNAL; goto destroy_session; } session->r_stage = R_STAGE_SESSION_REOPEN; err = sync_conn(session, 0); - if (err) { - if (err == ENOMEM) - err = MGMT_IPC_ERR_NOMEM; - else - err = MGMT_IPC_ERR_INVAL; + if (err) goto destroy_session; - } session->sync_qtask = qtask; qtask->rsp.command = MGMT_IPC_SESSION_SYNC; @@ -1798,12 +1797,12 @@ session_logout_task(int sid, queue_task_t *qtask) { iscsi_session_t *session; iscsi_conn_t *conn; - mgmt_ipc_err_e rc = MGMT_IPC_OK; + int rc = ISCSI_SUCCESS; session = session_find_by_sid(sid); if (!session) { log_debug(1, "session sid %d not found.\n", sid); - return MGMT_IPC_ERR_NOT_FOUND; + return ISCSI_ERR_SESS_NOT_FOUND; } conn = &session->conn[0]; /* @@ -1818,7 +1817,7 @@ session_logout_task(int sid, queue_task_t *qtask) invalid_state: log_error("session in invalid state for logout. " "Try again later\n"); - return MGMT_IPC_ERR_INTERNAL; + return ISCSI_ERR_INTERNAL; } /* FIXME: logout all active connections */ @@ -1834,22 +1833,22 @@ invalid_state: switch (conn->state) { case STATE_LOGGED_IN: if (!session_unbind(session)) - return MGMT_IPC_OK; + return ISCSI_SUCCESS; /* unbind is not supported so just do old logout */ if (!iscsi_send_logout(conn)) - return MGMT_IPC_OK; + return ISCSI_SUCCESS; log_error("Could not send logout pdu. Dropping session\n"); /* fallthrough */ default: - rc = session_conn_shutdown(conn, qtask, MGMT_IPC_OK); + rc = session_conn_shutdown(conn, qtask, ISCSI_SUCCESS); break; } return rc; } -mgmt_ipc_err_e +int iscsi_host_send_targets(queue_task_t *qtask, int host_no, int do_login, struct sockaddr_storage *ss) { @@ -1858,15 +1857,15 @@ iscsi_host_send_targets(queue_task_t *qtask, int host_no, int do_login, t = iscsi_sysfs_get_transport_by_hba(host_no); if (!t) { log_error("Invalid host no %d for sendtargets\n", host_no); - return MGMT_IPC_ERR_TRANS_FAILURE; + return ISCSI_ERR_TRANS_NOT_FOUND; } if (!(t->caps & CAP_SENDTARGETS_OFFLOAD)) - return MGMT_IPC_ERR_TRANS_CAPS; + return ISCSI_ERR_TRANS_CAPS; if (ipc->sendtargets(t->handle, host_no, (struct sockaddr *)ss)) - return MGMT_IPC_ERR; + return ISCSI_ERR; - return MGMT_IPC_OK; + return ISCSI_SUCCESS; } /* diff --git a/usr/initiator.h b/usr/initiator.h index de73f71..0fb2b7a 100644 --- a/usr/initiator.h +++ b/usr/initiator.h @@ -336,9 +336,9 @@ extern int iscsi_io_recv_pdu(iscsi_conn_t *conn, struct iscsi_hdr *hdr, extern int session_login_task(node_rec_t *rec, queue_task_t *qtask); extern int session_logout_task(int sid, queue_task_t *qtask); extern iscsi_session_t *session_find_by_sid(uint32_t sid); -extern mgmt_ipc_err_e iscsi_sync_session(node_rec_t *rec, queue_task_t +extern int iscsi_sync_session(node_rec_t *rec, queue_task_t *tsk, uint32_t sid); -extern mgmt_ipc_err_e iscsi_host_send_targets(queue_task_t *qtask, +extern int iscsi_host_send_targets(queue_task_t *qtask, int host_no, int do_login, struct sockaddr_storage *ss); extern void free_initiator(void); diff --git a/usr/initiator_common.c b/usr/initiator_common.c index 8a61da3..8e4e519 100644 --- a/usr/initiator_common.c +++ b/usr/initiator_common.c @@ -34,6 +34,7 @@ #include "iface.h" #include "host.h" #include "sysdeps.h" +#include "iscsi_err.h" struct iscsi_session *session_find_by_sid(uint32_t sid) { @@ -249,7 +250,7 @@ int iscsi_setup_portal(struct iscsi_conn *conn, char *address, int port) sprintf(serv, "%d", port); if (resolve_address(address, serv, &conn->saddr)) { log_error("cannot resolve host name %s", address); - return EINVAL; + return ISCSI_ERR_TRANS; } conn->failback_saddr = conn->saddr; diff --git a/usr/iscsi_err.h b/usr/iscsi_err.h new file mode 100644 index 0000000..72663b5 --- /dev/null +++ b/usr/iscsi_err.h @@ -0,0 +1,51 @@ +/* + * Return codes used by iSCSI tools. + */ +#ifndef _ISCSI_ERR_ +#define _ISCSI_ERR_ + +enum { + ISCSI_SUCCESS = 0, + /* Generic error */ + ISCSI_ERR = 1, + /* session/record could not be found */ + ISCSI_ERR_SESS_NOT_FOUND = 2, + /* Could not allocate resource for operation */ + ISCSI_ERR_NOMEM = 3, + /* Transport error caused operation to fail */ + ISCSI_ERR_TRANS = 4, + /* Generic login failure */ + ISCSI_ERR_LOGIN = 5, + /* Error accessing/managing iSCSI DB */ + ISCSI_ERR_IDBM = 6, + /* Invalid argument */ + ISCSI_ERR_INVAL = 7, + /* Connection timer exired while trying to connect */ + ISCSI_ERR_TRANS_TIMEOUT = 8, + /* Generic internal iscsid failure */ + ISCSI_ERR_INTERNAL = 9, + /* Logout failed */ + ISCSI_ERR_LOGOUT = 10, + /* iSCSI PDU timedout */ + ISCSI_ERR_PDU_TIMEOUT = 11, + /* iSCSI transport module not loaded in kernel or iscsid */ + ISCSI_ERR_TRANS_NOT_FOUND = 12, + /* Permission denied */ + ISCSI_ERR_ACCESS = 13, + /* Transport module did not support operation */ + ISCSI_ERR_TRANS_CAPS = 14, + /* Session is already logged in */ + ISCSI_ERR_SESS_EXISTS = 15, + /* Invalid IPC MGMT request */ + ISCSI_ERR_INVALID_MGMT_REQ = 16, + /* iSNS service is not supported */ + ISCSI_ERR_ISNS_UNAVAILABLE = 17, + /* A read/write to iscsid failed */ + ISCSI_ERR_ISCSID_COMM_ERR = 18, + /* Fatal login error */ + ISCSI_ERR_FATAL_LOGIN = 19, + /* Could ont connect to iscsid */ + ISCSI_ERR_ISCSID_NOTCONN = 20, +} iscsi_err; + +#endif diff --git a/usr/iscsid.c b/usr/iscsid.c index bce80c8..cae7e28 100644 --- a/usr/iscsid.c +++ b/usr/iscsid.c @@ -50,6 +50,7 @@ #include "sysdeps.h" #include "discoveryd.h" #include "iscsid_req.h" +#include "iscsi_err.h" /* global config info */ struct iscsi_daemon_config daemon_config; @@ -269,7 +270,7 @@ static int sync_session(void *data, struct session_info *info) retry: rc = iscsid_exec_req(&req, &rsp, 0); - if (rc == MGMT_IPC_ERR_ISCSID_NOTCONN && retries < 30) { + if (rc == ISCSI_ERR_ISCSID_NOTCONN && retries < 30) { retries++; sleep(1); goto retry; diff --git a/usr/iscsid_req.c b/usr/iscsid_req.c index 5280a0a..657cd55 100644 --- a/usr/iscsid_req.c +++ b/usr/iscsid_req.c @@ -31,6 +31,7 @@ #include "mgmt_ipc.h" #include "iscsi_util.h" #include "config.h" +#include "iscsi_err.h" static void iscsid_startup(void) { @@ -51,7 +52,7 @@ static void iscsid_startup(void) #define MAXSLEEP 128 -static mgmt_ipc_err_e iscsid_connect(int *fd, int start_iscsid) +static int iscsid_connect(int *fd, int start_iscsid) { int nsec; struct sockaddr_un addr; @@ -59,7 +60,7 @@ static mgmt_ipc_err_e iscsid_connect(int *fd, int start_iscsid) *fd = socket(AF_LOCAL, SOCK_STREAM, 0); if (*fd < 0) { log_error("can not create IPC socket (%d)!", errno); - return MGMT_IPC_ERR_ISCSID_NOTCONN; + return ISCSI_ERR_ISCSID_NOTCONN; } memset(&addr, 0, sizeof(addr)); @@ -72,7 +73,7 @@ static mgmt_ipc_err_e iscsid_connect(int *fd, int start_iscsid) for (nsec = 1; nsec <= MAXSLEEP; nsec <<= 1) { if (connect(*fd, (struct sockaddr *) &addr, sizeof(addr)) == 0) /* Connection established */ - return MGMT_IPC_OK; + return ISCSI_SUCCESS; /* If iscsid isn't there, there's no sense * in retrying. */ @@ -90,10 +91,10 @@ static mgmt_ipc_err_e iscsid_connect(int *fd, int start_iscsid) sleep(nsec); } log_error("can not connect to iSCSI daemon (%d)!", errno); - return MGMT_IPC_ERR_ISCSID_NOTCONN; + return ISCSI_ERR_ISCSID_NOTCONN; } -mgmt_ipc_err_e iscsid_request(int *fd, iscsiadm_req_t *req, int start_iscsid) +int iscsid_request(int *fd, iscsiadm_req_t *req, int start_iscsid) { int err; @@ -105,33 +106,33 @@ mgmt_ipc_err_e iscsid_request(int *fd, iscsiadm_req_t *req, int start_iscsid) log_error("got write error (%d/%d) on cmd %d, daemon died?", err, errno, req->command); close(*fd); - return MGMT_IPC_ERR_ISCSID_COMM_ERR; + return ISCSI_ERR_ISCSID_COMM_ERR; } - return MGMT_IPC_OK; + return ISCSI_SUCCESS; } -mgmt_ipc_err_e iscsid_response(int fd, iscsiadm_cmd_e cmd, iscsiadm_rsp_t *rsp) +int iscsid_response(int fd, iscsiadm_cmd_e cmd, iscsiadm_rsp_t *rsp) { - mgmt_ipc_err_e iscsi_err; + int iscsi_err; int err; if ((err = recv(fd, rsp, sizeof(*rsp), MSG_WAITALL)) != sizeof(*rsp)) { log_error("got read error (%d/%d), daemon died?", err, errno); - iscsi_err = MGMT_IPC_ERR_ISCSID_COMM_ERR; + iscsi_err = ISCSI_ERR_ISCSID_COMM_ERR; } else iscsi_err = rsp->err; close(fd); if (!iscsi_err && cmd != rsp->command) - iscsi_err = MGMT_IPC_ERR_ISCSID_COMM_ERR; + iscsi_err = ISCSI_ERR_ISCSID_COMM_ERR; return iscsi_err; } -mgmt_ipc_err_e iscsid_exec_req(iscsiadm_req_t *req, iscsiadm_rsp_t *rsp, +int iscsid_exec_req(iscsiadm_req_t *req, iscsiadm_rsp_t *rsp, int start_iscsid) { int fd; - mgmt_ipc_err_e err; + int err; err = iscsid_request(&fd, req, start_iscsid); if (err) @@ -190,7 +191,7 @@ int iscsid_req_by_sid(iscsiadm_cmd_e cmd, int sid) return iscsid_req_wait(cmd, fd); } -void iscsid_handle_error(mgmt_ipc_err_e err) +void iscsid_handle_error(int err) { static char *err_msgs[] = { /* 0 */ "", diff --git a/usr/iscsistart.c b/usr/iscsistart.c index 35d2a2f..a6752e9 100644 --- a/usr/iscsistart.c +++ b/usr/iscsistart.c @@ -47,6 +47,7 @@ #include "iface.h" #include "sysdeps.h" #include "iscsid_req.h" +#include "iscsi_err.h" /* global config info */ /* initiator needs initiator name/alias */ @@ -153,7 +154,7 @@ retry: * handle race where iscsid proc is starting up while we are * trying to connect. */ - if (rc == MGMT_IPC_ERR_ISCSID_NOTCONN && retries < 30) { + if (rc == ISCSI_ERR_ISCSID_NOTCONN && retries < 30) { retries++; sleep(1); goto retry; diff --git a/usr/mgmt_ipc.c b/usr/mgmt_ipc.c index 813bbca..3e4d2ef 100644 --- a/usr/mgmt_ipc.c +++ b/usr/mgmt_ipc.c @@ -35,6 +35,7 @@ #include "transport.h" #include "sysdeps.h" #include "iscsi_ipc.h" +#include "iscsi_err.h" #define PEERUSER_MAX 64 #define EXTMSG_MAX (64 * 1024) @@ -79,13 +80,13 @@ mgmt_ipc_close(int fd) close(fd); } -static mgmt_ipc_err_e +static int mgmt_ipc_session_login(queue_task_t *qtask) { return session_login_task(&qtask->req.u.session.rec, qtask); } -static mgmt_ipc_err_e +static int mgmt_ipc_session_getstats(queue_task_t *qtask) { int sid = qtask->req.u.session.sid; @@ -93,7 +94,7 @@ mgmt_ipc_session_getstats(queue_task_t *qtask) int rc; if (!(session = session_find_by_sid(sid))) - return MGMT_IPC_ERR_NOT_FOUND; + return ISCSI_ERR_SESS_NOT_FOUND; rc = ipc->get_stats(session->t->handle, session->id, session->conn[0].id, @@ -102,33 +103,33 @@ mgmt_ipc_session_getstats(queue_task_t *qtask) if (rc) { log_error("get_stats(): IPC error %d " "session [%02d]", rc, sid); - return MGMT_IPC_ERR_INTERNAL; + return ISCSI_ERR_INTERNAL; } - mgmt_ipc_write_rsp(qtask, MGMT_IPC_OK); - return MGMT_IPC_OK; + mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS); + return ISCSI_SUCCESS; } -static mgmt_ipc_err_e +static int mgmt_ipc_send_targets(queue_task_t *qtask) { iscsiadm_req_t *req = &qtask->req; - mgmt_ipc_err_e err; + int err; err = iscsi_host_send_targets(qtask, req->u.st.host_no, req->u.st.do_login, &req->u.st.ss); mgmt_ipc_write_rsp(qtask, err); - return MGMT_IPC_OK; + return ISCSI_SUCCESS; } -static mgmt_ipc_err_e +static int mgmt_ipc_session_logout(queue_task_t *qtask) { return session_logout_task(qtask->req.u.session.sid, qtask); } -static mgmt_ipc_err_e +static int mgmt_ipc_session_sync(queue_task_t *qtask) { struct ipc_msg_session *session= &qtask->req.u.session; @@ -136,16 +137,16 @@ mgmt_ipc_session_sync(queue_task_t *qtask) return iscsi_sync_session(&session->rec, qtask, session->sid); } -static mgmt_ipc_err_e +static int mgmt_ipc_cfg_initiatorname(queue_task_t *qtask) { if (dconfig->initiator_name) strcpy(qtask->rsp.u.config.var, dconfig->initiator_name); - mgmt_ipc_write_rsp(qtask, MGMT_IPC_OK); - return MGMT_IPC_OK; + mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS); + return ISCSI_SUCCESS; } -static mgmt_ipc_err_e +static int mgmt_ipc_session_info(queue_task_t *qtask) { int sid = qtask->req.u.session.sid; @@ -154,50 +155,50 @@ mgmt_ipc_session_info(queue_task_t *qtask) if (!(session = session_find_by_sid(sid))) { log_debug(1, "session with sid %d not found!", sid); - return MGMT_IPC_ERR_NOT_FOUND; + return ISCSI_ERR_SESS_NOT_FOUND; } info = &qtask->rsp.u.session_state; info->conn_state = session->conn[0].state; info->session_state = session->r_stage; - mgmt_ipc_write_rsp(qtask, MGMT_IPC_OK); - return MGMT_IPC_OK; + mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS); + return ISCSI_SUCCESS; } -static mgmt_ipc_err_e +static int mgmt_ipc_cfg_initiatoralias(queue_task_t *qtask) { strcpy(qtask->rsp.u.config.var, dconfig->initiator_alias); - mgmt_ipc_write_rsp(qtask, MGMT_IPC_OK); - return MGMT_IPC_OK; + mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS); + return ISCSI_SUCCESS; } -static mgmt_ipc_err_e +static int mgmt_ipc_cfg_filename(queue_task_t *qtask) { strcpy(qtask->rsp.u.config.var, dconfig->config_file); - mgmt_ipc_write_rsp(qtask, MGMT_IPC_OK); - return MGMT_IPC_OK; + mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS); + return ISCSI_SUCCESS; } -static mgmt_ipc_err_e +static int mgmt_ipc_conn_add(queue_task_t *qtask) { - return MGMT_IPC_ERR; + return ISCSI_ERR; } -static mgmt_ipc_err_e +static int mgmt_ipc_immediate_stop(queue_task_t *qtask) { event_loop_exit(qtask); - return MGMT_IPC_OK; + return ISCSI_SUCCESS; } -static mgmt_ipc_err_e +static int mgmt_ipc_conn_remove(queue_task_t *qtask) { - return MGMT_IPC_ERR; + return ISCSI_ERR; } /* @@ -252,12 +253,11 @@ again: return argc; } -static mgmt_ipc_err_e -mgmt_ipc_notify_common(queue_task_t *qtask, - mgmt_ipc_err_e (*handler)(int, char **)) +static int +mgmt_ipc_notify_common(queue_task_t *qtask, int (*handler)(int, char **)) { char **argv = NULL; - int argc, err = MGMT_IPC_ERR; + int argc, err = ISCSI_ERR; argc = mgmt_ipc_parse_strings(qtask, &argv); if (argc > 0) @@ -266,54 +266,54 @@ mgmt_ipc_notify_common(queue_task_t *qtask, if (argv) free(argv); mgmt_ipc_write_rsp(qtask, err); - return MGMT_IPC_OK; + return ISCSI_SUCCESS; } /* Replace these dummies as you implement them elsewhere */ -static mgmt_ipc_err_e +static int iscsi_discovery_add_node(int argc, char **argv) { - return MGMT_IPC_OK; + return ISCSI_SUCCESS; } -static mgmt_ipc_err_e +static int iscsi_discovery_del_node(int argc, char **argv) { - return MGMT_IPC_OK; + return ISCSI_SUCCESS; } -static mgmt_ipc_err_e +static int iscsi_discovery_add_portal(int argc, char **argv) { - return MGMT_IPC_OK; + return ISCSI_SUCCESS; } -static mgmt_ipc_err_e +static int iscsi_discovery_del_portal(int argc, char **argv) { - return MGMT_IPC_OK; + return ISCSI_SUCCESS; } -static mgmt_ipc_err_e +static int mgmt_ipc_notify_add_node(queue_task_t *qtask) { return mgmt_ipc_notify_common(qtask, iscsi_discovery_add_node); } -static mgmt_ipc_err_e +static int mgmt_ipc_notify_del_node(queue_task_t *qtask) { return mgmt_ipc_notify_common(qtask, iscsi_discovery_del_node); } -static mgmt_ipc_err_e +static int mgmt_ipc_notify_add_portal(queue_task_t *qtask) { return mgmt_ipc_notify_common(qtask, iscsi_discovery_add_portal); } -static mgmt_ipc_err_e +static int mgmt_ipc_notify_del_portal(queue_task_t *qtask) { return mgmt_ipc_notify_common(qtask, iscsi_discovery_del_portal); @@ -422,7 +422,7 @@ mgmt_ipc_destroy_queue_task(queue_task_t *qtask) * is for. */ void -mgmt_ipc_write_rsp(queue_task_t *qtask, mgmt_ipc_err_e err) +mgmt_ipc_write_rsp(queue_task_t *qtask, int err) { if (!qtask) return; @@ -526,7 +526,7 @@ void mgmt_ipc_handle(int accept_fd) qtask->mgmt_ipc_fd = fd; if (!mgmt_peeruser(fd, user) || strncmp(user, "root", PEERUSER_MAX)) { - err = MGMT_IPC_ERR_ACCESS; + err = ISCSI_ERR_ACCESS; goto err; } @@ -544,12 +544,12 @@ void mgmt_ipc_handle(int accept_fd) /* If the handler returns OK, this means it * already sent the reply. */ err = handler(qtask); - if (err == MGMT_IPC_OK) + if (err == ISCSI_SUCCESS) return; } else { log_error("unknown request: %s(%d) %u", __FUNCTION__, __LINE__, command); - err = MGMT_IPC_ERR_INVALID_REQ; + err = ISCSI_ERR_INVALID_MGMT_REQ; } err: diff --git a/usr/mgmt_ipc.h b/usr/mgmt_ipc.h index 4e19ce1..7d8ce72 100644 --- a/usr/mgmt_ipc.h +++ b/usr/mgmt_ipc.h @@ -26,30 +26,6 @@ #define ISCSIADM_NAMESPACE "ISCSIADM_ABSTRACT_NAMESPACE" #define PEERUSER_MAX 64 -typedef enum mgmt_ipc_err { - MGMT_IPC_OK = 0, - MGMT_IPC_ERR = 1, - MGMT_IPC_ERR_NOT_FOUND = 2, - MGMT_IPC_ERR_NOMEM = 3, - MGMT_IPC_ERR_TRANS_FAILURE = 4, - MGMT_IPC_ERR_LOGIN_FAILURE = 5, - MGMT_IPC_ERR_IDBM_FAILURE = 6, - MGMT_IPC_ERR_INVAL = 7, - MGMT_IPC_ERR_TRANS_TIMEOUT = 8, - MGMT_IPC_ERR_INTERNAL = 9, - MGMT_IPC_ERR_LOGOUT_FAILURE = 10, - MGMT_IPC_ERR_PDU_TIMEOUT = 11, - MGMT_IPC_ERR_TRANS_NOT_FOUND = 12, - MGMT_IPC_ERR_ACCESS = 13, - MGMT_IPC_ERR_TRANS_CAPS = 14, - MGMT_IPC_ERR_EXISTS = 15, - MGMT_IPC_ERR_INVALID_REQ = 16, - MGMT_IPC_ERR_ISNS_UNAVAILABLE = 17, - MGMT_IPC_ERR_ISCSID_COMM_ERR = 18, - MGMT_IPC_ERR_FATAL_LOGIN_FAILURE = 19, - MGMT_IPC_ERR_ISCSID_NOTCONN = 20, -} mgmt_ipc_err_e; - typedef enum iscsiadm_cmd { MGMT_IPC_UNKNOWN = 0, MGMT_IPC_SESSION_LOGIN = 1, @@ -107,7 +83,7 @@ typedef struct iscsiadm_req { /* IPC Response */ typedef struct iscsiadm_rsp { iscsiadm_cmd_e command; - mgmt_ipc_err_e err; + int err; /* ISCSI_ERR value */ union { #define MGMT_IPC_GETSTATS_BUF_MAX (sizeof(struct iscsi_uevent) + \ @@ -131,10 +107,10 @@ typedef struct iscsiadm_rsp { } iscsiadm_rsp_t; struct queue_task; -typedef mgmt_ipc_err_e mgmt_ipc_fn_t(struct queue_task *); +typedef int mgmt_ipc_fn_t(struct queue_task *); struct queue_task; -void mgmt_ipc_write_rsp(struct queue_task *qtask, mgmt_ipc_err_e err); +void mgmt_ipc_write_rsp(struct queue_task *qtask, int err); int mgmt_ipc_listen(void); void mgmt_ipc_close(int fd); void mgmt_ipc_handle(int accept_fd); diff --git a/usr/session_mgmt.c b/usr/session_mgmt.c index 2208d82..d7c4579 100644 --- a/usr/session_mgmt.c +++ b/usr/session_mgmt.c @@ -32,6 +32,7 @@ #include "iscsi_sysfs.h" #include "log.h" #include "iscsid_req.h" +#include "iscsi_err.h" static void log_login_msg(struct node_rec *rec, int rc) { @@ -124,7 +125,7 @@ int iscsi_login_portal(void *data, struct list_head *list, struct node_rec *rec) if (async_req) free(async_req); /* we raced with another app or instance of iscsiadm */ - if (rc == MGMT_IPC_ERR_EXISTS) + if (rc == ISCSI_ERR_SESS_EXISTS) return 0; return ENOTCONN; @@ -278,7 +279,7 @@ int iscsi_logout_portal(struct session_info *info, struct list_head *list) if (async_req) free(async_req); - if (rc == MGMT_IPC_ERR_NOT_FOUND) + if (rc == ISCSI_ERR_SESS_NOT_FOUND) return 0; return EIO; |