diff options
author | Manuel Bentele | 2021-06-15 12:26:14 +0200 |
---|---|---|
committer | Manuel Bentele | 2021-06-16 11:41:00 +0200 |
commit | 75e9f49df8ff7f00a2c28ee1e30f1d87bcce4bca (patch) | |
tree | 8e07b51378028acb2edaeceba31f79f67c464084 /src/kernel/blk.h | |
parent | server.conf: Update uplinkTimeout to match default value (diff) | |
download | dnbd3-75e9f49df8ff7f00a2c28ee1e30f1d87bcce4bca.tar.gz dnbd3-75e9f49df8ff7f00a2c28ee1e30f1d87bcce4bca.tar.xz dnbd3-75e9f49df8ff7f00a2c28ee1e30f1d87bcce4bca.zip |
[KERNEL] Add support for Linux kernels without blk-mq (e.g. CentOS 7)
Diffstat (limited to 'src/kernel/blk.h')
-rw-r--r-- | src/kernel/blk.h | 91 |
1 files changed, 90 insertions, 1 deletions
diff --git a/src/kernel/blk.h b/src/kernel/blk.h index 2410fe1..2da84bc 100644 --- a/src/kernel/blk.h +++ b/src/kernel/blk.h @@ -24,7 +24,96 @@ #include "dnbd3_main.h" -#define REQ_TYPE_SPECIAL REQ_TYPE_DRV_PRIV +/* define blkdev file system operation type */ +#define DNBD3_REQ_OP_FS REQ_TYPE_FS + +/* define blkdev special operation type */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) +#define DNBD3_REQ_OP_SPECIAL REQ_OP_DRV_IN +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0) || \ + RHEL_CHECK_VERSION(RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 3)) +#define DNBD3_REQ_OP_SPECIAL REQ_TYPE_DRV_PRIV +#else +#define DNBD3_REQ_OP_SPECIAL REQ_TYPE_SPECIAL +#endif + +/* define blkdev read operation type */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) +#define DNBD3_DEV_READ REQ_OP_READ +#else +#define DNBD3_DEV_READ DNBD3_REQ_OP_FS +#endif + +/* define blkdev write operation type */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) +#define DNBD3_DEV_WRITE REQ_OP_WRITE +#else +#define DNBD3_DEV_WRITE DNBD3_REQ_OP_FS +#endif + +/* define command and blkdev operation access macros */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) +#define DNBD3_REQ_FLAG_BITS REQ_FLAG_BITS +/* cmd_flags and cmd_type are merged into cmd_flags now */ +/* sanity check to avoid overriding of request bits */ +#if DNBD3_REQ_FLAG_BITS > 24 +#error "Fix CMD bitshift" +#endif +/* pack command into cmd_flags field by shifting CMD_* into unused bits of cmd_flags */ +#define dnbd3_cmd_to_priv(req, cmd) \ + ((req)->cmd_flags = DNBD3_REQ_OP_SPECIAL | ((cmd) << DNBD3_REQ_FLAG_BITS)) +#define dnbd3_priv_to_cmd(req) \ + ((req)->cmd_flags >> DNBD3_REQ_FLAG_BITS) +#define dnbd3_req_op(req) \ + req_op(req) +#else +/* pack command into cmd_type and cmd_flags field separated */ +#define dnbd3_cmd_to_priv(req, cmd) \ + do { \ + (req)->cmd_type = DNBD3_REQ_OP_SPECIAL; \ + (req)->cmd_flags = (cmd); \ + } while (0) +#define dnbd3_priv_to_cmd(req) \ + ((req)->cmd_flags) +#define dnbd3_req_op(req) \ + ((req)->cmd_type) +#endif + +/* define dnbd3_req_read(req) boolean expression */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) +#define dnbd3_req_read(req) \ + (req_op(req) == DNBD3_DEV_READ) +#else +#define dnbd3_req_read(req) \ + (rq_data_dir(req) == READ) +#endif + +/* define dnbd3_req_write(req) boolean expression */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) +#define dnbd3_req_write(req) \ + (req_op(req) == DNBD3_DEV_WRITE) +#else +#define dnbd3_req_write(req) \ + (rq_data_dir(req) == WRITE) +#endif + +/* define dnbd3_req_fs(req) boolean expression */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) +#define dnbd3_req_fs(req) \ + (dnbd3_req_read(req) || dnbd3_req_write(req)) +#else +#define dnbd3_req_fs(req) \ + (dnbd3_req_op(req) == DNBD3_REQ_OP_FS) +#endif + +/* define dnbd3_req_special(req) boolean expression */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) +#define dnbd3_req_special(req) \ + blk_rq_is_private(req) +#else +#define dnbd3_req_special(req) \ + (dnbd3_req_op(req) == DNBD3_REQ_OP_SPECIAL) +#endif int dnbd3_blk_add_device(dnbd3_device_t *dev, int minor); |