From: Steven Haigh Subject: Re: block-iscsi with Xen 4.5 / 4.6 Date: Wed, 4 May 2016 18:41:26 +1000 Message-ID: <5729B5B6.5030908@crc.id.au> References: <20160415072302.7n27oi7fq2ovkcfk@mac> <20160415074557.5jc6ra5cfh7lddni@mac> <20160415080354.3iw3g6f4qcbpmvoi@mac> <1aa4407c83225184e49138e4500246de@crc.id.au> <20160415090104.7flxu2jptoj6p4z2@mac> <5729834F.9050306@crc.id.au> <20160504073432.fpcporcbk4nwkzpa@mac> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2560340098650393468==" Return-path: Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1axsNL-00073L-E8 for xen-devel@lists.xenproject.org; Wed, 04 May 2016 08:41:43 +0000 In-Reply-To: <20160504073432.fpcporcbk4nwkzpa@mac> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Cc: xen-devel@lists.xenproject.org List-Id: xen-devel@lists.xenproject.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --===============2560340098650393468== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="gqDSamX6LwSA8NP4HKPWGnv0nkWqErv4S" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --gqDSamX6LwSA8NP4HKPWGnv0nkWqErv4S Content-Type: multipart/mixed; boundary="x9dwKtvBN49OJthJs5w7DBVigarGEvhgC" From: Steven Haigh To: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Cc: xen-devel@lists.xenproject.org Message-ID: <5729B5B6.5030908@crc.id.au> Subject: Re: block-iscsi with Xen 4.5 / 4.6 References: <20160415072302.7n27oi7fq2ovkcfk@mac> <20160415074557.5jc6ra5cfh7lddni@mac> <20160415080354.3iw3g6f4qcbpmvoi@mac> <1aa4407c83225184e49138e4500246de@crc.id.au> <20160415090104.7flxu2jptoj6p4z2@mac> <5729834F.9050306@crc.id.au> <20160504073432.fpcporcbk4nwkzpa@mac> In-Reply-To: <20160504073432.fpcporcbk4nwkzpa@mac> --x9dwKtvBN49OJthJs5w7DBVigarGEvhgC Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 4/05/2016 5:34 PM, Roger Pau Monn=E9 wrote: > Hello, >=20 > I'm re-adding xen-devel in case someone else also wants to provide feed= back. >=20 > On Wed, May 04, 2016 at 03:06:23PM +1000, Steven Haigh wrote: >> Hi Roger, >> >> I've been getting some good progress with iSCSI thanks to your insight= s. >> >> I'm now trying to add support for locking via Persistent Reservations = to >> ensure that only one Dom0 can attach / use a single iSCSI target at on= ce. >=20 > This might be problematic with migrations. IIRC there's a point during = the=20 > migration where both the sending and the receiving side have the disk o= pen=20 > at the same time. However Xen always makes sure that only one guest is = > actually accessing the disk, either the one on the receiving side (if=20 > everything has gone OK) or the one on the senders side (if migration ha= s=20 > failed). True - however I'd like to eventually attempt to commit changes to the project and allow locking to be done as an option - just like iqn / portal / multipath. In my specific use case, its to stop someone accidentally starting the same VM on multiple Dom0's at the same time - which from what I've seen causes disk corruption and all kinds of issues. It leads to people not having a good time. The iSCSI system has a limit to the max connections - however it seems that only applies *per host* meaning max connections =3D 1 will allow one= connection per Dom0. >> In a nutshell, my thoughts are to use the following to 'lock' a device= : >> ## Create a hex key for the lock from the systems IP. >> key=3D$(gethostip -x $(uname -n)) >> sg_persist -d ${dev} -o -G -S ${key} >> sg_persist -d ${dev} -o -R -K ${key} -T 6 >> >> This registers the device, and sets an Exclusive Access (-T 6) flag on= >> the iSCSI device which means nothing else will be able to open the >> device until the lock is removed. >> >> To unlock the device, on remove, we should do something like: >> key=3D$(gethostip -x $(uname -n)) >> sg_persist -d ${dev} -o -L -K ${key} -T 6 >> sg_persist -d ${dev} -o -G -K ${key} -S 0 >> >> This releases the device for other things to use. >> >> I've tried putting these in block-iscsi - by using a lock_device and >> unlock_device function and calling it after find_device in both attach= () >> and remove(). >> >> My problems: >> 1) -e is set on the script - and maybe elsewhere - so any time somethi= ng >> returns non-zero, you can't clean up. For example, if you can't get a >> lock, you should make sure all locks are removed from the host in >> question and then detach the iSCSI target. >=20 > You can avoid this by adding something like: >=20 > sg_persist ... || true >=20 > Of course you can replace the "true" command with something else, like = a=20 > fatal message or some cleanup code. You can also place the command insi= de of=20 > a conditional if you know it might fail: >=20 > if ! sg_persist ...; then > fatal ... > fi >=20 > It is important for us to use the '-e' in order to make sure all the fa= ilure=20 > points are correctly handled, without the '-e' some command might fail = and=20 > the script wouldn't realize. I honestly think this is pretty nasty. While it may not be true of all scripts, the block-iscsi script can only really fail in a couple of places - yet we have this set of procedures called: parse_target -> check_tools -> prepare -> add -> attach -> find_device -> write_dev. At least check_tools, prepare, add, attach, find_device could all be rolled into a single function - as the majority of the rest is 1-4 lines of code. There are situations where you may want to evaluate the result of sg_persist beyond a simple "worked or failed" - and that seems to be the idea of fatal "The reason that I died is X". >> 2) I can't find an easy way to clean up by doing an iscsiadm --logout = if >> the locking fails. >=20 > I'm not really following here, maybe because I don't know that much abo= ut=20 > iSCSI. Can you just put whatever code is needed in order to unlock befo= re=20 > doing the logout? Or that's not how it works? Yes, but if one of the two unlocks fails, the script terminates. It makes different error checking *VERY* difficult. If I remove the -e from line #1, the script still acts as if -e is still set - so something else is enforcing that. >> I'm wondering if there is a reason that the script is currently in the= >> stucture that it is - or if it just evolved like this? It may be a goo= d >> candidate for a complete re-write :\ >=20 > TBH, I thought this was one of the most clean and well structured block= =20 > scripts that Xen has ;). Please don't scare me ;) --=20 Steven Haigh Email: netwiz@crc.id.au Web: https://www.crc.id.au Phone: (03) 9001 6090 - 0412 935 897 --x9dwKtvBN49OJthJs5w7DBVigarGEvhgC-- --gqDSamX6LwSA8NP4HKPWGnv0nkWqErv4S Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXKbW2AAoJEEGvNdV6fTHcsjIP/RTBHW1/MmlJlJV6ID1lPwso rGWEu52C/v+4l7Bb/+AqM3syd1JJH0mhfdrezg7PmAyWHKrzGs6SaGSbFtmW7kTW k5pqqFHtqhbXvvIRh3K/TnGmEoOdJcLivZdpF1Gtu8WlY/dtiX3osOG0YedQZzCD oWr+atVfPDCTbXh0r9XnRhu3tyAeznCrv6MQT9KfQGERYkL45n7/5Lswqb8ShiUj +yJ+WPt92QQkmKnVIryiVZio++29r808b8fgmDxGZHef3k8bjt7mHRoBoiAvaXA6 IMekObofgZMRLBzFgyXSk/cQOFv70nwyAo5vx/Lqu//gyjFQpsDF63cEZulJCPFq u4y62SOnyASttVdMLRRFFy2BV7ZmXgosa0ggsVSARagjXVFT+xQGQivQ3B5XZ6Qx iaylCIAxJu68rdFJmJLlt8A8yWiIkCV2DFN95bVwc08lq/tR9LhfX7i7RR/IQJ98 mNNVWq5Coy8m1cNzFoGlz4h9TP8wM+W8oLIp4NNIopFfN5EME2ziYGMo1Wp5dEbh gAdiKSNMzIhI1UR2pm401PqdY+1EmkMDKPZdOPBSskqAUhcPM06scUAlxuy90O0m Ftnz5eDM3iR3nSHtH+Y0Xtte820uZNW+YAuwyUC0d+vfSJmRaGgoKQR1zmJMbhgH oK4X/h8SJZlzdxfgjjTA =5tnp -----END PGP SIGNATURE----- --gqDSamX6LwSA8NP4HKPWGnv0nkWqErv4S-- --===============2560340098650393468== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwOi8vbGlzdHMueGVuLm9y Zy94ZW4tZGV2ZWwK --===============2560340098650393468==--