1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) Intel Corporation. 3 * All rights reserved. 4 */ 5 #include "spdk/ftl.h" 6 7 #include "ftl_conf.h" 8 #include "ftl_core.h" 9 10 static const struct spdk_ftl_conf g_default_conf = { 11 /* 20% spare blocks */ 12 .overprovisioning = 20, 13 /* IO pool size per user thread (this should be adjusted to thread IO qdepth) */ 14 .user_io_pool_size = 2048, 15 }; 16 17 void 18 spdk_ftl_get_default_conf(struct spdk_ftl_conf *conf) 19 { 20 *conf = g_default_conf; 21 } 22 23 void 24 spdk_ftl_dev_get_conf(const struct spdk_ftl_dev *dev, struct spdk_ftl_conf *conf) 25 { 26 *conf = dev->conf; 27 } 28 29 int 30 spdk_ftl_conf_copy(struct spdk_ftl_conf *dst, const struct spdk_ftl_conf *src) 31 { 32 char *name = NULL; 33 char *core_mask = NULL; 34 char *base_bdev = NULL; 35 char *cache_bdev = NULL; 36 37 if (src->name) { 38 name = strdup(src->name); 39 if (!name) { 40 goto error; 41 } 42 } 43 if (src->core_mask) { 44 core_mask = strdup(src->core_mask); 45 if (!core_mask) { 46 goto error; 47 } 48 } 49 if (src->base_bdev) { 50 base_bdev = strdup(src->base_bdev); 51 if (!base_bdev) { 52 goto error; 53 } 54 } 55 if (src->cache_bdev) { 56 cache_bdev = strdup(src->cache_bdev); 57 if (!cache_bdev) { 58 goto error; 59 } 60 } 61 62 *dst = *src; 63 dst->name = name; 64 dst->core_mask = core_mask; 65 dst->base_bdev = base_bdev; 66 dst->cache_bdev = cache_bdev; 67 return 0; 68 error: 69 free(name); 70 free(core_mask); 71 free(base_bdev); 72 free(cache_bdev); 73 return -ENOMEM; 74 } 75 76 void 77 spdk_ftl_conf_deinit(struct spdk_ftl_conf *conf) 78 { 79 free(conf->name); 80 free(conf->core_mask); 81 free(conf->base_bdev); 82 free(conf->cache_bdev); 83 } 84 85 int 86 ftl_conf_init_dev(struct spdk_ftl_dev *dev, const struct spdk_ftl_conf *conf) 87 { 88 int rc; 89 90 if (!conf->name) { 91 FTL_ERRLOG(dev, "No FTL name in configuration\n"); 92 return -EINVAL; 93 } 94 if (!conf->base_bdev) { 95 FTL_ERRLOG(dev, "No base device in configuration\n"); 96 return -EINVAL; 97 } 98 if (!conf->cache_bdev) { 99 FTL_ERRLOG(dev, "No NV cache device in configuration\n"); 100 return -EINVAL; 101 } 102 103 rc = spdk_ftl_conf_copy(&dev->conf, conf); 104 if (rc) { 105 return rc; 106 } 107 108 return 0; 109 } 110 111 bool 112 ftl_conf_is_valid(const struct spdk_ftl_conf *conf) 113 { 114 if (conf->overprovisioning >= 100) { 115 return false; 116 } 117 if (conf->overprovisioning == 0) { 118 return false; 119 } 120 121 return true; 122 } 123