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