#needsrootforbuild
# Build documentation package
%bcond_with doc

Name: spdk
Version: 24.01
Release: 6
Summary: Set of libraries and utilities for high performance user-mode storage
License: BSD and MIT
URL: http://spdk.io
Source0: https://github.com/spdk/spdk/archive/refs/tags/v%{version}.tar.gz
Patch1: 0001-Add-without-ISA-L-option-and-disabled-by-default.patch
Patch2: 0002-backport-Add-ctrlr_lock-for-cuse-register-and-unregister.patch

%define package_version %{version}-%{release}

%define install_datadir %{buildroot}/%{_datadir}/%{name}
%define install_sbindir %{buildroot}/%{_sbindir}
%define install_docdir %{buildroot}/%{_docdir}/%{name}

# Distros that don't support python3 will use python2
%if "%{dist}" == ".el7"
%define use_python2 1
%else
%define use_python2 0
%endif

ExclusiveArch: x86_64 aarch64 loongarch64 ppc64le riscv64

BuildRequires: gcc gcc-c++ make
BuildRequires: dpdk-devel >= 23.11, numactl-devel, ncurses-devel
BuildRequires: libiscsi-devel, libaio-devel, openssl-devel, libuuid-devel
BuildRequires: libibverbs-devel, librdmacm-devel
BuildRequires: fuse3, fuse3-devel
BuildRequires: libboundscheck
BuildRequires: patchelf
BuildRequires: CUnit, CUnit-devel, python3-pip, chrpath
%if %{with doc}
BuildRequires: doxygen mscgen graphviz
%endif

# Install dependencies
Requires: dpdk >= 23.11, numactl-libs, openssl-libs
Requires: libiscsi, libaio, libuuid
Requires: fuse3, libboundscheck
# NVMe over Fabrics
Requires: librdmacm, librdmacm
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig

%description
The Storage Performance Development Kit provides a set of tools
and libraries for writing high performance, scalable, user-mode storage
applications.


%package devel
Summary: Storage Performance Development Kit development files
Requires: %{name}%{?_isa} = %{package_version}
Provides: %{name}-static%{?_isa} = %{package_version}

%description devel
This package contains the headers and other files needed for
developing applications with the Storage Performance Development Kit.


%package tools
Summary: Storage Performance Development Kit tools files
%if "%{use_python2}" == "0"
Requires: %{name} = %{package_version} python3 python3-configshell python3-pexpect
%else
Requires: %{name} = %{package_version} python python-configshell pexpect
%endif
BuildArch: noarch

%description tools
%{summary}


%if %{with doc}
%package doc
Summary: Storage Performance Development Kit documentation
BuildArch: noarch

%description doc
%{summary}
%endif


%prep
# add -q
%autosetup -n spdk-%{version} -p1

%build
./configure --prefix=%{_usr} \
	--disable-tests \
	--without-crypto \
	--without-isal \
	--with-dpdk \
	--without-fio \
	--with-vhost \
	--without-rbd \
	--with-rdma \
	--with-shared \
	--with-iscsi-initiator \
	--without-vtune \
	--with-nvme-cuse \

make -j`nproc` all

%if %{with doc}
make -C doc
%endif

%check
test/unit/unittest.sh

%install
%make_install -j`nproc` prefix=%{_usr} libdir=%{_libdir} datadir=%{_datadir}

# Install tools
mkdir -p %{install_datadir}
find scripts -type f -regextype egrep -regex '.*(spdkcli|rpc).*[.]py' \
	-exec cp --parents -t %{install_datadir} {} ";"

# env is banned - replace '/usr/bin/env anything' with '/usr/bin/anything'
find %{install_datadir}/scripts -type f -regextype egrep -regex '.*([.]py|[.]sh)' \
	-exec sed -i -E '1s@#!/usr/bin/env (.*)@#!/usr/bin/\1@' {} +

%if "%{use_python2}" == "1"
find %{install_datadir}/scripts -type f -regextype egrep -regex '.*([.]py)' \
	-exec sed -i -E '1s@#!/usr/bin/python3@#!/usr/bin/python2@' {} +
%endif

# synlinks to tools
mkdir -p %{install_sbindir}
ln -sf -r %{install_datadir}/scripts/rpc.py %{install_sbindir}/%{name}-rpc
ln -sf -r %{install_datadir}/scripts/spdkcli.py %{install_sbindir}/%{name}-cli

%if %{with doc}
# Install doc
mkdir -p %{install_docdir}
mv doc/output/html/ %{install_docdir}
%endif

%chrpath_delete

%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig


