~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to tools/hotplug/Linux/blktap

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
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
# Copyright (c) 2005, XenSource Ltd.
 
4
 
 
5
dir=$(dirname "$0")
 
6
. "$dir/xen-hotplug-common.sh"
 
7
. "$dir/block-common.sh"
 
8
 
 
9
findCommand "$@"
 
10
 
 
11
##
 
12
# check_blktap_sharing file mode
 
13
#
 
14
# Perform the sharing check for the given blktap and mode.
 
15
#
 
16
check_blktap_sharing()
 
17
{
 
18
    local file="$1"
 
19
    local mode="$2"
 
20
 
 
21
    local base_path="$XENBUS_BASE_PATH/$XENBUS_TYPE"
 
22
    for dom in $(xenstore-list "$base_path")
 
23
    do
 
24
        for dev in $(xenstore-list "$base_path/$dom")
 
25
        do
 
26
            params=$(xenstore_read_default "$base_path/$dom/$dev/params" "" | cut -d: -f2)
 
27
            if [ "$file" = "$params" ]
 
28
            then
 
29
 
 
30
                if [ "$mode" = 'w' ]
 
31
                then
 
32
                    if ! same_vm "$dom" 
 
33
                    then
 
34
                        echo 'guest'
 
35
                        return
 
36
                    fi
 
37
                else 
 
38
                    local m=$(xenstore_read_default "$base_path/$dom/$dev/mode" "")
 
39
                    m=$(canonicalise_mode "$m")
 
40
 
 
41
                    if [ "$m" = 'w' ] 
 
42
                    then
 
43
                        if ! same_vm "$dom"
 
44
                        then
 
45
                            echo 'guest'
 
46
                            return
 
47
                        fi
 
48
                    fi
 
49
                fi
 
50
            fi
 
51
        done
 
52
    done
 
53
 
 
54
    echo 'ok'
 
55
}
 
56
 
 
57
 
 
58
t=$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING')
 
59
if [ -n "$t" ]
 
60
then
 
61
    p=$(xenstore_read "$XENBUS_PATH/params")
 
62
    # if we have a ':', chew from head including :
 
63
    if echo $p | grep -q \:
 
64
    then
 
65
        p=${p#*:}
 
66
    fi
 
67
fi
 
68
# some versions of readlink cannot be passed a regular file
 
69
if [ -L "$p" ]; then
 
70
    file=$(readlink -f "$p") || fatal "$p link does not exist."
 
71
else
 
72
    file="$p"
 
73
fi
 
74
 
 
75
if [ "$command" = 'add' ]
 
76
then
 
77
    [ -e "$file" ] || { fatal $file does not exist; }
 
78
 
 
79
    FRONTEND_ID=$(xenstore_read "$XENBUS_PATH/frontend-id")
 
80
    FRONTEND_UUID=$(xenstore_read "/local/domain/$FRONTEND_ID/vm")
 
81
    mode=$(xenstore_read "$XENBUS_PATH/mode")
 
82
    mode=$(canonicalise_mode "$mode")
 
83
 
 
84
    if [ "$mode" != '!' ] 
 
85
    then
 
86
        result=$(check_blktap_sharing "$file" "$mode")
 
87
        [ "$result" = 'ok' ] || ebusy "$file already in use by other domain"
 
88
    fi
 
89
 
 
90
    success
 
91
fi
 
92
 
 
93
exit 0