diff options
author | Simon Rettberg | 2022-02-12 23:56:35 +0100 |
---|---|---|
committer | Simon Rettberg | 2022-02-18 21:34:55 +0100 |
commit | eb2876f6542af2bfa47c7a6905ecc4f81f1d2ad3 (patch) | |
tree | 17ebb5fd2d4770a4dd67f857f2488221cd46874c /src/kernel/blk.h | |
parent | [KERNEL] Add missing include to fix compile on 4.14.x (diff) | |
download | dnbd3-eb2876f6542af2bfa47c7a6905ecc4f81f1d2ad3.tar.gz dnbd3-eb2876f6542af2bfa47c7a6905ecc4f81f1d2ad3.tar.xz dnbd3-eb2876f6542af2bfa47c7a6905ecc4f81f1d2ad3.zip |
[KERNEL] Refactor to use workqueues and blk-mq only
Using workqueues frees us from having to manage the lifecycle
of three dedicated threads. Discovery (alt server checks) and
sending keepalive packets is now done using work on the
power efficient system queue. Sending and receiving happens
via dedicated work queues with higher priority.
blk-mq has also been around for quite a while in the kernel,
so switching to it doesn't hurt backwards compatibility.
As the code is now refactored to work more as blk-mq is designed,
backwards compatibility even improved while at the same time
freeing us from an arsenal of macros that were required to make
the blk-mq port look and feel like the old implementation.
For example, the code now compiles on CentOS 7 with kernel 3.10
without requiring special macros to detect the heavily modified
RedHat kernel with all its backported features.
A few other design limitations have been rectified along the way,
e.g. switching to another server now doesn't internally disconnect
from the current one first, which theoretically could lead to a
non-working setup, if the new server isn't reachable and then -
because of some transient network error - switching back also
fails. As the discover-thread was torn down from the disconnect
call, the connection would also not repair itself eventually.
we now establish the new connection in parallel to the old one,
and only if that succeeds do we replace the old one with it,
similar to how the automatic alt-server switch already does it.
Diffstat (limited to 'src/kernel/blk.h')
-rw-r--r-- | src/kernel/blk.h | 97 |
1 files changed, 4 insertions, 93 deletions
diff --git a/src/kernel/blk.h b/src/kernel/blk.h index cbab6f5..c6dcb8d 100644 --- a/src/kernel/blk.h +++ b/src/kernel/blk.h @@ -24,104 +24,15 @@ #include "dnbd3_main.h" -/* 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(5, 14, 0) -#define dnbd3_req_special(req) \ - (dnbd3_req_op(req) == DNBD3_REQ_OP_SPECIAL) -#elif 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 +// The device has been set up via IOCTL_OPEN and hasn't been closed yet +#define device_active(dev) ((dev)->reported_size != 0) int dnbd3_blk_add_device(dnbd3_device_t *dev, int minor); int dnbd3_blk_del_device(dnbd3_device_t *dev); +void dnbd3_blk_requeue_all_requests(dnbd3_device_t *dev); + void dnbd3_blk_fail_all_requests(dnbd3_device_t *dev); #endif /* BLK_H_ */ |