From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: KVM Block Device Driver Date: Sun, 18 Aug 2013 16:04:16 +0200 Message-ID: <5210D460.8060708@redhat.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Wolfgang Richter , Stefan Hajnoczi , Fam Zheng , "kvm@vger.kernel.org" To: "Spensky, Chad - 0559 - MITLL" Return-path: Received: from mail-wi0-f179.google.com ([209.85.212.179]:41654 "EHLO mail-wi0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750819Ab3HROFA (ORCPT ); Sun, 18 Aug 2013 10:05:00 -0400 Received: by mail-wi0-f179.google.com with SMTP id hr7so2195984wib.0 for ; Sun, 18 Aug 2013 07:04:59 -0700 (PDT) In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: 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