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

Re: [libvirt] [PATCH v3 10/31] Introduce virStreamInData



On 05/17/2017 12:00 AM, John Ferlan wrote:
> 
> 
> On 05/16/2017 10:03 AM, Michal Privoznik wrote:
>> This is just an internal API, that calls corresponding function
>> in stream driver. This function will set @data=1 if the
>> underlying file is in data section, or @data=0 if it is in a
>> hole. At any rate, @length is set to number of bytes remaining in
>> the section the file currently is.
>>
>> Signed-off-by: Michal Privoznik <mprivozn redhat com>
>> ---
>>  src/driver-stream.h      |  6 ++++++
>>  src/libvirt-stream.c     | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>>  src/libvirt_internal.h   |  4 ++++
>>  src/libvirt_private.syms |  1 +
>>  4 files changed, 59 insertions(+)
>>
> 
> [...]
> 
>> diff --git a/src/libvirt-stream.c b/src/libvirt-stream.c
>> index 4cbe5eee1..30c305035 100644
>> --- a/src/libvirt-stream.c
>> +++ b/src/libvirt-stream.c
>> @@ -481,6 +481,54 @@ virStreamRecvHole(virStreamPtr stream,
>>  }
>>  
>>  
>> +/**
>> + * virStreamInData:
>> + * @stream: stream
>> + * @data: are we in data or hole
>> + * @length: length to next section
>> + *
>> + * This function checks the underlying stream (typically a file)
>> + * to learn whether the current stream position lies within a
>> + * data section or a hole. Upon return @data is set to a nonzero
>> + * value if former is the case, or to zero if @stream is in a
>> + * hole. Moreover, @length is updated to tell caller how many
>> + * bytes can be read from @stream until current section changes
>> + * (from data to a hole or vice versa).
>> + *
>> + * NB: there's an implicit hole at EOF. In this situation this
>> + * function should set @data = false, @length = 0 and return 0.
>> + *
>> + * To sum it up:
>> + *
>> + * data section: @data = true,  @length > 0
>> + * hole:         @data = false, @length > 0
>> + * EOF:          @data = false, @length = 0
>> + *
>> + * Returns 0 on success,
>> + *        -1 otherwise
>> + */
>> +int
>> +virStreamInData(virStreamPtr stream,
>> +                int *data,
>> +                long long *length)
>> +{
>> +    VIR_DEBUG("stream=%p, data=%p, length=%p", stream, data, length);
>> +
>> +    /* No checks of arguments or error resetting. This is an
>> +     * internal function that just happen to live next to some
>> +     * public functions of ours. */
> 
> Well... If it's publicly accessible... @data and @length should probably
> be checked for non NULL.

It's not publicly accessible. It's private. But sure, checks would be
harmless. I can add them.

Michal


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