Jack Wang | 90426e8 | 2020-05-11 15:51:22 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | /* |
| 3 | * RDMA Network Block Driver |
| 4 | * |
| 5 | * Copyright (c) 2014 - 2018 ProfitBricks GmbH. All rights reserved. |
| 6 | * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved. |
| 7 | * Copyright (c) 2019 - 2020 1&1 IONOS SE. All rights reserved. |
| 8 | */ |
| 9 | |
| 10 | #ifndef RNBD_CLT_H |
| 11 | #define RNBD_CLT_H |
| 12 | |
| 13 | #include <linux/wait.h> |
| 14 | #include <linux/in.h> |
| 15 | #include <linux/inet.h> |
| 16 | #include <linux/blk-mq.h> |
| 17 | #include <linux/refcount.h> |
| 18 | |
| 19 | #include <rtrs.h> |
| 20 | #include "rnbd-proto.h" |
| 21 | #include "rnbd-log.h" |
| 22 | |
Jack Wang | 90426e8 | 2020-05-11 15:51:22 +0200 | [diff] [blame] | 23 | /* time in seconds between reconnect tries, default to 30 s */ |
| 24 | #define RECONNECT_DELAY 30 |
| 25 | /* |
| 26 | * Number of times to reconnect on error before giving up, 0 for * disabled, |
| 27 | * -1 for forever |
| 28 | */ |
| 29 | #define MAX_RECONNECTS -1 |
| 30 | |
| 31 | enum rnbd_clt_dev_state { |
| 32 | DEV_STATE_INIT, |
| 33 | DEV_STATE_MAPPED, |
| 34 | DEV_STATE_MAPPED_DISCONNECTED, |
| 35 | DEV_STATE_UNMAPPED, |
| 36 | }; |
| 37 | |
| 38 | struct rnbd_iu_comp { |
| 39 | wait_queue_head_t wait; |
| 40 | int errno; |
| 41 | }; |
| 42 | |
Gioh Kim | 5a1328d | 2020-12-10 11:18:25 +0100 | [diff] [blame] | 43 | #ifdef CONFIG_ARCH_NO_SG_CHAIN |
| 44 | #define RNBD_INLINE_SG_CNT 0 |
| 45 | #else |
| 46 | #define RNBD_INLINE_SG_CNT 2 |
| 47 | #endif |
| 48 | #define RNBD_RDMA_SGL_SIZE (sizeof(struct scatterlist) * RNBD_INLINE_SG_CNT) |
| 49 | |
Jack Wang | 90426e8 | 2020-05-11 15:51:22 +0200 | [diff] [blame] | 50 | struct rnbd_iu { |
| 51 | union { |
| 52 | struct request *rq; /* for block io */ |
| 53 | void *buf; /* for user messages */ |
| 54 | }; |
| 55 | struct rtrs_permit *permit; |
| 56 | union { |
| 57 | /* use to send msg associated with a dev */ |
| 58 | struct rnbd_clt_dev *dev; |
| 59 | /* use to send msg associated with a sess */ |
| 60 | struct rnbd_clt_session *sess; |
| 61 | }; |
Gioh Kim | 5a1328d | 2020-12-10 11:18:25 +0100 | [diff] [blame] | 62 | struct sg_table sgt; |
Jack Wang | 90426e8 | 2020-05-11 15:51:22 +0200 | [diff] [blame] | 63 | struct work_struct work; |
| 64 | int errno; |
| 65 | struct rnbd_iu_comp comp; |
| 66 | atomic_t refcount; |
Gioh Kim | 5a1328d | 2020-12-10 11:18:25 +0100 | [diff] [blame] | 67 | struct scatterlist first_sgl[]; /* must be the last one */ |
Jack Wang | 90426e8 | 2020-05-11 15:51:22 +0200 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | struct rnbd_cpu_qlist { |
| 71 | struct list_head requeue_list; |
| 72 | spinlock_t requeue_lock; |
| 73 | unsigned int cpu; |
| 74 | }; |
| 75 | |
| 76 | struct rnbd_clt_session { |
| 77 | struct list_head list; |
| 78 | struct rtrs_clt *rtrs; |
| 79 | wait_queue_head_t rtrs_waitq; |
| 80 | bool rtrs_ready; |
| 81 | struct rnbd_cpu_qlist __percpu |
| 82 | *cpu_queues; |
| 83 | DECLARE_BITMAP(cpu_queues_bm, NR_CPUS); |
| 84 | int __percpu *cpu_rr; /* per-cpu var for CPU round-robin */ |
| 85 | atomic_t busy; |
Md Haris Iqbal | 80d43cb | 2021-04-28 08:13:56 +0200 | [diff] [blame] | 86 | size_t queue_depth; |
Jack Wang | 90426e8 | 2020-05-11 15:51:22 +0200 | [diff] [blame] | 87 | u32 max_io_size; |
Jack Wang | 7404bdd | 2021-06-21 07:53:40 +0200 | [diff] [blame] | 88 | u32 max_segments; |
Jack Wang | 90426e8 | 2020-05-11 15:51:22 +0200 | [diff] [blame] | 89 | struct blk_mq_tag_set tag_set; |
Gioh Kim | 2958a99 | 2021-04-19 09:37:16 +0200 | [diff] [blame] | 90 | u32 nr_poll_queues; |
Jack Wang | 90426e8 | 2020-05-11 15:51:22 +0200 | [diff] [blame] | 91 | struct mutex lock; /* protects state and devs_list */ |
| 92 | struct list_head devs_list; /* list of struct rnbd_clt_dev */ |
| 93 | refcount_t refcount; |
| 94 | char sessname[NAME_MAX]; |
| 95 | u8 ver; /* protocol version */ |
| 96 | }; |
| 97 | |
| 98 | /** |
| 99 | * Submission queues. |
| 100 | */ |
| 101 | struct rnbd_queue { |
| 102 | struct list_head requeue_list; |
| 103 | unsigned long in_list; |
| 104 | struct rnbd_clt_dev *dev; |
| 105 | struct blk_mq_hw_ctx *hctx; |
| 106 | }; |
| 107 | |
| 108 | struct rnbd_clt_dev { |
| 109 | struct rnbd_clt_session *sess; |
| 110 | struct request_queue *queue; |
| 111 | struct rnbd_queue *hw_queues; |
| 112 | u32 device_id; |
| 113 | /* local Idr index - used to track minor number allocations. */ |
| 114 | u32 clt_device_id; |
| 115 | struct mutex lock; |
| 116 | enum rnbd_clt_dev_state dev_state; |
Md Haris Iqbal | 64e8a6e | 2020-11-26 11:47:23 +0100 | [diff] [blame] | 117 | char *pathname; |
Jack Wang | 90426e8 | 2020-05-11 15:51:22 +0200 | [diff] [blame] | 118 | enum rnbd_access_mode access_mode; |
Gioh Kim | 2958a99 | 2021-04-19 09:37:16 +0200 | [diff] [blame] | 119 | u32 nr_poll_queues; |
Jack Wang | 90426e8 | 2020-05-11 15:51:22 +0200 | [diff] [blame] | 120 | bool read_only; |
| 121 | bool rotational; |
Gioh Kim | 512c781 | 2020-12-10 11:18:24 +0100 | [diff] [blame] | 122 | bool wc; |
| 123 | bool fua; |
Jack Wang | 90426e8 | 2020-05-11 15:51:22 +0200 | [diff] [blame] | 124 | u32 max_hw_sectors; |
| 125 | u32 max_write_same_sectors; |
| 126 | u32 max_discard_sectors; |
| 127 | u32 discard_granularity; |
| 128 | u32 discard_alignment; |
| 129 | u16 secure_discard; |
| 130 | u16 physical_block_size; |
| 131 | u16 logical_block_size; |
| 132 | u16 max_segments; |
| 133 | size_t nsectors; |
| 134 | u64 size; /* device size in bytes */ |
| 135 | struct list_head list; |
| 136 | struct gendisk *gd; |
| 137 | struct kobject kobj; |
Md Haris Iqbal | 64e8a6e | 2020-11-26 11:47:23 +0100 | [diff] [blame] | 138 | char *blk_symlink_name; |
Jack Wang | 90426e8 | 2020-05-11 15:51:22 +0200 | [diff] [blame] | 139 | refcount_t refcount; |
| 140 | struct work_struct unmap_on_rmmod_work; |
| 141 | }; |
| 142 | |
| 143 | /* rnbd-clt.c */ |
| 144 | |
| 145 | struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname, |
| 146 | struct rtrs_addr *paths, |
| 147 | size_t path_cnt, u16 port_nr, |
| 148 | const char *pathname, |
Gioh Kim | 2958a99 | 2021-04-19 09:37:16 +0200 | [diff] [blame] | 149 | enum rnbd_access_mode access_mode, |
| 150 | u32 nr_poll_queues); |
Jack Wang | 90426e8 | 2020-05-11 15:51:22 +0200 | [diff] [blame] | 151 | int rnbd_clt_unmap_device(struct rnbd_clt_dev *dev, bool force, |
| 152 | const struct attribute *sysfs_self); |
| 153 | |
| 154 | int rnbd_clt_remap_device(struct rnbd_clt_dev *dev); |
| 155 | int rnbd_clt_resize_disk(struct rnbd_clt_dev *dev, size_t newsize); |
| 156 | |
| 157 | /* rnbd-clt-sysfs.c */ |
| 158 | |
| 159 | int rnbd_clt_create_sysfs_files(void); |
| 160 | |
| 161 | void rnbd_clt_destroy_sysfs_files(void); |
Jack Wang | 90426e8 | 2020-05-11 15:51:22 +0200 | [diff] [blame] | 162 | |
| 163 | void rnbd_clt_remove_dev_symlink(struct rnbd_clt_dev *dev); |
| 164 | |
| 165 | #endif /* RNBD_CLT_H */ |