path: root/include/linux/aio.h
diff options
authorKent Overstreet <>2013-10-10 20:50:11 -0700
committerKent Overstreet <>2013-10-10 20:50:46 -0700
commit87f98e774776d0f3e1214b61123b34de53e63e94 (patch)
tree7ab1b4f81329487991cb519bc3182bd72cdc6b06 /include/linux/aio.h
parent8613f0c75e242dd806ae7b84c67e1761a0ed6a9d (diff)
block: Bio cancellationaio
If a bio is associated with a kiocb, allow it to be cancelled. This is accomplished by adding a pointer to a kiocb in struct bio, and when we go to dequeue a request we check if its bio has been cancelled - if so, we end the request with -ECANCELED. We don't currently try to cancel bios if IO has already been started - that'd require a per bio callback function, and a way to find all the outstanding bios for a given kiocb. Such a mechanism may or may not be added in the future but this patch tries to start simple. Currently this can only be triggered with aio and io_cancel(), but the mechanism can be used for sync io too. It can also be used for bios created by stacking drivers, and bio clones in general - when cloning a bio, if the bi_iocb pointer is copied as well the clone will then be cancellable. bio_clone() could be modified to do this, but hasn't in this patch because all the bio_clone() users would need to be auditied to make sure that it's safe. We can't blindly make e.g. raid5 writes cancellable without the knowledge of the md code. Initial patch by Anatol Pomazau ( Signed-off-by: Kent Overstreet <> Cc: Zach Brown <> Cc: Joel Becker <> Cc: Jens Axboe <> Cc: Jeff Moyer <> Cc: Al Viro <> Cc: Benjamin LaHaise <>
Diffstat (limited to 'include/linux/aio.h')
1 files changed, 8 insertions, 0 deletions
diff --git a/include/linux/aio.h b/include/linux/aio.h
index 985e664fb05d..9c3cfc551c64 100644
--- a/include/linux/aio.h
+++ b/include/linux/aio.h
@@ -8,6 +8,7 @@
#include <linux/rcupdate.h>
#include <linux/atomic.h>
#include <linux/batch_complete.h>
+#include <linux/blk_types.h>
struct kioctx;
struct kiocb;
@@ -105,6 +106,13 @@ static inline bool kiocb_cancelled(struct kiocb *kiocb)
return kiocb->ki_cancel == KIOCB_CANCELLED;
+static inline bool bio_cancelled(struct bio *bio)
+ return bio->bi_iocb && kiocb_cancelled(bio->bi_iocb);
static inline bool is_sync_kiocb(struct kiocb *kiocb)
return kiocb->ki_ctx == NULL;