mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 18:21:39 +01:00
The blktap2 test in xen-hotplug-cleanup was not quite right, causing orphaned /vm/<uuid>/device node in xenstore. Attempt to reattach the device failed: xen53: # xm block-attach 0 file:/tmp/d0 /dev/xvdp r xen53: # xm block-detach 0 /dev/xvdp xen53: # xenstore-ls /vm/00000000-0000-0000-0000-000000000000/device vbd =3D "" 51952 =3D "" frontend =3D "/local/domain/0/device/vbd/51952" frontend-id =3D "0" backend-id =3D "0" backend =3D "/local/domain/0/backend/vbd/0/51952" xen53: # xm block-attach 0 file:/tmp/d0 /dev/xvdp r Error: Device /dev/xvdp (51952, vbd) is already connected. Usage: xm block-attach <Domain> <BackDev> <FrontDev> <Mode> [BackDomain] From: Jim Fehlig <jfehlig@novell.com> Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
44 lines
1.4 KiB
Bash
44 lines
1.4 KiB
Bash
#! /bin/bash
|
|
|
|
dir=$(dirname "$0")
|
|
. "$dir/xen-hotplug-common.sh"
|
|
|
|
# Claim the lock protecting ${XEN_SCRIPT_DIR}/block. This stops a race whereby
|
|
# paths in the store would disappear underneath that script as it attempted to
|
|
# read from the store checking for device sharing.
|
|
# Any other scripts that do similar things will have to have their lock
|
|
# claimed too.
|
|
# This is pretty horrible, but there's not really a nicer way of solving this.
|
|
claim_lock "block"
|
|
|
|
# split backend/DEVCLASS/VMID/DEVID on slashes
|
|
path_array=( ${XENBUS_PATH//\// } )
|
|
# get /vm/UUID path
|
|
vm=$(xenstore_read_default "/local/domain/${path_array[2]}/vm" "")
|
|
# construct /vm/UUID/device/DEVCLASS/DEVID
|
|
if [ "$vm" != "" ]; then
|
|
vm_dev="$vm/device/${path_array[1]}/${path_array[3]}"
|
|
|
|
# if the vm path does not exist and the device class is 'vbd' then we may have
|
|
# a tap2 device
|
|
if [ $(xenstore-read "$vm_dev" 2>/dev/null) != "" ] \
|
|
&& [ "${path_array[1]}" = "vbd" ]; then
|
|
vm_dev="$vm/device/tap2/${path_array[3]}"
|
|
fi
|
|
else
|
|
vm_dev=
|
|
fi
|
|
|
|
# remove device frontend store entries
|
|
xenstore-rm -t \
|
|
$(xenstore-read "$XENBUS_PATH/frontend" 2>/dev/null) 2>/dev/null || true
|
|
|
|
# remove device backend store entries
|
|
xenstore-rm -t "$XENBUS_PATH" 2>/dev/null || true
|
|
xenstore-rm -t "error/$XENBUS_PATH" 2>/dev/null || true
|
|
|
|
# remove device path from /vm/UUID
|
|
[ "$vm_dev" != "" ] && xenstore-rm -t "$vm_dev" 2>/dev/null || true
|
|
|
|
release_lock "block"
|