2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2018 Intel Corporation.
|
2018-01-29 17:24:04 +00:00
|
|
|
* All rights reserved.
|
2022-01-31 08:53:15 +00:00
|
|
|
* Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2018-01-29 17:24:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
#include "spdk/blob.h"
|
2022-01-31 08:53:15 +00:00
|
|
|
#include "spdk/dma.h"
|
2018-01-29 17:24:04 +00:00
|
|
|
|
|
|
|
#include "blobstore.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
zeroes_destroy(struct spdk_bs_dev *bs_dev)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zeroes_read(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload,
|
|
|
|
uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args)
|
|
|
|
{
|
|
|
|
memset(payload, 0, dev->blocklen * lba_count);
|
|
|
|
cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zeroes_write(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload,
|
|
|
|
uint64_t lba, uint32_t lba_count,
|
|
|
|
struct spdk_bs_dev_cb_args *cb_args)
|
|
|
|
{
|
|
|
|
cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zeroes_readv(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
|
|
|
|
struct iovec *iov, int iovcnt,
|
|
|
|
uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < iovcnt; i++) {
|
|
|
|
memset(iov[i].iov_base, 0, iov[i].iov_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zeroes_writev(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
|
|
|
|
struct iovec *iov, int iovcnt,
|
|
|
|
uint64_t lba, uint32_t lba_count,
|
|
|
|
struct spdk_bs_dev_cb_args *cb_args)
|
|
|
|
{
|
|
|
|
cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
|
2022-01-31 08:53:15 +00:00
|
|
|
static void
|
|
|
|
_read_memory_domain_memzero_done(void *ctx, int rc)
|
|
|
|
{
|
|
|
|
struct spdk_bs_dev_cb_args *cb_args = (struct spdk_bs_dev_cb_args *)ctx;
|
|
|
|
|
|
|
|
cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zeroes_readv_ext(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
|
|
|
|
struct iovec *iov, int iovcnt,
|
|
|
|
uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args,
|
|
|
|
struct spdk_blob_ext_io_opts *ext_io_opts)
|
|
|
|
{
|
|
|
|
int i, rc;
|
|
|
|
|
|
|
|
if (ext_io_opts->memory_domain) {
|
|
|
|
rc = spdk_memory_domain_memzero(ext_io_opts->memory_domain, ext_io_opts->memory_domain_ctx, iov,
|
|
|
|
iovcnt, _read_memory_domain_memzero_done, cb_args);
|
|
|
|
if (rc) {
|
|
|
|
cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, rc);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < iovcnt; i++) {
|
|
|
|
memset(iov[i].iov_base, 0, iov[i].iov_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zeroes_writev_ext(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
|
|
|
|
struct iovec *iov, int iovcnt,
|
|
|
|
uint64_t lba, uint32_t lba_count,
|
|
|
|
struct spdk_bs_dev_cb_args *cb_args,
|
|
|
|
struct spdk_blob_ext_io_opts *ext_io_opts)
|
|
|
|
{
|
|
|
|
cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
|
2018-01-29 17:24:04 +00:00
|
|
|
static void
|
|
|
|
zeroes_write_zeroes(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
|
2021-10-05 23:37:19 +00:00
|
|
|
uint64_t lba, uint64_t lba_count,
|
2018-01-29 17:24:04 +00:00
|
|
|
struct spdk_bs_dev_cb_args *cb_args)
|
|
|
|
{
|
2019-06-05 03:47:11 +00:00
|
|
|
cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
|
|
|
|
assert(false);
|
2018-01-29 17:24:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
zeroes_unmap(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
|
2021-10-05 23:37:19 +00:00
|
|
|
uint64_t lba, uint64_t lba_count,
|
2018-01-29 17:24:04 +00:00
|
|
|
struct spdk_bs_dev_cb_args *cb_args)
|
|
|
|
{
|
2019-06-05 03:47:11 +00:00
|
|
|
cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
|
|
|
|
assert(false);
|
2018-01-29 17:24:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-22 13:55:46 +00:00
|
|
|
static bool
|
|
|
|
zeroes_is_zeroes(struct spdk_bs_dev *dev, uint64_t lba, uint64_t lba_count)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-09-15 21:56:12 +00:00
|
|
|
static bool
|
|
|
|
zeroes_translate_lba(struct spdk_bs_dev *dev, uint64_t lba, uint64_t *base_lba)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-29 17:24:04 +00:00
|
|
|
static struct spdk_bs_dev g_zeroes_bs_dev = {
|
|
|
|
.blockcnt = UINT64_MAX,
|
2018-10-01 14:20:00 +00:00
|
|
|
.blocklen = 512,
|
2018-01-29 17:24:04 +00:00
|
|
|
.create_channel = NULL,
|
|
|
|
.destroy_channel = NULL,
|
|
|
|
.destroy = zeroes_destroy,
|
|
|
|
.read = zeroes_read,
|
|
|
|
.write = zeroes_write,
|
|
|
|
.readv = zeroes_readv,
|
|
|
|
.writev = zeroes_writev,
|
2022-01-31 08:53:15 +00:00
|
|
|
.readv_ext = zeroes_readv_ext,
|
|
|
|
.writev_ext = zeroes_writev_ext,
|
2018-01-29 17:24:04 +00:00
|
|
|
.write_zeroes = zeroes_write_zeroes,
|
|
|
|
.unmap = zeroes_unmap,
|
2022-06-22 13:55:46 +00:00
|
|
|
.is_zeroes = zeroes_is_zeroes,
|
2022-09-15 21:56:12 +00:00
|
|
|
.translate_lba = zeroes_translate_lba,
|
2018-01-29 17:24:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct spdk_bs_dev *
|
2020-04-07 00:03:39 +00:00
|
|
|
bs_create_zeroes_dev(void)
|
2018-01-29 17:24:04 +00:00
|
|
|
{
|
|
|
|
return &g_zeroes_bs_dev;
|
|
|
|
}
|