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