From patchwork Fri Jan 13 20:52:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 9516385 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 914C360761 for ; Fri, 13 Jan 2017 20:53:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BFA528781 for ; Fri, 13 Jan 2017 20:53:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F0DF28784; Fri, 13 Jan 2017 20:53:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F40D728781 for ; Fri, 13 Jan 2017 20:53:27 +0000 (UTC) Received: from localhost ([::1]:45178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cS8ql-0002Dt-1r for patchwork-qemu-devel@patchwork.kernel.org; Fri, 13 Jan 2017 15:53:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cS8qA-00029x-T0 for qemu-devel@nongnu.org; Fri, 13 Jan 2017 15:52:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cS8q9-0001sw-4A for qemu-devel@nongnu.org; Fri, 13 Jan 2017 15:52:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35900) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cS8q5-0001nQ-Nw; Fri, 13 Jan 2017 15:52:45 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 CAB7D61BA6; Fri, 13 Jan 2017 20:52:45 +0000 (UTC) Received: from localhost (ovpn-116-36.ams2.redhat.com [10.36.116.36]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0DKqi7f025516 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 13 Jan 2017 15:52:45 -0500 From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 13 Jan 2017 21:52:30 +0100 Message-Id: <20170113205237.30386-3-mreitz@redhat.com> In-Reply-To: <20170113205237.30386-1-mreitz@redhat.com> References: <20170113205237.30386-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 13 Jan 2017 20:52:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 2/9] block: Change bdrv_get_encrypted_filename() 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: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of returning a pointer to the filename, g_strdup() it. This will become necessary once we do not have BlockDriverState.filename anymore. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf --- include/block/block.h | 2 +- block.c | 17 ++++++++++------- monitor.c | 5 ++++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 7bcbd05338..3425e9fa79 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -432,7 +432,7 @@ void bdrv_round_to_clusters(BlockDriverState *bs, int64_t *cluster_offset, unsigned int *cluster_bytes); -const char *bdrv_get_encrypted_filename(BlockDriverState *bs); +char *bdrv_get_encrypted_filename(BlockDriverState *bs); void bdrv_get_backing_filename(BlockDriverState *bs, char *filename, int filename_size); char *bdrv_get_full_backing_filename(BlockDriverState *bs, Error **errp); diff --git a/block.c b/block.c index c63fc1b2da..95015251d5 100644 --- a/block.c +++ b/block.c @@ -2858,10 +2858,12 @@ void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp) } } else { if (bdrv_key_required(bs)) { + char *enc_filename = bdrv_get_encrypted_filename(bs); error_set(errp, ERROR_CLASS_DEVICE_ENCRYPTED, "'%s' (%s) is encrypted", bdrv_get_device_or_node_name(bs), - bdrv_get_encrypted_filename(bs)); + enc_filename ?: ""); + g_free(enc_filename); } } } @@ -3111,14 +3113,15 @@ bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs) return false; } -const char *bdrv_get_encrypted_filename(BlockDriverState *bs) +char *bdrv_get_encrypted_filename(BlockDriverState *bs) { - if (bs->backing && bs->backing->bs->encrypted) - return bs->backing_file; - else if (bs->encrypted) - return bs->filename; - else + if (bs->backing && bs->backing->bs->encrypted) { + return g_strdup(bs->backing_file); + } else if (bs->encrypted) { + return g_strdup(bs->filename); + } else { return NULL; + } } void bdrv_get_backing_filename(BlockDriverState *bs, diff --git a/monitor.c b/monitor.c index 0841d436b0..bb3000a2df 100644 --- a/monitor.c +++ b/monitor.c @@ -4056,10 +4056,13 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, BlockCompletionFunc *completion_cb, void *opaque) { + char *enc_filename; int err; + enc_filename = bdrv_get_encrypted_filename(bs); monitor_printf(mon, "%s (%s) is encrypted.\n", bdrv_get_device_name(bs), - bdrv_get_encrypted_filename(bs)); + enc_filename ?: ""); + g_free(enc_filename); mon->password_completion_cb = completion_cb; mon->password_opaque = opaque;