From mboxrd@z Thu Jan 1 00:00:00 1970 From: Philipp Hahn Subject: Re: [PATCHv2] insufficient quoting between "tap-ctl list" and xend/server/BlktapController.py Date: Sat, 3 Dec 2011 21:42:51 +0100 Message-ID: <201112032142.56295.hahn@univention.de> References: <201111251721.12753.hahn@univention.de> <201111252057.31649.hahn@univention.de> <20183.51176.909813.103305@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8160156230039480396==" Return-path: In-Reply-To: <20183.51176.909813.103305@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ian Jackson Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --===============8160156230039480396== Content-Type: multipart/signed; boundary="nextPart6805590.KM9JBeCDoc"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit --nextPart6805590.KM9JBeCDoc Content-Type: multipart/mixed; boundary="Boundary-01=_Lno2Oln0JD/AQPI" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_Lno2Oln0JD/AQPI Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello Ian, On Thursday 01 December 2011 19:31:04 you wrote: > Philipp Hahn writes ("Re: [Xen-devel] [BUG] insufficient quoting=20 between "tap-ctl list" and xend/server/BlktapController.py"): > > As a quick work-around, the attached patch fixes the problem for me. Th= at > > is, until tap-ctl changes it's output format. > > Thanks, I have applied it. Argh, I submitted the wrong patch. The "line.split(None, 4)" needs to be=20 a "3", because 3 splits needs to be done to get the 4 parts. 0004 is the correct full patch, 0005 is the inter-diff. Sorry for the mixup. Sincerely Philipp =2D-=20 Philipp Hahn Open Source Software Engineer hahn@univention.de Univention GmbH Linux for Your Business fon: +49 421 22 232- 0 Mary-Somerville-Str.1 D-28359 Bremen fax: +49 421 22 232-99 http://www.univention.de/ --Boundary-01=_Lno2Oln0JD/AQPI Content-Type: text/x-diff; charset="utf-8"; name="0004-tap-ctl.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0004-tap-ctl.patch" Bug #18357: Fix tap-ctl parsing. Shutting down a domU with xen-4.1.2 doesn't terminate the corresponding blk= tap2 process, since one (other) VM uses a image file, which contains spaces in i= ts file name. /var/log/xen/xend-debug.log has the following information: Unhandled exception in thread started by Traceback (most recent call last): =C2=A0 File "/usr/lib/python2.6/dist-packages/xen/xend/server/BlktapControl= ler.py", line 199, in finishDeviceCleanup =C2=A0 =C2=A0 TapdiskController.destroy(path) =C2=A0 File "/usr/lib/python2.6/dist-packages/xen/xend/server/BlktapControl= ler.py", line 289, in destroy =C2=A0 =C2=A0 tapdisk =3D TapdiskController.fromDevice(device) =C2=A0 File "/usr/lib/python2.6/dist-packages/xen/xend/server/BlktapControl= ler.py", line 278, in fromDevice =C2=A0 =C2=A0 TapdiskController.list()) =C2=A0 File "/usr/lib/python2.6/dist-packages/xen/xend/server/BlktapControl= ler.py", line 256, in list =C2=A0 =C2=A0 key, value =3D pair.split('=3D') ValueError: need more than 1 value to unpack BlktapController calls "tap-ctl list", which outputs one line for each proc= ess. Each line contains key=3Dvalue pairs without any quoting. # tap-ctl list | grep 'args=3D.*:.* ' pid=3D10145 minor=3D18 state=3D0 args=3Daio:/var/lib/libvirt/images/Xen Win= dows drivers (gplpv 308).iso (passing the output of tap-ctl through a pipe is important, since it switch= es to a different list-format when STDOUT is a tty.) BlktapController splits the output into lines using \n, then each line at e= ach space, and finally each of these 'words' at the '=3D', which fails for the filename. Limit the number of splits as a fast work-around. =2D-- a/tools/python/xen/xend/server/BlktapController.py +++ b/tools/python/xen/xend/server/BlktapController.py @@ -249,11 +249,12 @@ class TapdiskController(object): _list =3D TapdiskController.exc('list') if not _list: return [] =20 =2D for line in _list.split('\n'): + for line in _list.splitlines(): tapdisk =3D TapdiskController.Tapdisk() =20 =2D for pair in line.split(): =2D key, value =3D pair.split('=3D') + # Since 'tap-ctl list' does not escape blanks in the path, har= d-code the current format using 4 pairs to prevent splitting the path + for pair in line.split(None, 3): + key, value =3D pair.split('=3D', 1) if key =3D=3D 'pid': tapdisk.pid =3D value elif key =3D=3D 'minor': @@ -264,7 +265,7 @@ class TapdiskController(object): elif key =3D=3D 'state': tapdisk.state =3D value elif key =3D=3D 'args' and value.find(':') !=3D -1: =2D tapdisk.dtype, tapdisk.image =3D value.split(':') + tapdisk.dtype, tapdisk.image =3D value.split(':', 1) =20 tapdisks.append(tapdisk) =20 --Boundary-01=_Lno2Oln0JD/AQPI Content-Type: text/x-diff; charset="iso-8859-15"; name="0005-tap-ctl.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0005-tap-ctl.patch" Bug #18357: Fix tap-ctl parsing. The previous patch was still wrong: Pythons split() expects the number of splits, not the number of results. Do 3 splits to get pid, minor, state and args. =2D-- a/tools/python/xen/xend/server/BlktapController.py +++ b/tools/python/xen/xend/server/BlktapController.py @@ -252,7 +252,7 @@ class TapdiskController(object): tapdisk =3D TapdiskController.Tapdisk() =20 # Since 'tap-ctl list' does not escape blanks in the path, har= d-code the current format using 4 pairs to prevent splitting the path =2D for pair in line.split(None, 4): + for pair in line.split(None, 3): key, value =3D pair.split('=3D', 1) if key =3D=3D 'pid': tapdisk.pid =3D value --Boundary-01=_Lno2Oln0JD/AQPI-- --nextPart6805590.KM9JBeCDoc Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEABECAAYFAk7aicsACgkQYPlgoZpUDjlLzwCfUqzK00qj39sY2AgN0OQQtc0T S1QAnj+kzIKZAY1UyifVBaF0JOiqWEK4 =EeRp -----END PGP SIGNATURE----- --nextPart6805590.KM9JBeCDoc-- --===============8160156230039480396== 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 --===============8160156230039480396==--