From 7c3b2c4ca67f45a183c7a5bf3ad1a209b9c1e1fe Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 15:53:31 +0000 Subject: [PATCH 01/72] iscsi-scst: Fix spelling in a source code comment git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6321 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/nthread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iscsi-scst/kernel/nthread.c b/iscsi-scst/kernel/nthread.c index e89d4d405..5e0cbeffe 100644 --- a/iscsi-scst/kernel/nthread.c +++ b/iscsi-scst/kernel/nthread.c @@ -739,7 +739,7 @@ restart: if (res > 0) { /* * To save CPU cycles we suppose that sock_recvmsg() adjusts - * msg->msg_iov and msg->msg_iovlen. The BUG_ON() statements + * msg->msg_iov and msg->msg_iovlen. The BUG_ON() statement * below verifies this. */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) From 3e39f3852df077680bac157bbf95073e987602c6 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 17:36:27 +0000 Subject: [PATCH 02/72] scst.spec.in: Mention filenames only once (this is a follow-up for r5976) git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6322 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst.spec.in | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/scst.spec.in b/scst.spec.in index 9f243056f..78e2abeec 100644 --- a/scst.spec.in +++ b/scst.spec.in @@ -132,12 +132,6 @@ rm -f /usr/local/man/man8/iscsi-scstd.8 rm -f /usr/local/sbin/iscsi-scst-adm rm -f /usr/local/sbin/iscsi-scstd rm -rf /usr/local/include/scst -rm -f /usr/local/man/man5/iscsi-scstd.conf.5 -rm -f /usr/local/man/man8/iscsi-scst-adm.8 -rm -f /usr/local/man/man8/iscsi-scstd.8 -rm -f /usr/local/sbin/iscsi-scst-adm -rm -f /usr/local/sbin/iscsi-scstd -rm -rf /usr/local/include/scst %post /sbin/depmod -a %{kversion} @@ -170,13 +164,6 @@ rm -rf /usr/local/include/scst %{_sbindir}/iscsi-scstd %dir /var/lib/scst/pr %dir /var/lib/scst/vdev_mode_pages -%{_mandir}/man5/iscsi-scstd.conf.5.gz -%{_mandir}/man8/iscsi-scst-adm.8.gz -%{_mandir}/man8/iscsi-scstd.8.gz -%{_sbindir}/iscsi-scst-adm -%{_sbindir}/iscsi-scstd -%dir /var/lib/scst/pr -%dir /var/lib/scst/vdev_mode_pages %files devel %defattr(-,root,root) From 410519634eb28ddb19d5951d76b8ac3afbd3118d Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 17:38:05 +0000 Subject: [PATCH 03/72] qla2x00t: Minimize diffs with the upstream driver in the >= 3.19 kernel code git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6323 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- qla2x00t/qla_iocb.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/qla2x00t/qla_iocb.c b/qla2x00t/qla_iocb.c index 58465ee07..aa236d2ae 100644 --- a/qla2x00t/qla_iocb.c +++ b/qla2x00t/qla_iocb.c @@ -409,9 +409,8 @@ qla2x00_start_scsi(srb_t *sp) /* Set target ID and LUN number*/ SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id); cmd_pkt->lun = cpu_to_le16(cmd->device->lun); - - /* Update tagged queuing modifier */ #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) + /* Update tagged queuing modifier */ if (scsi_populate_tag_msg(cmd, tag)) { switch (tag[0]) { case HEAD_OF_QUEUE_TAG: @@ -429,8 +428,7 @@ qla2x00_start_scsi(srb_t *sp) } } #else - if (cmd->flags & SCMD_TAGGED) - cmd_pkt->control_flags = cpu_to_le16(CF_SIMPLE_TAG); + cmd_pkt->control_flags = cpu_to_le16(CF_SIMPLE_TAG); #endif /* Load SCSI command packet. */ @@ -1403,11 +1401,10 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt, cmd_pkt->fcp_cmnd_dseg_address[1] = cpu_to_le32( MSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF)); fcp_cmnd->task_management = 0; - +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) /* * Update tagged queuing modifier if using command tag queuing */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) if (scsi_populate_tag_msg(cmd, tag)) { switch (tag[0]) { case HEAD_OF_QUEUE_TAG: @@ -1424,7 +1421,7 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt, fcp_cmnd->task_attribute = 0; } #else - fcp_cmnd->task_attribute = 0; + fcp_cmnd->task_attribute = TSK_SIMPLE; #endif cmd_pkt->fcp_rsp_dseg_len = 0; /* Let response come in status iocb */ @@ -1634,6 +1631,8 @@ qla24xx_start_scsi(srb_t *sp) break; } } +#else + cmd_pkt->task = TSK_SIMPLE; #endif /* Load SCSI command packet. */ From fe36df55d373e871dd7fb4b6e730fcc90b3a9a21 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 17:40:09 +0000 Subject: [PATCH 04/72] scst-dkms.spec.in: Build in release mode instead of debug mode git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6324 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst-dkms.spec.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scst-dkms.spec.in b/scst-dkms.spec.in index e62d3cb61..61b54f9a4 100644 --- a/scst-dkms.spec.in +++ b/scst-dkms.spec.in @@ -145,7 +145,7 @@ cat >%{buildroot}/usr/src/%{kmod_name}-%{dkms_version}/dkms.conf <<"EOF" PACKAGE_VERSION="%{dkms_version}" PACKAGE_NAME="%{kmod_name}" AUTOINSTALL=yes -MAKE[0]="export KVER=${kernelver} KDIR=${kernel_source_dir} BUILD_2X_MODULE=y CONFIG_SCSI_QLA_FC=y CONFIG_SCSI_QLA2XXX_TARGET=y && make -sC scst && make -sC fcst && make -sC iscsi-scst && make -sC qla2x00t/qla2x00-target && make -sC scst_local && make -sC srpt && cp */*.ko */*/*.ko */*/*/*.ko ." +MAKE[0]="export KVER=${kernelver} KDIR=${kernel_source_dir} BUILD_2X_MODULE=y CONFIG_SCSI_QLA_FC=y CONFIG_SCSI_QLA2XXX_TARGET=y && make 2release && make -sC scst && make -sC fcst && make -sC iscsi-scst && make -sC qla2x00t/qla2x00-target && make -sC scst_local && make -sC srpt && cp */*.ko */*/*.ko */*/*/*.ko ." CLEAN="make clean" # Remove any existing ib_srpt.ko kernel modules PRE_INSTALL="find /lib/modules/${kernelver} -name ib_srpt.ko -exec rm {} \;" @@ -242,6 +242,10 @@ true /usr/include/scst/scst_user.h %changelog +* Wed May 6 2015 Bart Van Assche +- Build in release mode instead of debug mode. +* Mon May 4 2015 Bart Van Assche +- Added iSER target driver. * Mon Feb 23 2015 Bart Van Assche - Split spec file into a non-DKMS and a DKMS spec file. * Fri Jan 16 2015 Bart Van Assche From 1890eee7b91f3d373321b42e3a830df14e3d93a6 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 18:16:18 +0000 Subject: [PATCH 05/72] scstadmin: Rename the SCST-SCST Perl module into SCST_SCST From http://perldoc.perl.org/ExtUtils/MakeMaker.html: "NAME must be a valid Perl package name". Rename the Perl module to avoid that MakeMaker reports the following: Warning: NAME must be a package name git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6325 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/Makefile | 4 ++++ scstadmin/scstadmin.procfs/scst-0.8.22/Makefile.PL | 4 ++-- scstadmin/scstadmin.procfs/scst-0.8.22/README | 6 +++--- scstadmin/scstadmin.spec.in | 2 +- scstadmin/scstadmin.sysfs/scst-0.9.10/Makefile.PL | 4 ++-- scstadmin/scstadmin.sysfs/scst-0.9.10/README | 6 +++--- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/scstadmin/Makefile b/scstadmin/Makefile index eebdbc9fe..c6791f5cf 100644 --- a/scstadmin/Makefile +++ b/scstadmin/Makefile @@ -83,6 +83,10 @@ install install_vendor: fi \ fi \ done + # Remove the files that are obsolete since SCST-SCST has been + # renamed into SCST_SCST. + rm -rf "$$(/usr/bin/perl -V:sitearch | sed "s|.*='||;s|'.*||")/auto/SCST-SCST" + # Install the files that have just been built. install -d $(DESTDIR)$(INITDIR) tmp=/tmp/scst-initd-$$$$ && init.d/scst >$$tmp && \ install -m 755 $$tmp $(DESTDIR)$(INITDIR)/scst && \ diff --git a/scstadmin/scstadmin.procfs/scst-0.8.22/Makefile.PL b/scstadmin/scstadmin.procfs/scst-0.8.22/Makefile.PL index 5b400f804..621b905d9 100644 --- a/scstadmin/scstadmin.procfs/scst-0.8.22/Makefile.PL +++ b/scstadmin/scstadmin.procfs/scst-0.8.22/Makefile.PL @@ -1,12 +1,12 @@ #!/usr/bin/perl -w # -# Makefile for the SCST-SCST perl module +# Makefile for the SCST_SCST perl module # use ExtUtils::MakeMaker; WriteMakefile( - 'NAME' => 'SCST-SCST', + 'NAME' => 'SCST_SCST', 'VERSION_FROM' => 'lib/SCST/SCST.pm', 'AUTHOR' => 'Mark R. Buechler ', 'PREREQ_PM' => {}, diff --git a/scstadmin/scstadmin.procfs/scst-0.8.22/README b/scstadmin/scstadmin.procfs/scst-0.8.22/README index 95df1880b..75b5b8f1f 100644 --- a/scstadmin/scstadmin.procfs/scst-0.8.22/README +++ b/scstadmin/scstadmin.procfs/scst-0.8.22/README @@ -1,15 +1,15 @@ -SCST-SCST is a perl module for querying and configuring SCST. +SCST_SCST is a perl module for querying and configuring SCST. AVAILABILITY -Currently SCST-SCST ships with SCST itself available from +Currently SCST_SCST ships with SCST itself available from http://scst.sourceforge.net. INSTALLATION -Install SCST-SCST as you would any other perl module: +Install SCST_SCST as you would any other perl module: perl Makefile.PL make diff --git a/scstadmin/scstadmin.spec.in b/scstadmin/scstadmin.spec.in index e1c57cf7f..3105c71f3 100644 --- a/scstadmin/scstadmin.spec.in +++ b/scstadmin/scstadmin.spec.in @@ -69,7 +69,7 @@ rm -f /usr/local/man/man5/scst.conf.5* /etc/init.d/scst %{_sbindir}/scstadmin %{perl_vendorlib}/SCST -%{perl_vendorarch}/auto/SCST-SCST +%{perl_vendorarch}/auto/SCST_SCST %{_mandir}/man1/scstadmin.1* %{scstadmin_perl_installvendorman3dir}/SCST::SCST.3pm* %{_mandir}/man5/scst.5* diff --git a/scstadmin/scstadmin.sysfs/scst-0.9.10/Makefile.PL b/scstadmin/scstadmin.sysfs/scst-0.9.10/Makefile.PL index 5b400f804..621b905d9 100644 --- a/scstadmin/scstadmin.sysfs/scst-0.9.10/Makefile.PL +++ b/scstadmin/scstadmin.sysfs/scst-0.9.10/Makefile.PL @@ -1,12 +1,12 @@ #!/usr/bin/perl -w # -# Makefile for the SCST-SCST perl module +# Makefile for the SCST_SCST perl module # use ExtUtils::MakeMaker; WriteMakefile( - 'NAME' => 'SCST-SCST', + 'NAME' => 'SCST_SCST', 'VERSION_FROM' => 'lib/SCST/SCST.pm', 'AUTHOR' => 'Mark R. Buechler ', 'PREREQ_PM' => {}, diff --git a/scstadmin/scstadmin.sysfs/scst-0.9.10/README b/scstadmin/scstadmin.sysfs/scst-0.9.10/README index 611c795af..34e6085ed 100644 --- a/scstadmin/scstadmin.sysfs/scst-0.9.10/README +++ b/scstadmin/scstadmin.sysfs/scst-0.9.10/README @@ -1,15 +1,15 @@ -SCST-SCST is a perl module for querying and configuring SCST. +SCST_SCST is a perl module for querying and configuring SCST. AVAILABILITY -Currently SCST-SCST ships with SCST itself available from +Currently SCST_SCST ships with SCST itself available from http://scst.sourceforge.net. INSTALLATION -Install SCST-SCST as you would any other perl module: +Install SCST_SCST as you would any other perl module: perl Makefile.PL make From 2056892f23141355876f99bd72139230e44de805 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 18:21:11 +0000 Subject: [PATCH 06/72] scstadmin/Makefile: Take $(DESTDIR) into account git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6326 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scstadmin/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scstadmin/Makefile b/scstadmin/Makefile index c6791f5cf..72bb5b831 100644 --- a/scstadmin/Makefile +++ b/scstadmin/Makefile @@ -85,7 +85,7 @@ install install_vendor: done # Remove the files that are obsolete since SCST-SCST has been # renamed into SCST_SCST. - rm -rf "$$(/usr/bin/perl -V:sitearch | sed "s|.*='||;s|'.*||")/auto/SCST-SCST" + rm -rf "$(DESTDIR)$$(/usr/bin/perl -V:sitearch | sed "s|.*='||;s|'.*||")/auto/SCST-SCST" # Install the files that have just been built. install -d $(DESTDIR)$(INITDIR) tmp=/tmp/scst-initd-$$$$ && init.d/scst >$$tmp && \ From 86cb6fce1b2d44938cfd42c094abaf37913e5cd1 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 18:51:15 +0000 Subject: [PATCH 07/72] scst_vdisk: Remove superfluous braces Detected by checkpatch. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6327 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 437e37d5e..12a66a783 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -3796,9 +3796,8 @@ static int vdisk_sup_vpd(uint8_t *buf, struct scst_cmd *cmd, if (cmd->dev->type == TYPE_DISK) { *p++ = 0xB0; /* block limits */ *p++ = 0xB1; /* block device characteristics */ - if (virt_dev->thin_provisioned) { + if (virt_dev->thin_provisioned) *p++ = 0xB2; /* thin provisioning */ - } } buf[3] = p - page_list; /* page length */ From 807c4eacf050da9e66cd7f07d2db593ad5127043 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 18:51:47 +0000 Subject: [PATCH 08/72] isert: Use break in default case Detected by checkpatch. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6328 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/isert-scst/isert_login.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iscsi-scst/kernel/isert-scst/isert_login.c b/iscsi-scst/kernel/isert-scst/isert_login.c index 3e32c6c33..024d5bba8 100644 --- a/iscsi-scst/kernel/isert-scst/isert_login.c +++ b/iscsi-scst/kernel/isert-scst/isert_login.c @@ -460,7 +460,7 @@ static bool will_read_block(struct isert_conn_dev *dev) res = false; break; default: - ; + break; } } spin_unlock(&dev->pdu_lock); From 020ec68ddc985ff392267e0022d348a819e948bb Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 18:57:16 +0000 Subject: [PATCH 09/72] ib_srpt: Change default behavior from using SRQ to not using SRQ Although the non-SRQ mode needs more resources that mode has the advantage that the end-to-end flow control mechanism is used. From the IB spec: C9-150.2.1: For QPs that are not associated with an SRQ, each HCA receive queue shall generate end-to-end flow control credits. If a QP is associated with an SRQ, the HCA receive queue shall not generate end-to-end flow control credits. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6329 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- srpt/src/ib_srpt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srpt/src/ib_srpt.c b/srpt/src/ib_srpt.c index 30141669c..8e0d43005 100644 --- a/srpt/src/ib_srpt.c +++ b/srpt/src/ib_srpt.c @@ -130,9 +130,9 @@ MODULE_PARM_DESC(srp_max_rsp_size, #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) \ || defined(RHEL_MAJOR) && RHEL_MAJOR -0 <= 5 -static int use_srq = true; +static int use_srq; #else -static bool use_srq = true; +static bool use_srq; #endif module_param(use_srq, bool, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(use_srq, From eea3bca1e9d0204a2fce704519e4a4b0e56dbd02 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 20:08:45 +0000 Subject: [PATCH 10/72] scst: Remove unreachable code Code after BUG() is unreachable both with CONFIG_BUG=y and with CONFIG_BUG=n. Hence remove such code. Detected by smatch. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6330 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 2 -- scst/src/scst_targ.c | 1 - 2 files changed, 3 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 076d1e61b..43a80154e 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -12655,8 +12655,6 @@ int scst_parse_descriptors(struct scst_cmd *cmd) break; default: sBUG(); - res = -1; - break; } TRACE_EXIT_RES(res); diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 2103ca260..17aa700a0 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -2322,7 +2322,6 @@ static int scst_report_supported_opcodes(struct scst_cmd *cmd) break; default: sBUG(); - goto out_compl; } if (length > buf_len) From 550ab7c1d3e4ee3b58264fc7acfb4a46ab02b177 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 20:12:28 +0000 Subject: [PATCH 11/72] ib_srpt: RHEL 7.1 build fix With the RHEL 7.0 kernel ib_register_mad_agent() takes eight arguments. With the RHEL 7.1 kernel the same function takes nine arguments. Detect at build time how many arguments this function takes. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6331 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- srpt/Makefile | 5 +++-- srpt/conftest/register_mad_agent/Makefile | 3 +++ .../register_mad_agent/register_mad_agent.c | 13 +++++++++++++ srpt/src/ib_srpt.c | 3 ++- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 srpt/conftest/register_mad_agent/Makefile create mode 100644 srpt/conftest/register_mad_agent/register_mad_agent.c diff --git a/srpt/Makefile b/srpt/Makefile index 68fcfcdbf..6d3dbd896 100644 --- a/srpt/Makefile +++ b/srpt/Makefile @@ -77,8 +77,9 @@ endif OFED_MODULE_SYMVERS:=$(OFED_KERNEL_DIR)/$(MODULE_SYMVERS) endif -AUTOCONF_FLAGS = $(shell $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/conftest/gid_change PRE_CFLAGS="$(OFED_CFLAGS)" >/dev/null 2>&1 && echo -DHAVE_IB_EVENT_GID_CHANGE) -PRE_CFLAGS=$(OFED_CFLAGS) $(AUTOCONF_FLAGS) -DOFED_FLAVOR=$(OFED_FLAVOR) +GID_CHANGE_FLAG = $(shell $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/conftest/gid_change PRE_CFLAGS="$(OFED_CFLAGS)" >/dev/null 2>&1 && echo -DHAVE_IB_EVENT_GID_CHANGE) +REGISTER_MAD_AGENT_FLAG = $(shell $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/conftest/register_mad_agent PRE_CFLAGS="$(OFED_CFLAGS) -Werror" >/dev/null 2>&1 && echo -DREGISTER_MAD_AGENT_HAS_FLAGS_ARG) +PRE_CFLAGS=$(OFED_CFLAGS) $(GID_CHANGE_FLAG) $(REGISTER_MAD_AGENT_FLAG) -DOFED_FLAVOR=$(OFED_FLAVOR) all: src/$(MODULE_SYMVERS) $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/src \ diff --git a/srpt/conftest/register_mad_agent/Makefile b/srpt/conftest/register_mad_agent/Makefile new file mode 100644 index 000000000..11f6f4506 --- /dev/null +++ b/srpt/conftest/register_mad_agent/Makefile @@ -0,0 +1,3 @@ +LINUXINCLUDE := $(PRE_CFLAGS) $(LINUXINCLUDE) + +obj-m += register_mad_agent.o diff --git a/srpt/conftest/register_mad_agent/register_mad_agent.c b/srpt/conftest/register_mad_agent/register_mad_agent.c new file mode 100644 index 000000000..fe0421c2b --- /dev/null +++ b/srpt/conftest/register_mad_agent/register_mad_agent.c @@ -0,0 +1,13 @@ +#include +#include + +static int modinit(void) +{ + struct ib_mad_agent *a; + + a = ib_register_mad_agent(NULL, 0, 0, NULL, 0, NULL, NULL, NULL, 0); + + return a!= 0; +} + +module_init(modinit); diff --git a/srpt/src/ib_srpt.c b/srpt/src/ib_srpt.c index 8e0d43005..d419a38f3 100644 --- a/srpt/src/ib_srpt.c +++ b/srpt/src/ib_srpt.c @@ -712,7 +712,8 @@ static int srpt_refresh_port(struct srpt_port *sport) srpt_mad_send_handler, srpt_mad_recv_handler, sport -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0) || \ + defined(REGISTER_MAD_AGENT_HAS_FLAGS_ARG) , 0 #endif ); From 5516e63e253fade232366a2edf6c361d5286e494 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 20:13:14 +0000 Subject: [PATCH 12/72] qla2x00t: Port to RHEL 6 Although RHEL 6 is based on the 2.6.32 kernel, for RHEL 6.1 the argument list for sysfs callback functions follows the style of kernel 2.6.35. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6332 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- qla2x00t/qla_attr.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/qla2x00t/qla_attr.c b/qla2x00t/qla_attr.c index 3adcf4987..ec98b4cee 100644 --- a/qla2x00t/qla_attr.c +++ b/qla2x00t/qla_attr.c @@ -1168,7 +1168,9 @@ static struct bin_attribute sysfs_sfp_attr = { }; static ssize_t -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) && \ + (!defined(RHEL_RELEASE_CODE) || \ + RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(6, 1)) qla2x00_sysfs_write_reset( #else qla2x00_sysfs_write_reset(struct file *file, @@ -1248,7 +1250,9 @@ static struct bin_attribute sysfs_reset_attr = { }; static ssize_t -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) && \ + (!defined(RHEL_RELEASE_CODE) || \ + RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(6, 1)) qla2x00_sysfs_read_xgmac_stats( #else qla2x00_sysfs_read_xgmac_stats(struct file *file, @@ -1305,7 +1309,9 @@ static struct bin_attribute sysfs_xgmac_stats_attr = { }; static ssize_t -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) && \ + (!defined(RHEL_RELEASE_CODE) || \ + RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(6, 1)) qla2x00_sysfs_read_dcbx_tlv( #else qla2x00_sysfs_read_dcbx_tlv(struct file *file, From 1d58f5fd1432f5c8e09e32a01bb6e28e15164cc2 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 20:14:10 +0000 Subject: [PATCH 13/72] scst_local: RHEL 5 build fix Add a definition of scsi_bidi_cmnd() for older kernel versions. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6333 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/scst.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scst/include/scst.h b/scst/include/scst.h index c393205fa..8b9f490d2 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -139,6 +139,17 @@ char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap); typedef unsigned long uintptr_t; #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) +/* + * See also patch "[SCSI] bidirectional command support" + * (commit ID 6f9a35e2dafa). + */ +static inline int scsi_bidi_cmnd(struct scsi_cmnd *cmd) +{ + return false; +} +#endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28) #define cpumask_bits(maskp) ((maskp)->bits) #ifdef CONFIG_CPUMASK_OFFSTACK From 9bfdc312d3e7faf7caa9247125033f774e23f79c Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 20:15:12 +0000 Subject: [PATCH 14/72] ib_srpt: RHEL 5 build fix Make the ib_srpt driver build again on RHEL 5 systems. See also r6138. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6334 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- srpt/src/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/srpt/src/Makefile b/srpt/src/Makefile index 5beb4781c..5d0338c86 100644 --- a/srpt/src/Makefile +++ b/srpt/src/Makefile @@ -1,4 +1,5 @@ LINUXINCLUDE := $(PRE_CFLAGS) $(LINUXINCLUDE) +CPPFLAGS := $(PRE_CFLAGS) $(CPPFLAGS) EXTRA_CFLAGS += -I$(SCST_INC_DIR) -include $(SUBDIRS)/../build_mode From 502aef7b1b8cd8b45d14978f01412be4e7cdbec8 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 20:16:19 +0000 Subject: [PATCH 15/72] scst: Rename SERVICE_ACTION_IN into SERVICE_ACTION_IN_16 Rename this constant because it has been renamed in the Linux kernel. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6335 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/scst_const.h | 13 ++++++++++--- scst/src/dev_handlers/scst_vdisk.c | 12 ++++++------ scst/src/scst_tg.c | 2 +- usr/fileio/common.c | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/scst/include/scst_const.h b/scst/include/scst_const.h index b028e826c..a2546d9b4 100644 --- a/scst/include/scst_const.h +++ b/scst/include/scst_const.h @@ -395,9 +395,6 @@ static inline int scst_sense_response_code(const uint8_t *sense) #define MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0d #endif #endif -#ifndef SERVICE_ACTION_IN -#define SERVICE_ACTION_IN 0x9e -#endif #ifndef SAI_READ_CAPACITY_16 /* values for service action in */ #define SAI_READ_CAPACITY_16 0x10 @@ -447,6 +444,16 @@ static inline int scst_sense_response_code(const uint8_t *sense) #endif #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) +/* + * See also patch "scsi: rename SERVICE_ACTION_IN_16 to SERVICE_ACTION_IN_16" + * (commit eb846d9f147455e4e5e1863bfb5e31974bb69b7c). + */ +#ifndef SERVICE_ACTION_IN_16 +#define SERVICE_ACTION_IN_16 0x9e +#endif +#endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28) /* * From . See also commit diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 12a66a783..b2ea17676 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -1829,7 +1829,7 @@ static enum compl_status_e vdisk_nop(struct vdisk_cmd_params *p) return CMD_SUCCEEDED; } -static enum compl_status_e vdisk_exec_srv_action_in(struct vdisk_cmd_params *p) +static enum compl_status_e vdisk_exec_sai_16(struct vdisk_cmd_params *p) { switch (p->cmd->cdb[1] & 0x1f) { case SAI_READ_CAPACITY_16: @@ -2188,14 +2188,14 @@ static const struct scst_opcode_descriptor scst_op_descr_format_unit = { }; static const struct scst_opcode_descriptor scst_op_descr_get_lba_status = { - .od_opcode = SERVICE_ACTION_IN, + .od_opcode = SERVICE_ACTION_IN_16, .od_serv_action = SAI_GET_LBA_STATUS, .od_serv_action_valid = 1, .od_support = 3, /* supported as in the standard */ .od_cdb_size = 16, .od_nominal_timeout = SCST_DEFAULT_NOMINAL_TIMEOUT_SEC, .od_recommended_timeout = SCST_GENERIC_DISK_SMALL_TIMEOUT/HZ, - .od_cdb_usage_bits = { SERVICE_ACTION_IN, SAI_GET_LBA_STATUS, + .od_cdb_usage_bits = { SERVICE_ACTION_IN_16, SAI_GET_LBA_STATUS, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0, SCST_OD_DEFAULT_CONTROL_BYTE }, @@ -2281,14 +2281,14 @@ static const struct scst_opcode_descriptor scst_op_descr_read_capacity = { }; static const struct scst_opcode_descriptor scst_op_descr_read_capacity16 = { - .od_opcode = SERVICE_ACTION_IN, + .od_opcode = SERVICE_ACTION_IN_16, .od_serv_action = SAI_READ_CAPACITY_16, .od_serv_action_valid = 1, .od_support = 3, /* supported as in the standard */ .od_cdb_size = 16, .od_nominal_timeout = SCST_DEFAULT_NOMINAL_TIMEOUT_SEC, .od_recommended_timeout = SCST_GENERIC_DISK_SMALL_TIMEOUT/HZ, - .od_cdb_usage_bits = { SERVICE_ACTION_IN, SAI_READ_CAPACITY_16, + .od_cdb_usage_bits = { SERVICE_ACTION_IN_16, SAI_READ_CAPACITY_16, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF, 0, SCST_OD_DEFAULT_CONTROL_BYTE }, @@ -2565,7 +2565,7 @@ static const struct scst_opcode_descriptor scst_op_descr_read_toc = { [INQUIRY] = vdisk_exec_inquiry, \ [REQUEST_SENSE] = vdisk_exec_request_sense, \ [READ_CAPACITY] = vdisk_exec_read_capacity, \ - [SERVICE_ACTION_IN] = vdisk_exec_srv_action_in, \ + [SERVICE_ACTION_IN_16] = vdisk_exec_sai_16, \ [UNMAP] = vdisk_exec_unmap, \ [WRITE_SAME] = vdisk_exec_write_same, \ [WRITE_SAME_16] = vdisk_exec_write_same, \ diff --git a/scst/src/scst_tg.c b/scst/src/scst_tg.c index d48af7c6d..6a714014c 100644 --- a/scst/src/scst_tg.c +++ b/scst/src/scst_tg.c @@ -263,7 +263,7 @@ static bool scst_tg_accept(struct scst_cmd *cmd) case REPORT_LUNS: case REQUEST_SENSE: return true; - case SERVICE_ACTION_IN: + case SERVICE_ACTION_IN_16: switch (cmd->cdb[1] & 0x1f) { case SAI_READ_CAPACITY_16: return true; diff --git a/usr/fileio/common.c b/usr/fileio/common.c index feb4e8b3c..475704810 100644 --- a/usr/fileio/common.c +++ b/usr/fileio/common.c @@ -390,7 +390,7 @@ static int do_exec(struct vdisk_cmd *vcmd) case READ_CAPACITY: exec_read_capacity(vcmd); break; - case SERVICE_ACTION_IN: + case SERVICE_ACTION_IN_16: if ((cmd->cdb[1] & 0x1f) == SAI_READ_CAPACITY_16) exec_read_capacity16(vcmd); else { From 6b3f45696a1bf1f3fbf8a42484a71583b1fbbc17 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 20:17:52 +0000 Subject: [PATCH 16/72] RHEL 7.1: Add put_page_callback patch git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6336 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- .../rhel/put_page_callback-3.10.0-229.patch | 424 ++++++++++++++++++ 1 file changed, 424 insertions(+) create mode 100644 iscsi-scst/kernel/patches/rhel/put_page_callback-3.10.0-229.patch diff --git a/iscsi-scst/kernel/patches/rhel/put_page_callback-3.10.0-229.patch b/iscsi-scst/kernel/patches/rhel/put_page_callback-3.10.0-229.patch new file mode 100644 index 000000000..ae732d2d4 --- /dev/null +++ b/iscsi-scst/kernel/patches/rhel/put_page_callback-3.10.0-229.patch @@ -0,0 +1,424 @@ +diff -uprN linux-3.10.0-229.el7/drivers/block/drbd/drbd_receiver.c linux-3.10.0-229.el7-patched/drivers/block/drbd/drbd_receiver.c +--- linux-3.10.0-229.el7/drivers/block/drbd/drbd_receiver.c 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/drivers/block/drbd/drbd_receiver.c 2015-04-21 10:15:55.717008940 +0200 +@@ -130,7 +130,7 @@ static int page_chain_free(struct page * + struct page *tmp; + int i = 0; + page_chain_for_each_safe(page, tmp) { +- put_page(page); ++ net_put_page(page); + ++i; + } + return i; +diff -uprN linux-3.10.0-229.el7/drivers/net/macvtap.c linux-3.10.0-229.el7-patched/drivers/net/macvtap.c +--- linux-3.10.0-229.el7/drivers/net/macvtap.c 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/drivers/net/macvtap.c 2015-04-21 10:15:55.718008916 +0200 +@@ -604,7 +604,7 @@ static int zerocopy_sg_from_iovec(struct + int j; + + for (j = 0; j < num_pages; j++) +- put_page(page[i + j]); ++ net_put_page(page[i + j]); + return -EFAULT; + } + truesize = size * PAGE_SIZE; +diff -uprN linux-3.10.0-229.el7/drivers/net/tun.c linux-3.10.0-229.el7-patched/drivers/net/tun.c +--- linux-3.10.0-229.el7/drivers/net/tun.c 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/drivers/net/tun.c 2015-04-21 10:15:55.719008893 +0200 +@@ -1015,7 +1015,7 @@ static int zerocopy_sg_from_iovec(struct + int j; + + for (j = 0; j < num_pages; j++) +- put_page(page[i + j]); ++ net_put_page(page[i + j]); + return -EFAULT; + } + truesize = size * PAGE_SIZE; +diff -uprN linux-3.10.0-229.el7/drivers/net/vmxnet3/vmxnet3_drv.c linux-3.10.0-229.el7-patched/drivers/net/vmxnet3/vmxnet3_drv.c +--- linux-3.10.0-229.el7/drivers/net/vmxnet3/vmxnet3_drv.c 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/drivers/net/vmxnet3/vmxnet3_drv.c 2015-04-21 10:15:55.720008872 +0200 +@@ -1360,7 +1360,7 @@ vmxnet3_rq_cleanup(struct vmxnet3_rx_que + rq->buf_info[ring_idx][i].page) { + pci_unmap_page(adapter->pdev, rxd->addr, + rxd->len, PCI_DMA_FROMDEVICE); +- put_page(rq->buf_info[ring_idx][i].page); ++ net_put_page(rq->buf_info[ring_idx][i].page); + rq->buf_info[ring_idx][i].page = NULL; + } + } +diff -uprN linux-3.10.0-229.el7/drivers/net/xen-netback/netback.c linux-3.10.0-229.el7-patched/drivers/net/xen-netback/netback.c +--- linux-3.10.0-229.el7/drivers/net/xen-netback/netback.c 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/drivers/net/xen-netback/netback.c 2015-04-21 10:15:55.720008872 +0200 +@@ -1292,7 +1292,7 @@ static void xen_netbk_fill_frags(struct + skb->truesize += txp->size; + + /* Take an extra reference to offset xen_netbk_idx_release */ +- get_page(netbk->mmap_pages[pending_idx]); ++ net_get_page(netbk->mmap_pages[pending_idx]); + xen_netbk_idx_release(netbk, pending_idx, XEN_NETIF_RSP_OKAY); + } + } +@@ -1774,7 +1774,7 @@ static void xen_netbk_idx_release(struct + } while (!pending_tx_is_head(netbk, peek)); + + netbk->mmap_pages[pending_idx]->mapping = 0; +- put_page(netbk->mmap_pages[pending_idx]); ++ net_put_page(netbk->mmap_pages[pending_idx]); + netbk->mmap_pages[pending_idx] = NULL; + } + +diff -uprN linux-3.10.0-229.el7/include/linux/mm_types.h linux-3.10.0-229.el7-patched/include/linux/mm_types.h +--- linux-3.10.0-229.el7/include/linux/mm_types.h 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/include/linux/mm_types.h 2015-04-21 10:15:55.721008852 +0200 +@@ -188,6 +188,17 @@ struct page { + #ifdef LAST_CPUPID_NOT_IN_PAGE_FLAGS + int _last_cpupid; + #endif ++ ++#if defined(CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION) ++ /* ++ * Used to implement support for notification on zero-copy TCP transfer ++ * completion. It might look as not good to have this field here and ++ * it's better to have it in struct sk_buff, but it would make the code ++ * much more complicated and fragile, since all skb then would have to ++ * contain only pages with the same value in this field. ++ */ ++ void *net_priv; ++#endif + } + /* + * The struct page can be forced to be double word aligned so that atomic ops +diff -uprN linux-3.10.0-229.el7/include/linux/net.h linux-3.10.0-229.el7-patched/include/linux/net.h +--- linux-3.10.0-229.el7/include/linux/net.h 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/include/linux/net.h 2015-04-21 10:15:55.722008834 +0200 +@@ -19,6 +19,7 @@ + #define _LINUX_NET_H + + #include ++#include + #include + #include + #include /* For O_CLOEXEC and O_NONBLOCK */ +@@ -281,6 +282,45 @@ extern int kernel_sock_ioctl(struct sock + extern int kernel_sock_shutdown(struct socket *sock, + enum sock_shutdown_cmd how); + ++#if defined(CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION) ++/* Support for notification on zero-copy TCP transfer completion */ ++typedef void (*net_get_page_callback_t)(struct page *page); ++typedef void (*net_put_page_callback_t)(struct page *page); ++ ++extern net_get_page_callback_t net_get_page_callback; ++extern net_put_page_callback_t net_put_page_callback; ++ ++extern int net_set_get_put_page_callbacks( ++ net_get_page_callback_t get_callback, ++ net_put_page_callback_t put_callback); ++ ++/* ++ * See comment for net_set_get_put_page_callbacks() why those functions ++ * don't need any protection. ++ */ ++static inline void net_get_page(struct page *page) ++{ ++ if (page->net_priv != 0) ++ net_get_page_callback(page); ++ get_page(page); ++} ++static inline void net_put_page(struct page *page) ++{ ++ if (page->net_priv != 0) ++ net_put_page_callback(page); ++ put_page(page); ++} ++#else ++static inline void net_get_page(struct page *page) ++{ ++ get_page(page); ++} ++static inline void net_put_page(struct page *page) ++{ ++ put_page(page); ++} ++#endif /* CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION */ ++ + #define MODULE_ALIAS_NETPROTO(proto) \ + MODULE_ALIAS("net-pf-" __stringify(proto)) + +diff -uprN linux-3.10.0-229.el7/include/linux/skbuff.h linux-3.10.0-229.el7-patched/include/linux/skbuff.h +--- linux-3.10.0-229.el7/include/linux/skbuff.h 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/include/linux/skbuff.h 2015-04-21 10:15:55.724008801 +0200 +@@ -2101,7 +2101,7 @@ static inline struct page *skb_frag_page + */ + static inline void __skb_frag_ref(skb_frag_t *frag) + { +- get_page(skb_frag_page(frag)); ++ net_get_page(skb_frag_page(frag)); + } + + /** +@@ -2124,7 +2124,7 @@ static inline void skb_frag_ref(struct s + */ + static inline void __skb_frag_unref(skb_frag_t *frag) + { +- put_page(skb_frag_page(frag)); ++ net_put_page(skb_frag_page(frag)); + } + + /** +diff -uprN linux-3.10.0-229.el7/net/Kconfig linux-3.10.0-229.el7-patched/net/Kconfig +--- linux-3.10.0-229.el7/net/Kconfig 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/net/Kconfig 2015-04-21 10:15:55.725008788 +0200 +@@ -74,6 +74,18 @@ config INET + + Short answer: say Y. + ++config TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION ++ bool "TCP/IP zero-copy transfer completion notification" ++ depends on INET ++ default SCST_ISCSI ++ ---help--- ++ Adds support for sending a notification upon completion of a ++ zero-copy TCP/IP transfer. This can speed up certain TCP/IP ++ software. Currently this is only used by the iSCSI target driver ++ iSCSI-SCST. ++ ++ If unsure, say N. ++ + if INET + source "net/ipv4/Kconfig" + source "net/ipv6/Kconfig" +diff -uprN linux-3.10.0-229.el7/net/ceph/pagevec.c linux-3.10.0-229.el7-patched/net/ceph/pagevec.c +--- linux-3.10.0-229.el7/net/ceph/pagevec.c 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/net/ceph/pagevec.c 2015-04-21 10:15:55.726008775 +0200 +@@ -51,7 +51,7 @@ void ceph_put_page_vector(struct page ** + for (i = 0; i < num_pages; i++) { + if (dirty) + set_page_dirty_lock(pages[i]); +- put_page(pages[i]); ++ net_put_page(pages[i]); + } + kfree(pages); + } +diff -uprN linux-3.10.0-229.el7/net/core/skbuff.c linux-3.10.0-229.el7-patched/net/core/skbuff.c +--- linux-3.10.0-229.el7/net/core/skbuff.c 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/net/core/skbuff.c 2015-04-21 10:34:20.113935390 +0200 +@@ -79,13 +79,13 @@ static struct kmem_cache *skbuff_fclone_ + static void sock_pipe_buf_release(struct pipe_inode_info *pipe, + struct pipe_buffer *buf) + { +- put_page(buf->page); ++ net_put_page(buf->page); + } + + static void sock_pipe_buf_get(struct pipe_inode_info *pipe, + struct pipe_buffer *buf) + { +- get_page(buf->page); ++ net_get_page(buf->page); + } + + static int sock_pipe_buf_steal(struct pipe_inode_info *pipe, +@@ -453,7 +453,7 @@ struct sk_buff *__netdev_alloc_skb(struc + if (likely(data)) { + skb = build_skb(data, fragsz); + if (unlikely(!skb)) +- put_page(virt_to_head_page(data)); ++ net_put_page(virt_to_head_page(data)); + } + } else { + skb = __alloc_skb(length + NET_SKB_PAD, gfp_mask, +@@ -499,7 +499,7 @@ static void skb_clone_fraglist(struct sk + static void skb_free_head(struct sk_buff *skb) + { + if (skb->head_frag) +- put_page(virt_to_head_page(skb->head)); ++ net_put_page(virt_to_head_page(skb->head)); + else + kfree(skb->head); + } +@@ -826,7 +826,7 @@ int skb_copy_ubufs(struct sk_buff *skb, + if (!page) { + while (head) { + struct page *next = (struct page *)head->private; +- put_page(head); ++ net_put_page(head); + head = next; + } + return -ENOMEM; +@@ -1646,7 +1646,7 @@ EXPORT_SYMBOL(skb_copy_bits); + */ + static void sock_spd_release(struct splice_pipe_desc *spd, unsigned int i) + { +- put_page(spd->pages[i]); ++ net_put_page(spd->pages[i]); + } + + static struct page *linear_to_page(struct page *page, unsigned int *len, +@@ -1699,7 +1699,7 @@ static bool spd_fill_page(struct splice_ + spd->partial[spd->nr_pages - 1].len += *len; + return false; + } +- get_page(page); ++ net_get_page(page); + spd->pages[spd->nr_pages] = page; + spd->partial[spd->nr_pages].len = *len; + spd->partial[spd->nr_pages].offset = offset; +@@ -2158,7 +2158,7 @@ skb_zerocopy(struct sk_buff *to, struct + page = virt_to_head_page(from->head); + offset = from->data - (unsigned char *)page_address(page); + __skb_fill_page_desc(to, 0, page, offset, plen); +- get_page(page); ++ net_get_page(page); + j = 1; + len -= plen; + } +@@ -2807,7 +2807,7 @@ int skb_append_datato_frags(struct sock + copy); + frg_cnt++; + pfrag->offset += copy; +- get_page(pfrag->page); ++ net_get_page(pfrag->page); + + skb->truesize += copy; + atomic_add(copy, &sk->sk_wmem_alloc); +diff -uprN linux-3.10.0-229.el7/net/core/sock.c linux-3.10.0-229.el7-patched/net/core/sock.c +--- linux-3.10.0-229.el7/net/core/sock.c 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/net/core/sock.c 2015-04-21 10:15:55.728008756 +0200 +@@ -1826,7 +1826,7 @@ bool sk_page_frag_refill(struct sock *sk + } + if (pfrag->offset < pfrag->size) + return true; +- put_page(pfrag->page); ++ net_put_page(pfrag->page); + } + + /* We restrict high order allocations to users that can afford to wait */ +@@ -2528,7 +2528,7 @@ void sk_common_release(struct sock *sk) + sk_refcnt_debug_release(sk); + + if (sk->sk_frag.page) { +- put_page(sk->sk_frag.page); ++ net_put_page(sk->sk_frag.page); + sk->sk_frag.page = NULL; + } + +diff -uprN linux-3.10.0-229.el7/net/ipv4/Makefile linux-3.10.0-229.el7-patched/net/ipv4/Makefile +--- linux-3.10.0-229.el7/net/ipv4/Makefile 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/net/ipv4/Makefile 2015-04-21 10:15:55.728008756 +0200 +@@ -53,6 +53,7 @@ obj-$(CONFIG_TCP_CONG_YEAH) += tcp_yeah. + obj-$(CONFIG_TCP_CONG_ILLINOIS) += tcp_illinois.o + obj-$(CONFIG_MEMCG_KMEM) += tcp_memcontrol.o + obj-$(CONFIG_NETLABEL) += cipso_ipv4.o ++obj-$(CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION) += tcp_zero_copy.o + + obj-$(CONFIG_XFRM) += xfrm4_policy.o xfrm4_state.o xfrm4_input.o \ + xfrm4_output.o xfrm4_protocol.o +diff -uprN linux-3.10.0-229.el7/net/ipv4/ip_output.c linux-3.10.0-229.el7-patched/net/ipv4/ip_output.c +--- linux-3.10.0-229.el7/net/ipv4/ip_output.c 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/net/ipv4/ip_output.c 2015-04-21 10:15:55.729008747 +0200 +@@ -1047,7 +1047,7 @@ alloc_new_skb: + __skb_fill_page_desc(skb, i, pfrag->page, + pfrag->offset, 0); + skb_shinfo(skb)->nr_frags = ++i; +- get_page(pfrag->page); ++ net_get_page(pfrag->page); + } + copy = min_t(int, copy, pfrag->size - pfrag->offset); + if (getfrag(from, +@@ -1271,7 +1271,7 @@ ssize_t ip_append_page(struct sock *sk, + if (skb_can_coalesce(skb, i, page, offset)) { + skb_frag_size_add(&skb_shinfo(skb)->frags[i-1], len); + } else if (i < MAX_SKB_FRAGS) { +- get_page(page); ++ net_get_page(page); + skb_fill_page_desc(skb, i, page, offset, len); + } else { + err = -EMSGSIZE; +diff -uprN linux-3.10.0-229.el7/net/ipv4/tcp.c linux-3.10.0-229.el7-patched/net/ipv4/tcp.c +--- linux-3.10.0-229.el7/net/ipv4/tcp.c 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/net/ipv4/tcp.c 2015-04-21 10:15:55.730008741 +0200 +@@ -897,7 +897,7 @@ new_segment: + if (can_coalesce) { + skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy); + } else { +- get_page(page); ++ net_get_page(page); + skb_fill_page_desc(skb, i, page, offset, copy); + } + skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG; +@@ -1193,7 +1193,7 @@ new_segment: + } else { + skb_fill_page_desc(skb, i, pfrag->page, + pfrag->offset, copy); +- get_page(pfrag->page); ++ net_get_page(pfrag->page); + } + pfrag->offset += copy; + } +diff -uprN linux-3.10.0-229.el7/net/ipv4/tcp_zero_copy.c linux-3.10.0-229.el7-patched/net/ipv4/tcp_zero_copy.c +--- linux-3.10.0-229.el7/net/ipv4/tcp_zero_copy.c 1970-01-01 01:00:00.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/net/ipv4/tcp_zero_copy.c 2015-04-21 10:15:55.731008735 +0200 +@@ -0,0 +1,50 @@ ++/* ++ * Support routines for TCP zero copy transmit ++ * ++ * Created by Vladislav Bolkhovitin ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU General Public License ++ * version 2 as published by the Free Software Foundation. ++ */ ++ ++#include ++#include ++ ++net_get_page_callback_t net_get_page_callback __read_mostly; ++EXPORT_SYMBOL_GPL(net_get_page_callback); ++ ++net_put_page_callback_t net_put_page_callback __read_mostly; ++EXPORT_SYMBOL_GPL(net_put_page_callback); ++ ++/* ++ * Caller of this function must ensure that at the moment when it's called ++ * there are no pages in the system with net_priv field set to non-zero ++ * value. Hence, this function, as well as net_get_page() and net_put_page(), ++ * don't need any protection. ++ */ ++int net_set_get_put_page_callbacks( ++ net_get_page_callback_t get_callback, ++ net_put_page_callback_t put_callback) ++{ ++ int res = 0; ++ ++ if ((net_get_page_callback != NULL) && (get_callback != NULL) && ++ (net_get_page_callback != get_callback)) { ++ res = -EBUSY; ++ goto out; ++ } ++ ++ if ((net_put_page_callback != NULL) && (put_callback != NULL) && ++ (net_put_page_callback != put_callback)) { ++ res = -EBUSY; ++ goto out; ++ } ++ ++ net_get_page_callback = get_callback; ++ net_put_page_callback = put_callback; ++ ++out: ++ return res; ++} ++EXPORT_SYMBOL_GPL(net_set_get_put_page_callbacks); +diff -uprN linux-3.10.0-229.el7/net/ipv6/ip6_output.c linux-3.10.0-229.el7-patched/net/ipv6/ip6_output.c +--- linux-3.10.0-229.el7/net/ipv6/ip6_output.c 2015-01-30 00:15:53.000000000 +0100 ++++ linux-3.10.0-229.el7-patched/net/ipv6/ip6_output.c 2015-04-21 10:15:55.731008735 +0200 +@@ -1445,7 +1445,7 @@ alloc_new_skb: + __skb_fill_page_desc(skb, i, pfrag->page, + pfrag->offset, 0); + skb_shinfo(skb)->nr_frags = ++i; +- get_page(pfrag->page); ++ net_get_page(pfrag->page); + } + copy = min_t(int, copy, pfrag->size - pfrag->offset); + if (getfrag(from, From f6806b930c5554542d0226de0b776d561e5f5eb8 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 20:18:29 +0000 Subject: [PATCH 17/72] scripts/rebuild-rhel-kernel-rpm: Add RHEL 7.1 support git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6337 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scripts/rebuild-rhel-kernel-rpm | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/scripts/rebuild-rhel-kernel-rpm b/scripts/rebuild-rhel-kernel-rpm index 5e92901df..8f1b01fda 100755 --- a/scripts/rebuild-rhel-kernel-rpm +++ b/scripts/rebuild-rhel-kernel-rpm @@ -440,6 +440,49 @@ patch -p1 ${rpmbuild_dir}/SPECS/kernel.spec <<'EOF' || exit $? make %{?cross_opts} ARCH=$Arch listnewconfig | grep -E '^CONFIG_' >.newoptions || true %if %{listnewconfig_fail} EOF +elif [ ${kver#3.10.0-229} != $kver ]; then +# RHEL/CentOS/SL 7.0 +patch -p1 ${rpmbuild_dir}/SPECS/kernel.spec <<'EOF' || exit $? +--- kernel.spec.orig 2015-04-21 05:31:51.025000000 -0400 ++++ kernel.spec 2015-04-21 05:33:59.806000000 -0400 +@@ -4,6 +4,7 @@ + Summary: The Linux kernel + + # % define buildid .local ++%define buildid .scst + + # For a kernel released for public testing, released_kernel should be 1. + # For internal testing builds during development, it should be 0. +@@ -368,6 +369,9 @@ + Source2000: cpupower.service + Source2001: cpupower.config + ++#Patch200: scst_exec_req_fifo.patch ++Patch201: put_page_callback.patch ++ + # empty final patch to facilitate testing of kernel patches + Patch999999: linux-kernel-test.patch + Patch1000: debrand-single-cpu.patch +@@ -677,6 +681,9 @@ + ApplyOptionalPatch debrand-rh-i686-cpu.patch + # End of CentOS Modification + ++#ApplyPatch scst_exec_req_fifo.patch ++ApplyPatch put_page_callback.patch ++ + ApplyOptionalPatch linux-kernel-test.patch + + # Any further pre-build tree manipulations happen here. +@@ -709,6 +716,8 @@ + for i in *.config + do + mv $i .config ++ echo "CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION=y" >> .config ++ sed -i.tmp -e 's/^CONFIG_SCSI_QLA_FC=.*/CONFIG_SCSI_QLA_FC=n/' .config + Arch=`head -1 .config | cut -b 3-` + make %{?cross_opts} ARCH=$Arch listnewconfig | grep -E '^CONFIG_' >.newoptions || true + %if %{listnewconfig_fail} +EOF else log "Unrecognized kernel version ${kver}" fi From 3fe91cf714bfa2851fd47442da0fa7554277fd66 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 20:21:22 +0000 Subject: [PATCH 18/72] scst_vdisk: Fix error handling in __vdev_load_mode_pages() Avoid that unknown parameters cause __vdev_load_mode_pages() to return 0 instead of -EINVAL. Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6338 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index b2ea17676..f90d1ab90 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -1217,7 +1217,7 @@ out: /* Params are NULL-terminated */ static int __vdev_load_mode_pages(struct scst_vdisk_dev *virt_dev, char *params) { - int res; + int res = 0; char *param, *p, *pp; unsigned long val; @@ -1252,14 +1252,11 @@ static int __vdev_load_mode_pages(struct scst_vdisk_dev *virt_dev, char *params) else { TRACE_DBG("Unknown parameter %s", p); res = -EINVAL; - break; } if (res != 0) - goto out; + break; } - res = 0; - out: TRACE_EXIT_RES(res); return res; From 269d417601717dd277a4b2b6be5e959f4334bbc3 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 20:23:17 +0000 Subject: [PATCH 19/72] scst_debug(): Avoid that debug_print_with_prefix() overflows the output buffer Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6339 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scst/src/scst_debug.c b/scst/src/scst_debug.c index 40b8f54dd..88acf74e9 100644 --- a/scst/src/scst_debug.c +++ b/scst/src/scst_debug.c @@ -75,11 +75,11 @@ int debug_print_with_prefix(unsigned long trace_flag, const char *severity, spin_lock_irqsave(&trace_buf_lock, flags); - strcpy(trace_buf, severity); + strlcpy(trace_buf, severity, TRACE_BUF_SIZE); i = strlen(trace_buf); if (trace_flag & TRACE_PID) - i += snprintf(&trace_buf[i], TRACE_BUF_SIZE, "[%d]: ", pid); + i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i, "[%d]: ", pid); if (prefix != NULL) i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i, "%s: ", prefix); From f272064c12ddabe59037ec52ade5f4905c912be4 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:10:28 +0000 Subject: [PATCH 20/72] iscsi-scst: Suppress put_page_callback patch warnings The put_page_callback patch only improves performance on single socket systems but not on systems with multiple CPU sockets. Since this message is confusing to SCST users, do not print a warning if the put_page_callback patch has not been applied. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6340 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/iscsi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iscsi-scst/kernel/iscsi.c b/iscsi-scst/kernel/iscsi.c index 30df54f9d..c01d9636a 100644 --- a/iscsi-scst/kernel/iscsi.c +++ b/iscsi-scst/kernel/iscsi.c @@ -31,7 +31,7 @@ #include "iscsi.h" #include "digest.h" -#ifndef GENERATING_UPSTREAM_PATCH +#if 0 && !defined(GENERATING_UPSTREAM_PATCH) #if !defined(CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION) #warning Patch put_page_callback-.patch not applied on your \ kernel or CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION \ @@ -4298,7 +4298,7 @@ static int __init iscsi_init(void) goto out_destroy_mempool; } #else -#ifndef GENERATING_UPSTREAM_PATCH +#if 0 && !defined(GENERATING_UPSTREAM_PATCH) PRINT_WARNING("%s", "CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION " "not enabled in your kernel. ISCSI-SCST will be working with " From 4efcfc7bfde6fd40e96cc89ccd283e5a21a423ca Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:43:31 +0000 Subject: [PATCH 21/72] scst: Remove dead code from scst_assign_dev_handler() The BUG_ON(handler == NULL) statement at the start of this function guarantees that handler != NULL. Hence remove the remaining tests of the 'handler' pointer. Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6341 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_main.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index 63e7b7ab8..34f921728 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -2103,10 +2103,6 @@ int scst_assign_dev_handler(struct scst_device *dev, assign: dev->handler = handler; - - if (handler == NULL) - goto out; - dev->threads_num = handler->threads_num; dev->threads_pool_type = handler->threads_pool_type; dev->max_write_same_len = 256 * 1024 * 1024; /* 256 MB */ @@ -2152,7 +2148,7 @@ out: return res; out_err_detach_tgt: - if (handler && handler->detach_tgt) { + if (handler->detach_tgt) { list_for_each_entry(tgt_dev, &attached_tgt_devs, extra_tgt_dev_list_entry) { TRACE_DBG("Calling handler's detach_tgt(%p)", @@ -2165,7 +2161,7 @@ out_err_detach_tgt: scst_devt_dev_sysfs_del(dev); out_detach: - if (handler && handler->detach) { + if (handler->detach) { TRACE_DBG("%s", "Calling handler's detach()"); handler->detach(dev); TRACE_DBG("%s", "Handler's detach() returned"); From 1eb5498df2af9ab1175f9a397c566c587f310878 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:44:28 +0000 Subject: [PATCH 22/72] scst_local: Correct error handling in scst_local_sysfs_mgmt_cmd() Avoid that __scst_local_add_adapter() failures are ignored. Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6342 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst_local/scst_local.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scst_local/scst_local.c b/scst_local/scst_local.c index 92a971326..abae3052f 100644 --- a/scst_local/scst_local.c +++ b/scst_local/scst_local.c @@ -733,7 +733,7 @@ out_up: static ssize_t scst_local_sysfs_mgmt_cmd(char *buf) { - ssize_t res; + ssize_t res = 0; char *command, *target_name, *session_name; struct scst_local_tgt *t, *tgt; @@ -793,8 +793,6 @@ static ssize_t scst_local_sysfs_mgmt_cmd(char *buf) scst_local_close_session_impl(sess, false); } - res = 0; - out_unlock: mutex_unlock(&scst_local_mutex); From ac45265fd034c00838739a78ffdd94a0f53eaca0 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:45:15 +0000 Subject: [PATCH 23/72] scst_local: Fix scst_local_add_target() error path Do not return a pointer to freed memory in *out_tgt. Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6343 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst_local/scst_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scst_local/scst_local.c b/scst_local/scst_local.c index abae3052f..5f3564c63 100644 --- a/scst_local/scst_local.c +++ b/scst_local/scst_local.c @@ -1968,10 +1968,10 @@ static int scst_local_add_target(const char *target_name, res = 0; -out: if (out_tgt != NULL) *out_tgt = tgt; +out: TRACE_EXIT_RES(res); return res; From a0e4cc7288acd1addafd5c961ad4b5a246dbb7d7 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:45:51 +0000 Subject: [PATCH 24/72] fileio: Remove dead code There is no FUA bit in WRITE VERIFY commands. Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6344 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- usr/fileio/common.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/usr/fileio/common.c b/usr/fileio/common.c index 475704810..ecc91a77c 100644 --- a/usr/fileio/common.c +++ b/usr/fileio/common.c @@ -325,8 +325,6 @@ static int do_exec(struct vdisk_cmd *vcmd) /* O_DSYNC flag is used for WT devices */ if (reply->status == 0) exec_verify(vcmd, loff); - else if (fua) - exec_fsync(vcmd); } else { PRINT_WARNING("Attempt to write to read-only " "device %s", dev->name); From 69569b0cdf30fd2f3988f12c7c56248481cea319 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:46:17 +0000 Subject: [PATCH 25/72] fcst: Display RXID in SCST error messages git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6345 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- fcst/ft_cmd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fcst/ft_cmd.c b/fcst/ft_cmd.c index 3900e425d..e0b0baa2f 100644 --- a/fcst/ft_cmd.c +++ b/fcst/ft_cmd.c @@ -772,6 +772,7 @@ static void ft_recv_cmd(struct ft_sess *sess, struct fc_frame *fp) break; } + scst_cmd_set_tag(cmd, fc_seq_exch(sp)->rxid); scst_cmd_init_done(cmd, SCST_CONTEXT_THREAD); return; From 20986f4c1b900c3d0e425e5ed93ccc90e40893cd Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:49:18 +0000 Subject: [PATCH 26/72] scst_lib: Make a WRITE SAME debug statement more informative If a data length mismatch has been detected, report the LBA and the lengths that do not match. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6346 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 43a80154e..97cf59e8a 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -5491,7 +5491,11 @@ static int scst_ws_push_single_write(struct scst_write_same_priv *wsp, TRACE_ENTRY(); - EXTRACHECKS_BUG_ON(len != sg_data_length(wsp->ws_sg, wsp->ws_sg_cnt)); +#ifdef CONFIG_SCST_EXTRACHECKS + if (len != sg_data_length(wsp->ws_sg, wsp->ws_sg_cnt)) + WARN_ONCE(true, "lba %lld: %d <> %lld\n", lba, len, + sg_data_length(wsp->ws_sg, wsp->ws_sg_cnt)); +#endif if (unlikely(test_bit(SCST_CMD_ABORTED, &ws_cmd->cmd_flags)) || unlikely(ws_cmd->completed)) { From 47efee04ce7f7b9eb5dddcf4531de66baea05e87 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:51:26 +0000 Subject: [PATCH 27/72] scst: Fix WRITE SAME parsing Check bit 4 instead of bit 0 as the ANCHOR bit. Handle the NDOB bit correctly. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6347 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 6 +++-- scst/src/scst_lib.c | 38 +++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index f90d1ab90..6c826d2b4 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -3696,14 +3696,16 @@ static enum compl_status_e vdisk_exec_write_same(struct vdisk_cmd_params *p) TRACE_ENTRY(); - if (unlikely(cmd->cdb[ctrl_offs] & 1)) { + if (unlikely(cmd->cdb[ctrl_offs] & 0x10)) { TRACE_DBG("%s", "ANCHOR not supported"); scst_set_invalid_field_in_cdb(cmd, ctrl_offs, - SCST_INVAL_FIELD_BIT_OFFS_VALID | 0); + SCST_INVAL_FIELD_BIT_OFFS_VALID | 4); goto out; } if (unlikely(cmd->data_len <= 0)) { + PRINT_ERROR("WRITE SAME: refused data_len = %#llx", + cmd->data_len); scst_set_invalid_field_in_cdb(cmd, cmd->len_off, 0); goto out; } diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 97cf59e8a..901d7409f 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -10154,31 +10154,57 @@ static int get_cdb_info_lba_8_len_4_rdprotect32(struct scst_cmd *cmd, return scst_parse_rdprotect32(cmd); } +static int get_cdb_info_write_same(struct scst_cmd *cmd, + const struct scst_sdbops *sdbops, + const bool ndob) +{ + const uint8_t ctrl_offs = cmd->cdb_len < 32 ? 1 : 10; + const bool anchor = (cmd->cdb[ctrl_offs] >> 4) & 1; + const bool unmap = (cmd->cdb[ctrl_offs] >> 3) & 1; + + if (!unmap && (anchor || ndob)) { + PRINT_ERROR("Received invalid %s command (UNMAP = %d;" + " ANCHOR = %d; NDOB = %d)", + scst_get_opcode_name(cmd), unmap, anchor, ndob); + scst_set_invalid_field_in_cdb(cmd, ctrl_offs, + SCST_INVAL_FIELD_BIT_OFFS_VALID | (ndob ? 0 : 4)); + return 1; + } + + if (ndob) { + cmd->bufflen = 0; + cmd->data_direction = SCST_DATA_NONE; + } else { + cmd->bufflen = 1; + cmd->data_direction = SCST_DATA_WRITE; + } + + return cmd->cdb_len < 32 ? scst_parse_wrprotect(cmd) : + scst_parse_wrprotect32(cmd); +} + static int get_cdb_info_write_same10(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { cmd->lba = get_unaligned_be32(cmd->cdb + sdbops->info_lba_off); - cmd->bufflen = 1; cmd->data_len = get_unaligned_be16(cmd->cdb + sdbops->info_len_off); - return scst_parse_wrprotect(cmd); + return get_cdb_info_write_same(cmd, sdbops, false); } static int get_cdb_info_write_same16(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { cmd->lba = get_unaligned_be64(cmd->cdb + sdbops->info_lba_off); - cmd->bufflen = 1; cmd->data_len = get_unaligned_be32(cmd->cdb + sdbops->info_len_off); - return scst_parse_wrprotect(cmd); + return get_cdb_info_write_same(cmd, sdbops, cmd->cdb[1] & 1 /*NDOB*/); } static int get_cdb_info_write_same32(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { cmd->lba = get_unaligned_be64(cmd->cdb + sdbops->info_lba_off); - cmd->bufflen = 1; cmd->data_len = get_unaligned_be32(cmd->cdb + sdbops->info_len_off); - return scst_parse_wrprotect32(cmd); + return get_cdb_info_write_same(cmd, sdbops, cmd->cdb[1] & 1 /*NDOB*/); } static int scst_set_cmd_from_cdb_info(struct scst_cmd *cmd, From dce5cbc1cb5e790a9a63e1f4a8359934cfb969f9 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:52:10 +0000 Subject: [PATCH 28/72] iscsi-scst/README: Add a reference git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6348 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/README | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iscsi-scst/README b/iscsi-scst/README index db82baa7e..95580266d 100644 --- a/iscsi-scst/README +++ b/iscsi-scst/README @@ -994,8 +994,10 @@ Notes: References: [1] James Bottomley, Linux Kernel Mailing List, December 2008, http://lkml.org/lkml/2008/12/11/213. -[2] Ian Campbell, [PATCH v5 0/9] skb paged fragment destructors, May 3 2012, - linux-netdev, http://marc.info/?l=linux-netdev&m=133605705111948&w=2. +[2] Alex Bligh, Rebase Ian Campbell's skb fragment tracking to 3.2, January + 2013, linux-netdev, http://thread.gmane.org/gmane.linux.network/256820/. +[3] Ian Campbell, [PATCH v5 0/9] skb paged fragment destructors, May 3 2012, + linux-netdev, http://thread.gmane.org/gmane.linux.network/229669. Credits From ae2534f0a60811b6e7dfb3d713806fda9b7dfe02 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:53:00 +0000 Subject: [PATCH 29/72] qla2x00t: Update how-to with instructions for 16 Gb/s HBA Add instructions for how to download and install the 16 Gb/s FC HBA driver. Remove the "optional step" since this step should not be needed after various recent fixes in the SCST makefiles. Recommend to blacklist the distro QLA initiator driver even if the kernel is not being rebuilt. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6349 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- qla2x00t/doc/qla2x00t-howto.html | 105 ++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 37 deletions(-) diff --git a/qla2x00t/doc/qla2x00t-howto.html b/qla2x00t/doc/qla2x00t-howto.html index 4ed582fd4..2f3195e53 100644 --- a/qla2x00t/doc/qla2x00t-howto.html +++ b/qla2x00t/doc/qla2x00t-howto.html @@ -4,7 +4,7 @@ -How to configure QLogic target driver for 22xx/23xx/24xx/25xx adapters +QLogic FC Target Driver How-to for 22xx/23xx/24xx/25xx/26xx Adapters -
How to configure QLogic target driver for 22xx/23xx/24xx/25xx adapters. Step by step guide.

