[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [PATCH v2] qemu-io: add pattern file for write command
From: |
Denis Plotnikov |
Subject: |
Re: [Qemu-block] [PATCH v2] qemu-io: add pattern file for write command |
Date: |
Thu, 30 May 2019 08:11:52 +0000 |
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