From c8077590d4fd447e07508c7e511e9190920f0ca8 Mon Sep 17 00:00:00 2001
From: Patrick McLean <patrick.mclean@sony.com>
Date: Thu, 28 May 2020 12:08:53 -0700
Subject: [PATCH] sys-cluster/ceph-15.2.2-r1: Revbump, fix bugs #724508 and
 #724438

Adds a "diskprediction" USE flag to enable diskprediction_local since it
forces an old scipy (forcing off python3_8) (bug #724438)

Fixes up the systemd unit and adds a tmpfiles entry (bug #724508)

Closes: https://bugs.gentoo.org/724508
Closes: https://bugs.gentoo.org/724438
Copyright: Sony Interactive Entertainment Inc.
Package-Manager: Portage-2.3.100, Repoman-2.3.22
Signed-off-by: Patrick McLean <chutzpah@gentoo.org>
---
 ...ph-15.2.2.ebuild => ceph-15.2.2-r1.ebuild} | 30 +++++++++++++------
 .../ceph/files/ceph-15.2.2-systemd-unit.patch | 12 ++++++++
 sys-cluster/ceph/files/ceph-tmpfilesd         |  1 +
 sys-cluster/ceph/metadata.xml                 |  1 +
 4 files changed, 35 insertions(+), 9 deletions(-)
 rename sys-cluster/ceph/{ceph-15.2.2.ebuild => ceph-15.2.2-r1.ebuild} (92%)
 create mode 100644 sys-cluster/ceph/files/ceph-15.2.2-systemd-unit.patch
 create mode 100644 sys-cluster/ceph/files/ceph-tmpfilesd

diff --git a/sys-cluster/ceph/ceph-15.2.2.ebuild b/sys-cluster/ceph/ceph-15.2.2-r1.ebuild
similarity index 92%
rename from sys-cluster/ceph/ceph-15.2.2.ebuild
rename to sys-cluster/ceph/ceph-15.2.2-r1.ebuild
index 2d9f2924eca6..d84666892676 100644
--- a/sys-cluster/ceph/ceph-15.2.2.ebuild
+++ b/sys-cluster/ceph/ceph-15.2.2-r1.ebuild
@@ -9,7 +9,7 @@ DISTUTILS_OPTIONAL=1
 
 inherit check-reqs bash-completion-r1 cmake-utils distutils-r1 flag-o-matic \
 		multiprocessing python-r1 udev readme.gentoo-r1 toolchain-funcs \
-		systemd
+		systemd tmpfiles
 
 if [[ ${PV} == *9999* ]]; then
 	inherit git-r3
@@ -28,9 +28,9 @@ SLOT="0"
 
 CPU_FLAGS_X86=(sse{,2,3,4_1,4_2} ssse3)
 
-IUSE="babeltrace +cephfs custom-cflags dpdk fuse grafana jemalloc kafka kerberos ldap
-	libressl lttng +mgr numa +openssl pmdk rabbitmq +radosgw rbd-rwl +ssl spdk
-	system-boost systemd +tcmalloc test uring xfs zfs"
+IUSE="babeltrace +cephfs custom-cflags diskprediction dpdk fuse grafana jemalloc
+	kafka kerberos ldap libressl lttng +mgr numa +openssl pmdk rabbitmq +radosgw
+	rbd-rwl +ssl spdk system-boost systemd +tcmalloc test uring xfs zfs"
 IUSE+=" $(printf "cpu_flags_x86_%s\n" ${CPU_FLAGS_X86[@]})"
 
 COMMON_DEPEND="
@@ -153,18 +153,22 @@ RDEPEND="${COMMON_DEPEND}
 		dev-python/pyjwt[${PYTHON_USEDEP}]
 		dev-python/pyyaml[${PYTHON_USEDEP}]
 		dev-python/routes[${PYTHON_USEDEP}]
-		sci-libs/scipy[${PYTHON_USEDEP}]
+		diskprediction? (
+			$(python_gen_cond_dep '<sci-libs/scipy-1.4.0[${PYTHON_USEDEP}]' python3_{6,7})
+		)
 		sci-libs/scikits_learn[${PYTHON_USEDEP}]
 		dev-python/six[${PYTHON_USEDEP}]
 	)
 "
+# diskprediction needs older scipy not compatible with py38
+# bug #724438
 REQUIRED_USE="
 	${PYTHON_REQUIRED_USE}
+	?? ( jemalloc tcmalloc )
 	^^ ( openssl libressl )
+	diskprediction? ( mgr !python_targets_python3_8 )
 	kafka? ( radosgw )
-	rabbitmq? ( radosgw )
 	mgr? ( cephfs )
-	?? ( jemalloc tcmalloc )
 	rabbitmq? ( radosgw )
 "
 RESTRICT="!test? ( test )"
