From patchwork Thu May 26 06:11:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 626560 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 3rFf8m6FB6z9t3q for ; Thu, 26 May 2016 16:18:16 +1000 (AEST) Received: from localhost ([::1]:36577 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5ocY-0001eU-Hh for incoming@patchwork.ozlabs.org; Thu, 26 May 2016 02:18:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5oX9-00055y-I3 for qemu-devel@nongnu.org; Thu, 26 May 2016 02:12:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5oX3-0008HQ-CR for qemu-devel@nongnu.org; Thu, 26 May 2016 02:12:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56687) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5oX3-0008Gh-4k for qemu-devel@nongnu.org; Thu, 26 May 2016 02:12:33 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 A44B66331A; Thu, 26 May 2016 06:12:32 +0000 (UTC) Received: from localhost (ovpn-116-25.sin2.redhat.com [10.67.116.25]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4Q6CVDg028712; Thu, 26 May 2016 02:12:32 -0400 From: Amit Shah To: Peter Maydell Date: Thu, 26 May 2016 11:41:52 +0530 Message-Id: <1fd791f007821e2510899e60be0ddad3077120e3.1464242913.git.amit.shah@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 26 May 2016 06:12:32 +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 01/28] s390: use FILE instead of QEMUFile for creating text file 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: qemu list , Amit Shah , "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Daniel P. Berrange" The s390 skeys monitor command needs to write out a plain text file. Currently it is using the QEMUFile class for this, but work is ongoing to refactor QEMUFile and eliminate much code related to it. The only feature qemu_fopen() gives over fopen() is support for QEMU FD passing, but this can be achieved with qemu_open() + fdopen() too. Switching to regular stdio FILE APIs avoids the need to sprintf via an intermedia buffer which slightly simplifies the code. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange Reviewed-by: Juan Quintela Message-Id: <1461751518-12128-2-git-send-email-berrange@redhat.com> Signed-off-by: Amit Shah --- hw/s390x/s390-skeys.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c index d772cfc..e2d4e1a 100644 --- a/hw/s390x/s390-skeys.c +++ b/hw/s390x/s390-skeys.c @@ -47,15 +47,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; @@ -64,10 +60,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++; } } @@ -116,7 +111,8 @@ void qmp_dump_skeys(const char *filename, Error **errp) vaddr cur_gfn = 0; uint8_t *buf; int ret; - QEMUFile *f; + int fd; + FILE *f; /* Quick check to see if guest is using storage keys*/ if (!skeyclass->skeys_enabled(ss)) { @@ -125,8 +121,14 @@ void qmp_dump_skeys(const char *filename, Error **errp) return; } - f = qemu_fopen(filename, "wb"); + fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600); + if (fd < 0) { + error_setg_file_open(errp, errno, filename); + return; + } + f = fdopen(fd, "wb"); if (!f) { + close(fd); error_setg_file_open(errp, errno, filename); return; } @@ -162,7 +164,7 @@ out_free: error_propagate(errp, lerr); g_free(buf); out: - qemu_fclose(f); + fclose(f); } static void qemu_s390_skeys_init(Object *obj)