From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43910) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bru6Z-00013c-2m for qemu-devel@nongnu.org; Wed, 05 Oct 2016 17:52:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bru6T-0001Cr-TT for qemu-devel@nongnu.org; Wed, 05 Oct 2016 17:51:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34808) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bru6T-0001Cj-JZ for qemu-devel@nongnu.org; Wed, 05 Oct 2016 17:51:53 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 156658F29E for ; Wed, 5 Oct 2016 21:51:53 +0000 (UTC) References: <8a31654cb182932db78b95aae1e904fc2bd1c465.1475698895.git.tgolembi@redhat.com> From: Eric Blake Message-ID: <647a7dd0-9d4c-aa40-ed8a-6e8d63214e86@redhat.com> Date: Wed, 5 Oct 2016 16:51:51 -0500 MIME-Version: 1.0 In-Reply-To: <8a31654cb182932db78b95aae1e904fc2bd1c465.1475698895.git.tgolembi@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="x1TIcIlg3D7MefuMAPRSOiNxaaMc6biqP" Subject: Re: [Qemu-devel] [PATCH v2] qemu-nbd: Shrink image size by specified offset List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?B?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= , Paolo Bonzini , qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --x1TIcIlg3D7MefuMAPRSOiNxaaMc6biqP From: Eric Blake To: =?UTF-8?B?VG9tw6HFoSBHb2xlbWJpb3Zza8O9?= , Paolo Bonzini , qemu-devel@nongnu.org Message-ID: <647a7dd0-9d4c-aa40-ed8a-6e8d63214e86@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2] qemu-nbd: Shrink image size by specified offset References: <8a31654cb182932db78b95aae1e904fc2bd1c465.1475698895.git.tgolembi@redhat.com> In-Reply-To: <8a31654cb182932db78b95aae1e904fc2bd1c465.1475698895.git.tgolembi@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/05/2016 04:40 PM, Tom=C3=A1=C5=A1 Golembiovsk=C3=BD wrote: > When --offset is set the apparent device size has to be adjusted > accordingly. Otherwise client may request read/write beyond the file en= d > which would fail. >=20 > Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD > --- > qemu-nbd.c | 8 ++++++++ > 1 file changed, 8 insertions(+) Reviewed-by: Eric Blake >=20 > diff --git a/qemu-nbd.c b/qemu-nbd.c > index 99297a5..705b95e 100644 > --- a/qemu-nbd.c > +++ b/qemu-nbd.c > @@ -901,6 +901,14 @@ int main(int argc, char **argv) > exit(EXIT_FAILURE); > } > =20 > + if (dev_offset >=3D fd_size) { > + error_report("Offset (%lld) has to be smaller than the image s= ize " > + "(%lld)", > + (long long int)dev_offset, (long long int)fd_size= ); > + exit(EXIT_FAILURE); > + } > + fd_size -=3D dev_offset; > + > if (partition !=3D -1) { > ret =3D find_partition(blk, partition, &dev_offset, &fd_size);= > if (ret < 0) { >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --x1TIcIlg3D7MefuMAPRSOiNxaaMc6biqP 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/ iQEcBAEBCAAGBQJX9XX4AAoJEKeha0olJ0NqzYMH/3M7Qobqgaal4+gwGVc9xvs/ /dmFs4Oxm4h4PRltFVPzBZPVDu3kGuPeKlZkHepsYCPtRySeesxm4pJLGVy4y8J6 hp4LT2Z2tDU95LE6bcgi8MCwPCED7SKoXUUEiTTESFIxjyvpB19JQqLG/xJBelS/ PfXM7SSuv6u87LTwrKGieGXbj/FVjQsrqcm5jlLiAWj45HbbgUT/PjTp+fAXgQ1O ltJH3CfZHXPmBJ9nWVj2O6GzPO2q1qjvpJnqHQ9a6l8xarsRVURYKkA6eyRvHiB0 TLkER1nKo++cqneqYbbYMtzbQBhwA+MTsuxj0u4JsV7SwZzkC1wOVIiSXoAIHNU= =JY9K -----END PGP SIGNATURE----- --x1TIcIlg3D7MefuMAPRSOiNxaaMc6biqP--