%files
%{_bindir}/iscsi_tgt
%{_bindir}/nvmf_tgt
%{_bindir}/vhost
/usr/lib/python%{python3_version}/site-packages/spdk*/*
%{_bindir}/spdk_*
%{_libdir}/*.so.*


%files devel
%{_libdir}/pkgconfig/*.pc
%{_includedir}/%{name}
%{_libdir}/*.a
%{_libdir}/*.so


%files tools
%{_datadir}/%{name}/scripts
%{_sbindir}/%{name}-rpc
%{_sbindir}/%{name}-cli

%if %{with doc}
%files doc
%{_docdir}/%{name}
%endif


%changelog
* Thu Jun 6 2024 baiguo <baiguo@kylinos.cn> - 24.01-6
- Add ctrlr_lock for cuse register and unregister 

* Mon Apr 29 2024 huangwenhua <huangwenhua@kylinos.cn> - 24.01-5
- Add BuildRequires: patchelf

* Wed Mar 13 2024 wangxiaomeng <wangxiaomeng@kylinos.cn> - 24.01-4
- Add version constraints to the dpdk-devel package to resolve building error

* Tue Mar 5 2024 shafeipaozi <sunbo.oerv@isrc.iscas.ac.cn> - 24.01-3
- Add support for riscv64

* Tue Mar 5 2024 Ren Zhijie <zhijie.ren@shingroup.cn> - 24.01-2
- Add support for ppc64le

* Tue Feb 20 2024 Hongtao Zhang <zhanghongtao22@huawei.com> - 24.01-1
- Update to 24.01 LTS version

* Thu Jan 4 2024 Hongtao Zhang <zhanghongtao22@huawei.com> - 21.01.1-19
- Fix deadlock due to lock sequence in bdev_unregister_unsafe

* Thu Dec 14 2023 Hongtao Zhang <zhanghongtao22@huawei.com> - 21.01.1-18
- Return error when failing to get resource

* Tue Sep 5 2023 Hongtao Zhang <zhanghongtao22@huawei.com> - 21.01.1-17
- Replace backport solution to fix race condition in cuse session

* Fri Sep 1 2023 Xue Liu <liuxue@loongson.cn> - 21.01.1-16
- Add support for LOONGARCH.

* Sat Aug 26 2023 Weifeng Su <suweifeng1@huawei.com> - 21.01.1-15
- backport patch to fix gcc-12 warning

* Tue May 30 2023 Jia Chao <jiac13@chinaunicom.cn> - 21.01.1-14
- Fix: tools do not need require %{?_isa} package for it's noarch.

* Wed Mar 15 2023 tongkunkun <tongkunkun_yewu@cmss.chinamobile.com>- 21.01.1-13
- backport upstream patches

* Thu Jan 19 2023 shikemeng <shikemeng@huawei.com> - 21.01.1-12
- Fix compile error that "undefined reference to spdk_backdev_submit_io"

* Thu Jan 12 2023 shikemeng <shikemeng@huawei.com> - 21.01.1-11
- enable xcache

* Thu Dec 29 2022 shikemeng <shikemeng@huawei.com> - 21.01.1-10
- Upgrade ocf lib and ocf bdev to SPDK 22.05

* Mon Dec 12 2022 Hongtao Zhang <zhanghongtao22@huawei.com> - 21.01.1-9
- Fix UAF in STAILQ_FOREACH

* Wed Dec 7 2022 Hongtao Zhang <zhanghongtao22@huawei.com> - 21.01.1-8
- Fix Segmentation fault occurs due to recursion

* Tue Nov 1 2022 Weifeng Su <suweifeng1@huawei.com> - 21.01.1-7
- Enable unittest

* Mon Oct 10 2022 Hongtao Zhang <zhanghongtao22@huawei.com> - 21.01.1-6
- configure add CONFIG_HAVE_ARC4RANDOM

* Tue May 24 2022 Weifeng Su <suweifeng1@huawei.com> - 21.01.1-5
- Add support for HSAK

* Tue Mar 15 2022 Weifeng Su <suweifeng1@huawei.com> - 21.01.1-4
- Remove rpath link option, Due to it's easy for attacher to
  construct 'rpath' attacks

* Fri Feb 25 2022 Hongtao Zhang <zhanghongtao22@huawei.com> - 21.01.1-3
- Fix build error on ARM ThunderX2 and neoverse N1 platform

* Mon Jan 10 2022 Weifeng Su <suweifeng1@huawei.com> - 21.01.1-2
- Adapt for dpdk 21.11

* Tue Nov 23 2021 Weifeng Su <suweifeng1@huawei.com> - 21.01.1-1
- rebase to v21.01.1 Maintenance LTS Version

* Mon Sep 13 2021 Zhiqiang Liu <liuzhiqiang26@huawei.com> - 21.01-5
- use -fstack-protector-strong instead of -fstack-protector for
stronger security.

* Sat Jul 24 2021 Zhiqiang Liu <liuzhiqiang26@huawei.com> - 21.01-4
- backport 13 bugfix from upstream

* Tue Jul 13 2021 Xiaokeng Li <lixiaokeng@huawei.com> - 21.01-3
- backport bugfix from upstream

* Wed Mar 10 2021 Shihao Sun <sunshihao@huawei.com> - 21.01-2
- use --without-isal to avoid build failed in arm.

* Thu Feb 4 2021 Shihao Sun <sunshihao@huawei.com> - 21.01-1
- update spdk to 21.01 LTS version. 
* Thu Nov 26 2020 Shihao Sun <sunshihao@huawei.com> - 20.01.1-2
- modify license
* Sat Nov 7 2020 Feilong Lin <linfeilong@huawei.com> - 20.01.1-1
- Support aarch64
* Tue Sep 18 2018 Pawel Wodkowski <pawelx.wodkowski@intel.com> - 0:18.07-3
- Initial RPM release
