%global use_cluster 1
%global use_cmirror 1
%global use_lockd_sanlock 1
%global use_lockd_dlm 1
%ifnarch i686 x86_64
  %global use_cluster 0
  %global use_cmirror 0
  %global use_lockd_dlm 0
%endif

%ifnarch x86_64 aarch64
  %global use_lockd_sanlock 0
%endif

%if %{use_cluster}
  %global configure_cluster --with-cluster=internal --with-clvmd=corosync
  %if %{use_cmirror}
    %global configure_cmirror --enable-cmirrord
  %endif
%else
  %global configure_cluster --with-cluster=internal --with-clvmd=none
%endif

%if %{use_lockd_dlm}
%global configure_lockd_dlm --enable-lvmlockd-dlm
%endif

%if %{use_lockd_sanlock}
%global configure_lockd_sanlock --enable-lvmlockd-sanlock
%endif

%global libselinux_version 1.30.19-4
%global persistent_data_version 0.7.0-0.1.rc6
%global sanlock_version 3.3.0-2
%global device_mapper_version 1.02.150
%global systemd_version 189-3
%global dracut_version 002-18
%global util_linux_version 2.24
%global bash_version 4.0
%global corosync_version 1.99.9-1
%global resource_agents_version 3.9.5-12
%global dlm_version 4.0.6-2

Name:      lvm2
Version:   2.02.181
Release:   2
Epoch:     8
Summary:   Tools for logical volume management
License:   GPLv2 and LGPLv2
URL:       http://sourceware.org/lvm2
Source0:   ftp://sourceware.org/pub/lvm2/releases/LVM2.%{version}.tgz
Patch0000: 0000-lvm2-set-default-preferred_names.patch
Patch0001: 0001-lvm2-lvmetad-timeout.patch

Patch6000: 6000-mirrors-fix-read_only_volume_list.patch
Patch6001: 6001-bcache-reduce-MAX_IO-to-256.patch
Patch6002: 6002-lvmetad-fix-pvs-for-many-devices.patch
Patch6003: 6003-dmeventd-lvm2-plugin-uses-envvar-registry.patch
Patch6004: 6004-metadata-prevent-writing-beyond-metadata-area.patch
Patch6005: 6005-libdm-stats-move-no-regions-warning-after-dm_stats_l.patch
Patch6006: 6006-dmsetup-fix-stats-report-command-output.patch
Patch6007: 6007-io-use-sync-io-if-aio-fails.patch
Patch6008: 6008-bcache-sync-io-fixes.patch
Patch6009: 6009-lvmanip-uninitialized-members-in-struct-pv_list-10.patch
Patch6010: 6010-apply-obtain_device_list_from_udev-to-all-libudev-us.patch
Patch6011: 6011-cov-dmstats-check-for-failing-malloc.patch
Patch6012: 6012-cov-ensure-vars-are-set.patch
Patch6013: 6013-libdm-add-memory-barrier.patch
Patch6014: 6014-stats-fix-error-path-when-region-is-NULL.patch
Patch6015: 6015-stats-initilize-regions-to-NULL.patch
Patch6016: 6016-dmsetup-Fix-multi-line-concise-table-parsing.patch
Patch6017: 6017-Remove-VG-lock-ordering-check.patch
Patch6018: 6018-Fix-use-of-orphan-lock-in-commands.patch
Patch6019: 6019-metadata-remove-an-unused-and-incorrect-overflow-che.patch
Patch6020: 6020-cov-dmeventd-plugin-fix-memleak.patch
Patch6021: 6021-cov-fix-missing-null-allocation-check.patch
Patch6022: 6022-cov-add-check-for-positive-value.patch
Patch6023: 6023-cov-fix-failing-filter-initialization.patch
Patch6024: 6024-cov-check-dev_close_immediate.patch
Patch6025: 6025-cov-make-sure-label-scans-valid-lvinfo.patch
Patch6026: 6026-cov-add-missing-error-path-check-for-label_scan_open.patch
Patch6027: 6027-cov-pvscan-ensure-sigle_devs-list-is-always-initiali.patch
Patch6028: 6028-fix-cov-missed-return-value-test.patch
Patch6029: 6029-cov-trace-failing-pthread_kill.patch
Patch6030: 6030-cov-avoid-unsing-unchecked-label_scan_open.patch
Patch6031: 6031-lvmlockd-fix-missing-LV-lock-for-lvconvert-repair.patch
Patch6032: 6032-lvconvert-ensure-proper-init-of-pv_list.patch
Patch6033: 6033-dmeventd-unlock-lvm2-lock-on-error-path.patch
Patch6034: 6034-mangenerator-check-strdup-was-successfull.patch
Patch6035: 6035-cov-ensure-lock_type-is-not-NULL.patch
Patch6036: 6036-Remove-checking-for-locked-VGs.patch
Patch6037: 6037-lvm2-default-allow-changes-with-duplicate-pvs.patch

