Skip to content

Instantly share code, notes, and snippets.

@tuxoko
Created December 17, 2014 06:27
Show Gist options
  • Save tuxoko/671db4cd3b1cae77b07b to your computer and use it in GitHub Desktop.
Save tuxoko/671db4cd3b1cae77b07b to your computer and use it in GitHub Desktop.
diff --git a/include/sys/zio.h b/include/sys/zio.h
index e10e965..0ba6b65 100644
--- a/include/sys/zio.h
+++ b/include/sys/zio.h
@@ -383,6 +383,7 @@ typedef struct zio_link {
} zio_link_t;
struct zio {
+ int io_hold;
/* Core information about this I/O */
zbookmark_phys_t io_bookmark;
zio_prop_t io_prop;
diff --git a/module/zfs/zio.c b/module/zfs/zio.c
index 9d70b3e..c43355d 100644
--- a/module/zfs/zio.c
+++ b/module/zfs/zio.c
@@ -1454,6 +1454,11 @@ zio_wait(zio_t *zio)
cv_wait_io(&zio->io_cv, &zio->io_lock);
mutex_exit(&zio->io_lock);
+#ifdef _KERNEL
+ while (ACCESS_ONCE(zio->io_hold) != 0)
+ cpu_relax();
+#endif
+
error = zio->io_error;
zio_destroy(zio);
@@ -3328,8 +3333,14 @@ zio_done(zio_t *zio)
if (zio->io_waiter != NULL) {
mutex_enter(&zio->io_lock);
zio->io_executor = NULL;
+ zio->io_hold = 1;
cv_broadcast(&zio->io_cv);
mutex_exit(&zio->io_lock);
+ /* release hold after we make sure mutex exits */
+#ifdef _KERNEL
+ smp_mb();
+#endif
+ zio->io_hold = 0;
} else {
zio_destroy(zio);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment