xref: /spdk/lib/blob/zeroes.c (revision b30d57cdad6d2bc75cc1e4e2ebbcebcb0d98dcfa)
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 #include "spdk/stdinc.h"
35 #include "spdk/blob.h"
36 
37 #include "blobstore.h"
38 
39 static void
40 zeroes_destroy(struct spdk_bs_dev *bs_dev)
41 {
42 	return;
43 }
44 
45 static void
46 zeroes_read(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload,
47 	    uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args)
48 {
49 	memset(payload, 0, dev->blocklen * lba_count);
50 	cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
51 }
52 
53 static void
54 zeroes_write(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload,
55 	     uint64_t lba, uint32_t lba_count,
56 	     struct spdk_bs_dev_cb_args *cb_args)
57 {
58 	cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
59 	assert(false);
60 }
61 
62 static void
63 zeroes_readv(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
64 	     struct iovec *iov, int iovcnt,
65 	     uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args)
66 {
67 	int i;
68 
69 	for (i = 0; i < iovcnt; i++) {
70 		memset(iov[i].iov_base, 0, iov[i].iov_len);
71 	}
72 
73 	cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
74 }
75 
76 static void
77 zeroes_writev(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
78 	      struct iovec *iov, int iovcnt,
79 	      uint64_t lba, uint32_t lba_count,
80 	      struct spdk_bs_dev_cb_args *cb_args)
81 {
82 	cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
83 	assert(false);
84 }
85 
86 static void
87 zeroes_write_zeroes(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
88 		    uint64_t lba, uint32_t lba_count,
89 		    struct spdk_bs_dev_cb_args *cb_args)
90 {
91 	cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
92 	assert(false);
93 }
94 
95 static void
96 zeroes_unmap(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
97 	     uint64_t lba, uint32_t lba_count,
98 	     struct spdk_bs_dev_cb_args *cb_args)
99 {
100 	cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM);
101 	assert(false);
102 }
103 
104 static struct spdk_bs_dev g_zeroes_bs_dev = {
105 	.blockcnt = UINT64_MAX,
106 	.blocklen = 512,
107 	.create_channel = NULL,
108 	.destroy_channel = NULL,
109 	.destroy = zeroes_destroy,
110 	.read = zeroes_read,
111 	.write = zeroes_write,
112 	.readv = zeroes_readv,
113 	.writev = zeroes_writev,
114 	.write_zeroes = zeroes_write_zeroes,
115 	.unmap = zeroes_unmap,
116 };
117 
118 struct spdk_bs_dev *
119 bs_create_zeroes_dev(void)
120 {
121 	return &g_zeroes_bs_dev;
122 }
123