[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] Tidy and comment use of canonicalise_mode, et al.
# HG changeset patch # User emellor@xxxxxxxxxxxxxxxxxxxxxx # Node ID 8a00d9af329136d93937e10f5d207e4cb1a77364 # Parent 74fa88cf3dc7cc3132b8532ac65a5d1d6de2b63f Tidy and comment use of canonicalise_mode, et al. Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx> diff -r 74fa88cf3dc7 -r 8a00d9af3291 tools/examples/block --- a/tools/examples/block Tue Nov 29 15:00:27 2005 +++ b/tools/examples/block Tue Nov 29 15:01:47 2005 @@ -1,6 +1,4 @@ #!/bin/sh - -set -x dir=$(dirname "$0") . "$dir/block-common.sh" @@ -19,30 +17,49 @@ } +## +# 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 'ro' + echo 'r' elif ! expr index "$mode" '!' >/dev/null then - echo 'rw' + echo 'w' else - echo 'no' - fi -} - - -## -# check_sharing device device_major_minor mode + echo '!' + fi +} + + +## +# check_sharing device mode # # Check whether the device requested is already in use. To use the device in # read-only mode, it may be in use in read-only mode, but may not be in use in # read-write anywhere at all. To use the device in read-write mode, it must # not be in use anywhere at all. # +# Prints one of +# +# 'local': the device may not be used because it is mounted in the current +# (i.e. the privileged domain) in a way incompatible with the +# requested mode; +# 'guest': the device may not be used because it already mounted by a guest +# in a way incompatible with the requested mode; or +# 'ok': the device may be used. +# check_sharing() { local dev="$1" @@ -51,7 +68,7 @@ local devmm=$(device_major_minor "$dev") local file - if [ "$mode" == 'rw' ] + if [ "$mode" == 'w' ] then toskip="^$" else @@ -79,7 +96,7 @@ local d=$(cat "$file") if [ "$d" == "$devmm" ] then - if [ "$mode" == 'rw' ] + if [ "$mode" == 'w' ] then echo 'guest' return @@ -100,13 +117,18 @@ } +## +# check_device_sharing dev mode +# +# Perform the sharing check for the given physical device and mode. +# check_device_sharing() { local dev="$1" local mode=$(canonicalise_mode "$2") local result - if [ "$mode" == 'no' ] + if [ "$mode" == '!' ] then return 0 fi @@ -120,6 +142,12 @@ } +## +# check_device_sharing file dev mode +# +# Perform the sharing check for the given file mounted through the given +# loopback interface, in the given mode. +# check_file_sharing() { local file="$1" @@ -136,6 +164,13 @@ } +## +# do_ebusy prefix mode result +# +# Helper function for check_device_sharing check_file_sharing, calling ebusy +# with an error message constructed from the given prefix, mode, and result +# from a call to check_sharing. +# do_ebusy() { local prefix="$1" @@ -151,7 +186,7 @@ when='by a guest' fi - if [ "$mode" == 'rw' ] + if [ "$mode" == 'w' ] then m1='' m2='' @@ -195,7 +230,7 @@ file=$(readlink -f "$p") mode=$(canonicalise_mode "$mode") - if [ "$mode" == 'rw' ] && ! stat "$file" -c %A | grep w >&/dev/null + if [ "$mode" == 'w' ] && ! stat "$file" -c %A | grep -q w then ebusy \ "File $file is read-only, and so I will not @@ -221,7 +256,7 @@ if [ "$f" ] then # $dev is in use. Check sharing. - if [ "$mode" == 'no' ] + if [ "$mode" == '!' ] then continue fi _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |