From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:36421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StLzA-0000HK-8j for qemu-devel@nongnu.org; Mon, 23 Jul 2012 12:59:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StLz6-0004aH-0p for qemu-devel@nongnu.org; Mon, 23 Jul 2012 12:59:56 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:60689) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StLz5-0004aD-R8 for qemu-devel@nongnu.org; Mon, 23 Jul 2012 12:59:51 -0400 Received: by pbbro12 with SMTP id ro12so11013652pbb.4 for ; Mon, 23 Jul 2012 09:59:50 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <500D82FD.9040508@redhat.com> Date: Mon, 23 Jul 2012 18:59:41 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1342435377-25897-1-git-send-email-pbonzini@redhat.com> <1342435377-25897-13-git-send-email-pbonzini@redhat.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 12/12] raw-win32: add emulated AIO support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: kwolf@redhat.com, aliguori@linux.vnet.ibm.com, qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com, sw@weilnetz.de Il 23/07/2012 18:35, Blue Swirl ha scritto: >> > +struct qemu_paiocb { > QEMUPAIOCB RawWin32AIOData. :) >> > + BlockDriverState *bs; >> > + HANDLE hfile; >> > + struct iovec *aio_iov; >> > + int aio_niov; >> > + size_t aio_nbytes; >> > + off_t aio_offset; >> > + int aio_type; >> > +}; >> > + >> > typedef struct BDRVRawState { >> > HANDLE hfile; >> > int type; >> > char drive_path[16]; /* format: "d:\" */ >> > } BDRVRawState; >> > >> > +/* >> > + * Read/writes the data to/from a given linear buffer. >> > + * >> > + * Returns the number of bytes handles or -errno in case of an error. Short >> > + * reads are only returned if the end of the file is reached. >> > + */ >> > +static size_t handle_aiocb_rw(struct qemu_paiocb *aiocb) >> > +{ >> > + size_t offset = 0; >> > + int i; >> > + >> > + for (i = 0; i < aiocb->aio_niov; i++) { >> > + OVERLAPPED ov; >> > + DWORD ret, ret_count, len; >> > + >> > + memset(&ov, 0, sizeof(ov)); >> > + ov.Offset = (aiocb->aio_offset + offset); >> > + ov.OffsetHigh = (aiocb->aio_offset + offset) >> 32; >> > + len = aiocb->aio_iov[i].iov_len; >> > + if (aiocb->aio_type & QEMU_AIO_WRITE) { >> > + ret = WriteFile(aiocb->hfile, aiocb->aio_iov[i].iov_base, >> > + len, &ret_count, &ov); >> > + } else { >> > + ret = ReadFile(aiocb->hfile, aiocb->aio_iov[i].iov_base, >> > + len, &ret_count, &ov); >> > + } >> > + if (!ret) { >> > + ret_count = 0; >> > + } >> > + if (ret_count != len) { >> > + break; >> > + } >> > + offset += len; >> > + } >> > + >> > + return offset; >> > +} >> > + >> > +static int aio_worker(void *arg) >> > +{ >> > + struct qemu_paiocb *aiocb = arg; >> > + ssize_t ret = 0; >> > + size_t count; >> > + >> > + switch (aiocb->aio_type & QEMU_AIO_TYPE_MASK) { >> > + case QEMU_AIO_READ: >> > + count = handle_aiocb_rw(aiocb); >> > + if (count < aiocb->aio_nbytes && aiocb->bs->growable) { >> > + /* A short read means that we have reached EOF. Pad the buffer >> > + * with zeros for bytes after EOF. */ >> > + QEMUIOVector qiov; >> > + >> > + qemu_iovec_init_external(&qiov, aiocb->aio_iov, >> > + aiocb->aio_niov); >> > + qemu_iovec_memset_skip(&qiov, 0, aiocb->aio_nbytes - count, count); >> > + >> > + count = aiocb->aio_nbytes; >> > + } >> > + if (count == aiocb->aio_nbytes) { >> > + ret = 0; >> > + } else { >> > + ret = -EINVAL; >> > + } >> > + break; >> > + case QEMU_AIO_WRITE: >> > + count = handle_aiocb_rw(aiocb); >> > + if (count == aiocb->aio_nbytes) { >> > + count = 0; >> > + } else { >> > + count = -EINVAL; >> > + } >> > + break; >> > + case QEMU_AIO_FLUSH: >> > + if (!FlushFileBuffers(aiocb->hfile)) { >> > + return -EIO; >> > + } >> > + break; >> > + default: >> > + fprintf(stderr, "invalid aio request (0x%x)\n", aiocb->aio_type); > Assert instead? Yeah, this is cut-and-pasted from posix-aio-compat.c, I'll fix both. Paolo