Patch9000: 9000-bugfix-lvm2-add-SSD.patch
Patch9001: 9001-bugfix-add-timeout-when-fail-to-wait-udev.patch
Patch9002: 9002-bugfix-fix-the-code-maybe-lead-to-buffer-over-bound-access.patch
Patch9003: 9003-enhancement-modify-default-log-level-to-error-level.patch
Patch9004: 9004-enhancement-add-dfx-log.patch

BuildRequires: gcc
BuildRequires: gcc-c++
BuildRequires: libselinux-devel >= %{libselinux_version}, libsepol-devel
BuildRequires: libblkid-devel >= %{util_linux_version}
BuildRequires: ncurses-devel
BuildRequires: readline-devel
BuildRequires: libaio-devel
BuildRequires: module-init-tools
BuildRequires: pkgconfig
BuildRequires: systemd-devel
BuildRequires: systemd-units
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-dbus
BuildRequires: python3-pyudev
BuildRequires: device-mapper-persistent-data >= %{persistent_data_version}

%if %{use_cluster}
BuildRequires: corosynclib-devel >= %{corosync_version}
%endif
%if %{use_cluster} || %{use_lockd_dlm}
BuildRequires: dlm-devel >= %{dlm_version}
%endif
%if %{use_lockd_sanlock}
BuildRequires: sanlock-devel >= %{sanlock_version}
%endif

Requires: bash >= %{bash_version}
Requires: module-init-tools
Requires: device-mapper-persistent-data >= %{persistent_data_version}
Requires: device-mapper-event = %{?epoch}:%{device_mapper_version}-%{release}
Requires(post):   systemd-units >= %{systemd_version}, systemd-sysv
Requires(preun):  systemd-units >= %{systemd_version}
Requires(postun): systemd-units >= %{systemd_version}

Provides:  %{name}-libs
Obsoletes: %{name}-libs

%description
lvm2 refers to the userspace toolset that provide logical volume management facilities on linux.

%package devel
Summary:   lvm2 devel files
License:   LGPLv2
Requires:  %{name} = %{?epoch}:%{version}-%{release}
Requires:  pkgconfig
Requires:  device-mapper = %{?epoch}:%{device_mapper_version}-%{release}
Provides:  device-mapper-devel = %{?epoch}:%{device_mapper_version}-%{release}
Obsoletes: device-mapper-devel
Provides:  device-mapper-event-devel = %{?epoch}:%{device_mapper_version}-%{release}
Obsoletes: device-mapper-event-devel

%description devel
This package contains all include files, libraries files needed to develop programs that use lvm2.

%package help
Summary:   Including man files for lvm2
Requires:  man
BuildArch: noarch

%description help
This contains man files for the using of lvm2.

%package -n python3-lvm-deprecated
Summary: Python 3 api to lvm
License: LGPLv2
Provides: python3-lvm = %{?epoch}:%{version}-%{release}
%{?python_provide:%python_provide python3-lvm}
Provides: %{name}-python3-libs = %{?epoch}:%{version}-%{release}
Obsoletes: %{name}-python3-libs < %{?epoch}:%{version}-%{release}
Requires: %{name}-libs = %{?epoch}:%{version}-%{release}

%description -n python3-lvm-deprecated
Support python 3 to use lvm.

%if %{use_lockd_dlm} || %{use_lockd_sanlock}
%package lockd
Summary:  LVM locking daemon
Requires: lvm2 = %{?epoch}:%{version}-%{release}
%if %{use_lockd_sanlock}
Requires: sanlock-lib >= %{sanlock_version}
%endif
%if %{use_lockd_dlm}
Requires: dlm-lib >= %{dlm_version}
%endif
Requires(post):   systemd-units >= %{systemd_version}
Requires(preun):  systemd-units >= %{systemd_version}
Requires(postun): systemd-units >= %{systemd_version}

%description lockd
LVM commands use lvmlockd to coordinate access to shared storage.
%endif

