Blob Blame History Raw
%define kmod_name		qla2xxx
%define kmod_vendor		redhat
%define kmod_driver_version	10.01.00.20.07.8_k_dup7.7
%define kmod_driver_epoch	%{nil}
%define kmod_rpm_release	2
%define kmod_kernel_version	3.10.0-1062.el7
%define kmod_kernel_version_min	%{nil}
%define kmod_kernel_version_dep	%{nil}
%define kmod_kbuild_dir		drivers/scsi/qla2xxx
%define kmod_dependencies       %{nil}
%define kmod_dist_build_deps	%{nil}
%define kmod_build_dependencies	%{nil}
%define kmod_devel_package	1
%define kmod_install_path	extra/kmod-redhat-qla2xxx
%define kernel_pkg		kernel
%define kernel_devel_pkg	kernel-devel
%define kernel_modules_pkg	kernel-modules

%{!?dist: %define dist .el7_7}
%{!?make_build: %define make_build make}

%if "%{kmod_kernel_version_dep}" == ""
%define kmod_kernel_version_dep %{kmod_kernel_version}
%endif

%if "%{kmod_dist_build_deps}" == ""
%if (0%{?rhel} > 7) || (0%{?centos} > 7)
%define kmod_dist_build_deps redhat-rpm-config kernel-abi-whitelists elfutils-libelf-devel kernel-rpm-macros kmod
%else
%define kmod_dist_build_deps redhat-rpm-config kernel-abi-whitelists
%endif
%endif

