]> git.proxmox.com Git - mirror_zfs-debian.git/blobdiff - include/linux/blkdev_compat.h
New upstream version 0.7.2
[mirror_zfs-debian.git] / include / linux / blkdev_compat.h
index 871506d7c924019192e17082ea9c6854c24f4b4c..c8a8e856dee533c21233a8ebb31cd2741ff31106 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <linux/blkdev.h>
 #include <linux/elevator.h>
+#include <linux/backing-dev.h>
 
 #ifndef HAVE_FMODE_T
 typedef unsigned __bitwise__ fmode_t;
@@ -128,6 +129,16 @@ __blk_queue_max_segments(struct request_queue *q, unsigned short max_segments)
 }
 #endif
 
+static inline void
+blk_queue_set_read_ahead(struct request_queue *q, unsigned long ra_pages)
+{
+#ifdef HAVE_BLK_QUEUE_BDI_DYNAMIC
+       q->backing_dev_info->ra_pages = ra_pages;
+#else
+       q->backing_dev_info.ra_pages = ra_pages;
+#endif
+}
+
 #ifndef HAVE_GET_DISK_RO
 static inline int
 get_disk_ro(struct gendisk *disk)
@@ -145,6 +156,7 @@ get_disk_ro(struct gendisk *disk)
 #define        BIO_BI_SECTOR(bio)      (bio)->bi_iter.bi_sector
 #define        BIO_BI_SIZE(bio)        (bio)->bi_iter.bi_size
 #define        BIO_BI_IDX(bio)         (bio)->bi_iter.bi_idx
+#define        BIO_BI_SKIP(bio)        (bio)->bi_iter.bi_bvec_done
 #define        bio_for_each_segment4(bv, bvp, b, i)    \
        bio_for_each_segment((bv), (b), (i))
 typedef struct bvec_iter bvec_iterator_t;
@@ -152,6 +164,7 @@ typedef struct bvec_iter bvec_iterator_t;
 #define        BIO_BI_SECTOR(bio)      (bio)->bi_sector
 #define        BIO_BI_SIZE(bio)        (bio)->bi_size
 #define        BIO_BI_IDX(bio)         (bio)->bi_idx
+#define        BIO_BI_SKIP(bio)        (0)
 #define        bio_for_each_segment4(bv, bvp, b, i)    \
        bio_for_each_segment((bvp), (b), (i))
 typedef int bvec_iterator_t;
@@ -208,14 +221,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);
@@ -349,8 +452,6 @@ bio_set_flush(struct bio *bio)
        bio_set_op_attrs(bio, 0, WRITE_BARRIER);
 #else
 #error "Allowing the build will cause bio_set_flush requests to be ignored."
-       "Please file an issue report at: "
-       "https://github.com/zfsonlinux/zfs/issues/new"
 #endif
 }
 
@@ -388,8 +489,7 @@ bio_is_flush(struct bio *bio)
 #elif defined(HAVE_BIO_RW_BARRIER)
        return (bio->bi_rw & (1 << BIO_RW_BARRIER));
 #else
-#error "Allowing the build will cause flush requests to be ignored. Please "
-       "file an issue report at: https://github.com/zfsonlinux/zfs/issues/new"
+#error "Allowing the build will cause flush requests to be ignored."
 #endif
 }
 
@@ -408,8 +508,7 @@ bio_is_fua(struct bio *bio)
 #elif defined(REQ_FUA)
        return (bio->bi_rw & REQ_FUA);
 #else
-#error "Allowing the build will cause fua requests to be ignored. Please "
-       "file an issue report at: https://github.com/zfsonlinux/zfs/issues/new"
+#error "Allowing the build will cause fua requests to be ignored."
 #endif
 }
 
@@ -440,9 +539,8 @@ bio_is_discard(struct bio *bio)
 #elif defined(REQ_DISCARD)
        return (bio->bi_rw & REQ_DISCARD);
 #else
-#error "Allowing the build will cause discard requests to become writes "
-       "potentially triggering the DMU_MAX_ACCESS assertion. Please file "
-       "an issue report at: https://github.com/zfsonlinux/zfs/issues/new"
+/* potentially triggering the DMU_MAX_ACCESS assertion.  */
+#error "Allowing the build will cause discard requests to become writes."
 #endif
 }
 
@@ -500,9 +598,26 @@ blk_queue_discard_granularity(struct request_queue *q, unsigned int dg)
  */
 #define        VDEV_HOLDER                     ((void *)0x2401de7)
 
-#ifndef HAVE_GENERIC_IO_ACCT
-#define        generic_start_io_acct(rw, slen, part)           ((void)0)
-#define        generic_end_io_acct(rw, part, start_jiffies)    ((void)0)
+static inline void
+blk_generic_start_io_acct(struct request_queue *q, int rw,
+    unsigned long sectors, struct hd_struct *part)
+{
+#if defined(HAVE_GENERIC_IO_ACCT_3ARG)
+       generic_start_io_acct(rw, sectors, part);
+#elif defined(HAVE_GENERIC_IO_ACCT_4ARG)
+       generic_start_io_acct(q, rw, sectors, part);
 #endif
+}
+
+static inline void
+blk_generic_end_io_acct(struct request_queue *q, int rw,
+    struct hd_struct *part, unsigned long start_time)
+{
+#if defined(HAVE_GENERIC_IO_ACCT_3ARG)
+       generic_end_io_acct(rw, part, start_time);
+#elif defined(HAVE_GENERIC_IO_ACCT_4ARG)
+       generic_end_io_acct(q, rw, part, start_time);
+#endif
+}
 
 #endif /* _ZFS_BLKDEV_H */