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