device-mapper.c revision 1.4.2.2 1 1.4.2.2 mjf /* $NetBSD: device-mapper.c,v 1.4.2.2 2009/01/17 13:28:53 mjf Exp $ */
2 1.4.2.2 mjf
3 1.4.2.2 mjf /*
4 1.4.2.2 mjf * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.4.2.2 mjf * All rights reserved.
6 1.4.2.2 mjf *
7 1.4.2.2 mjf * This code is derived from software contributed to The NetBSD Foundation
8 1.4.2.2 mjf * by Adam Hamsik.
9 1.4.2.2 mjf *
10 1.4.2.2 mjf * Redistribution and use in source and binary forms, with or without
11 1.4.2.2 mjf * modification, are permitted provided that the following conditions
12 1.4.2.2 mjf * are met:
13 1.4.2.2 mjf * 1. Redistributions of source code must retain the above copyright
14 1.4.2.2 mjf * notice, this list of conditions and the following disclaimer.
15 1.4.2.2 mjf * 2. Redistributions in binary form must reproduce the above copyright
16 1.4.2.2 mjf * notice, this list of conditions and the following disclaimer in the
17 1.4.2.2 mjf * documentation and/or other materials provided with the distribution.
18 1.4.2.2 mjf *
19 1.4.2.2 mjf * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.4.2.2 mjf * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.4.2.2 mjf * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.4.2.2 mjf * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.4.2.2 mjf * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.4.2.2 mjf * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.4.2.2 mjf * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.4.2.2 mjf * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.4.2.2 mjf * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.4.2.2 mjf * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.4.2.2 mjf * POSSIBILITY OF SUCH DAMAGE.
30 1.4.2.2 mjf */
31 1.4.2.2 mjf
32 1.4.2.2 mjf /*
33 1.4.2.2 mjf * I want to say thank you to all people who helped me with this project.
34 1.4.2.2 mjf */
35 1.4.2.2 mjf
36 1.4.2.2 mjf #include <sys/types.h>
37 1.4.2.2 mjf #include <sys/param.h>
38 1.4.2.2 mjf
39 1.4.2.2 mjf #include <sys/buf.h>
40 1.4.2.2 mjf #include <sys/conf.h>
41 1.4.2.2 mjf #include <sys/dkio.h>
42 1.4.2.2 mjf #include <sys/disk.h>
43 1.4.2.2 mjf #include <sys/disklabel.h>
44 1.4.2.2 mjf #include <sys/ioctl.h>
45 1.4.2.2 mjf #include <sys/ioccom.h>
46 1.4.2.2 mjf #include <sys/kmem.h>
47 1.4.2.2 mjf #include <sys/module.h>
48 1.4.2.2 mjf
49 1.4.2.2 mjf #include "netbsd-dm.h"
50 1.4.2.2 mjf #include "dm.h"
51 1.4.2.2 mjf
52 1.4.2.2 mjf static dev_type_open(dmopen);
53 1.4.2.2 mjf static dev_type_close(dmclose);
54 1.4.2.2 mjf static dev_type_read(dmread);
55 1.4.2.2 mjf static dev_type_write(dmwrite);
56 1.4.2.2 mjf static dev_type_ioctl(dmioctl);
57 1.4.2.2 mjf static dev_type_strategy(dmstrategy);
58 1.4.2.2 mjf static dev_type_dump(dmdump);
59 1.4.2.2 mjf static dev_type_size(dmsize);
60 1.4.2.2 mjf
61 1.4.2.2 mjf /* attach and detach routines */
62 1.4.2.2 mjf int dmattach(void);
63 1.4.2.2 mjf int dmdestroy(void);
64 1.4.2.2 mjf
65 1.4.2.2 mjf static int dm_cmd_to_fun(prop_dictionary_t);
66 1.4.2.2 mjf static int disk_ioctl_switch(dev_t, u_long, void *);
67 1.4.2.2 mjf static int dm_ioctl_switch(u_long);
68 1.4.2.2 mjf static void dmminphys(struct buf *);
69 1.4.2.2 mjf
70 1.4.2.2 mjf /* ***Variable-definitions*** */
71 1.4.2.2 mjf const struct bdevsw dm_bdevsw = {
72 1.4.2.2 mjf dmopen, dmclose, dmstrategy, dmioctl, dmdump, dmsize, D_DISK | D_MPSAFE
73 1.4.2.2 mjf };
74 1.4.2.2 mjf
75 1.4.2.2 mjf const struct cdevsw dm_cdevsw = {
76 1.4.2.2 mjf dmopen, dmclose, dmread, dmwrite, dmioctl,
77 1.4.2.2 mjf nostop, notty, nopoll, nommap, nokqfilter, D_DISK | D_MPSAFE
78 1.4.2.2 mjf };
79 1.4.2.2 mjf
80 1.4.2.2 mjf extern uint64_t dev_counter;
81 1.4.2.2 mjf
82 1.4.2.2 mjf /*
83 1.4.2.2 mjf * This array is used to translate cmd to function pointer.
84 1.4.2.2 mjf *
85 1.4.2.2 mjf * Interface between libdevmapper and lvm2tools uses different
86 1.4.2.2 mjf * names for one IOCTL call because libdevmapper do another thing
87 1.4.2.2 mjf * then. When I run "info" or "mknodes" libdevmapper will send same
88 1.4.2.2 mjf * ioctl to kernel but will do another things in userspace.
89 1.4.2.2 mjf *
90 1.4.2.2 mjf */
91 1.4.2.2 mjf struct cmd_function cmd_fn[] = {
92 1.4.2.2 mjf {"version", dm_get_version_ioctl},
93 1.4.2.2 mjf {"targets", dm_list_versions_ioctl},
94 1.4.2.2 mjf {"create", dm_dev_create_ioctl},
95 1.4.2.2 mjf {"info", dm_dev_status_ioctl},
96 1.4.2.2 mjf {"mknodes", dm_dev_status_ioctl},
97 1.4.2.2 mjf {"names", dm_dev_list_ioctl},
98 1.4.2.2 mjf {"suspend", dm_dev_suspend_ioctl},
99 1.4.2.2 mjf {"remove", dm_dev_remove_ioctl},
100 1.4.2.2 mjf {"rename", dm_dev_rename_ioctl},
101 1.4.2.2 mjf {"resume", dm_dev_resume_ioctl},
102 1.4.2.2 mjf {"clear", dm_table_clear_ioctl},
103 1.4.2.2 mjf {"deps", dm_table_deps_ioctl},
104 1.4.2.2 mjf {"reload", dm_table_load_ioctl},
105 1.4.2.2 mjf {"status", dm_table_status_ioctl},
106 1.4.2.2 mjf {"table", dm_table_status_ioctl},
107 1.4.2.2 mjf {NULL, NULL}
108 1.4.2.2 mjf };
109 1.4.2.2 mjf
110 1.4.2.2 mjf
111 1.4.2.2 mjf MODULE(MODULE_CLASS_DRIVER, dm, NULL);
112 1.4.2.2 mjf
113 1.4.2.2 mjf /* New module handle routine */
114 1.4.2.2 mjf static int
115 1.4.2.2 mjf dm_modcmd(modcmd_t cmd, void *arg)
116 1.4.2.2 mjf {
117 1.4.2.2 mjf #ifdef _MODULE
118 1.4.2.2 mjf int bmajor = -1, cmajor = -1;
119 1.4.2.2 mjf
120 1.4.2.2 mjf switch (cmd) {
121 1.4.2.2 mjf case MODULE_CMD_INIT:
122 1.4.2.2 mjf dmattach();
123 1.4.2.2 mjf return devsw_attach("dm", &dm_bdevsw, &bmajor,
124 1.4.2.2 mjf &dm_cdevsw, &cmajor);
125 1.4.2.2 mjf break;
126 1.4.2.2 mjf
127 1.4.2.2 mjf case MODULE_CMD_FINI:
128 1.4.2.2 mjf /*
129 1.4.2.2 mjf * Disable unloading of dm module if there are any devices
130 1.4.2.2 mjf * defined in driver. This is probably too strong we need
131 1.4.2.2 mjf * to disable auto-unload only if there is mounted dm device
132 1.4.2.2 mjf * present.
133 1.4.2.2 mjf */
134 1.4.2.2 mjf if (dev_counter > 0)
135 1.4.2.2 mjf return EBUSY;
136 1.4.2.2 mjf dmdestroy();
137 1.4.2.2 mjf return devsw_detach(&dm_bdevsw, &dm_cdevsw);
138 1.4.2.2 mjf break;
139 1.4.2.2 mjf case MODULE_CMD_STAT:
140 1.4.2.2 mjf return ENOTTY;
141 1.4.2.2 mjf
142 1.4.2.2 mjf default:
143 1.4.2.2 mjf return ENOTTY;
144 1.4.2.2 mjf }
145 1.4.2.2 mjf
146 1.4.2.2 mjf return 0;
147 1.4.2.2 mjf #else
148 1.4.2.2 mjf
149 1.4.2.2 mjf if (cmd == MODULE_CMD_INIT)
150 1.4.2.2 mjf return 0;
151 1.4.2.2 mjf return ENOTTY;
152 1.4.2.2 mjf
153 1.4.2.2 mjf #endif /* _MODULE */
154 1.4.2.2 mjf }
155 1.4.2.2 mjf
156 1.4.2.2 mjf
157 1.4.2.2 mjf /* attach routine */
158 1.4.2.2 mjf int
159 1.4.2.2 mjf dmattach(void)
160 1.4.2.2 mjf {
161 1.4.2.2 mjf dm_target_init();
162 1.4.2.2 mjf dm_dev_init();
163 1.4.2.2 mjf dm_pdev_init();
164 1.4.2.2 mjf
165 1.4.2.2 mjf return 0;
166 1.4.2.2 mjf }
167 1.4.2.2 mjf
168 1.4.2.2 mjf /* Destroy routine */
169 1.4.2.2 mjf int
170 1.4.2.2 mjf dmdestroy(void)
171 1.4.2.2 mjf {
172 1.4.2.2 mjf dm_dev_destroy();
173 1.4.2.2 mjf dm_pdev_destroy();
174 1.4.2.2 mjf dm_target_destroy();
175 1.4.2.2 mjf
176 1.4.2.2 mjf return 0;
177 1.4.2.2 mjf }
178 1.4.2.2 mjf
179 1.4.2.2 mjf static int
180 1.4.2.2 mjf dmopen(dev_t dev, int flags, int mode, struct lwp *l)
181 1.4.2.2 mjf {
182 1.4.2.2 mjf aprint_debug("open routine called %llu\n", minor(dev));
183 1.4.2.2 mjf return 0;
184 1.4.2.2 mjf }
185 1.4.2.2 mjf
186 1.4.2.2 mjf static int
187 1.4.2.2 mjf dmclose(dev_t dev, int flags, int mode, struct lwp *l)
188 1.4.2.2 mjf {
189 1.4.2.2 mjf aprint_debug("CLOSE routine called\n");
190 1.4.2.2 mjf
191 1.4.2.2 mjf return 0;
192 1.4.2.2 mjf }
193 1.4.2.2 mjf
194 1.4.2.2 mjf
195 1.4.2.2 mjf static int
196 1.4.2.2 mjf dmioctl(dev_t dev, const u_long cmd, void *data, int flag, struct lwp *l)
197 1.4.2.2 mjf {
198 1.4.2.2 mjf int r;
199 1.4.2.2 mjf prop_dictionary_t dm_dict_in;
200 1.4.2.2 mjf
201 1.4.2.2 mjf r = 0;
202 1.4.2.2 mjf
203 1.4.2.2 mjf aprint_debug("dmioctl called\n");
204 1.4.2.2 mjf
205 1.4.2.2 mjf KASSERT(data != NULL);
206 1.4.2.2 mjf
207 1.4.2.2 mjf if (disk_ioctl_switch(dev, cmd, data) != 0) {
208 1.4.2.2 mjf struct plistref *pref = (struct plistref *) data;
209 1.4.2.2 mjf
210 1.4.2.2 mjf if((r = prop_dictionary_copyin_ioctl(pref, cmd, &dm_dict_in)) != 0)
211 1.4.2.2 mjf return r;
212 1.4.2.2 mjf
213 1.4.2.2 mjf dm_check_version(dm_dict_in);
214 1.4.2.2 mjf
215 1.4.2.2 mjf /* call cmd selected function */
216 1.4.2.2 mjf if ((r = dm_ioctl_switch(cmd)) != 0) {
217 1.4.2.2 mjf prop_object_release(dm_dict_in);
218 1.4.2.2 mjf return r;
219 1.4.2.2 mjf }
220 1.4.2.2 mjf
221 1.4.2.2 mjf /* run ioctl routine */
222 1.4.2.2 mjf if ((r = dm_cmd_to_fun(dm_dict_in)) != 0) {
223 1.4.2.2 mjf prop_object_release(dm_dict_in);
224 1.4.2.2 mjf return r;
225 1.4.2.2 mjf }
226 1.4.2.2 mjf
227 1.4.2.2 mjf r = prop_dictionary_copyout_ioctl(pref, cmd, dm_dict_in);
228 1.4.2.2 mjf
229 1.4.2.2 mjf prop_object_release(dm_dict_in);
230 1.4.2.2 mjf }
231 1.4.2.2 mjf
232 1.4.2.2 mjf return r;
233 1.4.2.2 mjf }
234 1.4.2.2 mjf
235 1.4.2.2 mjf /*
236 1.4.2.2 mjf * Translate command sent from libdevmapper to func.
237 1.4.2.2 mjf */
238 1.4.2.2 mjf static int
239 1.4.2.2 mjf dm_cmd_to_fun(prop_dictionary_t dm_dict){
240 1.4.2.2 mjf int i, r;
241 1.4.2.2 mjf prop_string_t command;
242 1.4.2.2 mjf
243 1.4.2.2 mjf r = 0;
244 1.4.2.2 mjf
245 1.4.2.2 mjf if ((command = prop_dictionary_get(dm_dict, DM_IOCTL_COMMAND)) == NULL)
246 1.4.2.2 mjf return EINVAL;
247 1.4.2.2 mjf
248 1.4.2.2 mjf for(i = 0; cmd_fn[i].cmd != NULL; i++)
249 1.4.2.2 mjf if (prop_string_equals_cstring(command, cmd_fn[i].cmd))
250 1.4.2.2 mjf break;
251 1.4.2.2 mjf
252 1.4.2.2 mjf if (cmd_fn[i].cmd == NULL)
253 1.4.2.2 mjf return EINVAL;
254 1.4.2.2 mjf
255 1.4.2.2 mjf aprint_debug("ioctl %s called\n", cmd_fn[i].cmd);
256 1.4.2.2 mjf r = cmd_fn[i].fn(dm_dict);
257 1.4.2.2 mjf
258 1.4.2.2 mjf return r;
259 1.4.2.2 mjf }
260 1.4.2.2 mjf
261 1.4.2.2 mjf /* Call apropriate ioctl handler function. */
262 1.4.2.2 mjf static int
263 1.4.2.2 mjf dm_ioctl_switch(u_long cmd)
264 1.4.2.2 mjf {
265 1.4.2.2 mjf int r;
266 1.4.2.2 mjf
267 1.4.2.2 mjf r = 0;
268 1.4.2.2 mjf
269 1.4.2.2 mjf switch(cmd) {
270 1.4.2.2 mjf
271 1.4.2.2 mjf case NETBSD_DM_IOCTL:
272 1.4.2.2 mjf aprint_debug("NetBSD_DM_IOCTL called\n");
273 1.4.2.2 mjf break;
274 1.4.2.2 mjf
275 1.4.2.2 mjf default:
276 1.4.2.2 mjf aprint_debug("unknown ioctl called\n");
277 1.4.2.2 mjf return ENOTTY;
278 1.4.2.2 mjf break; /* NOT REACHED */
279 1.4.2.2 mjf }
280 1.4.2.2 mjf
281 1.4.2.2 mjf return r;
282 1.4.2.2 mjf }
283 1.4.2.2 mjf
284 1.4.2.2 mjf /*
285 1.4.2.2 mjf * Check for disk specific ioctls.
286 1.4.2.2 mjf */
287 1.4.2.2 mjf
288 1.4.2.2 mjf static int
289 1.4.2.2 mjf disk_ioctl_switch(dev_t dev, u_long cmd, void *data)
290 1.4.2.2 mjf {
291 1.4.2.2 mjf dm_dev_t *dmv;
292 1.4.2.2 mjf
293 1.4.2.2 mjf switch(cmd) {
294 1.4.2.2 mjf case DIOCGWEDGEINFO:
295 1.4.2.2 mjf {
296 1.4.2.2 mjf struct dkwedge_info *dkw = (void *) data;
297 1.4.2.2 mjf
298 1.4.2.2 mjf if ((dmv = dm_dev_lookup(NULL, NULL, minor(dev))) == NULL)
299 1.4.2.2 mjf return ENOENT;
300 1.4.2.2 mjf
301 1.4.2.2 mjf aprint_normal("DIOCGWEDGEINFO ioctl called\n");
302 1.4.2.2 mjf
303 1.4.2.2 mjf strlcpy(dkw->dkw_devname, dmv->name, 16);
304 1.4.2.2 mjf strlcpy(dkw->dkw_wname, dmv->name, DM_NAME_LEN);
305 1.4.2.2 mjf strlcpy(dkw->dkw_parent, dmv->name, 16);
306 1.4.2.2 mjf
307 1.4.2.2 mjf dkw->dkw_offset = 0;
308 1.4.2.2 mjf dkw->dkw_size = dm_table_size(&dmv->table_head);
309 1.4.2.2 mjf strcpy(dkw->dkw_ptype, DKW_PTYPE_FFS);
310 1.4.2.2 mjf
311 1.4.2.2 mjf dm_dev_unbusy(dmv);
312 1.4.2.2 mjf break;
313 1.4.2.2 mjf }
314 1.4.2.2 mjf
315 1.4.2.2 mjf case DIOCGDINFO:
316 1.4.2.2 mjf {
317 1.4.2.2 mjf if ((dmv = dm_dev_lookup(NULL, NULL, minor(dev))) == NULL)
318 1.4.2.2 mjf return ENOENT;
319 1.4.2.2 mjf
320 1.4.2.2 mjf aprint_debug("DIOCGDINFO %d\n", dmv->diskp->dk_label->d_secsize);
321 1.4.2.2 mjf
322 1.4.2.2 mjf *(struct disklabel *)data = *(dmv->diskp->dk_label);
323 1.4.2.2 mjf
324 1.4.2.2 mjf dm_dev_unbusy(dmv);
325 1.4.2.2 mjf break;
326 1.4.2.2 mjf }
327 1.4.2.2 mjf
328 1.4.2.2 mjf case DIOCGPART:
329 1.4.2.2 mjf {
330 1.4.2.2 mjf if ((dmv = dm_dev_lookup(NULL, NULL, minor(dev))) == NULL)
331 1.4.2.2 mjf return ENOENT;
332 1.4.2.2 mjf
333 1.4.2.2 mjf ((struct partinfo *)data)->disklab = dmv->diskp->dk_label;
334 1.4.2.2 mjf ((struct partinfo *)data)->part = &dmv->diskp->dk_label->d_partitions[0];
335 1.4.2.2 mjf
336 1.4.2.2 mjf dm_dev_unbusy(dmv);
337 1.4.2.2 mjf break;
338 1.4.2.2 mjf }
339 1.4.2.2 mjf case DIOCWDINFO:
340 1.4.2.2 mjf case DIOCSDINFO:
341 1.4.2.2 mjf case DIOCKLABEL:
342 1.4.2.2 mjf case DIOCWLABEL:
343 1.4.2.2 mjf case DIOCGDEFLABEL:
344 1.4.2.2 mjf
345 1.4.2.2 mjf default:
346 1.4.2.2 mjf aprint_debug("unknown disk_ioctl called\n");
347 1.4.2.2 mjf return 1;
348 1.4.2.2 mjf break; /* NOT REACHED */
349 1.4.2.2 mjf }
350 1.4.2.2 mjf
351 1.4.2.2 mjf return 0;
352 1.4.2.2 mjf }
353 1.4.2.2 mjf
354 1.4.2.2 mjf /*
355 1.4.2.2 mjf * Do all IO operations on dm logical devices.
356 1.4.2.2 mjf */
357 1.4.2.2 mjf static void
358 1.4.2.2 mjf dmstrategy(struct buf *bp)
359 1.4.2.2 mjf {
360 1.4.2.2 mjf dm_dev_t *dmv;
361 1.4.2.2 mjf dm_table_t *tbl;
362 1.4.2.2 mjf dm_table_entry_t *table_en;
363 1.4.2.2 mjf struct buf *nestbuf;
364 1.4.2.2 mjf
365 1.4.2.2 mjf uint32_t dev_type;
366 1.4.2.2 mjf
367 1.4.2.2 mjf uint64_t buf_start, buf_len, issued_len;
368 1.4.2.2 mjf uint64_t table_start, table_end;
369 1.4.2.2 mjf uint64_t start, end;
370 1.4.2.2 mjf
371 1.4.2.2 mjf buf_start = bp->b_blkno * DEV_BSIZE;
372 1.4.2.2 mjf buf_len = bp->b_bcount;
373 1.4.2.2 mjf
374 1.4.2.2 mjf tbl = NULL;
375 1.4.2.2 mjf
376 1.4.2.2 mjf table_end = 0;
377 1.4.2.2 mjf dev_type = 0;
378 1.4.2.2 mjf issued_len = 0;
379 1.4.2.2 mjf
380 1.4.2.2 mjf if ((dmv = dm_dev_lookup(NULL, NULL, minor(bp->b_dev))) == NULL) {
381 1.4.2.2 mjf bp->b_error = EIO;
382 1.4.2.2 mjf bp->b_resid = bp->b_bcount;
383 1.4.2.2 mjf biodone(bp);
384 1.4.2.2 mjf return;
385 1.4.2.2 mjf }
386 1.4.2.2 mjf
387 1.4.2.2 mjf /* Select active table */
388 1.4.2.2 mjf tbl = dm_table_get_entry(&dmv->table_head, DM_TABLE_ACTIVE);
389 1.4.2.2 mjf
390 1.4.2.2 mjf /* Nested buffers count down to zero therefore I have
391 1.4.2.2 mjf to set bp->b_resid to maximal value. */
392 1.4.2.2 mjf bp->b_resid = bp->b_bcount;
393 1.4.2.2 mjf
394 1.4.2.2 mjf /*
395 1.4.2.2 mjf * Find out what tables I want to select.
396 1.4.2.2 mjf */
397 1.4.2.2 mjf SLIST_FOREACH(table_en, tbl, next)
398 1.4.2.2 mjf {
399 1.4.2.2 mjf /* I need need number of bytes not blocks. */
400 1.4.2.2 mjf table_start = table_en->start * DEV_BSIZE;
401 1.4.2.2 mjf /*
402 1.4.2.2 mjf * I have to sub 1 from table_en->length to prevent
403 1.4.2.2 mjf * off by one error
404 1.4.2.2 mjf */
405 1.4.2.2 mjf table_end = table_start + (table_en->length)* DEV_BSIZE;
406 1.4.2.2 mjf
407 1.4.2.2 mjf start = MAX(table_start, buf_start);
408 1.4.2.2 mjf
409 1.4.2.2 mjf end = MIN(table_end, buf_start + buf_len);
410 1.4.2.2 mjf
411 1.4.2.2 mjf aprint_debug("----------------------------------------\n");
412 1.4.2.2 mjf aprint_debug("table_start %010" PRIu64", table_end %010"
413 1.4.2.2 mjf PRIu64 "\n", table_start, table_end);
414 1.4.2.2 mjf aprint_debug("buf_start %010" PRIu64", buf_len %010"
415 1.4.2.2 mjf PRIu64"\n", buf_start, buf_len);
416 1.4.2.2 mjf aprint_debug("start-buf_start %010"PRIu64", end %010"
417 1.4.2.2 mjf PRIu64"\n", start - buf_start, end);
418 1.4.2.2 mjf aprint_debug("start %010" PRIu64" , end %010"
419 1.4.2.2 mjf PRIu64"\n", start, end);
420 1.4.2.2 mjf aprint_debug("\n----------------------------------------\n");
421 1.4.2.2 mjf
422 1.4.2.2 mjf if (start < end) {
423 1.4.2.2 mjf /* create nested buffer */
424 1.4.2.2 mjf nestbuf = getiobuf(NULL, true);
425 1.4.2.2 mjf
426 1.4.2.2 mjf nestiobuf_setup(bp, nestbuf, start - buf_start,
427 1.4.2.2 mjf (end - start));
428 1.4.2.2 mjf
429 1.4.2.2 mjf issued_len += end - start;
430 1.4.2.2 mjf
431 1.4.2.2 mjf /* I need number of blocks. */
432 1.4.2.2 mjf nestbuf->b_blkno = (start - table_start) / DEV_BSIZE;
433 1.4.2.2 mjf
434 1.4.2.2 mjf table_en->target->strategy(table_en, nestbuf);
435 1.4.2.2 mjf }
436 1.4.2.2 mjf }
437 1.4.2.2 mjf
438 1.4.2.2 mjf if (issued_len < buf_len)
439 1.4.2.2 mjf nestiobuf_done(bp, buf_len - issued_len, EINVAL);
440 1.4.2.2 mjf
441 1.4.2.2 mjf dm_table_release(&dmv->table_head, DM_TABLE_ACTIVE);
442 1.4.2.2 mjf dm_dev_unbusy(dmv);
443 1.4.2.2 mjf
444 1.4.2.2 mjf return;
445 1.4.2.2 mjf }
446 1.4.2.2 mjf
447 1.4.2.2 mjf
448 1.4.2.2 mjf static int
449 1.4.2.2 mjf dmread(dev_t dev, struct uio *uio, int flag)
450 1.4.2.2 mjf {
451 1.4.2.2 mjf return (physio(dmstrategy, NULL, dev, B_READ, dmminphys, uio));
452 1.4.2.2 mjf }
453 1.4.2.2 mjf
454 1.4.2.2 mjf static int
455 1.4.2.2 mjf dmwrite(dev_t dev, struct uio *uio, int flag)
456 1.4.2.2 mjf {
457 1.4.2.2 mjf return (physio(dmstrategy, NULL, dev, B_WRITE, dmminphys, uio));
458 1.4.2.2 mjf }
459 1.4.2.2 mjf
460 1.4.2.2 mjf static int
461 1.4.2.2 mjf dmdump(dev_t dev, daddr_t blkno, void *va, size_t size)
462 1.4.2.2 mjf {
463 1.4.2.2 mjf return ENODEV;
464 1.4.2.2 mjf }
465 1.4.2.2 mjf
466 1.4.2.2 mjf static int
467 1.4.2.2 mjf dmsize(dev_t dev)
468 1.4.2.2 mjf {
469 1.4.2.2 mjf dm_dev_t *dmv;
470 1.4.2.2 mjf uint64_t size;
471 1.4.2.2 mjf
472 1.4.2.2 mjf size = 0;
473 1.4.2.2 mjf
474 1.4.2.2 mjf if ((dmv = dm_dev_lookup(NULL, NULL, minor(dev))) == NULL)
475 1.4.2.2 mjf return -ENOENT;
476 1.4.2.2 mjf
477 1.4.2.2 mjf size = dm_table_size(&dmv->table_head);
478 1.4.2.2 mjf dm_dev_unbusy(dmv);
479 1.4.2.2 mjf
480 1.4.2.2 mjf return size;
481 1.4.2.2 mjf }
482 1.4.2.2 mjf
483 1.4.2.2 mjf static void
484 1.4.2.2 mjf dmminphys(struct buf *bp)
485 1.4.2.2 mjf {
486 1.4.2.2 mjf bp->b_bcount = MIN(bp->b_bcount, MAXPHYS);
487 1.4.2.2 mjf }
488 1.4.2.2 mjf
489 1.4.2.2 mjf /*
490 1.4.2.2 mjf * Load the label information on the named device
491 1.4.2.2 mjf * Actually fabricate a disklabel.
492 1.4.2.2 mjf *
493 1.4.2.2 mjf * EVENTUALLY take information about different
494 1.4.2.2 mjf * data tracks from the TOC and put it in the disklabel
495 1.4.2.2 mjf *
496 1.4.2.2 mjf * Copied from vnd code.
497 1.4.2.2 mjf */
498 1.4.2.2 mjf void
499 1.4.2.2 mjf dmgetdisklabel(struct disklabel *lp, dm_table_head_t *head)
500 1.4.2.2 mjf {
501 1.4.2.2 mjf struct partition *pp;
502 1.4.2.2 mjf int dmp_size;
503 1.4.2.2 mjf
504 1.4.2.2 mjf dmp_size = dm_table_size(head);
505 1.4.2.2 mjf
506 1.4.2.2 mjf /*
507 1.4.2.2 mjf * Size must be at least 2048 DEV_BSIZE blocks
508 1.4.2.2 mjf * (1M) in order to use this geometry.
509 1.4.2.2 mjf */
510 1.4.2.2 mjf
511 1.4.2.2 mjf lp->d_secperunit = dmp_size;
512 1.4.2.2 mjf lp->d_secsize = DEV_BSIZE;
513 1.4.2.2 mjf lp->d_nsectors = 32;
514 1.4.2.2 mjf lp->d_ntracks = 64;
515 1.4.2.2 mjf lp->d_ncylinders = dmp_size / (lp->d_nsectors * lp->d_ntracks);
516 1.4.2.2 mjf lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
517 1.4.2.2 mjf
518 1.4.2.2 mjf strncpy(lp->d_typename, "lvm", sizeof(lp->d_typename));
519 1.4.2.2 mjf lp->d_type = DTYPE_DM;
520 1.4.2.2 mjf strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname));
521 1.4.2.2 mjf lp->d_rpm = 3600;
522 1.4.2.2 mjf lp->d_interleave = 1;
523 1.4.2.2 mjf lp->d_flags = 0;
524 1.4.2.2 mjf
525 1.4.2.2 mjf pp = &lp->d_partitions[0];
526 1.4.2.2 mjf /*
527 1.4.2.2 mjf * This is logical offset and therefore it can be 0
528 1.4.2.2 mjf * I will consider table offsets later in dmstrategy.
529 1.4.2.2 mjf */
530 1.4.2.2 mjf pp->p_offset = 0;
531 1.4.2.2 mjf pp->p_size = dmp_size * DEV_BSIZE;
532 1.4.2.2 mjf pp->p_fstype = FS_BSDFFS; /* default value */
533 1.4.2.2 mjf lp->d_npartitions = 1;
534 1.4.2.2 mjf
535 1.4.2.2 mjf lp->d_magic = DISKMAGIC;
536 1.4.2.2 mjf lp->d_magic2 = DISKMAGIC;
537 1.4.2.2 mjf lp->d_checksum = dkcksum(lp);
538 1.4.2.2 mjf
539 1.4.2.2 mjf return;
540 1.4.2.2 mjf }
541