[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v6 for-2.7 01/28] s390: use FILE instead of QEMUFile
From: |
Daniel P. Berrange |
Subject: |
[Qemu-devel] [PATCH v6 for-2.7 01/28] s390: use FILE instead of QEMUFile for creating text file |
Date: |
Wed, 27 Apr 2016 11:04:51 +0100 |
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 <address@hidden>
Signed-off-by: Daniel P. Berrange <address@hidden>
---
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 6528ffe..1d4e537 100644
--- a/hw/s390x/s390-skeys.c
+++ b/hw/s390x/s390-skeys.c
@@ -46,15 +46,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;
@@ -63,10 +59,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,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)) {
@@ -124,8 +120,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;
}
@@ -161,7 +163,7 @@ out_free:
error_propagate(errp, lerr);
g_free(buf);
out:
- qemu_fclose(f);
+ fclose(f);
}
static void qemu_s390_skeys_init(Object *obj)
--
2.5.5
- [Qemu-devel] [PATCH v6 for-2.7 00/28] Convert migration to QIOChannel & support, Daniel P. Berrange, 2016/04/27
- [Qemu-devel] [PATCH v6 for-2.7 01/28] s390: use FILE instead of QEMUFile for creating text file,
Daniel P. Berrange <=
- [Qemu-devel] [PATCH v6 for-2.7 02/28] io: avoid double-free when closing QIOChannelBuffer, Daniel P. Berrange, 2016/04/27
- [Qemu-devel] [PATCH v6 for-2.7 04/28] migration: ensure qemu_fflush() always writes full data amount, Daniel P. Berrange, 2016/04/27
- [Qemu-devel] [PATCH v6 for-2.7 05/28] migration: split migration hooks out of QEMUFileOps, Daniel P. Berrange, 2016/04/27
- [Qemu-devel] [PATCH v6 for-2.7 07/28] migration: force QEMUFile to blocking mode for outgoing migration, Daniel P. Berrange, 2016/04/27
- [Qemu-devel] [PATCH v6 for-2.7 08/28] migration: introduce a new QEMUFile impl based on QIOChannel, Daniel P. Berrange, 2016/04/27
- [Qemu-devel] [PATCH v6 for-2.7 03/28] migration: remove use of qemu_bufopen from vmstate tests, Daniel P. Berrange, 2016/04/27
- [Qemu-devel] [PATCH v6 for-2.7 12/28] migration: convert unix socket protocol to use QIOChannel, Daniel P. Berrange, 2016/04/27
- [Qemu-devel] [PATCH v6 for-2.7 16/28] migration: convert exec socket protocol to use QIOChannel, Daniel P. Berrange, 2016/04/27
- [Qemu-devel] [PATCH v6 for-2.7 15/28] migration: convert fd socket protocol to use QIOChannel, Daniel P. Berrange, 2016/04/27
- [Qemu-devel] [PATCH v6 for-2.7 19/28] migration: delete QEMUFile buffer implementation, Daniel P. Berrange, 2016/04/27