Update openrc/dmcache.initd
Move blockdev --getsz to checkconfig()
This commit is contained in:
parent
ffb84bbc8c
commit
16fe60eb45
@ -1,115 +1,115 @@
|
|||||||
#!/sbin/openrc-run
|
#!/sbin/openrc-run
|
||||||
# shellcheck shell=sh
|
# shellcheck shell=sh
|
||||||
|
|
||||||
# dm-cache
|
# dm-cache
|
||||||
# A helper program to setup and manage device-mapper
|
# A helper program to setup and manage device-mapper
|
||||||
# cache devices.
|
# cache devices.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
# Copyright 2023 Forza <forza@tnonline.net>
|
# Copyright 2023 Forza <forza@tnonline.net>
|
||||||
|
|
||||||
name="dm-cache ${dmname}"
|
name="dm-cache ${dmname}"
|
||||||
description="Activates dm-cache devices"
|
description="Activates dm-cache devices"
|
||||||
extra_started_commands="suspend resume cleaner"
|
extra_started_commands="suspend resume cleaner"
|
||||||
: "${cacheblock:=256}"
|
: "${cacheblock:=256}"
|
||||||
: "${cachemode:="1 writethrough"}"
|
: "${cachemode:="1 writethrough"}"
|
||||||
: "${cachepolicy:="default"}"
|
: "${cachepolicy:="default"}"
|
||||||
: "${cachepolicyargs:=0}"
|
: "${cachepolicyargs:=0}"
|
||||||
: "${readahead:="auto"}"
|
: "${readahead:="auto"}"
|
||||||
# dm-cache requires the origindev size in sectors.
|
|
||||||
: "${originsize:="$(/sbin/blockdev --getsz "${origindev}")"}"
|
depend() {
|
||||||
|
need dev modules
|
||||||
depend() {
|
use lvm
|
||||||
need dev modules
|
before localmount
|
||||||
use lvm
|
}
|
||||||
before localmount
|
|
||||||
}
|
checkconfig() {
|
||||||
|
if [ -z "${origindev}" ]; then
|
||||||
checkconfig() {
|
eerror "origindev not set!"
|
||||||
if [ -z "${origindev}" ]; then
|
return 1
|
||||||
eerror "origindev not set!"
|
fi
|
||||||
return 1
|
if [ -z "${metadev}" ]; then
|
||||||
fi
|
eerror "metadev not set!"
|
||||||
if [ -z "${metadev}" ]; then
|
return 1
|
||||||
eerror "metadev not set!"
|
fi
|
||||||
return 1
|
if [ -z "${cachedev}" ]; then
|
||||||
fi
|
eerror "cachedev not set!"
|
||||||
if [ -z "${cachedev}" ]; then
|
return 1
|
||||||
eerror "cachedev not set!"
|
fi
|
||||||
return 1
|
if [ -z "${dmname}" ]; then
|
||||||
fi
|
eerror "dmname not set!"
|
||||||
if [ -z "${dmname}" ]; then
|
return 1
|
||||||
eerror "dmname not set!"
|
fi
|
||||||
return 1
|
# dm-cache requires the origindev size in sectors.
|
||||||
fi
|
: "${originsize:="$(/sbin/blockdev --getsz "${origindev}")"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
checkconfig || return 1
|
checkconfig || return 1
|
||||||
ebegin "Creating dm-cache ${dmname}"
|
ebegin "Creating dm-cache ${dmname}"
|
||||||
|
|
||||||
if findmnt "${origindev}" > /dev/null; then
|
if findmnt "${origindev}" > /dev/null; then
|
||||||
eerror "Origin device is already mounted. Aborting."
|
eerror "Origin device is already mounted. Aborting."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dmsetup create "${dmname}" --table "0 ${originsize} cache ${metadev} ${cachedev} ${origindev} ${cacheblock} ${cachemode} ${cachepolicy} ${cachepolicyargs}" --readahead "${readahead}"
|
dmsetup create "${dmname}" --table "0 ${originsize} cache ${metadev} ${cachedev} ${origindev} ${cacheblock} ${cachemode} ${cachepolicy} ${cachepolicyargs}" --readahead "${readahead}"
|
||||||
eend $?
|
eend $?
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
if [ "$RC_RUNLEVEL" = "shutdown" ]; then
|
if [ "$RC_RUNLEVEL" = "shutdown" ]; then
|
||||||
if findmnt "/dev/mapper/${dmname}" > /dev/null; then
|
if findmnt "/dev/mapper/${dmname}" > /dev/null; then
|
||||||
ewarn "System is shutting down and \"${dmname}\" is still mounted!"
|
ewarn "System is shutting down and \"${dmname}\" is still mounted!"
|
||||||
ewarn "Attempting to unmount holders..."
|
ewarn "Attempting to unmount holders..."
|
||||||
umount --all-targets "/dev/mapper/${dmname}" || eerror "Could not unmount!"
|
umount --all-targets "/dev/mapper/${dmname}" || eerror "Could not unmount!"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if findmnt "/dev/mapper/${dmname}" > /dev/null; then
|
if findmnt "/dev/mapper/${dmname}" > /dev/null; then
|
||||||
eerror "Cannot stop dm-cache. \"${dmname}\" is mounted!"
|
eerror "Cannot stop dm-cache. \"${dmname}\" is mounted!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
ebegin "Stopping dm-cache ${dmname}"
|
ebegin "Stopping dm-cache ${dmname}"
|
||||||
# Cannot flush or stop a suapended device.
|
# Cannot flush or stop a suapended device.
|
||||||
dmsetup resume "${dmname}"
|
dmsetup resume "${dmname}"
|
||||||
blockdev --flushbufs "/dev/mapper/${dmname}"
|
blockdev --flushbufs "/dev/mapper/${dmname}"
|
||||||
einfo "Waiting for flush. This can take a while with large caches..."
|
einfo "Waiting for flush. This can take a while with large caches..."
|
||||||
dmsetup remove "${dmname}"
|
dmsetup remove "${dmname}"
|
||||||
exit $?
|
exit $?
|
||||||
}
|
}
|
||||||
|
|
||||||
cleaner() {
|
cleaner() {
|
||||||
# The Cleaner policy attempts to write out cached data
|
# The Cleaner policy attempts to write out cached data
|
||||||
# to the origin device at a higher rate. This is useful
|
# to the origin device at a higher rate. This is useful
|
||||||
# if you want to remove or decomission the dm-cache.
|
# if you want to remove or decomission the dm-cache.
|
||||||
# Cleaner only makes sense for the 'writeback' mode.
|
# Cleaner only makes sense for the 'writeback' mode.
|
||||||
|
|
||||||
checkconfig || return 1
|
checkconfig || return 1
|
||||||
ebegin "Enabling the Cleaner write cache policy."
|
ebegin "Enabling the Cleaner write cache policy."
|
||||||
dmsetup suspend "${dmname}"
|
dmsetup suspend "${dmname}"
|
||||||
dmsetup reload -r --table "0 ${originsize} cache ${metadev} ${cachedev} ${origindev} ${cacheblock} ${cachemode} cleaner 0" "${dmname}"
|
dmsetup reload -r --table "0 ${originsize} cache ${metadev} ${cachedev} ${origindev} ${cacheblock} ${cachemode} cleaner 0" "${dmname}"
|
||||||
errorlevel=$?
|
errorlevel=$?
|
||||||
if [ ! $errorlevel = 0 ]; then
|
if [ ! $errorlevel = 0 ]; then
|
||||||
ewarn "Could not change to Cleaner policy"
|
ewarn "Could not change to Cleaner policy"
|
||||||
fi
|
fi
|
||||||
dmsetup resume "${dmname}"
|
dmsetup resume "${dmname}"
|
||||||
eend $?
|
eend $?
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend() {
|
suspend() {
|
||||||
checkconfig || return 1
|
checkconfig || return 1
|
||||||
if findmnt "/dev/mapper/${dmname}" > /dev/null; then
|
if findmnt "/dev/mapper/${dmname}" > /dev/null; then
|
||||||
ewarn "Warning, \"${dmname}\" is mounted!"
|
ewarn "Warning, \"${dmname}\" is mounted!"
|
||||||
fi
|
fi
|
||||||
ebegin "Suspending \"${dmname}\""
|
ebegin "Suspending \"${dmname}\""
|
||||||
dmsetup suspend "${dmname}"
|
dmsetup suspend "${dmname}"
|
||||||
eend $?
|
eend $?
|
||||||
}
|
}
|
||||||
|
|
||||||
resume() {
|
resume() {
|
||||||
checkconfig || return 1
|
checkconfig || return 1
|
||||||
ebegin "Resuming \"${dmname}\""
|
ebegin "Resuming \"${dmname}\""
|
||||||
dmsetup resume "${dmname}"
|
dmsetup resume "${dmname}"
|
||||||
eend $?
|
eend $?
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user