From: Paolo Bonzini <pbonzini@redhat.com>
To: Blue Swirl <blauwirbel@gmail.com>
Cc: kwolf@redhat.com, aliguori@linux.vnet.ibm.com,
qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com,
sw@weilnetz.de
Subject: Re: [Qemu-devel] [PATCH 12/12] raw-win32: add emulated AIO support
Date: Mon, 23 Jul 2012 18:59:41 +0200 [thread overview]
Message-ID: <500D82FD.9040508@redhat.com> (raw)
In-Reply-To: <CAAu8pHtWBErjbHr__=rLfJuELr2CaW6-a6emvLC3Kj5wu0sCEg@mail.gmail.com>
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
prev parent reply other threads:[~2012-07-23 16:59 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-16 10:42 [Qemu-devel] [PATCH 00/12] Portable thread-pool/AIO, Win32 emulated AIO Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 01/12] event_notifier: enable it to use pipes Paolo Bonzini
2012-07-19 18:58 ` Anthony Liguori
2012-07-16 10:42 ` [Qemu-devel] [PATCH 02/12] event_notifier: add Win32 implementation Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 03/12] main-loop: use event notifiers Paolo Bonzini
2012-07-19 19:04 ` Anthony Liguori
2012-07-16 10:42 ` [Qemu-devel] [PATCH 04/12] aio: provide platform-independent API Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 05/12] aio: add Win32 implementation Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 06/12] linux-aio: use event notifiers Paolo Bonzini
2012-07-19 19:10 ` Anthony Liguori
2012-07-16 10:42 ` [Qemu-devel] [PATCH 07/12] qemu-thread: add QemuSemaphore Paolo Bonzini
2012-07-16 12:00 ` Jan Kiszka
2012-07-16 12:01 ` [Qemu-devel] [PATCH] qemu-thread: Introduce qemu_cond_timedwait for POSIX Jan Kiszka
2012-07-16 13:20 ` [Qemu-devel] [PATCH 07/12] qemu-thread: add QemuSemaphore Paolo Bonzini
2012-07-16 13:34 ` Jan Kiszka
2012-07-16 13:35 ` Paolo Bonzini
2012-07-16 13:53 ` Jan Kiszka
2012-07-16 14:03 ` Paolo Bonzini
2012-07-16 14:09 ` Jan Kiszka
2012-07-16 14:20 ` Paolo Bonzini
2012-07-24 16:55 ` Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 08/12] aio: add generic thread-pool facility Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 09/12] block: switch posix-aio-compat to threadpool Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 10/12] raw: merge posix-aio-compat.c into block/raw-posix.c Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 11/12] raw-posix: rename raw-posix-aio.h, hide unavailable prototypes Paolo Bonzini
2012-07-16 10:42 ` [Qemu-devel] [PATCH 12/12] raw-win32: add emulated AIO support Paolo Bonzini
2012-07-23 16:35 ` Blue Swirl
2012-07-23 16:59 ` Paolo Bonzini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=500D82FD.9040508@redhat.com \
--to=pbonzini@redhat.com \
--cc=aliguori@linux.vnet.ibm.com \
--cc=blauwirbel@gmail.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.com \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).