diff --git a/iscsi-scst/Makefile b/iscsi-scst/Makefile index cd553c421..3b1d69809 100644 --- a/iscsi-scst/Makefile +++ b/iscsi-scst/Makefile @@ -39,7 +39,7 @@ include/iscsi_scst_itf_ver.h: include/iscsi_scst.h install: all @install -vD usr/iscsi-scstd $(DISTDIR)/usr/local/sbin/iscsi-scstd -# -@install -vD usr/iscsi-scst-adm $(DISTDIR)/usr/local/sbin/iscsi-scst-adm + @install -vD usr/iscsi-scst-adm $(DISTDIR)/usr/local/sbin/iscsi-scst-adm if [ -f /etc/debian_version ]; then \ install -vD -m 755 etc/initd/initd.debian $(DISTDIR)/etc/init.d/iscsi-scst; \ elif [ -f /etc/redhat-release ]; then \ diff --git a/iscsi-scst/Makefile_user_space_only b/iscsi-scst/Makefile_user_space_only index 7df06d406..3de57cf16 100644 --- a/iscsi-scst/Makefile_user_space_only +++ b/iscsi-scst/Makefile_user_space_only @@ -20,7 +20,7 @@ include/iscsi_scst_itf_ver.h: include/iscsi_scst.h install: all @install -vD usr/iscsi-scstd $(DISTDIR)/usr/local/sbin/iscsi-scstd -# -@install -vD usr/iscsi-scst-adm $(DISTDIR)/usr/local/sbin/iscsi-scst-adm + @install -vD usr/iscsi-scst-adm $(DISTDIR)/usr/local/sbin/iscsi-scst-adm if [ -f /etc/debian_version ]; then \ install -vD -m 755 etc/initd/initd.debian $(DISTDIR)/etc/init.d/iscsi-scst; \ elif [ -f /etc/redhat-release ]; then \ diff --git a/iscsi-scst/README b/iscsi-scst/README index d44dd91ac..4641a01b6 100644 --- a/iscsi-scst/README +++ b/iscsi-scst/README @@ -165,26 +165,6 @@ http://support.microsoft.com/kb/328890/ or google for "TcpAckFrequency" for more details. -Known issues ------------- - -Currently iscsi-scst-adm utility is broken, hence not built. But, in -contrast to IET, in iSCSI-SCST it isn't needed so much, since all -devices/LUNs management is done using SCST's /proc interface, e.g. using -scstadmin utility. What's remained for iscsi-scst-adm is manage of iSCSI -targets and their parameters. In case of changing any negotiable iSCSI -parameters renegotiation in all corresponding sessions is required by -iSCSI standard, i.e. they all must be restarted, which, basically, means -iSCSI-SCST restart. So, for parameters changing as well as for -adding/removing targets, the recommended way is to change -iscsi-scst.conf, then restart iSCSI-SCST. In contrast to IET, this -operation is safe. Also, as a side effect, your iscsi-scst.conf will -always be in sync with the running system. - -But, if you decide to fix iscsi-scst-adm, your patches will be -appreciated. - - Compilation options ------------------- diff --git a/iscsi-scst/ToDo b/iscsi-scst/ToDo index 8d0af2b3d..7b5fa1253 100644 --- a/iscsi-scst/ToDo +++ b/iscsi-scst/ToDo @@ -21,8 +21,6 @@ for adding support for ranges in the negotiation keys, so it needs to be fixed as well. - - Fix iscsi-scst-adm. - - Fix SNACK command handling. Currently it violates iSCSI RFC. - Consider better integration with TCP internals on receive path to diff --git a/iscsi-scst/usr/Makefile b/iscsi-scst/usr/Makefile index 876705bbd..24605dafd 100644 --- a/iscsi-scst/usr/Makefile +++ b/iscsi-scst/usr/Makefile @@ -23,8 +23,7 @@ OBJS_ADM = $(SRCS_ADM:.c=.o) CFLAGS += -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include CFLAGS += -D_GNU_SOURCE # required for glibc >= 2.8 -PROGRAMS = iscsi-scstd -# iscsi-scst-adm +PROGRAMS = iscsi-scstd iscsi-scst-adm LIBS = -lcrypto all: $(PROGRAMS) diff --git a/iscsi-scst/usr/conn.c b/iscsi-scst/usr/conn.c index b392d3c8c..a1a82bd15 100644 --- a/iscsi-scst/usr/conn.c +++ b/iscsi-scst/usr/conn.c @@ -123,8 +123,8 @@ void conn_take_fd(struct connection *conn, int fd) err = ki->conn_create(conn->tid, conn->session->sid.id64, conn->cid, conn->stat_sn, conn->exp_stat_sn, fd, - conn->session_param[key_header_digest].exec_val, - conn->session_param[key_data_digest].exec_val); + conn->session_param[key_header_digest].val, + conn->session_param[key_data_digest].val); return; } diff --git a/iscsi-scst/usr/ctldev.c b/iscsi-scst/usr/ctldev.c index 7eb888261..22c046012 100644 --- a/iscsi-scst/usr/ctldev.c +++ b/iscsi-scst/usr/ctldev.c @@ -45,7 +45,7 @@ static int ctrdev_open(int *max_data_seg_len) struct iscsi_register_info reg = { 0 }; if (!(f = fopen("/proc/devices", "r"))) { - perror("Cannot open control path to the driver\n"); + perror("Cannot open control path to the driver"); goto out; } @@ -86,6 +86,7 @@ static int ctrdev_open(int *max_data_seg_len) err = ioctl(ctlfd, REGISTER_USERD, ®); if (err < 0) { + err = -errno; log_error("Unable to register: %s. Incompatible version of the " "kernel module?\n", strerror(errno)); goto out_close; @@ -99,7 +100,7 @@ out: out_close: close(ctlfd); - ctlfd = -1; + ctlfd = err; goto out; } @@ -112,8 +113,10 @@ static int iscsi_target_create(u32 *tid, char *name) memcpy(info.name, name, sizeof(info.name) - 1); info.tid = *tid; - if ((err = ioctl(ctrl_fd, ADD_TARGET, &info)) < 0) - log_warning("can't create a target %d %u\n", errno, info.tid); + if ((err = ioctl(ctrl_fd, ADD_TARGET, &info)) < 0) { + err = -errno; + log_error("can't create a target %d %u\n", errno, info.tid); + } *tid = info.tid; return err; @@ -122,11 +125,16 @@ static int iscsi_target_create(u32 *tid, char *name) static int iscsi_target_destroy(u32 tid) { struct target_info info; + int res; memset(&info, 0, sizeof(info)); info.tid = tid; - return ioctl(ctrl_fd, DEL_TARGET, &info); + res = ioctl(ctrl_fd, DEL_TARGET, &info); + if (res < 0) + res = -errno; + + return res; } static int iscsi_conn_destroy(u32 tid, u64 sid, u32 cid) @@ -139,7 +147,7 @@ static int iscsi_conn_destroy(u32 tid, u64 sid, u32 cid) info.cid = cid; if ((err = ioctl(ctrl_fd, DEL_CONN, &info)) < 0) - err = errno; + err = -errno; return err; } @@ -258,22 +266,6 @@ static struct session_file_operations target_del_ops = { .target_op = __target_del, }; -int server_stop(void) -{ - conn_blocked = 1; - - proc_session_parse(ctrl_fd, &conn_close_ops, -1, NULL); - - while (proc_session_parse(ctrl_fd, &shutdown_wait_ops, -1, NULL) < 0) - sleep(1); - - proc_session_parse(ctrl_fd, &target_del_ops, -1, NULL); - - isns_exit(); - - return 0; -} - int target_destroy(u32 tid) { int err; @@ -323,8 +315,7 @@ int session_conns_close(u32 tid, u64 sid) return err; } -static int iscsi_param_get(u32 tid, u64 sid, int type, struct iscsi_param *param, - int local) +static int iscsi_param_get(u32 tid, u64 sid, int type, struct iscsi_param *param) { int err, i; struct iscsi_param_info info; @@ -334,30 +325,24 @@ static int iscsi_param_get(u32 tid, u64 sid, int type, struct iscsi_param *param info.sid = sid; info.param_type = type; - if ((err = ioctl(ctrl_fd, ISCSI_PARAM_GET, &info)) < 0) - log_error("Can't get session param %d %d\n", info.tid, errno); - - if (local) { - if (type == key_session) - for (i = 0; i < session_key_last; i++) - param[i].local_val = info.session_param[i]; - else - for (i = 0; i < target_key_last; i++) - param[i].local_val = info.target_param[i]; - } else { - if (type == key_session) - for (i = 0; i < session_key_last; i++) - param[i].exec_val = info.session_param[i]; - else - for (i = 0; i < target_key_last; i++) - param[i].exec_val = info.target_param[i]; + if ((err = ioctl(ctrl_fd, ISCSI_PARAM_GET, &info)) < 0) { + log_error("Can't get session param for session 0x%" PRIu64 + " (tid %u, err %d): %s\n", sid, tid, err, strerror(errno)); + err = -errno; } + if (type == key_session) + for (i = 0; i < session_key_last; i++) + param[i].val = info.session_param[i]; + else + for (i = 0; i < target_key_last; i++) + param[i].val = info.target_param[i]; + return err; } static int iscsi_param_set(u32 tid, u64 sid, int type, u32 partial, - struct iscsi_param *param, int local) + struct iscsi_param *param) { int i, err; struct iscsi_param_info info; @@ -368,25 +353,18 @@ static int iscsi_param_set(u32 tid, u64 sid, int type, u32 partial, info.param_type = type; info.partial = partial; - if (local) { - if (info.param_type == key_session) - for (i = 0; i < session_key_last; i++) - info.session_param[i] = param[i].local_val; - else - for (i = 0; i < target_key_last; i++) - info.target_param[i] = param[i].local_val; - } else { - if (info.param_type == key_session) - for (i = 0; i < session_key_last; i++) - info.session_param[i] = param[i].exec_val; - else - for (i = 0; i < target_key_last; i++) - info.target_param[i] = param[i].exec_val; - } + if (info.param_type == key_session) + for (i = 0; i < session_key_last; i++) + info.session_param[i] = param[i].val; + else + for (i = 0; i < target_key_last; i++) + info.target_param[i] = param[i].val; - if ((err = ioctl(ctrl_fd, ISCSI_PARAM_SET, &info)) < 0) - fprintf(stderr, "%d %d %u " "%" PRIu64 " %d %u\n", - err, errno, tid, sid, type, partial); + if ((err = ioctl(ctrl_fd, ISCSI_PARAM_SET, &info)) < 0) { + fprintf(stderr, "%d %u " "%" PRIu64 " %d %u\n", + errno, tid, sid, type, partial); + err = -errno; + } return err; } @@ -395,6 +373,7 @@ static int iscsi_session_create(u32 tid, u64 sid, u32 exp_cmd_sn, char *name, char *user) { struct session_info info; + int res; memset(&info, 0, sizeof(info)); @@ -404,7 +383,11 @@ static int iscsi_session_create(u32 tid, u64 sid, u32 exp_cmd_sn, strncpy(info.initiator_name, name, sizeof(info.initiator_name) - 1); strncpy(info.user_name, user, sizeof(info.user_name) - 1); - return ioctl(ctrl_fd, ADD_SESSION, &info); + res = ioctl(ctrl_fd, ADD_SESSION, &info); + if (res < 0) + res = -errno; + + return res; } static int iscsi_session_destroy(u32 tid, u64 sid) @@ -421,6 +404,9 @@ static int iscsi_session_destroy(u32 tid, u64 sid) res = ioctl(ctrl_fd, DEL_SESSION, &info); } while (res < 0 && errno == EINTR); + if (res < 0) + res = -errno; + return res; } @@ -428,6 +414,7 @@ static int iscsi_conn_create(u32 tid, u64 sid, u32 cid, u32 stat_sn, u32 exp_sta int fd, u32 hdigest, u32 ddigest) { struct conn_info info; + int res; memset(&info, 0, sizeof(info)); @@ -440,7 +427,11 @@ static int iscsi_conn_create(u32 tid, u64 sid, u32 cid, u32 stat_sn, u32 exp_sta info.header_digest = hdigest; info.data_digest = ddigest; - return ioctl(ctrl_fd, ADD_CONN, &info); + res = ioctl(ctrl_fd, ADD_CONN, &info); + if (res < 0) + res = -errno; + + return res; } struct iscsi_kernel_interface ioctl_ki = { diff --git a/iscsi-scst/usr/iscsi_adm.c b/iscsi-scst/usr/iscsi_adm.c index a300f70fd..68157fce1 100644 --- a/iscsi-scst/usr/iscsi_adm.c +++ b/iscsi-scst/usr/iscsi_adm.c @@ -95,9 +95,8 @@ iSCSI-SCST Target Administration Utility.\n\ If the session has no connections after\n\ the operation, the session will be deleted\n\ automatically.\n\ - --op delete stop all activity.\n\ --op update --tid=[id] --params=key1=value1,key2=value2,...\n\ - change SCST iSCSI target parameters of specific\n\ + change iSCSI target parameters of specific\n\ target with [id]. You can use parameters in iscsi-scstd.conf\n\ as a key.\n\ --op new --tid=[id] --user --params=[user]=[name],Password=[pass]\n\ @@ -147,8 +146,8 @@ static int iscsid_request_send(int fd, struct iscsi_adm_req *req) if (ret != sizeof(*req)) { err = (ret < 0) ? -errno : -EIO; - fprintf(stderr, "%s %d %d %d\n", __func__, __LINE__, ret, - err); + fprintf(stderr, "%s failed: written %d, to write %d, " + "error: %s\n", __func__, ret, err, strerror(err)); } else err = 0; @@ -173,8 +172,8 @@ static int iscsid_response_recv(int fd, struct iscsi_adm_req *req, void *rsp_dat if (ret != sizeof(rsp) + sizeof(*req)) { err = (ret < 0) ? -errno : -EIO; - fprintf(stderr, "%s %d %d %d\n", __func__, __LINE__, ret, - err); + fprintf(stderr, "readv failed: read %d instead of %d (%s)\n", + ret, sizeof(rsp) + sizeof(*req), strerror(err)); } else err = rsp.err; @@ -182,8 +181,8 @@ static int iscsid_response_recv(int fd, struct iscsi_adm_req *req, void *rsp_dat ret = read(fd, rsp_data, rsp_data_sz); if (ret != rsp_data_sz) { err = (ret < 0) ? -errno : -EIO; - fprintf(stderr, "%s %d %d %d\n", __FUNCTION__, - __LINE__, ret, err); + fprintf(stderr, "read failed: read %d instead of %d (%s)\n", + ret, rsp_data_sz, strerror(err)); } } @@ -196,16 +195,24 @@ static int iscsid_connect(void) struct sockaddr_un addr; fd = socket(AF_LOCAL, SOCK_STREAM, 0); - if (fd < 0) - return -errno; + if (fd < 0) { + perror("socket() failed"); + fd = -errno; + goto out; + } memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_LOCAL; memcpy((char *) &addr.sun_path + 1, ISCSI_ADM_NAMESPACE, strlen(ISCSI_ADM_NAMESPACE)); - if (connect(fd, (struct sockaddr *) &addr, sizeof(addr))) + if (connect(fd, (struct sockaddr *) &addr, sizeof(addr))) { fd = -errno; + fprintf(stderr, "Unable to connect to iscsid: %s\n", + strerror(-fd)); + goto out; + } +out: return fd; } @@ -216,21 +223,25 @@ static int iscsid_request(struct iscsi_adm_req *req, void *rsp_data, if ((fd = iscsid_connect()) < 0) { err = fd; - goto out; + goto out_close; } if ((err = iscsid_request_send(fd, req)) < 0) - goto out; + goto out_report; err = iscsid_response_recv(fd, req, rsp_data, rsp_data_sz); -out: +out_report: + if (err < 0) { + if (err == -ENOENT) + err = -EINVAL; + fprintf(stderr, "Request to iscsid failed: %s\n", strerror(-err)); + } + +out_close: if (fd > 0) close(fd); - if (err < 0) - fprintf(stderr, "%s.\n", strerror(-err)); - return err; } @@ -253,7 +264,7 @@ static void show_iscsi_param(int type, struct iscsi_param *param) strcpy(buf, keys[i].name); p = buf + strlen(buf); *p++ = '='; - param_val_to_str(keys, i, param[i].local_val, p); + param_val_to_str(keys, i, param[i].val, p); printf("%s\n", buf); } } @@ -280,7 +291,7 @@ static int parse_trgt_params(struct msg_trgt *msg, char *params) } if (!param_check_val(target_keys, idx, &val)) msg->target_partial |= (1 << idx); - msg->target_param[idx].local_val = val; + msg->target_param[idx].val = val; msg->type |= 1 << key_target; continue; @@ -295,7 +306,7 @@ static int parse_trgt_params(struct msg_trgt *msg, char *params) } if (!param_check_val(session_keys, idx, &val)) msg->session_partial |= (1 << idx); - msg->session_param[idx].local_val = val; + msg->session_param[idx].val = val; msg->type |= 1 << key_session; continue; @@ -323,11 +334,17 @@ static int trgt_handle(int op, u32 set, u32 tid, char *params) { char *p = params; - if (!params || !(p = strchr(params, '='))) + if (!params || !(p = strchr(params, '='))) { + fprintf(stderr, "Target name required\n"); + err = -EINVAL; goto out; + } *p++ = '\0'; - if (strcmp(params, "Name")) + if (strcmp(params, "Name")) { + fprintf(stderr, "Target name required\n"); + err = -EINVAL; goto out; + } req.rcmnd = C_TRGT_NEW; strncpy(req.u.trgt.name, p, sizeof(req.u.trgt.name) - 1); break; @@ -622,30 +639,6 @@ out: return err; } -static int sys_handle(int op, u32 set, char *params) -{ - int err = -EINVAL; - struct iscsi_adm_req req; - - memset(&req, 0, sizeof(req)); - - switch (op) { - case OP_NEW: - break; - case OP_DELETE: - req.rcmnd = C_SYS_DEL; - break; - case OP_UPDATE: - break; - case OP_SHOW: - break; - } - - err = iscsid_request(&req, NULL, 0); - - return err; -} - int main(int argc, char **argv) { int ch, longindex; @@ -661,15 +654,15 @@ int main(int argc, char **argv) op = str_to_op(optarg); break; case 't': - tid = strtoul(optarg, NULL, 10); + tid = strtoul(optarg, NULL, 0); set |= SET_TARGET; break; case 's': - sid = strtoull(optarg, NULL, 10); + sid = strtoull(optarg, NULL, 0); set |= SET_SESSION; break; case 'c': - cid = strtoul(optarg, NULL, 10); + cid = strtoul(optarg, NULL, 0); set |= SET_CONNECTION; break; case 'p': @@ -711,8 +704,6 @@ int main(int argc, char **argv) err = sess_handle(op, set, tid, sid, params); else if (set & SET_TARGET) err = trgt_handle(op, set, tid, params); - else if (!set) - err = sys_handle(op, set, params); else usage(-1); diff --git a/iscsi-scst/usr/iscsi_adm.h b/iscsi-scst/usr/iscsi_adm.h index 2dd651d37..0013f3581 100644 --- a/iscsi-scst/usr/iscsi_adm.h +++ b/iscsi-scst/usr/iscsi_adm.h @@ -65,11 +65,6 @@ enum iscsi_adm_cmnd { C_ACCT_UPDATE, C_ACCT_SHOW, - C_SYS_NEW, - C_SYS_DEL, - C_SYS_UPDATE, - C_SYS_SHOW, - C_ACCT_LIST, }; diff --git a/iscsi-scst/usr/iscsi_scstd.c b/iscsi-scst/usr/iscsi_scstd.c index d696cc362..b300d05e5 100644 --- a/iscsi-scst/usr/iscsi_scstd.c +++ b/iscsi-scst/usr/iscsi_scstd.c @@ -217,7 +217,7 @@ static void accept_connection(int listen) namesize = sizeof(from); if ((fd = accept(listen, (struct sockaddr *) &from, &namesize)) < 0) { if (errno != EINTR && errno != EAGAIN) { - perror("accept(incoming_socket)\n"); + perror("accept(incoming_socket) failed"); exit(1); } return; @@ -578,7 +578,7 @@ int main(int argc, char **argv) int max_data_seg_len = -1; if (pipe(init_report_pipe) == -1) { - perror("pipe"); + perror("pipe failed"); exit(-1); } @@ -600,16 +600,16 @@ int main(int argc, char **argv) log_level = strtol(optarg, NULL, 0); break; case 'u': - uid = strtoul(optarg, NULL, 10); + uid = strtoul(optarg, NULL, 0); break; case 'g': - gid = strtoul(optarg, NULL, 10); + gid = strtoul(optarg, NULL, 0); break; case 'a': server_address = strdup(optarg); break; case 'p': - server_port = (uint16_t)strtoul(optarg, NULL, 10); + server_port = (uint16_t)strtoul(optarg, NULL, 0); break; case 'v': printf("%s version %s\n", program_name, ISCSI_VERSION_STRING); @@ -625,7 +625,7 @@ int main(int argc, char **argv) } if ((nl_fd = nl_open()) < 0) { - perror("netlink fd\n"); + perror("netlink open failed"); exit(-1); }; @@ -635,7 +635,7 @@ int main(int argc, char **argv) init_max_data_seg_len(max_data_seg_len); if ((ipc_fd = iscsi_adm_request_listen()) < 0) { - perror("ipc fd\n"); + perror("ipc failed\n"); exit(-1); } @@ -698,10 +698,10 @@ int main(int argc, char **argv) exit(1); if (gid && setgid(gid) < 0) - perror("setgid\n"); + perror("setgid failed"); if (uid && setuid(uid) < 0) - perror("setuid\n"); + perror("setuid failed"); event_loop(timeout); diff --git a/iscsi-scst/usr/iscsid.c b/iscsi-scst/usr/iscsid.c index 97852034d..dcb3a566d 100644 --- a/iscsi-scst/usr/iscsid.c +++ b/iscsi-scst/usr/iscsid.c @@ -126,7 +126,7 @@ void text_key_add(struct connection *conn, char *key, char *value) size_t data_sz; data_sz = (conn->state == STATE_FULL) ? - conn->session_param[key_max_xmit_data_length].exec_val : + conn->session_param[key_max_xmit_data_length].val : INCOMING_BUFSIZE; seg = list_empty(&conn->rsp_buf_list) ? NULL : @@ -178,7 +178,7 @@ void text_key_add(struct connection *conn, char *key, char *value) break; } - log_debug(1, "wrote: %s\n", seg->data + seg->len); + log_debug(2, "wrote: %s\n", seg->data + seg->len); seg->len += sz; len -= sz; @@ -307,8 +307,7 @@ static void text_scan_login(struct connection *conn) idx = key_max_xmit_data_length; if (param_str_to_val(session_keys, idx, value, &val) < 0) { - if (conn->session_param[idx].state - == KEY_STATE_START) { + if (conn->session_param[idx].state == KEY_STATE_START) { text_key_add_reject(conn, key); continue; } else { @@ -331,12 +330,12 @@ static void text_scan_login(struct connection *conn) text_key_add(conn, key, buf); break; case KEY_STATE_REQUEST: - if (val != conn->session_param[idx].exec_val) { + if (val != conn->session_param[idx].val) { rsp->status_class = ISCSI_STATUS_INITIATOR_ERR; rsp->status_detail = ISCSI_STATUS_INIT_ERR; conn->state = STATE_EXIT; log_warning("%s %u %u\n", key, - val, conn->session_param[idx].exec_val); + val, conn->session_param[idx].val); goto out; } break; @@ -359,7 +358,7 @@ static int text_check_param(struct connection *conn) int i, cnt; for (i = 0, cnt = 0; session_keys[i].name; i++) { - if (p[i].state == KEY_STATE_START && p[i].exec_val != session_keys[i].rfc_def) { + if (p[i].state == KEY_STATE_START && p[i].val != session_keys[i].rfc_def) { switch (conn->state) { case STATE_LOGIN_FULL: case STATE_SECURITY_FULL: @@ -372,8 +371,7 @@ static int text_check_param(struct connection *conn) if (iscsi_is_key_declarative(i)) continue; memset(buf, 0, sizeof(buf)); - param_val_to_str(session_keys, i, p[i].exec_val, - buf); + param_val_to_str(session_keys, i, p[i].val, buf); text_key_add(conn, session_keys[i].name, buf); if (i == key_max_recv_data_length) { p[i].state = KEY_STATE_DONE; @@ -451,13 +449,11 @@ static void login_start(struct connection *conn) } if (ki->param_get(conn->tid, 0, key_session, - conn->session_param, 1)) { + conn->session_param)) { rsp->status_class = ISCSI_STATUS_TARGET_ERROR; rsp->status_detail = ISCSI_STATUS_SVC_UNAVAILABLE; conn->state = STATE_EXIT; } - conn->session_param[key_max_recv_data_length].exec_val = - conn->session_param[key_max_recv_data_length].local_val; } conn->exp_cmd_sn = be32_to_cpu(req->cmd_sn); log_debug(1, "exp_cmd_sn: %d,%d", conn->exp_cmd_sn, req->cmd_sn); @@ -468,10 +464,21 @@ static void login_finish(struct connection *conn) { switch (conn->session_type) { case SESSION_NORMAL: + { + int i; + for (i = 0; session_keys[i].name; i++) { + if (conn->session_param[i].state == KEY_STATE_START) { + log_debug(1, "Key %s was not negotiated, use RFC defined " + "default %d", session_keys[i].name, + session_keys[i].rfc_def); + conn->session_param[i].val = session_keys[i].rfc_def; + } + } if (!conn->session) session_create(conn); conn->sid = conn->session->sid; break; + } case SESSION_DISCOVERY: /* set a dummy tsih value */ conn->sid.id.tsih = 1; diff --git a/iscsi-scst/usr/iscsid.h b/iscsi-scst/usr/iscsid.h index a3d4d79b5..7f53da9ee 100644 --- a/iscsi-scst/usr/iscsid.h +++ b/iscsi-scst/usr/iscsid.h @@ -189,15 +189,21 @@ extern int log_daemon; extern int log_level; extern void log_init(void); -extern void log_info(const char *fmt, ...) - __attribute__ ((format (printf, 1, 2))); -extern void log_warning(const char *fmt, ...) - __attribute__ ((format (printf, 1, 2))); -extern void log_error(const char *fmt, ...) - __attribute__ ((format (printf, 1, 2))); -extern void log_debug(int level, const char *fmt, ...) - __attribute__ ((format (printf, 2, 3))); -extern void log_pdu(int level, struct PDU *pdu); +extern void __log_info(const char *func, int line, const char *fmt, ...) + __attribute__ ((format (printf, 3, 4))); +extern void __log_warning(const char *func, int line, const char *fmt, ...) + __attribute__ ((format (printf, 3, 4))); +extern void __log_error(const char *func, int line, const char *fmt, ...) + __attribute__ ((format (printf, 3, 4))); +extern void __log_debug(const char *func, int line, int level, const char *fmt, ...) + __attribute__ ((format (printf, 4, 5))); +extern void __log_pdu(const char *func, int line, int level, struct PDU *pdu); + +#define log_info(args...) __log_info(__func__, __LINE__, ## args) +#define log_warning(args...) __log_warning(__func__, __LINE__, ## args) +#define log_error(args...) __log_error(__func__, __LINE__, ## args) +#define log_debug(args...) __log_debug(__func__, __LINE__, ## args) +#define log_pdu(args...) __log_pdu(__func__, __LINE__, ## args) /* session.c */ extern struct session *session_find_name(u32 tid, const char *iname, union iscsi_sid sid); @@ -220,8 +226,8 @@ extern int iscsi_adm_request_handle(int accept_fd); /* ctldev.c */ struct iscsi_kernel_interface { int (*ctldev_open) (int *); - int (*param_get) (u32, u64, int, struct iscsi_param *, int); - int (*param_set) (u32, u64, int, u32, struct iscsi_param *, int); + int (*param_get) (u32, u64, int, struct iscsi_param *); + int (*param_set) (u32, u64, int, u32, struct iscsi_param *); int (*target_create) (u32 *, char *); int (*target_destroy) (u32); int (*session_create) (u32, u64, u32, char *, char *); @@ -234,7 +240,6 @@ extern struct iscsi_kernel_interface *ki; /* the following functions should be killed */ extern int session_conns_close(u32 tid, u64 sid); -extern int server_stop(void); extern int target_destroy(u32 tid); /* event.c */ diff --git a/iscsi-scst/usr/isns.c b/iscsi-scst/usr/isns.c index f29689a64..21e71ed62 100644 --- a/iscsi-scst/usr/isns.c +++ b/iscsi-scst/usr/isns.c @@ -92,14 +92,14 @@ static int isns_get_ip(int fd) err = getsockname(fd, (struct sockaddr *) &lss, &slen); if (err) { - log_error("getsockname error %s!", gai_strerror(err)); + log_error("getsockname error: %s!", gai_strerror(err)); return err; } err = getnameinfo((struct sockaddr *) &lss, sizeof(lss), eid, sizeof(eid), NULL, 0, 0); if (err) { - log_error("getaddrinfo error %s!", gai_strerror(err)); + log_error("getaddrinfo error: %s!", gai_strerror(err)); return err; } @@ -772,7 +772,7 @@ static int scn_accept_connection(void) slen = sizeof(from); fd = accept(scn_listen_fd, (struct sockaddr *) &from, &slen); if (fd < 0) { - log_error("%s %d: accept error %s", __func__, __LINE__, + log_error("%s %d: accept error: %s", __func__, __LINE__, strerror(errno)); return -errno; } @@ -920,7 +920,7 @@ int isns_init(char *addr, int isns_ac) hints.ai_socktype = SOCK_STREAM; err = getaddrinfo(addr, (char *) &port, &hints, &res); if (err) { - log_error("getaddrinfo error %s, %s", gai_strerror(err), addr); + log_error("getaddrinfo error: %s, %s", gai_strerror(err), addr); return -1; } memcpy(&ss, res->ai_addr, sizeof(ss)); diff --git a/iscsi-scst/usr/log.c b/iscsi-scst/usr/log.c index 4202c173b..4840aa2e1 100644 --- a/iscsi-scst/usr/log.c +++ b/iscsi-scst/usr/log.c @@ -32,7 +32,7 @@ void log_init(void) openlog("iscsi-scstd", 0, LOG_DAEMON); } -static void dolog(int prio, const char *fmt, va_list ap) +static void dolog_nofunc(int prio, const char *fmt, va_list ap) { if (log_daemon) { int len = strlen(fmt); @@ -53,41 +53,67 @@ static void dolog(int prio, const char *fmt, va_list ap) } } -void log_info(const char *fmt, ...) +static void dolog(int prio, const char *func, int line, const char *fmt, va_list ap) +{ + if (log_level == 0) { + dolog_nofunc(prio, fmt, ap); + return; + } + + if (log_daemon) { + int len = strlen(func) + strlen(fmt); + char f[len+1+1]; + if (fmt[len] != '\n') + sprintf(f, "%s:%d: %s\n", func, line, fmt); + else + sprintf(f, "%s:%d: %s", func, line, fmt); + vsyslog(prio, f, ap); + } else { + struct timeval time; + + gettimeofday(&time, NULL); + fprintf(stderr, "%ld.%06ld: %s:%d: ", time.tv_sec, time.tv_usec, func, line); + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + fflush(stderr); + } +} + +void __log_info(const char *func, int line, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - dolog(LOG_INFO, fmt, ap); + dolog(LOG_INFO, func, line, fmt, ap); va_end(ap); } -void log_warning(const char *fmt, ...) +void __log_warning(const char *func, int line, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - dolog(LOG_WARNING, fmt, ap); + dolog(LOG_WARNING, func, line, fmt, ap); va_end(ap); } -void log_error(const char *fmt, ...) +void __log_error(const char *func, int line, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - dolog(LOG_ERR, fmt, ap); + dolog(LOG_ERR, func, line, fmt, ap); va_end(ap); } -void log_debug(int level, const char *fmt, ...) +void __log_debug(const char *func, int line, int level, const char *fmt, ...) { if (log_level > level) { va_list ap; va_start(ap, fmt); - dolog(LOG_DEBUG, fmt, ap); + dolog(LOG_DEBUG, func, line, fmt, ap); va_end(ap); } } -/* Definition for log_pdu buffer */ +/* Definition for __log_pdu buffer */ #define BUFFER_SIZE 16 /* @@ -96,7 +122,7 @@ void log_debug(int level, const char *fmt, ...) */ #define LINE_SIZE (BUFFER_SIZE * 3 + BUFFER_SIZE / 4 * 2 + 1) -static void __dump_line(int level, unsigned char *buf, int *cp) +static void __dump_line(const char *func, int line_num, int level, unsigned char *buf, int *cp) { char line[LINE_SIZE], *lp = line; int i, cnt; @@ -116,23 +142,23 @@ static void __dump_line(int level, unsigned char *buf, int *cp) } /* buf is not \0-terminated! */ - log_debug(level, "%s %.*s |", line, BUFFER_SIZE, buf); + __log_debug(func, line_num, level, "%s %.*s |", line, BUFFER_SIZE, buf); *cp = 0; } -static void __dump_char(int level, unsigned char *buf, int *cp, int ch) +static void __dump_char(const char *func, int line, int level, unsigned char *buf, int *cp, int ch) { int cnt = (*cp)++; buf[cnt] = ch; if (cnt == BUFFER_SIZE - 1) - __dump_line(level, buf, cp); + __dump_line(func, line, level, buf, cp); } -#define dump_line() __dump_line(level, char_buf, &char_cnt) -#define dump_char(ch) __dump_char(level, char_buf, &char_cnt, ch) +#define dump_line() __dump_line(func, line, level, char_buf, &char_cnt) +#define dump_char(ch) __dump_char(func, line, level, char_buf, &char_cnt, ch) -void log_pdu(int level, struct PDU *pdu) +void __log_pdu(const char *func, int line, int level, struct PDU *pdu) { unsigned char char_buf[BUFFER_SIZE]; int char_cnt = 0; @@ -143,19 +169,19 @@ void log_pdu(int level, struct PDU *pdu) return; buf = (void *)&pdu->bhs; - log_debug(level, "BHS: (%p)", buf); + __log_debug(func, line, level, "BHS: (%p)", buf); for (i = 0; i < BHS_SIZE; i++) dump_char(*buf++); dump_line(); buf = (void *)pdu->ahs; - log_debug(level, "AHS: (%p)", buf); + __log_debug(func, line, level, "AHS: (%p)", buf); for (i = 0; i < pdu->ahssize; i++) dump_char(*buf++); dump_line(); buf = (void *)pdu->data; - log_debug(level, "Data: (%p)", buf); + __log_debug(func, line, level, "Data: (%p)", buf); for (i = 0; i < pdu->datasize; i++) dump_char(*buf++); dump_line(); diff --git a/iscsi-scst/usr/message.c b/iscsi-scst/usr/message.c index 01f5abbb3..94b5e7d58 100644 --- a/iscsi-scst/usr/message.c +++ b/iscsi-scst/usr/message.c @@ -53,8 +53,8 @@ static void iscsi_adm_request_exec(struct iscsi_adm_req *req, struct iscsi_adm_r { int err = 0; - log_debug(1, "%u %u %" PRIu64 " %u %u", req->rcmnd, req->tid, - req->sid, req->cid, req->lun); + log_debug(1, "request %u, tid %u, sid 0x%" PRIx64 ", cid %u, lun %u", + req->rcmnd, req->tid, req->sid, req->cid, req->lun); switch (req->rcmnd) { case C_TRGT_NEW: @@ -80,7 +80,7 @@ static void iscsi_adm_request_exec(struct iscsi_adm_req *req, struct iscsi_adm_r break; case C_TRGT_SHOW: err = ki->param_get(req->tid, req->sid, key_target, - req->u.trgt.target_param, 0); + req->u.trgt.target_param); break; case C_SESS_NEW: @@ -89,14 +89,13 @@ static void iscsi_adm_request_exec(struct iscsi_adm_req *req, struct iscsi_adm_r break; case C_SESS_SHOW: err = ki->param_get(req->tid, req->sid, key_session, - req->u.trgt.session_param, 0); + req->u.trgt.session_param); break; case C_CONN_NEW: case C_CONN_DEL: conn_blocked = 1; err = ki->conn_destroy(req->tid, req->sid, req->cid); - sleep(1); conn_blocked = 0; break; case C_CONN_UPDATE: @@ -134,14 +133,6 @@ static void iscsi_adm_request_exec(struct iscsi_adm_req *req, struct iscsi_adm_r req->u.acnt.u.user.name, req->u.acnt.u.user.pass); break; - case C_SYS_NEW: - break; - case C_SYS_DEL: - err = server_stop(); - break; - case C_SYS_UPDATE: - case C_SYS_SHOW: - break; default: break; } diff --git a/iscsi-scst/usr/param.c b/iscsi-scst/usr/param.c index 880d222d3..fd8323dc4 100644 --- a/iscsi-scst/usr/param.c +++ b/iscsi-scst/usr/param.c @@ -40,11 +40,7 @@ void param_set_defaults(struct iscsi_param *params, struct iscsi_key *keys) int i; for (i = 0; keys[i].name; i++) { - if (i == key_max_recv_data_length) - params[i].exec_val = keys[i].local_def; - else - params[i].exec_val = keys[i].rfc_def; - params[i].local_val = keys[i].local_def; + params[i].val = keys[i].local_def; } } @@ -94,16 +90,16 @@ static int bool_str_to_val(char *str, unsigned int *val) static int or_set_val(struct iscsi_param *param, int idx, unsigned int *val) { - *val |= param[idx].local_val; - param[idx].exec_val = *val; + *val |= param[idx].val; + param[idx].val = *val; return 0; } static int and_set_val(struct iscsi_param *param, int idx, unsigned int *val) { - *val &= param[idx].local_val; - param[idx].exec_val = *val; + *val &= param[idx].val; + param[idx].val = *val; return 0; } @@ -125,17 +121,17 @@ static int num_check_val(struct iscsi_key *key, unsigned int *val) static int minimum_set_val(struct iscsi_param *param, int idx, unsigned int *val) { - if (*val > param[idx].local_val) - *val = param[idx].local_val; - param[idx].exec_val = *val; + if (*val > param[idx].val) + *val = param[idx].val; + param[idx].val = *val; return 0; } static int maximum_set_val(struct iscsi_param *param, int idx, unsigned int *val) { - if (param[idx].local_val > *val) - *val = param[idx].local_val; - param[idx].exec_val = *val; + if (param[idx].val > *val) + *val = param[idx].val; + param[idx].val = *val; return 0; } @@ -179,12 +175,12 @@ static int digest_str_to_val(char *str, unsigned int *val) static int digest_set_val(struct iscsi_param *param, int idx, unsigned int *val) { - if (*val & DIGEST_CRC32C && param[idx].local_val & DIGEST_CRC32C) + if (*val & DIGEST_CRC32C && param[idx].val & DIGEST_CRC32C) *val = DIGEST_CRC32C; else *val = DIGEST_NONE; - param[idx].exec_val = *val; + param[idx].val = *val; return 0; } @@ -207,7 +203,7 @@ static int marker_set_val(struct iscsi_param *param, int idx, unsigned int *val) else *val = 1; - param[idx].exec_val = *val; + param[idx].val = *val; return 0; } diff --git a/iscsi-scst/usr/param.h b/iscsi-scst/usr/param.h index b1e63414f..af027dfd9 100644 --- a/iscsi-scst/usr/param.h +++ b/iscsi-scst/usr/param.h @@ -20,8 +20,7 @@ struct iscsi_key; struct iscsi_param { int state; - unsigned int exec_val; - unsigned int local_val; + unsigned int val; }; struct iscsi_key_ops { diff --git a/iscsi-scst/usr/plain.c b/iscsi-scst/usr/plain.c index 97bf51e43..977cfefad 100644 --- a/iscsi-scst/usr/plain.c +++ b/iscsi-scst/usr/plain.c @@ -475,7 +475,7 @@ static int __plain_target_create(u32 *tid, char *name, int update) return err; param_set_defaults(params, session_keys); - if ((err = ki->param_set(*tid, 0, key_session, 0, params, 1)) < 0) + if ((err = ki->param_set(*tid, 0, key_session, 0, params)) < 0) return err; if (update) @@ -505,7 +505,7 @@ static int __plain_param_set(u32 tid, u64 sid, int type, { int err; - if ((err = ki->param_set(tid, sid, type, partial, param, 1)) < 0) + if ((err = ki->param_set(tid, sid, type, partial, param)) < 0) return err; if (update) @@ -531,7 +531,7 @@ static int iscsi_param_partial_set(u32 tid, u64 sid, int type, int key, u32 val) else param = target_param; - param[key].local_val = val; + param[key].val = val; return __plain_param_set(tid, sid, type, 1 << key, param, 0); } diff --git a/iscsi-scst/usr/session.c b/iscsi-scst/usr/session.c index 7100dda69..64c0b45f2 100644 --- a/iscsi-scst/usr/session.c +++ b/iscsi-scst/usr/session.c @@ -163,7 +163,7 @@ void session_create(struct connection *conn) ki->session_create(conn->tid, session->sid.id64, conn->exp_cmd_sn, session->initiator, user); ki->param_set(conn->tid, session->sid.id64, key_session, 0, - conn->session_param, 0); + conn->session_param); } void session_remove(struct session *session)