From a23e34fb62135d9f4ee4f4712c16fb8d70d80ed4 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 22:04:07 +0000 Subject: [PATCH 01/22] The argument to sleep() would get "promoted" to an integer with value zero. - sleep(0.1); + usleep(100*1000); Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7107 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- usr/stpgd/stpgd_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/stpgd/stpgd_main.c b/usr/stpgd/stpgd_main.c index 63fa92bdd..be0796248 100644 --- a/usr/stpgd/stpgd_main.c +++ b/usr/stpgd/stpgd_main.c @@ -195,7 +195,7 @@ int wait_until_finished(pid_t pid, unsigned long deadline, int *status, int chil } break; } - sleep(0.1); + usleep(100*1000); time(&end); elapsed = difftime(end, start); } while (elapsed < deadline); From d236725cae6246083b97e0a688220564f78f5834 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 22:30:25 +0000 Subject: [PATCH 02/22] create_and_open_dev() returns a (-errno), so the "if (iser_fd...)" check should detect *any* negative return value as a case when fd should be set to -1. Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7108 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/iscsi_scstd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iscsi-scst/usr/iscsi_scstd.c b/iscsi-scst/usr/iscsi_scstd.c index 147bd3da0..dba29b113 100644 --- a/iscsi-scst/usr/iscsi_scstd.c +++ b/iscsi-scst/usr/iscsi_scstd.c @@ -232,14 +232,15 @@ static void create_iser_listen_socket(struct pollfd *array) iser_fd = create_and_open_dev("isert_scst", 1); - poll_array[POLL_ISER_LISTEN].fd = iser_fd; - if (iser_fd != -1) { + if (iser_fd >= 0) { + poll_array[POLL_ISER_LISTEN].fd = iser_fd; poll_array[POLL_ISER_LISTEN].events = POLLIN; /* RDMAExtensions */ session_keys[key_rdma_extensions].max = 1; session_keys[key_rdma_extensions].local_def = 1; } else { + poll_array[POLL_ISER_LISTEN].fd = -1; poll_array[POLL_ISER_LISTEN].events = 0; return; } From aa6c6a4c2fc3d025b2cb16ee4ab8533bad00da39 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 22:38:38 +0000 Subject: [PATCH 03/22] Change memcpy() to strncpy() because the source name string is not guaranteed to exist as valid addressable memory beyond the NULL byte. Signed-off-by: David Butterfield with small addition to force set last byte NULL git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7109 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/target.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iscsi-scst/usr/target.c b/iscsi-scst/usr/target.c index 9c6898d98..0cb47fe31 100644 --- a/iscsi-scst/usr/target.c +++ b/iscsi-scst/usr/target.c @@ -415,7 +415,8 @@ int target_create(const char *name, struct target **out_target) } memset(target, 0, sizeof(*target)); - memcpy(target->name, name, sizeof(target->name) - 1); + strncpy(target->name, name, sizeof(target->name) - 1); + target->name[sizeof(target->name)-1] = '\0'; params_set_defaults(target->target_params, target_keys); params_set_defaults(target->session_params, session_keys); From 2331e8ec33c40fcb350160c48dbe84d6062f05fd Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 23:02:18 +0000 Subject: [PATCH 04/22] Thre is potential buffer overflow in iscsi_session_alloc() due to short computation of needed string size. Notice the "%s@%s" in the first call to sprintf(). Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7110 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/session.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iscsi-scst/kernel/session.c b/iscsi-scst/kernel/session.c index 9c6bdc758..568415ef8 100644 --- a/iscsi-scst/kernel/session.c +++ b/iscsi-scst/kernel/session.c @@ -65,7 +65,7 @@ static int iscsi_session_alloc(struct iscsi_target *target, #ifdef CONFIG_SCST_PROC name = kmalloc(strlen(info->user_name) + strlen(info->initiator_name) + - 1, GFP_KERNEL); + 2, GFP_KERNEL); /* +1 (for '\0') +1 (for '@') */ if (name == NULL) { err = -ENOMEM; goto err; From baba3ad19543c62b3e190fdd4e9c8984ed97a281 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 23:12:46 +0000 Subject: [PATCH 05/22] iscsi: avoid a crash in iscsi_extracheck_is_rd_thread() Add an extra check in iscsi_extracheck_is_rd_thread() to avoid a crash when conn->rd_task is NULL. Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7111 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/conn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iscsi-scst/kernel/conn.c b/iscsi-scst/kernel/conn.c index 33e138ec0..e713a1e43 100644 --- a/iscsi-scst/kernel/conn.c +++ b/iscsi-scst/kernel/conn.c @@ -1126,7 +1126,8 @@ void iscsi_extracheck_is_rd_thread(struct iscsi_conn *conn) local_bh_enable(); pr_emerg("rd_state %x\n", conn->rd_state); pr_emerg("rd_task %p\n", conn->rd_task); - pr_emerg("rd_task->pid %d\n", conn->rd_task->pid); + if (conn->rd_task) + pr_emerg("rd_task->pid %d\n", conn->rd_task->pid); BUG(); } } From b71fa76b5b006b69a5acad266cad948b3aa2b954 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 23:15:17 +0000 Subject: [PATCH 06/22] iscsi: fix misleading error logging in config.c This fixes four similar instances of a very misleading and confusing logging statement, which would print a "Wrong value" that had already been corrected by the check function. Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7112 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/config.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/iscsi-scst/usr/config.c b/iscsi-scst/usr/config.c index 8a11f32ae..8ac6fa731 100644 --- a/iscsi-scst/usr/config.c +++ b/iscsi-scst/usr/config.c @@ -856,11 +856,12 @@ int config_params_set(u32 tid, u64 sid, int type, u32 partial, if (type == key_session) { for (i = 0; i < session_key_last; i++) { + uint32_t in_val = params[i].val; if (partial & (1 << i)) { err = params_check_val(session_keys, i, ¶ms[i].val); if (err < 0) { - log_error("Wrong value %u for parameter %s\n", - params[i].val, session_keys[i].name); + log_error("%s: Wrong value %u->%u for session parameter %s\n", + __func__, in_val, params[i].val, session_keys[i].name); goto out; } } @@ -871,11 +872,12 @@ int config_params_set(u32 tid, u64 sid, int type, u32 partial, } } else { for (i = 0; i < target_key_last; i++) { + uint32_t in_val = params[i].val; if (partial & (1 << i)) { err = params_check_val(target_keys, i, ¶ms[i].val); if (err < 0) { - log_error("Wrong value %u for parameter %s\n", - params[i].val, target_keys[i].name); + log_error("%s: Wrong value %u->%u for target parameter %s\n", + __func__, in_val, params[i].val, target_keys[i].name); goto out; } } @@ -962,10 +964,11 @@ int config_parse_main(const char *data, u32 cookie) continue; } + uint32_t in_val = val; res = params_check_val(target_keys, idx, &val); if (res < 0) { - log_error("Wrong value %u for parameter %s\n", - val, target_keys[idx].name); + log_error("%s: Wrong value %u->%u for target parameter %s\n", + __func__, in_val, val, target_keys[idx].name); continue; } target->target_params[idx] = val; @@ -986,10 +989,11 @@ int config_parse_main(const char *data, u32 cookie) continue; } + uint32_t in_val = val; res = params_check_val(session_keys, idx, &val); if (res < 0) { - log_error("Wrong value %u for parameter %s\n", - val, session_keys[idx].name); + log_error("%s: Wrong value %u->%u for session parameter %s\n", + __func__, in_val, val, session_keys[idx].name); continue; } target->session_params[idx] = val; From bcb87d57ec9642b41977c25c0fba1843e71d8e06 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 23:16:57 +0000 Subject: [PATCH 07/22] iscsi: logging improvements for iscsi_scstd.c Logging improvements for iscsi_scstd.c print more information about failures. Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7113 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/iscsi_scstd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/iscsi-scst/usr/iscsi_scstd.c b/iscsi-scst/usr/iscsi_scstd.c index dba29b113..7fa813d04 100644 --- a/iscsi-scst/usr/iscsi_scstd.c +++ b/iscsi-scst/usr/iscsi_scstd.c @@ -509,8 +509,11 @@ again: case IOSTATE_READ_BHS: case IOSTATE_READ_AHS_DATA: read_again: + errno = 0; /* for the log_debug() */ res = read(pollfd->fd, conn->buffer, conn->rwsize); if (res <= 0) { + log_debug(1, "read(%u, %p, %u) returned %d, errno=%u", + pollfd->fd, conn->buffer, conn->rwsize, res, errno); if (res == 0 || (errno != EINTR && errno != EAGAIN)) { conn->state = STATE_DROP; goto out; @@ -577,6 +580,8 @@ again: conn->cork_transmit(pollfd->fd); res = write(pollfd->fd, conn->buffer, conn->rwsize); if (res < 0) { + log_debug(1, "write(%u, %p, %u) returned %d, errno=%u", + pollfd->fd, conn->buffer, conn->rwsize, res, errno); if (errno != EINTR && errno != EAGAIN) { conn->state = STATE_DROP; goto out; @@ -747,7 +752,8 @@ static void event_loop(void) (conn->state == STATE_DROP)) { struct session *sess = conn->sess; - log_debug(1, "closing conn %p", conn); + log_debug(1, "closing conn %p state=0x%x fd=%u", + conn, conn->state, pollfd->fd); conn_free_pdu(conn); close(pollfd->fd); pollfd->fd = -1; From f05a100fb4aeb473f0d2078b8e46d2a1ee38db6f Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 23:19:05 +0000 Subject: [PATCH 08/22] scst_vdisk: logging to distinguish different cases of EINVAL Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7114 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index ba4d7ba69..7d188ee60 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -1158,6 +1158,8 @@ static int vdisk_get_file_size(const char *filename, bool blockio, } else if (S_ISBLK(inode->i_mode)) { inode = inode->i_bdev->bd_inode; } else { + PRINT_ERROR("File %s unsupported mode: mode=0%o\n", + filename, inode->i_mode); res = -EINVAL; goto out_close; } @@ -8115,6 +8117,7 @@ static int vdev_parse_add_dev_params(struct scst_vdisk_dev *virt_dev, } else if (!strcasecmp("blocksize", p)) { virt_dev->blk_shift = scst_calc_block_shift(val); if (virt_dev->blk_shift < 9) { + PRINT_ERROR("blocksize %u too small", 1<blk_shift); res = -EINVAL; goto out; } @@ -10358,6 +10361,7 @@ static int vdisk_write_proc(char *buffer, char **start, off_t offset, block_shift = scst_calc_block_shift(block_size); if (block_shift < 9) { + PRINT_ERROR("blocksize %u too small", 1< Date: Thu, 13 Apr 2017 23:37:13 +0000 Subject: [PATCH 09/22] scst: fix memory leak in scst_proc_group_add() Valgrind noticed that the "name" allocated in scst_proc_group_add() was leaking. It turns out that scst_alloc_add_acg makes its own copy of the name passed to it from this code, making the string duplication done here redundant (and leaky). The change eliminates the string duplication (along with all its associated error handling logic) and simply passes the (unowned) incoming string down for duplication below. Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7115 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_proc.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/scst/src/scst_proc.c b/scst/src/scst_proc.c index ebd12d5e8..199da4726 100644 --- a/scst/src/scst_proc.c +++ b/scst/src/scst_proc.c @@ -939,23 +939,14 @@ static void scst_proc_del_acg_tree(struct proc_dir_entry *acg_proc_root, /* The activity supposed to be suspended and scst_mutex held */ static int scst_proc_group_add(const char *p, unsigned int addr_method) { - int res = 0, len = strlen(p) + 1; + int res = 0; struct scst_acg *acg; - char *name = NULL; - TRACE_ENTRY(); - name = kmalloc(len, GFP_KERNEL); - if (name == NULL) { - PRINT_ERROR("Allocation of new name (size %d) failed", len); - goto out_nomem; - } - strlcpy(name, p, len); - - res = scst_alloc_add_acg(NULL, name, false, &acg); + res = scst_alloc_add_acg(NULL, p, false, &acg); if (res != 0) { - PRINT_ERROR("scst_alloc_add_acg() (name %s) failed", name); - goto out_free; + PRINT_ERROR("scst_alloc_add_acg() (name %s) failed", p); + goto out; } acg->addr_method = addr_method; @@ -971,11 +962,6 @@ out: out_free_acg: scst_proc_del_free_acg(acg, 0); -out_free: - kfree(name); - goto out; - -out_nomem: res = -ENOMEM; goto out; } From c0440263b057fea81b0c7fcb1f5828cf56916f9f Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 23:39:14 +0000 Subject: [PATCH 10/22] scst_vdisk: fix memory leak in vdisk_write_proc() Another leak valgrind popped out, this one in vdisk_write_proc(). Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7116 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 7d188ee60..6caed8d92 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -10429,7 +10429,7 @@ static int vdisk_write_proc(char *buffer, char **start, off_t offset, PRINT_ERROR("File path \"%s\" is not " "absolute", filename); res = -EINVAL; - goto out_up; + goto out_free_vdev; } virt_dev->filename = kstrdup(filename, GFP_KERNEL); From bbd9b42a2e7e3a93dfb58805cff142030d1b9583 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 23:41:14 +0000 Subject: [PATCH 11/22] scst: take scst_mutex before calling scst_del_free_acg() in exit_scst() scst_del_free_acg() does lockdep_assert_held(&scst_mutex), so we'd better take the lock before calling it. Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7117 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index 1f6139e52..da92985fb 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -2859,7 +2859,9 @@ static void __exit exit_scst(void) scsi_unregister_interface(&scst_interface); #ifdef CONFIG_SCST_PROC + mutex_lock(&scst_mutex); scst_del_free_acg(scst_default_acg, false); + mutex_unlock(&scst_mutex); #endif scst_sgv_pools_deinit(); From a4a1e480b155a6ac59b71e93f7df4af2f419ed2a Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 23:42:51 +0000 Subject: [PATCH 12/22] scst: take scst_mutex before calling scst_del_free_acg() in scst_proc_cleanup_module() Take lock before a call that ends up at the lockdep_assert_held() in scst_del_free_acg() without locking. Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7118 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_proc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scst/src/scst_proc.c b/scst/src/scst_proc.c index 199da4726..bf5d3637b 100644 --- a/scst/src/scst_proc.c +++ b/scst/src/scst_proc.c @@ -1213,7 +1213,11 @@ void scst_proc_cleanup_module(void) /* We may not bother about locks here */ scst_proc_cleanup_sgv(); + + mutex_lock(&scst_mutex); scst_proc_cleanup_groups(); + mutex_unlock(&scst_mutex); + scst_proc_cleanup_module_log(); remove_proc_entry(SCST_PROC_THREADS_NAME, scst_proc_scsi_tgt); remove_proc_entry(SCST_PROC_HELP_NAME, scst_proc_scsi_tgt); From f84ed1c222c8402f14a21a8a49fdb23fa6c21b50 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 23:43:55 +0000 Subject: [PATCH 13/22] scst: remove superfluous assignment in scst_dg_add() The "res" is unconditionally set by the call to scst_dg_sysfs_add(), so setting it to ENOMEM above that is superfluous. Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7119 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_tg.c | 1 - 1 file changed, 1 deletion(-) diff --git a/scst/src/scst_tg.c b/scst/src/scst_tg.c index b8cc4456c..a488230df 100644 --- a/scst/src/scst_tg.c +++ b/scst/src/scst_tg.c @@ -1296,7 +1296,6 @@ int scst_dg_add(struct kobject *parent, const char *name) res = -EEXIST; if (__lookup_dg_by_name(name)) goto out_unlock; - res = -ENOMEM; INIT_LIST_HEAD(&dg->dev_list); INIT_LIST_HEAD(&dg->tg_list); res = scst_dg_sysfs_add(parent, dg); From 011bc77ec9b682e7e5d28ad6782b47e6fd47ea30 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 23:45:15 +0000 Subject: [PATCH 14/22] scst_vdisk: remove parentheses from DEF_DIF_FILENAME_TMPL DEF_DIF_FILENAME_TMPL should not have the parentheses; I used it in some context where that became apparent. Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7120 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 6caed8d92..4bf745e7c 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -137,7 +137,7 @@ static struct scst_trace_log vdisk_local_trace_tbl[] = { #define DEF_DPICZ SCST_DPICZ_CHECK_ON_xPROT_0 -#define DEF_DIF_FILENAME_TMPL (SCST_VAR_DIR "/dif_tags/%s.dif") +#define DEF_DIF_FILENAME_TMPL SCST_VAR_DIR "/dif_tags/%s.dif" #ifdef CONFIG_SCST_PROC #define VDISK_PROC_HELP "help" From 9c7b81617946031584eb91b44e01431afda3d395 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 23:53:35 +0000 Subject: [PATCH 15/22] scst_vdisk: move declarations inside #ifdef Move some #ifdefs to also cover declarations used only inside the #ifdef. This is to avoid compiler warnings about unused variables. Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7121 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 4bf745e7c..8375281e0 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -1077,12 +1077,12 @@ check: #endif if (virt_dev->blockio) { +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) || \ + (defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 6) struct request_queue *q; sBUG_ON(!fd_open); q = bdev_get_queue(file_inode(fd)->i_bdev); -#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) || \ - (defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 6) virt_dev->unmap_opt_gran = q->limits.discard_granularity >> block_shift; virt_dev->unmap_align = q->limits.discard_alignment >> block_shift; if (virt_dev->unmap_opt_gran == virt_dev->unmap_align) @@ -7887,6 +7887,8 @@ static void vdev_destroy(struct scst_vdisk_dev *virt_dev) return; } +#ifndef CONFIG_SCST_PROC + static void vdev_check_node(struct scst_vdisk_dev **pvirt_dev, int orig_nodeid) { struct scst_vdisk_dev *virt_dev = *pvirt_dev; @@ -7914,8 +7916,6 @@ out: return; } -#ifndef CONFIG_SCST_PROC - static int vdev_parse_add_dev_params(struct scst_vdisk_dev *virt_dev, char *params, const char *const allowed_params[]) { From a2e0916fbf625adc51c84862562a4f1c071e7319 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Thu, 13 Apr 2017 23:58:32 +0000 Subject: [PATCH 16/22] Fix a few compiler messages issued when some extra warnings are enabled: casting const to non-const uninitialized structure members non-static local function missing enumerated switch-value cases Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7122 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/nthread.c | 4 +++- iscsi-scst/usr/config.c | 6 +++--- iscsi-scst/usr/iscsid.c | 18 +++++++++--------- iscsi-scst/usr/misc.c | 2 +- scst/src/dev_handlers/scst_vdisk.c | 3 +++ scst/src/scst_lib.c | 4 ++++ scst/src/scst_proc.c | 1 + scst/src/scst_targ.c | 2 ++ scst/src/scst_tg.c | 3 +++ 9 files changed, 29 insertions(+), 14 deletions(-) diff --git a/iscsi-scst/kernel/nthread.c b/iscsi-scst/kernel/nthread.c index 4c60d4b3c..1da2f808d 100644 --- a/iscsi-scst/kernel/nthread.c +++ b/iscsi-scst/kernel/nthread.c @@ -1687,8 +1687,10 @@ static int tx_padding(struct iscsi_cmnd *cmnd, int state) int res, rest = cmnd->conn->write_size; struct msghdr msg = {.msg_flags = MSG_NOSIGNAL | MSG_DONTWAIT}; struct kvec iov; - static const uint32_t padding; + static uint32_t padding; + BUG_ON(rest < 1); + BUG_ON(rest >= sizeof(uint32_t)); iscsi_extracheck_is_wr_thread(cmnd->conn); TRACE_DBG("Sending %d padding bytes (cmd %p)", rest, cmnd); diff --git a/iscsi-scst/usr/config.c b/iscsi-scst/usr/config.c index 8ac6fa731..ba2ed557e 100644 --- a/iscsi-scst/usr/config.c +++ b/iscsi-scst/usr/config.c @@ -41,9 +41,9 @@ * be the last to confirm expectations of __config_account_add()!! */ struct iscsi_key user_keys[] = { - {"IncomingUser",}, - {"OutgoingUser",}, - {NULL,}, + { .name = "IncomingUser",}, + { .name = "OutgoingUser",}, + { .name = NULL,}, }; static struct __qelem discovery_users_in = LIST_HEAD_INIT(discovery_users_in); diff --git a/iscsi-scst/usr/iscsid.c b/iscsi-scst/usr/iscsid.c index c0a58fa97..62f6a10bb 100644 --- a/iscsi-scst/usr/iscsid.c +++ b/iscsi-scst/usr/iscsid.c @@ -37,15 +37,15 @@ static u32 get_next_ttt(struct connection *conn __attribute__((unused))) } static struct iscsi_key login_keys[] = { - {"InitiatorName",}, - {"InitiatorAlias",}, - {"SessionType",}, - {"TargetName",}, - {"InitiatorRecvDataSegmentLength",}, - {"MaxAHSLength",}, - {"TaggedBufferForSolicitedDataOnly",}, - {"iSERHelloRequired",}, - {NULL,}, + { .name = "InitiatorName",}, + { .name = "InitiatorAlias",}, + { .name = "SessionType",}, + { .name = "TargetName",}, + { .name = "InitiatorRecvDataSegmentLength",}, + { .name = "MaxAHSLength",}, + { .name = "TaggedBufferForSolicitedDataOnly",}, + { .name = "iSERHelloRequired",}, + { .name = NULL,}, }; char *text_key_find(struct connection *conn, const char *searchKey) diff --git a/iscsi-scst/usr/misc.c b/iscsi-scst/usr/misc.c index c81ad40d2..465a1e094 100644 --- a/iscsi-scst/usr/misc.c +++ b/iscsi-scst/usr/misc.c @@ -25,7 +25,7 @@ #include "iscsid.h" -int driver_major(const char *dev) +static int driver_major(const char *dev) { FILE *f; char devname[256]; diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 8375281e0..3bf96a32b 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -2945,6 +2945,9 @@ static bool vdisk_parse_offset(struct vdisk_cmd_params *p, struct scst_cmd *cmd) TRACE(TRACE_ORDER, "HQ cmd %p (op %s)", cmd, scst_get_opcode_name(cmd)); break; + case SCST_CMD_QUEUE_ACA: + case SCST_CMD_QUEUE_SIMPLE: + case SCST_CMD_QUEUE_UNTAGGED: default: break; } diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 1c9c838bb..96764683d 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -5136,6 +5136,7 @@ int scst_tgt_dev_setup_threads(struct scst_tgt_dev *tgt_dev) tgtt->threads_num); break; } + case SCST_THREADS_POOL_TYPE_INVALID: default: PRINT_CRIT_ERROR("Unknown threads pool type %d (dev %s)", dev->threads_pool_type, dev->virt_name); @@ -9265,6 +9266,9 @@ static int scst_do_dif(struct scst_cmd *cmd, res = generate_fn(cmd); break; + case SCST_DIF_CHECK_APP_TAG: + case SCST_DIF_CHECK_GUARD_TAG: + case SCST_DIF_CHECK_REF_TAG: default: EXTRACHECKS_BUG_ON(1); /* go through */ diff --git a/scst/src/scst_proc.c b/scst/src/scst_proc.c index bf5d3637b..ed2803ec7 100644 --- a/scst/src/scst_proc.c +++ b/scst/src/scst_proc.c @@ -2512,6 +2512,7 @@ static int scst_groups_addr_method_show(struct seq_file *seq, void *v) case SCST_LUN_ADDR_METHOD_LUN: seq_printf(seq, "%s\n", "LUN"); break; + case SCST_LUN_ADDR_METHOD_EXTENDED_LUN: default: seq_printf(seq, "%s\n", "UNKNOWN"); break; diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 10cc62657..29db7baf7 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -906,6 +906,7 @@ active: scst_schedule_tasklet(cmd); break; + case SCST_CONTEXT_SAME: default: PRINT_ERROR("Context %x is undefined, using the thread one", pref_context); @@ -1904,6 +1905,7 @@ static void scst_process_redirect_cmd(struct scst_cmd *cmd, scst_schedule_tasklet(cmd); break; + case SCST_CONTEXT_SAME: default: PRINT_ERROR("Context %x is unknown, using the thread one", context); diff --git a/scst/src/scst_tg.c b/scst/src/scst_tg.c index a488230df..dce6122de 100644 --- a/scst/src/scst_tg.c +++ b/scst/src/scst_tg.c @@ -1757,6 +1757,9 @@ int scst_tg_set_group_info(struct scst_cmd *cmd) case SCST_TG_STATE_UNAVAILABLE: case SCST_TG_STATE_OFFLINE: break; + case SCST_TG_STATE_LBA_DEPENDENT: + case SCST_TG_STATE_TRANSITIONING: + case SCST_TG_STATE_UNDEFINED: default: TRACE_MGMT_DBG("Incorrect new state %d", osi[j].new_state); res = -EINVAL; From eaa99a8770f700ebca1206578663108c71300ee6 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Fri, 14 Apr 2017 01:03:25 +0000 Subject: [PATCH 17/22] Fix a few minor "extra" compiler warnings (mostly "const" issues) Add "XXX" comments in a few places about potential problems seen in SCST code, for future investigation and possible repair. Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7123 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/iscsi.c | 7 ++++++- iscsi-scst/kernel/nthread.c | 2 +- iscsi-scst/usr/chap.c | 5 +++++ iscsi-scst/usr/config.c | 2 +- scst/include/scst.h | 4 ++-- scst/src/dev_handlers/scst_vdisk.c | 9 ++++++--- scst/src/scst_lib.c | 14 +++++++------- scst/src/scst_targ.c | 8 ++++++-- usr/fileio/common.h | 2 +- 9 files changed, 35 insertions(+), 18 deletions(-) diff --git a/iscsi-scst/kernel/iscsi.c b/iscsi-scst/kernel/iscsi.c index d20799446..1a5ac0991 100644 --- a/iscsi-scst/kernel/iscsi.c +++ b/iscsi-scst/kernel/iscsi.c @@ -509,6 +509,11 @@ void cmnd_done(struct iscsi_cmnd *cmnd) if (cmnd->sg != &dummy_sg) scst_free_sg(cmnd->sg, cmnd->sg_cnt); #ifdef CONFIG_SCST_DEBUG + /* + * We can make correct behavior depend on this, so + * a bug can disappear whenever you enable debugging, + * but probability of failure on zero/NULL is much bigger + */ cmnd->own_sg = 0; cmnd->sg = NULL; cmnd->sg_cnt = -1; @@ -2911,7 +2916,7 @@ out: return; } -static void set_cork(struct socket *sock, int on) +static inline void set_cork(struct socket *sock, int on) { int opt = on; mm_segment_t oldfs; diff --git a/iscsi-scst/kernel/nthread.c b/iscsi-scst/kernel/nthread.c index 1da2f808d..b61540f7c 100644 --- a/iscsi-scst/kernel/nthread.c +++ b/iscsi-scst/kernel/nthread.c @@ -1687,7 +1687,7 @@ static int tx_padding(struct iscsi_cmnd *cmnd, int state) int res, rest = cmnd->conn->write_size; struct msghdr msg = {.msg_flags = MSG_NOSIGNAL | MSG_DONTWAIT}; struct kvec iov; - static uint32_t padding; + static const uint32_t padding; BUG_ON(rest < 1); BUG_ON(rest >= sizeof(uint32_t)); diff --git a/iscsi-scst/usr/chap.c b/iscsi-scst/usr/chap.c index dfefae1ac..7b70fbd5c 100644 --- a/iscsi-scst/usr/chap.c +++ b/iscsi-scst/usr/chap.c @@ -105,6 +105,9 @@ static u8 decode_base64_digit(char base64) else if ((base64 >= '0') && (base64 <= '9')) return 52 + (base64 - '0'); else + //XXX This return value should be unsigned; and anyway + //XXX in case of a bad character in the string, our + //XXX caller (sometimes) checks for 65, not 255 or -1 return -1; } } @@ -146,6 +149,8 @@ static void decode_base64_string(char *string, u8 *intnum, int int_len) num[1] = decode_base64_digit(string[count + 1]); num[2] = decode_base64_digit(string[count + 2]); num[3] = decode_base64_digit(string[count + 3]); + //XXX Check for the special "bad character in string" value here like above? + //XXX Also check the string for missing/incorrect padding? if ((num[0] == 64) || (num[1] == 64)) return; if (num[2] == 64) { diff --git a/iscsi-scst/usr/config.c b/iscsi-scst/usr/config.c index ba2ed557e..58469020c 100644 --- a/iscsi-scst/usr/config.c +++ b/iscsi-scst/usr/config.c @@ -1144,7 +1144,7 @@ int config_load(const char *config_name) err = config_isns_load(buf); if ((err == 0) && (isns_server != NULL)) { - int rc = isns_init(); + rc = isns_init(); if (rc != 0) { log_error("iSNS server %s init failed: %d", isns_server, rc); diff --git a/scst/include/scst.h b/scst/include/scst.h index d861d2906..e6c31828a 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -4081,8 +4081,8 @@ static inline enum scst_exec_context __scst_estimate_context(bool atomic) else if (in_atomic()) return SCST_CONTEXT_DIRECT_ATOMIC; else - return atomic ? SCST_CONTEXT_DIRECT : - SCST_CONTEXT_DIRECT_ATOMIC; + return atomic ? SCST_CONTEXT_DIRECT_ATOMIC : + SCST_CONTEXT_DIRECT; #else return SCST_CONTEXT_THREAD; #endif diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 3bf96a32b..41d93781e 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -83,7 +83,7 @@ static struct scst_trace_log vdisk_local_trace_tbl[] = { #define SCST_FIO_VENDOR "SCST_FIO" #define SCST_BIO_VENDOR "SCST_BIO" /* 4 byte ASCII Product Revision Level - left aligned */ -#define SCST_FIO_REV " 330" +#define SCST_FIO_REV "330 " #define MAX_USN_LEN (20+1) /* For '\0' */ #define MAX_INQ_VEND_SPECIFIC_LEN (INQ_BUF_SZ - 96) @@ -2081,8 +2081,11 @@ static int vdisk_format_dif(struct scst_cmd *cmd, uint64_t start_lba, goto out_set_fs; } else if (err < full_len) { /* - * Probably that's wrong, but sometimes write() returns - * value less, than requested. Let's restart. + * If a write() is interrupted by a signal handler before + * any bytes are written, then the call fails with the + * error EINTR; if it is interrupted after at least one + * byte has been written, the call succeeds, and returns + * the number of bytes written -- manpage write(2) */ left += full_len - err; done -= full_len - err; diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 96764683d..36456f224 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -11695,15 +11695,15 @@ uint64_t scst_unpack_lun(const uint8_t *lun, int len) case 2: break; case 8: - if ((*((__be64 *)lun) & cpu_to_be64(0x0000FFFFFFFFFFFFLL)) != 0) + if ((*((__be64 const *)lun) & cpu_to_be64(0x0000FFFFFFFFFFFFLL)) != 0) goto out_err; break; case 4: - if (*((__be16 *)&lun[2]) != 0) + if (*((__be16 const *)&lun[2]) != 0) goto out_err; break; case 6: - if (*((__be32 *)&lun[2]) != 0) + if (*((__be32 const *)&lun[2]) != 0) goto out_err; break; case 1: @@ -13870,10 +13870,10 @@ EXPORT_SYMBOL(scst_reassign_retained_sess_states); char *scst_get_next_lexem(char **token_str) { char *p, *q; - static const char blank = '\0'; + static char blank = '\0'; if ((token_str == NULL) || (*token_str == NULL)) - return (char *)␣ + return ␣ for (p = *token_str; (*p != '\0') && (isspace(*p) || (*p == '=')); p++) ; @@ -14874,7 +14874,7 @@ int scst_write_file_transactional(const char *name, const char *name1, pos = signature_len+1; - res = vfs_write(file, (void __force __user *)buf, size, &pos); + res = vfs_write(file, (void const __force __user *)buf, size, &pos); if (res != size) goto write_error; @@ -14885,7 +14885,7 @@ int scst_write_file_transactional(const char *name, const char *name1, } pos = 0; - res = vfs_write(file, (void __force __user *)signature, signature_len, &pos); + res = vfs_write(file, (void const __force __user *)signature, signature_len, &pos); if (res != signature_len) goto write_error; diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 29db7baf7..5ed8ead11 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -1552,9 +1552,13 @@ static int scst_prepare_space(struct scst_cmd *cmd) goto alloc; else if (r == 0) { if (unlikely(cmd->bufflen == 0)) { - /* See comment in scst_alloc_space() */ - if (cmd->sg == NULL) + if (cmd->sg == NULL) { + /* + * Let's still have a buffer for uniformity, + * scst_alloc_space() will handle bufflen 0 + */ goto alloc; + } } cmd->tgt_i_data_buf_alloced = 1; diff --git a/usr/fileio/common.h b/usr/fileio/common.h index 7c1bf6239..943da91b7 100644 --- a/usr/fileio/common.h +++ b/usr/fileio/common.h @@ -30,7 +30,7 @@ /* 8 byte ASCII Vendor */ #define VENDOR "SCST_USR" /* 4 byte ASCII Product Revision Level - left aligned */ -#define FIO_REV " 330" +#define FIO_REV "330 " #define MAX_USN_LEN (20+1) /* For '\0' */ From 68129122e8b8f8638efbec1903306079f8416f1e Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Fri, 14 Apr 2017 01:16:10 +0000 Subject: [PATCH 18/22] iscsi-scst: clean up the conftest subdirectory too Reported-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7124 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/Makefile | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/iscsi-scst/Makefile b/iscsi-scst/Makefile index 3ff356e99..85a1bc4ff 100644 --- a/iscsi-scst/Makefile +++ b/iscsi-scst/Makefile @@ -227,18 +227,14 @@ clean: kernel/isert-scst/Modules.symvers kernel/isert-scst/Module.symvers \ kernel/isert-scst/Module.markers kernel/isert-scst/modules.order \ include/iscsi_scst_itf_ver.h + rm -rf conftest/*/*.ko conftest/*/*.mod.c conftest/*/Module.symvers conftest/*/*.o \ + conftest/*/*.o.cmd conftest/*/*.ko.cmd conftest/*/.*.o.cmd conftest/*/.*.ko.cmd \ + conftest/*/*.order conftest/*/.*.o.d conftest/*/.tmp_versions/ -extraclean: - $(MAKE) -C usr $@ - $(MAKE) -C $(KDIR) SUBDIRS=$(KMOD) clean - $(MAKE) -C $(KDIR) SUBDIRS=$(ISERTMOD) clean - rm -f kernel/Modules.symvers kernel/Module.symvers \ - kernel/Module.markers kernel/modules.order \ - kernel/isert-scst/Modules.symvers kernel/isert-scst/Module.symvers \ - kernel/isert-scst/Module.markers kernel/isert-scst/modules.order \ - include/iscsi_scst_itf_ver.h \ - kernel/*.orig kernel/*.rej \ +extraclean: clean + rm -f kernel/*.orig kernel/*.rej \ kernel/isert-scst/*.orig kernel/isert-scst/*.rej + rm -rf conftest/*/*.rej conftest/*/*.orig 2release: sed -i.aa s/"^E\?XTRA_CFLAGS += \-DCONFIG_SCST_EXTRACHECKS"/"#EXTRA_CFLAGS += \-DCONFIG_SCST_EXTRACHECKS"/ $(KMOD)/Makefile From c98eb43f55b24cd20217deb80869a07a77715c22 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Fri, 14 Apr 2017 01:17:45 +0000 Subject: [PATCH 19/22] extraclean does "rm tags cscope.out" Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7125 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 174180907..f6365b839 100644 --- a/Makefile +++ b/Makefile @@ -196,7 +196,7 @@ clean: @if [ -d $(EMULEX_DIR) ]; then cd $(EMULEX_DIR) && $(MAKE) $@; fi extraclean: - -rm -f TAGS + -rm -f TAGS tags cscope.out cd $(SCST_DIR) && $(MAKE) $@ @if [ -d $(DOC_DIR) ]; then cd $(DOC_DIR) && $(MAKE) $@; fi @if [ -d $(QLA_INI_DIR) ]; then cd $(QLA_INI_DIR) && $(MAKE) $@; fi From 57ee5e39ab501965994e097922bd4de5364eb5c9 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Fri, 14 Apr 2017 01:19:06 +0000 Subject: [PATCH 20/22] backport ACCESS_ONCE() before 2.6.26 Signed-off-by: David Butterfield git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7126 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scst/include/backport.h b/scst/include/backport.h index ea40cea6d..d3f041307 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -76,6 +76,11 @@ static inline unsigned int queue_max_hw_sectors(struct request_queue *q) * 230fa253df6352af12ad0a16128760b5cb3f92df). */ #define READ_ONCE(x) (*(volatile typeof(x) *)&(x)) + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26) +#define ACCESS_ONCE(x) READ_ONCE(x) +#endif + #endif /* */ From 4f6fc459c03d5c960e1fe873533544e685ad4933 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 14 Apr 2017 04:21:38 +0000 Subject: [PATCH 21/22] ib_srpt: Optimize Makefile Cache conftest results and enable parallel invocation of conftests. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7127 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- srpt/Makefile | 171 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 115 insertions(+), 56 deletions(-) diff --git a/srpt/Makefile b/srpt/Makefile index e0d819eb4..0078ee610 100644 --- a/srpt/Makefile +++ b/srpt/Makefile @@ -1,6 +1,7 @@ # # Makefile for ib_srpt.ko. # + ifndef PREFIX PREFIX=/usr/local endif @@ -86,55 +87,30 @@ endif OFED_MODULE_SYMVERS:=$(OFED_KERNEL_DIR)/$(MODULE_SYMVERS) endif -GOALS:=$(if $(MAKECMDGOALS),$(MAKECMDGOALS),all) -OTHER_GOALS:=$(foreach goal,$(MAKECMDGOALS),$(subst all,,$(goal))) -# echo:=$(shell echo 'GOALS = $(GOALS)' >&2) -# echo:=$(shell echo 'OTHER_GOALS = $(OTHER_GOALS)' >&2) -ifneq ("$(GOALS)","$(OTHER_GOALS)") -run_conftest = $(shell if [ "0$(V)" -gt 0 ]; then output=/dev/stdout; else output=/dev/null; fi; if $(MAKE) -C $(KDIR) V=$(V) SUBDIRS="$(shell pwd)/conftest/$1" PRE_CFLAGS="-Werror $(OFED_CFLAGS)" 1>&2 2>$${output}; then echo "$2"; else echo "$3"; fi) -USE_PRE_440_WR_STRUCTURE := $(call run_conftest,use_pre_440_wr_structure,-DUSE_PRE_440_WR_STRUCTURE) -CREATE_CQ_FLAG := $(call run_conftest,create_cq,-DIB_CREATE_CQ_HAS_INIT_ATTR) -CREATE_SEND_MAD_AH_FLAG := $(call run_conftest,create_send_mad_ah,-DCREATE_SEND_MAD_HAS_AH_ARG) -ifeq ($(CREATE_SEND_MAD_AH_FLAG),) - CREATE_SEND_MAD_BASE_FLAG := $(call run_conftest,create_send_mad_base,-DCREATE_SEND_MAD_HAS_BASE_ARG) -endif -CLIENT_REMOVE := $(call run_conftest,ib_client_remove,-DIB_CLIENT_REMOVE_TAKES_TWO_ARGS) -CM_LISTEN := $(call run_conftest,cm_listen,-DIB_CM_LISTEN_TAKES_FOURTH_ARG) -MAD_HANDLER_TAKES_SEND_BUF := $(call run_conftest,mad_handler_takes_send_buf,-DMAD_HANDLER_TAKES_SEND_BUF) -HAVE_IB_DMA_MAP_OPS := $(call run_conftest,ib_dma_map_ops,-DHAVE_IB_DMA_MAP_OPS) -HAVE_IB_SET_CPI_RESP_TIME := $(call run_conftest,ib_set_cpi_resp_time,-DHAVE_IB_SET_CPI_RESP_TIME) -GID_CHANGE_FLAG := $(call run_conftest,gid_change,-DHAVE_IB_EVENT_GID_CHANGE) -PD_HAS_LOCAL_DMA_LKEY := $(call run_conftest,pd_has_local_dma_lkey,-DIB_PD_HAS_LOCAL_DMA_LKEY) -RDMA_CREATE_ID := $(call run_conftest,rdma_create_id_net,-DRDMA_CREATE_ID_TAKES_NET_ARG=1,-DRDMA_CREATE_ID_TAKES_NET_ARG=0) -REGISTER_MAD_AGENT_FLAG := $(call run_conftest,register_mad_agent,-DREGISTER_MAD_AGENT_HAS_FLAGS_ARG) -QUERY_DEVICE := $(call run_conftest,query_device,-DHAVE_IB_QUERY_DEVICE) -QUERY_DEVICE_HAS_ATTR_ARG := $(call run_conftest,query_device_attr_arg,-DIB_QUERY_DEVICE_HAS_ATTR_ARG) -QUERY_GID_FLAG := $(call run_conftest,query_gid,-DIB_QUERY_GID_HAS_ATTR_ARG) -PRE_CFLAGS=$(OFED_CFLAGS) \ - $(USE_PRE_440_WR_STRUCTURE) \ - $(CLIENT_REMOVE) \ - $(CREATE_CQ_FLAG) \ - $(CREATE_SEND_MAD_AH_FLAG) \ - $(CREATE_SEND_MAD_BASE_FLAG) \ - $(IB_CLIENT_REMOVE_TAKES_TWO_ARGS) \ - $(CM_LISTEN) \ - $(MAD_HANDLER_TAKES_SEND_BUF) \ - $(HAVE_IB_DMA_MAP_OPS) \ - $(HAVE_IB_SET_CPI_RESP_TIME) \ - $(GID_CHANGE_FLAG) \ - $(PD_HAS_LOCAL_DMA_LKEY) \ - $(RDMA_CREATE_ID) \ - $(REGISTER_MAD_AGENT_FLAG) \ - $(QUERY_GID_FLAG) \ - $(QUERY_DEVICE) \ - $(QUERY_DEVICE_HAS_ATTR_ARG) \ - -DOFED_FLAVOR=$(OFED_FLAVOR) -endif +run_conftest = $(shell if [ "0$(V)" -gt 0 ]; then output=/dev/stdout; else output=/dev/null; fi; if $(MAKE) -C $(KDIR) V=$(V) SUBDIRS="$(shell pwd)/conftest/$1" PRE_CFLAGS="-Werror $(OFED_CFLAGS)" 1>&2 2>$${output}; then echo "$(strip $2)"; else echo "$(strip $3)"; fi) +run_conftest_bool = $(call run_conftest,$1,-D$(strip $2)=1,-D$(strip $2)=0) -all: src/$(MODULE_SYMVERS) +CONFTESTS = $(shell ls -d conftest/*) +CONFTEST_OUTPUTS = $(shell \ + for t in $(CONFTESTS); do \ + echo $$t/result-$(KVER).txt; \ + done) + +PRE_CFLAGS = $(OFED_CFLAGS) \ + -DOFED_FLAVOR=$(OFED_FLAVOR) \ + $(shell for t in $(CONFTESTS); do \ + cat $$t/result-$(KVER).txt 2>/dev/null; \ + done) + +all: check src/$(MODULE_SYMVERS) $(CONFTEST_OUTPUTS) $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/src \ PRE_CFLAGS="$(PRE_CFLAGS)" SCST_INC_DIR=$(SCST_INC_DIR) modules +src/$(MODULE_SYMVERS): $(SCST_SYMVERS_DIR)/$(MODULE_SYMVERS) \ + $(OFED_MODULE_SYMVERS) + cat $^ | \ + awk '{sym[$$2]=$$0} END {for (s in sym){print sym[s]}}' >"$@" + install: all @[ -z "$(DESTDIR)$(INSTALL_MOD_PATH)" ] && \ find /lib/modules/$(KVER) -name ib_srpt.ko -exec rm {} \; ; \ @@ -148,8 +124,7 @@ uninstall: rm -f $(INSTALL_DIR)/ib_srpt.ko -/sbin/depmod -b $(INSTALL_MOD_PATH)/ -a $(KVER) -src/$(MODULE_SYMVERS): $(SCST_SYMVERS_DIR)/$(MODULE_SYMVERS) \ - $(OFED_MODULE_SYMVERS) +check: @if [ -n "$(OFED_KERNEL_IB_RPM)" ]; then \ if [ -z "$(OFED_KERNEL_IB_DEVEL_RPM)" ]; then \ echo "Error: the OFED package $(OFED_KERNEL_IB_RPM)-devel has" \ @@ -158,14 +133,6 @@ src/$(MODULE_SYMVERS): $(SCST_SYMVERS_DIR)/$(MODULE_SYMVERS) \ else \ echo " Building against $(OFED_FLAVOR) $(OFED_KERNEL_IB_RPM)" \ "InfiniBand kernel headers."; \ - ( \ - cat $(SCST_SYMVERS_DIR)/$(MODULE_SYMVERS) | \ - grep -v 'drivers/infiniband/' | \ - grep -v 'net/sunrpc/xprtrdma/' | \ - grep -v 'net/rds/' | \ - grep -v 'extra/ib_srpt'; \ - cat $(OFED_MODULE_SYMVERS) \ - ) >$@; \ fi \ else \ if [ -n "$(OFED_KERNEL_IB_DEVEL_RPM)" ]; then \ @@ -174,7 +141,6 @@ src/$(MODULE_SYMVERS): $(SCST_SYMVERS_DIR)/$(MODULE_SYMVERS) \ false; \ else \ echo " Building against in-tree InfiniBand kernel headers."; \ - cp $< $@; \ fi; \ fi @@ -182,12 +148,105 @@ clean: rm -rf conftest/pre_cflags conftest/kcflags for d in conftest/* src; do \ [ -d "$$d" ] && $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/$$d clean; \ + rm -f $$d/result*.txt; \ done rm -f src/$(MODULE_SYMVERS) src/Module.markers src/modules.order extraclean: clean rm -f *.orig *.rej +conftest/cm_listen/result-$(KVER).txt: \ + conftest/cm_listen/cm_listen.c \ + conftest/cm_listen/Makefile + echo "$(call run_conftest,cm_listen, \ + -DIB_CM_LISTEN_TAKES_FOURTH_ARG)" >"$@" + +conftest/create_cq/result-$(KVER).txt: \ + conftest/create_cq/create_cq.c \ + conftest/create_cq/Makefile + echo "$(call run_conftest,create_cq, \ + -DIB_CREATE_CQ_HAS_INIT_ATTR)" >"$@" + +conftest/create_send_mad_ah/result-$(KVER).txt: \ + conftest/create_send_mad_ah/create_send_mad_ah.c \ + conftest/create_send_mad_ah/Makefile + echo "$(call run_conftest,create_send_mad_ah, \ + -DCREATE_SEND_MAD_HAS_AH_ARG)" >"$@" + +conftest/create_send_mad_base/result-$(KVER).txt: \ + conftest/create_send_mad_base/create_send_mad_base.c \ + conftest/create_send_mad_base/Makefile + echo "$(call run_conftest,create_send_mad_base, \ + -DCREATE_SEND_MAD_HAS_BASE_ARG)" >"$@" + +conftest/gid_change/result-$(KVER).txt: \ + conftest/gid_change/gid_change.c \ + conftest/gid_change/Makefile + echo "$(call run_conftest,gid_change,-DHAVE_IB_EVENT_GID_CHANGE)" >"$@" + +conftest/ib_client_remove/result-$(KVER).txt: \ + conftest/ib_client_remove/ib_client_remove.c \ + conftest/ib_client_remove/Makefile + echo "$(call run_conftest,ib_client_remove, \ + -DIB_CLIENT_REMOVE_TAKES_TWO_ARGS)" >"$@" + +conftest/ib_dma_map_ops/result-$(KVER).txt: \ + conftest/ib_dma_map_ops/ib_dma_map_ops.c \ + conftest/ib_dma_map_ops/Makefile + echo "$(call run_conftest,ib_dma_map_ops,-DHAVE_IB_DMA_MAP_OPS)" >"$@" + +conftest/ib_set_cpi_resp_time/result-$(KVER).txt: \ + conftest/ib_set_cpi_resp_time/ib_set_cpi_resp_time.c \ + conftest/ib_set_cpi_resp_time/Makefile + echo "$(call run_conftest,ib_set_cpi_resp_time, \ + -DHAVE_IB_SET_CPI_RESP_TIME)" >"$@" + +conftest/mad_handler_takes_send_buf/result-$(KVER).txt: \ + conftest/mad_handler_takes_send_buf/mad_handler_takes_send_buf.c\ + conftest/mad_handler_takes_send_buf/Makefile + echo "$(call run_conftest,mad_handler_takes_send_buf, \ + -DMAD_HANDLER_TAKES_SEND_BUF)" >"$@" + +conftest/pd_has_local_dma_lkey/result-$(KVER).txt: \ + conftest/pd_has_local_dma_lkey/pd_has_local_dma_lkey.c \ + conftest/pd_has_local_dma_lkey/Makefile + echo "$(call run_conftest,pd_has_local_dma_lkey, \ + -DIB_PD_HAS_LOCAL_DMA_LKEY)" >"$@" + +conftest/query_device/result-$(KVER).txt: \ + conftest/query_device/query_device.c \ + conftest/query_device/Makefile + echo "$(call run_conftest,query_device,-DHAVE_IB_QUERY_DEVICE)" >"$@" + +conftest/query_device_attr_arg/result-$(KVER).txt: \ + conftest/query_device_attr_arg/query_device_attr_arg.c \ + conftest/query_device_attr_arg/Makefile + echo "$(call run_conftest,query_device_attr_arg, \ + -DIB_QUERY_DEVICE_HAS_ATTR_ARG)" >"$@" + +conftest/query_gid/result-$(KVER).txt: \ + conftest/query_gid/query_gid.c \ + conftest/query_gid/Makefile + echo "$(call run_conftest,query_gid,-DIB_QUERY_GID_HAS_ATTR_ARG)" >"$@" + +conftest/rdma_create_id_net/result-$(KVER).txt: \ + conftest/rdma_create_id_net/rdma_create_id_net.c \ + conftest/rdma_create_id_net/Makefile + echo "$(call run_conftest_bool,rdma_create_id_net, \ + RDMA_CREATE_ID_TAKES_NET_ARG)" >"$@" + +conftest/register_mad_agent/result-$(KVER).txt: \ + conftest/register_mad_agent/register_mad_agent.c \ + conftest/register_mad_agent/Makefile + echo "$(call run_conftest,register_mad_agent, \ + -DREGISTER_MAD_AGENT_HAS_FLAGS_ARG)" >"$@" + +conftest/use_pre_440_wr_structure/result-$(KVER).txt: \ + conftest/use_pre_440_wr_structure/use_pre_440_wr_structure.c \ + conftest/use_pre_440_wr_structure/Makefile + echo "$(call run_conftest,use_pre_440_wr_structure, \ + -DUSE_PRE_440_WR_STRUCTURE)" >"$@" + 2debug: -$(MAKE) clean $(call set_var,build_mode,BUILDMODE,) From 3685688caa57a80c6e8603d09b225abe1887533a Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Fri, 14 Apr 2017 04:29:38 +0000 Subject: [PATCH 22/22] iscsi-scst/Makefile: Optimize Makefile Cache conftest results and enable parallel invocation of conftests. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7128 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/Makefile | 144 +++++++++++++++++++++++++++++++++----------- 1 file changed, 110 insertions(+), 34 deletions(-) diff --git a/iscsi-scst/Makefile b/iscsi-scst/Makefile index 85a1bc4ff..5a83d7516 100644 --- a/iscsi-scst/Makefile +++ b/iscsi-scst/Makefile @@ -114,40 +114,23 @@ else endif endif -GOALS:=$(if $(MAKECMDGOALS),$(MAKECMDGOALS),all) -OTHER_GOALS:=$(foreach goal,$(MAKECMDGOALS),$(subst all,,$(goal))) -# echo:=$(shell echo 'GOALS = $(GOALS)' >&2) -# echo:=$(shell echo 'OTHER_GOALS = $(OTHER_GOALS)' >&2) -ifneq ("$(GOALS)","$(OTHER_GOALS)") -run_conftest = $(shell if [ "0$(V)" -gt 0 ]; then output=/dev/stdout; else output=/dev/null; fi; if $(MAKE) -C $(KDIR) V=$(V) SUBDIRS="$(shell pwd)/conftest/$1" PRE_CFLAGS="-Werror $(OFED_CFLAGS)" 1>&2 2>$${output}; then echo "$2"; else echo "$3"; fi) -USE_PRE_440_WR_STRUCTURE := $(call run_conftest,use_pre_440_wr_structure,-DUSE_PRE_440_WR_STRUCTURE) -CREATE_CQ_FLAG := $(call run_conftest,create_cq,-DIB_CREATE_CQ_HAS_INIT_ATTR) -CLIENT_REMOVE := $(call run_conftest,ib_client_remove,-DIB_CLIENT_REMOVE_TAKES_TWO_ARGS) -HAVE_IB_DMA_MAP_OPS := $(call run_conftest,ib_dma_map_ops,-DHAVE_IB_DMA_MAP_OPS) -HAVE_IB_SET_CPI_RESP_TIME := $(call run_conftest,ib_set_cpi_resp_time,-DHAVE_IB_SET_CPI_RESP_TIME) -GID_CHANGE_FLAG := $(call run_conftest,gid_change,-DHAVE_IB_EVENT_GID_CHANGE) -PD_HAS_LOCAL_DMA_LKEY := $(call run_conftest,pd_has_local_dma_lkey,-DIB_PD_HAS_LOCAL_DMA_LKEY) -RDMA_CREATE_ID := $(call run_conftest,rdma_create_id_net,-DRDMA_CREATE_ID_TAKES_NET_ARG=1,-DRDMA_CREATE_ID_TAKES_NET_ARG=0) -QUERY_DEVICE := $(call run_conftest,query_device,-DHAVE_IB_QUERY_DEVICE) -QUERY_DEVICE_HAS_ATTR_ARG := $(call run_conftest,query_device_attr_arg,-DIB_QUERY_DEVICE_HAS_ATTR_ARG) -QUERY_GID_FLAG := $(call run_conftest,query_gid,-DIB_QUERY_GID_HAS_ATTR_ARG) -PRE_CFLAGS=$(OFED_CFLAGS) \ - $(USE_PRE_440_WR_STRUCTURE) \ - $(CLIENT_REMOVE) \ - $(CREATE_CQ_FLAG) \ - $(IB_CLIENT_REMOVE_TAKES_TWO_ARGS) \ - $(HAVE_IB_DMA_MAP_OPS) \ - $(HAVE_IB_SET_CPI_RESP_TIME) \ - $(GID_CHANGE_FLAG) \ - $(PD_HAS_LOCAL_DMA_LKEY) \ - $(RDMA_CREATE_ID) \ - $(QUERY_GID_FLAG) \ - $(QUERY_DEVICE) \ - $(QUERY_DEVICE_HAS_ATTR_ARG) \ - -DOFED_FLAVOR=$(OFED_FLAVOR) -endif +run_conftest = $(shell if [ "0$(V)" -gt 0 ]; then output=/dev/stdout; else output=/dev/null; fi; if $(MAKE) -C $(KDIR) V=$(V) SUBDIRS="$(shell pwd)/conftest/$1" PRE_CFLAGS="-Werror $(OFED_CFLAGS)" 1>&2 2>$${output}; then echo "$(strip $2)"; else echo "$(strip $3)"; fi) +run_conftest_bool = $(call run_conftest,$1,-D$(strip $2)=1,-D$(strip $2)=0) -mods: include/iscsi_scst_itf_ver.h Modules.symvers Module.symvers +CONFTESTS = $(shell ls -d conftest/*) +CONFTEST_OUTPUTS = $(shell \ + for t in $(CONFTESTS); do \ + echo $$t/result-$(KVER).txt; \ + done) + +PRE_CFLAGS = $(OFED_CFLAGS) \ + -DOFED_FLAVOR=$(OFED_FLAVOR) \ + $(shell for t in $(CONFTESTS); do \ + cat $$t/result-$(KVER).txt 2>/dev/null; \ + done) + +mods: include/iscsi_scst_itf_ver.h Modules.symvers Module.symvers \ + $(CONFTEST_OUTPUTS) $(MAKE) -C $(KDIR) SCST_INC_DIR=$(SCST_INC_DIR) SUBDIRS=$(KMOD) modules echo "$@: INFINIBAND_ENABLED = $(INFINIBAND_ENABLED)" if $(INFINIBAND_ENABLED); then \ @@ -229,13 +212,106 @@ clean: include/iscsi_scst_itf_ver.h rm -rf conftest/*/*.ko conftest/*/*.mod.c conftest/*/Module.symvers conftest/*/*.o \ conftest/*/*.o.cmd conftest/*/*.ko.cmd conftest/*/.*.o.cmd conftest/*/.*.ko.cmd \ - conftest/*/*.order conftest/*/.*.o.d conftest/*/.tmp_versions/ + conftest/*/*.order conftest/*/.*.o.d conftest/*/.tmp_versions/ \ + conftest/*/result*.txt extraclean: clean rm -f kernel/*.orig kernel/*.rej \ kernel/isert-scst/*.orig kernel/isert-scst/*.rej rm -rf conftest/*/*.rej conftest/*/*.orig +conftest/cm_listen/result-$(KVER).txt: \ + conftest/cm_listen/cm_listen.c \ + conftest/cm_listen/Makefile + echo "$(call run_conftest,cm_listen, \ + -DIB_CM_LISTEN_TAKES_FOURTH_ARG)" >"$@" + +conftest/create_cq/result-$(KVER).txt: \ + conftest/create_cq/create_cq.c \ + conftest/create_cq/Makefile + echo "$(call run_conftest,create_cq, \ + -DIB_CREATE_CQ_HAS_INIT_ATTR)" >"$@" + +conftest/create_send_mad_ah/result-$(KVER).txt: \ + conftest/create_send_mad_ah/create_send_mad_ah.c \ + conftest/create_send_mad_ah/Makefile + echo "$(call run_conftest,create_send_mad_ah, \ + -DCREATE_SEND_MAD_HAS_AH_ARG)" >"$@" + +conftest/create_send_mad_base/result-$(KVER).txt: \ + conftest/create_send_mad_base/create_send_mad_base.c \ + conftest/create_send_mad_base/Makefile + echo "$(call run_conftest,create_send_mad_base, \ + -DCREATE_SEND_MAD_HAS_BASE_ARG)" >"$@" + +conftest/gid_change/result-$(KVER).txt: \ + conftest/gid_change/gid_change.c \ + conftest/gid_change/Makefile + echo "$(call run_conftest,gid_change,-DHAVE_IB_EVENT_GID_CHANGE)" >"$@" + +conftest/ib_client_remove/result-$(KVER).txt: \ + conftest/ib_client_remove/ib_client_remove.c \ + conftest/ib_client_remove/Makefile + echo "$(call run_conftest,ib_client_remove, \ + -DIB_CLIENT_REMOVE_TAKES_TWO_ARGS)" >"$@" + +conftest/ib_dma_map_ops/result-$(KVER).txt: \ + conftest/ib_dma_map_ops/ib_dma_map_ops.c \ + conftest/ib_dma_map_ops/Makefile + echo "$(call run_conftest,ib_dma_map_ops,-DHAVE_IB_DMA_MAP_OPS)" >"$@" + +conftest/ib_set_cpi_resp_time/result-$(KVER).txt: \ + conftest/ib_set_cpi_resp_time/ib_set_cpi_resp_time.c \ + conftest/ib_set_cpi_resp_time/Makefile + echo "$(call run_conftest,ib_set_cpi_resp_time, \ + -DHAVE_IB_SET_CPI_RESP_TIME)" >"$@" + +conftest/mad_handler_takes_send_buf/result-$(KVER).txt: \ + conftest/mad_handler_takes_send_buf/mad_handler_takes_send_buf.c\ + conftest/mad_handler_takes_send_buf/Makefile + echo "$(call run_conftest,mad_handler_takes_send_buf, \ + -DMAD_HANDLER_TAKES_SEND_BUF)" >"$@" + +conftest/pd_has_local_dma_lkey/result-$(KVER).txt: \ + conftest/pd_has_local_dma_lkey/pd_has_local_dma_lkey.c \ + conftest/pd_has_local_dma_lkey/Makefile + echo "$(call run_conftest,pd_has_local_dma_lkey, \ + -DIB_PD_HAS_LOCAL_DMA_LKEY)" >"$@" + +conftest/query_device/result-$(KVER).txt: \ + conftest/query_device/query_device.c \ + conftest/query_device/Makefile + echo "$(call run_conftest,query_device,-DHAVE_IB_QUERY_DEVICE)" >"$@" + +conftest/query_device_attr_arg/result-$(KVER).txt: \ + conftest/query_device_attr_arg/query_device_attr_arg.c \ + conftest/query_device_attr_arg/Makefile + echo "$(call run_conftest,query_device_attr_arg, \ + -DIB_QUERY_DEVICE_HAS_ATTR_ARG)" >"$@" + +conftest/query_gid/result-$(KVER).txt: \ + conftest/query_gid/query_gid.c \ + conftest/query_gid/Makefile + echo "$(call run_conftest,query_gid,-DIB_QUERY_GID_HAS_ATTR_ARG)" >"$@" + +conftest/rdma_create_id_net/result-$(KVER).txt: \ + conftest/rdma_create_id_net/rdma_create_id_net.c \ + conftest/rdma_create_id_net/Makefile + echo "$(call run_conftest_bool,rdma_create_id_net, \ + RDMA_CREATE_ID_TAKES_NET_ARG)" >"$@" + +conftest/register_mad_agent/result-$(KVER).txt: \ + conftest/register_mad_agent/register_mad_agent.c \ + conftest/register_mad_agent/Makefile + echo "$(call run_conftest,register_mad_agent, \ + -DREGISTER_MAD_AGENT_HAS_FLAGS_ARG)" >"$@" + +conftest/use_pre_440_wr_structure/result-$(KVER).txt: \ + conftest/use_pre_440_wr_structure/use_pre_440_wr_structure.c \ + conftest/use_pre_440_wr_structure/Makefile + echo "$(call run_conftest,use_pre_440_wr_structure, \ + -DUSE_PRE_440_WR_STRUCTURE)" >"$@" + 2release: sed -i.aa s/"^E\?XTRA_CFLAGS += \-DCONFIG_SCST_EXTRACHECKS"/"#EXTRA_CFLAGS += \-DCONFIG_SCST_EXTRACHECKS"/ $(KMOD)/Makefile grep "^#EXTRA_CFLAGS += \-DCONFIG_SCST_EXTRACHECKS" $(KMOD)/Makefile >/dev/null