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 /* time in seconds between reconnect tries, default to 30 s */
24 #define RECONNECT_DELAY 30
26 * Number of times to reconnect on error before giving up, 0 for * disabled,
29 #define MAX_RECONNECTS -1
31 enum rnbd_clt_dev_state
{
34 DEV_STATE_MAPPED_DISCONNECTED
,
39 wait_queue_head_t wait
;
43 #ifdef CONFIG_ARCH_NO_SG_CHAIN
44 #define RNBD_INLINE_SG_CNT 0
46 #define RNBD_INLINE_SG_CNT 2
48 #define RNBD_RDMA_SGL_SIZE (sizeof(struct scatterlist) * RNBD_INLINE_SG_CNT)
52 struct request
*rq
; /* for block io */
53 void *buf
; /* for user messages */
55 struct rtrs_permit
*permit
;
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
;
63 struct work_struct work
;
65 struct rnbd_iu_comp comp
;
67 struct scatterlist first_sgl
[]; /* must be the last one */
70 struct rnbd_cpu_qlist
{
71 struct list_head requeue_list
;
72 spinlock_t requeue_lock
;
76 struct rnbd_clt_session
{
77 struct list_head list
;
78 struct rtrs_clt_sess
*rtrs
;
79 wait_queue_head_t rtrs_waitq
;
81 struct rnbd_cpu_qlist __percpu
83 DECLARE_BITMAP(cpu_queues_bm
, NR_CPUS
);
84 int __percpu
*cpu_rr
; /* per-cpu var for CPU round-robin */
89 struct blk_mq_tag_set tag_set
;
91 struct mutex lock
; /* protects state and devs_list */
92 struct list_head devs_list
; /* list of struct rnbd_clt_dev */
94 char sessname
[NAME_MAX
];
95 u8 ver
; /* protocol version */
102 struct list_head requeue_list
;
103 unsigned long in_list
;
104 struct rnbd_clt_dev
*dev
;
105 struct blk_mq_hw_ctx
*hctx
;
108 struct rnbd_clt_dev
{
110 struct rnbd_clt_session
*sess
;
111 struct request_queue
*queue
;
112 struct rnbd_queue
*hw_queues
;
114 /* local Idr index - used to track minor number allocations. */
117 enum rnbd_clt_dev_state dev_state
;
120 enum rnbd_access_mode access_mode
;
122 u64 size
; /* device size in bytes */
123 struct list_head list
;
125 char *blk_symlink_name
;
126 struct work_struct unmap_on_rmmod_work
;
131 struct rnbd_clt_dev
*rnbd_clt_map_device(const char *sessname
,
132 struct rtrs_addr
*paths
,
133 size_t path_cnt
, u16 port_nr
,
134 const char *pathname
,
135 enum rnbd_access_mode access_mode
,
137 int rnbd_clt_unmap_device(struct rnbd_clt_dev
*dev
, bool force
,
138 const struct attribute
*sysfs_self
);
140 int rnbd_clt_remap_device(struct rnbd_clt_dev
*dev
);
141 int rnbd_clt_resize_disk(struct rnbd_clt_dev
*dev
, sector_t newsize
);
143 /* rnbd-clt-sysfs.c */
145 int rnbd_clt_create_sysfs_files(void);
147 void rnbd_clt_destroy_sysfs_files(void);
149 void rnbd_clt_remove_dev_symlink(struct rnbd_clt_dev
*dev
);
151 #endif /* RNBD_CLT_H */