bkctld-inc: add locks to btrfs actions

It's probably useless since btrfs commands return almost instantly
but it's consistent with ext4 commands.
This commit is contained in:
Jérémy Lecour 2020-04-05 11:40:24 +02:00 committed by Jérémy Lecour
parent f6665c646b
commit 6377ffd09e

View file

@ -14,18 +14,29 @@ create_inc_btrfs() {
jail_path=$(jail_path "${jail_name}") jail_path=$(jail_path "${jail_name}")
inc_path=$(inc_path "${jail_name}" "${inc_name}") inc_path=$(inc_path "${jail_name}" "${inc_name}")
start=$(current_time) # The lock file prevents from starting a new copy when one is already being done
lock_file="${LOCKDIR}/inc-${jail_name}-${inc_name}.lock"
if dry_run; then if [ -f "${lock_file}" ]; then
echo "[dry-run] btrfs subvolume snapshot of ${jail_path} to ${inc_path}" warning "${jail_name}: skipping '${inc_name}', it is already being created."
else else
mkdir --parents "$(dirname "${inc_path}")" (
# create a btrfs readonly snapshot from the jail start=$(current_time)
/bin/btrfs subvolume snapshot -r "${jail_path}" "${inc_path}" | debug mkdir --parents "${LOCKDIR}" && touch "${lock_file}"
fi # shellcheck disable=SC2064
trap "rm -f ${lock_file}" 0
end=$(current_time) if dry_run; then
notice "${jail_name}: inc '${inc_name}' has been created [${start}/${end}]" echo "[dry-run] btrfs subvolume snapshot of ${jail_path} to ${inc_path}"
else
mkdir --parents "$(dirname "${inc_path}")"
# create a btrfs readonly snapshot from the jail
/bin/btrfs subvolume snapshot -r "${jail_path}" "${inc_path}" | debug
fi
end=$(current_time)
notice "${jail_name}: inc '${inc_name}' has been created [${start}/${end}]"
)
fi
} }
create_inc_ext() { create_inc_ext() {
jail_name=$1 jail_name=$1