qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v5] qemu-io: add pattern file for write command


From: Denis Plotnikov
Subject: Re: [Qemu-devel] [PATCH v5] qemu-io: add pattern file for write command
Date: Mon, 10 Jun 2019 12:40:26 +0000


On 31.05.2019 18:13, Eric Blake wrote:
> 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 <address@hidden>
>> ---
>> 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.
> 
Yes, it is. Will change it.

Denis

reply via email to

[Prev in Thread] Current Thread [Next in Thread]