From patchwork Fri Jul 27 21:31:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 173815 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4D8782C0086 for ; Sat, 28 Jul 2012 08:46:38 +1000 (EST) Received: from localhost ([::1]:35905 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sus95-00080H-6f for incoming@patchwork.ozlabs.org; Fri, 27 Jul 2012 17:32:27 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sus8Y-0006ie-2i for qemu-devel@nongnu.org; Fri, 27 Jul 2012 17:31:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sus8X-0008Aj-3K for qemu-devel@nongnu.org; Fri, 27 Jul 2012 17:31:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57431) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sus8W-0008AU-QP for qemu-devel@nongnu.org; Fri, 27 Jul 2012 17:31:53 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6RLVqQI019733 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 27 Jul 2012 17:31:52 -0400 Received: from localhost (ovpn-113-90.phx2.redhat.com [10.3.113.90]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q6RLVp3g014308; Fri, 27 Jul 2012 17:31:51 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 27 Jul 2012 18:31:53 -0300 Message-Id: <1343424728-22461-13-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1343424728-22461-1-git-send-email-lcapitulino@redhat.com> References: <1343424728-22461-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, pbonzini@redhat.com, aliguori@us.ibm.com, eblake@redhat.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 12/27] hmp: hmp_change(): don't use error_get_field() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use the 'device' passed by the user and call qmp_query_block() to get the 'filename' info. error_get_field() is going to be dropped by a future commit. Signed-off-by: Luiz Capitulino --- hmp.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/hmp.c b/hmp.c index a906f8a..435c9cd 100644 --- a/hmp.c +++ b/hmp.c @@ -783,17 +783,35 @@ static void hmp_change_read_arg(Monitor *mon, const char *password, static void cb_hmp_change_bdrv_pwd(Monitor *mon, const char *password, void *opaque) { - Error *encryption_err = opaque; + char *device = opaque; Error *err = NULL; - const char *device; - - device = error_get_field(encryption_err, "device"); qmp_block_passwd(device, password, &err); hmp_handle_error(mon, &err); - error_free(encryption_err); monitor_read_command(mon, 1); + g_free(device); +} + +static char *get_device_file(const char *device) +{ + BlockInfoList *bdev_list, *bdev; + char *ret; + + bdev_list = qmp_query_block(NULL); + for (bdev = bdev_list; bdev; bdev = bdev->next) { + if (!strcmp(bdev->value->device, device)) { + break; + } + } + + assert(bdev); + assert(bdev->value->has_inserted); + + ret = g_strdup(bdev->value->inserted->file); + qapi_free_BlockInfoList(bdev_list); + + return ret; } void hmp_change(Monitor *mon, const QDict *qdict) @@ -814,9 +832,9 @@ void hmp_change(Monitor *mon, const QDict *qdict) qmp_change(device, target, !!arg, arg, &err); if (error_is_type(err, QERR_DEVICE_ENCRYPTED)) { - monitor_printf(mon, "%s (%s) is encrypted.\n", - error_get_field(err, "device"), - error_get_field(err, "filename")); + char *filename = get_device_file(device); + monitor_printf(mon, "%s (%s) is encrypted.\n", device, filename); + g_free(filename); if (!monitor_get_rs(mon)) { monitor_printf(mon, "terminal does not support password prompting\n"); @@ -824,9 +842,10 @@ void hmp_change(Monitor *mon, const QDict *qdict) return; } readline_start(monitor_get_rs(mon), "Password: ", 1, - cb_hmp_change_bdrv_pwd, err); + cb_hmp_change_bdrv_pwd, (void *) g_strdup(device)); return; } + hmp_handle_error(mon, &err); }