Received: from eggs.gnu.org ([2001:4830:134:3::10]:45141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCqQU-0003g7-BQ for qemu-devel@nongnu.org; Tue, 14 Jun 2016 11:38:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCqQQ-0006db-0p for qemu-devel@nongnu.org; Tue, 14 Jun 2016 11:38:50 -0400 References: <1465901813-510-1-git-send-email-berrange@redhat.com> <1465901813-510-3-git-send-email-berrange@redhat.com> From: Max Reitz Message-ID: <05bbe389-cb31-6084-7c94-662353e367d2@redhat.com> Date: Tue, 14 Jun 2016 17:38:36 +0200 MIME-Version: 1.0 In-Reply-To: <1465901813-510-3-git-send-email-berrange@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="22wXTB9JKc7QxHpeVk8iDqu5unoWT2sqP" Subject: Re: [Qemu-devel] [PATCH v2 2/2] block: export LUKS specific data to qemu-img info List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Eric Blake , qemu-block@nongnu.org, Kevin Wolf This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --22wXTB9JKc7QxHpeVk8iDqu5unoWT2sqP From: Max Reitz To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Eric Blake , qemu-block@nongnu.org, Kevin Wolf Message-ID: <05bbe389-cb31-6084-7c94-662353e367d2@redhat.com> Subject: Re: [PATCH v2 2/2] block: export LUKS specific data to qemu-img info References: <1465901813-510-1-git-send-email-berrange@redhat.com> <1465901813-510-3-git-send-email-berrange@redhat.com> In-Reply-To: <1465901813-510-3-git-send-email-berrange@redhat.com> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable On 14.06.2016 12:56, Daniel P. Berrange wrote: > The qemu-img info command has the ability to expose format > specific metadata about volumes. Wire up this facility for > the LUKS driver to report on cipher configuration and key > slot usage. >=20 > $ qemu-img info ~/VirtualMachines/demo.luks > image: /home/berrange/VirtualMachines/demo.luks > file format: luks > virtual size: 98M (102760448 bytes) > disk size: 100M > encrypted: yes > Format specific information: > ivgen alg: plain64 > hash alg: sha1 > cipher alg: aes-128 > uuid: 6ddee74b-3a22-408c-8909-6789d4fa2594 > cipher mode: xts > slots: > [0]: > active: true > iters: 572706 > key offset: 4096 > stripes: 4000 > [1]: > active: false > key offset: 135168 > [2]: > active: false > key offset: 266240 > [3]: > active: false > key offset: 397312 > [4]: > active: false > key offset: 528384 > [5]: > active: false > key offset: 659456 > [6]: > active: false > key offset: 790528 > [7]: > active: false > key offset: 921600 > payload offset: 2097152 > master key iters: 142375 >=20 > One somewhat undesirable artifact is that the data fields are > printed out in (apparently) random order. This will be addressed > later by changing the way the block layer pretty-prints the > image specific data. >=20 > Signed-off-by: Daniel P. Berrange > --- > block/crypto.c | 59 ++++++++++++++++++++++++++++++++++++++++++++= ++++++++ > qapi/block-core.json | 7 ++++++- > 2 files changed, 65 insertions(+), 1 deletion(-) >=20 > diff --git a/block/crypto.c b/block/crypto.c > index 758e14e..823572f 100644 > --- a/block/crypto.c > +++ b/block/crypto.c > @@ -565,6 +565,63 @@ static int block_crypto_create_luks(const char *fi= lename, > filename, opts, errp); > } > =20 > +static int block_crypto_get_info_luks(BlockDriverState *bs, > + BlockDriverInfo *bdi) > +{ > + BlockDriverInfo subbdi; > + int ret; > + > + ret =3D bdrv_get_info(bs->file->bs, &subbdi); > + if (ret !=3D 0) { > + return ret; > + } > + > + bdi->unallocated_blocks_are_zero =3D false; > + bdi->can_write_zeroes_with_unmap =3D false; > + bdi->cluster_size =3D subbdi.cluster_size; > + > + return 0; > +} > + > +static ImageInfoSpecific * > +block_crypto_get_specific_info_luks(BlockDriverState *bs) > +{ > + BlockCrypto *crypto =3D bs->opaque; > + ImageInfoSpecific *spec_info; > + QCryptoBlockInfo *info; > + > + info =3D qcrypto_block_get_info(crypto->block, NULL); > + if (!info) { > + return NULL; > + } > + if (info->format !=3D Q_CRYPTO_BLOCK_FORMAT_LUKS) { > + qapi_free_QCryptoBlockInfo(info); > + return NULL; > + } > + > + spec_info =3D g_new(ImageInfoSpecific, 1); > + spec_info->type =3D IMAGE_INFO_SPECIFIC_KIND_LUKS; One space too many. > + spec_info->u.luks.data =3D g_new(QCryptoBlockInfoLUKS, 1); > + spec_info->u.luks.data->cipher_alg =3D info->u.luks.cipher_alg; > + spec_info->u.luks.data->cipher_mode =3D info->u.luks.cipher_mode; > + spec_info->u.luks.data->ivgen_alg =3D info->u.luks.ivgen_alg; > + spec_info->u.luks.data->has_ivgen_hash_alg =3D > + info->u.luks.has_ivgen_hash_alg; > + spec_info->u.luks.data->ivgen_hash_alg =3D info->u.luks.ivgen_hash= _alg; > + spec_info->u.luks.data->hash_alg =3D info->u.luks.hash_alg; > + spec_info->u.luks.data->payload_offset =3D info->u.luks.payload_of= fset; > + spec_info->u.luks.data->master_key_iters =3D info->u.luks.master_k= ey_iters; > + spec_info->u.luks.data->uuid =3D g_strdup(info->u.luks.uuid); > + > + /* Steal the pointer instead of bothering to copy */ > + spec_info->u.luks.data->slots =3D info->u.luks.slots; > + info->u.luks.slots =3D NULL; Why not just steal everything by *spec_info->u.luks.data =3D info->u.luks= and then making sure the qapi_free() call below won't free anything in there with a memset(&info->u.luks, 0, sizeof(info->u.luks))? > + > + qapi_free_QCryptoBlockInfo(info); > + > + return spec_info; > +} > + > BlockDriver bdrv_crypto_luks =3D { > .format_name =3D "luks", > .instance_size =3D sizeof(BlockCrypto), > @@ -578,6 +635,8 @@ BlockDriver bdrv_crypto_luks =3D { > .bdrv_co_readv =3D block_crypto_co_readv, > .bdrv_co_writev =3D block_crypto_co_writev, > .bdrv_getlength =3D block_crypto_getlength, > + .bdrv_get_info =3D block_crypto_get_info_luks, > + .bdrv_get_specific_info =3D block_crypto_get_specific_info_luks, > }; > =20 > static void block_crypto_init(void) > diff --git a/qapi/block-core.json b/qapi/block-core.json > index 98a20d2..959dd8b 100644 > --- a/qapi/block-core.json > +++ b/qapi/block-core.json > @@ -74,6 +74,7 @@ > 'extents': ['ImageInfo'] > } } > =20 > + > ## > # @ImageInfoSpecific: > # This hunk looks unnecessary. Max > @@ -85,7 +86,11 @@ > { 'union': 'ImageInfoSpecific', > 'data': { > 'qcow2': 'ImageInfoSpecificQCow2', > - 'vmdk': 'ImageInfoSpecificVmdk' > + 'vmdk': 'ImageInfoSpecificVmdk', > + # If we need to add block driver specific parameters for > + # LUKS in future, then we'll subclass QCryptoBlockInfoLUKS > + # to define a ImageInfoSpecificLUKS > + 'luks': 'QCryptoBlockInfoLUKS' > } } > =20 > ## >=20 --22wXTB9JKc7QxHpeVk8iDqu5unoWT2sqP 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 iQEcBAEBCAAGBQJXYCT8AAoJEDuxQgLoOKyt1zIH/1zFhek5v7Jecu6Eg8Unazrz 9ifNLtwS/N21mJrnOtRQ+hXbe8Yp/VY7AARLlv40a9YiHXO3hB2kMj/XmMbRuWSa EmWiW/UcT/DxOO/QlT+zsdzMSIcHiPdwT3mYLQtZ2QzIXIsflP8iHaoOeDSUfAYq 7piKjlBh3buJa4z45bZNXwWayBVyYQJzPQ1jWv7LpUvzK+ZcrOLqN2Fe1142ntnB V2Prgwl5eEPpK9/tZGZmnsDnXepX6Tb4SBLEcseMbfrHW4TVGfDZEwqpr7D6F6Hg YvdQYSCi6jQCG1a8K/hy1laIMjl9jxOSes8FV7jATEDtPp5ELH3OnhGoN3YUO8E= =NTBw -----END PGP SIGNATURE----- --22wXTB9JKc7QxHpeVk8iDqu5unoWT2sqP--