On 5/31/19 2:46 AM, Denis Plotnikov wrote: > The patch allows to provide a pattern file for write > command. There was no similar ability before. > > Signed-off-by: Denis Plotnikov <[email protected]> > --- > v5: > * file name initiated with null to make compilers happy >
> +static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len,
> + char *file_name)
> +{
> + char *buf, *buf_pos;
> + FILE *f = fopen(file_name, "r");
> + int l;
> +
> + if (!f) {
> + printf("'%s': %s\n", file_name, strerror(errno));
> + return NULL;
> + }
> +
> + if (qemuio_misalign) {
> + len += MISALIGN_OFFSET;
> + }
> + buf = blk_blockalign(blk, len);
> + memset(buf, 0, len);
> +
> + buf_pos = buf;
> +
> + while (len > 0) {
> + l = fread(buf_pos, sizeof(char), len, f);
> +
> + if (feof(f)) {
> + rewind(f);
> + }
Why are we reading the file more than once? Once we've read it once,
it's more efficient to switch to a loop that memcpy()s the prefix into
the rest of the buffer, rather than to perform repeated I/O.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
