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