Commit a839180e authored by Jean-Philippe Brucker's avatar Jean-Philippe Brucker Committed by Will Deacon
Browse files

disk/aio: Cancel AIO thread on cleanup



If the AIO thread is still calling io_getevents() while the exit path
calls io_destroy(), it will segfault. Wait for the thread to finish before
destroying the context.

Reviewed-by: Andre Przywara's avatarAndre Przywara <andre.przywara@arm.com>
Signed-off-by: default avatarJean-Philippe Brucker <jean-philippe.brucker@arm.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
parent 200cb823
...@@ -99,7 +99,6 @@ static void *disk_aio_thread(void *param) ...@@ -99,7 +99,6 @@ static void *disk_aio_thread(void *param)
int disk_aio_setup(struct disk_image *disk) int disk_aio_setup(struct disk_image *disk)
{ {
int r; int r;
pthread_t thread;
/* No need to setup AIO if the disk ops won't make use of it */ /* No need to setup AIO if the disk ops won't make use of it */
if (!disk->ops->async) if (!disk->ops->async)
...@@ -110,7 +109,7 @@ int disk_aio_setup(struct disk_image *disk) ...@@ -110,7 +109,7 @@ int disk_aio_setup(struct disk_image *disk)
return -errno; return -errno;
io_setup(AIO_MAX, &disk->ctx); io_setup(AIO_MAX, &disk->ctx);
r = pthread_create(&thread, NULL, disk_aio_thread, disk); r = pthread_create(&disk->thread, NULL, disk_aio_thread, disk);
if (r) { if (r) {
r = -errno; r = -errno;
close(disk->evt); close(disk->evt);
...@@ -126,6 +125,8 @@ void disk_aio_destroy(struct disk_image *disk) ...@@ -126,6 +125,8 @@ void disk_aio_destroy(struct disk_image *disk)
if (!disk->async) if (!disk->async)
return; return;
pthread_cancel(disk->thread);
pthread_join(disk->thread, NULL);
close(disk->evt); close(disk->evt);
io_destroy(disk->ctx); io_destroy(disk->ctx);
} }
...@@ -69,6 +69,7 @@ struct disk_image { ...@@ -69,6 +69,7 @@ struct disk_image {
#ifdef CONFIG_HAS_AIO #ifdef CONFIG_HAS_AIO
io_context_t ctx; io_context_t ctx;
int evt; int evt;
pthread_t thread;
#endif /* CONFIG_HAS_AIO */ #endif /* CONFIG_HAS_AIO */
const char *wwpn; const char *wwpn;
const char *tpgt; const char *tpgt;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment