dm_target_error.c revision 1.26 1 1.26 tkusumi /* $NetBSD: dm_target_error.c,v 1.26 2019/12/18 14:31:35 tkusumi Exp $ */
2 1.2 haad
3 1.2 haad /*
4 1.2 haad * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.2 haad * All rights reserved.
6 1.2 haad *
7 1.2 haad * This code is derived from software contributed to The NetBSD Foundation
8 1.2 haad * by Adam Hamsik.
9 1.2 haad *
10 1.2 haad * Redistribution and use in source and binary forms, with or without
11 1.2 haad * modification, are permitted provided that the following conditions
12 1.2 haad * are met:
13 1.2 haad * 1. Redistributions of source code must retain the above copyright
14 1.2 haad * notice, this list of conditions and the following disclaimer.
15 1.2 haad * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 haad * notice, this list of conditions and the following disclaimer in the
17 1.2 haad * documentation and/or other materials provided with the distribution.
18 1.2 haad *
19 1.2 haad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2 haad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2 haad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2 haad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2 haad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2 haad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2 haad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2 haad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2 haad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2 haad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2 haad * POSSIBILITY OF SUCH DAMAGE.
30 1.2 haad */
31 1.12 christos #include <sys/cdefs.h>
32 1.26 tkusumi __KERNEL_RCSID(0, "$NetBSD: dm_target_error.c,v 1.26 2019/12/18 14:31:35 tkusumi Exp $");
33 1.2 haad
34 1.2 haad /*
35 1.2 haad * This file implements initial version of device-mapper error target.
36 1.2 haad */
37 1.2 haad #include <sys/types.h>
38 1.2 haad #include <sys/param.h>
39 1.2 haad #include <sys/buf.h>
40 1.2 haad
41 1.2 haad #include "dm.h"
42 1.2 haad
43 1.4 haad #ifdef DM_TARGET_MODULE
44 1.4 haad /*
45 1.4 haad * Every target can be compiled directly to dm driver or as a
46 1.4 haad * separate module this part of target is used for loading targets
47 1.4 haad * to dm driver.
48 1.4 haad * Target can be unloaded from kernel only if there are no users of
49 1.4 haad * it e.g. there are no devices which uses that target.
50 1.4 haad */
51 1.4 haad #include <sys/kernel.h>
52 1.4 haad #include <sys/module.h>
53 1.4 haad
54 1.6 haad MODULE(MODULE_CLASS_MISC, dm_target_error, "dm");
55 1.4 haad
56 1.4 haad static int
57 1.4 haad dm_target_error_modcmd(modcmd_t cmd, void *arg)
58 1.4 haad {
59 1.4 haad dm_target_t *dmt;
60 1.4 haad int r;
61 1.10 haad
62 1.4 haad switch (cmd) {
63 1.4 haad case MODULE_CMD_INIT:
64 1.10 haad if ((dmt = dm_target_lookup("error")) != NULL) {
65 1.7 haad dm_target_unbusy(dmt);
66 1.4 haad return EEXIST;
67 1.7 haad }
68 1.4 haad dmt = dm_target_alloc("error");
69 1.10 haad
70 1.4 haad dmt->version[0] = 1;
71 1.4 haad dmt->version[1] = 0;
72 1.4 haad dmt->version[2] = 0;
73 1.4 haad dmt->init = &dm_target_error_init;
74 1.21 tkusumi dmt->table = &dm_target_error_table;
75 1.4 haad dmt->strategy = &dm_target_error_strategy;
76 1.4 haad dmt->deps = &dm_target_error_deps;
77 1.4 haad dmt->destroy = &dm_target_error_destroy;
78 1.4 haad dmt->upcall = &dm_target_error_upcall;
79 1.4 haad
80 1.4 haad r = dm_target_insert(dmt);
81 1.10 haad
82 1.4 haad break;
83 1.4 haad
84 1.4 haad case MODULE_CMD_FINI:
85 1.4 haad r = dm_target_rem("error");
86 1.4 haad break;
87 1.4 haad
88 1.4 haad case MODULE_CMD_STAT:
89 1.4 haad return ENOTTY;
90 1.4 haad
91 1.4 haad default:
92 1.4 haad return ENOTTY;
93 1.4 haad }
94 1.4 haad
95 1.4 haad return r;
96 1.4 haad }
97 1.4 haad #endif
98 1.4 haad
99 1.2 haad /* Init function called from dm_table_load_ioctl. */
100 1.2 haad int
101 1.19 tkusumi dm_target_error_init(dm_table_entry_t *table_en, int argc, char **argv)
102 1.2 haad {
103 1.2 haad
104 1.26 tkusumi if (argc != 0) {
105 1.26 tkusumi printf("Error target takes 0 args, %d given\n", argc);
106 1.26 tkusumi return EINVAL;
107 1.26 tkusumi }
108 1.26 tkusumi
109 1.2 haad printf("Error target init function called!!\n");
110 1.2 haad
111 1.17 tkusumi table_en->target_config = NULL;
112 1.2 haad
113 1.2 haad return 0;
114 1.2 haad }
115 1.12 christos
116 1.21 tkusumi /* Table routine called to get params string. */
117 1.2 haad char *
118 1.21 tkusumi dm_target_error_table(void *target_config)
119 1.2 haad {
120 1.24 tkusumi
121 1.2 haad return NULL;
122 1.10 haad }
123 1.12 christos
124 1.2 haad /* Strategy routine called from dm_strategy. */
125 1.2 haad int
126 1.16 tkusumi dm_target_error_strategy(dm_table_entry_t *table_en, struct buf *bp)
127 1.2 haad {
128 1.2 haad
129 1.2 haad bp->b_error = EIO;
130 1.2 haad bp->b_resid = 0;
131 1.2 haad
132 1.2 haad biodone(bp);
133 1.10 haad
134 1.2 haad return 0;
135 1.2 haad }
136 1.12 christos
137 1.2 haad /* Doesn't do anything here. */
138 1.2 haad int
139 1.16 tkusumi dm_target_error_destroy(dm_table_entry_t *table_en)
140 1.2 haad {
141 1.24 tkusumi
142 1.3 haad /* Unbusy target so we can unload it */
143 1.3 haad dm_target_unbusy(table_en->target);
144 1.10 haad
145 1.2 haad return 0;
146 1.2 haad }
147 1.12 christos
148 1.2 haad /* Doesn't not need to do anything here. */
149 1.2 haad int
150 1.16 tkusumi dm_target_error_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
151 1.10 haad {
152 1.24 tkusumi
153 1.2 haad return 0;
154 1.2 haad }
155 1.12 christos
156 1.2 haad /* Unsupported for this target. */
157 1.2 haad int
158 1.16 tkusumi dm_target_error_upcall(dm_table_entry_t *table_en, struct buf *bp)
159 1.2 haad {
160 1.24 tkusumi
161 1.2 haad return 0;
162 1.2 haad }
163