1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2018 Intel Corporation. 3 * All rights reserved. 4 * Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 5 */ 6 7 #include "spdk/stdinc.h" 8 #include "spdk/blob.h" 9 #include "spdk/dma.h" 10 11 #include "blobstore.h" 12 13 static void 14 zeroes_destroy(struct spdk_bs_dev *bs_dev) 15 { 16 return; 17 } 18 19 static void 20 zeroes_read(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload, 21 uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args) 22 { 23 memset(payload, 0, dev->blocklen * lba_count); 24 cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); 25 } 26 27 static void 28 zeroes_write(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload, 29 uint64_t lba, uint32_t lba_count, 30 struct spdk_bs_dev_cb_args *cb_args) 31 { 32 cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM); 33 assert(false); 34 } 35 36 static void 37 zeroes_readv(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, 38 struct iovec *iov, int iovcnt, 39 uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args) 40 { 41 int i; 42 43 for (i = 0; i < iovcnt; i++) { 44 memset(iov[i].iov_base, 0, iov[i].iov_len); 45 } 46 47 cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); 48 } 49 50 static void 51 zeroes_writev(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, 52 struct iovec *iov, int iovcnt, 53 uint64_t lba, uint32_t lba_count, 54 struct spdk_bs_dev_cb_args *cb_args) 55 { 56 cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM); 57 assert(false); 58 } 59 60 static void 61 _read_memory_domain_memzero_done(void *ctx, int rc) 62 { 63 struct spdk_bs_dev_cb_args *cb_args = (struct spdk_bs_dev_cb_args *)ctx; 64 65 cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, rc); 66 } 67 68 static void 69 zeroes_readv_ext(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, 70 struct iovec *iov, int iovcnt, 71 uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args, 72 struct spdk_blob_ext_io_opts *ext_io_opts) 73 { 74 int i, rc; 75 76 if (ext_io_opts->memory_domain) { 77 rc = spdk_memory_domain_memzero(ext_io_opts->memory_domain, ext_io_opts->memory_domain_ctx, iov, 78 iovcnt, _read_memory_domain_memzero_done, cb_args); 79 if (rc) { 80 cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, rc); 81 } 82 return; 83 } 84 85 for (i = 0; i < iovcnt; i++) { 86 memset(iov[i].iov_base, 0, iov[i].iov_len); 87 } 88 89 cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); 90 } 91 92 static void 93 zeroes_writev_ext(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, 94 struct iovec *iov, int iovcnt, 95 uint64_t lba, uint32_t lba_count, 96 struct spdk_bs_dev_cb_args *cb_args, 97 struct spdk_blob_ext_io_opts *ext_io_opts) 98 { 99 cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM); 100 assert(false); 101 } 102 103 static void 104 zeroes_write_zeroes(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, 105 uint64_t lba, uint64_t lba_count, 106 struct spdk_bs_dev_cb_args *cb_args) 107 { 108 cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM); 109 assert(false); 110 } 111 112 static void 113 zeroes_unmap(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, 114 uint64_t lba, uint64_t lba_count, 115 struct spdk_bs_dev_cb_args *cb_args) 116 { 117 cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM); 118 assert(false); 119 } 120 121 static bool 122 zeroes_is_zeroes(struct spdk_bs_dev *dev, uint64_t lba, uint64_t lba_count) 123 { 124 return true; 125 } 126 127 static bool 128 zeroes_translate_lba(struct spdk_bs_dev *dev, uint64_t lba, uint64_t *base_lba) 129 { 130 return false; 131 } 132 133 static struct spdk_bs_dev g_zeroes_bs_dev = { 134 .blockcnt = UINT64_MAX, 135 .blocklen = 512, 136 .create_channel = NULL, 137 .destroy_channel = NULL, 138 .destroy = zeroes_destroy, 139 .read = zeroes_read, 140 .write = zeroes_write, 141 .readv = zeroes_readv, 142 .writev = zeroes_writev, 143 .readv_ext = zeroes_readv_ext, 144 .writev_ext = zeroes_writev_ext, 145 .write_zeroes = zeroes_write_zeroes, 146 .unmap = zeroes_unmap, 147 .is_zeroes = zeroes_is_zeroes, 148 .translate_lba = zeroes_translate_lba, 149 }; 150 151 struct spdk_bs_dev * 152 bs_create_zeroes_dev(void) 153 { 154 return &g_zeroes_bs_dev; 155 } 156