Re: KVM Block Device Driver

Wolfgang Richter
2013-08-18T14:48:20Z

Also there are utility functions within the QEMU code base that help deal with QEMUIOVectors (as far as I remember) which would help maybe so you don't have to directly code using them.

--
Wolf

On Aug 18, 2013, at 10:04 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:

> Il 14/08/2013 20:44, Spensky, Chad - 0559 - MITLL ha scritto:
>> Wolfgang,
>>
>> Thanks so much for the response. It turns out that wasn't handling the
>> QEMUIOVector properly. When I first implemented it, I saw that the iovec
>> was a pointer and assumed that there would only ever be one. Given the
>> lack of documentation and my lack of understanding this went undetected
>> for a while. everything now seems to work just fine. :-) See below for
>> the portion of code that threw me off. Thanks again!
>>
>> - Chad
>>
>>
>> Proposed change to qemu-common.h (:
>>
>> typedef struct QEMUIOVector {
>> struct iovec *iov;
>> int niov;
>> int nalloc;
>> size_t size;
>> } QEMUIOVector;
>>
>> changed to:
>>
>> // Array of I/O vectors
>>
>> typedef struct QEMUIOVector {
>> struct iovec iov[];
>> int niov;
>> int nalloc;
>> size_t size;
>> } QEMUIOVector;
>
> This wouldn't work. As you wrote it, it wouldn't even compile.
>
> Embedding an array is possible if you place it at the end of the struct,
> but then it is not possible to resize the array (because when you
> reallocate it, the containing QEMUIOVector could move in memory and any
> pointers to the containing QEMUIOVector would become invalid).
>
> In C, a dynamically-allocated array is represented by a pointer to the
> first item. The size of the array and the size of the
> dynamically-allocated memory block are stored together with the pointer
> (in this case, in the niov and nalloc members).
>
> In fact, whenever you see something like "iovec iov[]" in Java, what's
> being stored in memory is exactly a pointer to the first item, the size
> of the array and the size of the dynamically-allocated memory block. C
> just makes that explicit.
>
> Paolo