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_INTERNAL_LVOLSTORE_H 8 #define SPDK_INTERNAL_LVOLSTORE_H 9 10 #include "spdk/blob.h" 11 #include "spdk/lvol.h" 12 #include "spdk/queue.h" 13 #include "spdk/tree.h" 14 #include "spdk/uuid.h" 15 16 /* Default size of blobstore cluster */ 17 #define SPDK_LVS_OPTS_CLUSTER_SZ (4 * 1024 * 1024) 18 19 /* UUID + '_' + blobid (20 characters for uint64_t). 20 * Null terminator is already included in SPDK_UUID_STRING_LEN. */ 21 #define SPDK_LVOL_UNIQUE_ID_MAX (SPDK_UUID_STRING_LEN + 1 + 20) 22 23 struct spdk_lvs_req { 24 spdk_lvs_op_complete cb_fn; 25 void *cb_arg; 26 struct spdk_lvol_store *lvol_store; 27 int lvserrno; 28 }; 29 30 struct spdk_lvs_grow_req { 31 struct spdk_lvs_req base; 32 spdk_lvs_op_complete cb_fn; 33 void *cb_arg; 34 struct lvol_store_bdev *lvs_bdev; 35 int lvol_cnt; 36 }; 37 38 struct spdk_lvol_req { 39 spdk_lvol_op_complete cb_fn; 40 void *cb_arg; 41 struct spdk_lvol *lvol; 42 /* Only set while lvol is being deleted and has a clone. */ 43 struct spdk_lvol *clone_lvol; 44 size_t sz; 45 struct spdk_io_channel *channel; 46 char name[SPDK_LVOL_NAME_MAX]; 47 }; 48 49 struct spdk_lvs_with_handle_req { 50 spdk_lvs_op_with_handle_complete cb_fn; 51 void *cb_arg; 52 struct spdk_lvol_store *lvol_store; 53 struct spdk_bs_dev *bs_dev; 54 struct spdk_bdev *base_bdev; 55 int lvserrno; 56 }; 57 58 struct spdk_lvs_destroy_req { 59 spdk_lvs_op_complete cb_fn; 60 void *cb_arg; 61 struct spdk_lvol_store *lvs; 62 }; 63 64 struct spdk_lvol_with_handle_req { 65 spdk_lvol_op_with_handle_complete cb_fn; 66 void *cb_arg; 67 struct spdk_lvol *lvol; 68 struct spdk_lvol *origlvol; 69 }; 70 71 struct spdk_lvs_degraded_lvol_set; 72 73 struct spdk_lvol_store { 74 struct spdk_bs_dev *bs_dev; 75 struct spdk_blob_store *blobstore; 76 struct spdk_blob *super_blob; 77 spdk_blob_id super_blob_id; 78 struct spdk_uuid uuid; 79 int lvol_count; 80 int lvols_opened; 81 TAILQ_HEAD(, spdk_lvol) lvols; 82 TAILQ_HEAD(, spdk_lvol) pending_lvols; 83 TAILQ_HEAD(, spdk_lvol) retry_open_lvols; 84 bool load_esnaps; 85 bool on_list; 86 TAILQ_ENTRY(spdk_lvol_store) link; 87 char name[SPDK_LVS_NAME_MAX]; 88 char new_name[SPDK_LVS_NAME_MAX]; 89 spdk_bs_esnap_dev_create esnap_bs_dev_create; 90 RB_HEAD(degraded_lvol_sets_tree, spdk_lvs_degraded_lvol_set) degraded_lvol_sets_tree; 91 struct spdk_thread *thread; 92 }; 93 94 struct spdk_lvol { 95 struct spdk_lvol_store *lvol_store; 96 struct spdk_blob *blob; 97 spdk_blob_id blob_id; 98 char unique_id[SPDK_LVOL_UNIQUE_ID_MAX]; 99 char name[SPDK_LVOL_NAME_MAX]; 100 struct spdk_uuid uuid; 101 char uuid_str[SPDK_UUID_STRING_LEN]; 102 struct spdk_bdev *bdev; 103 int ref_count; 104 bool action_in_progress; 105 enum blob_clear_method clear_method; 106 TAILQ_ENTRY(spdk_lvol) link; 107 struct spdk_lvs_degraded_lvol_set *degraded_set; 108 TAILQ_ENTRY(spdk_lvol) degraded_link; 109 }; 110 111 struct lvol_store_bdev *vbdev_lvol_store_first(void); 112 struct lvol_store_bdev *vbdev_lvol_store_next(struct lvol_store_bdev *prev); 113 114 void spdk_lvol_resize(struct spdk_lvol *lvol, uint64_t sz, spdk_lvol_op_complete cb_fn, 115 void *cb_arg); 116 117 void spdk_lvol_set_read_only(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, 118 void *cb_arg); 119 120 int spdk_lvs_esnap_missing_add(struct spdk_lvol_store *lvs, struct spdk_lvol *lvol, 121 const void *esnap_id, uint32_t id_len); 122 void spdk_lvs_esnap_missing_remove(struct spdk_lvol *lvol); 123 bool spdk_lvs_notify_hotplug(const void *esnap_id, uint32_t id_len, 124 spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg); 125 126 #endif /* SPDK_INTERNAL_LVOLSTORE_H */ 127