void qmp_pmemsave(int64_t addr, int64_t size, const char *filename, Error **errp) { FILE *f; uint32_t l; uint8_t buf[1024]; f = fopen(filename, "wb"); if (!f) { error_setg_file_open(errp, errno, filename); return; } while (size != 0) { l = sizeof(buf); if (l > size) l = size; cpu_physical_memory_rw(addr, buf, l, 0); if (fwrite(buf, 1, l, f) != l) { error_set(errp, QERR_IO_ERROR); goto exit; } addr += l; size -= l; } exit: fclose(f); }
void qmp_dump_skeys(const char *filename, Error **errp) { S390SKeysState *ss = s390_get_skeys_device(); S390SKeysClass *skeyclass = S390_SKEYS_GET_CLASS(ss); const uint64_t total_count = ram_size / TARGET_PAGE_SIZE; uint64_t handled_count = 0, cur_count; Error *lerr = NULL; vaddr cur_gfn = 0; uint8_t *buf; int ret; QEMUFile *f; /* Quick check to see if guest is using storage keys*/ if (!skeyclass->skeys_enabled(ss)) { error_setg(errp, "This guest is not using storage keys - " "nothing to dump"); return; } f = qemu_fopen(filename, "wb"); if (!f) { error_setg_file_open(errp, errno, filename); return; } buf = g_try_malloc(S390_SKEYS_BUFFER_SIZE); if (!buf) { error_setg(errp, "Could not allocate memory"); goto out; } /* we'll only dump initial memory for now */ while (handled_count < total_count) { /* Calculate how many keys to ask for & handle overflow case */ cur_count = MIN(total_count - handled_count, S390_SKEYS_BUFFER_SIZE); ret = skeyclass->get_skeys(ss, cur_gfn, cur_count, buf); if (ret < 0) { error_setg(errp, "get_keys error %d", ret); goto out_free; } /* write keys to stream */ write_keys(f, buf, cur_gfn, cur_count, &lerr); if (lerr) { goto out_free; } cur_gfn += cur_count; handled_count += cur_count; } out_free: error_propagate(errp, lerr); g_free(buf); out: qemu_fclose(f); }
int qmp_chardev_open_file_source(char *src, int flags, Error **errp) { int fd = -1; TFR(fd = qemu_open(src, flags, 0666)); if (fd == -1) { error_setg_file_open(errp, errno, src); } return fd; }
static void rng_random_opened(RngBackend *b, Error **errp) { RndRandom *s = RNG_RANDOM(b); if (s->filename == NULL) { error_set(errp, QERR_INVALID_PARAMETER_VALUE, "filename", "a valid filename"); } else { s->fd = qemu_open(s->filename, O_RDONLY | O_NONBLOCK); if (s->fd == -1) { error_setg_file_open(errp, errno, s->filename); } } }
void qmp_memsave(int64_t addr, int64_t size, const char *filename, bool has_cpu, int64_t cpu_index, Error **errp) { FILE *f; uint32_t l; CPUState *cpu; uint8_t buf[1024]; if (!has_cpu) { cpu_index = 0; } cpu = qemu_get_cpu(cpu_index); if (cpu == NULL) { error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index", "a CPU number"); return; } f = fopen(filename, "wb"); if (!f) { error_setg_file_open(errp, errno, filename); return; } while (size != 0) { l = sizeof(buf); if (l > size) l = size; cpu_memory_rw_debug(cpu, addr, buf, l, 0); if (fwrite(buf, 1, l, f) != l) { error_set(errp, QERR_IO_ERROR); goto exit; } addr += l; size -= l; } exit: fclose(f); }
static void mirror_complete(BlockJob *job, Error **errp) { MirrorBlockJob *s = container_of(job, MirrorBlockJob, common); int ret; ret = bdrv_open_backing_file(s->target, NULL); if (ret < 0) { char backing_filename[PATH_MAX]; bdrv_get_full_backing_filename(s->target, backing_filename, sizeof(backing_filename)); error_setg_file_open(errp, -ret, backing_filename); return; } if (!s->synced) { error_set(errp, QERR_BLOCK_JOB_NOT_READY, job->bs->device_name); return; } s->should_complete = true; block_job_resume(job); }