Branch data Line data Source code
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 : 1276 : zeroes_destroy(struct spdk_bs_dev *bs_dev)
15 : : {
16 : 1276 : return;
17 : : }
18 : :
19 : : static void
20 : 168 : 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 : 168 : memset(payload, 0, dev->blocklen * lba_count);
24 : 168 : cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
25 : 168 : }
26 : :
27 : : static void
28 : 0 : 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 : 0 : cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
33 : 0 : assert(false);
34 : : }
35 : :
36 : : static void
37 : 32 : 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 [ + + ]: 96 : for (i = 0; i < iovcnt; i++) {
44 : 64 : memset(iov[i].iov_base, 0, iov[i].iov_len);
45 : : }
46 : :
47 : 32 : cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
48 : 32 : }
49 : :
50 : : static void
51 : 0 : 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 : 0 : cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
57 : 0 : assert(false);
58 : : }
59 : :
60 : : static void
61 : 0 : _read_memory_domain_memzero_done(void *ctx, int rc)
62 : : {
63 : 0 : struct spdk_bs_dev_cb_args *cb_args = (struct spdk_bs_dev_cb_args *)ctx;
64 : :
65 : 0 : cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, rc);
66 : 0 : }
67 : :
68 : : static void
69 : 18 : 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 [ - + ]: 18 : if (ext_io_opts->memory_domain) {
77 : 0 : 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 [ # # ]: 0 : if (rc) {
80 : 0 : cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, rc);
81 : : }
82 : 0 : return;
83 : : }
84 : :
85 [ + + ]: 36 : for (i = 0; i < iovcnt; i++) {
86 : 18 : memset(iov[i].iov_base, 0, iov[i].iov_len);
87 : : }
88 : :
89 : 18 : cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
90 : : }
91 : :
92 : : static void
93 : 0 : 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 : 0 : cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
100 : 0 : assert(false);
101 : : }
102 : :
103 : : static void
104 : 0 : 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 : 0 : cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
109 : 0 : assert(false);
110 : : }
111 : :
112 : : static void
113 : 0 : 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 : 0 : cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
118 : 0 : assert(false);
119 : : }
120 : :
121 : : static bool
122 : 814 : zeroes_is_zeroes(struct spdk_bs_dev *dev, uint64_t lba, uint64_t lba_count)
123 : : {
124 : 814 : return true;
125 : : }
126 : :
127 : : static bool
128 : 954 : zeroes_is_range_valid(struct spdk_bs_dev *dev, uint64_t lba, uint64_t lba_count)
129 : : {
130 : 954 : return true;
131 : : }
132 : :
133 : : static bool
134 : 404 : zeroes_translate_lba(struct spdk_bs_dev *dev, uint64_t lba, uint64_t *base_lba)
135 : : {
136 : 404 : return false;
137 : : }
138 : :
139 : : static struct spdk_bs_dev g_zeroes_bs_dev = {
140 : : .blockcnt = UINT64_MAX,
141 : : .blocklen = 512,
142 : : .create_channel = NULL,
143 : : .destroy_channel = NULL,
144 : : .destroy = zeroes_destroy,
145 : : .read = zeroes_read,
146 : : .write = zeroes_write,
147 : : .readv = zeroes_readv,
148 : : .writev = zeroes_writev,
149 : : .readv_ext = zeroes_readv_ext,
150 : : .writev_ext = zeroes_writev_ext,
151 : : .write_zeroes = zeroes_write_zeroes,
152 : : .unmap = zeroes_unmap,
153 : : .is_zeroes = zeroes_is_zeroes,
154 : : .is_range_valid = zeroes_is_range_valid,
155 : : .translate_lba = zeroes_translate_lba,
156 : : };
157 : :
158 : : struct spdk_bs_dev *
159 : 1276 : bs_create_zeroes_dev(void)
160 : : {
161 : 1276 : return &g_zeroes_bs_dev;
162 : : }
|