From: Eric Blake <eblake@redhat.com>
To: Denis Plotnikov <dplotnikov@virtuozzo.com>,
sgarzare@redhat.com, kwolf@redhat.com, mreitz@redhat.com,
qemu-block@nongnu.org
Cc: vsementsov@virtuozzo.com, qemu-devel@nongnu.org, den@virtuozzo.com
Subject: Re: [Qemu-devel] [PATCH v5] qemu-io: add pattern file for write command
Date: Fri, 31 May 2019 10:13:52 -0500 [thread overview]
Message-ID: <d2498589-e866-475c-13dd-fe9ce35b914b@redhat.com> (raw)
In-Reply-To: <20190531074620.24934-1-dplotnikov@virtuozzo.com>
[-- Attachment #1: Type: text/plain, Size: 1311 bytes --]
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 <dplotnikov@virtuozzo.com>
> ---
> 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
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2019-05-31 15:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-31 7:46 [Qemu-devel] [PATCH v5] qemu-io: add pattern file for write command Denis Plotnikov
2019-05-31 15:13 ` Eric Blake [this message]
2019-06-10 12:40 ` Denis Plotnikov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d2498589-e866-475c-13dd-fe9ce35b914b@redhat.com \
--to=eblake@redhat.com \
--cc=den@virtuozzo.com \
--cc=dplotnikov@virtuozzo.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).