From: Steven Haigh Subject: Re: block-iscsi with Xen 4.5 / 4.6 Date: Wed, 4 May 2016 18:48:13 +1000 Message-ID: <5729B74D.6000409@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="===============1973643552889755822==" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1axsTs-0007W0-2J for xen-devel@lists.xenproject.org; Wed, 04 May 2016 08:48:28 +0000 In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: George Dunlap , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Cc: xen-devel List-Id: xen-devel@lists.xenproject.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --===============1973643552889755822== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1H5jb5C7Xr4v8ibWf5AWburF2vVNDsbJk" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --1H5jb5C7Xr4v8ibWf5AWburF2vVNDsbJk Content-Type: multipart/mixed; boundary="vjP3TUC4eMMXFNtV6tvI0hVHt7KsPwarX" From: Steven Haigh To: George Dunlap , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Cc: xen-devel Message-ID: <5729B74D.6000409@crc.id.au> Subject: Re: [Xen-devel] 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: --vjP3TUC4eMMXFNtV6tvI0hVHt7KsPwarX Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 4/05/2016 6:25 PM, George Dunlap wrote: > On Wed, May 4, 2016 at 8:34 AM, Roger Pau Monn=C3=A9 wrote: >> Hello, >> >> I'm re-adding xen-devel in case someone else also wants to provide fee= dback. >> >> 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 insigh= ts. >>> >>> 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 o= nce. >> >> This might be problematic with migrations. IIRC there's a point during= the >> migration where both the sending and the receiving side have the disk = open >> 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 >> everything has gone OK) or the one on the senders side (if migration h= as >> failed). >> >>> In a nutshell, my thoughts are to use the following to 'lock' a devic= e: >>> ## 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 o= n >>> 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 attac= h() >>> and remove(). >>> >>> My problems: >>> 1) -e is set on the script - and maybe elsewhere - so any time someth= ing >>> 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. >> >> You can avoid this by adding something like: >> >> sg_persist ... || true >> >> Of course you can replace the "true" command with something else, like= a >> fatal message or some cleanup code. You can also place the command ins= ide of >> a conditional if you know it might fail: >> >> if ! sg_persist ...; then >> fatal ... >> fi >> >> It is important for us to use the '-e' in order to make sure all the f= ailure >> points are correctly handled, without the '-e' some command might fail= and >> the script wouldn't realize. >=20 > I realize I'm a bit in the minority here, but I've always thought this > was rather a strange habit of bash scripts. In every other language, > you check the error codes of things that can fail and you handle them > appropriately. If you're just hacking something together, then "set > -e" is probably OK, but wouldn't it make more sense in an > infrastructure script like this to actually go through and handle all > the errors? Worst case you could just if ! [command] ; then exit 1 ; > fi. Then I'm in the minority too ;) > Regarding the "maybe elsewhere" -- AFAIK the block-scsi script itself > is run directly from libxl, so nothing "above" it should be setting > -e; and it only includes block-common, which does not seem to be > setting it. Right now, even removing -e from line 1 causes something like this to exit the script: if [ $? !=3D 0 ]; then So, if I run the following, the script will always fail: key=3D$(gethostip -x $(uname -n)) sg_persist -d ${dev} -o -G -S ${key} > /dev/null if [ $? !=3D 0 ]; then iscsiadm -m node -T ${iqn} --logout > /dev/null fatal "Could not obtain lock on $iqn" fi man 3 sg3_utils (http://linux.die.net/man/8/sg3_utils) shows a possible list of exit codes - which it would be useful to consult at least *some* of them with useful errors - such as: Exit status 3: the DEVICE reports that it is not ready for the operation requested. The device may be in the process of becoming ready (e.g. spinning up but not at speed) so the utility may work after a wait. Also possibly a case for locking not being supported. > That said, in theory as Roger said, if you actually are checking the > error code of all your commands (which you should be if you need to do > clean-up on failure), then 'set -e' shouldn't actually be causing an > exit. >=20 > -George >=20 --=20 Steven Haigh Email: netwiz@crc.id.au Web: https://www.crc.id.au Phone: (03) 9001 6090 - 0412 935 897 --vjP3TUC4eMMXFNtV6tvI0hVHt7KsPwarX-- --1H5jb5C7Xr4v8ibWf5AWburF2vVNDsbJk 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 iQIcBAEBCAAGBQJXKbdNAAoJEEGvNdV6fTHc5q0P/jeck0K5ORashV4TGBqpGYhz SzQDqY94CUkkLjC5Do3G6GsM9IEDcmIjRfpmLx4HD6MISqOd78cyDlAtcKdFMBV9 V0KcxQvLHRwdo1WnerMRcZL2mxu9Q+a5XO712TD1tWkQwaTICggZlNzY1C51OBH7 vnAQhfeVDAbbOdN8kwaS2fvR3EStd9/jPrrYLgzxCdlZbmXOi1148XPO3fe1CVFU JmLtGQOTaQqywrmZAku1A+QjZPDzbNmHtZt2PPjxV8eAPqgaCisC8pSytx91xDN1 6EAhC9VACHrAh4cuqeoxwGM+tHSOLWtUdSKYlm9lsJE1bofbUYASwLT1T5v96398 ewMGPjig1NkLFzP36H0bBQ3GwmIDzMkV1wwqRoJZD2LOwFp4QtxEL9E1JuO5+6Dh 0HykCKER2MO208sS8nOYC6Q+M5BkZFQy72c2A8YVva/8YJBJGj0AyA2JTX4OmopJ 6Wzfv0xZmCe6a0TOoTdJ5GbTdOG10BV8dZjQjeuzluc1IlXG3YK9m8Om2MW2v5Bp P6G/UTmGNbO9L3rsEW0xSf6apHHJNMKd++nfXe98zD9xFxUsRy8TkG50SldE4VA8 XB2giU5SztXGbWFKPqYmlpn8GP/SnjKfuD5ED7h7CR85FJSmsPn1jU3vXguTcGX0 0n3zRX6qzex9EkOhRWVM =pdwk -----END PGP SIGNATURE----- --1H5jb5C7Xr4v8ibWf5AWburF2vVNDsbJk-- --===============1973643552889755822== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwOi8vbGlzdHMueGVuLm9y Zy94ZW4tZGV2ZWwK --===============1973643552889755822==--