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

« back to all changes in this revision

Viewing changes to tools/hotplug/Linux/block-common.sh

  • 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
#
 
2
# Copyright (c) 2005 XenSource Ltd.
 
3
#
 
4
# This library is free software; you can redistribute it and/or
 
5
# modify it under the terms of version 2.1 of the GNU Lesser General Public
 
6
# License as published by the Free Software Foundation.
 
7
#
 
8
# This library is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
# Lesser General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU Lesser General Public
 
14
# License along with this library; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
#
 
17
 
 
18
 
 
19
dir=$(dirname "$0")
 
20
. "$dir/xen-hotplug-common.sh"
 
21
 
 
22
findCommand "$@"
 
23
 
 
24
if [ "$command" != "add" ] &&
 
25
   [ "$command" != "remove" ]
 
26
then
 
27
  log err "Invalid command: $command"
 
28
  exit 1
 
29
fi
 
30
 
 
31
 
 
32
XENBUS_PATH="${XENBUS_PATH:?}"
 
33
 
 
34
 
 
35
ebusy()
 
36
{
 
37
  xenstore_write "$XENBUS_PATH/hotplug-error" "$*" \
 
38
                 "$XENBUS_PATH/hotplug-status" busy
 
39
  log err "$@"
 
40
  exit 1
 
41
}
 
42
 
 
43
 
 
44
##
 
45
# Print the given device's major and minor numbers, written in hex and
 
46
# separated by a colon.
 
47
device_major_minor()
 
48
{
 
49
  stat -L -c %t:%T "$1"
 
50
}
 
51
 
 
52
 
 
53
##
 
54
# Write physical-device = MM,mm to the store, where MM and mm are the major 
 
55
# and minor numbers of device respectively.
 
56
#
 
57
# @param device The device from which major and minor numbers are read, which
 
58
#               will be written into the store.
 
59
#
 
60
write_dev() {
 
61
  local mm
 
62
  
 
63
  mm=$(device_major_minor "$1")
 
64
 
 
65
  if [ -z $mm ]
 
66
  then
 
67
    fatal "Backend device does not exist"
 
68
  fi
 
69
 
 
70
  xenstore_write "$XENBUS_PATH/physical-device" "$mm"
 
71
 
 
72
  success
 
73
}
 
74
 
 
75
 
 
76
##
 
77
# canonicalise_mode mode
 
78
#
 
79
# Takes the given mode, which may be r, w, ro, rw, w!, or rw!, or variations
 
80
# thereof, and canonicalises them to one of
 
81
#
 
82
#   'r': perform checks for a new read-only mount;
 
83
#   'w': perform checks for a read-write mount; or
 
84
#   '!': perform no checks at all.
 
85
#
 
86
canonicalise_mode()
 
87
{
 
88
  local mode="$1"
 
89
 
 
90
  if ! expr index "$mode" 'w' >/dev/null
 
91
  then
 
92
    echo 'r'
 
93
  elif ! expr index "$mode" '!' >/dev/null
 
94
  then
 
95
    echo 'w'
 
96
  else
 
97
    echo '!'
 
98
  fi
 
99
}
 
100
 
 
101
 
 
102
same_vm()
 
103
{
 
104
  local otherdom="$1"
 
105
  # Note that othervm can be MISSING here, because Xend will be racing with
 
106
  # the hotplug scripts -- the entries in /local/domain can be removed by
 
107
  # Xend before the hotplug scripts have removed the entry in
 
108
  # /local/domain/0/backend/.  In this case, we want to pretend that the
 
109
  # VM is the same as FRONTEND_UUID, because that way the 'sharing' will be
 
110
  # allowed.
 
111
  local othervm=$(xenstore_read_default "/local/domain/$otherdom/vm"         \
 
112
                  "$FRONTEND_UUID")
 
113
  local target=$(xenstore_read_default  "/local/domain/$FRONTEND_ID/target"   \
 
114
                 "-1")
 
115
  local otarget=$(xenstore_read_default  "/local/domain/$otherdom/target"   \
 
116
                 "-1")
 
117
  local otvm=$(xenstore_read_default  "/local/domain/$otarget/vm"   \
 
118
                 "-1")
 
119
  otvm=${otvm%-1}
 
120
  othervm=${othervm%-1}
 
121
  local frontend_uuid=${FRONTEND_UUID%-1}
 
122
  
 
123
  [ "$frontend_uuid" = "$othervm" -o "$target" = "$otherdom" -o "$frontend_uuid" = "$otvm" ]
 
124
}
 
125