%if %{use_cluster}
%package cluster
Summary:  cluster LVM daemon tools
License:  GPLv2
Requires: lvm2 = %{?epoch}:%{version}-%{release}
Requires(preun): device-mapper >= %{?epoch}:%{device_mapper_version}
Requires(preun): lvm2 >= 2.02
Requires:  corosync >= %{corosync_version}
Requires:  dlm >= %{dlm_version}
Requires:  resource-agents >= %{resource_agents_version}
Provides:  cluster-standalone
Obsoletes: cluster-standalone

%description cluster
cluster distributes LVM metadata updates  around  a  cluster.
%endif

%if %{use_cluster} && %{use_cmirror}
%package -n cmirror
Summary:   cluster mirror log daemon
License:   GPLv2
Requires:  corosync >= %{corosync_version}
Requires:  device-mapper = %{?epoch}:%{device_mapper_version}-%{release}
Requires:  resource-agents >= %{resource_agents_version}
Provides:  cmirror-standalone
Obsoletes: cmirror-standalone

%description -n cmirror
cmirror tracks mirror log information in a cluster.
%endif

%package dbusd
Summary:  LVM2 D-Bus daemon
License:  GPLv2
Requires: lvm2 >= %{?epoch}:%{version}-%{release}
Requires: dbus
Requires: python3-dbus
Requires: python3-pyudev
Requires: python3-gobject-base
Requires(post):   systemd-units >= %{systemd_version}
Requires(preun):  systemd-units >= %{systemd_version}
Requires(postun): systemd-units >= %{systemd_version}

%description dbusd
dbusd is a service which provides a D-Bus API to the logical volume manager.

%package test
Summary:   Testsuite for lvm2
License:   LGPLv2 and GPLv2 and BSD-2-Clause
Provides:  %{name}-testsuite
Obsoletes: %{name}-testsuite

%description test
An extensive functional testsuite for LVM2.

%prep
%autosetup -n LVM2.%{version} -p1

%package -n device-mapper
Summary:   Low level logical volume management
Version:   %{device_mapper_version}
License:   LGPLv2
URL:       http://sources.redhat.com/dm
Requires:  util-linux >= %{util_linux_version}
Requires:  systemd >= %{systemd_version}
Provides:  device-mapper-libs = %{?epoch}:%{device_mapper_version}-%{release}
Obsoletes: device-mapper-libs
Conflicts: dracut < %{dracut_version}

%description -n device-mapper
Manages logical devices that use the device-mapper driver.

%package -n device-mapper-event
Summary:   Handle device-mapper events
Version:   %{device_mapper_version}
Requires:  device-mapper = %{?epoch}:%{device_mapper_version}-%{release}
Requires:  systemd-units
Provides:  device-mapper-event-libs = %{?epoch}:%{device_mapper_version}-%{release}
Obsoletes: device-mapper-event-libs

%description -n device-mapper-event
It contains tthe event monitoring daemon for device-mapper devices.  Library plugins
can register and carryout actions triggered when particular events occur.

%build
%configure --with-default-dm-run-dir=/run --with-default-run-dir=/run/lvm --with-default-pid-dir=/run --with-default-locking-dir=/run/lock/lvm --with-usrlibdir=%{_libdir} --enable-fsadm --enable-write_install --with-user= --with-group= --with-device-uid=0 --with-device-gid=6 --with-device-mode=0660 --enable-pkgconfig --enable-applib --enable-cmdlib --enable-dmeventd --enable-blkid_wiping --enable-python3-bindings %{?configure_cluster} %{?configure_cmirror} --with-udevdir=%{_prefix}/lib/udev/rules.d --enable-udev_sync --with-thin=internal --enable-lvmetad --with-thin=internal --enable-lvmpolld %{?configure_lockd_dlm} %{?configure_lockd_sanlock} --enable-dbus-service --enable-notify-dbus --enable-dmfilemapd
make %{?_smp_mflags}

%install
make install DESTDIR=%{buildroot}
make install_system_dirs DESTDIR=%{buildroot}
make install_systemd_units DESTDIR=%{buildroot}
make install_systemd_generators DESTDIR=%{buildroot}
make install_tmpfiles_configuration DESTDIR=%{buildroot}
make -C test install DESTDIR=%{buildroot}

%post
/sbin/ldconfig
%systemd_post blk-availability.service lvm2-monitor.service
if [ "$1" = "1" ] ; then
    systemctl enable lvm2-monitor.service
    systemctl start lvm2-monitor.service >/dev/null 2>&1 || :
fi
%systemd_post lvm2-lvmetad.socket
systemctl start lvm2-lvmetad.socket >/dev/null 2>&1 || :

%systemd_post lvm2-lvmpolld.socket
systemctl enable lvm2-lvmpolld.socket
systemctl start lvm2-lvmpolld.socket >/dev/null 2>&1 || :

%preun
%systemd_preun blk-availability.service lvm2-monitor.service
%systemd_preun lvm2-lvmetad.service lvm2-lvmetad.socket
%systemd_preun lvm2-lvmpolld.service lvm2-lvmpolld.socket

%postun
%systemd_postun lvm2-monitor.service
%systemd_postun_with_restart lvm2-lvmetad.service
%systemd_postun_with_restart lvm2-lvmpolld.service
/sbin/ldconfig

%post -n device-mapper
/sbin/ldconfig

%postun -n device-mapper
/sbin/ldconfig

%post -n device-mapper-event
/sbin/ldconfig
%systemd_post dm-event.socket
systemctl enable dm-event.socket
systemctl start dm-event.socket >/dev/null 2>&1 || :
if [ -e %{_default_pid_dir}/dmeventd.pid ]; then
    %{_sbindir}/dmeventd -R || echo "Failed to start dmeventd."
fi

%preun -n device-mapper-event
%systemd_preun dm-event.service dm-event.socket

%postun -n device-mapper-event
/sbin/ldconfig

%if %{use_lockd_dlm} || %{use_lockd_sanlock}
%post lockd
%systemd_post lvm2-lvmlockd.service lvm2-lvmlocking.service

%preun lockd
%systemd_preun lvm2-lvmlockd.service lvm2-lvmlocking.service

%postun lockd
%systemd_postun lvm2-lvmlockd.service lvm2-lvmlocking.service
%endif

%if %{use_cluster}
%post cluster
if [ -e /run/clvmd.pid ]; then
    /usr/sbin/clvmd -S || echo "Failed to start clvmd."
fi
%systemd_post lvm2-clvmd.service lvm2-cluster-activation.service

%preun cluster
if [ "$1" = "0" ]; then
    /sbin/lvmconf --disable-cluster
fi
%systemd_preun lvm2-clvmd.service lvm2-cluster-activation.service

%postun cluster
%systemd_postun lvm2-clvmd.service lvm2-cluster-activation.service
%endif

%if %{use_cluster} && %{use_cmirror}
%post -n cmirror
%systemd_post lvm2-cmirrord.service

%preun -n cmirror
%systemd_preun lvm2-cmirrord.service

%postun -n cmirror
%systemd_postun lvm2-cmirrord.service
%endif

%post dbusd
%systemd_post lvm2-lvmdbusd.service

%preun dbusd
%systemd_preun lvm2-lvmdbusd.service

%postun dbusd
%systemd_postun lvm2-lvmdbusd.service

%files
%license COPYING COPYING.LIB

%defattr(555,root,root,-)
%{_sbindir}/fsadm
%{_sbindir}/lvm
%{_sbindir}/lvmconf
%{_sbindir}/lvmconfig
%{_sbindir}/lvmdump
%{_sbindir}/lvmetad
%{_sbindir}/lvmpolld
%{_libdir}/liblvm2app.so.*
%{_libdir}/liblvm2cmd.so.*
%{_libdir}/libdevmapper-event-lvm2.so.*

%defattr(444,root,root,-)
%{_sbindir}/lvchange
%{_sbindir}/lvconvert
%{_sbindir}/lvcreate
%{_sbindir}/lvdisplay
%{_sbindir}/lvextend
%{_sbindir}/lvmdiskscan
%{_sbindir}/lvmsadc
%{_sbindir}/lvmsar
%{_sbindir}/lvreduce
%{_sbindir}/lvremove
%{_sbindir}/lvrename
%{_sbindir}/lvresize
%{_sbindir}/lvs
%{_sbindir}/lvscan
%{_sbindir}/pv*
%{_sbindir}/vg*

%{_prefix}/lib/udev/rules.d/69-dm-lvm-metad.rules
%{_prefix}/lib/udev/rules.d/11-dm-lvm.rules

