xref: /spdk/include/spdk_internal/lvolstore.h (revision 2a6c8d3ffccbd44d0e3dbf594c0c080b6f4e0b3e)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2017 Intel Corporation.
3  *   All rights reserved.
4  *   Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5  */
6 
7 #ifndef SPDK_INTERNAL_LVOLSTORE_H
8 #define SPDK_INTERNAL_LVOLSTORE_H
9 
10 #include "spdk/blob.h"
11 #include "spdk/lvol.h"
12 #include "spdk/queue.h"
13 #include "spdk/tree.h"
14 #include "spdk/uuid.h"
15 
16 /* Default size of blobstore cluster */
17 #define SPDK_LVS_OPTS_CLUSTER_SZ (4 * 1024 * 1024)
18 
19 /* UUID + '_' + blobid (20 characters for uint64_t).
20  * Null terminator is already included in SPDK_UUID_STRING_LEN. */
21 #define SPDK_LVOL_UNIQUE_ID_MAX (SPDK_UUID_STRING_LEN + 1 + 20)
22 
23 struct spdk_lvs_req {
24 	spdk_lvs_op_complete    cb_fn;
25 	void                    *cb_arg;
26 	struct spdk_lvol_store		*lvol_store;
27 	int				lvserrno;
28 };
29 
30 struct spdk_lvs_grow_req {
31 	struct spdk_lvs_req	base;
32 	spdk_lvs_op_complete	cb_fn;
33 	void			*cb_arg;
34 	struct lvol_store_bdev	*lvs_bdev;
35 	int			lvol_cnt;
36 };
37 
38 struct spdk_lvol_req {
39 	spdk_lvol_op_complete   cb_fn;
40 	void                    *cb_arg;
41 	struct spdk_lvol	*lvol;
42 	/* Only set while lvol is being deleted and has a clone. */
43 	struct spdk_lvol	*clone_lvol;
44 	size_t			sz;
45 	struct spdk_io_channel	*channel;
46 	char			name[SPDK_LVOL_NAME_MAX];
47 };
48 
49 struct spdk_lvol_copy_req {
50 	spdk_lvol_op_complete	cb_fn;
51 	void			*cb_arg;
52 	struct spdk_lvol	*lvol;
53 	struct spdk_io_channel	*channel;
54 	struct spdk_bs_dev	*ext_dev;
55 };
56 
57 struct spdk_lvs_with_handle_req {
58 	spdk_lvs_op_with_handle_complete cb_fn;
59 	void				*cb_arg;
60 	struct spdk_lvol_store		*lvol_store;
61 	struct spdk_bs_dev		*bs_dev;
62 	struct spdk_bdev		*base_bdev;
63 	int				lvserrno;
64 };
65 
66 struct spdk_lvs_destroy_req {
67 	spdk_lvs_op_complete    cb_fn;
68 	void                    *cb_arg;
69 	struct spdk_lvol_store	*lvs;
70 };
71 
72 struct spdk_lvol_with_handle_req {
73 	spdk_lvol_op_with_handle_complete cb_fn;
74 	void				*cb_arg;
75 	struct spdk_lvol		*lvol;
76 	struct spdk_lvol		*origlvol;
77 };
78 
79 struct spdk_lvol_bs_dev_req {
80 	struct spdk_lvol	*lvol;
81 	struct spdk_bs_dev	*bs_dev;
82 	spdk_lvol_op_complete	cb_fn;
83 	void			*cb_arg;
84 };
85 
86 struct spdk_lvs_degraded_lvol_set;
87 
88 struct spdk_lvol_store {
89 	struct spdk_bs_dev		*bs_dev;
90 	struct spdk_blob_store		*blobstore;
91 	struct spdk_blob		*super_blob;
92 	spdk_blob_id			super_blob_id;
93 	struct spdk_uuid		uuid;
94 	int				lvol_count;
95 	int				lvols_opened;
96 	TAILQ_HEAD(, spdk_lvol)		lvols;
97 	TAILQ_HEAD(, spdk_lvol)		pending_lvols;
98 	TAILQ_HEAD(, spdk_lvol)		retry_open_lvols;
99 	bool				load_esnaps;
100 	bool				on_list;
101 	TAILQ_ENTRY(spdk_lvol_store)	link;
102 	char				name[SPDK_LVS_NAME_MAX];
103 	char				new_name[SPDK_LVS_NAME_MAX];
104 	spdk_bs_esnap_dev_create	esnap_bs_dev_create;
105 	RB_HEAD(degraded_lvol_sets_tree, spdk_lvs_degraded_lvol_set)	degraded_lvol_sets_tree;
106 	struct spdk_thread		*thread;
107 };
108 
109 struct spdk_lvol {
110 	struct spdk_lvol_store		*lvol_store;
111 	struct spdk_blob		*blob;
112 	spdk_blob_id			blob_id;
113 	char				unique_id[SPDK_LVOL_UNIQUE_ID_MAX];
114 	char				name[SPDK_LVOL_NAME_MAX];
115 	struct spdk_uuid		uuid;
116 	char				uuid_str[SPDK_UUID_STRING_LEN];
117 	struct spdk_bdev		*bdev;
118 	int				ref_count;
119 	bool				action_in_progress;
120 	enum blob_clear_method		clear_method;
121 	TAILQ_ENTRY(spdk_lvol)		link;
122 	struct spdk_lvs_degraded_lvol_set *degraded_set;
123 	TAILQ_ENTRY(spdk_lvol)		degraded_link;
124 };
125 
126 struct lvol_store_bdev *vbdev_lvol_store_first(void);
127 struct lvol_store_bdev *vbdev_lvol_store_next(struct lvol_store_bdev *prev);
128 
129 void spdk_lvol_resize(struct spdk_lvol *lvol, uint64_t sz, spdk_lvol_op_complete cb_fn,
130 		      void *cb_arg);
131 
132 void spdk_lvol_set_read_only(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn,
133 			     void *cb_arg);
134 
135 int spdk_lvs_esnap_missing_add(struct spdk_lvol_store *lvs, struct spdk_lvol *lvol,
136 			       const void *esnap_id, uint32_t id_len);
137 void spdk_lvs_esnap_missing_remove(struct spdk_lvol *lvol);
138 bool spdk_lvs_notify_hotplug(const void *esnap_id, uint32_t id_len,
139 			     spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg);
140 
141 #endif /* SPDK_INTERNAL_LVOLSTORE_H */
142