]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
11fdf7f2 TL |
34 | #include "spdk/stdinc.h" |
35 | #include "spdk/blob.h" | |
7c673cae | 36 | |
11fdf7f2 TL |
37 | #include "blobstore.h" |
38 | ||
39 | static void | |
40 | zeroes_destroy(struct spdk_bs_dev *bs_dev) | |
7c673cae | 41 | { |
11fdf7f2 | 42 | return; |
7c673cae FG |
43 | } |
44 | ||
45 | static void | |
11fdf7f2 TL |
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) | |
7c673cae | 48 | { |
11fdf7f2 TL |
49 | memset(payload, 0, dev->blocklen * lba_count); |
50 | cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); | |
7c673cae FG |
51 | } |
52 | ||
53 | static void | |
11fdf7f2 TL |
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) | |
7c673cae | 57 | { |
11fdf7f2 TL |
58 | cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM); |
59 | assert(false); | |
7c673cae FG |
60 | } |
61 | ||
62 | static void | |
11fdf7f2 TL |
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) | |
7c673cae | 66 | { |
11fdf7f2 TL |
67 | int i; |
68 | ||
69 | for (i = 0; i < iovcnt; i++) { | |
70 | memset(iov[i].iov_base, 0, iov[i].iov_len); | |
71 | } | |
7c673cae | 72 | |
7c673cae FG |
73 | cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0); |
74 | } | |
75 | ||
76 | static void | |
11fdf7f2 TL |
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) | |
7c673cae | 81 | { |
11fdf7f2 TL |
82 | cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM); |
83 | assert(false); | |
7c673cae FG |
84 | } |
85 | ||
86 | static void | |
11fdf7f2 TL |
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) | |
7c673cae | 90 | { |
9f95a23c TL |
91 | cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM); |
92 | assert(false); | |
7c673cae FG |
93 | } |
94 | ||
95 | static void | |
11fdf7f2 TL |
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) | |
7c673cae | 99 | { |
9f95a23c TL |
100 | cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EPERM); |
101 | assert(false); | |
7c673cae FG |
102 | } |
103 | ||
11fdf7f2 TL |
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 | spdk_bs_create_zeroes_dev(void) | |
7c673cae | 120 | { |
11fdf7f2 | 121 | return &g_zeroes_bs_dev; |
7c673cae | 122 | } |