1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * RDMA Network Block Driver
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.
13 #include <linux/wait.h>
15 #include <linux/inet.h>
16 #include <linux/blk-mq.h>
17 #include <linux/refcount.h>
20 #include "rnbd-proto.h"
23 /* Max. number of segments per IO request, Mellanox Connect X ~ Connect X5,
24 * choose minimial 30 for all, minus 1 for internal protocol, so 29.
26 #define BMAX_SEGMENTS 29
27 /* time in seconds between reconnect tries, default to 30 s */
28 #define RECONNECT_DELAY 30
30 * Number of times to reconnect on error before giving up, 0 for * disabled,
33 #define MAX_RECONNECTS -1
35 enum rnbd_clt_dev_state {
38 DEV_STATE_MAPPED_DISCONNECTED,
43 wait_queue_head_t wait;
49 struct request *rq; /* for block io */
50 void *buf; /* for user messages */
52 struct rtrs_permit *permit;
54 /* use to send msg associated with a dev */
55 struct rnbd_clt_dev *dev;
56 /* use to send msg associated with a sess */
57 struct rnbd_clt_session *sess;
59 struct scatterlist sglist[BMAX_SEGMENTS];
60 struct work_struct work;
62 struct rnbd_iu_comp comp;
66 struct rnbd_cpu_qlist {
67 struct list_head requeue_list;
68 spinlock_t requeue_lock;
72 struct rnbd_clt_session {
73 struct list_head list;
74 struct rtrs_clt *rtrs;
75 wait_queue_head_t rtrs_waitq;
77 struct rnbd_cpu_qlist __percpu
79 DECLARE_BITMAP(cpu_queues_bm, NR_CPUS);
80 int __percpu *cpu_rr; /* per-cpu var for CPU round-robin */
84 struct blk_mq_tag_set tag_set;
85 struct mutex lock; /* protects state and devs_list */
86 struct list_head devs_list; /* list of struct rnbd_clt_dev */
88 char sessname[NAME_MAX];
89 u8 ver; /* protocol version */
96 struct list_head requeue_list;
97 unsigned long in_list;
98 struct rnbd_clt_dev *dev;
99 struct blk_mq_hw_ctx *hctx;
102 struct rnbd_clt_dev {
103 struct rnbd_clt_session *sess;
104 struct request_queue *queue;
105 struct rnbd_queue *hw_queues;
107 /* local Idr index - used to track minor number allocations. */
110 enum rnbd_clt_dev_state dev_state;
112 enum rnbd_access_mode access_mode;
116 u32 max_write_same_sectors;
117 u32 max_discard_sectors;
118 u32 discard_granularity;
119 u32 discard_alignment;
121 u16 physical_block_size;
122 u16 logical_block_size;
125 u64 size; /* device size in bytes */
126 struct list_head list;
129 char *blk_symlink_name;
131 struct work_struct unmap_on_rmmod_work;
136 struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname,
137 struct rtrs_addr *paths,
138 size_t path_cnt, u16 port_nr,
139 const char *pathname,
140 enum rnbd_access_mode access_mode);
141 int rnbd_clt_unmap_device(struct rnbd_clt_dev *dev, bool force,
142 const struct attribute *sysfs_self);
144 int rnbd_clt_remap_device(struct rnbd_clt_dev *dev);
145 int rnbd_clt_resize_disk(struct rnbd_clt_dev *dev, size_t newsize);
147 /* rnbd-clt-sysfs.c */
149 int rnbd_clt_create_sysfs_files(void);
151 void rnbd_clt_destroy_sysfs_files(void);
152 void rnbd_clt_destroy_default_group(void);
154 void rnbd_clt_remove_dev_symlink(struct rnbd_clt_dev *dev);
156 #endif /* RNBD_CLT_H */