dm_target_mirror.c revision 1.22 1 1.22 tkusumi /*$NetBSD: dm_target_mirror.c,v 1.22 2019/12/15 14:39:42 tkusumi 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.10 christos #include <sys/cdefs.h>
32 1.22 tkusumi __KERNEL_RCSID(0, "$NetBSD: dm_target_mirror.c,v 1.22 2019/12/15 14:39:42 tkusumi Exp $");
33 1.1 haad
34 1.1 haad /*
35 1.1 haad * This file implements initial version of device-mapper mirror target.
36 1.1 haad */
37 1.1 haad #include <sys/types.h>
38 1.1 haad #include <sys/param.h>
39 1.1 haad #include <sys/buf.h>
40 1.1 haad
41 1.1 haad #include "dm.h"
42 1.1 haad
43 1.9 haad /* dm_target_mirror.c */
44 1.18 tkusumi int dm_target_mirror_init(dm_table_entry_t *, int, char **);
45 1.20 tkusumi char *dm_target_mirror_table(void *);
46 1.9 haad int dm_target_mirror_strategy(dm_table_entry_t *, struct buf *);
47 1.9 haad int dm_target_mirror_sync(dm_table_entry_t *);
48 1.9 haad int dm_target_mirror_deps(dm_table_entry_t *, prop_array_t);
49 1.9 haad int dm_target_mirror_destroy(dm_table_entry_t *);
50 1.9 haad int dm_target_mirror_upcall(dm_table_entry_t *, struct buf *);
51 1.9 haad
52 1.16 tkusumi typedef struct target_mirror_config {
53 1.16 tkusumi #define MAX_MIRROR_COPIES 4
54 1.16 tkusumi dm_pdev_t *orig;
55 1.16 tkusumi dm_pdev_t *copies[MAX_MIRROR_COPIES];
56 1.16 tkusumi
57 1.16 tkusumi /* copied blocks bitmaps administration etc*/
58 1.16 tkusumi dm_pdev_t *log_pdev; /* for administration */
59 1.16 tkusumi uint64_t log_regionsize; /* blocksize of mirror */
60 1.16 tkusumi
61 1.16 tkusumi /* list of parts that still need copied etc.; run length encoded? */
62 1.16 tkusumi } dm_target_mirror_config_t;
63 1.16 tkusumi
64 1.1 haad #ifdef DM_TARGET_MODULE
65 1.1 haad /*
66 1.1 haad * Every target can be compiled directly to dm driver or as a
67 1.1 haad * separate module this part of target is used for loading targets
68 1.1 haad * to dm driver.
69 1.1 haad * Target can be unloaded from kernel only if there are no users of
70 1.1 haad * it e.g. there are no devices which uses that target.
71 1.1 haad */
72 1.1 haad #include <sys/kernel.h>
73 1.1 haad #include <sys/module.h>
74 1.1 haad
75 1.3 haad MODULE(MODULE_CLASS_MISC, dm_target_mirror, "dm");
76 1.1 haad
77 1.1 haad static int
78 1.1 haad dm_target_mirror_modcmd(modcmd_t cmd, void *arg)
79 1.1 haad {
80 1.1 haad dm_target_t *dmt;
81 1.1 haad int r;
82 1.8 haad
83 1.1 haad switch (cmd) {
84 1.1 haad case MODULE_CMD_INIT:
85 1.8 haad if ((dmt = dm_target_lookup("mirror")) != NULL) {
86 1.4 haad dm_target_unbusy(dmt);
87 1.1 haad return EEXIST;
88 1.4 haad }
89 1.1 haad dmt = dm_target_alloc("mirror");
90 1.8 haad
91 1.1 haad dmt->version[0] = 1;
92 1.1 haad dmt->version[1] = 0;
93 1.1 haad dmt->version[2] = 0;
94 1.1 haad dmt->init = &dm_target_mirror_init;
95 1.20 tkusumi dmt->table = &dm_target_mirror_table;
96 1.1 haad dmt->strategy = &dm_target_mirror_strategy;
97 1.9 haad dmt->sync = &dm_target_mirror_sync;
98 1.1 haad dmt->deps = &dm_target_mirror_deps;
99 1.1 haad dmt->destroy = &dm_target_mirror_destroy;
100 1.1 haad dmt->upcall = &dm_target_mirror_upcall;
101 1.1 haad
102 1.1 haad r = dm_target_insert(dmt);
103 1.8 haad
104 1.1 haad break;
105 1.1 haad
106 1.1 haad case MODULE_CMD_FINI:
107 1.1 haad r = dm_target_rem("mirror");
108 1.1 haad break;
109 1.1 haad
110 1.1 haad case MODULE_CMD_STAT:
111 1.1 haad return ENOTTY;
112 1.1 haad
113 1.1 haad default:
114 1.1 haad return ENOTTY;
115 1.1 haad }
116 1.1 haad
117 1.1 haad return r;
118 1.1 haad }
119 1.1 haad #endif
120 1.1 haad
121 1.5 haad /*
122 1.5 haad * Init function called from dm_table_load_ioctl.
123 1.5 haad * start length mirror log_type #logargs logarg1 ... logargN #devs device1 offset1 ... deviceN offsetN
124 1.5 haad * 0 52428800 mirror clustered_disk 4 253:2 1024 UUID block_on_error 3 253:3 0 253:4 0 253:5 0
125 1.5 haad */
126 1.1 haad int
127 1.18 tkusumi dm_target_mirror_init(dm_table_entry_t *table_en, int argc, char **argv)
128 1.1 haad {
129 1.1 haad
130 1.1 haad printf("Mirror target init function called!!\n");
131 1.1 haad
132 1.15 tkusumi table_en->target_config = NULL;
133 1.1 haad
134 1.2 haad return ENOSYS;
135 1.1 haad }
136 1.10 christos
137 1.20 tkusumi /* Table routine called to get params string. */
138 1.1 haad char *
139 1.20 tkusumi dm_target_mirror_table(void *target_config)
140 1.1 haad {
141 1.22 tkusumi
142 1.1 haad return NULL;
143 1.8 haad }
144 1.10 christos
145 1.1 haad /* Strategy routine called from dm_strategy. */
146 1.1 haad int
147 1.14 tkusumi dm_target_mirror_strategy(dm_table_entry_t *table_en, struct buf *bp)
148 1.1 haad {
149 1.1 haad
150 1.1 haad bp->b_error = EIO;
151 1.1 haad bp->b_resid = 0;
152 1.1 haad
153 1.1 haad biodone(bp);
154 1.8 haad
155 1.1 haad return 0;
156 1.1 haad }
157 1.10 christos
158 1.9 haad /* Sync underlying disk caches. */
159 1.9 haad int
160 1.14 tkusumi dm_target_mirror_sync(dm_table_entry_t *table_en)
161 1.9 haad {
162 1.9 haad
163 1.9 haad return 0;
164 1.9 haad }
165 1.10 christos
166 1.1 haad /* Doesn't do anything here. */
167 1.1 haad int
168 1.14 tkusumi dm_target_mirror_destroy(dm_table_entry_t *table_en)
169 1.1 haad {
170 1.22 tkusumi
171 1.1 haad /* Unbusy target so we can unload it */
172 1.1 haad dm_target_unbusy(table_en->target);
173 1.8 haad
174 1.1 haad return 0;
175 1.1 haad }
176 1.10 christos
177 1.1 haad /* Doesn't not need to do anything here. */
178 1.1 haad int
179 1.14 tkusumi dm_target_mirror_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
180 1.8 haad {
181 1.22 tkusumi
182 1.1 haad return 0;
183 1.1 haad }
184 1.10 christos
185 1.1 haad /* Unsupported for this target. */
186 1.1 haad int
187 1.14 tkusumi dm_target_mirror_upcall(dm_table_entry_t *table_en, struct buf *bp)
188 1.1 haad {
189 1.22 tkusumi
190 1.1 haad return 0;
191 1.1 haad }
192