1 /*- 2 * BSD LICENSE 3 * 4 * Copyright (c) Intel Corporation. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name of Intel Corporation nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #ifndef SPDK_INTERNAL_LVOLSTORE_H 35 #define SPDK_INTERNAL_LVOLSTORE_H 36 37 #include "spdk/blob.h" 38 #include "spdk/lvol.h" 39 #include "spdk/uuid.h" 40 #include "spdk/bdev_module.h" 41 42 /* Default size of blobstore cluster */ 43 #define SPDK_LVS_OPTS_CLUSTER_SZ (4 * 1024 * 1024) 44 45 /* UUID + '_' + blobid (20 characters for uint64_t). 46 * Null terminator is already included in SPDK_UUID_STRING_LEN. */ 47 #define SPDK_LVOL_UNIQUE_ID_MAX (SPDK_UUID_STRING_LEN + 1 + 20) 48 49 struct spdk_lvs_req { 50 spdk_lvs_op_complete cb_fn; 51 void *cb_arg; 52 struct spdk_lvol_store *lvol_store; 53 int lvserrno; 54 }; 55 56 struct spdk_lvol_req { 57 spdk_lvol_op_complete cb_fn; 58 void *cb_arg; 59 struct spdk_lvol *lvol; 60 size_t sz; 61 struct spdk_io_channel *channel; 62 char name[SPDK_LVOL_NAME_MAX]; 63 }; 64 65 struct spdk_lvs_with_handle_req { 66 spdk_lvs_op_with_handle_complete cb_fn; 67 void *cb_arg; 68 struct spdk_lvol_store *lvol_store; 69 struct spdk_bs_dev *bs_dev; 70 struct spdk_bdev *base_bdev; 71 int lvserrno; 72 }; 73 74 struct spdk_lvs_destroy_req { 75 spdk_lvs_op_complete cb_fn; 76 void *cb_arg; 77 struct spdk_lvol_store *lvs; 78 }; 79 80 struct spdk_lvol_with_handle_req { 81 spdk_lvol_op_with_handle_complete cb_fn; 82 void *cb_arg; 83 struct spdk_lvol *lvol; 84 }; 85 86 struct spdk_lvol_store { 87 struct spdk_bs_dev *bs_dev; 88 struct spdk_blob_store *blobstore; 89 struct spdk_blob *super_blob; 90 spdk_blob_id super_blob_id; 91 struct spdk_uuid uuid; 92 int lvol_count; 93 int lvols_opened; 94 bool destruct; 95 TAILQ_HEAD(, spdk_lvol) lvols; 96 TAILQ_HEAD(, spdk_lvol) pending_lvols; 97 bool on_list; 98 TAILQ_ENTRY(spdk_lvol_store) link; 99 char name[SPDK_LVS_NAME_MAX]; 100 char new_name[SPDK_LVS_NAME_MAX]; 101 }; 102 103 struct spdk_lvol { 104 struct spdk_lvol_store *lvol_store; 105 struct spdk_blob *blob; 106 spdk_blob_id blob_id; 107 char unique_id[SPDK_LVOL_UNIQUE_ID_MAX]; 108 char name[SPDK_LVOL_NAME_MAX]; 109 struct spdk_uuid uuid; 110 char uuid_str[SPDK_UUID_STRING_LEN]; 111 bool thin_provision; 112 struct spdk_bdev *bdev; 113 int ref_count; 114 bool action_in_progress; 115 enum blob_clear_method clear_method; 116 TAILQ_ENTRY(spdk_lvol) link; 117 }; 118 119 struct lvol_store_bdev *vbdev_lvol_store_first(void); 120 struct lvol_store_bdev *vbdev_lvol_store_next(struct lvol_store_bdev *prev); 121 122 void spdk_lvol_resize(struct spdk_lvol *lvol, uint64_t sz, spdk_lvol_op_complete cb_fn, 123 void *cb_arg); 124 125 void spdk_lvol_set_read_only(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, 126 void *cb_arg); 127 128 #endif /* SPDK_INTERNAL_LVOLSTORE_H */ 129