Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 28 Sep 2008 00:52:04 +0200 (CEST)
From:      Juergen Lock <nox@jelal.kn-bremen.de>
To:        anthony@codemonkey.ws
Cc:        freebsd-emulation@freebsd.org, qemu-devel@nongnu.org
Subject:   Re: [Qemu-devel] Re: qemu svn r5281 on FreeBSD - slow usb, vmwarevga, screen updates... (now updated to r5313)
Message-ID:  <200809272252.m8RMq4fu057049@saturn.kn-bremen.de>
In-Reply-To: <48DE5256.5000101@codemonkey.ws>
References:  <20080921204025.GA81055@saturn.kn-bremen.de> <cd6b4a5b0809230639x27e94477k315796c2cfb650f2@mail.gmail.com> <200809242210.m8OMAcSZ021572@saturn.kn-bremen.de> <cd6b4a5b0809241954p159dd86u17fdc2a485008e7d@mail.gmail.com> <48DCF9FC.2070708@codemonkey.ws> <20080926220445.GA13099@saturn.kn-bremen.de>

next in thread | previous in thread | raw e-mail | index | archive | help
In article <48DE5256.5000101@codemonkey.ws> you write:
>[...]

>>> The one thing that really tripped me up with the whole aio kld-module 
>>> thing.  Perhaps we should detect the presence of the module at run time and 
>>> disable aio?  I assume kldload can only be run as root?
>>>     
>>
>> Yes.  Atm the ports print a warning when aio is not loaded:
>>   
>
>Yeah, I don't think this is enough.  I'd rather see AIO be disabled when 
>modfind("aio") is not available (printing a warning along with that 
>would be fine).  A non-privileged user cannot load the aio module so 
>it's not very useful to tell them to load it.

OK so how about the following?  (only tested with a raw image, but if
the way its disabled for OpenBSD works for all of them this should as well.)

 Oh and am I right qemu-img doesn't use aio?  If it actually does we may
want to add the same check there instead of just disabling it.  (I kept it
enabled for qemu-nbd since thats not built on FreeBSD anyway.)

Index: qemu/block.h
@@ -50,10 +50,9 @@
 #define BDRV_O_DIRECT      0x0020
 #define BDRV_O_AUTOGROW    0x0040 /* Allow backing file to extend when writing past end of file */
 
-void bdrv_info(void);
+void bdrv_init(int emulate_aio);
 void bdrv_info_stats(void);
 
-void bdrv_init(void);
 BlockDriver *bdrv_find_format(const char *format_name);
 int bdrv_create(BlockDriver *drv,
                 const char *filename, int64_t size_in_sectors,
Index: qemu/block.c
@@ -177,9 +177,9 @@
 }
 
 
-static void bdrv_register(BlockDriver *bdrv)
+static void bdrv_register(BlockDriver *bdrv, int emulate_aio)
 {
-    if (!bdrv->bdrv_aio_read) {
+    if (!bdrv->bdrv_aio_read || emulate_aio) {
         /* add AIO emulation layer */
         bdrv->bdrv_aio_read = bdrv_aio_read_em;
         bdrv->bdrv_aio_write = bdrv_aio_write_em;
@@ -1374,23 +1374,23 @@
     return async_ret;
 }
 
-void bdrv_init(void)
+void bdrv_init(int emulate_aio)
 {
-    bdrv_register(&bdrv_raw);
-    bdrv_register(&bdrv_host_device);
+    bdrv_register(&bdrv_raw, emulate_aio);
+    bdrv_register(&bdrv_host_device, 0);
 #ifndef _WIN32
-    bdrv_register(&bdrv_cow);
+    bdrv_register(&bdrv_cow, 0);
 #endif
-    bdrv_register(&bdrv_qcow);
-    bdrv_register(&bdrv_vmdk);
-    bdrv_register(&bdrv_cloop);
-    bdrv_register(&bdrv_dmg);
-    bdrv_register(&bdrv_bochs);
-    bdrv_register(&bdrv_vpc);
-    bdrv_register(&bdrv_vvfat);
-    bdrv_register(&bdrv_qcow2);
-    bdrv_register(&bdrv_parallels);
-    bdrv_register(&bdrv_nbd);
+    bdrv_register(&bdrv_qcow, 0);
+    bdrv_register(&bdrv_vmdk, 0);
+    bdrv_register(&bdrv_cloop, 0);
+    bdrv_register(&bdrv_dmg, 0);
+    bdrv_register(&bdrv_bochs, 0);
+    bdrv_register(&bdrv_vpc, 0);
+    bdrv_register(&bdrv_vvfat, 0);
+    bdrv_register(&bdrv_qcow2, 0);
+    bdrv_register(&bdrv_parallels, 0);
+    bdrv_register(&bdrv_nbd, 0);
 }
 
 void *qemu_aio_get(BlockDriverState *bs, BlockDriverCompletionFunc *cb,
Index: qemu/vl.c
@@ -8609,6 +8609,7 @@
     int tb_size;
     const char *pid_file = NULL;
     VLANState *vlan;
+    int emulate_aio = 0;
 
     LIST_INIT (&vm_change_state_head);
 #ifndef _WIN32
@@ -8681,6 +8682,13 @@
 
     tb_size = 0;
     
+#ifdef __FreeBSD__
+    if (modfind("aio") == -1) {
+        emulate_aio = 1;
+        fprintf(stderr, "warning: aio not (kld)loaded, disabling (may slow down on disk IO\n");
+    }
+#endif
+
     optind = 1;
     for(;;) {
         if (optind >= argc)
@@ -9415,7 +9423,7 @@
     /* init the dynamic translator */
     cpu_exec_init_all(tb_size * 1024 * 1024);
 
-    bdrv_init();
+    bdrv_init(emulate_aio);
 
     /* we always create the cdrom drive, even if no disk is there */
 
Index: qemu/qemu-img.c
@@ -733,7 +733,7 @@
 {
     const char *cmd;
 
-    bdrv_init();
+    bdrv_init(1);
     if (argc < 2)
         help();
     cmd = argv[1];
Index: qemu/qemu-nbd.c
@@ -326,7 +326,7 @@
 	return 0;
     }
 
-    bdrv_init();
+    bdrv_init(0);
 
     bs = bdrv_new("hda");
     if (bs == NULL)

Signed-off-by: Juergen Lock <nox@jelal.kn-bremen.de>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200809272252.m8RMq4fu057049>