From 84756879f17a8dd9acaca32e7edfee5cdeb2dbb8 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Fri, 2 Mar 2018 21:20:48 +0000
Subject: lvm2: update to 2.02.177

---
 abs/core/lvm2/PKGBUILD               | 122 +++++++++++++++++++++--------------
 abs/core/lvm2/dmeventd.service       |  14 ----
 abs/core/lvm2/dmeventd.socket        |  11 ----
 abs/core/lvm2/lvm-monitoring.service |  17 -----
 abs/core/lvm2/lvm2.conf              |   2 -
 abs/core/lvm2/lvm2.install           |   9 +++
 abs/core/lvm2/lvm2_hook              |  13 ++++
 abs/core/lvm2/lvm2_install           |  23 ++++++-
 abs/core/lvm2/lvmetad.service        |  16 -----
 abs/core/lvm2/lvmetad.socket         |  10 ---
 abs/core/lvm2/sd-lvm2                |  31 ---------
 abs/core/lvm2/sd-lvm2_install        |  49 ++++++++++++++
 12 files changed, 166 insertions(+), 151 deletions(-)
 delete mode 100644 abs/core/lvm2/dmeventd.service
 delete mode 100644 abs/core/lvm2/dmeventd.socket
 delete mode 100644 abs/core/lvm2/lvm-monitoring.service
 delete mode 100644 abs/core/lvm2/lvm2.conf
 delete mode 100644 abs/core/lvm2/lvmetad.service
 delete mode 100644 abs/core/lvm2/lvmetad.socket
 delete mode 100644 abs/core/lvm2/sd-lvm2
 create mode 100644 abs/core/lvm2/sd-lvm2_install

diff --git a/abs/core/lvm2/PKGBUILD b/abs/core/lvm2/PKGBUILD
index e31f8a8..a449821 100644
--- a/abs/core/lvm2/PKGBUILD
+++ b/abs/core/lvm2/PKGBUILD
@@ -1,82 +1,105 @@
-# $Id: PKGBUILD 199802 2013-11-16 17:53:26Z thomas $
+# $Id$
 # Maintainer: Eric Bélanger <eric@archlinux.org>
 # Maintainer: Thomas Bächler <thomas@archlinux.org>
 
 pkgbase=lvm2
 pkgname=('lvm2' 'device-mapper')
-pkgver=2.02.104
-pkgrel=1
-arch=('i686' 'x86_64')
+pkgver=2.02.177
+pkgrel=4
+arch=('x86_64')
 url="http://sourceware.org/lvm2/"
 license=('GPL2' 'LGPL2.1')
 makedepends=('systemd' 'thin-provisioning-tools')
 groups=('base')
