Annotation of src/sys/dev/dm/dm_target_linear.c, revision 1.36
1.36 ! tkusumi 1: /* $NetBSD: dm_target_linear.c,v 1.35 2019/12/21 11:59:03 tkusumi Exp $ */
1.2 haad 2:
3: /*
4: * Copyright (c) 2008 The NetBSD Foundation, Inc.
5: * All rights reserved.
6: *
7: * This code is derived from software contributed to The NetBSD Foundation
8: * by Adam Hamsik.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: *
19: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29: * POSSIBILITY OF SUCH DAMAGE.
30: */
1.17 christos 31: #include <sys/cdefs.h>
1.36 ! tkusumi 32: __KERNEL_RCSID(0, "$NetBSD: dm_target_linear.c,v 1.35 2019/12/21 11:59:03 tkusumi Exp $");
1.2 haad 33:
34: /*
1.36 ! tkusumi 35: * This file implements initial version of device-mapper linear target.
1.2 haad 36: */
37:
38: #include <sys/types.h>
39: #include <sys/param.h>
40: #include <sys/buf.h>
41: #include <sys/kmem.h>
1.11 uebayasi 42: #include <sys/lwp.h>
1.2 haad 43:
44: #include <machine/int_fmtio.h>
45:
46: #include "dm.h"
47:
48: /*
49: * Allocate target specific config data, and link them to table.
50: * This function is called only when, flags is not READONLY and
1.9 haad 51: * therefore we can add things to pdev list. This should not a
1.6 yamt 52: * problem because this routine is called only from dm_table_load_ioctl.
1.2 haad 53: * @argv[0] is name,
54: * @argv[1] is physical data offset.
55: */
56: int
1.27 tkusumi 57: dm_target_linear_init(dm_table_entry_t *table_en, int argc, char **argv)
1.2 haad 58: {
59: dm_target_linear_config_t *tlc;
60: dm_pdev_t *dmp;
61:
1.27 tkusumi 62: if (argc != 2) {
1.33 tkusumi 63: printf("Linear target takes 2 args, %d given\n", argc);
1.8 haad 64: return EINVAL;
65: }
1.2 haad 66:
1.8 haad 67: aprint_debug("Linear target init function called %s--%s!!\n",
68: argv[0], argv[1]);
1.9 haad 69:
1.2 haad 70: /* Insert dmp to global pdev list */
1.8 haad 71: if ((dmp = dm_pdev_insert(argv[0])) == NULL)
1.2 haad 72: return ENOENT;
1.9 haad 73:
1.15 chs 74: tlc = kmem_alloc(sizeof(dm_target_linear_config_t), KM_SLEEP);
1.2 haad 75: tlc->pdev = dmp;
1.32 tkusumi 76: tlc->offset = atoi64(argv[1]);
1.2 haad 77:
1.35 tkusumi 78: dm_table_add_deps(table_en, dmp);
1.25 tkusumi 79: table_en->target_config = tlc;
1.2 haad 80:
81: return 0;
82: }
1.17 christos 83:
1.2 haad 84: /*
1.29 tkusumi 85: * Table routine is called to get params string, which is target
1.2 haad 86: * specific. When dm_table_status_ioctl is called with flag
87: * DM_STATUS_TABLE_FLAG I have to sent params string back.
88: */
89: char *
1.29 tkusumi 90: dm_target_linear_table(void *target_config)
1.2 haad 91: {
92: dm_target_linear_config_t *tlc;
93: char *params;
1.8 haad 94: tlc = target_config;
95:
1.29 tkusumi 96: aprint_debug("Linear target table function called\n");
1.2 haad 97:
1.18 chs 98: params = kmem_alloc(DM_MAX_PARAMS_SIZE, KM_SLEEP);
1.9 haad 99: snprintf(params, DM_MAX_PARAMS_SIZE, "%s %" PRIu64,
1.34 tkusumi 100: tlc->pdev->udev_name, tlc->offset);
1.8 haad 101:
1.2 haad 102: return params;
103: }
1.17 christos 104:
1.2 haad 105: /*
106: * Do IO operation, called from dmstrategy routine.
107: */
108: int
1.24 tkusumi 109: dm_target_linear_strategy(dm_table_entry_t *table_en, struct buf *bp)
1.2 haad 110: {
111: dm_target_linear_config_t *tlc;
112:
113: tlc = table_en->target_config;
1.9 haad 114:
1.2 haad 115: bp->b_blkno += tlc->offset;
1.9 haad 116:
1.2 haad 117: VOP_STRATEGY(tlc->pdev->pdev_vnode, bp);
1.9 haad 118:
1.2 haad 119: return 0;
120: }
1.17 christos 121:
1.2 haad 122: /*
1.10 haad 123: * Sync underlying disk caches.
124: */
125: int
1.24 tkusumi 126: dm_target_linear_sync(dm_table_entry_t *table_en)
1.10 haad 127: {
128: int cmd;
129: dm_target_linear_config_t *tlc;
130:
131: tlc = table_en->target_config;
132:
133: cmd = 1;
1.23 tkusumi 134:
1.10 haad 135: return VOP_IOCTL(tlc->pdev->pdev_vnode, DIOCCACHESYNC, &cmd,
1.23 tkusumi 136: FREAD|FWRITE, kauth_cred_get());
1.10 haad 137: }
1.17 christos 138:
1.10 haad 139: /*
1.2 haad 140: * Destroy target specific data. Decrement table pdevs.
141: */
142: int
1.24 tkusumi 143: dm_target_linear_destroy(dm_table_entry_t *table_en)
1.2 haad 144: {
145:
146: /*
147: * Destroy function is called for every target even if it
148: * doesn't have target_config.
149: */
150: if (table_en->target_config == NULL)
1.17 christos 151: goto out;
1.9 haad 152:
1.17 christos 153: dm_target_linear_config_t *tlc = table_en->target_config;
1.9 haad 154:
1.2 haad 155: /* Decrement pdev ref counter if 0 remove it */
156: dm_pdev_decr(tlc->pdev);
1.9 haad 157:
1.17 christos 158: kmem_free(tlc, sizeof(*tlc));
159:
160: out:
1.3 haad 161: /* Unbusy target so we can unload it */
162: dm_target_unbusy(table_en->target);
1.2 haad 163: return 0;
164: }
1.17 christos 165:
1.2 haad 166: /*
167: * Register upcall device.
168: * Linear target doesn't need any upcall devices but other targets like
169: * mirror, snapshot, multipath, stripe will use this functionality.
170: */
171: int
1.24 tkusumi 172: dm_target_linear_upcall(dm_table_entry_t *table_en, struct buf *bp)
1.2 haad 173: {
1.31 tkusumi 174:
1.2 haad 175: return 0;
176: }
1.17 christos 177:
1.2 haad 178: /*
1.12 mlelstv 179: * Query physical block size of this target
180: * For a linear target this is just the sector size of the underlying device
181: */
182: int
1.30 tkusumi 183: dm_target_linear_secsize(dm_table_entry_t *table_en, unsigned int *secsizep)
1.12 mlelstv 184: {
185: dm_target_linear_config_t *tlc;
1.30 tkusumi 186: unsigned int secsize;
1.12 mlelstv 187:
188: secsize = 0;
189:
190: tlc = table_en->target_config;
191: if (tlc != NULL)
192: secsize = tlc->pdev->pdev_secsize;
193:
194: *secsizep = secsize;
195:
196: return 0;
197: }
CVSweb <webmaster@jp.NetBSD.org>