mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 18:21:39 +01:00
same_vm is broken when the two main domains do not have targets. otvm
and targetvm are both missing, which means they get set to -1 and then
converted to empty strings:
++10697+ local targetvm=-1
++10697+ local otvm=-1
++10697+ otvm=
++10697+ othervm=/vm/cc97bc2f-3a91-43f7-8fbc-4cb92f90b4e4
++10697+ targetvm=
++10697+ local frontend_uuid=/vm/844dea4e-44f8-4e3e-8145-325132a31ca5
The final comparison returns true since the two empty strings match:
++10697+ '[' /vm/844dea4e-44f8-4e3e-8145-325132a31ca5 = /vm/cc97bc2f-3a91-43f7-8fbc-4cb92f90b4e4 -o '' = /vm/cc97bc2f-3a91-43f7-8fbc-4cb92f90b4e4 -o /vm/844dea4e-44f8-4e3e-8145-325132a31ca5 = '' -o '' = '' ']'
Replace -1 with distinct strings indicating the lack of a value and
remove the collescing to empty stings. The strings themselves will no
longer match, and that is correct.
++12364+ '[' /vm/844dea4e-44f8-4e3e-8145-325132a31ca5 = /vm/cc97bc2f-3a91-43f7-8fbc-4cb92f90b4e4 -o 'No target' = /vm/cc97bc2f-3a91-43f7-8fbc-4cb92f90b4e4 -o /vm/844dea4e-44f8-4e3e-8145-325132a31ca5 = 'No other target' -o 'No target' = 'No other target' ']'
Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
master commit: e8f1bb803f
master date: 2024-02-07 13:46:52 +0100
127 lines
3.2 KiB
Bash
127 lines
3.2 KiB
Bash
#
|
|
# Copyright (c) 2005 XenSource Ltd.
|
|
#
|
|
# This library is free software; you can redistribute it and/or
|
|
# modify it under the terms of version 2.1 of the GNU Lesser General Public
|
|
# License as published by the Free Software Foundation.
|
|
#
|
|
# This library is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# Lesser General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
# License along with this library; If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
|
|
dir=$(dirname "$0")
|
|
. "$dir/xen-hotplug-common.sh"
|
|
|
|
findCommand "$@"
|
|
|
|
if [ "$command" != "add" ] &&
|
|
[ "$command" != "remove" ]
|
|
then
|
|
log err "Invalid command: $command"
|
|
exit 1
|
|
fi
|
|
|
|
|
|
XENBUS_PATH="${XENBUS_PATH:?}"
|
|
|
|
|
|
ebusy()
|
|
{
|
|
xenstore_write "$XENBUS_PATH/hotplug-error" "$*" \
|
|
"$XENBUS_PATH/hotplug-status" busy
|
|
log err "$@"
|
|
exit 1
|
|
}
|
|
|
|
|
|
##
|
|
# Print the given device's major and minor numbers, written in hex and
|
|
# separated by a colon.
|
|
device_major_minor()
|
|
{
|
|
stat -L -c %t:%T "$1"
|
|
}
|
|
|
|
|
|
##
|
|
# Write physical-device = MM,mm to the store, where MM and mm are the major
|
|
# and minor numbers of device respectively.
|
|
#
|
|
# @param device The device from which major and minor numbers are read, which
|
|
# will be written into the store.
|
|
#
|
|
write_dev() {
|
|
local mm
|
|
|
|
mm=$(device_major_minor "$1")
|
|
|
|
if [ -z $mm ]
|
|
then
|
|
fatal "Backend device does not exist"
|
|
fi
|
|
|
|
xenstore_write "$XENBUS_PATH/physical-device" "$mm"
|
|
xenstore_write "$XENBUS_PATH/physical-device-path" "$1"
|
|
|
|
success
|
|
}
|
|
|
|
|
|
##
|
|
# canonicalise_mode mode
|
|
#
|
|
# Takes the given mode, which may be r, w, ro, rw, w!, or rw!, or variations
|
|
# thereof, and canonicalises them to one of
|
|
#
|
|
# 'r': perform checks for a new read-only mount;
|
|
# 'w': perform checks for a read-write mount; or
|
|
# '!': perform no checks at all.
|
|
#
|
|
canonicalise_mode()
|
|
{
|
|
local mode="$1"
|
|
|
|
if ! expr index "$mode" 'w' >/dev/null
|
|
then
|
|
echo 'r'
|
|
elif ! expr index "$mode" '!' >/dev/null
|
|
then
|
|
echo 'w'
|
|
else
|
|
echo '!'
|
|
fi
|
|
}
|
|
|
|
|
|
same_vm()
|
|
{
|
|
local otherdom="$1"
|
|
# Note that othervm can be MISSING here, because Xend will be racing with
|
|
# the hotplug scripts -- the entries in /local/domain can be removed by
|
|
# Xend before the hotplug scripts have removed the entry in
|
|
# /local/domain/0/backend/. In this case, we want to pretend that the
|
|
# VM is the same as FRONTEND_UUID, because that way the 'sharing' will be
|
|
# allowed.
|
|
local othervm=$(xenstore_read_default "/local/domain/$otherdom/vm" \
|
|
"$FRONTEND_UUID")
|
|
local target=$(xenstore_read_default "/local/domain/$FRONTEND_ID/target" \
|
|
"-1")
|
|
local targetvm=$(xenstore_read_default "/local/domain/$target/vm" "No Target")
|
|
local otarget=$(xenstore_read_default "/local/domain/$otherdom/target" \
|
|
"-1")
|
|
local otvm=$(xenstore_read_default "/local/domain/$otarget/vm" \
|
|
"No Other Target")
|
|
|
|
local frontend_uuid=${FRONTEND_UUID%-1}
|
|
|
|
[ "$frontend_uuid" = "$othervm" -o "$targetvm" = "$othervm" -o \
|
|
"$frontend_uuid" = "$otvm" -o "$targetvm" = "$otvm" ]
|
|
}
|
|
|