Received: from eggs.gnu.org ([2001:4830:134:3::10]:53067) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7rxt-0004m7-GT for qemu-devel@nongnu.org; Fri, 18 Nov 2016 17:49:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c7rxs-0004fp-AK for qemu-devel@nongnu.org; Fri, 18 Nov 2016 17:49:01 -0500 References: <1479413642-22463-1-git-send-email-eblake@redhat.com> <1479413642-22463-5-git-send-email-eblake@redhat.com> From: Eric Blake Message-ID: Date: Fri, 18 Nov 2016 16:48:50 -0600 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Wm2k0PXR23qv6kiiqjhAC8tbd11gkD30e" Subject: Re: [Qemu-devel] [PATCH v2 4/9] block: Return -ENOTSUP rather than assert on unaligned discards List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, kwolf@redhat.com, pbonzini@redhat.com, qemu-stable@nongnu.org, Ronnie Sahlberg , Peter Lieven , Hitoshi Mitake , Liu Yuan , Jeff Cody , "open list:Sheepdog" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --Wm2k0PXR23qv6kiiqjhAC8tbd11gkD30e From: Eric Blake To: Max Reitz , qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, kwolf@redhat.com, pbonzini@redhat.com, qemu-stable@nongnu.org, Ronnie Sahlberg , Peter Lieven , Hitoshi Mitake , Liu Yuan , Jeff Cody , "open list:Sheepdog" Message-ID: Subject: Re: [PATCH v2 4/9] block: Return -ENOTSUP rather than assert on unaligned discards References: <1479413642-22463-1-git-send-email-eblake@redhat.com> <1479413642-22463-5-git-send-email-eblake@redhat.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 11/17/2016 04:01 PM, Max Reitz wrote: > On 17.11.2016 21:13, Eric Blake wrote: >> Right now, the block layer rounds discard requests, so that >> individual drivers are able to assert that discard requests >> will never be unaligned. But there are some ISCSI devices >> that track and coalesce multiple unaligned requests, turning it >> into an actual discard if the requests eventually cover an >> entire page, which implies that it is better to always pass >> discard requests as low down the stack as possible. >> >> In isolation, this patch has no semantic effect, since the >> block layer currently never passes an unaligned request through. >> But the block layer already has code that silently ignores >> drivers that return -ENOTSUP for a discard request that cannot >> be honored (as well as drivers that return 0 even when nothing >> was done). But the next patch will update the block layer to >> fragment discard requests, so that clients are guaranteed that >> they are either dealing with an unaligned head or tail, or an >> aligned core, making it similar to the block layer semantics of >> write zero fragmentation. >> >> +++ b/block/iscsi.c >> @@ -1083,7 +1083,9 @@ coroutine_fn iscsi_co_pdiscard(BlockDriverState = *bs, int64_t offset, int count) >> struct IscsiTask iTask; >> struct unmap_list list; >> >> - assert(is_byte_request_lun_aligned(offset, count, iscsilun)); >> + if (!is_byte_request_lun_aligned(offset, count, iscsilun)) { >> + return -ENOTSUP; >> + } >> >> if (!iscsilun->lbp.lbpu) { >> /* UNMAP is not supported by the target */ >=20 > Next line is: >=20 >> return 0; >=20 > Hmm... -ENOTSUP would be the obvious return value here, too. That might= > interfere with your next patch, though. Shouldn't interfere. I guess no one value is better than the other; I can respin to pick a consistent value (I'd lean towards -ENOTSUP) if you think it is worth it; but I'd rather get this into 2.8 without worrying about it. >=20 >> diff --git a/block/qcow2.c b/block/qcow2.c >> index e22f6dc..7cfcd84 100644 >> --- a/block/qcow2.c >> +++ b/block/qcow2.c >> @@ -2491,6 +2491,11 @@ static coroutine_fn int qcow2_co_pdiscard(Block= DriverState *bs, >> int ret; >> BDRVQcow2State *s =3D bs->opaque; >> >> + if (!QEMU_IS_ALIGNED(offset | count, s->cluster_size)) { >=20 > Ha! I like "offset | count". It only works because we know that qcow2 guarantees that s->cluster_size is a power of 2 (it does not work at the block layer, where the bs->bl.pdiscard_align need not be a power of 2). >=20 >> + assert(count < s->cluster_size); >=20 > Maybe add a comment for this assertion? E.g. "The block layer will only= > generate unaligned discard requests that are smaller than the alignment= ". Sure, if the maintainer wants a respin. >=20 >> + return -ENOTSUP; >> + } >> + >> qemu_co_mutex_lock(&s->lock); >> ret =3D qcow2_discard_clusters(bs, offset, count >> BDRV_SECTOR_B= ITS, >> QCOW2_DISCARD_REQUEST, false); >> diff --git a/block/sheepdog.c b/block/sheepdog.c >> index 1fb9173..4c9af89 100644 >> --- a/block/sheepdog.c >> +++ b/block/sheepdog.c >> @@ -2829,8 +2829,9 @@ static coroutine_fn int sd_co_pdiscard(BlockDriv= erState *bs, int64_t offset, >> iov.iov_len =3D sizeof(zero); >> discard_iov.iov =3D &iov; >> discard_iov.niov =3D 1; >> - assert((offset & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); >> - assert((count & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); >> + if (!QEMU_IS_ALIGNED(offset | count, BDRV_SECTOR_SIZE)) { Again, works because this is a power of 2. >> + return -ENOTSUP; >> + } >=20 > Out of interest: Where does sheepdog tell the block layer that requests= > have to be aligned to this value? It's Magic ! Don't tell anyone that I told you :) Actually, it's because sheepdog still uses .bdrv_co_readv (sector-based), and not .bdrv_co_preadv (byte-based), so the block layer automatically sets bs->bl.request_alignment to BDRV_SECTOR_SIZE for sheepdog and all other old-school drivers. The block layer then treats bs->bl.request_alignment as the very minimum that can be changed in the image at a time, so it only makes sense that sheepdog can't react to a discard request aligned below those limits. This code is weakening from an assertion to an early error return, and then 5/9 is what starts calling the code even with something aligned smaller than a sector. Someday the sheepdog driver may be relaxed to implement byte-based callbacks, and then we may want to delete the early error return of -ENOTSUP for requests smaller than 512; but that depends on whether sheepdog uses bytes or sectors over the wire. >=20 > With this patch, it doesn't matter though, it only did before, so: >=20 > Reviewed-by: Max Reitz >=20 >> acb =3D sd_aio_setup(bs, &discard_iov, offset >> BDRV_SECTOR_BITS= , >> count >> BDRV_SECTOR_BITS); >> acb->aiocb_type =3D AIOCB_DISCARD_OBJ; >> >=20 >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --Wm2k0PXR23qv6kiiqjhAC8tbd11gkD30e 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 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJYL4VSAAoJEKeha0olJ0NqZC8H/22fj3NYnwaOBULSPOntVT7R jDLUx+2/2JI5zAWNXKUMgkkpbTdmTJEMM2gnbzmdeAfg/hHitMruESV7X9KnaEc2 SFNF+gpYDHG2c/hB1bhULZM773rnj9XZk0vm7nAcOkvRfR055PW/XL/k8Vuz0lkU CO88qqH3cHrXHqjNnYs+jUxAo4gTiRMQLc8ELmlIHOPP3JICJf6ieEsAMWXQlmko P5nD5s7s00tSKdaYjqKLU60HqBG47U1EtROcFx6hS92G4z7hqX4PPXa0rM5eVSEF qD/EVdF27pLQMElx/AvQhQ+fdSJG+9zRU8t0H+60SUUuFj4r7Kr0sOsbze5fUM0= =fBk3 -----END PGP SIGNATURE----- --Wm2k0PXR23qv6kiiqjhAC8tbd11gkD30e--