From a2f4d66bc8a311ba90880656d117ee115eb57971 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Tue, 7 Jun 2011 18:22:22 +0000 Subject: [PATCH] Merge of the trunk's r3552: Errors reporting fixes git-svn-id: http://svn.code.sf.net/p/scst/svn/branches/2.1.0.x@3554 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/config.c | 10 ++++----- iscsi-scst/usr/ctldev.c | 28 ++++++++++++------------- iscsi-scst/usr/event.c | 18 ++++++++-------- iscsi-scst/usr/iscsi_scstd.c | 32 ++++++++++++++--------------- iscsi-scst/usr/iscsid.c | 4 ++-- iscsi-scst/usr/isns.c | 40 ++++++++++++++++++------------------ iscsi-scst/usr/target.c | 4 ++-- 7 files changed, 68 insertions(+), 68 deletions(-) diff --git a/iscsi-scst/usr/config.c b/iscsi-scst/usr/config.c index 2e7c3349d..0ea77feea 100644 --- a/iscsi-scst/usr/config.c +++ b/iscsi-scst/usr/config.c @@ -1086,7 +1086,7 @@ int config_load(const char *config_name) } else { err = -errno; log_error("Open config file %s failed: %s", cname, - get_error_str(err)); + strerror(errno)); goto out; } } @@ -1094,21 +1094,21 @@ int config_load(const char *config_name) size = lseek(config, 0, SEEK_END); if (size < 0) { err = -errno; - log_error("lseek() failed: %s", get_error_str(err)); + log_error("lseek() failed: %s", strerror(errno)); goto out_close; } buf = malloc(size+1); if (buf == NULL) { err = -ENOMEM; - log_error("malloc() failed: %s", get_error_str(err)); + log_error("malloc() failed: %s", strerror(-err)); goto out_close; } rc = lseek(config, 0, SEEK_SET); if (rc < 0) { err = -errno; - log_error("lseek() failed: %s", get_error_str(err)); + log_error("lseek() failed: %s", strerror(errno)); goto out_free; } @@ -1117,7 +1117,7 @@ int config_load(const char *config_name) rc = read(config, &buf[i], size - i); if (rc < 0) { err = -errno; - log_error("read() failed: %s", get_error_str(err)); + log_error("read() failed: %s", strerror(errno)); goto out_free; } else if (rc == 0) break; diff --git a/iscsi-scst/usr/ctldev.c b/iscsi-scst/usr/ctldev.c index 186e96f02..aa9a043d2 100644 --- a/iscsi-scst/usr/ctldev.c +++ b/iscsi-scst/usr/ctldev.c @@ -71,14 +71,14 @@ int kernel_open(void) unlink(CTL_DEVICE); if (mknod(CTL_DEVICE, (S_IFCHR | 0600), (devn << 8))) { err = -errno; - printf("cannot create %s %d\n", CTL_DEVICE, errno); + printf("cannot create %s %s\n", CTL_DEVICE, strerror(errno)); goto out_err; } ctlfd = open(CTL_DEVICE, O_RDWR); if (ctlfd < 0) { err = -errno; - printf("cannot open %s %d\n", CTL_DEVICE, errno); + printf("cannot open %s %s\n", CTL_DEVICE, strerror(errno)); goto out_err; } @@ -89,7 +89,7 @@ int kernel_open(void) if (err != 0) { err = -errno; log_error("Unable to register: %s. Incompatible version of the " - "kernel module?\n", get_error_str(errno)); + "kernel module?\n", strerror(errno)); goto out_close; } else { log_debug(0, "max_data_seg_len %d, max_queued_cmds %d", @@ -202,7 +202,7 @@ int kernel_target_create(struct target *target, u32 *tid, u32 cookie) if ((err = ioctl(ctrl_fd, ADD_TARGET, &info)) < 0) { err = -errno; log_error("Can't create target %s: %s\n", target->name, - get_error_str(errno)); + strerror(errno)); } else { target->tid = err; if (tid != NULL) @@ -228,7 +228,7 @@ int kernel_target_destroy(u32 tid, u32 cookie) res = ioctl(ctrl_fd, DEL_TARGET, &info); if (res < 0) { res = -errno; - log_error("Can't destroy target %d %u\n", errno, tid); + log_error("Can't destroy target %s %u\n", strerror(errno), tid); } return res; @@ -299,8 +299,8 @@ int kernel_initiator_allowed(u32 tid, const char *full_initiator_name) if ((err = ioctl(ctrl_fd, ISCSI_INITIATOR_ALLOWED, &info)) < 0) { err = -errno; - log_error("Can't find out initiator %s permissions (errno %d, " - "tid %u", full_initiator_name, errno, tid); + log_error("Can't find out initiator %s permissions (%s, " + "tid %u", full_initiator_name, strerror(errno), tid); } return err; @@ -317,8 +317,8 @@ int kernel_conn_destroy(u32 tid, u64 sid, u32 cid) if ((err = ioctl(ctrl_fd, DEL_CONN, &info)) < 0) { err = -errno; - log_debug(2, "Can't destroy conn (errno %d, tid %u, sid 0x%" - PRIx64 ", cid %u\n", errno, tid, sid, cid); + log_debug(2, "Can't destroy conn (%s, tid %u, sid 0x%" + PRIx64 ", cid %u\n", strerror(errno), tid, sid, cid); } return err; @@ -343,7 +343,7 @@ int kernel_params_get(u32 tid, u64 sid, int type, struct iscsi_param *params) if ((err = ioctl(ctrl_fd, ISCSI_PARAM_GET, &info)) < 0) { err = -errno; log_debug(1, "Can't get session params for session 0x%" PRIx64 - " (tid %u, err %d): %s\n", sid, tid, err, get_error_str(errno)); + " (tid %u, err %d): %s\n", sid, tid, err, strerror(errno)); } if (type == key_session) @@ -386,7 +386,7 @@ int kernel_params_set(u32 tid, u64 sid, int type, u32 partial, err = -errno; log_error("Can't set session params for session 0x%" PRIx64 " (tid %u, type %d, partial %d, err %d): %s\n", sid, - tid, type, partial, err, get_error_str(errno)); + tid, type, partial, err, strerror(errno)); } out: @@ -435,7 +435,7 @@ int kernel_session_create(struct connection *conn) res = -errno; log_error("Can't create sess 0x%" PRIx64 " (tid %d, " "initiator %s): %s\n", conn->sess->sid.id64, conn->tid, - conn->sess->initiator, get_error_str(errno)); + conn->sess->initiator, strerror(errno)); } out: @@ -456,7 +456,7 @@ int kernel_session_destroy(u32 tid, u64 sid) if (res < 0) { res = -errno; log_debug(2, "Can't destroy sess 0x%" PRIx64 " (tid %d): %s\n", - sid, tid, get_error_str(errno)); + sid, tid, strerror(errno)); } return res; @@ -481,7 +481,7 @@ int kernel_conn_create(u32 tid, u64 sid, u32 cid, u32 stat_sn, u32 exp_stat_sn, if (res < 0) { res = -errno; log_error("Can't create conn %x (sess 0x%" PRIx64 ", tid %d): %s\n", - cid, sid, tid, get_error_str(errno)); + cid, sid, tid, strerror(errno)); } return res; diff --git a/iscsi-scst/usr/event.c b/iscsi-scst/usr/event.c index 1f103cda7..53211de45 100644 --- a/iscsi-scst/usr/event.c +++ b/iscsi-scst/usr/event.c @@ -134,7 +134,7 @@ static int send_mgmt_cmd_res(u32 tid, u32 cookie, u32 req_cmd, int result, if (res != 0) { res = -errno; log_error("Can't send mgmt reply (cookie %d, result %d, " - "res %d): %s\n", cookie, result, res, get_error_str(errno)); + "res %d): %s\n", cookie, result, res, strerror(errno)); } return res; @@ -170,7 +170,7 @@ static int handle_e_add_target(int fd, const struct iscsi_kern_event *event) if ((errno == EINTR) || (errno == EAGAIN)) continue; log_error("read netlink fd (%d) failed: %s", fd, - get_error_str(errno)); + strerror(errno)); send_mgmt_cmd_res(0, event->cookie, E_ADD_TARGET, -errno, NULL); exit(1); } @@ -186,7 +186,7 @@ static int handle_e_add_target(int fd, const struct iscsi_kern_event *event) if ((errno == EINTR) || (errno == EAGAIN)) continue; log_error("read netlink fd (%d) failed: %s", fd, - get_error_str(errno)); + strerror(errno)); send_mgmt_cmd_res(0, event->cookie, E_ADD_TARGET, -errno, NULL); exit(1); } @@ -407,7 +407,7 @@ static int handle_e_mgmt_cmd(int fd, const struct iscsi_kern_event *event) if ((errno == EINTR) || (errno == EAGAIN)) continue; log_error("read netlink fd (%d) failed: %s", fd, - get_error_str(errno)); + strerror(errno)); send_mgmt_cmd_res(0, event->cookie, E_MGMT_CMD, -errno, NULL); exit(1); } @@ -496,7 +496,7 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event) if ((errno == EINTR) || (errno == EAGAIN)) continue; log_error("read netlink fd (%d) failed: %s", fd, - get_error_str(errno)); + strerror(errno)); send_mgmt_cmd_res(0, event->cookie, E_GET_ATTR_VALUE, -errno, NULL); exit(1); } @@ -759,7 +759,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event) if ((errno == EINTR) || (errno == EAGAIN)) continue; log_error("read netlink fd (%d) failed: %s", fd, - get_error_str(errno)); + strerror(errno)); send_mgmt_cmd_res(0, event->cookie, E_SET_ATTR_VALUE, -errno, NULL); exit(1); } @@ -774,7 +774,7 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event) if ((errno == EINTR) || (errno == EAGAIN)) continue; log_error("read netlink fd (%d) failed: %s", fd, - get_error_str(errno)); + strerror(errno)); send_mgmt_cmd_res(0, event->cookie, E_SET_ATTR_VALUE, -errno, NULL); exit(1); } @@ -1039,7 +1039,7 @@ retry: return EAGAIN; if (errno == EINTR) goto retry; - log_error("read netlink fd (%d) failed: %s", fd, get_error_str(errno)); + log_error("read netlink fd (%d) failed: %s", fd, strerror(errno)); exit(1); } @@ -1151,7 +1151,7 @@ int nl_open(void) nl_fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_ISCSI_SCST); if (nl_fd == -1) { - log_error("%s %d\n", __FUNCTION__, errno); + log_error("%s %s\n", __FUNCTION__, strerror(errno)); return -1; } diff --git a/iscsi-scst/usr/iscsi_scstd.c b/iscsi-scst/usr/iscsi_scstd.c index 0b57a56bc..de2cf8906 100644 --- a/iscsi-scst/usr/iscsi_scstd.c +++ b/iscsi-scst/usr/iscsi_scstd.c @@ -99,9 +99,9 @@ static void set_non_blocking(int fd) if (res != -1) { res = fcntl(fd, F_SETFL, res | O_NONBLOCK); if (res) - log_warning("unable to set fd flags (%s)!", get_error_str(errno)); + log_warning("unable to set fd flags (%s)!", strerror(errno)); } else - log_warning("unable to get fd flags (%s)!", get_error_str(errno)); + log_warning("unable to get fd flags (%s)!", strerror(errno)); } static void sock_set_keepalive(int sock, int timeout) @@ -110,18 +110,18 @@ static void sock_set_keepalive(int sock, int timeout) int opt = 2; if (setsockopt(sock, SOL_TCP, TCP_KEEPCNT, &opt, sizeof(opt))) - log_warning("unable to set TCP_KEEPCNT on server socket (%s)!", get_error_str(errno)); + log_warning("unable to set TCP_KEEPCNT on server socket (%s)!", strerror(errno)); if (setsockopt(sock, SOL_TCP, TCP_KEEPIDLE, &timeout, sizeof(timeout))) - log_warning("unable to set TCP_KEEPIDLE on server socket (%s)!", get_error_str(errno)); + log_warning("unable to set TCP_KEEPIDLE on server socket (%s)!", strerror(errno)); opt = 3; if (setsockopt(sock, SOL_TCP, TCP_KEEPINTVL, &opt, sizeof(opt))) - log_warning("unable to set KEEPINTVL on server socket (%s)!", get_error_str(errno)); + log_warning("unable to set KEEPINTVL on server socket (%s)!", strerror(errno)); opt = 1; if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt))) - log_warning("unable to set SO_KEEPALIVE on server socket (%s)!", get_error_str(errno)); + log_warning("unable to set SO_KEEPALIVE on server socket (%s)!", strerror(errno)); } } @@ -158,7 +158,7 @@ static void create_listen_socket(struct pollfd *array) sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (sock < 0) { log_error("Unable to create server socket (%s) %d %d %d!", - get_error_str(errno), res->ai_family, + strerror(errno), res->ai_family, res->ai_socktype, res->ai_protocol); continue; } @@ -168,23 +168,23 @@ static void create_listen_socket(struct pollfd *array) opt = 1; if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) log_warning("Unable to set SO_REUSEADDR on server socket (%s)!", - get_error_str(errno)); + strerror(errno)); opt = 1; if (res->ai_family == AF_INET6 && setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt))) { - log_error("Unable to restrict IPv6 socket (%s)", get_error_str(errno)); + log_error("Unable to restrict IPv6 socket (%s)", strerror(errno)); close(sock); continue; } if (bind(sock, res->ai_addr, res->ai_addrlen)) { - log_error("Unable to bind server socket (%s)!", get_error_str(errno)); + log_error("Unable to bind server socket (%s)!", strerror(errno)); close(sock); continue; } if (listen(sock, INCOMING_MAX)) { - log_error("Unable to listen to server socket (%s)!", get_error_str(errno)); + log_error("Unable to listen to server socket (%s)!", strerror(errno)); close(sock); continue; } @@ -233,7 +233,7 @@ static void accept_connection(int listen) break; default: log_error("accept(incoming_socket) failed: %s", - get_error_str(errno)); + strerror(errno)); exit(1); } goto out; @@ -242,7 +242,7 @@ static void accept_connection(int listen) namesize = sizeof(to); rc = getsockname(fd, &to.sa, &namesize); if (rc != 0) { - log_error("getsockname() failed: %s", get_error_str(errno)); + log_error("getsockname() failed: %s", strerror(errno)); goto out_close; } @@ -526,7 +526,7 @@ static void event_loop(void) "of iSCSI-SCST.", __FUNCTION__); else log_error("%s: poll() failed: %s", __FUNCTION__, - get_error_str(errno)); + strerror(errno)); exit(1); } @@ -784,10 +784,10 @@ int main(int argc, char **argv) exit(1); if (gid && setgid(gid) < 0) - log_error("setgid failed: %s", get_error_str(errno)); + log_error("setgid failed: %s", strerror(errno)); if (uid && setuid(uid) < 0) - log_error("setuid failed: %s", get_error_str(errno)); + log_error("setuid failed: %s", strerror(errno)); event_loop(); diff --git a/iscsi-scst/usr/iscsid.c b/iscsi-scst/usr/iscsid.c index 42222a9d0..4dc94547f 100644 --- a/iscsi-scst/usr/iscsid.c +++ b/iscsi-scst/usr/iscsid.c @@ -463,7 +463,7 @@ static int init_conn_session_params(struct connection *conn) target = target_find_by_id(conn->tid); if (target == NULL) { log_error("target %d not found", conn->tid); - res = -EINVAL; + res = -ENOENT; goto out; } @@ -574,7 +574,7 @@ static void login_start(struct connection *conn) if (err != 0) { log_error("Can't get session params for session 0x%" PRIx64 " (err %d): %s\n", conn->sid.id64, err, - get_error_str(-err)); + strerror(-err)); login_rsp_tgt_err(conn, ISCSI_STATUS_TARGET_ERROR); return; } diff --git a/iscsi-scst/usr/isns.c b/iscsi-scst/usr/isns.c index 1dfb98479..7e8c00e0c 100644 --- a/iscsi-scst/usr/isns.c +++ b/iscsi-scst/usr/isns.c @@ -102,7 +102,7 @@ static int isns_get_ip(int fd) err = getsockname(fd, &lss.sa, &slen); if (err) { - log_error("getsockname error: %s!", get_error_str(err)); + log_error("getsockname error: %s!", strerror(errno)); return err; } @@ -143,7 +143,7 @@ static int isns_connect(void) fd = socket(ss.ss_family, SOCK_STREAM, IPPROTO_TCP); if (fd < 0) { - log_error("unable to create (%s) %d!", get_error_str(errno), + log_error("unable to create (%s) %d!", strerror(errno), ss.ss_family); return -errno; } @@ -154,7 +154,7 @@ static int isns_connect(void) */ err = connect(fd, (struct sockaddr *)&ss, sizeof(ss)); if (err < 0) { - log_error("unable to connect (%s) %d!", get_error_str(errno), + log_error("unable to connect (%s) %d!", strerror(errno), ss.ss_family); close(fd); return -errno; @@ -256,7 +256,7 @@ static int isns_scn_deregister(char *name) err = write(isns_fd, buf, length + sizeof(struct isns_hdr)); if (err < 0) - log_error("%s %d: %s", __func__, __LINE__, get_error_str(errno)); + log_error("%s %d: %s", __func__, __LINE__, strerror(errno)); out: return err; @@ -334,7 +334,7 @@ static int isns_scn_register(void) err = write(isns_fd, buf, length + sizeof(struct isns_hdr)); if (err < 0) - log_error("%s %d: %s", __func__, __LINE__, get_error_str(errno)); + log_error("%s %d: %s", __func__, __LINE__, strerror(errno)); out: return err; @@ -417,7 +417,7 @@ static int isns_attr_query(char *name) err = write(isns_fd, buf, length + sizeof(struct isns_hdr)); if (err < 0) - log_error("%s %d: %s", __func__, __LINE__, get_error_str(errno)); + log_error("%s %d: %s", __func__, __LINE__, strerror(errno)); out: return err; @@ -471,7 +471,7 @@ static int isns_deregister(void) err = write(isns_fd, buf, length + sizeof(struct isns_hdr)); if (err < 0) - log_error("%s %d: %s", __func__, __LINE__, get_error_str(errno)); + log_error("%s %d: %s", __func__, __LINE__, strerror(errno)); out: return err; } @@ -576,7 +576,7 @@ int isns_target_register(char *name) err = write(isns_fd, buf, length + sizeof(struct isns_hdr)); if (err < 0) - log_error("%s %d: %s", __func__, __LINE__, get_error_str(errno)); + log_error("%s %d: %s", __func__, __LINE__, strerror(errno)); if (scn_listen_port) isns_scn_register(); @@ -658,7 +658,7 @@ int isns_target_deregister(char *name) err = write(isns_fd, buf, length + sizeof(struct isns_hdr)); if (err < 0) - log_error("%s %d: %s", __func__, __LINE__, get_error_str(errno)); + log_error("%s %d: %s", __func__, __LINE__, strerror(errno)); out: return err; @@ -674,8 +674,8 @@ static int recv_hdr(int fd, struct isns_io *rx, struct isns_hdr *hdr) if (err < 0) { if (errno == EAGAIN || errno == EINTR) return -EAGAIN; - log_error("header read error %d %d %d %d", - fd, err, errno, rx->offset); + log_error("header read error %d %d %s %d", + fd, err, strerror(errno), rx->offset); return -1; } else if (err == 0) return -1; @@ -726,8 +726,8 @@ static int recv_pdu(int fd, struct isns_io *rx, struct isns_hdr *hdr) if (err < 0) { if (errno == EAGAIN || errno == EINTR) return -EAGAIN; - log_error("pdu read error %d %d %d %d", - fd, err, errno, rx->offset); + log_error("pdu read error %d %d %s %d", + fd, err, strerror(errno), rx->offset); return -1; } else if (err == 0) return -1; @@ -971,7 +971,7 @@ static int scn_accept_connection(void) fd = accept(scn_listen_fd, &from.sa, &slen); if (fd < 0) { log_error("%s %d: accept error: %s", __func__, __LINE__, - get_error_str(errno)); + strerror(errno)); return -errno; } log_error("Accept scn connection %d", fd); @@ -979,7 +979,7 @@ static int scn_accept_connection(void) err = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)); if (err) log_error("%s %d: %s\n", __func__, __LINE__, - get_error_str(errno)); + strerror(errno)); /* not critical, so ignore. */ scn_fd = fd; @@ -1013,7 +1013,7 @@ static int send_scn_rsp(char *name, uint16_t transaction) err = write(scn_fd, buf, length + sizeof(struct isns_hdr)); if (err < 0) - log_error("%s %d: %s", __func__, __LINE__, get_error_str(errno)); + log_error("%s %d: %s", __func__, __LINE__, strerror(errno)); out: return err; @@ -1077,7 +1077,7 @@ static int scn_init(void) fd = socket(ss.ss_family, SOCK_STREAM, IPPROTO_TCP); if (fd < 0) { - log_error("%s %d: %s\n", __func__, __LINE__, get_error_str(errno)); + log_error("%s %d: %s\n", __func__, __LINE__, strerror(errno)); err = -errno; goto out; } @@ -1087,21 +1087,21 @@ static int scn_init(void) err = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt)); if (err) { log_error("%s %d: %s\n", __func__, __LINE__, - get_error_str(errno)); + strerror(errno)); goto out_close; } } err = listen(fd, 5); if (err) { - log_error("%s %d: %s\n", __func__, __LINE__, get_error_str(errno)); + log_error("%s %d: %s\n", __func__, __LINE__, strerror(errno)); goto out_close; } slen = sizeof(lss); err = getsockname(fd, (struct sockaddr *)&lss, &slen); if (err) { - log_error("%s %d: %s\n", __func__, __LINE__, get_error_str(errno)); + log_error("%s %d: %s\n", __func__, __LINE__, strerror(errno)); goto out_close; } diff --git a/iscsi-scst/usr/target.c b/iscsi-scst/usr/target.c index 63afb23f5..3f08634e3 100644 --- a/iscsi-scst/usr/target.c +++ b/iscsi-scst/usr/target.c @@ -449,13 +449,13 @@ bool target_redirected(struct target *target, struct connection *conn) rc = getsockname(conn->fd, (struct sockaddr *)&sa.sa, &slen); if (rc != 0) { - log_error("getsockname() failed: %s", get_error_str(errno)); + log_error("getsockname() failed: %s", strerror(errno)); goto out; } rc = getnameinfo(&sa.sa, sizeof(sa), tmp, sizeof(tmp), NULL, 0, NI_NUMERICHOST); if (rc != 0) { - log_error("getnameinfo() failed: %s", get_error_str(errno)); + log_error("getnameinfo() failed: %s", get_error_str(rc)); goto out; }