From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5WWQ-000099-5T for qemu-devel@nongnu.org; Wed, 25 May 2016 06:58:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5WWP-0002Gf-2D for qemu-devel@nongnu.org; Wed, 25 May 2016 06:58:42 -0400 References: <1464151079-4341-1-git-send-email-eblake@redhat.com> <18efe9a1-d22c-fa23-66c5-64cc7db0ff02@redhat.com> From: Eric Blake Message-ID: <57458559.1070204@redhat.com> Date: Wed, 25 May 2016 04:58:33 -0600 MIME-Version: 1.0 In-Reply-To: <18efe9a1-d22c-fa23-66c5-64cc7db0ff02@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="erpxdsWeQWTIJDimWexKOCabPioCxewku" Subject: Re: [Qemu-devel] [PATCH] nbd: Don't trim unrequested bytes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini , qemu-devel@nongnu.org Cc: kwolf@redhat.com, qemu-stable@nongnu.org, qemu-block@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --erpxdsWeQWTIJDimWexKOCabPioCxewku Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 05/25/2016 02:31 AM, Paolo Bonzini wrote: >=20 >=20 > On 25/05/2016 06:37, Eric Blake wrote: >> Similar to commit df7b97ff, we are mishandling clients that >> give an unaligned NBD_CMD_TRIM request, and potentially >> trimming bytes that occur before their request; which in turn >> can cause potential unintended data loss (unlikely in >> practice, since most clients are sane and issue aligned trim >> requests). However, while we fixed read and write by switching >> to the byte interfaces of blk_, we don't yet have a byte >> interface for discard. On the other hand, trim is advisory, so >> rounding the user's request to simply ignore the first and last >> unaligned sectors (or the entire request, if it is sub-sector >> in length) is just fine. >> >> CC: qemu-stable@nongnu.org >> Signed-off-by: Eric Blake >> --- >> nbd/server.c | 8 ++++++-- >> 1 file changed, 6 insertions(+), 2 deletions(-) >> >> diff --git a/nbd/server.c b/nbd/server.c >> index fa862cd..5aed8db 100644 >> --- a/nbd/server.c >> +++ b/nbd/server.c >> @@ -1153,8 +1153,12 @@ static void nbd_trip(void *opaque) >> break; >> case NBD_CMD_TRIM: >> TRACE("Request type is TRIM"); >> - ret =3D blk_co_discard(exp->blk, (request.from + exp->dev_off= set) >> - / BDRV_SECTOR_SIZE, >> + /* Ignore unaligned head or tail, until block layer adds byte= >> + * interface */ >> + request.len -=3D (request.from + request.len) % BDRV_SECTOR_S= IZE; Gaaah - this version can underflow request.len. v2 coming up. > Thanks, queued for 2.7. Fortunately, rebasing a staging queue is easier than dealing with an incorrect pull request. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --erpxdsWeQWTIJDimWexKOCabPioCxewku 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/ iQEcBAEBCAAGBQJXRYVZAAoJEKeha0olJ0NqOY8H/06src/4H7NjVFyHOypWZVsN zLwP2El51p4boZhN+fPsed5gX1d3I/1W74pxVcF6nX6Iq+iiXBwk2KdqIUfBzBPv 2xoSOrn5LTwm0/8TSsq76ogt6fVmZhYovcRFpnthfgn9kkZbr4/yRH3X09JuRv/W Ab6eL/N0gAkXi1qgFfOtbToQixzTFXG8AGxAdFisu3CGHeg4lv5xlYHIJv5hsh7L yBzvb6grn6LEIT0+qvNrFW5tfuyTRLh383L5FcbY4t0hv4FiVVpWJLt1l2/BUVcX /E2e9BhA3LQLQW8qMpgD5RYbpIrsHL9vxH9YLLh6OufJE9NzPkLf/dSvR1f4kyk= =3e1g -----END PGP SIGNATURE----- --erpxdsWeQWTIJDimWexKOCabPioCxewku--