From e252aadf35e809e85d7dc93825205229a8d90dbe Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Tue, 17 Mar 2009 18:00:26 +0000 Subject: [PATCH] - Fixed problems in reading iscsi-scst.conf - Cleanups git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@698 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/Makefile | 2 +- iscsi-scst/usr/chap.c | 6 +-- iscsi-scst/usr/{plain.c => config.c} | 74 ++++++++++------------------ iscsi-scst/usr/config.h | 35 ------------- iscsi-scst/usr/conn.c | 3 -- iscsi-scst/usr/ctldev.c | 68 ++++++++++++++----------- iscsi-scst/usr/iscsi_scstd.c | 7 +-- iscsi-scst/usr/iscsid.c | 28 +++++++++-- iscsi-scst/usr/iscsid.h | 21 ++++++-- iscsi-scst/usr/isns.c | 14 +----- iscsi-scst/usr/message.c | 16 +++--- iscsi-scst/usr/param.c | 5 +- iscsi-scst/usr/session.c | 8 +-- iscsi-scst/usr/target.c | 44 +++++++++++------ 14 files changed, 155 insertions(+), 176 deletions(-) rename iscsi-scst/usr/{plain.c => config.c} (84%) delete mode 100644 iscsi-scst/usr/config.h diff --git a/iscsi-scst/usr/Makefile b/iscsi-scst/usr/Makefile index 9710bb172..0ce5f815e 100644 --- a/iscsi-scst/usr/Makefile +++ b/iscsi-scst/usr/Makefile @@ -15,7 +15,7 @@ # GNU General Public License for more details. SRCS_D = iscsid.c iscsi_scstd.c conn.c session.c target.c message.c ctldev.c \ - log.c chap.c event.c param.c plain.c isns.c + log.c chap.c event.c param.c config.c isns.c OBJS_D = $(SRCS_D:.c=.o) SRCS_ADM = iscsi_adm.c param.c diff --git a/iscsi-scst/usr/chap.c b/iscsi-scst/usr/chap.c index cb3c13412..e8a866692 100644 --- a/iscsi-scst/usr/chap.c +++ b/iscsi-scst/usr/chap.c @@ -391,7 +391,7 @@ static int chap_initiator_auth_check_response(struct connection *conn) char pass[ISCSI_NAME_LEN]; memset(pass, 0, sizeof(pass)); - if (cops->account_query(conn->tid, AUTH_DIR_INCOMING, pass, pass) < 0) { + if (config_account_query(conn->tid, AUTH_DIR_INCOMING, pass, pass) < 0) { log_warning("CHAP initiator auth.: " "No CHAP credentials configured"); retval = CHAP_TARGET_ERROR; @@ -409,7 +409,7 @@ static int chap_initiator_auth_check_response(struct connection *conn) } memset(pass, 0, sizeof(pass)); - if (cops->account_query(conn->tid, AUTH_DIR_INCOMING, value, pass) < 0) { + if (config_account_query(conn->tid, AUTH_DIR_INCOMING, value, pass) < 0) { log_warning("CHAP initiator auth.: " "No valid user/pass combination for initiator %s " "found", conn->initiator); @@ -506,7 +506,7 @@ static int chap_target_auth_create_response(struct connection *conn) memset(pass, 0, sizeof(pass)); memset(name, 0, sizeof(name)); - if (cops->account_query(conn->tid, AUTH_DIR_OUTGOING, name, pass) < 0) { + if (config_account_query(conn->tid, AUTH_DIR_OUTGOING, name, pass) < 0) { log_warning("CHAP target auth.: " "no outgoing credentials configured%s", conn->tid ? "." : " for discovery."); diff --git a/iscsi-scst/usr/plain.c b/iscsi-scst/usr/config.c similarity index 84% rename from iscsi-scst/usr/plain.c rename to iscsi-scst/usr/config.c index 20efe3f78..98fbd7c74 100644 --- a/iscsi-scst/usr/plain.c +++ b/iscsi-scst/usr/config.c @@ -1,6 +1,4 @@ /* - * Plain file-based configuration file code. - * * Copyright (C) 2005 FUJITA Tomonori * Copyright (C) 2007 - 2008 Vladislav Bolkhovitin * Copyright (C) 2007 - 2008 CMS Distribution Limited @@ -95,7 +93,7 @@ static struct __qelem *account_list_get(u32 tid, int dir) return list; } -static int plain_account_init(char *filename) +static int config_account_init(char *filename) { FILE *fp; char buf[BUFSIZE], *p, *q; @@ -117,15 +115,15 @@ static int plain_account_init(char *filename) tid = 0; if (!(p = target_sep_string(&q))) continue; - tid = target_find_by_name(p); + tid = target_find_id_by_name(p); } else if (!((idx = param_index_by_name(p, user_keys)) < 0)) { char *name, *pass; name = target_sep_string(&q); pass = target_sep_string(&q); - res = cops->account_add(tid, idx, name, pass); + res = config_account_add(tid, idx, name, pass); if (res < 0) { - fprintf(stderr, "%s %s\n", name, pass); + log_error("%s %s\n", name, pass); break; } } @@ -143,7 +141,6 @@ static struct user *account_lookup_by_name(u32 tid, int dir, char *name) struct user *user = NULL; list_for_each_entry(user, list, ulist) { - fprintf(stderr, "%u %s %s\n", user->tid, user->password, user->name); if (user->tid != tid) continue; if (!strlen(name)) @@ -155,7 +152,7 @@ static struct user *account_lookup_by_name(u32 tid, int dir, char *name) return NULL; } -static int plain_account_query(u32 tid, int dir, char *name, char *pass) +int config_account_query(u32 tid, int dir, char *name, char *pass) { struct user *user; @@ -170,8 +167,8 @@ static int plain_account_query(u32 tid, int dir, char *name, char *pass) return 0; } -static int plain_account_list(u32 tid, int dir, u32 *cnt, u32 *overflow, - char *buf, size_t buf_sz) +int config_account_list(u32 tid, int dir, u32 *cnt, u32 *overflow, + char *buf, size_t buf_sz) { struct __qelem *list = account_list_get(tid, dir); struct user *user; @@ -204,7 +201,7 @@ static void account_destroy(struct user *user) free(user); } -static int plain_account_del(u32 tid, int dir, char *name) +int config_account_del(u32 tid, int dir, char *name) { struct user *user; @@ -230,7 +227,7 @@ static struct user *account_create(void) return user; } -static int plain_account_add(u32 tid, int dir, char *name, char *pass) +int config_account_add(u32 tid, int dir, char *name, char *pass) { int err = -ENOMEM; struct user *user; @@ -438,7 +435,7 @@ static int initiator_match(u32 tid, int fd, char *filename) continue; *(p++) = '\0'; - if (target_find_by_name(buf) != tid && strcmp(buf, "ALL")) + if (target_find_id_by_name(buf) != tid && strcmp(buf, "ALL")) continue; err = __initiator_match(fd, p); @@ -449,7 +446,7 @@ static int initiator_match(u32 tid, int fd, char *filename) return err; } -static int plain_initiator_access(u32 tid, int fd) +int config_initiator_access(u32 tid, int fd) { if (initiator_match(tid, fd, "/etc/initiators.deny") && !initiator_match(tid, fd, "/etc/initiators.allow")) @@ -462,7 +459,7 @@ static int plain_initiator_access(u32 tid, int fd) * Main configuration code */ -static int __plain_target_create(u32 *tid, char *name, int update) +static int __config_target_create(u32 *tid, char *name, int update) { int err; @@ -476,39 +473,31 @@ static int __plain_target_create(u32 *tid, char *name, int update) return err; } -static int plain_target_create(u32 *tid, char *name) +int config_target_create(u32 *tid, char *name) { - return __plain_target_create(tid, name, 1); + return __config_target_create(tid, name, 1); } -static int plain_target_destroy(u32 tid) +int config_target_destroy(u32 tid) { int err; if ((err = target_del(tid)) < 0) return err; - /* Update the config file here. */ return err; } -static int __plain_param_set(u32 tid, u64 sid, int type, - u32 partial, struct iscsi_param *param, int update) +int config_param_set(u32 tid, u64 sid, int type, u32 partial, + struct iscsi_param *param) { int err; - if ((err = kernel_param_set(tid, sid, type, partial, param)) < 0) - return err; + err = kernel_param_set(tid, sid, type, partial, param); return err; } -static int plain_param_set(u32 tid, u64 sid, int type, - u32 partial, struct iscsi_param *param) -{ - return __plain_param_set(tid, sid, type, partial, param, 1); -} - static int iscsi_param_partial_set(u32 tid, u64 sid, int type, int key, u32 val) { struct iscsi_param *param; @@ -522,10 +511,10 @@ static int iscsi_param_partial_set(u32 tid, u64 sid, int type, int key, u32 val) param[key].val = val; - return __plain_param_set(tid, sid, type, 1 << key, param, 0); + return config_param_set(tid, sid, type, 1 << key, param); } -static int plain_main_init(char *filename) +static int config_main_init(char *filename) { FILE *config; char buf[BUFSIZE]; @@ -548,7 +537,7 @@ static int plain_main_init(char *filename) tid = 0; if (!(p = target_sep_string(&q))) continue; - if (__plain_target_create(&tid, p, 0)) + if (__config_target_create(&tid, p, 0)) log_debug(1, "creating target %s", p); } else if (!strcasecmp(p, "Alias") && tid) { ; @@ -587,7 +576,7 @@ static int plain_main_init(char *filename) return res; } -static int plain_default_load(char *params) +int config_load(char *params) { int i, err; @@ -597,10 +586,10 @@ static int plain_default_load(char *params) } /* First, we must finish the main configuration. */ - if ((err = plain_main_init(params ? params : CONFIG_FILE))) + if ((err = config_main_init(params ? params : CONFIG_FILE))) return err; - if ((err = plain_account_init(ACCT_CONFIG_FILE)) < 0) + if ((err = config_account_init(ACCT_CONFIG_FILE)) < 0) return err; /* TODO: error handling */ @@ -608,7 +597,7 @@ static int plain_default_load(char *params) return err; } -static int plain_init(char *params, char **isns, int *isns_ac) +int config_isns_load(char *params, char **isns, int *isns_ac) { FILE *config; char buf[BUFSIZE]; @@ -634,16 +623,3 @@ static int plain_init(char *params, char **isns, int *isns_ac) fclose(config); return 0; } - -struct config_operations plain_ops = { - .init = plain_init, - .default_load = plain_default_load, - .target_add = plain_target_create, - .target_del = plain_target_destroy, - .param_set = plain_param_set, - .account_add = plain_account_add, - .account_del = plain_account_del, - .account_query = plain_account_query, - .account_list = plain_account_list, - .initiator_access = plain_initiator_access, -}; diff --git a/iscsi-scst/usr/config.h b/iscsi-scst/usr/config.h deleted file mode 100644 index 33cf495f6..000000000 --- a/iscsi-scst/usr/config.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2007 - 2008 Vladislav Bolkhovitin - * Copyright (C) 2007 - 2008 CMS Distribution Limited - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation, version 2 - * of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#ifndef CONFIG_H -#define CONFIG_H - -struct config_operations { - int (*init) (char *, char **, int *); - int (*default_load) (char *); - int (*target_add) (u32 *, char *); - int (*target_stop) (u32); - int (*target_del) (u32); - int (*param_set) (u32, u64, int, u32, struct iscsi_param *); - int (*account_add) (u32, int, char *, char *); - int (*account_del) (u32, int, char *); - int (*account_query) (u32, int, char *, char *); - int (*account_list) (u32, int, u32 *, u32 *, char *, size_t); - int (*initiator_access) (u32, int); -}; - -extern struct config_operations *cops; - -#endif diff --git a/iscsi-scst/usr/conn.c b/iscsi-scst/usr/conn.c index 38d396abf..0514745c7 100644 --- a/iscsi-scst/usr/conn.c +++ b/iscsi-scst/usr/conn.c @@ -65,9 +65,6 @@ void conn_pass_to_kern(struct connection *conn, int fd) conn->session_param[key_header_digest].val, conn->session_param[key_data_digest].val); - if (err != 0) - log_error("kernel_conn_create() failed: %s", strerror(errno)); - /* We don't need to return err, because we are going to close conn anyway */ return; } diff --git a/iscsi-scst/usr/ctldev.c b/iscsi-scst/usr/ctldev.c index f5d6a83dd..ed5ee85c5 100644 --- a/iscsi-scst/usr/ctldev.c +++ b/iscsi-scst/usr/ctldev.c @@ -28,12 +28,6 @@ #define CTL_DEVICE "/dev/iscsi-scst-ctl" -struct session_file_operations { - int (*target_op) (int fd, u32 tid, void *arg); - int (*session_op) (int fd, u32 tid, u64 sid, void *arg); - int (*connection_op) (int fd, u32 tid, u64 sid, u32 cid, void *arg); -}; - int kernel_open(int *max_data_seg_len) { FILE *f; @@ -45,8 +39,9 @@ int kernel_open(int *max_data_seg_len) struct iscsi_kern_register_info reg = { 0 }; if (!(f = fopen("/proc/devices", "r"))) { + err = -errno; perror("Cannot open control path to the driver"); - goto out; + goto out_err; } devn = 0; @@ -65,21 +60,24 @@ int kernel_open(int *max_data_seg_len) fclose(f); if (!devn) { + err = -ENOENT; printf("cannot find iscsictl in /proc/devices - " "make sure the module is loaded\n"); - goto out; + goto out_err; } unlink(CTL_DEVICE); if (mknod(CTL_DEVICE, (S_IFCHR | 0600), (devn << 8))) { + err = -errno; printf("cannot create %s %d\n", CTL_DEVICE, errno); - goto out; + goto out_err; } ctlfd = open(CTL_DEVICE, O_RDWR); if (ctlfd < 0) { + err = -errno; printf("cannot open %s %d\n", CTL_DEVICE, errno); - goto out; + goto out_err; } reg.version = (uintptr_t)ISCSI_SCST_INTERFACE_VERSION; @@ -100,6 +98,8 @@ out: out_close: close(ctlfd); + +out_err: ctlfd = err; goto out; } @@ -115,10 +115,11 @@ int kernel_target_create(u32 *tid, char *name) info.tid = *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); - } + log_error("Can't create target %u: %s\n", *tid, + strerror(errno)); + } else + *tid = info.tid; - *tid = info.tid; return err; } @@ -131,8 +132,10 @@ int kernel_target_destroy(u32 tid) info.tid = tid; res = ioctl(ctrl_fd, DEL_TARGET, &info); - if (res < 0) + if (res < 0) { res = -errno; + log_error("Can't destroy target %d %u\n", errno, tid); + } return res; } @@ -146,16 +149,14 @@ int kernel_conn_destroy(u32 tid, u64 sid, u32 cid) info.sid = sid; info.cid = cid; - if ((err = ioctl(ctrl_fd, DEL_CONN, &info)) < 0) + if ((err = ioctl(ctrl_fd, DEL_CONN, &info)) < 0) { err = -errno; + log_error("Can't destroy conn %d %u\n", errno, cid); + } return err; } -struct session_conn_close_arg { - u64 sid; -}; - int kernel_param_get(u32 tid, u64 sid, int type, struct iscsi_param *param) { int err, i; @@ -167,9 +168,9 @@ int kernel_param_get(u32 tid, u64 sid, int type, struct iscsi_param *param) info.param_type = type; 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; + log_debug(1, "Can't get session param for session 0x%" PRIu64 + " (tid %u, err %d): %s\n", sid, tid, err, strerror(errno)); } if (type == key_session) @@ -202,9 +203,10 @@ int kernel_param_set(u32 tid, u64 sid, int type, u32 partial, info.target_param[i] = param[i].val; 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; + log_error("Can't set session param for session 0x%" PRIu64 + " (tid %u, type %d, partial %d, err %d): %s\n", sid, + tid, type, partial, err, strerror(errno)); } return err; @@ -225,8 +227,11 @@ int kernel_session_create(u32 tid, u64 sid, u32 exp_cmd_sn, strncpy(info.user_name, user, sizeof(info.user_name) - 1); res = ioctl(ctrl_fd, ADD_SESSION, &info); - if (res < 0) + if (res < 0) { res = -errno; + log_error("Can't create sess 0x%" PRIu64 " (tid %d, " + "initiator %s): %s\n", sid, tid, name, strerror(errno)); + } return res; } @@ -241,12 +246,12 @@ int kernel_session_destroy(u32 tid, u64 sid) info.tid = tid; info.sid = sid; - do { - res = ioctl(ctrl_fd, DEL_SESSION, &info); - } while (res < 0 && errno == EINTR); - - if (res < 0) + res = ioctl(ctrl_fd, DEL_SESSION, &info); + if (res < 0) { res = -errno; + log_error("Can't destroy sess 0x%" PRIu64 " (tid %d): %s\n", + sid, tid, strerror(errno)); + } return res; } @@ -269,8 +274,11 @@ int kernel_conn_create(u32 tid, u64 sid, u32 cid, u32 stat_sn, u32 exp_stat_sn, info.data_digest = ddigest; res = ioctl(ctrl_fd, ADD_CONN, &info); - if (res < 0) + if (res < 0) { res = -errno; + log_error("Can't create conn %x (sess 0x%" PRIu64 ", tid %d): %s\n", + cid, sid, tid, strerror(errno)); + } return res; } diff --git a/iscsi-scst/usr/iscsi_scstd.c b/iscsi-scst/usr/iscsi_scstd.c index 6b663af11..5a4d9de9e 100644 --- a/iscsi-scst/usr/iscsi_scstd.c +++ b/iscsi-scst/usr/iscsi_scstd.c @@ -78,9 +78,6 @@ static struct option const long_options[] = {0, 0, 0, 0}, }; -/* This will be comfigurable by command line options */ -struct config_operations *cops = &plain_ops; - int init_report_pipe[2]; static void usage(int status) @@ -737,11 +734,11 @@ int main(int argc, char **argv) setsid(); } - cops->init(config, &isns, &isns_ac); + config_isns_load(config, &isns, &isns_ac); if (isns) timeout = isns_init(isns, isns_ac); - if (cops->default_load(config) != 0) + if (config_load(config) != 0) exit(1); if (gid && setgid(gid) < 0) diff --git a/iscsi-scst/usr/iscsid.c b/iscsi-scst/usr/iscsid.c index 3304a12ad..08f423b61 100644 --- a/iscsi-scst/usr/iscsid.c +++ b/iscsi-scst/usr/iscsid.c @@ -195,7 +195,7 @@ static int account_empty(u32 tid, int dir) char pass[ISCSI_NAME_LEN]; memset(pass, 0, sizeof(pass)); - return cops->account_query(tid, dir, pass, pass) < 0 ? 1 : 0; + return config_account_query(tid, dir, pass, pass) < 0 ? 1 : 0; } static void text_scan_security(struct connection *conn) @@ -496,6 +496,9 @@ static void login_start(struct connection *conn) } if (conn->session_type == SESSION_NORMAL) { + struct target *target; + int err; + if (!target_name) { rsp->status_class = ISCSI_STATUS_INITIATOR_ERR; rsp->status_detail = ISCSI_STATUS_MISSING_FIELDS; @@ -503,14 +506,33 @@ static void login_start(struct connection *conn) return; } - if (!(conn->tid = target_find_by_name(target_name)) || - cops->initiator_access(conn->tid, conn->fd) || + target = target_find_by_name(target_name); + if ((target == NULL) || + config_initiator_access(conn->tid, conn->fd) || isns_scn_access(conn->tid, conn->fd, name)) { rsp->status_class = ISCSI_STATUS_INITIATOR_ERR; rsp->status_detail = ISCSI_STATUS_TGT_NOT_FOUND; conn->state = STATE_EXIT; return; } + conn->tid = target->tid; + + err = kernel_param_get(conn->tid, conn->sid.id64, key_session, + conn->session_param); + if (err == -ENOENT) { + err = kernel_param_get(conn->tid, 0, key_session, + conn->session_param); + } + + if (err != 0) { + log_error("Can't get session param for session 0x%" PRIu64 + " (err %d): %s\n", conn->sid.id64, err, + strerror(-err)); + rsp->status_class = ISCSI_STATUS_TARGET_ERR; + rsp->status_detail = ISCSI_STATUS_TARGET_ERROR; + conn->state = STATE_EXIT; + return; + } if (login_check_reinstatement(conn) != 0) return; diff --git a/iscsi-scst/usr/iscsid.h b/iscsi-scst/usr/iscsid.h index 4396dc66a..7992e6c73 100644 --- a/iscsi-scst/usr/iscsid.h +++ b/iscsi-scst/usr/iscsid.h @@ -25,7 +25,6 @@ #include "iscsi_hdr.h" #include "iscsi_scst.h" #include "param.h" -#include "config.h" #include "misc.h" #define sBUG() assert(0) @@ -161,7 +160,6 @@ struct target { struct __qelem isns_head; }; -extern struct config_operations plain_ops; extern int ctrl_fd; extern int conn_blocked; @@ -222,8 +220,9 @@ extern struct connection *conn_find(struct session *session, u16 cid); extern struct __qelem targets_list; extern int target_add(u32 *, char *); extern int target_del(u32); -extern u32 target_find_by_name(const char *name); -struct target * target_find_by_id(u32); +extern u32 target_find_id_by_name(const char *name); +extern struct target *target_find_by_name(const char *name); +struct target *target_find_by_id(u32); extern void target_list_build(struct connection *, char *, char *); /* message.c */ @@ -251,6 +250,20 @@ extern int nl_open(void); /* param.c */ extern int param_index_by_name(char *name, struct iscsi_key *keys); +/* config.c */ +extern int config_isns_load(char *params, char **isns, int *isns_ac); +extern int config_load(char *params); +extern int config_target_create(u32 *tid, char *name); +extern int config_target_destroy(u32 tid); +int config_account_add(u32 tid, int dir, char *name, char *pass); +extern int config_account_query(u32 tid, int dir, char *name, char *pass); +extern int config_account_list(u32 tid, int dir, u32 *cnt, u32 *overflow, + char *buf, size_t buf_sz); +extern int config_account_del(u32 tid, int dir, char *name); +extern int config_param_set(u32 tid, u64 sid, int type, u32 partial, + struct iscsi_param *param); +extern int config_initiator_access(u32 tid, int fd); + /* isns.c */ extern int isns_init(char *addr, int isns_ac); extern int isns_handle(int is_timeout, int *timeout); diff --git a/iscsi-scst/usr/isns.c b/iscsi-scst/usr/isns.c index 21e71ed62..85e159e51 100644 --- a/iscsi-scst/usr/isns.c +++ b/iscsi-scst/usr/isns.c @@ -447,16 +447,6 @@ static void free_all_acl(struct target *target) } } -static struct target *target_lookup_by_name(char *name) -{ - uint32_t tid; - - tid = target_find_by_name(name); - if (!tid) - return NULL; - return target_find_by_id(tid); -} - int isns_target_deregister(char *name) { char buf[4096]; @@ -466,7 +456,7 @@ int isns_target_deregister(char *name) int err, last = list_empty(&targets_list); struct target *target; - target = target_lookup_by_name(name); + target = target_find_by_name(name); if (target) free_all_acl(target); @@ -667,7 +657,7 @@ found: goto free_qry_mgmt; } - target = target_lookup_by_name(mgmt->name); + target = target_find_by_name(mgmt->name); if (!target) { log_error("%s %d: invalid tid %s", __func__, __LINE__, mgmt->name); diff --git a/iscsi-scst/usr/message.c b/iscsi-scst/usr/message.c index a26ead2d3..b829d0813 100644 --- a/iscsi-scst/usr/message.c +++ b/iscsi-scst/usr/message.c @@ -58,14 +58,14 @@ static void iscsi_adm_request_exec(struct iscsi_adm_req *req, struct iscsi_adm_r switch (req->rcmnd) { case C_TRGT_NEW: - err = cops->target_add(&req->tid, req->u.trgt.name); + err = config_target_create(&req->tid, req->u.trgt.name); break; case C_TRGT_DEL: - err = cops->target_del(req->tid); + err = config_target_destroy(req->tid); break; case C_TRGT_UPDATE: if (req->u.trgt.type & (1 << key_session)) - err = cops->param_set(req->tid, req->sid, + err = config_param_set(req->tid, req->sid, key_session, req->u.trgt.session_partial, req->u.trgt.session_param); @@ -74,7 +74,7 @@ static void iscsi_adm_request_exec(struct iscsi_adm_req *req, struct iscsi_adm_r goto out; if (req->u.trgt.type & (1 << key_target)) - err = cops->param_set(req->tid, req->sid, key_target, + err = config_param_set(req->tid, req->sid, key_target, req->u.trgt.target_partial, req->u.trgt.target_param); break; @@ -103,12 +103,12 @@ static void iscsi_adm_request_exec(struct iscsi_adm_req *req, struct iscsi_adm_r break; case C_ACCT_NEW: - err = cops->account_add(req->tid, req->u.acnt.auth_dir, + err = config_account_add(req->tid, req->u.acnt.auth_dir, req->u.acnt.u.user.name, req->u.acnt.u.user.pass); break; case C_ACCT_DEL: - err = cops->account_del(req->tid, req->u.acnt.auth_dir, + err = config_account_del(req->tid, req->u.acnt.auth_dir, req->u.acnt.u.user.name); break; case C_ACCT_LIST: @@ -121,7 +121,7 @@ static void iscsi_adm_request_exec(struct iscsi_adm_req *req, struct iscsi_adm_r *rsp_data_sz = req->u.acnt.u.list.alloc_len; memset(*rsp_data, 0x0, *rsp_data_sz); - err = cops->account_list(req->tid, req->u.acnt.auth_dir, + err = config_account_list(req->tid, req->u.acnt.auth_dir, &req->u.acnt.u.list.count, &req->u.acnt.u.list.overflow, *rsp_data, *rsp_data_sz); @@ -129,7 +129,7 @@ static void iscsi_adm_request_exec(struct iscsi_adm_req *req, struct iscsi_adm_r case C_ACCT_UPDATE: break; case C_ACCT_SHOW: - err = cops->account_query(req->tid, req->u.acnt.auth_dir, + err = config_account_query(req->tid, req->u.acnt.auth_dir, req->u.acnt.u.user.name, req->u.acnt.u.user.pass); break; diff --git a/iscsi-scst/usr/param.c b/iscsi-scst/usr/param.c index cad5bf81a..f2c08b235 100644 --- a/iscsi-scst/usr/param.c +++ b/iscsi-scst/usr/param.c @@ -39,9 +39,10 @@ void param_set_defaults(struct iscsi_param *params, struct iscsi_key *keys) { int i; - for (i = 0; keys[i].name; i++) { + for (i = 0; keys[i].name; i++) params[i].val = keys[i].local_def; - } + + return; } static int range_val_to_str(unsigned int val, char *str) diff --git a/iscsi-scst/usr/session.c b/iscsi-scst/usr/session.c index 3567eac4d..ff4e7a352 100644 --- a/iscsi-scst/usr/session.c +++ b/iscsi-scst/usr/session.c @@ -143,17 +143,13 @@ int session_create(struct connection *conn) res = kernel_session_create(conn->tid, session->sid.id64, conn->exp_cmd_sn, session->initiator, user); - if (res != 0) { - log_error("kernel_session_create() failed: %d", res); + if (res != 0) goto out_free; - } res = kernel_param_set(conn->tid, session->sid.id64, key_session, 0, conn->session_param); - if (res != 0) { - log_error("kernel_param_set() failed: %d", res); + if (res != 0) goto out_destroy; - } out: return res; diff --git a/iscsi-scst/usr/target.c b/iscsi-scst/usr/target.c index 2c31ae4d4..08ab2408f 100644 --- a/iscsi-scst/usr/target.c +++ b/iscsi-scst/usr/target.c @@ -33,7 +33,7 @@ void target_list_build(struct connection *conn, char *addr, char *name) list_for_each_entry(target, &targets_list, tlist) { if (name && strcmp(target->name, name)) continue; - if (cops->initiator_access(target->tid, conn->fd) || + if (config_initiator_access(target->tid, conn->fd) || isns_scn_access(target->tid, conn->fd, conn->initiator)) continue; @@ -42,7 +42,7 @@ void target_list_build(struct connection *conn, char *addr, char *name) } } -u32 target_find_by_name(const char *name) +u32 target_find_id_by_name(const char *name) { struct target *target; @@ -54,6 +54,18 @@ u32 target_find_by_name(const char *name) return 0; } +struct target *target_find_by_name(const char *name) +{ + struct target *target; + + list_for_each_entry(target, &targets_list, tlist) { + if (!strcasecmp(target->name, name)) + return target; + } + + return NULL; +} + struct target *target_find_by_id(u32 tid) { struct target *target; @@ -72,9 +84,9 @@ static void all_accounts_del(u32 tid, int dir) memset(name, 0, sizeof(name)); - for (;cops->account_query(tid, dir, name, pass) != -ENOENT; + for (; config_account_query(tid, dir, name, pass) != -ENOENT; memset(name, 0, sizeof(name))) { - cops->account_del(tid, dir, name); + config_account_del(tid, dir, name); } } @@ -84,8 +96,8 @@ int target_del(u32 tid) struct target *target = target_find_by_id(tid); int err = kernel_target_destroy(tid); - if (err < 0 && errno != ENOENT) - return -errno; + if (err < 0 && err != -ENOENT) + return err; else if (!err && !target) /* A leftover kernel object was cleaned up - don't complain. */ return 0; @@ -114,7 +126,8 @@ int target_add(u32 *tid, char *name) { struct target *target; int err; - struct iscsi_param params[target_key_last]; + struct iscsi_param tgt_params[target_key_last]; + struct iscsi_param sess_params[session_key_last]; if (!name) return -EINVAL; @@ -125,17 +138,18 @@ int target_add(u32 *tid, char *name) memset(target, 0, sizeof(*target)); memcpy(target->name, name, sizeof(target->name) - 1); - if ((err = kernel_target_create(tid, name)) < 0) { - log_warning("can't create a target %d %u\n", errno, *tid); + if ((err = kernel_target_create(tid, name)) < 0) goto out_free; - } - param_set_defaults(params, target_keys); - err = kernel_param_set(*tid, 0, key_target, 0, params); - if (err != 0) { - log_error("kernel_param_set() failed: %s", strerror(errno)); + param_set_defaults(tgt_params, target_keys); + err = kernel_param_set(*tid, 0, key_target, 0, tgt_params); + if (err != 0) + goto out_destroy; + + param_set_defaults(sess_params, session_keys); + err = kernel_param_set(*tid, 0, key_session, 0, sess_params); + if (err != 0) goto out_destroy; - } INIT_LIST_HEAD(&target->tlist); INIT_LIST_HEAD(&target->sessions_list);