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