xref: /spdk/module/bdev/lvol/vbdev_lvol.h (revision 6b79f76769c83dacf162ff2ca2cf1cf133896835)
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_VBDEV_LVOL_H
8 #define SPDK_VBDEV_LVOL_H
9 
10 #include "spdk/lvol.h"
11 #include "spdk/bdev_module.h"
12 
13 #include "spdk_internal/lvolstore.h"
14 
15 struct lvol_store_bdev {
16 	struct spdk_lvol_store	*lvs;
17 	struct spdk_bdev	*bdev;
18 	struct spdk_lvs_req	*req;
19 	bool			removal_in_progress;
20 
21 	TAILQ_ENTRY(lvol_store_bdev)	lvol_stores;
22 };
23 
24 struct lvol_bdev {
25 	struct spdk_bdev	bdev;
26 	struct spdk_lvol	*lvol;
27 	struct lvol_store_bdev	*lvs_bdev;
28 };
29 
30 int vbdev_lvs_create(const char *base_bdev_name, const char *name, uint32_t cluster_sz,
31 		     enum lvs_clear_method clear_method, uint32_t num_md_pages_per_cluster_ratio,
32 		     spdk_lvs_op_with_handle_complete cb_fn, void *cb_arg);
33 void vbdev_lvs_destruct(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn, void *cb_arg);
34 void vbdev_lvs_unload(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn, void *cb_arg);
35 
36 int vbdev_lvol_create(struct spdk_lvol_store *lvs, const char *name, uint64_t sz,
37 		      bool thin_provisioned, enum lvol_clear_method clear_method,
38 		      spdk_lvol_op_with_handle_complete cb_fn,
39 		      void *cb_arg);
40 
41 void vbdev_lvol_create_snapshot(struct spdk_lvol *lvol, const char *snapshot_name,
42 				spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg);
43 
44 void vbdev_lvol_create_clone(struct spdk_lvol *lvol, const char *clone_name,
45 			     spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg);
46 void vbdev_lvol_create_bdev_clone(const char *esnap_uuid,
47 				  struct spdk_lvol_store *lvs, const char *clone_name,
48 				  spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg);
49 
50 /**
51  * \brief Change size of lvol
52  * \param lvol Handle to lvol
53  * \param sz Size of lvol to change
54  * \param cb_fn Completion callback
55  * \param cb_arg Completion callback custom arguments
56  * \return error
57  */
58 void vbdev_lvol_resize(struct spdk_lvol *lvol, uint64_t sz, spdk_lvol_op_complete cb_fn,
59 		       void *cb_arg);
60 
61 /**
62  * \brief Mark lvol as read only
63  * \param lvol Handle to lvol
64  * \param cb_fn Completion callback
65  * \param cb_arg Completion callback custom arguments
66  */
67 void vbdev_lvol_set_read_only(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg);
68 
69 void vbdev_lvol_rename(struct spdk_lvol *lvol, const char *new_lvol_name,
70 		       spdk_lvol_op_complete cb_fn, void *cb_arg);
71 
72 /**
73  * Destroy a logical volume
74  * \param lvol Handle to lvol
75  * \param cb_fn Completion callback
76  * \param cb_arg Completion callback custom arguments
77  */
78 void vbdev_lvol_destroy(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg);
79 
80 /**
81  * \brief Renames given lvolstore.
82  *
83  * \param lvs Pointer to lvolstore
84  * \param new_name New name of lvs
85  * \param cb_fn Completion callback
86  * \param cb_arg Completion callback custom arguments
87  */
88 void vbdev_lvs_rename(struct spdk_lvol_store *lvs, const char *new_lvs_name,
89 		      spdk_lvs_op_complete cb_fn, void *cb_arg);
90 
91 /**
92  * \brief Search for handle lvolstore
93  * \param uuid_str UUID of lvolstore
94  * \return Handle to spdk_lvol_store or NULL if not found.
95  */
96 struct spdk_lvol_store *vbdev_get_lvol_store_by_uuid(const char *uuid_str);
97 
98 /**
99  * \brief Search for handle to lvolstore
100  * \param name name of lvolstore
101  * \return Handle to spdk_lvol_store or NULL if not found.
102  */
103 struct spdk_lvol_store *vbdev_get_lvol_store_by_name(const char *name);
104 
105 /**
106  * \brief Search for handle to lvol_store_bdev
107  * \param lvs handle to lvolstore
108  * \return Handle to lvol_store_bdev or NULL if not found.
109  */
110 struct lvol_store_bdev *vbdev_get_lvs_bdev_by_lvs(struct spdk_lvol_store *lvs);
111 
112 struct spdk_lvol *vbdev_lvol_get_from_bdev(struct spdk_bdev *bdev);
113 
114 /**
115  * \brief Grow given lvolstore.
116  *
117  * \param lvs Pointer to lvolstore
118  * \param cb_fn Completion callback
119  * \param cb_arg Completion callback custom arguments
120  */
121 void vbdev_lvs_grow(struct spdk_lvol_store *lvs,
122 		    spdk_lvs_op_complete cb_fn, void *cb_arg);
123 
124 int vbdev_lvol_esnap_dev_create(void *bs_ctx, void *blob_ctx, struct spdk_blob *blob,
125 				const void *esnap_id, uint32_t id_len,
126 				struct spdk_bs_dev **_bs_dev);
127 
128 #endif /* SPDK_VBDEV_LVOL_H */
129