summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'sys-block')
-rw-r--r--sys-block/tgt/files/tgtd.confd-new7
-rw-r--r--sys-block/tgt/files/tgtd.initd-new136
-rw-r--r--sys-block/tgt/tgt-1.0.87-r1.ebuild61
3 files changed, 204 insertions, 0 deletions
diff --git a/sys-block/tgt/files/tgtd.confd-new b/sys-block/tgt/files/tgtd.confd-new
new file mode 100644
index 000000000000..99a8f8db02fd
--- /dev/null
+++ b/sys-block/tgt/files/tgtd.confd-new
@@ -0,0 +1,7 @@
+# Here you can specify options that are passed directly to tgt daemon
+#tgtd_opts=""
+
+# Config file for automatic configuration with tgt-admin
+#tgtd_conf="/etc/tgt/targets.conf"
+
+# vim: ft=gentoo-conf-d
diff --git a/sys-block/tgt/files/tgtd.initd-new b/sys-block/tgt/files/tgtd.initd-new
new file mode 100644
index 000000000000..7941f1a7e974
--- /dev/null
+++ b/sys-block/tgt/files/tgtd.initd-new
@@ -0,0 +1,136 @@
+#!/sbin/openrc-run
+# Copyright 1999-2019 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# shellcheck shell=sh
+
+# Default configuration fike
+: "${tgtd_conf:=/etc/tgt/targets.conf}"
+
+pidfile="/var/run/${RC_SVCNAME}.pid"
+command="/usr/sbin/tgtd"
+command_args_background="--pid-file ${pidfile}"
+extra_commands="forcedstop"
+extra_started_commands="forcedreload reload"
+
+depend() {
+ use net
+}
+
+start_post() {
+ # We need to wait for 1 second before do anything with tgtd.
+ sleep 1
+ # Put tgtd into "offline" state until all the targets are configured.
+ # We don't want initiators to (re)connect and fail the connection
+ # if configuration is not ready.
+ tgtadm --op update --mode sys --name State -v offline
+
+ # Configure the targets.
+ if [ ! -r "${tgtd_conf}" ]; then
+ ewarn "Configuration file '${tgtd_conf}' not found!"
+ ewarn "Leaving ${SVCNAME} running in 'offline' state."
+ eend 0
+ else
+ ebegin "Loading target configuration"
+ tgt-admin --update ALL -c "${tgtd_conf}"
+ retval=$?
+ if [ $retval -ne 0 ]; then
+ eerror "Could not load configuration!"
+ stop
+ exit $?
+ fi
+ eend $retval
+
+ # Put tgtd into "ready" state.
+ ebegin "Onlining targets. Accepting connections"
+ tgtadm --op update --mode sys --name State -v ready
+ eend $?
+ fi
+}
+
+stop() {
+ ebegin "Stopping ${SVCNAME}"
+ # We need to force shutdown if system is restarting
+ # or shutting down.
+ if [ "$RC_RUNLEVEL" = "shutdown" ] ; then
+ forcedstop
+ else
+ # Remove all targets. Only remove targets which are not in use.
+ tgt-admin --update ALL -c /dev/null >/dev/null 2>&1
+ retval=$?
+ if [ $retval -eq 107 ] ; then
+ einfo "tgtd is not running"
+ else
+ # tgtd will exit if all targets were removed.
+ tgtadm --op delete --mode system >/dev/null 2>&1
+ retval=$?
+ if [ $retval -ne 0 ] ; then
+ eerror "WARNING: Some initiators are still connected - could not stop tgtd"
+ fi
+ fi
+ fi
+ eend $retval
+}
+
+forcedstop() {
+ # NOTE: Forced shutdown of the iscsi target may cause data corruption
+ # for initiators that are connected.
+ ewarn "WARNING: Force-stopping target framework daemon"
+ for i in 5 4 3 2 1; do
+ einfo "Continuing in $i seconds..."
+ sleep 1
+ done
+
+ # Offline everything first. May be needed if we're rebooting, but
+ # expect the initiators to reconnect cleanly when we boot again
+ # (i.e. we don't want them to reconnect to a tgtd which is still
+ # onlineg, but the target is gone).
+ tgtadm --op update --mode sys --name State -v offline >/dev/null 2>&1
+ retval=$?
+ if [ $retval -eq 107 ] ; then
+ einfo "tgtd is not running"
+ else
+ # Offline all targets
+ tgt-admin --offline ALL
+
+ # Remove all targets, even if they are still in use.
+ tgt-admin --update ALL -c /dev/null -f
+
+ # tgtd shuts down after all targets are removed.
+ tgtadm --op delete --mode system
+ retval=$?
+ if [ $retval -ne 0 ] ; then
+ eerror "Failed to shutdown tgtd"
+ eend 1
+ fi
+ fi
+ eend $retval
+}
+
+reload() {
+ ebegin "Updating target framework daemon configuration"
+ # Update configuration for targets. Only targets which
+ # are not in use will be updated.
+ tgt-admin --update ALL -c "${tgtd_conf}" >/dev/null 2>&1
+ retval=$?
+ if [ $retval -eq 107 ]; then
+ ewarn "WARNING: tgtd is not running"
+ fi
+ eend $retval
+}
+
+forcedreload() {
+ ebegin "Updating target framework daemon configuration"
+ ewarn "WARNING: Force-updating running configuration!"
+ # Update configuration for targets, even those in use.
+ tgt-admin --update ALL -f -c "${tgtd_conf}" >/dev/null 2>&1
+ retval=$?
+ if [ $retval -eq 107 ]; then
+ ewarn "WARNING: tgtd is not running"
+ fi
+ eend $retval
+}
+
+status_post() {
+ einfo "Run 'tgt-admin -s' to see detailed target info."
+}
diff --git a/sys-block/tgt/tgt-1.0.87-r1.ebuild b/sys-block/tgt/tgt-1.0.87-r1.ebuild
new file mode 100644
index 000000000000..559e0ae2c41b
--- /dev/null
+++ b/sys-block/tgt/tgt-1.0.87-r1.ebuild
@@ -0,0 +1,61 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+inherit toolchain-funcs systemd
+
+DESCRIPTION="Linux SCSI target framework (tgt)"
+HOMEPAGE="https://github.com/fujita/tgt"
+SRC_URI="https://github.com/fujita/tgt/archive/v${PV}.tar.gz -> ${P}.tar.gz"
+
+LICENSE="GPL-2"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm64 ~hppa ~ia64 ~loong ~ppc ~ppc64 ~riscv ~sparc ~x86"
+IUSE="fcoe fcp ibmvio infiniband rbd selinux"
+
+DEPEND="
+ app-text/docbook-xsl-stylesheets
+ dev-libs/libxslt
+ dev-perl/Config-General
+ rbd? ( sys-cluster/ceph )
+ infiniband? ( sys-cluster/rdma-core )
+"
+RDEPEND="
+ ${DEPEND}
+ dev-libs/libaio
+ sys-apps/sg3_utils
+ selinux? ( sec-policy/selinux-tgtd )
+"
+
+pkg_setup() {
+ tc-export CC
+}
+
+src_prepare() {
+ default
+ sed -i -e 's:\($(CC)\) $^:\1 $(LDFLAGS) $^:' usr/Makefile || die
+ # make sure xml docs are generated before trying to install them
+ sed -i -e "s@install: @& all @g" doc/Makefile || die
+ sed -i -e 's|-Werror||g' usr/Makefile || die
+}
+
+src_compile() {
+ local myconf
+ use ibmvio && myconf="${myconf} IBMVIO=1"
+ use infiniband && myconf="${myconf} ISCSI_RDMA=1"
+ use fcp && myconf="${myconf} FCP=1"
+ use fcoe && myconf="${myconf} FCOE=1"
+ use rbd && myconf="${myconf} CEPH_RBD=1"
+
+ emake -C usr/ KERNELSRC="${KERNEL_DIR}" ISCSI=1 ${myconf}
+ emake -C doc
+}
+
+src_install() {
+ emake install-programs install-scripts install-doc DESTDIR="${D}" docdir=/usr/share/doc/${PF}
+ newinitd "${FILESDIR}"/tgtd.initd-new tgtd
+ newconfd "${FILESDIR}"/tgtd.confd-new tgtd
+ systemd_dounit "${S}"/scripts/tgtd.service
+ dodir /etc/tgt
+ keepdir /etc/tgt
+}