xref: /spdk/module/bdev/lvol/vbdev_lvol.h (revision 2e1d23f4b70ea8940db7624b3bb974a4a8658ec7)
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 #include "spdk/blob_bdev.h"
13 
14 #include "spdk_internal/lvolstore.h"
15 
16 struct lvol_store_bdev {
17 	struct spdk_lvol_store	*lvs;
18 	struct spdk_bdev	*bdev;
19 	struct spdk_lvs_req	*req;
20 	bool			removal_in_progress;
21 
22 	TAILQ_ENTRY(lvol_store_bdev)	lvol_stores;
23 };
24 
25 struct lvol_bdev {
26 	struct spdk_bdev	bdev;
27 	struct spdk_lvol	*lvol;
28 	struct lvol_store_bdev	*lvs_bdev;
29 };
30 
31 int vbdev_lvs_create(const char *base_bdev_name, const char *name, uint32_t cluster_sz,
32 		     enum lvs_clear_method clear_method, uint32_t num_md_pages_per_cluster_ratio,
33 		     spdk_lvs_op_with_handle_complete cb_fn, void *cb_arg);
34 int vbdev_lvs_create_ext(const char *base_bdev_name, const char *name, uint32_t cluster_sz,
35 			 enum lvs_clear_method clear_method, uint32_t num_md_pages_per_cluster_ratio,
36 			 uint32_t md_page_size, spdk_lvs_op_with_handle_complete cb_fn, void *cb_arg);
37 void vbdev_lvs_destruct(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn, void *cb_arg);
38 void vbdev_lvs_unload(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn, void *cb_arg);
39 
40 int vbdev_lvol_create(struct spdk_lvol_store *lvs, const char *name, uint64_t sz,
41 		      bool thin_provisioned, enum lvol_clear_method clear_method,
42 		      spdk_lvol_op_with_handle_complete cb_fn,
43 		      void *cb_arg);
44 
45 void vbdev_lvol_create_snapshot(struct spdk_lvol *lvol, const char *snapshot_name,
46 				spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg);
47 
48 void vbdev_lvol_create_clone(struct spdk_lvol *lvol, const char *clone_name,
49 			     spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg);
50 void vbdev_lvol_create_bdev_clone(const char *esnap_uuid,
51 				  struct spdk_lvol_store *lvs, const char *clone_name,
52 				  spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg);
53 
54 /**
55  * \brief Change size of lvol
56  * \param lvol Handle to lvol
57  * \param sz Size of lvol to change
58  * \param cb_fn Completion callback
59  * \param cb_arg Completion callback custom arguments
60  * \return error
61  */
62 void vbdev_lvol_resize(struct spdk_lvol *lvol, uint64_t sz, spdk_lvol_op_complete cb_fn,
63 		       void *cb_arg);
64 
65 /**
66  * \brief Mark lvol as read only
67  * \param lvol Handle to lvol
68  * \param cb_fn Completion callback
69  * \param cb_arg Completion callback custom arguments
70  */
71 void vbdev_lvol_set_read_only(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg);
72 
73 void vbdev_lvol_rename(struct spdk_lvol *lvol, const char *new_lvol_name,
74 		       spdk_lvol_op_complete cb_fn, void *cb_arg);
75 
76 /**
77  * Destroy a logical volume
78  * \param lvol Handle to lvol
79  * \param cb_fn Completion callback
80  * \param cb_arg Completion callback custom arguments
81  */
82 void vbdev_lvol_destroy(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg);
83 
84 /**
85  * \brief Renames given lvolstore.
86  *
87  * \param lvs Pointer to lvolstore
88  * \param new_name New name of lvs
89  * \param cb_fn Completion callback
90  * \param cb_arg Completion callback custom arguments
91  */
92 void vbdev_lvs_rename(struct spdk_lvol_store *lvs, const char *new_lvs_name,
93 		      spdk_lvs_op_complete cb_fn, void *cb_arg);
94 
95 /**
96  * \brief Search for handle lvolstore
97  * \param uuid_str UUID of lvolstore
98  * \return Handle to spdk_lvol_store or NULL if not found.
99  */
100 struct spdk_lvol_store *vbdev_get_lvol_store_by_uuid(const char *uuid_str);
101 
102 /**
103  * \brief Search for handle to lvolstore
104  * \param name name of lvolstore
105  * \return Handle to spdk_lvol_store or NULL if not found.
106  */
107 struct spdk_lvol_store *vbdev_get_lvol_store_by_name(const char *name);
108 
109 /**
110  * \brief Search for handle to lvol_store_bdev
111  * \param lvs handle to lvolstore
112  * \return Handle to lvol_store_bdev or NULL if not found.
113  */
114 struct lvol_store_bdev *vbdev_get_lvs_bdev_by_lvs(struct spdk_lvol_store *lvs);
115 
116 struct spdk_lvol *vbdev_lvol_get_from_bdev(struct spdk_bdev *bdev);
117 
118 int vbdev_lvol_esnap_dev_create(void *bs_ctx, void *blob_ctx, struct spdk_blob *blob,
119 				const void *esnap_id, uint32_t id_len,
120 				struct spdk_bs_dev **_bs_dev);
121 
122 /**
123  * \brief Make a shallow copy of lvol over a bdev
124  *
125  * \param lvol Handle to lvol
126  * \param bdev_name Name of the bdev to copy on
127  * \param status_cb_fn Called repeatedly during operation with status updates
128  * \param status_cb_arg Argument passed to function status_cb_fn.
129  * \param cb_fn Completion callback
130  * \param cb_arg Completion callback custom arguments
131  *
132  * \return 0 if operation starts correctly, negative errno on failure.
133  */
134 int vbdev_lvol_shallow_copy(struct spdk_lvol *lvol, const char *bdev_name,
135 			    spdk_blob_shallow_copy_status status_cb_fn, void *status_cb_arg,
136 			    spdk_lvol_op_complete cb_fn, void *cb_arg);
137 
138 /**
139  * \brief Set an external snapshot as the parent of a lvol.
140  *
141  * \param lvol Handle to lvol
142  * \param esnap_name Name of the bdev that acts as external snapshot
143  * \param cb_fn Completion callback
144  * \param cb_arg Completion callback custom arguments
145  */
146 void vbdev_lvol_set_external_parent(struct spdk_lvol *lvol, const char *esnap_name,
147 				    spdk_lvol_op_complete cb_fn, void *cb_arg);
148 
149 #endif /* SPDK_VBDEV_LVOL_H */
150