xref: /spdk/include/spdk_internal/lvolstore.h (revision f6866117acb32c78d5ea7bd76ba330284655af35)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2017 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #ifndef SPDK_INTERNAL_LVOLSTORE_H
7 #define SPDK_INTERNAL_LVOLSTORE_H
8 
9 #include "spdk/blob.h"
10 #include "spdk/lvol.h"
11 #include "spdk/queue.h"
12 #include "spdk/uuid.h"
13 
14 /* Default size of blobstore cluster */
15 #define SPDK_LVS_OPTS_CLUSTER_SZ (4 * 1024 * 1024)
16 
17 /* UUID + '_' + blobid (20 characters for uint64_t).
18  * Null terminator is already included in SPDK_UUID_STRING_LEN. */
19 #define SPDK_LVOL_UNIQUE_ID_MAX (SPDK_UUID_STRING_LEN + 1 + 20)
20 
21 struct spdk_lvs_req {
22 	spdk_lvs_op_complete    cb_fn;
23 	void                    *cb_arg;
24 	struct spdk_lvol_store		*lvol_store;
25 	int				lvserrno;
26 };
27 
28 struct spdk_lvs_grow_req {
29 	struct spdk_lvs_req	base;
30 	spdk_lvs_op_complete	cb_fn;
31 	void			*cb_arg;
32 	struct lvol_store_bdev	*lvs_bdev;
33 	int			lvol_cnt;
34 };
35 
36 struct spdk_lvol_req {
37 	spdk_lvol_op_complete   cb_fn;
38 	void                    *cb_arg;
39 	struct spdk_lvol	*lvol;
40 	size_t			sz;
41 	struct spdk_io_channel	*channel;
42 	char			name[SPDK_LVOL_NAME_MAX];
43 };
44 
45 struct spdk_lvs_with_handle_req {
46 	spdk_lvs_op_with_handle_complete cb_fn;
47 	void				*cb_arg;
48 	struct spdk_lvol_store		*lvol_store;
49 	struct spdk_bs_dev		*bs_dev;
50 	struct spdk_bdev		*base_bdev;
51 	int				lvserrno;
52 };
53 
54 struct spdk_lvs_destroy_req {
55 	spdk_lvs_op_complete    cb_fn;
56 	void                    *cb_arg;
57 	struct spdk_lvol_store	*lvs;
58 };
59 
60 struct spdk_lvol_with_handle_req {
61 	spdk_lvol_op_with_handle_complete cb_fn;
62 	void				*cb_arg;
63 	struct spdk_lvol		*lvol;
64 };
65 
66 struct spdk_lvol_store {
67 	struct spdk_bs_dev		*bs_dev;
68 	struct spdk_blob_store		*blobstore;
69 	struct spdk_blob		*super_blob;
70 	spdk_blob_id			super_blob_id;
71 	struct spdk_uuid		uuid;
72 	int				lvol_count;
73 	int				lvols_opened;
74 	TAILQ_HEAD(, spdk_lvol)		lvols;
75 	TAILQ_HEAD(, spdk_lvol)		pending_lvols;
76 	TAILQ_HEAD(, spdk_lvol)		retry_open_lvols;
77 	bool				on_list;
78 	TAILQ_ENTRY(spdk_lvol_store)	link;
79 	char				name[SPDK_LVS_NAME_MAX];
80 	char				new_name[SPDK_LVS_NAME_MAX];
81 };
82 
83 struct spdk_lvol {
84 	struct spdk_lvol_store		*lvol_store;
85 	struct spdk_blob		*blob;
86 	spdk_blob_id			blob_id;
87 	char				unique_id[SPDK_LVOL_UNIQUE_ID_MAX];
88 	char				name[SPDK_LVOL_NAME_MAX];
89 	struct spdk_uuid		uuid;
90 	char				uuid_str[SPDK_UUID_STRING_LEN];
91 	bool				thin_provision;
92 	struct spdk_bdev		*bdev;
93 	int				ref_count;
94 	bool				action_in_progress;
95 	enum blob_clear_method		clear_method;
96 	TAILQ_ENTRY(spdk_lvol) link;
97 };
98 
99 struct lvol_store_bdev *vbdev_lvol_store_first(void);
100 struct lvol_store_bdev *vbdev_lvol_store_next(struct lvol_store_bdev *prev);
101 
102 void spdk_lvol_resize(struct spdk_lvol *lvol, uint64_t sz, spdk_lvol_op_complete cb_fn,
103 		      void *cb_arg);
104 
105 void spdk_lvol_set_read_only(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn,
106 			     void *cb_arg);
107 
108 #endif /* SPDK_INTERNAL_LVOLSTORE_H */
109