Source0:	%{kmod_name}-%{kmod_vendor}-%{kmod_driver_version}.tar.bz2
# Source code patches
Patch0:	0001-scsi-scsi-qla2xxx-Add-protection-mask-module-paramet.patch
Patch1:	0002-scsi-scsi-qla2xxx-Fix-DMA-error-when-the-DIF-sg-buff.patch
Patch2:	0003-scsi-scsi-qla2xxx-no-need-to-check-return-value-of-d.patch
Patch3:	0004-scsi-scsi-qla2xxx-Fix-N2N-target-discovery-with-Loca.patch
Patch4:	0005-scsi-scsi-qla2xxx-Change-default-ZIO-threshold.patch
Patch5:	0006-scsi-scsi-qla2xxx-Fix-session-cleanup-hang.patch
Patch6:	0007-scsi-scsi-qla2xxx-flush-IO-on-chip-reset-or-sess-del.patch
Patch7:	0008-scsi-scsi-qla2xxx-fix-fcport-null-pointer-access.patch
Patch8:	0009-scsi-scsi-qla2xxx-allow-session-delete-to-finish-bef.patch
Patch9:	0010-scsi-scsi-qla2xxx-Fix-SRB-allocation-flag-to-avoid-s.patch
Patch10:	0011-scsi-scsi-qla2xxx-Prevent-memory-leak-for-CT-req-rsp.patch
Patch11:	0012-scsi-scsi-qla2xxx-Restore-FAWWPN-of-Physical-Port-on.patch
Patch12:	0013-scsi-scsi-qla2xxx-Fix-fw-options-handle-eh_bus_reset.patch
Patch13:	0014-scsi-scsi-qla2xxx-Move-debug-messages-before-sending.patch
Patch14:	0015-scsi-scsi-qla2xxx-remove-redundant-null-check-on-poi.patch
Patch15:	0016-scsi-scsi-qla2xxx-Fix-LUN-discovery-if-loop-id-is-no.patch
Patch16:	0017-scsi-scsi-qla2xxx-Add-First-Burst-support-for-FC-NVM.patch
Patch17:	0018-scsi-scsi-qla2xxx-Fix-unload-when-NVMe-devices-are-c.patch
Patch18:	0019-scsi-scsi-qla2xxx-Check-for-FW-started-flag-before-a.patch
Patch19:	0020-scsi-scsi-qla2xxx-Prevent-multiple-ADISC-commands-pe.patch
Patch20:	0021-scsi-scsi-qla2xxx-Add-support-for-setting-port-speed.patch
Patch21:	0022-scsi-scsi-qla2xxx-Prevent-SysFS-access-when-chip-is-.patch
Patch22:	0023-scsi-scsi-qla2xxx-Move-marker-request-behind-QPair.patch
Patch23:	0024-scsi-scsi-qla2xxx-Fix-code-indentation-for-qla27xx_f.patch
Patch24:	0025-scsi-scsi-qla2xxx-Add-new-FW-dump-template-entry-typ.patch
Patch25:	0026-scsi-scsi-qla2xxx-Fix-panic-in-qla_dfs_tgt_counters_.patch
Patch26:	0027-scsi-scsi-qla2xxx-avoid-printf-format-warning.patch
Patch27:	0028-scsi-scsi-qla2xxx-check-for-kstrtol-failure.patch
Patch28:	0029-scsi-scsi-qla2xxx-Add-fw_attr-and-port_no-SysFS-node.patch
Patch29:	0030-scsi-scsi-qla2xxx-Remove-FW-default-template.patch
Patch30:	0031-scsi-scsi-qla2xxx-Fix-routine-qla27xx_dump_-mpi-ram.patch
Patch31:	0032-scsi-scsi-qla2xxx-Add-Device-ID-for-ISP28XX.patch
Patch32:	0033-scsi-scsi-qla2xxx-Add-Serdes-support-for-ISP28XX.patch
Patch33:	0034-scsi-scsi-qla2xxx-Correctly-report-max-min-supported.patch
Patch34:	0035-scsi-scsi-qla2xxx-Cleanups-for-NVRAM-Flash-read-writ.patch
Patch35:	0036-scsi-scsi-qla2xxx-Add-support-for-multiple-fwdump-te.patch
Patch36:	0037-scsi-scsi-qla2xxx-Update-flash-read-write-routine.patch
Patch37:	0038-scsi-scsi-qla2xxx-Correction-and-improvement-to-fwdt.patch
Patch38:	0039-scsi-scsi-qla2xxx-Simplification-of-register-address.patch
Patch39:	0040-scsi-scsi-qla2xxx-Add-28xx-flash-primary-secondary-s.patch
Patch40:	0041-scsi-scsi-qla2xxx-Secure-flash-update-support-for-IS.patch
Patch41:	0042-scsi-scsi-qla2xxx-Fix-a-small-typo-in-qla_bsg.c.patch
Patch42:	0043-scsi-scsi-qla2xxx-Simplify-conditional-check-again.patch
Patch43:	0044-scsi-scsi-qla2xxx-Set-the-SCSI-command-result-before.patch
Patch44:	0045-scsi-scsi-qla2xxx-Set-the-qpair-in-SRB-to-NULL-when-.patch
Patch45:	0046-scsi-scsi-qla2xxx-Reset-the-FCF_ASYNC_-SENT-ACTIVE-f.patch
Patch46:	0047-scsi-scsi-qla2xxx-Increase-the-max_sgl_segments-to-1.patch
Patch47:	0048-scsi-scsi-qla2xxx-Disable-T10-DIF-feature-with-FC-NV.patch
Patch48:	0049-scsi-scsi-qla2xxx-Fix-incorrect-region-size-setting-.patch
Patch49:	0050-scsi-scsi-qla2xxx-Further-limit-FLASH-region-write-a.patch
Patch50:	0051-scsi-scsi-qla2xxx-Fix-fw-dump-corruption.patch
Patch51:	0052-scsi-scsi-qla2xxx-Use-mutex-protection-during-qla2x0.patch
Patch52:	0053-scsi-scsi-qla2xxx-Cleanup-fcport-memory-to-prevent-l.patch
Patch53:	0054-scsi-scsi-qla2xxx-Set-remote-port-devloss-timeout-to.patch
Patch54:	0055-scsi-scsi-qla2xxx-Cleanup-redundant-qla2x00_abort_al.patch
Patch55:	0056-scsi-scsi-qla2xxx-Fix-driver-unload-when-FC-NVMe-LUN.patch
Patch56:	0057-scsi-scsi-qla2xxx-Remove-useless-set-memory-to-zero-.patch
Patch57:	0058-scsi-scsi-qla2xxx-fix-spelling-mistake-alredy-alread.patch
Patch58:	0059-scsi-scsi-qla2xxx-Remove-a-comment-that-refers-to-th.patch
Patch59:	0060-scsi-scsi-qla2xxx-Use-ARRAY_SIZE-in-the-definition-o.patch
Patch60:	0061-scsi-scsi-qla2xxx-Declare-local-symbols-static.patch
Patch61:	0062-scsi-scsi-qla2xxx-Make-qla2x00_process_response_queu.patch
Patch62:	0063-scsi-scsi-qla2xxx-Use-get-put_unaligned-where-approp.patch
Patch63:	0064-scsi-scsi-qla2xxx-Unregister-chrdev-if-module-initia.patch
Patch64:	0065-scsi-scsi-tcm_qla2xxx-Minimize-include-directives.patch
Patch65:	0066-scsi-scsi-qla2xxx-Fix-FC-AL-connection-target-discov.patch
Patch66:	0067-scsi-scsi-qla2xxx-Use-tabs-to-indent-code.patch
Patch67:	0068-scsi-scsi-qla2xxx-Leave-a-blank-line-after-declarati.patch
Patch68:	0069-scsi-scsi-qla2xxx-Fix-formatting-of-pointer-types.patch
Patch69:	0070-scsi-scsi-qla2xxx-Insert-spaces-where-required.patch
Patch70:	0071-scsi-scsi-qla2xxx-Move-the-port_state_strdefinition-.patch
Patch71:	0072-scsi-scsi-qla2xxx-Declare-qla24xx_build_scsi_crc_2_i.patch
Patch72:	0073-scsi-scsi-qla2xxx-Remove-qla_tgt_cmd.data_work-and-q.patch
Patch73:	0074-scsi-scsi-qla2xxx-Remove-two-superfluous-casts.patch
Patch74:	0075-scsi-scsi-qla2xxx-Move-qla2x00_set_fcport_state-from.patch
Patch75:	0076-scsi-scsi-qla2xxx-Fix-read-offset-in-qla24xx_load_ri.patch
Patch76:	0077-scsi-scsi-qla2xxx-Update-two-source-code-comments.patch
Patch77:	0078-scsi-scsi-qla2xxx-Fix-a-format-specifier.patch
Patch78:	0079-scsi-scsi-qla2xxx-Move-qla2x00_set_reserved_loop_ids.patch
Patch79:	0080-scsi-scsi-qla2xxx-Declare-qla2x00_find_new_loop_id-s.patch
Patch80:	0081-scsi-scsi-qla2xxx-Remove-a-set-but-not-used-variable.patch
Patch81:	0082-scsi-scsi-qla2xxx-Move-qla2x00_clear_loop_id-from-ql.patch
Patch82:	0083-scsi-scsi-qla2xxx-Move-qla2x00_is_reserved_id-from-q.patch
Patch83:	0084-scsi-scsi-qla2xxx-Remove-the-fcport-test-from-qla_nv.patch
Patch84:	0085-scsi-scsi-qla2xxx-NULL-check-before-some-freeing-fun.patch
Patch85:	0086-scsi-scsi-qla2xxx-Make-qla2x00_mem_free-easier-to-ve.patch
Patch86:	0087-scsi-scsi-qla2xxx-Avoid-that-qla2x00_mem_free-crashe.patch
Patch87:	0088-scsi-scsi-qla2xxx-Avoid-that-Coverity-complains-abou.patch
Patch88:	0089-scsi-scsi-qla2xxx-Log-the-status-code-if-a-firmware-.patch
Patch89:	0090-scsi-scsi-qla2xxx-Fix-a-qla24xx_enable_msix-error-pa.patch
Patch90:	0091-scsi-scsi-qla2xxx-Fix-use-after-free-issues-in-qla2x.patch
Patch91:	0092-scsi-scsi-qla2xxx-Pass-little-endian-values-to-the-f.patch
Patch92:	0093-scsi-scsi-qla2xxx-Check-the-size-of-firmware-data-st.patch
Patch93:	0094-scsi-scsi-qla2xxx-Use-an-on-stack-completion-in-qla2.patch
Patch94:	0095-scsi-scsi-qla2xxx-Remove-a-set-but-not-used-variable.patch
Patch95:	0096-scsi-scsi-qla2xxx-Split-the-__qla2x00_abort_all_cmds.patch
Patch96:	0097-scsi-scsi-qla2xxx-Fix-race-conditions-in-the-code-fo.patch
Patch97:	0098-scsi-scsi-qla2xxx-Complain-loudly-about-reference-co.patch
Patch98:	0099-scsi-scsi-qla2xxx-Avoid-that-qlt_send_resp_ctio-corr.patch
Patch99:	0100-scsi-scsi-qla2xxx-Fix-hardlockup-in-abort-command-du.patch
Patch100:	0101-scsi-scsi-qla2xxx-remove-double-assignment-in-qla2x0.patch
Patch101:	0102-scsi-scsi-qla2xxx-Fix-kernel-crash-after-disconnecti.patch
Patch102:	0103-scsi-scsi-qla2xxx-on-session-delete-return-nvme-cmd.patch
Patch103:	0104-scsi-scsi-qla2xxx-Fix-NVME-cmd-and-LS-cmd-timeout-ra.patch
Patch104:	0105-scsi-scsi-qla2xxx-move-IO-flush-to-the-front-of-NVME.patch
Patch105:	0106-scsi-scsi-qla2xxx-Remove-unnecessary-null-check.patch
Patch106:	0107-scsi-scsi-qla2xxx-Replace-vmalloc-memset-with-vzallo.patch
Patch107:	0108-scsi-scsi-qla2xxx-Fix-DMA-unmap-leak.patch
Patch108:	0109-scsi-scsi-qla2xxx-Fix-different-size-DMA-Alloc-Unmap.patch
Patch109:	0110-scsi-scsi-qla2xxx-Fix-abort-timeout-race-condition.patch
Patch110:	0111-scsi-scsi-qla2xxx-Allow-NVMe-IO-to-resume-with-short.patch
Patch111:	0112-scsi-scsi-qla2xxx-Fix-hang-in-fcport-delete-path.patch
Patch112:	0113-scsi-scsi-qla2xxx-Use-common-update-firmware-options.patch
Patch113:	0114-scsi-scsi-qla2xxx-Fix-NVMe-port-discovery-after-a-sh.patch
Patch114:	0115-scsi-scsi-qla2xxx-Correct-error-handling-during-init.patch
Patch115:	0116-scsi-scsi-qla2xxx-Fix-Relogin-to-prevent-modifying-s.patch
Patch116:	0117-scsi-scsi-qla2xxx-Reject-EH_-abort-device_reset-targ.patch
Patch117:	0118-scsi-qla2xxx-Update-driver-version-to-10.01.00.18.07.patch
Patch118:	0120-scsi-scsi-qla2xxx-qla2x00_alloc_fw_dump-set-ha-eft.patch
Patch119:	0121-scsi-scsi-qla2xxx-cleanup-trace-buffer-initializatio.patch
Patch120:	0122-scsi-scsi-qla2xxx-Fix-flash-read-for-Qlogic-ISPs.patch
Patch121:	0123-scsi-scsi-qla2xxx-Fix-driver-reload-for-ISP82xx.patch
Patch122:	0124-scsi-scsi-qla2xxx-Use-correct-size-in-call-to-dma_fr.patch
Patch123:	0125-scsi-scsi-qla2xxx-Initialized-mailbox-to-prevent-dri.patch
Patch124:	0126-scsi-scsi-qla2xxx-Fix-panic-from-use-after-free-in-q.patch
Patch125:	0127-scsi-scsi-qla2xxx-Fix-stuck-login-session.patch
Patch126:	0128-scsi-scsi-qla2xxx-Remove-a-superfluous-forward-decla.patch
Patch127:	0129-scsi-scsi-qla2xxx-Reduce-the-number-of-forward-decla.patch
Patch128:	0130-scsi-scsi-qla2xxx-Make-qla24xx_async_abort_cmd-stati.patch
Patch129:	0131-scsi-scsi-qla2xxx-Really-fix-qla2xxx_eh_abort.patch
Patch130:	0132-scsi-scsi-qla2xxx-Introduce-the-function-qla2xxx_ini.patch
Patch131:	0133-scsi-scsi-qla2xxx-Fix-a-race-condition-between-abort.patch
Patch132:	0134-scsi-scsi-qla2xxx-Fix-N2N-link-reset.patch
Patch133:	0135-scsi-scsi-qla2xxx-Fix-N2N-link-up-fail.patch
Patch134:	0136-scsi-scsi-qla2xxx-Use-tabs-instead-of-spaces-for-ind.patch
Patch135:	0137-scsi-scsi-qla2xxx-Dual-FCP-NVMe-target-port-support.patch
Patch136:	0138-scsi-scsi-qla2xxx-Inline-the-qla2x00_fcport_event_ha.patch
Patch137:	0139-scsi-scsi-qla2xxx-Add-error-handling-for-PLOGI-ELS-p.patch
Patch138:	0140-scsi-scsi-qla2xxx-Retry-PLOGI-on-FC-NVMe-PRLI-failur.patch
Patch139:	0141-scsi-scsi-qla2xxx-Do-command-completion-on-abort-tim.patch
Patch140:	0142-scsi-scsi-qla2xxx-Uninline-qla2x00_init_timer.patch
Patch141:	0143-scsi-scsi-qla2xxx-Fix-premature-timer-expiration.patch
Patch142:	0144-scsi-scsi-qla2xxx-Fix-SRB-leak-on-switch-command-tim.patch
Patch143:	0145-scsi-scsi-qla2xxx-Fix-driver-unload-hang.patch
Patch144:	0146-scsi-scsi-qla2xxx-Make-qla2x00_abort_srb-again-decre.patch
Patch145:	0147-scsi-scsi-qla2xxx-Fix-double-scsi_done-for-abort-pat.patch
Patch146:	0148-scsi-scsi-qla2xxx-Fix-a-NULL-pointer-dereference.patch
Patch147:	0149-scsi-scsi-qla2xxx-Fix-device-connect-issues-in-P2P-c.patch
Patch148:	0150-scsi-scsi-qla2xxx-Fix-partial-flash-write-of-MBI.patch
Patch149:	0151-scsi-qla2xxx-Update-driver-version.patch
Patch150:	0153-scsi-scsi-qla2xxx-Correctly-retrieve-and-interpret-a.patch
Patch151:	0154-scsi-scsi-qla2xxx-Added-support-for-MPI-and-PEP-regi.patch
Patch152:	0155-scsi-scsi-qla2xxx-Fix-incorrect-SFUB-length-used-for.patch
Patch153:	9000-bump-kmod-version.patch

