Annotation of src/sys/dev/dm/dm_target_linear.c, revision 1.32
1.32 ! tkusumi 1: /* $NetBSD: dm_target_linear.c,v 1.31 2019/12/15 14:39:42 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.32 ! tkusumi 32: __KERNEL_RCSID(0, "$NetBSD: dm_target_linear.c,v 1.31 2019/12/15 14:39:42 tkusumi Exp $");
1.2 haad 33:
34: /*
35: * This file implements initial version of device-mapper dklinear target.
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: /*
63: if (argc != 2) {
64: printf("Linear target takes 2 args\n");
1.8 haad 65: return EINVAL;
66: }
1.27 tkusumi 67: */
1.2 haad 68:
1.8 haad 69: aprint_debug("Linear target init function called %s--%s!!\n",
70: argv[0], argv[1]);
1.9 haad 71:
1.2 haad 72: /* Insert dmp to global pdev list */
1.8 haad 73: if ((dmp = dm_pdev_insert(argv[0])) == NULL)
1.2 haad 74: return ENOENT;
1.9 haad 75:
1.15 chs 76: tlc = kmem_alloc(sizeof(dm_target_linear_config_t), KM_SLEEP);
1.2 haad 77: tlc->pdev = dmp;
1.32 ! tkusumi 78: tlc->offset = atoi64(argv[1]);
1.2 haad 79:
1.25 tkusumi 80: table_en->target_config = tlc;
1.2 haad 81:
82: return 0;
83: }
1.17 christos 84:
1.2 haad 85: /*
1.29 tkusumi 86: * Table routine is called to get params string, which is target
1.2 haad 87: * specific. When dm_table_status_ioctl is called with flag
88: * DM_STATUS_TABLE_FLAG I have to sent params string back.
89: */
90: char *
1.29 tkusumi 91: dm_target_linear_table(void *target_config)
1.2 haad 92: {
93: dm_target_linear_config_t *tlc;
94: char *params;
1.8 haad 95: tlc = target_config;
96:
1.29 tkusumi 97: aprint_debug("Linear target table function called\n");
1.2 haad 98:
1.18 chs 99: params = kmem_alloc(DM_MAX_PARAMS_SIZE, KM_SLEEP);
1.9 haad 100: snprintf(params, DM_MAX_PARAMS_SIZE, "%s %" PRIu64,
1.8 haad 101: tlc->pdev->name, tlc->offset);
102:
1.2 haad 103: return params;
104: }
1.17 christos 105:
1.2 haad 106: /*
107: * Do IO operation, called from dmstrategy routine.
108: */
109: int
1.24 tkusumi 110: dm_target_linear_strategy(dm_table_entry_t *table_en, struct buf *bp)
1.2 haad 111: {
112: dm_target_linear_config_t *tlc;
113:
114: tlc = table_en->target_config;
1.9 haad 115:
1.2 haad 116: bp->b_blkno += tlc->offset;
1.9 haad 117:
1.2 haad 118: VOP_STRATEGY(tlc->pdev->pdev_vnode, bp);
1.9 haad 119:
1.2 haad 120: return 0;
121: }
1.17 christos 122:
1.2 haad 123: /*
1.10 haad 124: * Sync underlying disk caches.
125: */
126: int
1.24 tkusumi 127: dm_target_linear_sync(dm_table_entry_t *table_en)
1.10 haad 128: {
129: int cmd;
130: dm_target_linear_config_t *tlc;
131:
132: tlc = table_en->target_config;
133:
134: cmd = 1;
1.23 tkusumi 135:
1.10 haad 136: return VOP_IOCTL(tlc->pdev->pdev_vnode, DIOCCACHESYNC, &cmd,
1.23 tkusumi 137: FREAD|FWRITE, kauth_cred_get());
1.10 haad 138: }
1.17 christos 139:
1.10 haad 140: /*
1.2 haad 141: * Destroy target specific data. Decrement table pdevs.
142: */
143: int
1.24 tkusumi 144: dm_target_linear_destroy(dm_table_entry_t *table_en)
1.2 haad 145: {
146:
147: /*
148: * Destroy function is called for every target even if it
149: * doesn't have target_config.
150: */
151: if (table_en->target_config == NULL)
1.17 christos 152: goto out;
1.9 haad 153:
1.17 christos 154: dm_target_linear_config_t *tlc = table_en->target_config;
1.9 haad 155:
1.2 haad 156: /* Decrement pdev ref counter if 0 remove it */
157: dm_pdev_decr(tlc->pdev);
1.9 haad 158:
1.17 christos 159: kmem_free(tlc, sizeof(*tlc));
160:
161: out:
1.3 haad 162: /* Unbusy target so we can unload it */
163: dm_target_unbusy(table_en->target);
1.2 haad 164: return 0;
165: }
1.17 christos 166:
1.16 mbalmer 167: /* Add this target pdev dependencies to prop_array_t */
1.2 haad 168: int
1.24 tkusumi 169: dm_target_linear_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
1.2 haad 170: {
171: dm_target_linear_config_t *tlc;
1.9 haad 172:
1.2 haad 173: if (table_en->target_config == NULL)
174: return ENOENT;
1.9 haad 175:
1.2 haad 176: tlc = table_en->target_config;
1.9 haad 177:
1.14 hannken 178: prop_array_add_uint64(prop_array,
179: (uint64_t) tlc->pdev->pdev_vnode->v_rdev);
1.9 haad 180:
1.2 haad 181: return 0;
182: }
1.17 christos 183:
1.2 haad 184: /*
185: * Register upcall device.
186: * Linear target doesn't need any upcall devices but other targets like
187: * mirror, snapshot, multipath, stripe will use this functionality.
188: */
189: int
1.24 tkusumi 190: dm_target_linear_upcall(dm_table_entry_t *table_en, struct buf *bp)
1.2 haad 191: {
1.31 tkusumi 192:
1.2 haad 193: return 0;
194: }
1.17 christos 195:
1.2 haad 196: /*
1.12 mlelstv 197: * Query physical block size of this target
198: * For a linear target this is just the sector size of the underlying device
199: */
200: int
1.30 tkusumi 201: dm_target_linear_secsize(dm_table_entry_t *table_en, unsigned int *secsizep)
1.12 mlelstv 202: {
203: dm_target_linear_config_t *tlc;
1.30 tkusumi 204: unsigned int secsize;
1.12 mlelstv 205:
206: secsize = 0;
207:
208: tlc = table_en->target_config;
209: if (tlc != NULL)
210: secsize = tlc->pdev->pdev_secsize;
211:
212: *secsizep = secsize;
213:
214: return 0;
215: }
CVSweb <webmaster@jp.NetBSD.org>