]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - zfs/include/linux/blkdev_compat.h
UBUNTU: SAUCE: (noup) Update spl to 0.6.5.11-ubuntu1, zfs to 0.6.5.11-1ubuntu3
[mirror_ubuntu-artful-kernel.git] / zfs / include / linux / blkdev_compat.h
index 871506d7c924019192e17082ea9c6854c24f4b4c..f3054a375e0d5d73beddb6fc5fe4d7044cc1c9d4 100644 (file)
@@ -208,14 +208,104 @@ bio_set_flags_failfast(struct block_device *bdev, int *flags)
 #define        DISK_NAME_LEN   32
 #endif /* DISK_NAME_LEN */
 
+#ifdef HAVE_BIO_BI_STATUS
+static inline int
+bi_status_to_errno(blk_status_t status)
+{
+       switch (status) {
+       case BLK_STS_OK:
+               return (0);
+       case BLK_STS_NOTSUPP:
+               return (EOPNOTSUPP);
+       case BLK_STS_TIMEOUT:
+               return (ETIMEDOUT);
+       case BLK_STS_NOSPC:
+               return (ENOSPC);
+       case BLK_STS_TRANSPORT:
+               return (ENOLINK);
+       case BLK_STS_TARGET:
+               return (EREMOTEIO);
+       case BLK_STS_NEXUS:
+               return (EBADE);
+       case BLK_STS_MEDIUM:
+               return (ENODATA);
+       case BLK_STS_PROTECTION:
+               return (EILSEQ);
+       case BLK_STS_RESOURCE:
+               return (ENOMEM);
+       case BLK_STS_AGAIN:
+               return (EAGAIN);
+       case BLK_STS_IOERR:
+               return (EIO);
+       default:
+               return (EIO);
+       }
+}
+
+static inline blk_status_t
+errno_to_bi_status(int error)
+{
+       switch (error) {
+       case 0:
+               return (BLK_STS_OK);
+       case EOPNOTSUPP:
+               return (BLK_STS_NOTSUPP);
+       case ETIMEDOUT:
+               return (BLK_STS_TIMEOUT);
+       case ENOSPC:
+               return (BLK_STS_NOSPC);
+       case ENOLINK:
+               return (BLK_STS_TRANSPORT);
+       case EREMOTEIO:
+               return (BLK_STS_TARGET);
+       case EBADE:
+               return (BLK_STS_NEXUS);
+       case ENODATA:
+               return (BLK_STS_MEDIUM);
+       case EILSEQ:
+               return (BLK_STS_PROTECTION);
+       case ENOMEM:
+               return (BLK_STS_RESOURCE);
+       case EAGAIN:
+               return (BLK_STS_AGAIN);
+       case EIO:
+               return (BLK_STS_IOERR);
+       default:
+               return (BLK_STS_IOERR);
+       }
+}
+#endif /* HAVE_BIO_BI_STATUS */
+
 /*
  * 4.3 API change
  * The bio_endio() prototype changed slightly.  These are helper
  * macro's to ensure the prototype and invocation are handled.
  */
 #ifdef HAVE_1ARG_BIO_END_IO_T
+#ifdef HAVE_BIO_BI_STATUS
+#define        BIO_END_IO_ERROR(bio)           bi_status_to_errno(bio->bi_status)
+#define        BIO_END_IO_PROTO(fn, x, z)      static void fn(struct bio *x)
+#define        BIO_END_IO(bio, error)          bio_set_bi_status(bio, error)
+static inline void
+bio_set_bi_status(struct bio *bio, int error)
+{
+       ASSERT3S(error, <=, 0);
+       bio->bi_status = errno_to_bi_status(-error);
+       bio_endio(bio);
+}
+#else
+#define        BIO_END_IO_ERROR(bio)           (-(bio->bi_error))
 #define        BIO_END_IO_PROTO(fn, x, z)      static void fn(struct bio *x)
-#define        BIO_END_IO(bio, error)          bio->bi_error = error; bio_endio(bio);
+#define        BIO_END_IO(bio, error)          bio_set_bi_error(bio, error)
+static inline void
+bio_set_bi_error(struct bio *bio, int error)
+{
+       ASSERT3S(error, <=, 0);
+       bio->bi_error = error;
+       bio_endio(bio);
+}
+#endif /* HAVE_BIO_BI_STATUS */
+
 #else
 #define        BIO_END_IO_PROTO(fn, x, z)      static void fn(struct bio *x, int z)
 #define        BIO_END_IO(bio, error)          bio_endio(bio, error);