-source=(ftp://sources.redhat.com/pub/lvm2/LVM2.${pkgver}.tgz{,.asc}
-        lvm2_install
-        lvm2_hook
-        sd-lvm2
-        11-dm-initramfs.rules
-        lvm2.conf
-        dmeventd.service
-        dmeventd.socket
-        lvm-monitoring.service
-        lvmetad.service
-        lvmetad.socket)
-sha1sums=('4c296453e10deafe02004fde40075cdb3792eeb2'
-          'SKIP'
-          '76e83966d1bc84f9a1e30bcaff84b8b8fefbca0f'
-          'ff0fdf0a3005a41acd4b36865056109effc3474b'
-          '30777d42e31cb7fe1f4fadc1e8f4c4d4cdd8ffed'
-          'f6a554eea9557c3c236df2943bb6e7e723945c41'
-          'ccefad65fde3d50331a42b0e90a1539dc7c8b9e4'
-          '01782ce8e10718c1513e3906b126f30f682f5cab'
-          '1d56f47a81350ae37ffbf61ee036fe31f4c5d504'
-          'aad90fce0e12eda41d38571d8eb27c5d5a8c59ec'
-          'f857a4a63fcc604a981e56875edda91767d4f1bf'
-          'fcfc265e3b10294cc4b10949a342e9db4310b186')
+validpgpkeys=('88437EF5C077BD113D3B7224228191C1567E2C17') # Alasdair G Kergon <agk@redhat.com>
+source=("https://mirrors.kernel.org/sourceware/lvm2/releases/LVM2.${pkgver}.tgz"{,.asc}
+        'lvm2_install'
+        'lvm2_hook'
+        'sd-lvm2_install'
+        '11-dm-initramfs.rules')
+sha256sums=('4025a23ec9b15c2cb7486d151c29dc953b75efc4d452cfe9dbbc7c0fac8e80f2'
+            'SKIP'
+            '5129f87a8b30d5a8621e9c1c0664910a588bdd77bff09473afb73efb41305cbb'
+            '97d7c92e4954bc0108e7cd183b2eb5fe7ecc97e6f56369669e6537cb6ed45d80'
+            'cc1ed670a7ca21ee2ab32ad6b5ab7a6a5e86d0651ea2e1593e289a82c87aa4da'
+            'e10f24b57582d6e2da71f7c80732a62e0ee2e3b867fe84591ccdb53e80fa92e0')
 
 prepare() {
   cd LVM2.${pkgver}
+
   # enable lvmetad
   sed -i 's|use_lvmetad = 0|use_lvmetad = 1|' conf/example.conf.in
+
+  # remove install section from systemd units that are enabled by default
+  sed -i -e '/^\[Install\]$/,$d' \
+    scripts/dm_event_systemd_red_hat.socket.in \
+    scripts/lvm2_lvmetad_systemd_red_hat.socket.in \
+    scripts/lvm2_lvmpolld_systemd_red_hat.socket.in \
+    scripts/lvm2_monitoring_systemd_red_hat.service.in
 }
 
 build() {
+  local CONFIGUREOPTS=(
+    --prefix=/usr
+    --sbindir=/usr/bin
+    --sysconfdir=/etc
+    --localstatedir=/var
+    --enable-applib
+    --enable-cmdlib
+    --enable-dmeventd
+    --enable-lvmetad
+    --enable-lvmpolld
+    --enable-pkgconfig
+    --enable-readline
+    --enable-udev_rules
+    --enable-udev_sync
+    --with-cache=internal
+    --with-default-dm-run-dir=/run
+    --with-default-locking-dir=/run/lock/lvm
+    --with-default-pid-dir=/run
+    --with-default-run-dir=/run/lvm
+    --with-systemdsystemunitdir=/usr/lib/systemd/system
+    --with-thin=internal
+    --with-udev-prefix=/usr
+  )
+
+  cp -a LVM2.${pkgver} LVM2-initramfs
+
   cd LVM2.${pkgver}
-  unset LDFLAGS
 
-  ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --sbindir=/usr/bin \
-    --with-udev-prefix=/usr --with-systemdsystemunitdir=/usr/lib/systemd/system \
-    --with-default-pid-dir=/run --with-default-dm-run-dir=/run --with-default-run-dir=/run/lvm \
-    --enable-pkgconfig --enable-readline --enable-dmeventd --enable-cmdlib --enable-applib \
-    --enable-udev_sync --enable-udev_rules --with-default-locking-dir=/run/lock/lvm \
-    --enable-lvmetad --with-thin=internal
+  ./configure "${CONFIGUREOPTS[@]}" --enable-udev-systemd-background-jobs
   make
+
+  # Build legacy udev rule for initramfs
+  cd ../LVM2-initramfs
+  ./configure "${CONFIGUREOPTS[@]}" --enable-udev-systemd-background-jobs=no
+  cd udev
+  make 69-dm-lvm-metad.rules
 }
 
 package_device-mapper() {
   pkgdesc="Device mapper userspace library and tools"
   url="http://sourceware.org/dm/"
-  depends=('glibc' 'systemd')
+  depends=('glibc' 'libsystemd')
 
   cd LVM2.${pkgver}
   make DESTDIR="${pkgdir}" install_device-mapper
   # extra udev rule for device-mapper in initramfs
   install -D -m644 "${srcdir}/11-dm-initramfs.rules" "${pkgdir}/usr/lib/initcpio/udev/11-dm-initramfs.rules"
   # Install dmeventd socket and service
-  install -D -m644 "${srcdir}/dmeventd.service" "${pkgdir}/usr/lib/systemd/system/dmeventd.service"
-  install -D -m644 "${srcdir}/dmeventd.socket" "${pkgdir}/usr/lib/systemd/system/dmeventd.socket"
+  make DESTDIR="${pkgdir}" install_systemd_units
+  rm -f "${pkgdir}/usr/lib/systemd/system/"{blk-availability.service,lvm2-*}
   install -d -m755 "${pkgdir}/usr/lib/systemd/system/sockets.target.wants"
-  ln -sf /usr/lib/systemd/system/dmeventd.socket "${pkgdir}/usr/lib/systemd/system/sockets.target.wants/dmeventd.socket"
+  ln -sf ../dm-event.socket "${pkgdir}/usr/lib/systemd/system/sockets.target.wants/dm-event.socket"
 }
 
 package_lvm2() {
   pkgdesc="Logical Volume Manager 2 utilities"
-  depends=('bash' "device-mapper>=${pkgver}" 'systemd' 'readline')
+  depends=('bash' "device-mapper>=${pkgver}" 'libsystemd' 'readline' 'thin-provisioning-tools')
   conflicts=('lvm' 'mkinitcpio<0.7')
-  backup=('etc/lvm/lvm.conf')
+  backup=('etc/lvm/lvm.conf'
+    'etc/lvm/lvmlocal.conf')
   options=('!makeflags')
-  optdepends=('thin-provisioning-tools: For thin provisioning support.')
   install=lvm2.install
 
   cd LVM2.${pkgver}
@@ -88,12 +111,15 @@ package_lvm2() {
   # mkinitcpio hook
   install -D -m644 "${srcdir}/lvm2_hook" "${pkgdir}/usr/lib/initcpio/hooks/lvm2"
   install -D -m644 "${srcdir}/lvm2_install" "${pkgdir}/usr/lib/initcpio/install/lvm2"
-  install -D -m644 "${srcdir}/sd-lvm2" "${pkgdir}/usr/lib/initcpio/install/sd-lvm2"
+  install -D -m644 "${srcdir}/sd-lvm2_install" "${pkgdir}/usr/lib/initcpio/install/sd-lvm2"
+  # extra udev rule for lvmetad in non-systemd initramfs
+  install -D -m644 "${srcdir}/LVM2-initramfs/udev/69-dm-lvm-metad.rules" "${pkgdir}/usr/lib/initcpio/udev/69-dm-lvm-metad.rules"
   # systemd support
-  install -D -m644 "${srcdir}/lvm2.conf" "${pkgdir}/usr/lib/tmpfiles.d/lvm2.conf"
-  install -D -m644 "${srcdir}/lvm-monitoring.service" "${pkgdir}/usr/lib/systemd/system/lvm-monitoring.service"
-  install -D -m644 "${srcdir}/lvmetad.service" "${pkgdir}/usr/lib/systemd/system/lvmetad.service"
-  install -D -m644 "${srcdir}/lvmetad.socket" "${pkgdir}/usr/lib/systemd/system/lvmetad.socket"
-  install -d -m755 "${pkgdir}/usr/lib/systemd/system/sockets.target.wants"
-  ln -sf /usr/lib/systemd/system/lvmetad.socket "${pkgdir}/usr/lib/systemd/system/sockets.target.wants/lvmetad.socket"
+  make DESTDIR="${pkgdir}" install_systemd_units
+  rm -f "${pkgdir}/usr/lib/systemd/system/"dm-*
+  install -d -m755 "${pkgdir}/usr/lib/systemd/system/sysinit.target.wants"
+  ln -sf ../lvm2-lvmetad.socket "${pkgdir}/usr/lib/systemd/system/sysinit.target.wants/lvm2-lvmetad.socket"
+  ln -sf ../lvm2-lvmpolld.socket "${pkgdir}/usr/lib/systemd/system/sysinit.target.wants/lvm2-lvmpolld.socket"
+  ln -sf ../lvm2-monitor.service "${pkgdir}/usr/lib/systemd/system/sysinit.target.wants/lvm2-monitor.service"
+  make DESTDIR="${pkgdir}" install_systemd_generators
 }
diff --git a/abs/core/lvm2/dmeventd.service b/abs/core/lvm2/dmeventd.service
deleted file mode 100644
index e0b1b33..0000000
--- a/abs/core/lvm2/dmeventd.service
+++ /dev/null
@@ -1,14 +0,0 @@
-[Unit]
-Description=Device-mapper event daemon
-Documentation=man:dmeventd(8)
-Requires=dmeventd.socket
-After=dmeventd.socket
-DefaultDependencies=no
-
-[Service]
-Type=forking
-ExecStart=/usr/bin/dmeventd
-ExecReload=/usr/bin/dmeventd -R
-Environment=SD_ACTIVATION=1
-PIDFile=/run/dmeventd.pid
-OOMScoreAdjust=-1000
diff --git a/abs/core/lvm2/dmeventd.socket b/abs/core/lvm2/dmeventd.socket
deleted file mode 100644
index 726d112..0000000
--- a/abs/core/lvm2/dmeventd.socket
+++ /dev/null
@@ -1,11 +0,0 @@
-[Unit]
-Description=Device-mapper event daemon FIFOs
-Documentation=man:dmeventd(8)
-Before=sockets.target
-DefaultDependencies=no
-Conflicts=shutdown.target
-
-[Socket]
-ListenFIFO=/run/dmeventd-server
-ListenFIFO=/run/dmeventd-client
-SocketMode=0600
diff --git a/abs/core/lvm2/lvm-monitoring.service b/abs/core/lvm2/lvm-monitoring.service
deleted file mode 100644
index 14b2d1d..0000000
--- a/abs/core/lvm2/lvm-monitoring.service
+++ /dev/null
@@ -1,17 +0,0 @@
-[Unit]
-Description=Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or progress polling
-Documentation=man:dmeventd(8) man:lvcreate(8) man:lvchange(8) man:vgchange(8)
-Requires=dmeventd.socket
-After=dmeventd.socket lvmetad.socket
-DefaultDependencies=no
-Conflicts=shutdown.target
-
-[Service]
-Type=oneshot
-Environment=LVM_SUPPRESS_LOCKING_FAILURE_MESSAGES=1
-ExecStart=/usr/bin/lvm vgchange --monitor y
-ExecStop=/usr/bin/lvm vgchange --monitor n
-RemainAfterExit=yes
-
-[Install]
-WantedBy=sysinit.target
diff --git a/abs/core/lvm2/lvm2.conf b/abs/core/lvm2/lvm2.conf
deleted file mode 100644
index 1298245..0000000
--- a/abs/core/lvm2/lvm2.conf
+++ /dev/null
@@ -1,2 +0,0 @@
-d /run/lock/lvm 0755 root root -
-d /run/lvm 0755 root root -
diff --git a/abs/core/lvm2/lvm2.install b/abs/core/lvm2/lvm2.install
index 7faf708..e11834d 100644
--- a/abs/core/lvm2/lvm2.install
+++ b/abs/core/lvm2/lvm2.install
@@ -11,6 +11,15 @@ post_upgrade() {
         echo "         into /etc/lvm/lvm.conf or LVM will fail to work."
     fi
   fi
+
+  if [ $(vercmp $2 2.02.106-2) -lt 0 ]; then
+    if [ -L /etc/systemd/system/sysinit.target.wants/lvm-monitoring.service ]; then
+      echo "rm /etc/systemd/system/sysinit.target.wants/lvm-monitoring.service"
+      rm /etc/systemd/system/sysinit.target.wants/lvm-monitoring.service
+      echo "ln -s /usr/lib/systemd/system/lvm2-monitor.service /etc/systemd/system/sysinit.target.wants/lvm2-monitor.service"
+      ln -s /usr/lib/systemd/system/lvm2-monitor.service /etc/systemd/system/sysinit.target.wants/lvm2-monitor.service
+    fi
+  fi
 }
 
 # vim:set ts=2 sw=2 et:
diff --git a/abs/core/lvm2/lvm2_hook b/abs/core/lvm2/lvm2_hook
index 65de7bd..3c28d67 100644
--- a/abs/core/lvm2/lvm2_hook
+++ b/abs/core/lvm2/lvm2_hook
@@ -5,6 +5,19 @@ run_earlyhook() {
     lvmetad
 }
 
+# We are suffering a race condition in non-systemd initramfs: If lvmetad is
+# killed before pvscan processes finish we have stale processes and
+# uninitialized physical volumes. So wait for pvscan processes to finish.
+# Break after 10 seconds (50*0.2s) to avaid infinite loop.
+run_latehook() {
+    local i=50
+
+    while pgrep -f pvscan >/dev/null 2>/dev/null && [ $i -gt 0 ]; do
+        sleep 0.2
+        i=$((i - 1))
+    done
+}
+
 run_cleanuphook() {
     kill $(cat /run/lvmetad.pid)
 }
diff --git a/abs/core/lvm2/lvm2_install b/abs/core/lvm2/lvm2_install
index 6f3c1cb..e0be711 100644
--- a/abs/core/lvm2/lvm2_install
+++ b/abs/core/lvm2/lvm2_install
@@ -2,18 +2,37 @@
 
 build() {
     local mod
-    for mod in dm-mod dm-snapshot dm-mirror; do
+    local symlink
+
+    # device mapper modules
+    for mod in dm-mod dm-snapshot dm-mirror dm-cache dm-cache-smq dm-thin-pool; do
         add_module "$mod"
     done
 
+    # binaries from lvm2
     add_binary "/usr/bin/lvm"
     add_binary "/usr/bin/lvmetad"
+
+    # beinaries from device-mapper
     add_binary "/usr/bin/dmsetup"
+    add_binary "/usr/bin/dmeventd"
+
+    # these are dlopen()ed
+    for library in libdevmapper-event-lvm2{mirror,raid,snapshot,thin}; do
+    	add_binary "/usr/lib/${library}.so"
+    done
+
+    # from thin-provisioning-tools
+    add_binary "/usr/bin/pdata_tools"
+    for symlink in cache_{check,dump,metadata_size,repair,restore} thin_{check,delta,dump,ls,metadata_size,repair,restore,rmap,trim}; do
+        add_symlink "/usr/bin/${symlink}" "pdata_tools"
+    done
+
     add_file "/usr/lib/udev/rules.d/10-dm.rules"
     add_file "/usr/lib/udev/rules.d/13-dm-disk.rules"
     add_file "/usr/lib/udev/rules.d/95-dm-notify.rules"
     add_file "/usr/lib/udev/rules.d/11-dm-lvm.rules"
-    add_file "/usr/lib/udev/rules.d/69-dm-lvm-metad.rules"
+    add_file "/usr/lib/initcpio/udev/69-dm-lvm-metad.rules" "/usr/lib/udev/rules.d/69-dm-lvm-metad.rules"
     add_file "/usr/lib/initcpio/udev/11-dm-initramfs.rules" "/usr/lib/udev/rules.d/11-dm-initramfs.rules"
     add_file "/etc/lvm/lvm.conf"
 
diff --git a/abs/core/lvm2/lvmetad.service b/abs/core/lvm2/lvmetad.service
deleted file mode 100644
index 4be520a..0000000
--- a/abs/core/lvm2/lvmetad.service
+++ /dev/null
@@ -1,16 +0,0 @@
-[Unit]
-Description=LVM2 metadata daemon
-Documentation=man:lvmetad(8)
-Requires=lvmetad.socket
-After=lvmetad.socket
-DefaultDependencies=no
-Conflicts=shutdown.target
-
-[Service]
-Type=forking
-NonBlocking=true
-ExecStart=/usr/bin/lvmetad
-ExecReload=/usr/bin/lvmetad -R
-Environment=SD_ACTIVATION=1
-Restart=on-abort
-PIDFile=/run/lvmetad.pid
diff --git a/abs/core/lvm2/lvmetad.socket b/abs/core/lvm2/lvmetad.socket
deleted file mode 100644
index 9c0ffa5..0000000
--- a/abs/core/lvm2/lvmetad.socket
+++ /dev/null
@@ -1,10 +0,0 @@
-[Unit]
-Description=LVM2 metadata daemon socket
-Documentation=man:lvmetad(8)
-Before=sockets.target systemd-udev-trigger.service
-DefaultDependencies=no
-Conflicts=shutdown.target
-
-[Socket]
-ListenStream=/run/lvm/lvmetad.socket
-SocketMode=0600
diff --git a/abs/core/lvm2/sd-lvm2 b/abs/core/lvm2/sd-lvm2
deleted file mode 100644
index 07cb19a..0000000
--- a/abs/core/lvm2/sd-lvm2
+++ /dev/null
@@ -1,31 +0,0 @@
-#!/usr/bin/bash
-
-build() {
-    local mod
-    for mod in dm-mod dm-snapshot dm-mirror; do
-        add_module "$mod"
-    done
-
-    add_binary "/usr/bin/lvm"
-    add_binary "/usr/bin/lvmetad"
-    add_binary "/usr/bin/dmsetup"
-    add_file "/usr/lib/udev/rules.d/10-dm.rules"
-    add_file "/usr/lib/udev/rules.d/13-dm-disk.rules"
-    add_file "/usr/lib/udev/rules.d/95-dm-notify.rules"
-    add_file "/usr/lib/udev/rules.d/11-dm-lvm.rules"
-    add_file "/usr/lib/udev/rules.d/69-dm-lvm-metad.rules"
-    add_file "/usr/lib/initcpio/udev/11-dm-initramfs.rules" "/usr/lib/udev/rules.d/11-dm-initramfs.rules"
-    add_file "/etc/lvm/lvm.conf"
-
-    add_file "/usr/lib/systemd/system/lvmetad.service"
-    add_file "/usr/lib/systemd/system/lvmetad.socket"
-    add_symlink "/usr/lib/systemd/system/sockets.target.wants/lvmetad.socket"
-}
-
-help() {
-  cat <<HELPEOF
-This hook enables LVM2 volumes in systemd-based initramfs.
-HELPEOF
-}
-
-# vim: set ft=sh ts=4 sw=4 et:
diff --git a/abs/core/lvm2/sd-lvm2_install b/abs/core/lvm2/sd-lvm2_install
new file mode 100644
index 0000000..f90cc82
--- /dev/null
+++ b/abs/core/lvm2/sd-lvm2_install
@@ -0,0 +1,49 @@
+#!/usr/bin/bash
+
+build() {
+    local mod
+    local symlink
+
+    # device mapper modules
+    for mod in dm-mod dm-snapshot dm-mirror dm-cache dm-cache-smq dm-thin-pool; do
+        add_module "$mod"
+    done
+
+    # device mapper and lvm2 systemd units
+    # binaries and libraries are pull automatically, except ...
+    add_systemd_unit "dm-event.service"
+    add_systemd_unit "lvm2-lvmetad.service"
+    add_systemd_unit "lvm2-pvscan@.service"
+    add_symlink "/usr/lib/systemd/system/sysinit.target.wants/lvm2-lvmetad.socket"
+
+    # ... dmsetup and ...
+    add_binary "dmsetup"
+
+    # ... these, which are dlopen()ed
+    for library in libdevmapper-event-lvm2{mirror,raid,snapshot,thin}; do
+    	add_binary "/usr/lib/${library}.so"
+    done
+
+    # from thin-provisioning-tools
+    add_binary "pdata_tools"
+    for symlink in cache_{check,dump,metadata_size,repair,restore} thin_{check,delta,dump,ls,metadata_size,repair,restore,rmap,trim}; do
+        add_symlink "/usr/bin/${symlink}" "pdata_tools"
+    done
+
+    # udev rules and lvm configuration
+    add_file "/usr/lib/udev/rules.d/10-dm.rules"
+    add_file "/usr/lib/udev/rules.d/13-dm-disk.rules"
+    add_file "/usr/lib/udev/rules.d/95-dm-notify.rules"
+    add_file "/usr/lib/udev/rules.d/11-dm-lvm.rules"
+    add_file "/usr/lib/udev/rules.d/69-dm-lvm-metad.rules"
+    add_file "/usr/lib/initcpio/udev/11-dm-initramfs.rules" "/usr/lib/udev/rules.d/11-dm-initramfs.rules"
+    add_file "/etc/lvm/lvm.conf"
+}
+
+help() {
+  cat <<HELPEOF
+This hook enables LVM2 volumes in systemd-based initramfs.
+HELPEOF
+}
+
+# vim: set ft=sh ts=4 sw=4 et:
-- 
cgit v0.12