%dir %{_sysconfdir}/lvm
%ghost %{_sysconfdir}/lvm/cache/.cache
%attr(644, -, -) %config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/lvm/lvm.conf
%attr(644, -, -) %config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/lvm/lvmlocal.conf
%dir %{_sysconfdir}/lvm/profile
%{_sysconfdir}/lvm/profile/*
%dir %{_sysconfdir}/lvm/backup
%dir %{_sysconfdir}/lvm/cache
%dir %{_sysconfdir}/lvm/archive
%ghost %dir /run/lock/lvm
%ghost %dir /run/lvm
%dir %{_libdir}/device-mapper
%{_libdir}/device-mapper/*
%{_libdir}/libdevmapper-event-lvm2mirror.so
%{_libdir}/libdevmapper-event-lvm2snapshot.so
%{_libdir}/libdevmapper-event-lvm2raid.so
%{_libdir}/libdevmapper-event-lvm2thin.so
%{_libdir}/libdevmapper-event-lvm2vdo.so
%{_tmpfilesdir}/%{name}.conf
%{_unitdir}/blk-availability.service
%{_unitdir}/lvm2-monitor.service
%attr(555, -, -) %{_prefix}/lib/systemd/system-generators/lvm2-activation-generator
%{_unitdir}/lvm2-lvmetad.socket
%{_unitdir}/lvm2-lvmetad.service
%{_unitdir}/lvm2-pvscan@.service
%{_unitdir}/lvm2-lvmpolld.socket
%{_unitdir}/lvm2-lvmpolld.service

%files -n device-mapper
%license COPYING COPYING.LIB
%doc udev/12-dm-permissions.rules
%defattr(555,root,root,-)
%{_sbindir}/dmsetup
%{_sbindir}/blkdeactivate
%{_sbindir}/dmstats
%{_sbindir}/dmfilemapd
%{_libdir}/libdevmapper.so.*
%defattr(444,root,root,-)
%{_prefix}/lib/udev/rules.d/10-dm.rules
%{_prefix}/lib/udev/rules.d/13-dm-disk.rules
%{_prefix}/lib/udev/rules.d/95-dm-notify.rules

%files -n device-mapper-event
%license COPYING.LIB
%defattr(555,root,root,-)
%{_sbindir}/dmeventd
%{_libdir}/libdevmapper-event.so.*
%defattr(444,root,root,-)
%{_unitdir}/dm-event.socket
%{_unitdir}/dm-event.service

%files devel
%defattr(444,root,root,-)
%{_libdir}/liblvm2app.so
%{_libdir}/liblvm2cmd.so
%{_libdir}/libdevmapper-event-lvm2.so
%{_libdir}/libdevmapper.so
%{_libdir}/libdevmapper-event.so
%{_includedir}/lvm2app.h
%{_includedir}/lvm2cmd.h
%{_includedir}/libdevmapper.h
%{_includedir}/libdevmapper-event.h
%{_libdir}/pkgconfig/lvm2app.pc
%{_libdir}/pkgconfig/devmapper.pc
%{_libdir}/pkgconfig/devmapper-event.pc

%files help
%{_mandir}/man5/*
%{_mandir}/man7/*
%{_mandir}/man8/*

%files -n python3-lvm-deprecated
%{python3_sitearch}/*.so
%{python3_sitearch}/*.egg-info

%if %{use_lockd_dlm} || %{use_lockd_sanlock}
%files lockd
%defattr(444,root,root,-)
%%attr(555, -, -) %{_sbindir}/lvmlockd
%%attr(555, -, -) %{_sbindir}/lvmlockctl
%{_unitdir}/lvm2-lvmlockd.service
%{_unitdir}/lvm2-lvmlocking.service
%endif

%if %{use_cluster}
%files cluster
%defattr(555,root,root,-)
%{_sbindir}/clvmd
%{_prefix}/lib/systemd/lvm2-cluster-activation
%defattr(444,root,root,-)
%{_unitdir}/lvm2-clvmd.service
%{_unitdir}/lvm2-cluster-activation.service
%endif

%if %{use_cluster} && %{use_cmirror}
%files -n cmirror
%defattr(555,root,root,-)
%{_sbindir}/cmirrord
%{_unitdir}/lvm2-cmirrord.service
%endif

%files dbusd
%defattr(555,root,root,-)
%{_sbindir}/lvmdbusd
%defattr(444,root,root,-)
%{_sysconfdir}/dbus-1/system.d/com.redhat.lvmdbus1.conf
%{_datadir}/dbus-1/system-services/com.redhat.lvmdbus1.service
%{_unitdir}/lvm2-lvmdbusd.service
%{python3_sitelib}/lvmdbusd/*

%files test
%license COPYING COPYING.LIB COPYING.BSD
%{_datadir}/lvm2-testsuite/
%{_libexecdir}/lvm2-testsuite/
%{_bindir}/lvm2-testsuite


%changelog
* Fri Sep 06 2019 wangjufeng <wangjufeng@huawei.com> - 2.02.181-2
- Package init
