From patchwork Tue Jul 19 22:47:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 650491 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rvFZq6JRnz9sf9 for ; Wed, 20 Jul 2016 08:48:51 +1000 (AEST) Received: from localhost ([::1]:59431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPdon-00055K-Ix for incoming@patchwork.ozlabs.org; Tue, 19 Jul 2016 18:48:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPdnk-0004Ky-9w for qemu-devel@nongnu.org; Tue, 19 Jul 2016 18:47:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPdnj-0000nk-9L for qemu-devel@nongnu.org; Tue, 19 Jul 2016 18:47:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51029) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPdnj-0000ng-0y for qemu-devel@nongnu.org; Tue, 19 Jul 2016 18:47:43 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 90B8F12B28; Tue, 19 Jul 2016 22:47:42 +0000 (UTC) Received: from localhost (ovpn-116-40.phx2.redhat.com [10.3.116.40]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6JMleaa009192 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 19 Jul 2016 18:47:42 -0400 From: Max Reitz To: qemu-devel@nongnu.org Date: Wed, 20 Jul 2016 00:47:30 +0200 Message-Id: <20160719224730.6948-5-mreitz@redhat.com> In-Reply-To: <20160719224730.6948-1-mreitz@redhat.com> References: <20160719224730.6948-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 19 Jul 2016 22:47:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/4] block: export LUKS specific data to qemu-img info X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Daniel P. Berrange" 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. $ 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 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. Signed-off-by: Daniel P. Berrange Message-id: 1465921477-9005-3-git-send-email-berrange@redhat.com Reviewed-by: Max Reitz Signed-off-by: Max Reitz --- block/crypto.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ qapi/block-core.json | 6 +++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/block/crypto.c b/block/crypto.c index 7eaa057..7f61e12 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -563,6 +563,53 @@ static int block_crypto_create_luks(const char *filename, filename, opts, errp); } +static int block_crypto_get_info_luks(BlockDriverState *bs, + BlockDriverInfo *bdi) +{ + BlockDriverInfo subbdi; + int ret; + + ret = bdrv_get_info(bs->file->bs, &subbdi); + if (ret != 0) { + return ret; + } + + bdi->unallocated_blocks_are_zero = false; + bdi->can_write_zeroes_with_unmap = false; + bdi->cluster_size = subbdi.cluster_size; + + return 0; +} + +static ImageInfoSpecific * +block_crypto_get_specific_info_luks(BlockDriverState *bs) +{ + BlockCrypto *crypto = bs->opaque; + ImageInfoSpecific *spec_info; + QCryptoBlockInfo *info; + + info = qcrypto_block_get_info(crypto->block, NULL); + if (!info) { + return NULL; + } + if (info->format != Q_CRYPTO_BLOCK_FORMAT_LUKS) { + qapi_free_QCryptoBlockInfo(info); + return NULL; + } + + spec_info = g_new(ImageInfoSpecific, 1); + spec_info->type = IMAGE_INFO_SPECIFIC_KIND_LUKS; + spec_info->u.luks.data = g_new(QCryptoBlockInfoLUKS, 1); + *spec_info->u.luks.data = info->u.luks; + + /* Blank out pointers we've just stolen to avoid double free */ + memset(&info->u.luks, 0, sizeof(info->u.luks)); + + qapi_free_QCryptoBlockInfo(info); + + return spec_info; +} + BlockDriver bdrv_crypto_luks = { .format_name = "luks", .instance_size = sizeof(BlockCrypto), @@ -576,6 +623,8 @@ BlockDriver bdrv_crypto_luks = { .bdrv_co_readv = block_crypto_co_readv, .bdrv_co_writev = block_crypto_co_writev, .bdrv_getlength = block_crypto_getlength, + .bdrv_get_info = block_crypto_get_info_luks, + .bdrv_get_specific_info = block_crypto_get_specific_info_luks, }; static void block_crypto_init(void) diff --git a/qapi/block-core.json b/qapi/block-core.json index 3444a9b..8d1913d 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -85,7 +85,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' } } ##