From: Denis Plotnikov <dplotnikov@virtuozzo.com>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: "kwolf@redhat.com" <kwolf@redhat.com>,
Denis Lunev <den@virtuozzo.com>,
"qemu-block@nongnu.org" <qemu-block@nongnu.org>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"mreitz@redhat.com" <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH v2] qemu-io: add pattern file for write command
Date: Thu, 30 May 2019 08:11:52 +0000 [thread overview]
Message-ID: <762e39e1-f39d-f7bd-96bf-107a70ca00a7@virtuozzo.com> (raw)
In-Reply-To: <20190530075158.nxwed37oqs5qqjzb@steredhat.homenet.telecomitalia.it>
On 30.05.2019 10:51, Stefano Garzarella wrote:
> On Wed, May 29, 2019 at 02:46:24PM +0300, Denis Plotnikov wrote:
>> The patch allows to provide a pattern file for write
>> command. There was no similar ability before.
>> ---
>> qemu-io-cmds.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++----
>> 1 file changed, 54 insertions(+), 4 deletions(-)
>>
>> diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
>> index 09750a23ce..148f2ff92a 100644
>> --- a/qemu-io-cmds.c
>> +++ b/qemu-io-cmds.c
>> @@ -21,6 +21,7 @@
>> #include "qemu/option.h"
>> #include "qemu/timer.h"
>> #include "qemu/cutils.h"
>> +#include "string.h"
>>
>> #define CMD_NOFILE_OK 0x01
>>
>> @@ -343,6 +344,35 @@ static void *qemu_io_alloc(BlockBackend *blk, size_t len, int pattern)
>> return buf;
>> }
>>
>> +static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len,
>> + char *file_name)
>> +{
>> + void *buf;
>> + FILE *f = fopen(file_name, "r");
>> +
>> + if (!f) {
>> + printf("cannot open file '%s'\n", file_name);
>> + return NULL;
>> + }
>> +
>> + if (qemuio_misalign) {
>> + len += MISALIGN_OFFSET;
>> + }
>> + buf = blk_blockalign(blk, len);
>> + memset(buf, 0, len);
>> +
>> + if (!fread(buf, sizeof(char), len, f)) {
>> + printf("file '%s' is empty\n", file_name);
>> + qemu_vfree(buf);
>> + return NULL;
>> + }
>
> Should we close the FILE *f at the end of this function or when fread()
> returns with an error?
I think we should. Fixed in v3 (v4 has been sent).
Thanks!
>
> Thanks,
> Stefano
>
--
Best,
Denis
prev parent reply other threads:[~2019-05-30 8:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-29 11:46 [Qemu-devel] [PATCH v2] qemu-io: add pattern file for write command Denis Plotnikov
2019-05-29 11:51 ` no-reply
2019-05-29 12:28 ` Max Reitz
2019-05-30 7:51 ` [Qemu-devel] [Qemu-block] " Stefano Garzarella
2019-05-30 8:11 ` Denis Plotnikov [this message]
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=762e39e1-f39d-f7bd-96bf-107a70ca00a7@virtuozzo.com \
--to=dplotnikov@virtuozzo.com \
--cc=den@virtuozzo.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.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).