xref: /openbmc/linux/drivers/block/rnbd/rnbd-srv.h (revision f7ecac6a)
1d4c6957dSJack Wang /* SPDX-License-Identifier: GPL-2.0-or-later */
2d4c6957dSJack Wang /*
3d4c6957dSJack Wang  * RDMA Network Block Driver
4d4c6957dSJack Wang  *
5d4c6957dSJack Wang  * Copyright (c) 2014 - 2018 ProfitBricks GmbH. All rights reserved.
6d4c6957dSJack Wang  * Copyright (c) 2018 - 2019 1&1 IONOS Cloud GmbH. All rights reserved.
7d4c6957dSJack Wang  * Copyright (c) 2019 - 2020 1&1 IONOS SE. All rights reserved.
8d4c6957dSJack Wang  */
9d4c6957dSJack Wang #ifndef RNBD_SRV_H
10d4c6957dSJack Wang #define RNBD_SRV_H
11d4c6957dSJack Wang 
12d4c6957dSJack Wang #include <linux/types.h>
13d4c6957dSJack Wang #include <linux/idr.h>
14d4c6957dSJack Wang #include <linux/kref.h>
15d4c6957dSJack Wang 
16d4c6957dSJack Wang #include <rtrs.h>
17d4c6957dSJack Wang #include "rnbd-proto.h"
18d4c6957dSJack Wang #include "rnbd-log.h"
19d4c6957dSJack Wang 
20d4c6957dSJack Wang struct rnbd_srv_session {
21d4c6957dSJack Wang 	/* Entry inside global sess_list */
22d4c6957dSJack Wang 	struct list_head        list;
23*f7ecac6aSVaishali Thakkar 	struct rtrs_srv_sess	*rtrs;
24d4c6957dSJack Wang 	char			sessname[NAME_MAX];
25d4c6957dSJack Wang 	int			queue_depth;
26d4c6957dSJack Wang 	struct bio_set		sess_bio_set;
27d4c6957dSJack Wang 
28d4c6957dSJack Wang 	struct xarray		index_idr;
29d4c6957dSJack Wang 	/* List of struct rnbd_srv_sess_dev */
30d4c6957dSJack Wang 	struct list_head        sess_dev_list;
31d4c6957dSJack Wang 	struct mutex		lock;
32d4c6957dSJack Wang 	u8			ver;
33d4c6957dSJack Wang };
34d4c6957dSJack Wang 
35d4c6957dSJack Wang struct rnbd_srv_dev {
36d4c6957dSJack Wang 	/* Entry inside global dev_list */
37d4c6957dSJack Wang 	struct list_head                list;
38d4c6957dSJack Wang 	struct kobject                  dev_kobj;
39d4c6957dSJack Wang 	struct kobject                  *dev_sessions_kobj;
40d4c6957dSJack Wang 	struct kref                     kref;
41d4c6957dSJack Wang 	char				id[NAME_MAX];
42d4c6957dSJack Wang 	/* List of rnbd_srv_sess_dev structs */
43d4c6957dSJack Wang 	struct list_head		sess_dev_list;
44d4c6957dSJack Wang 	struct mutex			lock;
45d4c6957dSJack Wang 	int				open_write_cnt;
46d4c6957dSJack Wang };
47d4c6957dSJack Wang 
48d4c6957dSJack Wang /* Structure which binds N devices and N sessions */
49d4c6957dSJack Wang struct rnbd_srv_sess_dev {
50d4c6957dSJack Wang 	/* Entry inside rnbd_srv_dev struct */
51d4c6957dSJack Wang 	struct list_head		dev_list;
52d4c6957dSJack Wang 	/* Entry inside rnbd_srv_session struct */
53d4c6957dSJack Wang 	struct list_head		sess_list;
54d4c6957dSJack Wang 	struct rnbd_dev			*rnbd_dev;
55d4c6957dSJack Wang 	struct rnbd_srv_session		*sess;
56d4c6957dSJack Wang 	struct rnbd_srv_dev		*dev;
57d4c6957dSJack Wang 	struct kobject                  kobj;
58d4c6957dSJack Wang 	u32                             device_id;
5978699805SLutz Pogrell 	bool				keep_id;
60d4c6957dSJack Wang 	fmode_t                         open_flags;
61d4c6957dSJack Wang 	struct kref			kref;
62d4c6957dSJack Wang 	struct completion               *destroy_comp;
63d4c6957dSJack Wang 	char				pathname[NAME_MAX];
64d4c6957dSJack Wang 	enum rnbd_access_mode		access_mode;
65d4c6957dSJack Wang };
66d4c6957dSJack Wang 
67c77bfa8fSGioh Kim void rnbd_srv_sess_dev_force_close(struct rnbd_srv_sess_dev *sess_dev,
68c77bfa8fSGioh Kim 				   struct kobj_attribute *attr);
69d4c6957dSJack Wang /* rnbd-srv-sysfs.c */
70d4c6957dSJack Wang 
71d4c6957dSJack Wang int rnbd_srv_create_dev_sysfs(struct rnbd_srv_dev *dev,
72d4c6957dSJack Wang 			      struct block_device *bdev,
73d4c6957dSJack Wang 			      const char *dir_name);
74d4c6957dSJack Wang void rnbd_srv_destroy_dev_sysfs(struct rnbd_srv_dev *dev);
75d4c6957dSJack Wang int rnbd_srv_create_dev_session_sysfs(struct rnbd_srv_sess_dev *sess_dev);
76d4c6957dSJack Wang void rnbd_srv_destroy_dev_session_sysfs(struct rnbd_srv_sess_dev *sess_dev);
77d4c6957dSJack Wang int rnbd_srv_create_sysfs_files(void);
78d4c6957dSJack Wang void rnbd_srv_destroy_sysfs_files(void);
7978699805SLutz Pogrell void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id);
80d4c6957dSJack Wang 
81d4c6957dSJack Wang #endif /* RNBD_SRV_H */
82