Received: from eggs.gnu.org ([2001:4830:134:3::10]:38659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCjaf-0003EN-Ap for qemu-devel@nongnu.org; Tue, 14 Jun 2016 04:20:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCjad-0001w2-84 for qemu-devel@nongnu.org; Tue, 14 Jun 2016 04:20:52 -0400 Date: Tue, 14 Jun 2016 10:20:38 +0200 From: Kevin Wolf Message-ID: <20160614082038.GB4916@noname.str.redhat.com> References: <1464973388-15821-1-git-send-email-eblake@redhat.com> <1464973388-15821-4-git-send-email-eblake@redhat.com> <20160607124522.GH4684@noname.str.redhat.com> <575C8B48.7030909@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="pvezYHf7grwyp3Bc" Content-Disposition: inline In-Reply-To: <575C8B48.7030909@redhat.com> Subject: Re: [Qemu-devel] [PATCH 3/5] block: Switch transfer length bounds to byte-based List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: qemu-devel@nongnu.org, mreitz@redhat.com, qemu-block@nongnu.org, Stefan Hajnoczi , Fam Zheng , Ronnie Sahlberg , Paolo Bonzini , Peter Lieven , "Michael S. Tsirkin" --pvezYHf7grwyp3Bc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Am 12.06.2016 um 00:06 hat Eric Blake geschrieben: > On 06/07/2016 06:45 AM, Kevin Wolf wrote: > > Am 03.06.2016 um 19:03 hat Eric Blake geschrieben: > >> Sector-based limits are awkward to think about; in our on-going > >> quest to move to byte-based interfaces, convert max_transfer_length > >> and opt_transfer_length. Rename them (dropping the _length suffix) > >> so that the compiler will help us catch the change in semantics > >> across any rebased code. Improve the documentation, and guarantee > >> that blk_get_max_transfer() returns a non-zero value. Use unsigned > >> values, so that we don't have to worry about negative values and > >> so that bit-twiddling is easier; however, we are still constrained > >> by 2^31 of signed int in most APIs. > >> > >> Of note: the iscsi calculations use a 64-bit number internally, > >> but the final result is guaranteed to fit in 32 bits. NBD is > >> fixed to advertise the maximum length of 32M that the qemu and > >> kernel servers enforce, rather than a number of sectors that > >> would overflow int when converted back to bytes. scsi-generic > >> now advertises a maximum always, rather than just when the > >> underlying device advertised a maximum. > >> > >> Signed-off-by: Eric Blake > >=20 > >> @@ -1177,7 +1176,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes= (BlockDriverState *bs, > >> > >> if (ret =3D=3D -ENOTSUP) { > >> /* Fall back to bounce buffer if write zeroes is unsuppor= ted */ > >> - int max_xfer_len =3D MIN_NON_ZERO(bs->bl.max_transfer_len= gth, > >> + int max_xfer_len =3D MIN_NON_ZERO(bs->bl.max_transfer, > >> MAX_WRITE_ZEROES_BOUNCE_B= UFFER); > >=20 > > You could consider renaming the variable to max_transfer to keep it > > consistent with the BlockLimits field name and to make it even more > > obvious that you converted all uses. >=20 > Good idea. >=20 > >> @@ -1706,13 +1708,14 @@ static void iscsi_refresh_limits(BlockDriverSt= ate *bs, Error **errp) > >> * iscsi_open(): iscsi targets don't change their limits. */ > >> > >> IscsiLun *iscsilun =3D bs->opaque; > >> - uint32_t max_xfer_len =3D iscsilun->use_16_for_rw ? 0xffffffff : = 0xffff; > >> + uint64_t max_xfer_len =3D iscsilun->use_16_for_rw ? 0xffffffff : = 0xffff; > >> > >> if (iscsilun->bl.max_xfer_len) { > >> max_xfer_len =3D MIN(max_xfer_len, iscsilun->bl.max_xfer_len); > >> } > >> > >> - bs->bl.max_transfer_length =3D sector_limits_lun2qemu(max_xfer_le= n, iscsilun); > >> + bs->bl.max_transfer =3D MIN(BDRV_REQUEST_MAX_SECTORS << BDRV_SECT= OR_BITS, > >> + max_xfer_len * iscsilun->block_size); > >=20 > > Why don't you simply use 0 when you defined it as no limit? > >=20 > > If we make some drivers put 0 there and others INT_MAX, chances are that > > we'll introduce places where we fail to handle 0 correctly. >=20 > So if I'm understanding correctly, we want something like: >=20 > if (max_xfer_len * iscsilun->block_size > INT_MAX) { > bs->bl.max_transfer =3D 0; > } else { > bs->bl.max_transfer =3D max_xfer_len * iscsilun->block_size; > } >=20 > and make sure that 0 continues to mean 'no signed 32-bit limit'. Forget that, brain fart. Somehow I was thinking that just doing the assignment without MIN() would do the right thing. Which it very obviously doesn't. Kevin --pvezYHf7grwyp3Bc Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJXX75WAAoJEH8JsnLIjy/Wij0P/jdx2Fy2Br7hHOYdD8l34nt7 a4D0lbI4pZB12kenJx00pYQOGwAT2MePb0dQDyBqSy53I+iEnKFqKBR1AXGCYYsr cFtl5UHIBDZrIeqpMpxBzCSHvy//ZIKToT6aZKqRqa0ufYm1jPB/Zj5CH1PVbrPf 11S9Z2duP7Vd/qvsLatgzMr+EEr54oYn8UAYCqAzQLiWTYihalk7dEpFwWFWkbYx uTvxYvxb6BuAiMsDYXEhq1y3EAuuk/Rfo8G87B7pUXiS4SxUmOPLD9RTeF1H/hiD GL7KWjwDh4UzLP/A93qZ+tx/AQo3FowoHuFyWIBrDuuNpHJZo15O10p+S7cC8dzl lBbfMF4YYnD4WPSVU4iyRMagiYfbmobwZ02tfIMPAgITXcHGnadBx5bnHYp4NfY5 Ri3gsnsWGmBDopdUdfglVjL+hn0HLk9ixf9wFPW1qZ16kYvBlGTe0zNkvJ7lFvR/ Q18CACfExAZHU04UPOYwp6Z2YT1Rk9Jx43Zkwoe9t+OugHSPzwZvSKHWF8gWFLbu /utrDm/ZUOVbDXYAfGCq0NCNz2GkwgqSW53UNliRRN4Am+gquOZNAHyvpasYH2Ai JkV1DwjPWOFzBVKVHriXrPnRPLM0TgEJN+rEWpyELWYZCy+nDbSyAgldCwlHggwk d9Nv0LazpYsh/2x8ggyJ =ShK4 -----END PGP SIGNATURE----- --pvezYHf7grwyp3Bc--