Use signalfd() to work around signal/select race
RFC PATCH 1/1 Use signalfd() to work around signal/select race
Here's my patch to work around the signal/select race. I think it cleans up the code quite nicely. While signalfd() is Linux-bias, I think it's a nice interface and the emulation isn't too bad.
I've only lightly tested. I'm looking to see what people's reaction would be to this.
Makefile +2 -2
@@ -177,7 +177,7 @@ QEMU_IMG_BLOCK_OBJS = $(BLOCK_OBJS) 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 @@ qemu-nbd-%.o: %.c $(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
Makefile.target +1 -1
@@ -476,7 +476,7 @@ OBJS=vl.o osdep.o monitor.o pci.o loader.o isa_mmio.o machine.o net-checksum.o ifdef CONFIG_WIN32 OBJS+=block-raw-win32.o else -OBJS+=block-raw-posix.o +OBJS+=block-raw-posix.o compatfd.o endif LIBS+=-lz
block-raw-posix.c +48 -81
185 lines not on this page · raw message
block-raw-win32.c +0 -12
@@ -350,18 +350,10 @@ 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_IMG
@@ -369,10 +361,6 @@ void qemu_aio_wait(void)#endif } -void qemu_aio_wait_end (void ) -{ -} -BlockDriver bdrv_raw = {"raw" ,sizeof (BDRVRawState),
block.c +4 -10
@@ -1281,17 +1281,15 @@ static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num,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; }
@@ -1302,17 +1300,13 @@ static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,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; }
block.h +0 -3
@@ -90,11 +90,8 @@ BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,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);
compatfd.c new file +128 -0
128 lines not on this page · raw message
vl.c +0 -1
@@ -7470,7 +7470,6 @@ void main_loop_wait(int timeout) slirp_select_poll(&rfds, &wfds, &xfds); }#endif -qemu_aio_poll ();if (vm_running) {if (likely (!(cur_cpu->singlestep_enabled &SSTEP_NOTIMER )))
Anthony Liguori writes ("[PATCH][RFC] Use signalfd() to work around signal/select race"):
Quoted 6 lines
Here's my patch to work around the signal/select race. I think it cleans up the code quite nicely. While
signalfd()is Linux-bias, I think it's a nice interface and the emulation isn't too bad.I've only lightly tested. I'm looking to see what people's reaction would be to this.
For the avoidance of any doubt, following my criticisms of Anthony's
approach: I think it's essential that we have at least one of Anthony's or my fixes to this problem.
Obviously I prefer my patch because I wrote it, but other people might prefer it because it's textually much smaller, closer to the existing code, and doesn't use threads.
Also, my patch has been pretty thoroughly tested, including some performance stress testing, as part of the Xen 3.3.0 release.
Ian.
Quoted 14 lines · Ian Jackson
Anthony Liguori writes ("[PATCH][RFC] Use
signalfd()to work around signal/select race"):Quoted 7 lines
Here's my patch to work around the signal/select race. I think it cleans up the code quite nicely. While
signalfd()is Linux-bias, I think it's a nice interface and the emulation isn't too bad.I've only lightly tested. I'm looking to see what people's reaction would be to this.
For the avoidance of any doubt, following my criticisms of Anthony's
approach: I think it's essential that we have at least one of Anthony's or my fixes to this problem.
Quoted 7 lines
Obviously I prefer my patch because I wrote it, but other people might prefer it because it's textually much smaller, closer to the existing code, and doesn't use threads.
Also, my patch has been pretty thoroughly tested, including some performance stress testing, as part of the Xen 3.3.0 release.
FWIW, I still don't see your patch. It's not on gmane so I don't think it's a problem on my side.
Regards,
Anthony Liguori
Quoted 2 lines
Ian.
Anthony Liguori writes ("Re: [PATCH][RFC] Use signalfd() to work around signal/select race"):
Quoted 2 lines
FWIW, I still don't see your patch. It's not on gmane so I don't think it's a problem on my side.
Thanks for pointing that out. git-format-patch had written a random hex number in the From_ line. formail didn't strip it out as I was hoping. exim took it as the envelope sender. Presumably Citrix's M$ mail system then offered it to lists.nongnu.org which rejected it, and probably Citrix's system then discarded it. Adding -f to my sendmail invocation seems to have done the trick.
Ian.