Received: from eggs.gnu.org ([2001:4830:134:3::10]:33011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqMxZ-0007Tn-HH for qemu-devel@nongnu.org; Wed, 13 Apr 2016 11:44:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aqMxY-0004XD-B6 for qemu-devel@nongnu.org; Wed, 13 Apr 2016 11:44:05 -0400 From: Pino Toscano Date: Wed, 13 Apr 2016 17:43:50 +0200 Message-ID: <1518327.kX30qTdlC0@pendragon.usersys.redhat.com> In-Reply-To: <1460557100-1393-1-git-send-email-berrange@redhat.com> References: <1460557100-1393-1-git-send-email-berrange@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1521438.OPSqkH8H5m"; micalg="pgp-sha256"; protocol="application/pgp-signature" Subject: Re: [Qemu-devel] [PATCH for 2.6] block: convert iscsi target to a valid ID for -iscsi arg lookup List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, Paolo Bonzini , Ronnie Sahlberg , Peter Lieven , Eric Blake --nextPart1521438.OPSqkH8H5m Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="ISO-8859-1" On Wednesday 13 April 2016 15:18:20 Daniel P. Berrange wrote: > The iSCSI block driver has a very strange approach whereby it > does not accept options directly as part of the -drive arg, > but instead takes them indirectly from a -iscsi arg. To make > up -driver and -iscsi args, it takes the iSCSI target name > and uses that as an ID value for the -iscsi arg lookup. >=20 > For example, given a -drive arg that looks like >=20 > -drive file=3Discsi://192.168.122.1:3260/iqn.2013-12.com.example%3Ai= scsi-chap-netpool/1,format=3Draw,if=3Dnone,id=3Ddrive-virtio-disk0 >=20 > The iSCSI driver will try to find the -iscsi arg with an > id of "iqn.2013-12.com.example:iscsi-chap-netpool" eg it > expects >=20 > -iscsi id=3Diqn.2013-12.com.example:iscsi-chap-netpool,user=3Dfred,= password-secret=3Dsecret0 >=20 > Unfortunately this is impossible to actually do in practice > because almost all iSCSI target names contain a ':' which > is not a valid ID character for QEMU: >=20 > $ qemu-system-x86_64: -iscsi id=3Diqn.2013-12.com.example:iscsi-chap= =2Dnetpool,user=3Dredhat,password=3D123456: Parameter 'id' expects an ide= ntifier > Identifiers consist of letters, digits, '-', '.', '_', starting with= a letter. >=20 > So for this to work we need to remove the invalid characters > in some manner. This patch takes the simplest possible approach > of just converting all invalid characters into underscores. eg > you can now use >=20 > $ qemu-system-x86_64: -iscsi id=3Diqn.2013-12.com.example_iscsi-chap= =2Dnetpool,user=3Dredhat,password=3D123456: Parameter 'id' expects an ide= ntifier >=20 > There is theoretically the possibility for collison with this > approach if there were 2 iSCSI luns attached to the same VM > with target names that clash on the escaped char: eg >=20 > iqn.2013-12.com.example:iscsi-chap-netpool > iqn.2013-12.com.example_iscsi-chap-netpool >=20 > but in reality this will never happen. In addition in QEMU 2.7 > the need to use the -iscsi arg will be removed by allowing all > the desired options to be listed directly with -drive. IOW this > quick stripping of invalid characters is just a short term fix > that will ultimately go away. For this reason it is not thought > worthwhile to invent a full collision-free escaping syntax for > iSCSI target IDs. Maybe it would be worth as workaround for 2.6, although ... > Signed-off-by: Daniel P. Berrange > --- >=20 > Note this problem was previously raised: >=20 > http://lists.nongnu.org/archive/html/qemu-devel/2015-11/msg06501.htm= l >=20 > and discussed the following month: >=20 > http://lists.nongnu.org/archive/html/qemu-devel/2015-12/msg00112.htm= l >=20 > block/iscsi.c | 21 ++++++++++++++++++++- > 1 file changed, 20 insertions(+), 1 deletion(-) >=20 > diff --git a/block/iscsi.c b/block/iscsi.c > index 302baf8..7475cc9 100644 > --- a/block/iscsi.c > +++ b/block/iscsi.c > @@ -1070,6 +1070,22 @@ retry: > return 0; > } > =20 > + > +static char *convert_target_to_id(const char *target) > +{ > + char *id =3D g_strdup(target); > + size_t i; > + > + for (i =3D 1; id[i]; i++) { > + if (!qemu_isalnum(id[i]) && !strchr("-._", id[i])) { > + id[i] =3D '_'; > + } > + } > + > + return id; > +} > + > + > static void parse_chap(struct iscsi_context *iscsi, const char *targ= et, > Error **errp) > { > @@ -1079,13 +1095,16 @@ static void parse_chap(struct iscsi_context *= iscsi, const char *target, > const char *password =3D NULL; > const char *secretid; > char *secret =3D NULL; > + char *targetid =3D NULL; > =20 > list =3D qemu_find_opts("iscsi"); > if (!list) { > return; > } > =20 > - opts =3D qemu_opts_find(list, target); > + targetid =3D convert_target_to_id(target); > + opts =3D qemu_opts_find(list, targetid); > + g_free(targetid); > if (opts =3D=3D NULL) { > opts =3D QTAILQ_FIRST(&list->head); > if (!opts) { ... the commit message seems to suggest that it applies to all the iSCSI parameter, but it actually works on the authentication-related ones. IMHO a better way would be using convert_target_to_id directly in iscsi_open on iscsi_url->target (right after the url parsing) passing the converted id to parse_initiator_name, iscsi_set_targetname, parse_chap, and parse_header_digest: this way it can apply to all the parameters. Thanks, =2D-=20 Pino Toscano --nextPart1521438.OPSqkH8H5m Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAABCAAGBQJXDmk2AAoJEMPRTC2YZDfNd5kQAKcJS8fXQJTIIRGNvbdbq4xw 30joyD8M+4sZ0EG6W9Zfg0WppWbkmXD8nm6QrWFCB0d3GG9EmgJy/SDXslBPsmFe NGiZmkxKdI6kQUdFLiB7NThOtFYIs9xyljUMtY+Uh1QE34e4Pnb9sMGUAcEf2sYv x51cNU4wDf9wL8kCXNjVfnn4wVRPTmfFNzInAPeWWwI8ejQ2j7vUga0t+J87QN1+ K7OZPM7Vbukfo1asHZhFyVPe84WpkemTmDO5LYnJc9jJ6RuOmAhpkZYNnaVoNvjP qXTDxMfS5vj+JLal9oS0m+zh718CyIIy+QhrFkP3GGu1ZHCoj/ha+nf33Re50Vq4 p+fAtw1h8opgO1esCVURv5b7K8XTAQe1oj5Wg/qdVT6N+RaAnMRtl3CHT8j63i3P F7Ec97ku1LfIiZV3FGySgO42z574kFXX9rn2n26JMgZOmt/Qyugl+W6TNY3oOpUX NSMSCEWAZiw9eKBLvsAhMqfKVS/K7hgakxmOBFCJCrWSAF+gCdeJu6iHxtBlPFwP WdO7UWPkIv1+TRNCMeITUJivXXnEaAFy0OworbPSumyST16Vrhc3ar2tQiuUG5Jj 7Ag1qqORzXm7JY1nvv222EzGBk4o4hB8WsqhEWzGsRPDXeBI8Eldmr1B5UqVlH1B aHSLRmWz3V+fAhLwUd+n =uY3X -----END PGP SIGNATURE----- --nextPart1521438.OPSqkH8H5m--