%define findpat %( echo "%""P" )
%define __find_requires /usr/lib/rpm/redhat/find-requires.ksyms
%define __find_provides /usr/lib/rpm/redhat/find-provides.ksyms %{kmod_name} %{?epoch:%{epoch}:}%{version}-%{release}
%define sbindir %( if [ -d "/sbin" -a \! -h "/sbin" ]; then echo "/sbin"; else echo %{_sbindir}; fi )
%define dup_state_dir %{_localstatedir}/lib/rpm-state/kmod-dups
%define kver_state_dir %{dup_state_dir}/kver
%define kver_state_file %{kver_state_dir}/%{kmod_kernel_version}.%(arch)
%define dup_module_list %{dup_state_dir}/rpm-kmod-%{kmod_name}-modules

Name:		kmod-redhat-qla2xxx
Version:	%{kmod_driver_version}
Release:	%{kmod_rpm_release}%{?dist}
%if "%{kmod_driver_epoch}" != ""
Epoch:		%{kmod_driver_epoch}
%endif
Summary:	qla2xxx kernel module for Driver Update Program
Group:		System/Kernel
License:	GPLv2
URL:		https://www.kernel.org/
BuildRoot:	%(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRequires:	%kernel_devel_pkg = %kmod_kernel_version
%if "%{kmod_dist_build_deps}" != ""
BuildRequires:	%{kmod_dist_build_deps}
%endif
ExclusiveArch:	x86_64
%global kernel_source() /usr/src/kernels/%{kmod_kernel_version}.$(arch)

%global _use_internal_dependency_generator 0
%if "%{?kmod_kernel_version_min}" != ""
Provides:	%kernel_modules_pkg >= %{kmod_kernel_version_min}.%{_target_cpu}
%else
Provides:	%kernel_modules_pkg = %{kmod_kernel_version_dep}.%{_target_cpu}
%endif
Provides:	kmod-%{kmod_name} = %{?epoch:%{epoch}:}%{version}-%{release}
Requires(post):	%{sbindir}/weak-modules
Requires(postun):	%{sbindir}/weak-modules
Requires:	kernel >= 3.10.0-1062.el7

Requires:	kernel < 3.10.0-1063.el7
%if 0
Requires: firmware(%{kmod_name}) = ENTER_FIRMWARE_VERSION
%endif
%if "%{kmod_build_dependencies}" != ""
BuildRequires:  %{kmod_build_dependencies}
%endif
%if "%{kmod_dependencies}" != ""
Requires:       %{kmod_dependencies}
%endif
# if there are multiple kmods for the same driver from different vendors,
# they should conflict with each other.
Conflicts:	kmod-%{kmod_name}

%description
qla2xxx kernel module for Driver Update Program

%if 0

%package -n kmod-redhat-qla2xxx-firmware
Version:	ENTER_FIRMWARE_VERSION
Summary:	qla2xxx firmware for Driver Update Program
Provides:	firmware(%{kmod_name}) = ENTER_FIRMWARE_VERSION
%if "%{kmod_kernel_version_min}" != ""
Provides:	%kernel_modules_pkg >= %{kmod_kernel_version_min}.%{_target_cpu}
%else
Provides:	%kernel_modules_pkg = %{kmod_kernel_version_dep}.%{_target_cpu}
%endif
%description -n  kmod-redhat-qla2xxx-firmware
qla2xxx firmware for Driver Update Program


%files -n kmod-redhat-qla2xxx-firmware
%defattr(644,root,root,755)
%{FIRMWARE_FILES}

%endif

# Development package
%if 0%{kmod_devel_package}
%package -n kmod-redhat-qla2xxx-devel
Version:	%{kmod_driver_version}
Requires:	kernel >= 3.10.0-1062.el7

Requires:	kernel < 3.10.0-1063.el7
Summary:	qla2xxx development files for Driver Update Program

%description -n  kmod-redhat-qla2xxx-devel
qla2xxx development files for Driver Update Program


%files -n kmod-redhat-qla2xxx-devel
%defattr(644,root,root,755)
/usr/share/kmod-%{kmod_vendor}-%{kmod_name}/Module.symvers
%endif

%post
modules=( $(find /lib/modules/%{kmod_kernel_version}.%(arch)/%{kmod_install_path} | grep '\.ko$') )
printf '%s\n' "${modules[@]}" | %{sbindir}/weak-modules --add-modules --no-initramfs

mkdir -p "%{kver_state_dir}"
touch "%{kver_state_file}"

exit 0

%posttrans
# We have to re-implement part of weak-modules here because it doesn't allow
# calling initramfs regeneration separately
if [ -f "%{kver_state_file}" ]; then
	kver_base="%{kmod_kernel_version_dep}"
	kvers=$(ls -d "/lib/modules/${kver_base%%.*}"*)

	for k_dir in $kvers; do
		k="${k_dir#/lib/modules/}"

		tmp_initramfs="/boot/initramfs-$k.tmp"
		dst_initramfs="/boot/initramfs-$k.img"

		# The same check as in weak-modules: we assume that the kernel present
		# if the symvers file exists.
		if [ -e "/boot/symvers-$k.gz" ]; then
			/usr/bin/dracut -f "$tmp_initramfs" "$k" || exit 1
			cmp -s "$tmp_initramfs" "$dst_initramfs"
			if [ "$?" = 1 ]; then
				mv "$tmp_initramfs" "$dst_initramfs"
			else
				rm -f "$tmp_initramfs"
			fi
		fi
	done

	rm -f "%{kver_state_file}"
	rmdir "%{kver_state_dir}" 2> /dev/null
fi

rmdir "%{dup_state_dir}" 2> /dev/null

exit 0

%preun
if rpm -q --filetriggers kmod 2> /dev/null| grep -q "Trigger for weak-modules call on kmod removal"; then
	mkdir -p "%{kver_state_dir}"
	touch "%{kver_state_file}"
fi

mkdir -p "%{dup_state_dir}"
rpm -ql kmod-redhat-qla2xxx-%{kmod_driver_version}-%{kmod_rpm_release}%{?dist}.$(arch) | \
	grep '\.ko$' > "%{dup_module_list}"

%postun
if rpm -q --filetriggers kmod 2> /dev/null| grep -q "Trigger for weak-modules call on kmod removal"; then
	initramfs_opt="--no-initramfs"
else
	initramfs_opt=""
fi

modules=( $(cat "%{dup_module_list}") )
rm -f "%{dup_module_list}"
printf '%s\n' "${modules[@]}" | %{sbindir}/weak-modules --remove-modules $initramfs_opt

rmdir "%{dup_state_dir}" 2> /dev/null

exit 0

%files
%defattr(644,root,root,755)
/lib/modules/%{kmod_kernel_version}.%(arch)
/etc/depmod.d/%{kmod_name}.conf
/usr/share/doc/kmod-%{kmod_name}/greylist.txt

%prep
%setup -n %{kmod_name}-%{kmod_vendor}-%{kmod_driver_version}

%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
%patch16 -p1
%patch17 -p1
%patch18 -p1
%patch19 -p1
%patch20 -p1
%patch21 -p1
%patch22 -p1
%patch23 -p1
%patch24 -p1
%patch25 -p1
%patch26 -p1
%patch27 -p1
%patch28 -p1
%patch29 -p1
%patch30 -p1
%patch31 -p1
%patch32 -p1
%patch33 -p1
%patch34 -p1
%patch35 -p1
%patch36 -p1
%patch37 -p1
%patch38 -p1
%patch39 -p1
%patch40 -p1
%patch41 -p1
%patch42 -p1
%patch43 -p1
%patch44 -p1
%patch45 -p1
%patch46 -p1
%patch47 -p1
%patch48 -p1
%patch49 -p1
%patch50 -p1
%patch51 -p1
%patch52 -p1
%patch53 -p1
%patch54 -p1
%patch55 -p1
%patch56 -p1
%patch57 -p1
%patch58 -p1
%patch59 -p1
%patch60 -p1
%patch61 -p1
%patch62 -p1
%patch63 -p1
%patch64 -p1
%patch65 -p1
%patch66 -p1
%patch67 -p1
%patch68 -p1
%patch69 -p1
%patch70 -p1
%patch71 -p1
%patch72 -p1
%patch73 -p1
%patch74 -p1
%patch75 -p1
%patch76 -p1
%patch77 -p1
%patch78 -p1
%patch79 -p1
%patch80 -p1
%patch81 -p1
%patch82 -p1
%patch83 -p1
%patch84 -p1
%patch85 -p1
%patch86 -p1
%patch87 -p1
%patch88 -p1
%patch89 -p1
%patch90 -p1
%patch91 -p1
%patch92 -p1
%patch93 -p1
%patch94 -p1
%patch95 -p1
%patch96 -p1
%patch97 -p1
%patch98 -p1
%patch99 -p1
%patch100 -p1
%patch101 -p1
%patch102 -p1
%patch103 -p1
%patch104 -p1
%patch105 -p1
%patch106 -p1
%patch107 -p1
%patch108 -p1
%patch109 -p1
%patch110 -p1
%patch111 -p1
%patch112 -p1
%patch113 -p1
%patch114 -p1
%patch115 -p1
%patch116 -p1
%patch117 -p1
%patch118 -p1
%patch119 -p1
%patch120 -p1
%patch121 -p1
%patch122 -p1
%patch123 -p1
%patch124 -p1
%patch125 -p1
%patch126 -p1
%patch127 -p1
%patch128 -p1
%patch129 -p1
%patch130 -p1
%patch131 -p1
%patch132 -p1
%patch133 -p1
%patch134 -p1
%patch135 -p1
%patch136 -p1
%patch137 -p1
%patch138 -p1
%patch139 -p1
%patch140 -p1
%patch141 -p1
%patch142 -p1
%patch143 -p1
%patch144 -p1
%patch145 -p1
%patch146 -p1
%patch147 -p1
%patch148 -p1
%patch149 -p1
%patch150 -p1
%patch151 -p1
%patch152 -p1
%patch153 -p1
set -- *
mkdir source
mv "$@" source/
mkdir obj

%build
rm -rf obj
cp -r source obj

PWD_PATH="$PWD"
%if "%{workaround_no_pwd_rel_path}" != "1"
PWD_PATH=$(realpath --relative-to="%{kernel_source}" . 2>/dev/null || echo "$PWD")
%endif
%{make_build} -C %{kernel_source} V=1 M="$PWD_PATH/obj/%{kmod_kbuild_dir}" \
	NOSTDINC_FLAGS="-I$PWD_PATH/obj/include -I$PWD_PATH/obj/include/uapi" \
	EXTRA_CFLAGS="%{nil}" \
	%{nil}
# mark modules executable so that strip-to-file can strip them
find obj/%{kmod_kbuild_dir} -name "*.ko" -type f -exec chmod u+x '{}' +

whitelist="/lib/modules/kabi-current/kabi_whitelist_%{_target_cpu}"
for modules in $( find obj/%{kmod_kbuild_dir} -name "*.ko" -type f -printf "%{findpat}\n" | sed 's|\.ko$||' | sort -u ) ; do
	# update depmod.conf
	module_weak_path=$(echo "$modules" | sed 's/[\/]*[^\/]*$//')
	if [ -z "$module_weak_path" ]; then
		module_weak_path=%{name}
	else
		module_weak_path=%{name}/$module_weak_path
	fi
	echo "override $(echo $modules | sed 's/.*\///')" \
	     "$(echo "%{kmod_kernel_version_dep}" |
	        sed 's/\.[^\.]*$//;
		     s/\([.+?^$\/\\|()\[]\|\]\)/\\\0/g').*" \
		     "weak-updates/$module_weak_path" >> source/depmod.conf

	# update greylist
	nm -u obj/%{kmod_kbuild_dir}/$modules.ko | sed 's/.*U //' |  sed 's/^\.//' | sort -u | while read -r symbol; do
		grep -q "^\s*$symbol\$" $whitelist || echo "$symbol" >> source/greylist
	done
done
sort -u source/greylist | uniq > source/greylist.txt

%install
export INSTALL_MOD_PATH=$RPM_BUILD_ROOT
export INSTALL_MOD_DIR=%{kmod_install_path}
PWD_PATH="$PWD"
%if "%{workaround_no_pwd_rel_path}" != "1"
PWD_PATH=$(realpath --relative-to="%{kernel_source}" . 2>/dev/null || echo "$PWD")
%endif
make -C %{kernel_source} modules_install \
	M=$PWD_PATH/obj/%{kmod_kbuild_dir}
# Cleanup unnecessary kernel-generated module dependency files.
find $INSTALL_MOD_PATH/lib/modules -iname 'modules.*' -exec rm {} \;

install -m 644 -D source/depmod.conf $RPM_BUILD_ROOT/etc/depmod.d/%{kmod_name}.conf
install -m 644 -D source/greylist.txt $RPM_BUILD_ROOT/usr/share/doc/kmod-%{kmod_name}/greylist.txt
%if 0
%{FIRMWARE_FILES_INSTALL}
%endif
%if 0%{kmod_devel_package}
install -m 644 -D $PWD/obj/%{kmod_kbuild_dir}/Module.symvers $RPM_BUILD_ROOT/usr/share/kmod-%{kmod_vendor}-%{kmod_name}/Module.symvers
%endif

%clean
rm -rf $RPM_BUILD_ROOT

%changelog
* Tue Jan 07 2020 Eugene Syromiatnikov <esyr@redhat.com> 10.01.00.20.07.8_k_dup7.7-2
- Rebuild due to issues with brew environment

* Mon Jan 06 2020 Eugene Syromiatnikov <esyr@redhat.com> 10.01.00.20.07.8_k_dup7.7-1
- c45db7d2f34d6fad924c20443f73147dca7f6e29
- qla2xxx kernel module for Driver Update Program
- Resolves: #bz1784769