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