~ressu/+junk/xen-common-ubuntu

« back to all changes in this revision

Viewing changes to tools/hotplug/Linux/xen-hotplug-cleanup

  • Committer: sami at haahtinen
  • Author(s): Bastian Blank
  • Date: 2010-06-21 15:09:01 UTC
  • Revision ID: sami@haahtinen.name-20100621150901-yqspr1ttydxocscz
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/bash
 
2
 
 
3
dir=$(dirname "$0")
 
4
. "$dir/xen-hotplug-common.sh"
 
5
 
 
6
# Claim the lock protecting ${XEN_SCRIPT_DIR}/block.  This stops a race whereby
 
7
# paths in the store would disappear underneath that script as it attempted to
 
8
# read from the store checking for device sharing.
 
9
# Any other scripts that do similar things will have to have their lock
 
10
# claimed too.
 
11
# This is pretty horrible, but there's not really a nicer way of solving this.
 
12
claim_lock "block"
 
13
 
 
14
# split backend/DEVCLASS/VMID/DEVID on slashes
 
15
path_array=( ${XENBUS_PATH//\// } )
 
16
# get /vm/UUID path
 
17
vm=$(xenstore_read_default "/local/domain/${path_array[2]}/vm" "")
 
18
# construct /vm/UUID/device/DEVCLASS/DEVID
 
19
if [ "$vm" != "" ]; then
 
20
  vm_dev="$vm/device/${path_array[1]}/${path_array[3]}"
 
21
 
 
22
  # if the vm path does not exist and the device class is 'vbd' then we may have
 
23
  # a tap2 device
 
24
  if [ $(xenstore-read "$vm_dev" 2>/dev/null) != "" ] \
 
25
       && [ "${path_array[1]}" = "vbd" ]; then
 
26
    vm_dev="$vm/device/tap2/${path_array[3]}"
 
27
  fi
 
28
else
 
29
  vm_dev=
 
30
fi
 
31
 
 
32
# remove device frontend store entries
 
33
xenstore-rm -t \
 
34
  $(xenstore-read "$XENBUS_PATH/frontend" 2>/dev/null) 2>/dev/null || true
 
35
 
 
36
# remove device backend store entries
 
37
xenstore-rm -t "$XENBUS_PATH"        2>/dev/null || true
 
38
xenstore-rm -t "error/$XENBUS_PATH"  2>/dev/null || true
 
39
 
 
40
# remove device path from /vm/UUID
 
41
[ "$vm_dev" != "" ] && xenstore-rm -t "$vm_dev" 2>/dev/null || true
 
42
 
 
43
release_lock "block"