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