From: "Kasai Takanori" Subject: [PATCH] Add sharing-check for blktap Date: Fri, 17 Aug 2007 17:52:30 +0900 Message-ID: <095a01c7e0ab$f66f57b0$dab2220a@VF03007L> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0957_01C7E0F7.61E833E0" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel List-Id: xen-devel@lists.xenproject.org This is a multi-part message in MIME format. ------=_NextPart_000_0957_01C7E0F7.61E833E0 Content-Type: text/plain; format=flowed; charset="iso-2022-jp"; reply-type=original Content-Transfer-Encoding: 7bit Hi All, When the same file is specified with blktap in two or more domains, it is not checked regardless of the mode. The configuration file is defined as follows. Domain1 : disk = [ ,"tap:aio:/xen/image/tmp/drive.img-1,xvdd,w" ] Domain2 : disk = [ ,"tap:aio:/xen/image/tmp/drive.img-1,xvdd,w" ] Even if the same file is specified, the domain can be started. # xm create -f Domain1 Using config file "./Domain1" Started domain Domain1 # xm create -f Domain2 Using config file "./Domain2" Started domain Domain2 Whether it is possible to share in the specified mode in file backend and physical device is checked. However, blktap is not checked at all. Domain1 Domain2 phy: tap: mode mode file: --------+---------+----------+------------ w w Error Started w r Error Started w w! Started Started r w Error Started r r Started Started r w! Started Started w! w Error Started w! r Started Started w! w! Started Started There is a possibility of breaking the file because it can unconsciously share the same file by two or more domains. We corrected to do the sharing-check for blktap similarly. It was tested to check it similarly with all cases in this patch. Signed-off-by: Takanori Kasai Signed-off-by: Hirofumi Tsujimura Best Regards -- Takanori Kasai ------=_NextPart_000_0957_01C7E0F7.61E833E0 Content-Type: application/octet-stream; name="sharing-check-for-blktap.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="sharing-check-for-blktap.patch" # HG changeset patch=0A= # User kasai.takanori@jp.fujitsu.com=0A= # Date 1187334489 -32400=0A= # Node ID f7d985c286f1b670bc470383094bd6238eed122b=0A= # Parent 256160ff19b74057f5819af20d68e6e3388c80e3=0A= Add sharing-check for blktap=0A= =0A= Signed-off-by: Takanori Kasai =0A= Signed-off-by: Hirofumi Tsujimura =0A= =0A= diff -r 256160ff19b7 -r f7d985c286f1 tools/examples/blktap=0A= --- a/tools/examples/blktap Thu Aug 16 13:27:59 2007 +0100=0A= +++ b/tools/examples/blktap Fri Aug 17 16:08:09 2007 +0900=0A= @@ -7,6 +7,57 @@ dir=3D$(dirname "$0")=0A= . "$dir/block-common.sh"=0A= =0A= findCommand "$@"=0A= +=0A= +##=0A= +# check_blktap_sharing file mode=0A= +#=0A= +# Perform the sharing check for the given blktap and mode.=0A= +#=0A= +check_blktap_sharing()=0A= +{=0A= + local file=3D"$1"=0A= + local mode=3D"$2"=0A= +=0A= + local base_path=3D"$XENBUS_BASE_PATH/$XENBUS_TYPE"=0A= + for dom in $(xenstore-list "$base_path")=0A= + do=0A= + for dev in $(xenstore-list "$base_path/$dom")=0A= + do=0A= + params=3D$(xenstore_read "$base_path/$dom/$dev/params" | = cut -d: -f2)=0A= + if [ "$file" =3D "$params" ]=0A= + then=0A= +=0A= + if [ "$mode" =3D 'w' ]=0A= + then=0A= + if ! same_vm "$dom" =0A= + then=0A= + echo 'guest'=0A= + return=0A= + fi=0A= + else =0A= + local m=3D$(xenstore_read = "$base_path/$dom/$dev/mode")=0A= + m=3D$(canonicalise_mode "$m")=0A= +=0A= + if [ "$m" =3D 'w' ] =0A= + then=0A= + if ! same_vm "$dom"=0A= + then=0A= + echo 'guest'=0A= + return=0A= + fi=0A= + fi=0A= + fi=0A= + fi=0A= + done=0A= + done=0A= +=0A= + echo 'ok'=0A= +}=0A= +=0A= +FRONTEND_ID=3D$(xenstore_read "$XENBUS_PATH/frontend-id")=0A= +FRONTEND_UUID=3D$(xenstore_read "/local/domain/$FRONTEND_ID/vm")=0A= +mode=3D$(xenstore_read "$XENBUS_PATH/mode")=0A= +mode=3D$(canonicalise_mode "$mode")=0A= =0A= t=3D$(xenstore_read_default "$XENBUS_PATH/type" 'MISSING')=0A= if [ -n "$t" ]=0A= @@ -20,6 +71,12 @@ fi=0A= fi=0A= file=3D$(readlink -f "$p") || ebusy "$p does not exist."=0A= =0A= +if [ "$mode" !=3D '!' ] =0A= +then=0A= + result=3D$(check_blktap_sharing "$file" "$mode")=0A= + [ "$result" =3D 'ok' ] || ebusy "$file already in use by other = domain"=0A= +fi=0A= +=0A= if [ "$command" =3D 'add' ]=0A= then=0A= [ -e "$file" ] || { ebusy $file does not exist; }=0A= diff -r 256160ff19b7 -r f7d985c286f1 tools/examples/block=0A= --- a/tools/examples/block Thu Aug 16 13:27:59 2007 +0100=0A= +++ b/tools/examples/block Fri Aug 17 16:08:09 2007 +0900=0A= @@ -14,32 +14,6 @@ expand_dev() {=0A= ;;=0A= esac=0A= echo -n $dev=0A= -}=0A= -=0A= -=0A= -##=0A= -# canonicalise_mode mode=0A= -#=0A= -# Takes the given mode, which may be r, w, ro, rw, w!, or rw!, or = variations=0A= -# thereof, and canonicalises them to one of=0A= -#=0A= -# 'r': perform checks for a new read-only mount;=0A= -# 'w': perform checks for a read-write mount; or=0A= -# '!': perform no checks at all.=0A= -#=0A= -canonicalise_mode()=0A= -{=0A= - local mode=3D"$1"=0A= -=0A= - if ! expr index "$mode" 'w' >/dev/null=0A= - then=0A= - echo 'r'=0A= - elif ! expr index "$mode" '!' >/dev/null=0A= - then=0A= - echo 'w'=0A= - else=0A= - echo '!'=0A= - fi=0A= }=0A= =0A= =0A= @@ -123,22 +97,6 @@ check_sharing()=0A= done=0A= =0A= echo 'ok'=0A= -}=0A= -=0A= -=0A= -same_vm()=0A= -{=0A= - local otherdom=3D"$1"=0A= - # Note that othervm can be MISSING here, because Xend will be racing = with=0A= - # the hotplug scripts -- the entries in /local/domain can be removed = by=0A= - # Xend before the hotplug scripts have removed the entry in=0A= - # /local/domain/0/backend/. In this case, we want to pretend that the=0A= - # VM is the same as FRONTEND_UUID, because that way the 'sharing' = will be=0A= - # allowed.=0A= - local othervm=3D$(xenstore_read_default "/local/domain/$otherdom/vm" = \=0A= - "$FRONTEND_UUID")=0A= -=0A= - [ "$FRONTEND_UUID" =3D "$othervm" ]=0A= }=0A= =0A= =0A= diff -r 256160ff19b7 -r f7d985c286f1 tools/examples/block-common.sh=0A= --- a/tools/examples/block-common.sh Thu Aug 16 13:27:59 2007 +0100=0A= +++ b/tools/examples/block-common.sh Fri Aug 17 16:08:09 2007 +0900=0A= @@ -71,3 +71,46 @@ write_dev() {=0A= =0A= success=0A= }=0A= +=0A= +=0A= +##=0A= +# canonicalise_mode mode=0A= +#=0A= +# Takes the given mode, which may be r, w, ro, rw, w!, or rw!, or = variations=0A= +# thereof, and canonicalises them to one of=0A= +#=0A= +# 'r': perform checks for a new read-only mount;=0A= +# 'w': perform checks for a read-write mount; or=0A= +# '!': perform no checks at all.=0A= +#=0A= +canonicalise_mode()=0A= +{=0A= + local mode=3D"$1"=0A= +=0A= + if ! expr index "$mode" 'w' >/dev/null=0A= + then=0A= + echo 'r'=0A= + elif ! expr index "$mode" '!' >/dev/null=0A= + then=0A= + echo 'w'=0A= + else=0A= + echo '!'=0A= + fi=0A= +}=0A= +=0A= +=0A= +same_vm()=0A= +{=0A= + local otherdom=3D"$1"=0A= + # Note that othervm can be MISSING here, because Xend will be racing = with=0A= + # the hotplug scripts -- the entries in /local/domain can be removed = by=0A= + # Xend before the hotplug scripts have removed the entry in=0A= + # /local/domain/0/backend/. In this case, we want to pretend that the=0A= + # VM is the same as FRONTEND_UUID, because that way the 'sharing' = will be=0A= + # allowed.=0A= + local othervm=3D$(xenstore_read_default "/local/domain/$otherdom/vm" = \=0A= + "$FRONTEND_UUID")=0A= +=0A= + [ "$FRONTEND_UUID" =3D "$othervm" ]=0A= +}=0A= +=0A= ------=_NextPart_000_0957_01C7E0F7.61E833E0 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel ------=_NextPart_000_0957_01C7E0F7.61E833E0--