+
How to Configure the FC QLogic Target Driver for 22xx/23xx/24xx/25xx/26xx Adapters

-
ON TARGET


+
TARGET SYSTEM


  1. - Download the appropriate firmware for your QLogic card from - http://ldriver.qlogic.com/firmware/ and save it in the /lib/firmware directory. + Look up the model numbers of the FC HBA and of the FC HBA RISC controller. If + it is not easy to access the label printed on the HBA, one way to look up + these model numbers is as follows: +
    [root@proj ]# dmesg -c >/dev/null
    +[root@proj ]# rmmod qla2xxx
    +[root@proj ]# modprobe qla2xxx
    +[root@proj ]# dmesg | grep -E 'qla2xxx .* QLogic | Found an ISP'
    +qla2xxx [0000:01:00.0]-001d: Found an ISP2532 irq 16 iobase 0xffffc9000413e000.
    +qla2xxx [0000:01:00.0]-00fb:164: QLogic QLE2562 - PCI-Express Dual Channel 8Gb Fibre Channel HBA.
    +qla2xxx [0000:01:00.1]-001d: Found an ISP2532 irq 17 iobase 0xffffc9000417c000.
    +qla2xxx [0000:01:00.1]-00fb:165: QLogic QLE2562 - PCI-Express Dual Channel 8Gb Fibre Channel HBA.
    + The above information not only contains the HBA model number (QLE2562) but + also the RISC controller ID (ISP2532). +
  2. +
  3. Download the Linux version of the QConvergeConsoleCLI software package + from http://driverdownloads.qlogic.com/ + and install that software package. +
  4. +
  5. + Download the appropriate firmware for your QLogic card from + http://driverdownloads.qlogic.com/. It is strongly recommended to use firmware version 5.x or higher for 24xx/25xx adapters. More information about this subject can be found in - the following thread on the scst-devel mailing list: - FC - session gets closed with qla2x00t. + the following e-mail thread: Vladislav Bolkhovitin and Artur Piechocki, + FC + session gets closed with qla2x00t, scst-devel mailing list, January 2010.

    If no firmware image is available when the QLogic kernel module is loaded, - the following error message will appear in the kernel log - (/var/log/messages): + the following error message will appear in the system log + (/var/log/messages or /var/log/syslog):
    qla2xxx 0000:13:00.0: Firmware image unavailable.
     qla2xxx 0000:13:00.0: Failed to initialize adapter
    - - In this case I had to download ql2500_fw.bin.
  6. +
  7. + Copy the firmware image (.BIN) file to the /lib/firmware directory and + rename it such that the kernel driver can find it. The file name that should + be used for the firmware file depends on the RISC controller ID: + + + + + + + + + + +
    ISP ModelFirmware file
    name
    ISP 21XXql2100_fw.bin
    ISP 22XXql2200_fw.bin
    ISP 2300ql2300_fw.bin
    ISP 2322ql2322_fw.bin
    ISP 24XXql2400_fw.bin
    ISP 25XXql2500_fw.bin
    ISP 2031ql2600_fw.bin
    ISP 27XXql2700_fw.bin
    +
  8. +
  9. + Update the firmware image in the HBA. Although the QLogic kernel driver is + able to load the firmware from /lib/firmware, QLogic recommends to update + the firmware image that resides in the HBA (see also Quinn Tran, + Re: + [ANNOUNCE]: qla2x00t QLogic git integration into the SCST build + tree, scst-devel mailing list, September 5, 2014). An example: +
    [root@proj ]# /opt/QLogic_Corporation/QConvergeConsoleCLI/qaucli -fc -b all /lib/firmware/ql2500_fw.bin
    +
  10. Install the necessary kernel development packages. On a Debian system these packages can be installed as follows:
    [root@proj ]# apt-get install gcc libncurses5-dev linux-headers-`uname -r` lsscsi patch subversion
    @@ -47,6 +89,11 @@ And on SUSE systems these packages can be installed by running the following com
    [root@proj ]# zypper install gcc ncurses-devel kernel-devel lsscsi patch subversion
  11. +
  12. + Download the latest QLogic SCST target driver: +
    [root@proj ]# git clone git://git.qlogic.com/scst-qla2xxx.git
    +
  13. +
  14. Download the SCST source code. That source code can be downloaded either from the SCST @@ -65,10 +112,16 @@ And on SUSE systems these packages can be installed by running the following com created in the current directory, which is /root in this how-to.
  15. +
  16. + In the SCST directory, create a soft link to the QLogic driver: +
    [root@proj ]# cd scst
    +[root@proj scst]# ln -s ../scst-qla2xxx/drivers/scsi/qla2xxx qla2x00t_git
    +
  17. +
  18. Find out whether you will need SCSI pass-through and/or the iSCSI zero-copy optimization. If not, skip the kernel download, patch, rebuild -and reboot steps and continue with the SCST build step. +and reboot steps and continue with the SCST build step.
  19. Decide whether you want to start from a vanilla Linux kernel source tree @@ -104,34 +157,12 @@ CONFIG_NOHIGHMEM=y Reboot the system and during boot select the freshly built kernel to boot from.
  20. -
  21. +
  22. Unload the qla2xxx kernel module provided by your Linux distribution and blacklist it:
    [root@proj ]# echo blacklist qla2xxx >/etc/modprobe.d/blacklist-qla2xxx.conf
     [root@proj ]# rmmod qla2xxx
  23. -
  24. - OPTIONAL step: clean up the kernel modules directory before building the - SCST kernel modules.
    This is only necessary if you encounter the - following error message: "scst: disagrees about version of symbol - struct_module".

    - - That error message indicates that a kernel module was compiled against - kernel headers that did not match the running kernel. Doing a clean rebuild - of the kernel and SCST should make the above error go away. To make sure - nothing of the old kernel is left, do a clean rebuild of the Linux kernel - and SCST as follows: - -
    [root@proj linux ]# pwd
    -/usr/src/linux
    -[root@proj linux ]# make oldconfig
    -[root@proj linux ]# make clean
    -[root@proj linux ]# rm -rf /lib/modules/`uname -r`
    -[root@proj linux ]# make -j$(ls -1d /sys/devices/system/cpu/cpu[0-9]* | wc -l) bzImage modules
    -[root@proj linux ]# make modules_install install
    -[root@proj linux ]# reboot
    -
  25. -
  26. Select a build mode that suits your needs, e.g. optimal performance or debugging SCST. The default mode is debug mode. Here is how to switch to @@ -318,7 +349,7 @@ The same can be done directly via the sysfs interface of SCST:

-
ON INITIATOR
+
INITIATOR SYSTEM

    From a0f46a0a6938d8b540465d950a7ad5824a61b567 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:53:43 +0000 Subject: [PATCH 30/72] scst_lib: WRITE SAME performance improvement fix Fix the argument of the second kunmap() call. Detected by smatch. See also patch "scst_lib: Improve WRITE SAME performance" (commit ID a15628d68309). Note: this patch does not have any impact on 64-bit architectures since kunmap() doesn't to anything on such architectures. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6350 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 901d7409f..87efc4dc6 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -5877,16 +5877,18 @@ void scst_write_same(struct scst_cmd *cmd) if (cmd->bufflen <= PAGE_SIZE / 2) pg = alloc_page(GFP_KERNEL); if (pg) { + struct page *src_pg; void *src, *dst; int k; mult = 0; - src = kmap(sg_page(cmd->sg)); + src_pg = sg_page(cmd->sg); + src = kmap(src_pg); dst = kmap(pg); for (k = 0; k < PAGE_SIZE; k += cmd->bufflen, mult++) memcpy(dst + k, src + cmd->sg->offset, cmd->bufflen); kunmap(pg); - kunmap(src); + kunmap(src_pg); offset = 0; length = k; } else { From 29d11c1ee20099b7389409e33321a773f272d3ed Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:54:14 +0000 Subject: [PATCH 31/72] scst_user: Fix indentation Detected by smatch. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6351 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scst/src/dev_handlers/scst_user.c b/scst/src/dev_handlers/scst_user.c index 2d45bb4f1..9c2ac3bc4 100644 --- a/scst/src/dev_handlers/scst_user.c +++ b/scst/src/dev_handlers/scst_user.c @@ -1487,7 +1487,7 @@ static int dev_user_process_reply_exec(struct scst_user_cmd *ucmd, cmd->atomic = 0; - if (ereply->resp_data_len != 0) { + if (ereply->resp_data_len != 0) { if (ucmd->ubuff == 0) { int pages, rc; if (unlikely(ereply->pbuf == 0)) From bf0fdcb36d272eec0d7050ac3d84f9feee73dab1 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:54:47 +0000 Subject: [PATCH 32/72] scst_proc: Indent consistently Detected by smatch. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6352 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_proc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scst/src/scst_proc.c b/scst/src/scst_proc.c index e430c1a36..a7f2169b5 100644 --- a/scst/src/scst_proc.c +++ b/scst/src/scst_proc.c @@ -1699,15 +1699,15 @@ static ssize_t scst_proc_scsi_tgt_gen_write(struct file *file, while (!isspace(*ppp) && *ppp != '\0') ppp++; if (*ppp != '\0') { - *ppp = '\0'; + *ppp = '\0'; ppp++; while (isspace(*ppp) && *ppp != '\0') ppp++; if (*ppp != '\0') { PRINT_ERROR("%s", "Too many " "arguments"); - res = -EINVAL; - goto out_up_free; + res = -EINVAL; + goto out_up_free; } } if (strcasecmp(pp, "FLAT") == 0) From eb10fe3f7d1d563d15d1cb2c0fdb41bf2631a240 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:55:22 +0000 Subject: [PATCH 33/72] iscsi-scst: Surround complex values with parentheses Detected by checkpatch. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6353 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/param.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iscsi-scst/kernel/param.c b/iscsi-scst/kernel/param.c index 525cd633a..3a703bf3b 100644 --- a/iscsi-scst/kernel/param.c +++ b/iscsi-scst/kernel/param.c @@ -50,7 +50,7 @@ do { \ }) #define GET_PARAM(params, info, iparams, word) \ - (iparams)[key_##word] = (params)->word + ((iparams)[key_##word] = (params)->word) const char *iscsi_get_bool_value(int val) { From 612fac98740001689074f53af484870649bff1b3 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:55:52 +0000 Subject: [PATCH 34/72] isert: Declare a local function static Detected by checkpatch. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6354 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/isert-scst/iser_rdma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iscsi-scst/kernel/isert-scst/iser_rdma.c b/iscsi-scst/kernel/isert-scst/iser_rdma.c index ad0f402b5..635d429c2 100644 --- a/iscsi-scst/kernel/isert-scst/iser_rdma.c +++ b/iscsi-scst/kernel/isert-scst/iser_rdma.c @@ -45,7 +45,7 @@ static DEFINE_MUTEX(dev_list_mutex); -void isert_portal_free(struct isert_portal *portal); +static void isert_portal_free(struct isert_portal *portal); static int isert_num_recv_posted_on_err(struct ib_recv_wr *first_ib_wr, struct ib_recv_wr *bad_wr) @@ -1658,7 +1658,7 @@ out: return err; } -void isert_portal_free(struct isert_portal *portal) +static void isert_portal_free(struct isert_portal *portal) { lockdep_assert_held(&dev_list_mutex); From e31d1999f38f1dfce5997d36e7371fd786b9839e Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 16 Jun 2015 23:59:38 +0000 Subject: [PATCH 35/72] dev_handlers: Report invalid block sizes If while attaching a pass-through device the READ CAPACITY command reports an invalid sector size, log an error message. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6355 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_cdrom.c | 6 ++++++ scst/src/dev_handlers/scst_disk.c | 6 ++++++ scst/src/dev_handlers/scst_modisk.c | 6 ++++++ scst/src/dev_handlers/scst_user.c | 9 ++++++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/scst/src/dev_handlers/scst_cdrom.c b/scst/src/dev_handlers/scst_cdrom.c index 1e5826d77..a08999b4f 100644 --- a/scst/src/dev_handlers/scst_cdrom.c +++ b/scst/src/dev_handlers/scst_cdrom.c @@ -129,6 +129,12 @@ static int cdrom_attach(struct scst_device *dev) dev->block_shift = scst_calc_block_shift(sector_size); TRACE_DBG("Sector size is %i scsi_level %d(SCSI_2 %d)", sector_size, dev->scsi_dev->scsi_level, SCSI_2); + if (dev->block_shift < 9) { + PRINT_ERROR("READ CAPACITY reported an invalid sector size: %d", + sector_size); + res = -EINVAL; + goto out_free_buf; + } } else { dev->block_shift = CDROM_DEF_BLOCK_SHIFT; TRACE(TRACE_MINOR, "Read capacity failed: %x, using default " diff --git a/scst/src/dev_handlers/scst_disk.c b/scst/src/dev_handlers/scst_disk.c index 9ef9e8682..a56cc204c 100644 --- a/scst/src/dev_handlers/scst_disk.c +++ b/scst/src/dev_handlers/scst_disk.c @@ -221,6 +221,12 @@ static int disk_attach(struct scst_device *dev) dev->block_shift = DISK_DEF_BLOCK_SHIFT; else dev->block_shift = scst_calc_block_shift(sector_size); + if (dev->block_shift < 9) { + PRINT_ERROR("READ CAPACITY reported an invalid sector size: %d", + sector_size); + res = -EINVAL; + goto out_free_buf; + } } else { dev->block_shift = DISK_DEF_BLOCK_SHIFT; TRACE(TRACE_MINOR, "Read capacity failed: %x, using default " diff --git a/scst/src/dev_handlers/scst_modisk.c b/scst/src/dev_handlers/scst_modisk.c index b3461b1a9..850f8efe2 100644 --- a/scst/src/dev_handlers/scst_modisk.c +++ b/scst/src/dev_handlers/scst_modisk.c @@ -228,6 +228,12 @@ static int modisk_attach(struct scst_device *dev) dev->block_shift = scst_calc_block_shift(sector_size); TRACE_DBG("Sector size is %i scsi_level %d(SCSI_2 %d)", sector_size, dev->scsi_dev->scsi_level, SCSI_2); + if (dev->block_shift < 9) { + PRINT_ERROR("READ CAPACITY reported an invalid sector size: %d", + sector_size); + res = -EINVAL; + goto out_free_buf; + } } else { dev->block_shift = MODISK_DEF_BLOCK_SHIFT; TRACE(TRACE_MINOR, "Read capacity failed: %x, using default " diff --git a/scst/src/dev_handlers/scst_user.c b/scst/src/dev_handlers/scst_user.c index 9c2ac3bc4..60a5077e2 100644 --- a/scst/src/dev_handlers/scst_user.c +++ b/scst/src/dev_handlers/scst_user.c @@ -1030,7 +1030,9 @@ static void dev_user_set_block_shift(struct scst_cmd *cmd, int block_shift) */ new_block_shift = block_shift ? : scst_calc_block_shift(udev->def_block_size); - if (dev->block_shift != new_block_shift) { + if (new_block_shift < 9) { + PRINT_ERROR("Invalid block shift %d", new_block_shift); + } else if (dev->block_shift != new_block_shift) { PRINT_INFO("%s: Changed block shift from %d into %d / %d", dev->virt_name, dev->block_shift, block_shift, new_block_shift); @@ -2582,6 +2584,11 @@ static int dev_user_attach(struct scst_device *sdev) case TYPE_ROM: case TYPE_MOD: sdev->block_shift = scst_calc_block_shift(sdev->block_size); + if (sdev->block_shift < 9) { + PRINT_ERROR("Invalid block size %d", sdev->block_size); + res = -EINVAL; + goto out; + } break; default: sdev->block_shift = -1; /* not used */ From a6f9f870b32c9c26311a718289fbeb89ea39801e Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:00:40 +0000 Subject: [PATCH 36/72] scst_lib: Fix a use-after-free in an error path scst_free_tgt_dev() frees the memory tgt_dev points at which means that list_for_each_entry_safe() is needed here. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6356 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 87efc4dc6..37e242f8f 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -4167,7 +4167,7 @@ int scst_acg_add_lun(struct scst_acg *acg, struct kobject *parent, { int res; struct scst_acg_dev *acg_dev; - struct scst_tgt_dev *tgt_dev; + struct scst_tgt_dev *tgt_dev, *tt; struct scst_session *sess; LIST_HEAD(tmp_tgt_dev_list); @@ -4229,7 +4229,7 @@ out: return res; out_free: - list_for_each_entry(tgt_dev, &tmp_tgt_dev_list, + list_for_each_entry_safe(tgt_dev, tt, &tmp_tgt_dev_list, extra_tgt_dev_list_entry) { scst_free_tgt_dev(tgt_dev); } From b6c00bfba160b2ea36a46c74548544d1eadcf7e9 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:01:24 +0000 Subject: [PATCH 37/72] scst_targ: Add more debug code in scst_unblock_aborted_cmds() Use lockdep to verify that the caller holds scst_mutex if the scst_mutex_held argument has not been set. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6357 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_targ.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 17aa700a0..232b87a84 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -5617,6 +5617,8 @@ void scst_unblock_aborted_cmds(const struct scst_tgt *tgt, if (!scst_mutex_held) mutex_lock(&scst_mutex); + else + lockdep_assert_held(&scst_mutex); list_for_each_entry(dev, &scst_dev_list, dev_list_entry) { struct scst_cmd *cmd, *tcmd; From b936c235435f63c9586dad0669e9be580c284b5f Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:03:35 +0000 Subject: [PATCH 38/72] qla2xxx: Declare local symbols 'static' Additionally, remove unused code. Detected by sparse. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6358 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- qla2x00t/qla2x00-target/qla2x00t.c | 6 ++-- qla2x00t/qla_init.c | 3 +- qla2x00t/qla_nx.c | 47 +++++++----------------------- qla2x00t/qla_os.c | 2 +- 4 files changed, 16 insertions(+), 42 deletions(-) diff --git a/qla2x00t/qla2x00-target/qla2x00t.c b/qla2x00t/qla2x00-target/qla2x00t.c index d047c5c7e..70612dccb 100644 --- a/qla2x00t/qla2x00-target/qla2x00t.c +++ b/qla2x00t/qla2x00-target/qla2x00t.c @@ -114,7 +114,7 @@ static ssize_t q2t_version_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf); -struct kobj_attribute q2t_version_attr = +static struct kobj_attribute q2t_version_attr = __ATTR(version, S_IRUGO, q2t_version_show, NULL); static const struct attribute *q2tt_attrs[] = { @@ -127,14 +127,14 @@ static ssize_t q2t_show_expl_conf_enabled(struct kobject *kobj, static ssize_t q2t_store_expl_conf_enabled(struct kobject *kobj, struct kobj_attribute *attr, const char *buffer, size_t size); -struct kobj_attribute q2t_expl_conf_attr = +static struct kobj_attribute q2t_expl_conf_attr = __ATTR(explicit_confirmation, S_IRUGO|S_IWUSR, q2t_show_expl_conf_enabled, q2t_store_expl_conf_enabled); static ssize_t q2t_abort_isp_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buffer, size_t size); -struct kobj_attribute q2t_abort_isp_attr = +static struct kobj_attribute q2t_abort_isp_attr = __ATTR(abort_isp, S_IWUSR, NULL, q2t_abort_isp_store); static ssize_t q2t_hw_target_show(struct kobject *kobj, diff --git a/qla2x00t/qla_init.c b/qla2x00t/qla_init.c index 4a65cc235..074ce7300 100644 --- a/qla2x00t/qla_init.c +++ b/qla2x00t/qla_init.c @@ -923,8 +923,7 @@ qla2x00_reset_chip(scsi_qla_host_t *vha) * * Returns 0 on success. */ -int -qla81xx_reset_mpi(scsi_qla_host_t *vha) +static int qla81xx_reset_mpi(scsi_qla_host_t *vha) { uint16_t mb[4] = {0x1010, 0, 1, 0}; diff --git a/qla2x00t/qla_nx.c b/qla2x00t/qla_nx.c index b0bad5671..266c1a15d 100644 --- a/qla2x00t/qla_nx.c +++ b/qla2x00t/qla_nx.c @@ -36,7 +36,7 @@ #define MAX_CRB_XFORM 60 static unsigned long crb_addr_xform[MAX_CRB_XFORM]; -int qla82xx_crb_table_initialized; +static int qla82xx_crb_table_initialized; #define qla82xx_crb_addr_transform(name) \ (crb_addr_xform[QLA82XX_HW_PX_MAP_CRB_##name] = \ @@ -102,7 +102,7 @@ static void qla82xx_crb_addr_transform_setup(void) qla82xx_crb_table_initialized = 1; } -struct crb_128M_2M_block_map crb_128M_2M_map[64] = { +static struct crb_128M_2M_block_map crb_128M_2M_map[64] = { {{{0, 0, 0, 0} } }, {{{1, 0x0100000, 0x0102000, 0x120000}, {1, 0x0110000, 0x0120000, 0x130000}, @@ -262,7 +262,7 @@ struct crb_128M_2M_block_map crb_128M_2M_map[64] = { /* * top 12 bits of crb internal address (hub, agent) */ -unsigned qla82xx_crb_hub_agt[64] = +static unsigned qla82xx_crb_hub_agt[64] = { 0, QLA82XX_HW_CRB_HUB_AGT_ADR_PS, @@ -331,7 +331,7 @@ unsigned qla82xx_crb_hub_agt[64] = }; /* Device states */ -char *q_dev_state[] = { +static char *q_dev_state[] = { "Unknown", "Cold", "Initializing", @@ -474,8 +474,7 @@ qla82xx_pci_get_crb_addr_2M(struct qla_hw_data *ha, ulong *off) return 1; } -int -qla82xx_wr_32(struct qla_hw_data *ha, ulong off, u32 data) +int qla82xx_wr_32(struct qla_hw_data *ha, ulong off, u32 data) { unsigned long flags = 0; int rv; @@ -499,8 +498,7 @@ qla82xx_wr_32(struct qla_hw_data *ha, ulong off, u32 data) return 0; } -int -qla82xx_rd_32(struct qla_hw_data *ha, ulong off) +int qla82xx_rd_32(struct qla_hw_data *ha, ulong off) { unsigned long flags = 0; int rv; @@ -584,7 +582,7 @@ qla82xx_pci_mem_bound_check(struct qla_hw_data *ha, return 1; } -int qla82xx_pci_set_window_warning_count; +static int qla82xx_pci_set_window_warning_count; static unsigned long qla82xx_pci_set_window(struct qla_hw_data *ha, unsigned long long addr) @@ -927,7 +925,7 @@ qla82xx_wait_rom_done(struct qla_hw_data *ha) return 0; } -int +static int qla82xx_md_rw_32(struct qla_hw_data *ha, uint32_t off, u32 data, uint8_t flag) { uint32_t off_value, rval = 0; @@ -1784,14 +1782,6 @@ qla82xx_config_rings(struct scsi_qla_host *vha) WRT_REG_DWORD((unsigned long __iomem *)®->rsp_q_out[0], 0); } -void qla82xx_reset_adapter(struct scsi_qla_host *vha) -{ - struct qla_hw_data *ha = vha->hw; - vha->flags.online = 0; - qla2x00_try_to_stop_firmware(vha); - ha->isp_ops->disable_intrs(ha); -} - static int qla82xx_fw_load_from_blob(struct qla_hw_data *ha) { @@ -1875,7 +1865,7 @@ qla82xx_set_product_offset(struct qla_hw_data *ha) return -1; } -int +static int qla82xx_validate_firmware_blob(scsi_qla_host_t *vha, uint8_t fw_type) { __le32 val; @@ -1980,20 +1970,6 @@ qla82xx_check_rcvpeg_state(struct qla_hw_data *ha) } /* ISR related functions */ -uint32_t qla82xx_isr_int_target_mask_enable[8] = { - ISR_INT_TARGET_MASK, ISR_INT_TARGET_MASK_F1, - ISR_INT_TARGET_MASK_F2, ISR_INT_TARGET_MASK_F3, - ISR_INT_TARGET_MASK_F4, ISR_INT_TARGET_MASK_F5, - ISR_INT_TARGET_MASK_F7, ISR_INT_TARGET_MASK_F7 -}; - -uint32_t qla82xx_isr_int_target_status[8] = { - ISR_INT_TARGET_STATUS, ISR_INT_TARGET_STATUS_F1, - ISR_INT_TARGET_STATUS_F2, ISR_INT_TARGET_STATUS_F3, - ISR_INT_TARGET_STATUS_F4, ISR_INT_TARGET_STATUS_F5, - ISR_INT_TARGET_STATUS_F7, ISR_INT_TARGET_STATUS_F7 -}; - static struct qla82xx_legacy_intr_set legacy_intr[] = \ QLA82XX_LEGACY_INTR_CONFIG; @@ -2819,7 +2795,7 @@ qla82xx_start_iocbs(scsi_qla_host_t *vha) } } -void qla82xx_rom_lock_recovery(struct qla_hw_data *ha) +static void qla82xx_rom_lock_recovery(struct qla_hw_data *ha) { scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); @@ -3177,8 +3153,7 @@ qla82xx_check_md_needed(scsi_qla_host_t *vha) } -int -qla82xx_check_fw_alive(scsi_qla_host_t *vha) +static int qla82xx_check_fw_alive(scsi_qla_host_t *vha) { uint32_t fw_heartbeat_counter; int status = 0; diff --git a/qla2x00t/qla_os.c b/qla2x00t/qla_os.c index b9a07695d..401778dcf 100644 --- a/qla2x00t/qla_os.c +++ b/qla2x00t/qla_os.c @@ -4589,7 +4589,7 @@ qla2xxx_pci_mmio_enabled(struct pci_dev *pdev) return PCI_ERS_RESULT_RECOVERED; } -uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha) +static uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha) { uint32_t rval = QLA_FUNCTION_FAILED; uint32_t drv_active = 0; From 76cc064b48ad64bbfe848d991a807c2ec4db6165 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:05:29 +0000 Subject: [PATCH 39/72] scst: Fix a race between scst_del_threads() and the sysfs API kthread_stop() not only stops a thread but also frees the associated task struct. Avoid that functions that iterate over the thread list can encounter an invalid task structure pointer. This patch fixes the following kernel crash: general protection fault: 0000 [#2] PREEMPT SMP RIP: 0010:[] [] __task_pid_nr_ns+0x9c/0x1b0 Call Trace: [] task_pid_vnr+0xd/0x10 [scst] [] scst_tgt_dev_thread_pid_show+0x78/0xd0 [scst] [] scst_show+0xf/0x20 [scst] [] sysfs_kf_seq_show+0xab/0x130 [] kernfs_seq_show+0x26/0x30 [] seq_read+0xe0/0x3e0 [] kernfs_fop_read+0x125/0x180 [] __vfs_read+0x28/0xe0 [] vfs_read+0x8a/0x140 [] SyS_read+0x49/0xb0 [] system_call_fastpath+0x16/0x7a git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6359 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_main.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index 34f921728..06f9e6255 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -1958,6 +1958,7 @@ void scst_del_threads(struct scst_cmd_threads *cmd_threads, int num) thread_list_entry) { if (!ct2->being_stopped) { ct = ct2; + list_del(&ct->thread_list_entry); ct->being_stopped = true; cmd_threads->nr_threads--; break; @@ -1972,10 +1973,6 @@ void scst_del_threads(struct scst_cmd_threads *cmd_threads, int num) if (rc != 0 && rc != -EINTR) TRACE_MGMT_DBG("kthread_stop() failed: %d", rc); - spin_lock(&cmd_threads->thr_lock); - list_del(&ct->thread_list_entry); - spin_unlock(&cmd_threads->thr_lock); - kfree(ct); } From 250faea9854856e22ef0d89bdfdaf20ebc4e69da Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:06:18 +0000 Subject: [PATCH 40/72] scst_targ: Remove dead code Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6360 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_targ.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 232b87a84..73eac6679 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -3239,7 +3239,6 @@ static int scst_exec_check_blocking(struct scst_cmd **active_cmd) { struct scst_cmd *cmd = *active_cmd; struct scst_cmd *ref_cmd; - int count = 0; TRACE_ENTRY(); @@ -3300,8 +3299,6 @@ static int scst_exec_check_blocking(struct scst_cmd **active_cmd) sBUG_ON(rc != SCST_EXEC_COMPLETED); done: - count++; - cmd = scst_post_exec_sn(cmd, false); if (cmd == NULL) break; @@ -3320,15 +3317,11 @@ done: *active_cmd = cmd; - if (count == 0) - goto out_put; - #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) if (ref_cmd->dev->scsi_dev != NULL) generic_unplug_device(ref_cmd->dev->scsi_dev->request_queue); #endif -out_put: __scst_cmd_put(ref_cmd); /* !! At this point sess, dev and tgt_dev can be already freed !! */ From 4b9efe2090743b15ae877f02a6cde98055bbeeb4 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:07:20 +0000 Subject: [PATCH 41/72] scst_tg: Convert dynamic into static initialization This patch does not change any functionality. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6361 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_tg.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scst/src/scst_tg.c b/scst/src/scst_tg.c index 6a714014c..7b04f0eaa 100644 --- a/scst/src/scst_tg.c +++ b/scst/src/scst_tg.c @@ -38,7 +38,7 @@ static const struct alua_state_and_name scst_tg_state_names[] = { { SCST_TG_STATE_TRANSITIONING, "transitioning" }, }; -static struct list_head scst_dev_group_list; +static LIST_HEAD(scst_dev_group_list); #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) || \ defined(RHEL_MAJOR) && RHEL_MAJOR -0 <= 5 @@ -1092,7 +1092,6 @@ out: void scst_tg_init(void) { - INIT_LIST_HEAD(&scst_dev_group_list); } void scst_tg_cleanup(void) From 4891109301ae7b9f0827377acabc3f29f3a1ccb8 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:08:48 +0000 Subject: [PATCH 42/72] scst_tg: Introduce scst_dg_mutex Make target group locking more fine grained by protecting target group related data structures via scst_dg_mutex. This patch fixes a rare deadlock between VPD inquiry and LUN removal. See also patch "scst: Rework sess_tgt_dev_list locking" (commit ID 5af7d9277ddf). INFO: task scst_uid:12943 blocked for more than 120 seconds. Call Trace: [] schedule+0x37/0x90 [] schedule_timeout+0x20c/0x370 [] wait_for_completion+0xf7/0x130 [] kthread_stop+0x84/0x470 [] scst_del_threads+0xc8/0x250 [scst] [] scst_tgt_dev_stop_threads+0x185/0x1a0 [scst] [] scst_free_tgt_dev+0x103/0x280 [scst] [] scst_acg_del_lun+0xcd/0x270 [scst] [] __scst_process_luns_mgmt_store+0x653/0x6b0 [scst] [] scst_luns_mgmt_store_work_fn+0x27/0x30 [scst] [] scst_process_sysfs_works+0xed/0x1f0 [scst] [] sysfs_work_thread_fn+0x13d/0x2e0 [scst] [] kthread+0x10a/0x120 [] ret_from_fork+0x42/0x70 1 lock held by scst_uid/12943: (&scst_mutex){+.+.+.}, at: [] scst_acg_del_lun+0xab/0x270 [scst] INFO: task diskf00_0:19854 blocked for more than 120 seconds. Call Trace: [] schedule+0x37/0x90 [] schedule_preempt_disabled+0x18/0x30 [] mutex_lock_nested+0x16e/0x450 [] scst_impl_alua_configured+0x1f/0x50 [scst] [] vdisk_inq+0x68/0x2c0 [scst_vdisk] [] vdisk_exec_inquiry+0x31e/0x440 [scst_vdisk] [] vdev_do_job+0x1b6/0x3c0 [scst_vdisk] [] vdisk_exec+0x29/0x90 [scst_vdisk] [] scst_do_real_exec+0xa1/0x450 [scst] [] scst_exec_check_blocking+0xad/0x2b0 [scst] [] scst_exec_check_sn+0xe/0x10 [scst] [] scst_process_active_cmd+0x3f5/0x7e0 [scst] [] scst_do_job_active+0xeb/0x180 [scst] [] scst_cmd_thread+0x13c/0x2c0 [scst] [] kthread+0x10a/0x120 [] ret_from_fork+0x42/0x70 1 lock held by diskf00_0/19854: (&scst_mutex){+.+.+.}, at: [] scst_impl_alua_configured+0x1f/0x50 [scst] git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6362 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_tg.c | 144 ++++++++++++++++++++++++++------------------- 1 file changed, 83 insertions(+), 61 deletions(-) diff --git a/scst/src/scst_tg.c b/scst/src/scst_tg.c index 7b04f0eaa..be84d62c7 100644 --- a/scst/src/scst_tg.c +++ b/scst/src/scst_tg.c @@ -38,6 +38,11 @@ static const struct alua_state_and_name scst_tg_state_names[] = { { SCST_TG_STATE_TRANSITIONING, "transitioning" }, }; +/* + * Protects scst_dev_group_list and also dev_list and tg_list in struct + * scst_dev_group. + */ +static DEFINE_MUTEX(scst_dg_mutex); static LIST_HEAD(scst_dev_group_list); #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) || \ @@ -77,7 +82,7 @@ static struct scst_device *__lookup_dev(const char *name) { struct scst_device *dev; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); list_for_each_entry(dev, &scst_dev_list, dev_list_entry) if (strcmp(dev->virt_name, name) == 0) @@ -109,7 +114,7 @@ static struct scst_tg_tgt *__lookup_dg_tgt(struct scst_dev_group *dg, struct scst_target_group *tg; struct scst_tg_tgt *tg_tgt; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); BUG_ON(!dg); BUG_ON(!tgt_name); @@ -127,7 +132,7 @@ __lookup_tg_by_name(struct scst_dev_group *dg, const char *name) { struct scst_target_group *tg; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); list_for_each_entry(tg, &dg->tg_list, entry) if (strcmp(tg->name, name) == 0) @@ -143,7 +148,7 @@ __lookup_tg_by_tgt(struct scst_dev_group *dg, const struct scst_tgt *tgt) struct scst_target_group *tg; struct scst_tg_tgt *tg_tgt; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); list_for_each_entry(tg, &dg->tg_list, entry) list_for_each_entry(tg_tgt, &tg->tgt_list, entry) @@ -159,7 +164,7 @@ static struct scst_dg_dev *__lookup_dg_dev_by_dev(struct scst_dev_group *dg, { struct scst_dg_dev *dgd; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); list_for_each_entry(dgd, &dg->dev_list, entry) if (dgd->dev == dev) @@ -174,7 +179,7 @@ static struct scst_dg_dev *__lookup_dg_dev_by_name(struct scst_dev_group *dg, { struct scst_dg_dev *dgd; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); list_for_each_entry(dgd, &dg->dev_list, entry) if (strcmp(dgd->dev->virt_name, name) == 0) @@ -189,7 +194,7 @@ static struct scst_dg_dev *__global_lookup_dg_dev_by_name(const char *name) struct scst_dev_group *dg; struct scst_dg_dev *dgd; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); list_for_each_entry(dg, &scst_dev_group_list, entry) { dgd = __lookup_dg_dev_by_name(dg, name); @@ -204,7 +209,7 @@ static struct scst_dev_group *__lookup_dg_by_name(const char *name) { struct scst_dev_group *dg; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); list_for_each_entry(dg, &scst_dev_group_list, entry) if (strcmp(dg->name, name) == 0) @@ -218,7 +223,7 @@ static struct scst_dev_group *__lookup_dg_by_dev(struct scst_device *dev) { struct scst_dev_group *dg; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); list_for_each_entry(dg, &scst_dev_group_list, entry) if (__lookup_dg_dev_by_dev(dg, dev)) @@ -335,7 +340,10 @@ static void scst_check_alua_invariant(void) struct scst_target_group *tg; enum scst_tg_state expected_state; - lockdep_assert_held(&scst_mutex); +#if 0 + lockdep_assert_held(&scst_mutex); /* scst_dev_list, dev_tgt_dev_list */ +#endif + lockdep_assert_held(&scst_dg_mutex); if (!alua_invariant_check) return; @@ -370,7 +378,7 @@ static void scst_check_alua_invariant(void) static void scst_update_tgt_dev_alua_filter(struct scst_tgt_dev *tgt_dev, enum scst_tg_state state) { - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); tgt_dev->alua_filter = scst_alua_filter[state]; } @@ -380,7 +388,7 @@ static void scst_tg_change_tgt_dev_state(struct scst_tgt_dev *tgt_dev, enum scst_tg_state state, bool gen_ua) { - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); TRACE_MGMT_DBG("ALUA state of tgt_dev %p has changed", tgt_dev); scst_update_tgt_dev_alua_filter(tgt_dev, state); @@ -395,8 +403,7 @@ void scst_tg_init_tgt_dev(struct scst_tgt_dev *tgt_dev) struct scst_dev_group *dg; struct scst_target_group *tg; - lockdep_assert_held(&scst_mutex); - + mutex_lock(&scst_dg_mutex); dg = __lookup_dg_by_dev(tgt_dev->dev); if (dg) { tg = __lookup_tg_by_tgt(dg, tgt_dev->acg_dev->acg->tgt); @@ -405,6 +412,7 @@ void scst_tg_init_tgt_dev(struct scst_tgt_dev *tgt_dev) scst_check_alua_invariant(); } } + mutex_unlock(&scst_dg_mutex); } /* @@ -417,7 +425,7 @@ static void scst_update_tgt_alua_filter(struct scst_target_group *tg, struct scst_dg_dev *dgd; struct scst_tgt_dev *tgt_dev; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); list_for_each_entry(dgd, &tg->dg->dev_list, entry) { list_for_each_entry(tgt_dev, &dgd->dev->dev_tgt_dev_list, @@ -441,7 +449,7 @@ static void scst_reset_tgt_alua_filter(struct scst_target_group *tg, struct scst_dg_dev *dgd; struct scst_tgt_dev *tgt_dev; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); list_for_each_entry(dgd, &tg->dg->dev_list, entry) { list_for_each_entry(tgt_dev, &dgd->dev->dev_tgt_dev_list, @@ -485,23 +493,33 @@ int scst_tg_tgt_add(struct scst_target_group *tg, const char *name) res = mutex_lock_interruptible(&scst_mutex); if (res) goto out_put; + res = mutex_lock_interruptible(&scst_dg_mutex); + if (res) + goto out_unlock_scst; res = -EEXIST; tgt = __lookup_tgt(name); if (__lookup_dg_tgt(tg->dg, name)) - goto out_unlock; + goto out_unlock_dg; tg_tgt->tgt = tgt; res = scst_tg_tgt_sysfs_add(tg, tg_tgt); if (res) - goto out_unlock; + goto out_unlock_dg; list_add_tail(&tg_tgt->entry, &tg->tgt_list); scst_update_tgt_alua_filter(tg, tgt); res = 0; + mutex_unlock(&scst_dg_mutex); mutex_unlock(&scst_mutex); + out: TRACE_EXIT_RES(res); return res; -out_unlock: + +out_unlock_dg: + mutex_unlock(&scst_dg_mutex); + +out_unlock_scst: mutex_unlock(&scst_mutex); + out_put: kobject_put(&tg_tgt->kobj); goto out; @@ -529,7 +547,7 @@ int scst_tg_tgt_remove_by_name(struct scst_target_group *tg, const char *name) TRACE_ENTRY(); BUG_ON(!tg); BUG_ON(!name); - res = mutex_lock_interruptible(&scst_mutex); + res = mutex_lock_interruptible(&scst_dg_mutex); if (res) goto out; res = -EINVAL; @@ -539,27 +557,26 @@ int scst_tg_tgt_remove_by_name(struct scst_target_group *tg, const char *name) __scst_tg_tgt_remove(tg, tg_tgt); res = 0; out_unlock: - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); out: TRACE_EXIT_RES(res); return res; } -/* Caller must hold scst_mutex. Called from the target removal code. */ +/* Called from the target removal code. */ void scst_tg_tgt_remove_by_tgt(struct scst_tgt *tgt) { struct scst_dev_group *dg; struct scst_target_group *tg; struct scst_tg_tgt *t, *t2; - lockdep_assert_held(&scst_mutex); - - BUG_ON(!tgt); + mutex_lock(&scst_dg_mutex); list_for_each_entry(dg, &scst_dev_group_list, entry) list_for_each_entry(tg, &dg->tg_list, entry) list_for_each_entry_safe(t, t2, &tg->tgt_list, entry) if (t->tgt == tgt) __scst_tg_tgt_remove(tg, t); + mutex_unlock(&scst_dg_mutex); } /* @@ -608,7 +625,7 @@ int scst_tg_add(struct scst_dev_group *dg, const char *name) tg->state = SCST_TG_STATE_OPTIMIZED; INIT_LIST_HEAD(&tg->tgt_list); - res = mutex_lock_interruptible(&scst_mutex); + res = mutex_lock_interruptible(&scst_dg_mutex); if (res) goto out_put; res = -EEXIST; @@ -618,14 +635,14 @@ int scst_tg_add(struct scst_dev_group *dg, const char *name) if (res) goto out_unlock; list_add_tail(&tg->entry, &dg->tg_list); - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); out: TRACE_EXIT_RES(res); return res; out_unlock: - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); out_put: kobject_put(&tg->kobj); goto out; @@ -658,7 +675,7 @@ int scst_tg_remove_by_name(struct scst_dev_group *dg, const char *name) struct scst_target_group *tg; int res; - res = mutex_lock_interruptible(&scst_mutex); + res = mutex_lock_interruptible(&scst_dg_mutex); if (res) goto out; res = -EINVAL; @@ -668,7 +685,7 @@ int scst_tg_remove_by_name(struct scst_dev_group *dg, const char *name) __scst_tg_remove(dg, tg); res = 0; out_unlock: - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); out: return res; } @@ -689,7 +706,7 @@ static void __scst_tg_set_state(struct scst_target_group *tg, struct scst_tgt *tgt; sBUG_ON(state >= ARRAY_SIZE(scst_alua_filter)); - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); if (tg->state == state) return; @@ -725,13 +742,13 @@ int scst_tg_set_state(struct scst_target_group *tg, enum scst_tg_state state) if (state >= ARRAY_SIZE(scst_alua_filter)) goto out; - res = mutex_lock_interruptible(&scst_mutex); + res = mutex_lock_interruptible(&scst_dg_mutex); if (res) goto out; __scst_tg_set_state(tg, state, NULL); - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); out: return res; } @@ -753,7 +770,7 @@ static void __scst_gen_alua_state_changed_ua(struct scst_target_group *tg) struct scst_tg_tgt *tg_tgt; struct scst_tgt *tgt; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); list_for_each_entry(dg_dev, &tg->dg->dev_list, entry) { dev = dg_dev->dev; @@ -776,7 +793,7 @@ static void __scst_tg_set_preferred(struct scst_target_group *tg, { bool prev_preferred; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); if (tg->preferred == preferred) return; @@ -796,11 +813,11 @@ int scst_tg_set_preferred(struct scst_target_group *tg, { int res; - res = mutex_lock_interruptible(&scst_mutex); + res = mutex_lock_interruptible(&scst_dg_mutex); if (res) goto out; __scst_tg_set_preferred(tg, preferred); - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); out: return res; } @@ -819,7 +836,7 @@ static void scst_update_dev_alua_filter(struct scst_dev_group *dg, struct scst_tgt_dev *tgt_dev; struct scst_target_group *tg; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); list_for_each_entry(tgt_dev, &dev->dev_tgt_dev_list, dev_tgt_dev_list_entry) { @@ -839,7 +856,7 @@ static void scst_reset_dev_alua_filter(struct scst_device *dev) { struct scst_tgt_dev *tgt_dev; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); list_for_each_entry(tgt_dev, &dev->dev_tgt_dev_list, dev_tgt_dev_list_entry) @@ -866,7 +883,7 @@ int scst_dg_dev_add(struct scst_dev_group *dg, const char *name) if (!dgdev) goto out; - res = mutex_lock_interruptible(&scst_mutex); + res = mutex_lock_interruptible(&scst_dg_mutex); if (res) goto out_free; res = -EEXIST; @@ -882,13 +899,13 @@ int scst_dg_dev_add(struct scst_dev_group *dg, const char *name) goto out_unlock; list_add_tail(&dgdev->entry, &dg->dev_list); scst_update_dev_alua_filter(dg, dev); - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); out: return res; out_unlock: - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); out_free: kfree(dgdev); goto out; @@ -911,7 +928,7 @@ int scst_dg_dev_remove_by_name(struct scst_dev_group *dg, const char *name) struct scst_dg_dev *dgdev; int res; - res = mutex_lock_interruptible(&scst_mutex); + res = mutex_lock_interruptible(&scst_dg_mutex); if (res) goto out; res = -EINVAL; @@ -921,12 +938,12 @@ int scst_dg_dev_remove_by_name(struct scst_dev_group *dg, const char *name) __scst_dg_dev_remove(dg, dgdev); res = 0; out_unlock: - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); out: return res; } -/* Caller must hold scst_mutex. Called from the device removal code. */ +/* Called from the device removal code. */ int scst_dg_dev_remove_by_dev(struct scst_device *dev) { struct scst_dev_group *dg; @@ -934,6 +951,8 @@ int scst_dg_dev_remove_by_dev(struct scst_device *dev) int res; res = -EINVAL; + + mutex_lock(&scst_dg_mutex); dg = __lookup_dg_by_dev(dev); if (!dg) goto out; @@ -941,7 +960,10 @@ int scst_dg_dev_remove_by_dev(struct scst_device *dev) BUG_ON(!dgdev); __scst_dg_dev_remove(dg, dgdev); res = 0; + out: + mutex_unlock(&scst_dg_mutex); + return res; } @@ -989,7 +1011,7 @@ int scst_dg_add(struct kobject *parent, const char *name) if (!dg->name) goto out_put; - res = mutex_lock_interruptible(&scst_mutex); + res = mutex_lock_interruptible(&scst_dg_mutex); if (res) goto out_put; res = -EEXIST; @@ -1002,13 +1024,13 @@ int scst_dg_add(struct kobject *parent, const char *name) if (res) goto out_unlock; list_add_tail(&dg->entry, &scst_dev_group_list); - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); out: TRACE_EXIT_RES(res); return res; out_unlock: - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); out_put: kobject_put(&dg->kobj); goto out; @@ -1019,7 +1041,7 @@ static void __scst_dg_remove(struct scst_dev_group *dg) struct scst_dg_dev *dgdev; struct scst_target_group *tg; - lockdep_assert_held(&scst_mutex); + lockdep_assert_held(&scst_dg_mutex); list_del(&dg->entry); scst_dg_sysfs_del(dg); @@ -1043,7 +1065,7 @@ int scst_dg_remove(const char *name) struct scst_dev_group *dg; int res; - res = mutex_lock_interruptible(&scst_mutex); + res = mutex_lock_interruptible(&scst_dg_mutex); if (res) goto out; res = -EINVAL; @@ -1053,7 +1075,7 @@ int scst_dg_remove(const char *name) __scst_dg_remove(dg); res = 0; out_unlock: - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); out: return res; } @@ -1072,7 +1094,7 @@ struct scst_dev_group *scst_lookup_dg_by_kobj(struct kobject *kobj) struct scst_dev_group *dg; dg = NULL; - res = mutex_lock_interruptible(&scst_mutex); + res = mutex_lock_interruptible(&scst_dg_mutex); if (res) goto out; list_for_each_entry(dg, &scst_dev_group_list, entry) @@ -1080,7 +1102,7 @@ struct scst_dev_group *scst_lookup_dg_by_kobj(struct kobject *kobj) goto out_unlock; dg = NULL; out_unlock: - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); out: return dg; } @@ -1098,13 +1120,13 @@ void scst_tg_cleanup(void) { struct scst_dev_group *tg; - mutex_lock(&scst_mutex); + mutex_lock(&scst_dg_mutex); while (!list_empty(&scst_dev_group_list)) { tg = list_first_entry(&scst_dev_group_list, struct scst_dev_group, entry); __scst_dg_remove(tg); } - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); } /* @@ -1126,7 +1148,7 @@ uint16_t scst_lookup_tg_id(struct scst_device *dev, struct scst_tgt *tgt) uint16_t tg_id = 0; TRACE_ENTRY(); - mutex_lock(&scst_mutex); + mutex_lock(&scst_dg_mutex); dg = __lookup_dg_by_dev(dev); if (!dg) goto out_unlock; @@ -1137,7 +1159,7 @@ uint16_t scst_lookup_tg_id(struct scst_device *dev, struct scst_tgt *tgt) BUG_ON(!tg); tg_id = tg->group_id; out_unlock: - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); TRACE_EXIT_RES(tg_id); return tg_id; @@ -1152,9 +1174,9 @@ bool scst_impl_alua_configured(struct scst_device *dev) { struct scst_dev_group *dg; - mutex_lock(&scst_mutex); + mutex_lock(&scst_dg_mutex); dg = __lookup_dg_by_dev(dev); - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); return dg != NULL; } @@ -1200,7 +1222,7 @@ int scst_tg_get_group_info(void **buf, uint32_t *length, *length = 4; - mutex_lock(&scst_mutex); + mutex_lock(&scst_dg_mutex); dg = __lookup_dg_by_dev(dev); if (dg) { @@ -1267,7 +1289,7 @@ done: res = 0; out_unlock: - mutex_unlock(&scst_mutex); + mutex_unlock(&scst_dg_mutex); out: TRACE_EXIT_RES(res); return res; From 63cb4a9d4047e3c1c156f4b98400dd46c13cb0b3 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:09:23 +0000 Subject: [PATCH 43/72] iscsi-scst: Fix indentation git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6363 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/nthread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iscsi-scst/kernel/nthread.c b/iscsi-scst/kernel/nthread.c index 5e0cbeffe..d76c95975 100644 --- a/iscsi-scst/kernel/nthread.c +++ b/iscsi-scst/kernel/nthread.c @@ -1743,7 +1743,7 @@ int iscsi_send(struct iscsi_conn *conn) conn->write_state = TX_PADDING; else if (ddigest) conn->write_state = TX_INIT_DDIGEST; - else + else conn->write_state = TX_END; break; case TX_PADDING: From 26cda0eb387294f30a4509cb3f9ae65974d846a6 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:18:23 +0000 Subject: [PATCH 44/72] iscsi-scst: Annotate fall-through cases for Coverity git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6364 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/nthread.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iscsi-scst/kernel/nthread.c b/iscsi-scst/kernel/nthread.c index d76c95975..ae4ff7b40 100644 --- a/iscsi-scst/kernel/nthread.c +++ b/iscsi-scst/kernel/nthread.c @@ -1731,11 +1731,13 @@ int iscsi_send(struct iscsi_conn *conn) if (!(conn->hdigest_type & DIGEST_NONE)) init_tx_hdigest(cmnd); conn->write_state = TX_BHS_DATA; + /* fall-through */ case TX_BHS_DATA: res = iscsi_do_send(conn, cmnd->pdu.datasize ? TX_INIT_PADDING : TX_END); if (res <= 0 || conn->write_state != TX_INIT_PADDING) break; + /* fall-through */ case TX_INIT_PADDING: cmnd->conn->write_size = ((cmnd->pdu.datasize + 3) & -4) - cmnd->pdu.datasize; @@ -1750,9 +1752,11 @@ int iscsi_send(struct iscsi_conn *conn) res = tx_padding(cmnd, ddigest ? TX_INIT_DDIGEST : TX_END); if (res <= 0 || conn->write_state != TX_INIT_DDIGEST) break; + /* fall-through */ case TX_INIT_DDIGEST: cmnd->conn->write_size = sizeof(u32); conn->write_state = TX_DDIGEST; + /* fall-through */ case TX_DDIGEST: res = tx_ddigest(cmnd, TX_END); break; From 40a90a705dbf3ff685ba5847f5a9229353c86cc9 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:19:27 +0000 Subject: [PATCH 45/72] isert-scst: Add address length check in isert_listen_ioctl() Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6365 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/isert-scst/isert_login.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/iscsi-scst/kernel/isert-scst/isert_login.c b/iscsi-scst/kernel/isert-scst/isert_login.c index 024d5bba8..688fd637b 100644 --- a/iscsi-scst/kernel/isert-scst/isert_login.c +++ b/iscsi-scst/kernel/isert-scst/isert_login.c @@ -389,6 +389,13 @@ static long isert_listen_ioctl(struct file *filp, unsigned int cmd, goto out; } + if (unlikely(dev->info.addr_len > sizeof(dev->info.addr))) { + PRINT_ERROR("Invalid address length %zd > %zd", + dev->info.addr_len, sizeof(dev->info.addr)); + res = -EINVAL; + goto out; + } + portal = isert_portal_add((struct sockaddr *)&dev->info.addr, dev->info.addr_len); if (IS_ERR(portal)) { From d70b1e39c0b859f66a5bd06db95c44a5a4e4c546 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:20:21 +0000 Subject: [PATCH 46/72] iscsi-scstd: Fix a dereference-before-null-check Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6366 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/session.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iscsi-scst/usr/session.c b/iscsi-scst/usr/session.c index fe25b1c05..9886cfe42 100644 --- a/iscsi-scst/usr/session.c +++ b/iscsi-scst/usr/session.c @@ -172,11 +172,11 @@ void session_free(struct session *session) { log_debug(1, "Freeing session sid %#"PRIx64, session->sid.id64); - kernel_session_destroy(session->target->tid, session->sid.id64); - if (session->target) { struct target *target = session->target; + kernel_session_destroy(target->tid, session->sid.id64); + target->sessions_count--; log_debug(1, "target %s, sessions_count %d", target->name, target->sessions_count); From 165b0f1d1082f10b95d34e69399d7dec0b29e216 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:21:28 +0000 Subject: [PATCH 47/72] iscsi-scstd: Improve create_and_open_dev() robustness Reset 'devn' if the sscanf() return value is lower than two. Based on a Coverity report. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6367 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/misc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/iscsi-scst/usr/misc.c b/iscsi-scst/usr/misc.c index 357be4d11..13c7676e8 100644 --- a/iscsi-scst/usr/misc.c +++ b/iscsi-scst/usr/misc.c @@ -43,12 +43,9 @@ int create_and_open_dev(const char *dev, int readonly) } devn = 0; - while (!feof(f)) { - if (!fgets(buf, sizeof(buf), f)) - break; - if (sscanf(buf, "%d %s", &devn, devname) != 2) - continue; - if (!strcmp(devname, dev)) + while (fgets(buf, sizeof(buf), f)) { + if (sscanf(buf, "%d %s", &devn, devname) == 2 && + devn > 0 && strcmp(devname, dev) == 0) break; devn = 0; } From dfcb53a9b207e341ed02b41026bf398c6e7d2772 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:22:14 +0000 Subject: [PATCH 48/72] iscsi-scstd: Rearrange driver major number lookup code Introduce a function for looking up the driver major number. This patch does not change any functionality but makes the source code easier to read and also makes it easier for Coverity to analyze this code. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6368 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/misc.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/iscsi-scst/usr/misc.c b/iscsi-scst/usr/misc.c index 13c7676e8..8a2273c28 100644 --- a/iscsi-scst/usr/misc.c +++ b/iscsi-scst/usr/misc.c @@ -25,36 +25,48 @@ #include "iscsid.h" -int create_and_open_dev(const char *dev, int readonly) +int driver_major(const char *dev) { FILE *f; char devname[256]; char buf[256]; int devn; - int ctlfd = -1; - int err; - int flags; f = fopen("/proc/devices", "r"); if (!f) { - err = -errno; + devn = -errno; perror("Cannot open control path to the driver"); goto out; } - devn = 0; + devn = -ENOENT; while (fgets(buf, sizeof(buf), f)) { if (sscanf(buf, "%d %s", &devn, devname) == 2 && devn > 0 && strcmp(devname, dev) == 0) break; - devn = 0; + devn = -ENOENT; } - fclose(f); - if (!devn) { - err = -ENOENT; + + if (devn < 0) printf("cannot find %s in /proc/devices - " "make sure the module is loaded\n", dev); + +out: + return devn; +} + +int create_and_open_dev(const char *dev, int readonly) +{ + char devname[256]; + int devn; + int ctlfd = -1; + int err; + int flags; + + devn = driver_major(dev); + if (devn < 0) { + err = devn; goto out; } From b099782023a108ee5b97c157f5927c929e2067c1 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:22:46 +0000 Subject: [PATCH 49/72] iscsi-scstd: Fix a memory leak in the iSNS code Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6369 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/config.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iscsi-scst/usr/config.c b/iscsi-scst/usr/config.c index f6017e5e7..0e988e195 100644 --- a/iscsi-scst/usr/config.c +++ b/iscsi-scst/usr/config.c @@ -1048,6 +1048,7 @@ static int config_isns_load(const char *config) if ((*p == '\0') || (*p == '#')) continue; if (!strcasecmp(p, ISCSI_ISNS_SERVER_ATTR_NAME)) { + free(isns_server); isns_server = strdup(config_sep_string(&q)); } else if (!strcasecmp(p, ISCSI_ISNS_ACCESS_CONTROL_ATTR_NAME)) { char *str = config_sep_string(&q); From 21b60063a9ae5b12e1aa0afde91c4daef6a0d9d3 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:23:14 +0000 Subject: [PATCH 50/72] iscsi-scstd: Fix a dereference-before-null-check Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6370 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iscsi-scst/usr/config.c b/iscsi-scst/usr/config.c index 0e988e195..c1ac14ab2 100644 --- a/iscsi-scst/usr/config.c +++ b/iscsi-scst/usr/config.c @@ -245,7 +245,7 @@ static struct __qelem *account_list_get(struct target *target, int dir) char *config_sep_string(char **pp) { - char *p = *pp; + char *p; char *q; static char blank = '\0'; From 41caee31481d2bee0a0b44cce0e25d52fe68e9c5 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:23:38 +0000 Subject: [PATCH 51/72] iscsi-scstd: Fix a file descriptor leak in an error path Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6371 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/event.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iscsi-scst/usr/event.c b/iscsi-scst/usr/event.c index 719c7e2a6..2dbf387bb 100644 --- a/iscsi-scst/usr/event.c +++ b/iscsi-scst/usr/event.c @@ -1188,6 +1188,7 @@ int nl_open(void) res = nl_write(nl_fd, NULL, 0); if (res < 0) { log_error("%s %d\n", __FUNCTION__, res); + close(nl_fd); return res; } From 102d8d54c97355e8ba424710395c65bc4ace32fa Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:24:03 +0000 Subject: [PATCH 52/72] iscsi-scstd: Move two local variables to suppress a Coverity complaint git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6372 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iscsi-scst/usr/config.c b/iscsi-scst/usr/config.c index c1ac14ab2..7d0ec9b00 100644 --- a/iscsi-scst/usr/config.c +++ b/iscsi-scst/usr/config.c @@ -654,7 +654,6 @@ static int address_match(struct sockaddr *sa1, struct sockaddr *sa2) static int __initiator_match(int fd, char *str) { struct sockaddr_storage from; - struct addrinfo hints, *res; socklen_t len; char *p, *q; int err = 0; @@ -664,6 +663,8 @@ static int __initiator_match(int fd, char *str) return 0; while ((p = strsep(&str, ","))) { + struct addrinfo hints, *res; + while (isblank(*p)) p++; From b3f49a0a17f983c219b9d873ba21f131af5b12d8 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:24:25 +0000 Subject: [PATCH 53/72] iscsi-scstd: Annotate fall-throughs for Coverity git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6373 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/iscsi_scstd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iscsi-scst/usr/iscsi_scstd.c b/iscsi-scst/usr/iscsi_scstd.c index 322b4c321..c2ff33df7 100644 --- a/iscsi-scst/usr/iscsi_scstd.c +++ b/iscsi-scst/usr/iscsi_scstd.c @@ -595,6 +595,7 @@ again: conn->rwsize = conn->rsp.ahssize; goto write_again; } + /* fall-through */ case IOSTATE_WRITE_AHS: if (conn->rsp.datasize) { int o; @@ -610,6 +611,7 @@ again: } goto write_again; } + /* fall-through */ case IOSTATE_WRITE_DATA: conn->uncork_transmit(pollfd->fd); cmnd_finish(conn); From 74b4104994b652f3a79682cba112219ce78f316d Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:25:05 +0000 Subject: [PATCH 54/72] iscsi-scstd: Avoid that Coverity complains about a use-after-free git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6374 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/iscsi_scstd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iscsi-scst/usr/iscsi_scstd.c b/iscsi-scst/usr/iscsi_scstd.c index c2ff33df7..777744e1a 100644 --- a/iscsi-scst/usr/iscsi_scstd.c +++ b/iscsi-scst/usr/iscsi_scstd.c @@ -761,10 +761,10 @@ static void event_loop(void) */ if (!sess && conn->sessions_count_incremented) conn->target->sessions_count--; - conn_free(conn); log_debug(1, "conn %p freed (sess %p, empty %d)", conn, sess, sess ? list_empty(&sess->conn_list) : -1); + conn_free(conn); if (sess && list_empty(&sess->conn_list)) session_free(sess); } From a6121b03c81d1d75d5b766526c22e28dda087c69 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:25:42 +0000 Subject: [PATCH 55/72] iscsi-scstd: Fix a potential file descriptor leak git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6375 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/message.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iscsi-scst/usr/message.c b/iscsi-scst/usr/message.c index acd257153..a0f34f0f3 100644 --- a/iscsi-scst/usr/message.c +++ b/iscsi-scst/usr/message.c @@ -194,7 +194,7 @@ send: err = writev(fd, iov, 2 + !!iov[2].iov_len); out: - if (fd > 0) + if (fd >= 0) close(fd); if (rsp_data) free(rsp_data); From f5f85b95fb35c9096d7b8fb0bec395b231fc87ea Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:26:08 +0000 Subject: [PATCH 56/72] iscsi-scstd: Fix a resource leak in an error path git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6376 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/message.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iscsi-scst/usr/message.c b/iscsi-scst/usr/message.c index a0f34f0f3..271ef74c4 100644 --- a/iscsi-scst/usr/message.c +++ b/iscsi-scst/usr/message.c @@ -42,8 +42,10 @@ int iscsi_adm_request_listen(void) if ((err = bind(fd, (struct sockaddr *) &addr, sizeof(addr))) < 0) return err; - if ((err = listen(fd, 32)) < 0) + if ((err = listen(fd, 32)) < 0) { + close(fd); return err; + } return fd; } From ff2b660264a304674f701859ce15388962019201 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:26:35 +0000 Subject: [PATCH 57/72] iscsiadm: Fix a file descriptor leak in an error path Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6377 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/iscsi_adm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iscsi-scst/usr/iscsi_adm.c b/iscsi-scst/usr/iscsi_adm.c index dc0a85f2e..c50f45923 100644 --- a/iscsi-scst/usr/iscsi_adm.c +++ b/iscsi-scst/usr/iscsi_adm.c @@ -206,6 +206,7 @@ static int iscsid_connect(void) memcpy((char *) &addr.sun_path + 1, ISCSI_ADM_NAMESPACE, strlen(ISCSI_ADM_NAMESPACE)); if (connect(fd, (struct sockaddr *) &addr, sizeof(addr))) { + close(fd); fd = -errno; fprintf(stderr, "Unable to connect to iscsid: %s\n", strerror(-fd)); From a14df3994219436dd54ab9592cfbb769d799086e Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:27:18 +0000 Subject: [PATCH 58/72] iscsiadm: Do not allocate more memory than needed Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6378 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/iscsi_adm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iscsi-scst/usr/iscsi_adm.c b/iscsi-scst/usr/iscsi_adm.c index c50f45923..c29aa5f79 100644 --- a/iscsi-scst/usr/iscsi_adm.c +++ b/iscsi-scst/usr/iscsi_adm.c @@ -488,7 +488,7 @@ static int user_handle_show_list(struct iscsi_adm_req *req) buf_sz = buf_sz ? buf_sz : ISCSI_NAME_LEN; - buf = calloc(buf_sz, sizeof(char *)); + buf = calloc(buf_sz, sizeof(*buf)); if (!buf) { fprintf(stderr, "Memory allocation failed\n"); return -ENOMEM; From ad38432332eda3c0ff1acd5d2affe79c3b1d80c4 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:27:41 +0000 Subject: [PATCH 59/72] iscsiadm: Fix strerror() argument Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6379 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/iscsi_adm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iscsi-scst/usr/iscsi_adm.c b/iscsi-scst/usr/iscsi_adm.c index c29aa5f79..1f53ceb5f 100644 --- a/iscsi-scst/usr/iscsi_adm.c +++ b/iscsi-scst/usr/iscsi_adm.c @@ -147,7 +147,7 @@ static int iscsid_request_send(int fd, struct iscsi_adm_req *req) if (ret != sizeof(*req)) { err = (ret < 0) ? -errno : -EIO; fprintf(stderr, "%s failed: written %d, to write %d, " - "error: %s\n", __func__, ret, err, strerror(err)); + "error: %s\n", __func__, ret, err, strerror(-err)); } else err = 0; @@ -173,7 +173,7 @@ 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, "readv failed: read %d instead of %d (%s)\n", - ret, (int)(sizeof(rsp) + sizeof(*req)), strerror(err)); + ret, (int)(sizeof(rsp) + sizeof(*req)), strerror(-err)); } else err = rsp.err; @@ -182,7 +182,7 @@ static int iscsid_response_recv(int fd, struct iscsi_adm_req *req, void *rsp_dat if (ret != rsp_data_sz) { err = (ret < 0) ? -errno : -EIO; fprintf(stderr, "read failed: read %d instead of %d (%s)\n", - ret, (int)rsp_data_sz, strerror(err)); + ret, (int)rsp_data_sz, strerror(-err)); } } From a8da0107f8c1c88c9e578af10decc6a2e36c87da Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:28:02 +0000 Subject: [PATCH 60/72] iscsiadm: Fix a resource leak Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6380 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/iscsi_adm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iscsi-scst/usr/iscsi_adm.c b/iscsi-scst/usr/iscsi_adm.c index 1f53ceb5f..3fd6033f5 100644 --- a/iscsi-scst/usr/iscsi_adm.c +++ b/iscsi-scst/usr/iscsi_adm.c @@ -240,7 +240,7 @@ out_report: } out_close: - if (fd > 0) + if (fd >= 0) close(fd); return err; From e2210ff40f2c932b33494ad2b0cc44dc9f602771 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:28:39 +0000 Subject: [PATCH 61/72] ib_srpt, make clean: Remove all temporary files git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6381 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- srpt/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/srpt/Makefile b/srpt/Makefile index 6d3dbd896..d7805080e 100644 --- a/srpt/Makefile +++ b/srpt/Makefile @@ -132,8 +132,9 @@ src/$(MODULE_SYMVERS): $(SCST_SYMVERS_DIR)/$(MODULE_SYMVERS) \ fi clean: - $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/conftest/gid_change clean - $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/ clean + for d in conftest/gid_change conftest/register_mad_agent src; do \ + $(MAKE) -C $(KDIR) SUBDIRS=$(shell pwd)/$$d clean; \ + done rm -f src/$(MODULE_SYMVERS) src/Module.markers src/modules.order rm -rf conftest/pre_cflags conftest/kcflags From 18c63e434b4e577f8d785ef7a5effbd5a7ec6cd0 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:29:04 +0000 Subject: [PATCH 62/72] qla2x00t: Fix a potential buffer overflow Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6382 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- qla2x00t/qla_gs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qla2x00t/qla_gs.c b/qla2x00t/qla_gs.c index 5f3f3b0b2..b25f97551 100644 --- a/qla2x00t/qla_gs.c +++ b/qla2x00t/qla_gs.c @@ -1392,7 +1392,8 @@ qla2x00_fdmi_rhba(scsi_qla_host_t *vha) /* Driver version. */ eiter = (struct ct_fdmi_hba_attr *) (entries + size); eiter->type = __constant_cpu_to_be16(FDMI_HBA_DRIVER_VERSION); - strcpy(eiter->a.driver_version, qla2x00_version_str); + snprintf(eiter->a.driver_version, sizeof(eiter->a.driver_version), + "%s", qla2x00_version_str); alen = strlen(eiter->a.driver_version); alen += (alen & 3) ? (4 - (alen & 3)) : 4; eiter->len = cpu_to_be16(4 + alen); From 556023b862bbc5f38012f8b433b0aebf9976756b Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:29:40 +0000 Subject: [PATCH 63/72] qla2x00t: Help Coverity with analyzing ct_sns_pkt initialization This patch does not change any functionality. See also the upstream patch "qla2xxx: Help Coverity with analyzing ct_sns_pkt initialization". git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6383 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- qla2x00t/qla_gs.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/qla2x00t/qla_gs.c b/qla2x00t/qla_gs.c index b25f97551..71fc63bf4 100644 --- a/qla2x00t/qla_gs.c +++ b/qla2x00t/qla_gs.c @@ -1260,18 +1260,18 @@ qla2x00_update_ms_fdmi_iocb(scsi_qla_host_t *vha, uint32_t req_size) * Returns a pointer to the intitialized @ct_req. */ static inline struct ct_sns_req * -qla2x00_prep_ct_fdmi_req(struct ct_sns_req *ct_req, uint16_t cmd, +qla2x00_prep_ct_fdmi_req(struct ct_sns_pkt *p, uint16_t cmd, uint16_t rsp_size) { - memset(ct_req, 0, sizeof(struct ct_sns_pkt)); + memset(p, 0, sizeof(struct ct_sns_pkt)); - ct_req->header.revision = 0x01; - ct_req->header.gs_type = 0xFA; - ct_req->header.gs_subtype = 0x10; - ct_req->command = cpu_to_be16(cmd); - ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4); + p->p.req.header.revision = 0x01; + p->p.req.header.gs_type = 0xFA; + p->p.req.header.gs_subtype = 0x10; + p->p.req.command = cpu_to_be16(cmd); + p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4); - return ct_req; + return &p->p.req; } /** @@ -1299,8 +1299,7 @@ qla2x00_fdmi_rhba(scsi_qla_host_t *vha) ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RHBA_RSP_SIZE); /* Prepare CT request */ - ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RHBA_CMD, - RHBA_RSP_SIZE); + ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RHBA_CMD, RHBA_RSP_SIZE); ct_rsp = &ha->ct_sns->p.rsp; /* Prepare FDMI command arguments -- attribute block, attributes. */ @@ -1490,8 +1489,7 @@ qla2x00_fdmi_dhba(scsi_qla_host_t *vha) DHBA_RSP_SIZE); /* Prepare CT request */ - ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, DHBA_CMD, - DHBA_RSP_SIZE); + ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, DHBA_CMD, DHBA_RSP_SIZE); ct_rsp = &ha->ct_sns->p.rsp; /* Prepare FDMI command arguments -- portname. */ @@ -1547,8 +1545,7 @@ qla2x00_fdmi_rpa(scsi_qla_host_t *vha) ms_pkt = ha->isp_ops->prep_ms_fdmi_iocb(vha, 0, RPA_RSP_SIZE); /* Prepare CT request */ - ct_req = qla2x00_prep_ct_fdmi_req(&ha->ct_sns->p.req, RPA_CMD, - RPA_RSP_SIZE); + ct_req = qla2x00_prep_ct_fdmi_req(ha->ct_sns, RPA_CMD, RPA_RSP_SIZE); ct_rsp = &ha->ct_sns->p.rsp; /* Prepare FDMI command arguments -- attribute block, attributes. */ From 4ad34f74d5f0aec2ccef4eed6690846095f55fa8 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:30:16 +0000 Subject: [PATCH 64/72] fileio: Fix a potential buffer overflow Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6384 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- usr/fileio/debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/fileio/debug.c b/usr/fileio/debug.c index 8e93a70e1..296025302 100644 --- a/usr/fileio/debug.c +++ b/usr/fileio/debug.c @@ -52,11 +52,11 @@ int debug_print_prefix(unsigned long trace_flag, const char *prefix, time_t tt; time(&tt); localtime_r(&tt, &t); - i += snprintf(&trace_buf[i], TRACE_BUF_SIZE, "%d:%d:%d ", + i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i, "%d:%d:%d ", t.tm_hour, t.tm_min, t.tm_sec); } if (trace_flag & TRACE_PID) - i += snprintf(&trace_buf[i], TRACE_BUF_SIZE, "[%d]: ", + i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i, "[%d]: ", gettid()); if (prefix != NULL) i += snprintf(&trace_buf[i], TRACE_BUF_SIZE - i, "%s:", prefix); From 8a4e41fb4461c2dfe023e49f8b7a827d4be4da87 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:30:40 +0000 Subject: [PATCH 65/72] iscsi-scstd: Allow the compiler to inline functions git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6385 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iscsi-scst/usr/Makefile b/iscsi-scst/usr/Makefile index f9953a253..eec0bcaad 100644 --- a/iscsi-scst/usr/Makefile +++ b/iscsi-scst/usr/Makefile @@ -26,7 +26,7 @@ OBJS_D = $(SRCS_D:.c=.o) SRCS_ADM = iscsi_adm.c param.c OBJS_ADM = $(SRCS_ADM:.c=.o) -CFLAGS += -O2 -fno-inline -Wall -Wextra -Wstrict-prototypes -Wno-sign-compare \ +CFLAGS += -O2 -Wall -Wextra -Wstrict-prototypes -Wno-sign-compare \ -Wimplicit-function-declaration -Wno-unused-parameter \ -Wno-missing-field-initializers -g -I../include -I$(SCST_INC_DIR) CFLAGS += -D_GNU_SOURCE # required for glibc >= 2.8 From f05dfcf88f112339a33aaa668e4793aaf986bf97 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:31:20 +0000 Subject: [PATCH 66/72] iscsi-scstd: Suppress a compiler warning Avoid that gcc reports the following compiler warning: message.c:197:44: warning: 'rsp_data_sz' may be used uninitialized in this function [-Wmaybe-uninitialized] git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6386 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/message.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iscsi-scst/usr/message.c b/iscsi-scst/usr/message.c index 271ef74c4..b68f80904 100644 --- a/iscsi-scst/usr/message.c +++ b/iscsi-scst/usr/message.c @@ -154,7 +154,7 @@ int iscsi_adm_request_handle(int accept_fd) struct iscsi_adm_rsp rsp; struct iovec iov[3]; void *rsp_data = NULL; - size_t rsp_data_sz; + size_t rsp_data_sz = 0; memset(&rsp, 0, sizeof(rsp)); len = sizeof(addr); From 476d0ba89846f10e2ba896552303fa987b713180 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:32:02 +0000 Subject: [PATCH 67/72] iscsi-scstd: Constify several function arguments git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6387 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/config.c | 10 +++++----- iscsi-scst/usr/event.c | 4 ++-- iscsi-scst/usr/iscsid.c | 4 ++-- iscsi-scst/usr/iscsid.h | 9 +++++---- iscsi-scst/usr/param.c | 24 +++++++++++++----------- iscsi-scst/usr/param.h | 23 +++++++++++++---------- 6 files changed, 40 insertions(+), 34 deletions(-) diff --git a/iscsi-scst/usr/config.c b/iscsi-scst/usr/config.c index 7d0ec9b00..b423a722b 100644 --- a/iscsi-scst/usr/config.c +++ b/iscsi-scst/usr/config.c @@ -478,8 +478,8 @@ int account_replace(struct target *target, int direction, return iscsi_attr_replace(list, sysfs_name, value); } -int __config_account_add(struct target *target, int dir, char *name, - char *pass, char *sysfs_name, int send_to_kern, u32 cookie) +int __config_account_add(struct target *target, int dir, char *name, char *pass, + const char *sysfs_name, int send_to_kern, u32 cookie) { int err = 0; struct iscsi_attr *user; @@ -550,8 +550,8 @@ out_destroy: goto out; } -int config_account_add(u32 tid, int dir, char *name, char *pass, char *sysfs_name, - u32 cookie) +int config_account_add(u32 tid, int dir, char *name, char *pass, + const char *sysfs_name, u32 cookie) { int err = 0; struct target *target; @@ -705,7 +705,7 @@ static int __initiator_match(int fd, char *str) return err; } -static int initiator_match(u32 tid, int fd, char *filename) +static int initiator_match(u32 tid, int fd, const char *filename) { int err = 0; FILE *fp; diff --git a/iscsi-scst/usr/event.c b/iscsi-scst/usr/event.c index 2dbf387bb..8c8b5e601 100644 --- a/iscsi-scst/usr/event.c +++ b/iscsi-scst/usr/event.c @@ -226,8 +226,8 @@ static int handle_e_del_target(int fd, const struct iscsi_kern_event *event) return res; } -static int handle_add_user(struct target *target, int dir, char *sysfs_name, - char *p, u32 cookie) +static int handle_add_user(struct target *target, int dir, + const char *sysfs_name, char *p, u32 cookie) { int res; char *name, *pass; diff --git a/iscsi-scst/usr/iscsid.c b/iscsi-scst/usr/iscsid.c index 1e4ee87bc..d1e0e46c6 100644 --- a/iscsi-scst/usr/iscsid.c +++ b/iscsi-scst/usr/iscsid.c @@ -48,7 +48,7 @@ static struct iscsi_key login_keys[] = { {NULL,}, }; -char *text_key_find(struct connection *conn, char *searchKey) +char *text_key_find(struct connection *conn, const char *searchKey) { char *data, *key, *value; int keylen, datasize; @@ -120,7 +120,7 @@ static struct buf_segment *conn_alloc_buf_segment(struct connection *conn, return seg; } -void text_key_add(struct connection *conn, char *key, const char *value) +void text_key_add(struct connection *conn, const char *key, const char *value) { struct buf_segment *seg; int keylen = strlen(key); diff --git a/iscsi-scst/usr/iscsid.h b/iscsi-scst/usr/iscsid.h index a245b3513..eadc60911 100644 --- a/iscsi-scst/usr/iscsid.h +++ b/iscsi-scst/usr/iscsid.h @@ -266,8 +266,9 @@ extern int iscsi_enabled; extern int cmnd_execute(struct connection *conn); extern void cmnd_finish(struct connection *conn); -extern char *text_key_find(struct connection *conn, char *searchKey); -extern void text_key_add(struct connection *conn, char *key, const char *value); +extern char *text_key_find(struct connection *conn, const char *searchKey); +extern void text_key_add(struct connection *conn, const char *key, + const char *value); /* log.c */ extern int log_daemon; @@ -358,9 +359,9 @@ extern int config_load(const char *config_name); extern int config_target_create(u32 *tid, char *name); extern int config_target_destroy(u32 tid); extern int config_account_add(u32 tid, int dir, char *name, char *pass, - char *sysfs_name, u32 cookie); + const char *sysfs_name, u32 cookie); extern int __config_account_add(struct target *target, int dir, char *name, - char *pass, char *sysfs_name, int send_to_kern, u32 cookie); + char *pass, const char *sysfs_name, int send_to_kern, u32 cookie); extern int config_account_query(u32 tid, int dir, const char *name, char *pass); extern int config_account_list(u32 tid, int dir, u32 *cnt, u32 *overflow, char *buf, size_t buf_sz); diff --git a/iscsi-scst/usr/param.c b/iscsi-scst/usr/param.c index 09a93e3cc..04b692e78 100644 --- a/iscsi-scst/usr/param.c +++ b/iscsi-scst/usr/param.c @@ -35,7 +35,7 @@ size_t strlcpy(char *dest, const char *src, size_t size) return ret; } -int params_index_by_name(char *name, struct iscsi_key *keys) +int params_index_by_name(const char *name, const struct iscsi_key *keys) { int i, err = -ENOENT; @@ -49,7 +49,7 @@ int params_index_by_name(char *name, struct iscsi_key *keys) return err; } -int params_index_by_name_numwild(char *name, struct iscsi_key *keys) +int params_index_by_name_numwild(const char *name, const struct iscsi_key *keys) { int i, err = -ENOENT; @@ -72,7 +72,7 @@ next: return err; } -void params_set_defaults(unsigned int *params, struct iscsi_key *keys) +void params_set_defaults(unsigned int *params, const struct iscsi_key *keys) { int i; @@ -88,7 +88,7 @@ static int range_val_to_str(unsigned int val, char *str, int len) return 0; } -static int range_str_to_val(char *str, unsigned int *val) +static int range_str_to_val(const char *str, unsigned int *val) { *val = strtol(str, NULL, 0); return 0; @@ -112,7 +112,7 @@ static int bool_val_to_str(unsigned int val, char *str, int len) return err; } -static int bool_str_to_val(char *str, unsigned int *val) +static int bool_str_to_val(const char *str, unsigned int *val) { int err = 0; @@ -142,7 +142,7 @@ static int and_set_val(struct iscsi_param *param, int idx, unsigned int *val) return 0; } -static int num_check_val(struct iscsi_key *key, unsigned int *val) +static int num_check_val(const struct iscsi_key *key, unsigned int *val) { int err = 0; @@ -201,10 +201,10 @@ out: return 0; } -static int digest_str_to_val(char *str, unsigned int *val) +static int digest_str_to_val(const char *str, unsigned int *val) { int err = 0; - char *p, *q; + const char *p, *q; p = str; *val = 0; @@ -265,7 +265,8 @@ static int marker_set_val(struct iscsi_param *params, int idx, unsigned int *val return 0; } -int params_val_to_str(struct iscsi_key *keys, int idx, unsigned int val, char *str, int len) +int params_val_to_str(const struct iscsi_key *keys, int idx, unsigned int val, + char *str, int len) { if (keys[idx].ops->val_to_str) return keys[idx].ops->val_to_str(val, str, len); @@ -273,7 +274,8 @@ int params_val_to_str(struct iscsi_key *keys, int idx, unsigned int val, char *s return 0; } -int params_str_to_val(struct iscsi_key *keys, int idx, char *str, unsigned int *val) +int params_str_to_val(const struct iscsi_key *keys, int idx, const char *str, + unsigned int *val) { if (keys[idx].ops->str_to_val) return keys[idx].ops->str_to_val(str, val); @@ -281,7 +283,7 @@ int params_str_to_val(struct iscsi_key *keys, int idx, char *str, unsigned int * return 0; } -int params_check_val(struct iscsi_key *keys, int idx, unsigned int *val) +int params_check_val(const struct iscsi_key *keys, int idx, unsigned int *val) { if (keys[idx].ops->check_val) return keys[idx].ops->check_val(&keys[idx], val); diff --git a/iscsi-scst/usr/param.h b/iscsi-scst/usr/param.h index 7b46900aa..cc0e43c62 100644 --- a/iscsi-scst/usr/param.h +++ b/iscsi-scst/usr/param.h @@ -35,13 +35,13 @@ struct iscsi_param { struct iscsi_key_ops { int (*val_to_str)(unsigned int, char *, int); - int (*str_to_val)(char *, unsigned int *); - int (*check_val)(struct iscsi_key *, unsigned int *); + int (*str_to_val)(const char *, unsigned int *); + int (*check_val)(const struct iscsi_key *, unsigned int *); int (*set_val)(struct iscsi_param *, int, unsigned int *); }; struct iscsi_key { - char *name; + const char *name; unsigned int rfc_def; unsigned int local_def; unsigned int min; @@ -56,12 +56,15 @@ extern struct iscsi_key user_keys[]; extern size_t strlcpy(char *dest, const char *src, size_t size); -extern void params_set_defaults(unsigned int *, struct iscsi_key *); -extern int params_index_by_name(char *, struct iscsi_key *); -extern int params_index_by_name_numwild(char *, struct iscsi_key *); -extern int params_val_to_str(struct iscsi_key *, int, unsigned int, char *, int); -extern int params_str_to_val(struct iscsi_key *, int, char *, unsigned int *); -extern int params_check_val(struct iscsi_key *, int, unsigned int *); -extern int params_set_val(struct iscsi_key *, struct iscsi_param *, int, unsigned int *); +extern void params_set_defaults(unsigned int *, const struct iscsi_key *); +extern int params_index_by_name(const char *, const struct iscsi_key *); +extern int params_index_by_name_numwild(const char *, const struct iscsi_key *); +extern int params_val_to_str(const struct iscsi_key *, int, unsigned int, + char *, int); +extern int params_str_to_val(const struct iscsi_key *, int, const char *, + unsigned int *); +extern int params_check_val(const struct iscsi_key *, int, unsigned int *); +extern int params_set_val(struct iscsi_key *, struct iscsi_param *, int, + unsigned int *); #endif From bb0a7c894a2cacc0892aade11000d05abbe64b4c Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:32:27 +0000 Subject: [PATCH 68/72] iscsi-scstd: Annotate a fall-through for Coverity git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6388 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/iscsi_scstd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iscsi-scst/usr/iscsi_scstd.c b/iscsi-scst/usr/iscsi_scstd.c index 777744e1a..c2d35d2a8 100644 --- a/iscsi-scst/usr/iscsi_scstd.c +++ b/iscsi-scst/usr/iscsi_scstd.c @@ -550,6 +550,7 @@ again: conn->req.data = conn->buffer + conn->req.ahssize; goto read_again; } + /* fall-through */ case IOSTATE_READ_AHS_DATA: conn_write_pdu(conn); From 11df04544944bc3e607020e4396643bd0b75208a Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:32:53 +0000 Subject: [PATCH 69/72] iscsiadm: Fix a resource leak in an error path Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6389 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/message.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iscsi-scst/usr/message.c b/iscsi-scst/usr/message.c index b68f80904..6a6802108 100644 --- a/iscsi-scst/usr/message.c +++ b/iscsi-scst/usr/message.c @@ -39,8 +39,10 @@ int iscsi_adm_request_listen(void) memcpy((char *) &addr.sun_path + 1, ISCSI_ADM_NAMESPACE, strlen(ISCSI_ADM_NAMESPACE)); - if ((err = bind(fd, (struct sockaddr *) &addr, sizeof(addr))) < 0) + if ((err = bind(fd, (struct sockaddr *) &addr, sizeof(addr))) < 0) { + close(fd); return err; + } if ((err = listen(fd, 32)) < 0) { close(fd); From 2a6a25ba455ea6affa84022abff03c7d33b59583 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:35:43 +0000 Subject: [PATCH 70/72] qla2x00t: Change type of first argument of qla24xx_prep_ct_fm_req() This makes it easier for Coverity to analyze this code. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6390 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- qla2x00t/qla_gs.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/qla2x00t/qla_gs.c b/qla2x00t/qla_gs.c index 71fc63bf4..bd7a2cc13 100644 --- a/qla2x00t/qla_gs.c +++ b/qla2x00t/qla_gs.c @@ -1838,18 +1838,17 @@ qla24xx_prep_ms_fm_iocb(scsi_qla_host_t *vha, uint32_t req_size, static inline struct ct_sns_req * -qla24xx_prep_ct_fm_req(struct ct_sns_req *ct_req, uint16_t cmd, - uint16_t rsp_size) +qla24xx_prep_ct_fm_req(struct ct_sns_pkt *p, uint16_t cmd, uint16_t rsp_size) { - memset(ct_req, 0, sizeof(struct ct_sns_pkt)); + memset(p, 0, sizeof(struct ct_sns_pkt)); - ct_req->header.revision = 0x01; - ct_req->header.gs_type = 0xFA; - ct_req->header.gs_subtype = 0x01; - ct_req->command = cpu_to_be16(cmd); - ct_req->max_rsp_size = cpu_to_be16((rsp_size - 16) / 4); + p->p.req.header.revision = 0x01; + p->p.req.header.gs_type = 0xFA; + p->p.req.header.gs_subtype = 0x01; + p->p.req.command = cpu_to_be16(cmd); + p->p.req.max_rsp_size = cpu_to_be16((rsp_size - 16) / 4); - return ct_req; + return &p->p.req; } /** @@ -1885,8 +1884,8 @@ qla2x00_gpsc(scsi_qla_host_t *vha, sw_info_t *list) GPSC_RSP_SIZE); /* Prepare CT request */ - ct_req = qla24xx_prep_ct_fm_req(&ha->ct_sns->p.req, - GPSC_CMD, GPSC_RSP_SIZE); + ct_req = qla24xx_prep_ct_fm_req(ha->ct_sns, GPSC_CMD, + GPSC_RSP_SIZE); ct_rsp = &ha->ct_sns->p.rsp; /* Prepare CT arguments -- port_name */ From 7b8ad567909928d39444a5fc9444c177b10ecd09 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:36:22 +0000 Subject: [PATCH 71/72] qla2x00t: Fix a potential buffer overflow Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6391 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- qla2x00t/qla_init.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qla2x00t/qla_init.c b/qla2x00t/qla_init.c index 074ce7300..e0c01ceca 100644 --- a/qla2x00t/qla_init.c +++ b/qla2x00t/qla_init.c @@ -2187,8 +2187,9 @@ qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, if (use_tbl && ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && index < QLA_MODEL_NAMES) { - strcpy(ha->model_number, - qla2x00_model_name[index * 2]); + strlcpy(ha->model_number, + qla2x00_model_name[index * 2], + sizeof(ha->model_number)); strncpy(ha->model_desc, qla2x00_model_name[index * 2 + 1], sizeof(ha->model_desc) - 1); From cd0a7b7b9d849ebdbfd94b419c4761a50791aa50 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 17 Jun 2015 00:36:52 +0000 Subject: [PATCH 72/72] qla2x00t: Fix a potential buffer overflow Detected by Coverity. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6392 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- qla2x00t/qla_gs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qla2x00t/qla_gs.c b/qla2x00t/qla_gs.c index bd7a2cc13..10d5b853a 100644 --- a/qla2x00t/qla_gs.c +++ b/qla2x00t/qla_gs.c @@ -1355,7 +1355,7 @@ qla2x00_fdmi_rhba(scsi_qla_host_t *vha) /* Model name. */ eiter = (struct ct_fdmi_hba_attr *) (entries + size); eiter->type = __constant_cpu_to_be16(FDMI_HBA_MODEL); - strcpy(eiter->a.model, ha->model_number); + strlcpy(eiter->a.model, ha->model_number, sizeof(eiter->a.model)); alen = strlen(eiter->a.model); alen += (alen & 3) ? (4 - (alen & 3)) : 4; eiter->len = cpu_to_be16(4 + alen);