From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:53000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbVQR-0003na-GC for qemu-devel@nongnu.org; Thu, 22 Nov 2012 06:58:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TbVQL-0003cu-Gy for qemu-devel@nongnu.org; Thu, 22 Nov 2012 06:58:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:4073) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbVQL-0003ch-7q for qemu-devel@nongnu.org; Thu, 22 Nov 2012 06:58:29 -0500 Date: Thu, 22 Nov 2012 12:58:23 +0100 From: Stefan Hajnoczi Message-ID: <20121122115823.GA13571@stefanha-thinkpad.redhat.com> References: <1353522781-12721-1-git-send-email-stefanha@redhat.com> <1353522781-12721-10-git-send-email-stefanha@redhat.com> <50ADF195.4030204@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <50ADF195.4030204@redhat.com> Subject: Re: [Qemu-devel] [PATCH v3 09/12] iov: add iov_get_ptr() to reference vector data List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Kevin Wolf , Anthony Liguori , dkoch@cloudswitch.com, "Michael S. Tsirkin" , qemu-devel@nongnu.org, Michael Roth , Blue Swirl , khoa@us.ibm.com, Asias He On Thu, Nov 22, 2012 at 10:34:13AM +0100, Paolo Bonzini wrote: > Il 21/11/2012 19:32, Stefan Hajnoczi ha scritto: > > The iov_get_ptr() data returns a pointer to contiguous data within a > > vector. This allows the caller to manipulate data inside the vector > > without copying in/out using iov_from_buf()/iov_to_buf() when we know > > that data is contiguous within an iovec element. > > This works for you because you have a single byte to write. It would > not work for the SG_IO inhdr, which would need iov_to_buf(). Guilty as charged, your honor. :) Let me give a few more details about the motivation for this function: In virtio-blk-data-plane we have an iovec[] array. In the read/write code path we discard the inhdr/outhdr so just the data buffers are left in the iovec[] array. Then we can pass the iovec[] array straight to the Linux AIO functions. Because we're using the iovec[] array for data buffers and we're not allowed to make assumptions about iovec layout, we cannot use iov_to_buf()/iov_from_buf() at the end to fill in the status field - the inhdr has already been discarded from the iovec[] array. Since I knew the inhdr is only 1 byte I decided against doing something like dynamically allocating/freeing a QEMUIOVector which could handle spanning iovecs. That said, I think this function is okay as-is because it works fine for non-virtio cases where the caller *knows* the iovec[] layout. As a utility function it stands on its own. > What about the following alternative API: > > void *iov_get_ptr(struct iovec *iov, unsigned int iov_cnt, > ssize_t offset, size_t *bytes); > > which would place the number of valid bytes (i.e. the length of the > remainder of the iovec entry) in *bytes? > > Also, I think that offset == iov_size(iov, iov_cnt) should be > acceptable, and it would be the only case in which *bytes == 0. Hmm...this may be more useful than the version I proposed since the caller can also use it to find out how many bytes are contiguous. Michael: Any concerns if I update the code to reflect Paolo's suggestion? Stefan