[5187] Use signalfd() to work around signal/select race
Revision: 5187
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5187 Author: aliguori Date: 2008-09-10 15:45:19 +0000 (Wed, 10 Sep 2008)
Log Message:
-----------
Use signalfd() to work around signal/select race
This patch introduces signalfd() to work around the signal/select race in checking for AIO completions. For platforms that don't support signalfd(), we emulate it with threads.
There was a long discussion about this approach. I don't believe there are any fundamental problems with this approach and I believe eliminating the use of signals is a good thing.
I've tested Windows and Linux using Windows and Linux guests. I've also checked for disk IO performance regressions.
Modified Paths:
--------------
trunk/Makefile
trunk/Makefile.target
trunk/block-raw-posix.c
trunk/block-raw-win32.c
trunk/block.c
trunk/block.h
trunk/vl.cModified: trunk/Makefile
===================================================================
Makefile +2 -2
@@ -177,7 +177,7 @@ ifdef CONFIG_WIN32 QEMU_IMG_BLOCK_OBJS += qemu-img-block-raw-win32.o else -QEMU_IMG_BLOCK_OBJS += nbd.o qemu-img-block-raw-posix.o +QEMU_IMG_BLOCK_OBJS += nbd.o qemu-img-block-raw-posix.o compatfd.o endif ######################################################################
@@ -195,7 +195,7 @@ $(CC) $(CFLAGS) $(CPPFLAGS) -DQEMU_NBD -c -o $@ $< qemu-nbd$(EXESUF): qemu-nbd.o qemu-nbd-nbd.o qemu-img-block.o \ - osdep.o qemu-nbd-block-raw-posix.o $(BLOCK_OBJS) + osdep.o qemu-nbd-block-raw-posix.o compatfd.o $(BLOCK_OBJS) $(CC) $(LDFLAGS) -o $@ $^ -lz $(LIBS) # dyngen host tool
Modified: trunk/Makefile.target
===================================================================
Makefile.target +1 -1
@@ -476,7 +476,7 @@ ifdef CONFIG_WIN32 OBJS+=block-raw-win32.o else -OBJS+=block-raw-posix.o +OBJS+=block-raw-posix.o compatfd.o endif LIBS+=-lz
Modified: trunk/block-raw-posix.c
===================================================================
block-raw-posix.c +48 -81
186 lines not on this page · raw message
Modified: trunk/block-raw-win32.c
===================================================================
block-raw-win32.c +0 -12
@@ -350,18 +350,10 @@ { } -void qemu_aio_poll (void ) -{ -} -void qemu_aio_flush (void ) { } -void qemu_aio_wait_start (void ) -{ -} -void qemu_aio_wait (void ) {#ifndef QEMU_IMG
@@ -369,10 +361,6 @@#endif } -void qemu_aio_wait_end (void ) -{ -} -BlockDriver bdrv_raw = {"raw" ,sizeof (BDRVRawState),
Modified: trunk/block.c
===================================================================
block.c +4 -10
@@ -1280,17 +1280,15 @@BlockDriverAIOCB *acb; async_ret =NOT_DONE ; -qemu_aio_wait_start (); acb =bdrv_aio_read (bs, sector_num, buf, nb_sectors, bdrv_rw_em_cb, &async_ret); -if (acb ==NULL ) { -qemu_aio_wait_end (); +if (acb ==NULL )return -1 ; - } +while (async_ret ==NOT_DONE ) {qemu_aio_wait (); } -qemu_aio_wait_end (); +return async_ret; }
@@ -1301,17 +1299,13 @@BlockDriverAIOCB *acb; async_ret =NOT_DONE ; -qemu_aio_wait_start (); acb =bdrv_aio_write (bs, sector_num, buf, nb_sectors, bdrv_rw_em_cb, &async_ret); -if (acb ==NULL ) { -qemu_aio_wait_end (); +if (acb ==NULL )return -1 ; - }while (async_ret ==NOT_DONE ) {qemu_aio_wait (); } -qemu_aio_wait_end ();return async_ret; }
Modified: trunk/block.h
===================================================================
block.h +0 -3
@@ -90,11 +90,8 @@void bdrv_aio_cancel (BlockDriverAIOCB *acb);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 ); -void qemu_aio_wait_end (void );int qemu_key_check (BlockDriverState *bs,const char *name);
Modified: trunk/vl.c
===================================================================
vl.c +0 -1
@@ -7482,7 +7482,6 @@ slirp_select_poll(&rfds, &wfds, &xfds); }#endif -qemu_aio_poll ();if (vm_running) {if (likely (!(cur_cpu->singlestep_enabled &SSTEP_NOTIMER )))
Quoted 24 lines · Anthony Liguori
Revision: 5187
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5187Author: aliguori
Date: 2008-09-10 15:45:19 +0000 (Wed, 10 Sep 2008)Log Message:
-----------
Usesignalfd()to work around signal/select raceThis patch introduces
signalfd()to work around the signal/select race in checking for AIO completions. For platforms that don't supportsignalfd(), we emulate it with threads.There was a long discussion about this approach. I don't believe there are any fundamental problems with this approach and I believe eliminating the use of signals is a good thing.
I've tested Windows and Linux using Windows and Linux guests. I've also checked for disk IO performance regressions.
Signed-off-by Anthony Liguori <[email protected]>Modified Paths:
--------------
Quoted 7 lines
trunk/Makefile
trunk/Makefile.target
trunk/block-raw-posix.c
trunk/block-raw-win32.c
trunk/block.c
trunk/block.h
trunk/vl.cThe file compatfd.h is missing.
Quoted 33 lines · Blue Swirl
Quoted 22 lines · Anthony Liguori
Revision: 5187
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5187 Author: aliguori Date: 2008-09-10 15:45:19 +0000 (Wed, 10 Sep 2008)Log Message:
-----------
Usesignalfd()to work around signal/select raceThis patch introduces
signalfd()to work around the signal/select race in checking for AIO completions. For platforms that don't supportsignalfd(), we emulate it with threads.There was a long discussion about this approach. I don't believe there are any fundamental problems with this approach and I believe eliminating the use of signals is a good thing.
I've tested Windows and Linux using Windows and Linux guests. I've also checked for disk IO performance regressions.
Signed-off-by Anthony Liguori <[email protected]>Quoted 9 lines
Modified Paths:
--------------
trunk/Makefile
trunk/Makefile.target
trunk/block-raw-posix.c
trunk/block-raw-win32.c
trunk/block.c
trunk/block.h
trunk/vl.c
Quoted 2 lines
The file
compatfd.his missing.
And possible compatfd.c
Quoted 4 lines · Blue Swirl
On 9/10/08, Anthony Liguori <[email protected]> wrote:
The file
compatfd.his missing.
Ugh, sorry about that!
Regards,
Anthony Liguori
Quoted 8 lines · Anthony Liguori
Revision: 5187
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5187 Author: aliguori Date: 2008-09-10 15:45:19 +0000 (Wed, 10 Sep 2008)Log Message:
-----------
Usesignalfd()to work around signal/select race
This commit breaks qemu-nbd:
# ./qemu-nbd --port 1024 --persistent ../disk.qcow2 generates "Bus error" when I connect the client: # ./x86_64-softmmu/qemu-system-x86_64 -hda ../etch64.qcow2 -hdb nbd:localhost:1024
* gdb output:
Program received signal SIGBUS, Bus error.
[Switching to Thread 0x7f3accdf76e0 (LWP 13146)]qemu_aio_wait () at block-raw-posix.c:541
541 FD_SET(aio_sig_fd, &rdfds);
(gdb) bt
#0 qemu_aio_wait () at block-raw-posix.c:541
#1 0x0000000000406245 in bdrv_read_em (bs=0x0,
sector_num=140736764918416,
buf=0x8000000000000000 <Address 0x8000000000000000 out of bounds>,
nb_sectors=0) at block.c:1289
#2 0x000000000040437a in nbd_trip (bs=0x622010, csock=8,
size=6442450944,
dev_offset=0, offset=0x7fffd4e13c78, readonly=false,
data=0x7f3acccd5200 "�H\220м", data_size=1048576) at nbd.c:573#3 0x0000000000402d11 in main (argc=1, argv=0x1) at qemu-nbd.c:444
Laurent
Signature · 3 lines
----------------- [email protected] ------------------ "La perfection est atteinte non quand il ne reste rien à ajouter mais quand il ne reste rien à enlever." Saint Exupéry
Quoted 28 lines · Laurent Vivier
Quoted 9 lines · Anthony Liguori
Revision: 5187
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5187 Author: aliguori Date: 2008-09-10 15:45:19 +0000 (Wed, 10 Sep 2008)Log Message:
-----------
Usesignalfd()to work around signal/select raceThis commit breaks qemu-nbd:
# ./qemu-nbd --port 1024 --persistent ../disk.qcow2 generates "Bus error" when I connect the client: # ./x86_64-softmmu/qemu-system-x86_64 -hda ../etch64.qcow2 -hdb nbd:localhost:1024* gdb output:
Program received signal SIGBUS, Bus error.
[Switching to Thread0x7f3accdf76e0(LWP 13146)]qemu_aio_wait() at block-raw-posix.c:541
541FD_SET(aio_sig_fd, &rdfds);
(gdb) bt
#0qemu_aio_wait() at block-raw-posix.c:541
#10x0000000000406245inbdrv_read_em(bs=0x0,
sector_num=140736764918416,
Quoted 8 lines
buf=0x8000000000000000 <Address 0x8000000000000000 out of bounds>, nb_sectors=0) at block.c:1289 #2 0x000000000040437a in nbd_trip (bs=0x622010, csock=8, size=6442450944, dev_offset=0, offset=0x7fffd4e13c78, readonly=false, data=0x7f3acccd5200 "�H\220м", data_size=1048576) at nbd.c:573#3
0x0000000000402d11in main (argc=1, argv=0x1) at qemu-nbd.c:444
That's because qemu-nbd isn't doing an qemu_aio_init(). There still appears to be an issue though because qemu_aio_wait() doesn't ever returning. I'm looking into it right now.
Regards,
Anthony Liguori
Quoted 2 lines
Laurent
Quoted 28 lines · Laurent Vivier
Quoted 9 lines · Anthony Liguori
Revision: 5187
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5187 Author: aliguori Date: 2008-09-10 15:45:19 +0000 (Wed, 10 Sep 2008)Log Message:
-----------
Usesignalfd()to work around signal/select raceThis commit breaks qemu-nbd:
# ./qemu-nbd --port 1024 --persistent ../disk.qcow2 generates "Bus error" when I connect the client: # ./x86_64-softmmu/qemu-system-x86_64 -hda ../etch64.qcow2 -hdb nbd:localhost:1024* gdb output:
Program received signal SIGBUS, Bus error.
[Switching to Thread0x7f3accdf76e0(LWP 13146)]qemu_aio_wait() at block-raw-posix.c:541
541FD_SET(aio_sig_fd, &rdfds);
(gdb) bt
#0qemu_aio_wait() at block-raw-posix.c:541
#10x0000000000406245inbdrv_read_em(bs=0x0,
sector_num=140736764918416,
Quoted 8 lines
buf=0x8000000000000000 <Address 0x8000000000000000 out of bounds>, nb_sectors=0) at block.c:1289 #2 0x000000000040437a in nbd_trip (bs=0x622010, csock=8, size=6442450944, dev_offset=0, offset=0x7fffd4e13c78, readonly=false, data=0x7f3acccd5200 "�H\220м", data_size=1048576) at nbd.c:573#3
0x0000000000402d11in main (argc=1, argv=0x1) at qemu-nbd.c:444
Should be fixed now. But the following is broken:
qemu-system-x86_64 -hda nbd:localhost:1024
That was broken before the signalfd stuff. My guest hangs after loading grub. You're command line probably suggests you knew that. Do you know why this is?
Regards,
Anthony Liguori
Quoted 2 lines
Laurent
Quoted 39 lines · Anthony Liguori
Quoted 29 lines · Laurent Vivier
Quoted 9 lines · Anthony Liguori
Revision: 5187
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5187 Author: aliguori Date: 2008-09-10 15:45:19 +0000 (Wed, 10 Sep 2008)Log Message:
-----------
Usesignalfd()to work around signal/select raceThis commit breaks qemu-nbd:
# ./qemu-nbd --port 1024 --persistent ../disk.qcow2 generates "Bus error" when I connect the client: # ./x86_64-softmmu/qemu-system-x86_64 -hda ../etch64.qcow2 -hdb nbd:localhost:1024* gdb output:
Program received signal SIGBUS, Bus error.
[Switching to Thread0x7f3accdf76e0(LWP 13146)]qemu_aio_wait() at block-raw-posix.c:541
541FD_SET(aio_sig_fd, &rdfds);
(gdb) bt
#0qemu_aio_wait() at block-raw-posix.c:541
#10x0000000000406245inbdrv_read_em(bs=0x0,
sector_num=140736764918416,Quoted 8 lines
buf=0x8000000000000000 <Address 0x8000000000000000 out of bounds>, nb_sectors=0) at block.c:1289 #2 0x000000000040437a in nbd_trip (bs=0x622010, csock=8, size=6442450944, dev_offset=0, offset=0x7fffd4e13c78, readonly=false, data=0x7f3acccd5200 "�H\220м", data_size=1048576) at nbd.c:573#3
0x0000000000402d11in main (argc=1, argv=0x1) at qemu-nbd.c:444
Quoted 1 line
Should be fixed now. But the following is broken:
Yes
Quoted 5 lines
qemu-system-x86_64 -hda nbd:localhost:1024
That was broken before the signalfd stuff. My guest hangs after loading grub. You're command line probably suggests you knew that. Do you know why this is?
It doesn't hang: it's just incredibly slow. Try "-socket /tmp/foo" instead of "-port 1024" (you can add "--verbose" to see it is alive...) or move the qemu-nbd to another server (with gigabit it's nice).
Laurent
Signature · 3 lines
----------------- [email protected] ------------------ "La perfection est atteinte non quand il ne reste rien à ajouter mais quand il ne reste rien à enlever." Saint Exupéry