@@ -189,10 +193,11 @@ PATCHES=(
 	"${FILESDIR}/ceph-14.2.0-link-crc32-statically.patch"
 	"${FILESDIR}/ceph-14.2.0-cython-0.29.patch"
 	"${FILESDIR}/ceph-15.2.0-rocksdb-cmake.patch"
+	"${FILESDIR}/ceph-15.2.2-systemd-unit.patch"
 )
 
 check-reqs_export_vars() {
-	CHECKREQS_DISK_BUILD="5.2G"
+	CHECKREQS_DISK_BUILD="5200M"
 	CHECKREQS_DISK_USR="510M"
 
 	export CHECKREQS_DISK_BUILD CHECKREQS_DISK_USR
@@ -223,6 +228,10 @@ src_prepare() {
 	sed -i -r "s:DESTINATION .+\\):DESTINATION $(get_bashcompdir)\\):" \
 		src/bash_completion/CMakeLists.txt || die
 
+	if ! use diskprediction; then
+		rm -rf src/pybind/mgr/diskprediction_local || die
+	fi
+
 	# remove tests that need root access
 	rm src/test/cli/ceph-authtool/cap*.t || die
 }
@@ -262,6 +271,7 @@ ceph_src_configure() {
 		-DWITH_RDMA=OFF
 		-DWITH_TBB=OFF
 		-DSYSTEMD_UNITDIR=$(systemd_get_systemunitdir)
+		-DCMAKE_INSTALL_SYSTEMD_SERVICEDIR=$(systemd_get_systemunitdir)
 		-DEPYTHON_VERSION="${EPYTHON#python}"
 		-DCMAKE_INSTALL_DOCDIR="${EPREFIX}/usr/share/doc/${PN}-${PVR}"
 		-DCMAKE_INSTALL_SYSCONFDIR="${EPREFIX}/etc"
@@ -356,13 +366,15 @@ src_install() {
 
 		systemd_install_serviced "${FILESDIR}/ceph-osd_at.service.conf" \
 			"ceph-osd@.service"
+
 	fi
 
 	udev_dorules udev/*.rules
+	newtmpfiles "${FILESDIR}"/ceph-tmpfilesd ${PN}.conf
 
 	readme.gentoo_create_doc
 
-	python_setup 'python3*'
+	python_setup
 
 	# bug #630232
 	sed -i -r "s:${T//:/\\:}/${EPYTHON}:/usr:" "${ED}"/usr/bin/ceph{,-crash} \
diff --git a/sys-cluster/ceph/files/ceph-15.2.2-systemd-unit.patch b/sys-cluster/ceph/files/ceph-15.2.2-systemd-unit.patch
new file mode 100644
index 000000000000..fdd3a6ac2ac7
--- /dev/null
+++ b/sys-cluster/ceph/files/ceph-15.2.2-systemd-unit.patch
@@ -0,0 +1,12 @@
+diff -ur ceph-15.2.2/systemd/ceph-osd@.service.in ceph-15.2.2.af/systemd/ceph-osd@.service.in
+--- ceph-15.2.2/systemd/ceph-osd@.service.in    2020-05-18 16:25:12.000000000 +0000
++++ ceph-15.2.2.af/systemd/ceph-osd@.service.in 2020-05-21 21:20:58.318655944 +0000
+@@ -10,7 +10,7 @@
+ EnvironmentFile=-@SYSTEMD_ENV_FILE@
+ Environment=CLUSTER=ceph
+ ExecStart=/usr/bin/ceph-osd -f --cluster ${CLUSTER} --id %i --setuser ceph --setgroup ceph
+-ExecStartPre=/usr/lib/ceph/ceph-osd-prestart.sh --cluster ${CLUSTER} --id %i
++ExecStartPre=/usr/libexec/ceph/ceph-osd-prestart.sh --cluster ${CLUSTER} --id %i
+ ExecReload=/bin/kill -HUP $MAINPID
+ LockPersonality=true
+ MemoryDenyWriteExecute=true
diff --git a/sys-cluster/ceph/files/ceph-tmpfilesd b/sys-cluster/ceph/files/ceph-tmpfilesd
new file mode 100644
index 000000000000..2ded82f5f659
--- /dev/null
+++ b/sys-cluster/ceph/files/ceph-tmpfilesd
@@ -0,0 +1 @@
+d /run/ceph 0770 ceph ceph -
diff --git a/sys-cluster/ceph/metadata.xml b/sys-cluster/ceph/metadata.xml
index dcf0de05f77f..b29a383d9b5a 100644
--- a/sys-cluster/ceph/metadata.xml
+++ b/sys-cluster/ceph/metadata.xml
@@ -20,6 +20,7 @@
     <flag name="babeltrace">Add support for LTTng babeltrace</flag>
     <flag name="cephfs">Build support for cephfs, a POSIX compatible filesystem built on top of ceph</flag>
     <flag name="dpdk">Enable DPDK messaging</flag>
+    <flag name="diskprediction">Enable local diskprediction module to predict disk failures</flag>
     <flag name="spdk">Enable SPDK user-mode storage driver toolkit</flag>
     <flag name="fuse">Build fuse client</flag>
     <flag name="grafana">Install grafana dashboards</flag>
-- 
2.26.2