From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57684) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VMkoF-00047T-Oh for qemu-devel@nongnu.org; Thu, 19 Sep 2013 16:26:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VMkoB-0004zS-8M for qemu-devel@nongnu.org; Thu, 19 Sep 2013 16:26:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34925) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VMkoB-0004zD-0q for qemu-devel@nongnu.org; Thu, 19 Sep 2013 16:26:39 -0400 Message-ID: <523B5DF6.4000907@redhat.com> Date: Thu, 19 Sep 2013 14:26:30 -0600 From: Eric Blake MIME-Version: 1.0 References: <1379425736-11326-1-git-send-email-pl@kamp.de> <1379425736-11326-14-git-send-email-pl@kamp.de> In-Reply-To: <1379425736-11326-14-git-send-email-pl@kamp.de> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="6TnNMF66FlqJVIARtAsv0wtT68WHDU4WI" Subject: Re: [Qemu-devel] [PATCHv2 13/20] block: introduce bdrv_zeroize List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Lieven Cc: kwolf@redhat.com, ronniesahlberg@gmail.com, stefanha@redhat.com, qemu-devel@nongnu.org, anthony@codemonkey.ws, pbonzini@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --6TnNMF66FlqJVIARtAsv0wtT68WHDU4WI Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 09/17/2013 07:48 AM, Peter Lieven wrote: > this patch adds a call to completely zero out a block device. > the operation is sped up by checking the block status and > only writing zeroes to the device if they currently do not > return zeroes. optionally the zero writing can be sped up > by setting the flag BDRV_REQ_MAY_UNMAP to emulate the zero > write by unmapping if the driver supports it. >=20 > Signed-off-by: Peter Lieven > --- > block.c | 30 ++++++++++++++++++++++++++++++ > include/block/block.h | 1 + > 2 files changed, 31 insertions(+) >=20 > diff --git a/block.c b/block.c > index ecc5be4..88b137c 100644 > --- a/block.c > +++ b/block.c > @@ -2342,6 +2342,36 @@ int bdrv_write_zeroes(BlockDriverState *bs, int6= 4_t sector_num, > BDRV_REQ_ZERO_WRITE | flags); > } > =20 > +int bdrv_zeroize(BlockDriverState *bs, BdrvRequestFlags flags) Please add documentation in the code base about what this function does, and what return values mean. (Bad practice in the past doesn't excuse new patches from being more maintainer-friendly) > +{ > + int64_t target_size =3D bdrv_getlength(bs) / BDRV_SECTOR_SIZE; > + int64_t ret, nb_sectors, sector_num =3D 0; > + int n; > + /* split the write requests into 1MB chunks if the driver > + * does not return a maximal size via bdi */ > + for (;;) { > + nb_sectors =3D target_size - sector_num; > + if (nb_sectors <=3D 0) { > + return 0; > + } > + if (nb_sectors > INT_MAX) { > + nb_sectors =3D INT_MAX; > + } > + ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, &n);= > + if (ret & BDRV_BLOCK_ZERO) { > + sector_num +=3D n; > + continue; > + } > + ret =3D bdrv_write_zeroes(bs, sector_num, n, flags & BDRV_REQ_= MAY_UNMAP); Is this intentionally throwing away all other flags except BDRV_REQ_MAY_UNMAP? --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --6TnNMF66FlqJVIARtAsv0wtT68WHDU4WI Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJSO133AAoJEKeha0olJ0NqJoMH/jQvFpvxPIcfNVYm6xtack1o ti8x3VpGerFOFuSCn6KhrF1qZZU9LQ9nhC36oPVnI3gato9CFO0EFX3XFEMFoxYK vCHnmIU6/bbUSTa6LTyZrgh9CotwFDdX5szH3UfVACQwgPsCpfiwxiHMOfYdOGg1 bAbiyBut4PkHgNjZp8R2X30mCwStoS3Uhw3ekZ83oM9ktPE75DVxEobVdhrTMJEX SOME/twa+pm2G4j0MhtbanLMRimUbVNIMGlBxpyGyLkgBdUTi9EPHBtbTDE8AEyO eyIXpXqCgCVqF3G6xryV1P4kOjNTEJ41XdOJn4q6+Rknm+WtMwkc9gO6INd1OHA= =W/4/ -----END PGP SIGNATURE----- --6TnNMF66FlqJVIARtAsv0wtT68WHDU4WI--