From patchwork Tue Jan 12 11:43:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 566498 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 22D0B140B96 for ; Tue, 12 Jan 2016 22:45:07 +1100 (AEDT) Received: from localhost ([::1]:59303 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIxNo-00027v-TS for incoming@patchwork.ozlabs.org; Tue, 12 Jan 2016 06:45:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45293) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIxNH-00010L-LX for qemu-devel@nongnu.org; Tue, 12 Jan 2016 06:44:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIxNF-000483-QQ for qemu-devel@nongnu.org; Tue, 12 Jan 2016 06:44:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51436) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIxNF-00047z-LV for qemu-devel@nongnu.org; Tue, 12 Jan 2016 06:44:29 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 39E7942E5C2 for ; Tue, 12 Jan 2016 11:44:29 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (vpn1-7-155.ams2.redhat.com [10.36.7.155]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0CBiQA0011644; Tue, 12 Jan 2016 06:44:27 -0500 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Tue, 12 Jan 2016 11:43:55 +0000 Message-Id: <1452599056-27357-2-git-send-email-berrange@redhat.com> In-Reply-To: <1452599056-27357-1-git-send-email-berrange@redhat.com> References: <1452599056-27357-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Amit Shah , "Dr. David Alan Gilbert" , Juan Quintela Subject: [Qemu-devel] [PATCH v1 01/22] s390: use FILE instead of QEMUFile for creating text file 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 The s390 skeys monitor command needs to write out a plain text file. Currently it is using the QEMUFile class for this. There is no real benefit to this, and the downside is that it needs to snprintf via an intermediate buffer. Switching to regular FILE objects simplifies the code. Signed-off-by: Daniel P. Berrange Reviewed-by: Dr. David Alan Gilbert --- hw/s390x/s390-skeys.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index 539ef6d..637ccf5 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -45,15 +45,11 @@ void s390_skeys_init(void) qdev_init_nofail(DEVICE(obj)); } -static void write_keys(QEMUFile *f, uint8_t *keys, uint64_t startgfn, +static void write_keys(FILE *f, uint8_t *keys, uint64_t startgfn, uint64_t count, Error **errp) { uint64_t curpage = startgfn; uint64_t maxpage = curpage + count - 1; - const char *fmt = "page=%03" PRIx64 ": key(%d) => ACC=%X, FP=%d, REF=%d," - " ch=%d, reserved=%d\n"; - char buf[128]; - int len; for (; curpage <= maxpage; curpage++) { uint8_t acc = (*keys & 0xF0) >> 4; @@ -62,10 +58,9 @@ static void write_keys(QEMUFile *f, uint8_t *keys, uint64_t startgfn, int ch = (*keys & 0x02); int res = (*keys & 0x01); - len = snprintf(buf, sizeof(buf), fmt, curpage, - *keys, acc, fp, ref, ch, res); - assert(len < sizeof(buf)); - qemu_put_buffer(f, (uint8_t *)buf, len); + fprintf(f, "page=%03" PRIx64 ": key(%d) => ACC=%X, FP=%d, REF=%d," + " ch=%d, reserved=%d\n", + curpage, *keys, acc, fp, ref, ch, res); keys++; } } @@ -115,7 +110,7 @@ void qmp_dump_skeys(const char *filename, Error **errp) vaddr cur_gfn = 0; uint8_t *buf; int ret; - QEMUFile *f; + FILE *f; /* Quick check to see if guest is using storage keys*/ if (!skeyclass->skeys_enabled(ss)) { @@ -124,7 +119,7 @@ void qmp_dump_skeys(const char *filename, Error **errp) return; } - f = qemu_fopen(filename, "wb"); + f = fopen(filename, "wb"); if (!f) { error_setg_file_open(errp, errno, filename); return; @@ -161,7 +156,7 @@ out_free: error_propagate(errp, lerr); g_free(buf); out: - qemu_fclose(f); + fclose(f); } static void qemu_s390_skeys_init(Object *obj)