Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * RDMA Network Block Driver
0004  *
0005  * Copyright (c) 2014 - 2018 ProfitBricks GmbH. All rights reserved.
0006  * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
0007  * Copyright (c) 2019 - 2020 1&1 IONOS SE. All rights reserved.
0008  */
0009 
0010 #ifndef RNBD_CLT_H
0011 #define RNBD_CLT_H
0012 
0013 #include <linux/wait.h>
0014 #include <linux/in.h>
0015 #include <linux/inet.h>
0016 #include <linux/blk-mq.h>
0017 #include <linux/refcount.h>
0018 
0019 #include <rtrs.h>
0020 #include "rnbd-proto.h"
0021 #include "rnbd-log.h"
0022 
0023 /*  time in seconds between reconnect tries, default to 30 s */
0024 #define RECONNECT_DELAY 30
0025 /*
0026  * Number of times to reconnect on error before giving up, 0 for * disabled,
0027  * -1 for forever
0028  */
0029 #define MAX_RECONNECTS -1
0030 
0031 enum rnbd_clt_dev_state {
0032     DEV_STATE_INIT,
0033     DEV_STATE_MAPPED,
0034     DEV_STATE_MAPPED_DISCONNECTED,
0035     DEV_STATE_UNMAPPED,
0036 };
0037 
0038 struct rnbd_iu_comp {
0039     wait_queue_head_t wait;
0040     int errno;
0041 };
0042 
0043 #ifdef CONFIG_ARCH_NO_SG_CHAIN
0044 #define RNBD_INLINE_SG_CNT 0
0045 #else
0046 #define RNBD_INLINE_SG_CNT 2
0047 #endif
0048 #define RNBD_RDMA_SGL_SIZE (sizeof(struct scatterlist) * RNBD_INLINE_SG_CNT)
0049 
0050 struct rnbd_iu {
0051     union {
0052         struct request *rq; /* for block io */
0053         void *buf; /* for user messages */
0054     };
0055     struct rtrs_permit  *permit;
0056     union {
0057         /* use to send msg associated with a dev */
0058         struct rnbd_clt_dev *dev;
0059         /* use to send msg associated with a sess */
0060         struct rnbd_clt_session *sess;
0061     };
0062     struct sg_table     sgt;
0063     struct work_struct  work;
0064     int         errno;
0065     struct rnbd_iu_comp comp;
0066     atomic_t        refcount;
0067     struct scatterlist  first_sgl[]; /* must be the last one */
0068 };
0069 
0070 struct rnbd_cpu_qlist {
0071     struct list_head    requeue_list;
0072     spinlock_t      requeue_lock;
0073     unsigned int        cpu;
0074 };
0075 
0076 struct rnbd_clt_session {
0077     struct list_head        list;
0078     struct rtrs_clt_sess        *rtrs;
0079     wait_queue_head_t       rtrs_waitq;
0080     bool                    rtrs_ready;
0081     struct rnbd_cpu_qlist   __percpu
0082                 *cpu_queues;
0083     DECLARE_BITMAP(cpu_queues_bm, NR_CPUS);
0084     int __percpu    *cpu_rr; /* per-cpu var for CPU round-robin */
0085     atomic_t        busy;
0086     size_t          queue_depth;
0087     u32         max_io_size;
0088     u32         max_segments;
0089     struct blk_mq_tag_set   tag_set;
0090     u32         nr_poll_queues;
0091     struct mutex        lock; /* protects state and devs_list */
0092     struct list_head        devs_list; /* list of struct rnbd_clt_dev */
0093     refcount_t      refcount;
0094     char            sessname[NAME_MAX];
0095     u8          ver; /* protocol version */
0096 };
0097 
0098 /**
0099  * Submission queues.
0100  */
0101 struct rnbd_queue {
0102     struct list_head    requeue_list;
0103     unsigned long       in_list;
0104     struct rnbd_clt_dev *dev;
0105     struct blk_mq_hw_ctx    *hctx;
0106 };
0107 
0108 struct rnbd_clt_dev {
0109     struct kobject      kobj;
0110     struct rnbd_clt_session *sess;
0111     struct request_queue    *queue;
0112     struct rnbd_queue   *hw_queues;
0113     u32         device_id;
0114     /* local Idr index - used to track minor number allocations. */
0115     u32         clt_device_id;
0116     struct mutex        lock;
0117     enum rnbd_clt_dev_state dev_state;
0118     refcount_t      refcount;
0119     char            *pathname;
0120     enum rnbd_access_mode   access_mode;
0121     u32         nr_poll_queues;
0122     u64         size;       /* device size in bytes */
0123     struct list_head        list;
0124     struct gendisk      *gd;
0125     char            *blk_symlink_name;
0126     struct work_struct  unmap_on_rmmod_work;
0127 };
0128 
0129 /* rnbd-clt.c */
0130 
0131 struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname,
0132                        struct rtrs_addr *paths,
0133                        size_t path_cnt, u16 port_nr,
0134                        const char *pathname,
0135                        enum rnbd_access_mode access_mode,
0136                        u32 nr_poll_queues);
0137 int rnbd_clt_unmap_device(struct rnbd_clt_dev *dev, bool force,
0138                const struct attribute *sysfs_self);
0139 
0140 int rnbd_clt_remap_device(struct rnbd_clt_dev *dev);
0141 int rnbd_clt_resize_disk(struct rnbd_clt_dev *dev, sector_t newsize);
0142 
0143 /* rnbd-clt-sysfs.c */
0144 
0145 int rnbd_clt_create_sysfs_files(void);
0146 
0147 void rnbd_clt_destroy_sysfs_files(void);
0148 
0149 void rnbd_clt_remove_dev_symlink(struct rnbd_clt_dev *dev);
0150 
0151 #endif /* RNBD_CLT_H */