s390: use FILE instead of QEMUFile for creating text file

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 <eblake@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Message-Id: <1461751518-12128-2-git-send-email-berrange@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
This commit is contained in:
Daniel P. Berrange 2016-04-27 11:04:51 +01:00 committed by Amit Shah
parent 287db79df8
commit 1fd791f007

View File

@ -47,15 +47,11 @@ void s390_skeys_init(void)
qdev_init_nofail(DEVICE(obj)); 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 count, Error **errp)
{ {
uint64_t curpage = startgfn; uint64_t curpage = startgfn;
uint64_t maxpage = curpage + count - 1; 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++) { for (; curpage <= maxpage; curpage++) {
uint8_t acc = (*keys & 0xF0) >> 4; 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 ch = (*keys & 0x02);
int res = (*keys & 0x01); int res = (*keys & 0x01);
len = snprintf(buf, sizeof(buf), fmt, curpage, fprintf(f, "page=%03" PRIx64 ": key(%d) => ACC=%X, FP=%d, REF=%d,"
*keys, acc, fp, ref, ch, res); " ch=%d, reserved=%d\n",
assert(len < sizeof(buf)); curpage, *keys, acc, fp, ref, ch, res);
qemu_put_buffer(f, (uint8_t *)buf, len);
keys++; keys++;
} }
} }
@ -116,7 +111,8 @@ void qmp_dump_skeys(const char *filename, Error **errp)
vaddr cur_gfn = 0; vaddr cur_gfn = 0;
uint8_t *buf; uint8_t *buf;
int ret; int ret;
QEMUFile *f; int fd;
FILE *f;
/* Quick check to see if guest is using storage keys*/ /* Quick check to see if guest is using storage keys*/
if (!skeyclass->skeys_enabled(ss)) { if (!skeyclass->skeys_enabled(ss)) {
@ -125,8 +121,14 @@ void qmp_dump_skeys(const char *filename, Error **errp)
return; 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) { if (!f) {
close(fd);
error_setg_file_open(errp, errno, filename); error_setg_file_open(errp, errno, filename);
return; return;
} }
@ -162,7 +164,7 @@ out_free:
error_propagate(errp, lerr); error_propagate(errp, lerr);
g_free(buf); g_free(buf);
out: out:
qemu_fclose(f); fclose(f);
} }
static void qemu_s390_skeys_init(Object *obj) static void qemu_s390_skeys_init(Object *obj)