From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HSM1h-0007N3-JR for qemu-devel@nongnu.org; Fri, 16 Mar 2007 19:40:01 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HSM1g-0007Me-4a for qemu-devel@nongnu.org; Fri, 16 Mar 2007 19:40:01 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HSM1g-0007Mb-0w for qemu-devel@nongnu.org; Fri, 16 Mar 2007 18:40:00 -0500 Received: from nf-out-0910.google.com ([64.233.182.189]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from <3n4ch3@gmail.com>) id 1HSM0U-0000jw-PC for qemu-devel@nongnu.org; Fri, 16 Mar 2007 19:38:47 -0400 Received: by nf-out-0910.google.com with SMTP id c31so840005nfb for ; Fri, 16 Mar 2007 16:38:41 -0700 (PDT) Date: Sat, 17 Mar 2007 01:38:27 +0200 From: Enache Adrian <3n4ch3@gmail.com> Subject: Re: [Qemu-devel] support for non aio host os's? References: <20070316213135.GA32640@fries.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070316213135.GA32640@fries.net> Message-ID: <45fb2a80.36998767.1d9a.7e60@mx.google.com> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: todd@fries.net, qemu-devel@nongnu.org On Fri, Mar 16, 2007 at 04:31:36PM -0500, Todd T. Fries wrote: > .. so now that aio is in, and whatever existed before is out, has anybody > come up with a way to support host os's that do not have aio? This is what I'm using. Just manage to have '#define CONFIG_NO_AIO 1' in ./config-host.h. Patch is against qemu-cvs, and also includes a raw_getlength() function that works with disk devices on OpenBSD. Adi --- /home/src/qemu/block-raw.c Sat Jan 20 14:10:33 2007 +++ ./block-raw.c Sat Mar 17 01:34:36 2007 @@ -25,7 +25,10 @@ #include "block_int.h" #include #ifndef _WIN32 + +#ifndef CONFIG_NO_AIO #include +#endif #ifndef QEMU_TOOL #include "exec-all.h" @@ -57,6 +60,13 @@ #include #endif +#ifdef __OpenBSD__ +#include +#include +#include +#endif + + //#define DEBUG_FLOPPY #define FTYPE_FILE 0 @@ -158,6 +168,7 @@ static int raw_pwrite(BlockDriverState * } /***********************************************************/ +#ifndef CONFIG_NO_AIO /* Unix AIO using POSIX AIO */ typedef struct RawAIOCB { @@ -380,6 +391,37 @@ static void raw_aio_cancel(BlockDriverAI } } +#else /* !CONFIG_NO_AIO */ + +void qemu_aio_init(void) +{ +} + +void qemu_aio_poll(void) +{ +} + +void qemu_aio_flush(void) +{ +} + +void qemu_aio_wait_start(void) +{ +} + +void qemu_aio_wait(void) +{ +#ifndef QEMU_TOOL + qemu_bh_poll(); +#endif +} + +void qemu_aio_wait_end(void) +{ +} + +#endif /* !CONFIG_NO_AIO */ + static void raw_close(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; @@ -399,8 +441,28 @@ static int raw_truncate(BlockDriverState return 0; } +#ifdef __OpenBSD__ + static int64_t raw_getlength(BlockDriverState *bs) { + int fd = ((BDRVRawState*)bs->opaque)->fd; + struct stat st; + if(fstat(fd, &st)) + return -1; + if(S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)){ + struct disklabel dl; + if(ioctl(fd, DIOCGDINFO, &dl)) + return -1; + return (int64_t)dl.d_secsize * + dl.d_partitions[DISKPART(st.st_rdev)].p_size; + }else + return st.st_size; +} + +#else /* !__OpenBSD__ */ + +static int64_t raw_getlength(BlockDriverState *bs) +{ BDRVRawState *s = bs->opaque; int fd = s->fd; int64_t size; @@ -446,6 +508,8 @@ static int64_t raw_getlength(BlockDrive return size; } +#endif /* !__OpenBSD__ */ + static int raw_create(const char *filename, int64_t total_size, const char *backing_file, int flags) { @@ -480,10 +544,12 @@ BlockDriver bdrv_raw = { raw_create, raw_flush, +#ifndef CONFIG_NO_AIO .bdrv_aio_read = raw_aio_read, .bdrv_aio_write = raw_aio_write, .bdrv_aio_cancel = raw_aio_cancel, .aiocb_size = sizeof(RawAIOCB), +#endif /* !CONFIG_NO_AIO */ .protocol_name = "file", .bdrv_pread = raw_pread, .bdrv_pwrite = raw_pwrite, @@ -816,10 +882,12 @@ BlockDriver bdrv_host_device = { NULL, raw_flush, +#ifndef CONFIG_NO_AIO .bdrv_aio_read = raw_aio_read, .bdrv_aio_write = raw_aio_write, .bdrv_aio_cancel = raw_aio_cancel, .aiocb_size = sizeof(RawAIOCB), +#endif /* !CONFIG_NO_AIO */ .bdrv_pread = raw_pread, .bdrv_pwrite = raw_pwrite, .bdrv_getlength = raw_getlength,