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
;
47 #ifdef CONFIG_ARCH_NO_SG_CHAIN
48 #define RNBD_INLINE_SG_CNT 0
50 #define RNBD_INLINE_SG_CNT 2
52 #define RNBD_RDMA_SGL_SIZE (sizeof(struct scatterlist) * RNBD_INLINE_SG_CNT)
56 struct request
*rq
; /* for block io */
57 void *buf
; /* for user messages */
59 struct rtrs_permit
*permit
;
61 /* use to send msg associated with a dev */
62 struct rnbd_clt_dev
*dev
;
63 /* use to send msg associated with a sess */
64 struct rnbd_clt_session
*sess
;
67 struct work_struct work
;
69 struct rnbd_iu_comp comp
;
71 struct scatterlist first_sgl
[]; /* must be the last one */
74 struct rnbd_cpu_qlist
{
75 struct list_head requeue_list
;
76 spinlock_t requeue_lock
;
80 struct rnbd_clt_session
{
81 struct list_head list
;
82 struct rtrs_clt
*rtrs
;
83 wait_queue_head_t rtrs_waitq
;
85 struct rnbd_cpu_qlist __percpu
87 DECLARE_BITMAP(cpu_queues_bm
, NR_CPUS
);
88 int __percpu
*cpu_rr
; /* per-cpu var for CPU round-robin */
92 struct blk_mq_tag_set tag_set
;
93 struct mutex lock
; /* protects state and devs_list */
94 struct list_head devs_list
; /* list of struct rnbd_clt_dev */
96 char sessname
[NAME_MAX
];
97 u8 ver
; /* protocol version */
104 struct list_head requeue_list
;
105 unsigned long in_list
;
106 struct rnbd_clt_dev
*dev
;
107 struct blk_mq_hw_ctx
*hctx
;
110 struct rnbd_clt_dev
{
111 struct rnbd_clt_session
*sess
;
112 struct request_queue
*queue
;
113 struct rnbd_queue
*hw_queues
;
115 /* local Idr index - used to track minor number allocations. */
118 enum rnbd_clt_dev_state dev_state
;
120 enum rnbd_access_mode access_mode
;
126 u32 max_write_same_sectors
;
127 u32 max_discard_sectors
;
128 u32 discard_granularity
;
129 u32 discard_alignment
;
131 u16 physical_block_size
;
132 u16 logical_block_size
;
135 u64 size
; /* device size in bytes */
136 struct list_head list
;
139 char *blk_symlink_name
;
141 struct work_struct unmap_on_rmmod_work
;
146 struct rnbd_clt_dev
*rnbd_clt_map_device(const char *sessname
,
147 struct rtrs_addr
*paths
,
148 size_t path_cnt
, u16 port_nr
,
149 const char *pathname
,
150 enum rnbd_access_mode access_mode
);
151 int rnbd_clt_unmap_device(struct rnbd_clt_dev
*dev
, bool force
,
152 const struct attribute
*sysfs_self
);
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
);
157 /* rnbd-clt-sysfs.c */
159 int rnbd_clt_create_sysfs_files(void);
161 void rnbd_clt_destroy_sysfs_files(void);
162 void rnbd_clt_destroy_default_group(void);
164 void rnbd_clt_remove_dev_symlink(struct rnbd_clt_dev
*dev
);
166 #endif /* RNBD_CLT_H */