dom0: block-snapshot: add prepare and cleanup actions
"prepare" and "cleanup" actions can be used to setup device manually - not from udev. This is used by qvm-revert-template-changes.
This commit is contained in:
parent
f3b245a45a
commit
4ab4783ee2
@ -5,7 +5,12 @@
|
|||||||
# This creates dm-snapshot device on given arguments
|
# This creates dm-snapshot device on given arguments
|
||||||
|
|
||||||
dir=$(dirname "$0")
|
dir=$(dirname "$0")
|
||||||
. "$dir/block-common.sh"
|
if [ "$1" = "prepare" ] || [ "$1" = "cleanup" ]; then
|
||||||
|
. "$dir/xen-hotplug-common.sh"
|
||||||
|
command=$1
|
||||||
|
else
|
||||||
|
. "$dir/block-common.sh"
|
||||||
|
fi
|
||||||
|
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
@ -143,10 +148,58 @@ case "$command" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
remove)
|
prepare)
|
||||||
|
t=$2
|
||||||
case $t in
|
case $t in
|
||||||
snapshot|origin)
|
snapshot|origin)
|
||||||
node=$(cat "$HOTPLUG_STORE-node")
|
p=$3
|
||||||
|
base=${p/:*/}
|
||||||
|
cow=${p/*:/}
|
||||||
|
|
||||||
|
if [ -L "$base" ]; then
|
||||||
|
base=$(readlink -f "$base") || fatal "$base link does not exist."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -L "$cow" ]; then
|
||||||
|
cow=$(readlink -f "$cow") || fatal "$cow link does not exist."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# first ensure that snapshot device exists (to write somewhere changes from snapshot-origin)
|
||||||
|
dm_devname=$(get_dm_snapshot_name "$base" "$cow")
|
||||||
|
|
||||||
|
claim_lock "block"
|
||||||
|
|
||||||
|
# prepare snapshot device
|
||||||
|
create_dm_snapshot $dm_devname "$base" "$cow"
|
||||||
|
|
||||||
|
if [ "$t" == "snapshot" ]; then
|
||||||
|
#that's all for snapshot, store name of prepared device
|
||||||
|
echo "/dev/mapper/$dm_devname"
|
||||||
|
elif [ "$t" == "origin" ]; then
|
||||||
|
# for origin - prepare snapshot-origin device and store its name
|
||||||
|
dm_devname=origin-$(stat -c '%D:%i' "$base")
|
||||||
|
create_dm_snapshot_origin $dm_devname "$base"
|
||||||
|
echo "/dev/mapper/$dm_devname"
|
||||||
|
fi
|
||||||
|
|
||||||
|
release_lock "block"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
remove|cleanup)
|
||||||
|
if [ "$command" = "cleanup" ]; then
|
||||||
|
t=$2
|
||||||
|
else
|
||||||
|
t=$(cat $HOTPLUG_STORE-type)
|
||||||
|
fi
|
||||||
|
case $t in
|
||||||
|
snapshot|origin)
|
||||||
|
if [ "$command" = "cleanup" ]; then
|
||||||
|
node=$3
|
||||||
|
else
|
||||||
|
node=$(cat "$HOTPLUG_STORE-node")
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$node" ]; then
|
if [ -z "$node" ]; then
|
||||||
fatal "No device node to remove"
|
fatal "No device node to remove"
|
||||||
@ -186,11 +239,13 @@ case "$command" in
|
|||||||
dmsetup remove $snap
|
dmsetup remove $snap
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
# Commit template changes
|
if [ "$command" = "remove" ]; then
|
||||||
domain=$(cat "$HOTPLUG_STORE-domain")
|
# Commit template changes
|
||||||
if [ "$domain" ]; then
|
domain=$(cat "$HOTPLUG_STORE-domain")
|
||||||
# Dont stop on errors
|
if [ "$domain" ]; then
|
||||||
/usr/bin/qvm-template-commit "$domain" || true
|
# Dont stop on errors
|
||||||
|
/usr/bin/qvm-template-commit "$domain" || true
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user