1/*- 2 * Copyright (c) 2002 Poul-Henning Kamp 3 * Copyright (c) 2002 Networks Associates Technology, Inc. 4 * All rights reserved. 5 * 6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp 7 * and NAI Labs, the Security Research Division of Network Associates, Inc. 8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the 9 * DARPA CHATS research program. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. The names of the authors may not be used to endorse or promote 20 * products derived from this software without specific prior written 21 * permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 *
| 1/*- 2 * Copyright (c) 2002 Poul-Henning Kamp 3 * Copyright (c) 2002 Networks Associates Technology, Inc. 4 * All rights reserved. 5 * 6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp 7 * and NAI Labs, the Security Research Division of Network Associates, Inc. 8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the 9 * DARPA CHATS research program. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. The names of the authors may not be used to endorse or promote 20 * products derived from this software without specific prior written 21 * permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 *
|
35 * $FreeBSD: head/sys/geom/geom_dev.c 94287 2002-04-09 15:43:32Z phk $
| 35 * $FreeBSD: head/sys/geom/geom_dev.c 95038 2002-04-19 09:24:12Z phk $
|
36 */ 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/malloc.h> 41#include <sys/kernel.h> 42#include <sys/conf.h> 43#include <sys/bio.h> 44#include <sys/lock.h> 45#include <sys/mutex.h> 46#include <sys/errno.h> 47#include <sys/time.h> 48#include <sys/disk.h> 49#include <sys/fcntl.h> 50#include <geom/geom.h>
| 36 */ 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/malloc.h> 41#include <sys/kernel.h> 42#include <sys/conf.h> 43#include <sys/bio.h> 44#include <sys/lock.h> 45#include <sys/mutex.h> 46#include <sys/errno.h> 47#include <sys/time.h> 48#include <sys/disk.h> 49#include <sys/fcntl.h> 50#include <geom/geom.h>
|
| 51#include <machine/limits.h>
|
51 52#define CDEV_MAJOR 4 53 54static d_open_t g_dev_open; 55static d_close_t g_dev_close; 56static d_strategy_t g_dev_strategy; 57static d_ioctl_t g_dev_ioctl; 58static d_psize_t g_dev_psize; 59 60static struct cdevsw g_dev_cdevsw = { 61 /* open */ g_dev_open, 62 /* close */ g_dev_close, 63 /* read */ physread, 64 /* write */ physwrite, 65 /* ioctl */ g_dev_ioctl, 66 /* poll */ nopoll, 67 /* mmap */ nommap, 68 /* strategy */ g_dev_strategy, 69 /* name */ "g_dev", 70 /* maj */ CDEV_MAJOR, 71 /* dump */ nodump, 72 /* psize */ g_dev_psize, 73 /* flags */ D_DISK | D_CANFREE | D_TRACKCLOSE, 74}; 75 76static g_taste_t g_dev_taste; 77static g_orphan_t g_dev_orphan; 78 79static struct g_class g_dev_class = { 80 "DEV-class", 81 g_dev_taste, 82 NULL, 83 G_CLASS_INITSTUFF 84}; 85 86static void 87g_dev_clone(void *arg, char *name, int namelen, dev_t *dev) 88{ 89 struct g_geom *gp; 90 91 if (*dev != NODEV) 92 return; 93 94 g_trace(G_T_TOPOLOGY, "g_dev_clone(%s)", name); 95 g_rattle(); 96 97 /* XXX: can I drop Giant here ??? */ 98 /* g_topology_lock(); */ 99 LIST_FOREACH(gp, &g_dev_class.geom, geom) { 100 if (strcmp(gp->name, name)) 101 continue; 102 *dev = gp->softc; 103 g_trace(G_T_TOPOLOGY, "g_dev_clone(%s) = %p", name, *dev); 104 return; 105 } 106 /* g_topology_unlock(); */ 107 return; 108} 109 110static void 111g_dev_register_cloner(void *foo __unused) 112{ 113 static int once; 114 115 if (!once) { 116 if (!once) 117 EVENTHANDLER_REGISTER(dev_clone, g_dev_clone, 0, 1000); 118 once++; 119 } 120} 121 122SYSINIT(geomdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE,g_dev_register_cloner,NULL); 123 124static struct g_geom * 125g_dev_taste(struct g_class *mp, struct g_provider *pp, int insist __unused) 126{ 127 struct g_geom *gp; 128 struct g_consumer *cp; 129 static int unit; 130 u_int secsize; 131 off_t mediasize; 132 int error, j; 133 dev_t dev; 134 135 g_trace(G_T_TOPOLOGY, "dev_taste(%s,%s)", mp->name, pp->name); 136 g_topology_assert(); 137 LIST_FOREACH(cp, &pp->consumers, consumers) 138 if (cp->geom->class == mp) 139 return (NULL); 140 gp = g_new_geomf(mp, pp->name); 141 gp->orphan = g_dev_orphan; 142 cp = g_new_consumer(gp); 143 g_attach(cp, pp); 144 error = g_access_rel(cp, 1, 0, 0); 145 g_topology_unlock(); 146 if (!error) { 147 j = sizeof secsize; 148 error = g_io_getattr("GEOM::sectorsize", cp, &j, &secsize); 149 if (error) { 150 secsize = 512; 151 printf("g_dev_taste: error %d Sectors are %d bytes\n", 152 error, secsize); 153 } 154 j = sizeof mediasize; 155 error = g_io_getattr("GEOM::mediasize", cp, &j, &mediasize); 156 if (error) { 157 mediasize = 0; 158 printf("g_dev_taste: error %d Mediasize is %lld bytes\n", 159 error, (long long)mediasize); 160 } 161 g_topology_lock(); 162 g_access_rel(cp, -1, 0, 0); 163 g_topology_unlock(); 164 } else { 165 secsize = 512; 166 mediasize = 0; 167 } 168 mtx_lock(&Giant); 169 if (mediasize != 0) 170 printf("GEOM: \"%s\" %lld bytes in %lld sectors of %u bytes\n", 171 pp->name, (long long)mediasize, 172 (long long)mediasize / secsize, secsize); 173 else 174 printf("GEOM: \"%s\" (size unavailable)\n", pp->name); 175 dev = make_dev(&g_dev_cdevsw, unit++, 176 UID_ROOT, GID_WHEEL, 0600, gp->name); 177 gp->softc = dev; 178 dev->si_drv1 = gp; 179 dev->si_drv2 = cp; 180 mtx_unlock(&Giant); 181 g_topology_lock(); 182 return (gp); 183} 184 185static int 186g_dev_open(dev_t dev, int flags, int fmt, struct thread *td) 187{ 188 struct g_geom *gp; 189 struct g_consumer *cp; 190 int error, r, w, e; 191 192 gp = dev->si_drv1; 193 cp = dev->si_drv2; 194 if (gp == NULL || cp == NULL) 195 return(ENXIO); 196 g_trace(G_T_ACCESS, "g_dev_open(%s, %d, %d, %p)", 197 gp->name, flags, fmt, td); 198 DROP_GIANT(); 199 g_topology_lock(); 200 g_silence(); 201 r = flags & FREAD ? 1 : 0; 202 w = flags & FWRITE ? 1 : 0; 203 e = flags & O_EXCL ? 1 : 0; 204 error = g_access_rel(cp, r, w, e); 205 g_topology_unlock(); 206 PICKUP_GIANT(); 207 g_rattle(); 208 return(error); 209} 210 211static int 212g_dev_close(dev_t dev, int flags, int fmt, struct thread *td) 213{ 214 struct g_geom *gp; 215 struct g_consumer *cp; 216 int error, r, w, e; 217 218 gp = dev->si_drv1; 219 cp = dev->si_drv2; 220 if (gp == NULL || cp == NULL) 221 return(ENXIO); 222 g_trace(G_T_ACCESS, "g_dev_close(%s, %d, %d, %p)", 223 gp->name, flags, fmt, td); 224 DROP_GIANT(); 225 g_topology_lock(); 226 g_silence(); 227 r = flags & FREAD ? -1 : 0; 228 w = flags & FWRITE ? -1 : 0; 229 e = flags & O_EXCL ? -1 : 0; 230 error = g_access_rel(cp, r, w, e); 231 g_topology_unlock(); 232 PICKUP_GIANT(); 233 g_rattle(); 234 return (error); 235} 236 237static int 238g_dev_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td) 239{ 240 struct g_geom *gp; 241 struct g_consumer *cp;
| 52 53#define CDEV_MAJOR 4 54 55static d_open_t g_dev_open; 56static d_close_t g_dev_close; 57static d_strategy_t g_dev_strategy; 58static d_ioctl_t g_dev_ioctl; 59static d_psize_t g_dev_psize; 60 61static struct cdevsw g_dev_cdevsw = { 62 /* open */ g_dev_open, 63 /* close */ g_dev_close, 64 /* read */ physread, 65 /* write */ physwrite, 66 /* ioctl */ g_dev_ioctl, 67 /* poll */ nopoll, 68 /* mmap */ nommap, 69 /* strategy */ g_dev_strategy, 70 /* name */ "g_dev", 71 /* maj */ CDEV_MAJOR, 72 /* dump */ nodump, 73 /* psize */ g_dev_psize, 74 /* flags */ D_DISK | D_CANFREE | D_TRACKCLOSE, 75}; 76 77static g_taste_t g_dev_taste; 78static g_orphan_t g_dev_orphan; 79 80static struct g_class g_dev_class = { 81 "DEV-class", 82 g_dev_taste, 83 NULL, 84 G_CLASS_INITSTUFF 85}; 86 87static void 88g_dev_clone(void *arg, char *name, int namelen, dev_t *dev) 89{ 90 struct g_geom *gp; 91 92 if (*dev != NODEV) 93 return; 94 95 g_trace(G_T_TOPOLOGY, "g_dev_clone(%s)", name); 96 g_rattle(); 97 98 /* XXX: can I drop Giant here ??? */ 99 /* g_topology_lock(); */ 100 LIST_FOREACH(gp, &g_dev_class.geom, geom) { 101 if (strcmp(gp->name, name)) 102 continue; 103 *dev = gp->softc; 104 g_trace(G_T_TOPOLOGY, "g_dev_clone(%s) = %p", name, *dev); 105 return; 106 } 107 /* g_topology_unlock(); */ 108 return; 109} 110 111static void 112g_dev_register_cloner(void *foo __unused) 113{ 114 static int once; 115 116 if (!once) { 117 if (!once) 118 EVENTHANDLER_REGISTER(dev_clone, g_dev_clone, 0, 1000); 119 once++; 120 } 121} 122 123SYSINIT(geomdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE,g_dev_register_cloner,NULL); 124 125static struct g_geom * 126g_dev_taste(struct g_class *mp, struct g_provider *pp, int insist __unused) 127{ 128 struct g_geom *gp; 129 struct g_consumer *cp; 130 static int unit; 131 u_int secsize; 132 off_t mediasize; 133 int error, j; 134 dev_t dev; 135 136 g_trace(G_T_TOPOLOGY, "dev_taste(%s,%s)", mp->name, pp->name); 137 g_topology_assert(); 138 LIST_FOREACH(cp, &pp->consumers, consumers) 139 if (cp->geom->class == mp) 140 return (NULL); 141 gp = g_new_geomf(mp, pp->name); 142 gp->orphan = g_dev_orphan; 143 cp = g_new_consumer(gp); 144 g_attach(cp, pp); 145 error = g_access_rel(cp, 1, 0, 0); 146 g_topology_unlock(); 147 if (!error) { 148 j = sizeof secsize; 149 error = g_io_getattr("GEOM::sectorsize", cp, &j, &secsize); 150 if (error) { 151 secsize = 512; 152 printf("g_dev_taste: error %d Sectors are %d bytes\n", 153 error, secsize); 154 } 155 j = sizeof mediasize; 156 error = g_io_getattr("GEOM::mediasize", cp, &j, &mediasize); 157 if (error) { 158 mediasize = 0; 159 printf("g_dev_taste: error %d Mediasize is %lld bytes\n", 160 error, (long long)mediasize); 161 } 162 g_topology_lock(); 163 g_access_rel(cp, -1, 0, 0); 164 g_topology_unlock(); 165 } else { 166 secsize = 512; 167 mediasize = 0; 168 } 169 mtx_lock(&Giant); 170 if (mediasize != 0) 171 printf("GEOM: \"%s\" %lld bytes in %lld sectors of %u bytes\n", 172 pp->name, (long long)mediasize, 173 (long long)mediasize / secsize, secsize); 174 else 175 printf("GEOM: \"%s\" (size unavailable)\n", pp->name); 176 dev = make_dev(&g_dev_cdevsw, unit++, 177 UID_ROOT, GID_WHEEL, 0600, gp->name); 178 gp->softc = dev; 179 dev->si_drv1 = gp; 180 dev->si_drv2 = cp; 181 mtx_unlock(&Giant); 182 g_topology_lock(); 183 return (gp); 184} 185 186static int 187g_dev_open(dev_t dev, int flags, int fmt, struct thread *td) 188{ 189 struct g_geom *gp; 190 struct g_consumer *cp; 191 int error, r, w, e; 192 193 gp = dev->si_drv1; 194 cp = dev->si_drv2; 195 if (gp == NULL || cp == NULL) 196 return(ENXIO); 197 g_trace(G_T_ACCESS, "g_dev_open(%s, %d, %d, %p)", 198 gp->name, flags, fmt, td); 199 DROP_GIANT(); 200 g_topology_lock(); 201 g_silence(); 202 r = flags & FREAD ? 1 : 0; 203 w = flags & FWRITE ? 1 : 0; 204 e = flags & O_EXCL ? 1 : 0; 205 error = g_access_rel(cp, r, w, e); 206 g_topology_unlock(); 207 PICKUP_GIANT(); 208 g_rattle(); 209 return(error); 210} 211 212static int 213g_dev_close(dev_t dev, int flags, int fmt, struct thread *td) 214{ 215 struct g_geom *gp; 216 struct g_consumer *cp; 217 int error, r, w, e; 218 219 gp = dev->si_drv1; 220 cp = dev->si_drv2; 221 if (gp == NULL || cp == NULL) 222 return(ENXIO); 223 g_trace(G_T_ACCESS, "g_dev_close(%s, %d, %d, %p)", 224 gp->name, flags, fmt, td); 225 DROP_GIANT(); 226 g_topology_lock(); 227 g_silence(); 228 r = flags & FREAD ? -1 : 0; 229 w = flags & FWRITE ? -1 : 0; 230 e = flags & O_EXCL ? -1 : 0; 231 error = g_access_rel(cp, r, w, e); 232 g_topology_unlock(); 233 PICKUP_GIANT(); 234 g_rattle(); 235 return (error); 236} 237 238static int 239g_dev_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td) 240{ 241 struct g_geom *gp; 242 struct g_consumer *cp;
|
| 243 struct g_kerneldump kd;
|
242 int i, error;
| 244 int i, error;
|
| 245 u_int u;
|
243 struct g_ioctl *gio; 244 245 gp = dev->si_drv1; 246 cp = dev->si_drv2; 247 248 error = 0; 249 DROP_GIANT(); 250 251 i = IOCPARM_LEN(cmd); 252 switch (cmd) { 253 case DIOCGSECTORSIZE: 254 error = g_io_getattr("GEOM::sectorsize", cp, &i, data); 255 break; 256 case DIOCGMEDIASIZE: 257 error = g_io_getattr("GEOM::mediasize", cp, &i, data); 258 break; 259 case DIOCGFWSECTORS: 260 error = g_io_getattr("GEOM::fwsectors", cp, &i, data); 261 break; 262 case DIOCGFWHEADS: 263 error = g_io_getattr("GEOM::fwheads", cp, &i, data); 264 break; 265 case DIOCGFRONTSTUFF: 266 error = g_io_getattr("GEOM::frontstuff", cp, &i, data); 267 break;
| 246 struct g_ioctl *gio; 247 248 gp = dev->si_drv1; 249 cp = dev->si_drv2; 250 251 error = 0; 252 DROP_GIANT(); 253 254 i = IOCPARM_LEN(cmd); 255 switch (cmd) { 256 case DIOCGSECTORSIZE: 257 error = g_io_getattr("GEOM::sectorsize", cp, &i, data); 258 break; 259 case DIOCGMEDIASIZE: 260 error = g_io_getattr("GEOM::mediasize", cp, &i, data); 261 break; 262 case DIOCGFWSECTORS: 263 error = g_io_getattr("GEOM::fwsectors", cp, &i, data); 264 break; 265 case DIOCGFWHEADS: 266 error = g_io_getattr("GEOM::fwheads", cp, &i, data); 267 break; 268 case DIOCGFRONTSTUFF: 269 error = g_io_getattr("GEOM::frontstuff", cp, &i, data); 270 break;
|
| 271 case DIOCSKERNELDUMP: 272 u = *((u_int *)data); 273 if (!u) { 274 set_dumper(NULL); 275 error = 0; 276 break; 277 } 278 kd.offset = 0; 279 kd.length = OFF_MAX; 280 i = sizeof kd; 281 error = g_io_getattr("GEOM::kerneldump", cp, &i, &kd); 282 if (!error) 283 dev->si_flags |= SI_DUMPDEV; 284 break;
|
268 default: 269 gio = g_malloc(sizeof *gio, M_WAITOK); 270 gio->cmd = cmd; 271 gio->data = data; 272 gio->fflag = fflag; 273 gio->td = td; 274 i = sizeof *gio; 275 if (cmd & IOC_IN) 276 error = g_io_setattr("GEOM::ioctl", cp, i, gio); 277 else 278 error = g_io_getattr("GEOM::ioctl", cp, &i, gio); 279 g_free(gio); 280 break; 281 } 282 283 if (error != 0 && cmd == DIOCGDVIRGIN) { 284 g_topology_lock(); 285 gp = g_create_geomf("BSD-class", cp->provider, NULL); 286 g_topology_unlock(); 287 } 288 PICKUP_GIANT(); 289 g_rattle(); 290 if (error == ENOIOCTL) { 291 i = IOCGROUP(cmd); 292 printf("IOCTL(0x%lx) \"%s\"", cmd, gp->name); 293 if (i > ' ' && i <= '~') 294 printf(" '%c'", (int)IOCGROUP(cmd)); 295 else 296 printf(" 0x%lx", IOCGROUP(cmd)); 297 printf("/%ld ", cmd & 0xff); 298 if (cmd & IOC_IN) 299 printf("I"); 300 if (cmd & IOC_OUT) 301 printf("O"); 302 printf("(%ld) = ENOIOCTL\n", IOCPARM_LEN(cmd)); 303 error = ENOTTY; 304 } 305 return (error); 306} 307 308static int 309g_dev_psize(dev_t dev) 310{ 311 struct g_consumer *cp; 312 int i, error; 313 off_t mediasize; 314 315 cp = dev->si_drv2; 316 317 i = sizeof mediasize; 318 error = g_io_getattr("GEOM::mediasize", cp, &i, &mediasize); 319 if (error) 320 return (-1); 321 return (mediasize >> DEV_BSHIFT); 322} 323 324static void 325g_dev_done(struct bio *bp2) 326{ 327 struct bio *bp; 328 329 bp = bp2->bio_linkage; 330 bp->bio_error = bp2->bio_error; 331 if (bp->bio_error != 0) { 332 g_trace(G_T_BIO, "g_dev_done(%p) had error %d", 333 bp2, bp->bio_error); 334 bp->bio_flags |= BIO_ERROR; 335 } else { 336 g_trace(G_T_BIO, "g_dev_done(%p/%p) resid %ld completed %lld", 337 bp2, bp, bp->bio_resid, bp2->bio_completed); 338 } 339 bp->bio_resid = bp->bio_bcount - bp2->bio_completed; 340 g_destroy_bio(bp2); 341 mtx_lock(&Giant); 342 biodone(bp); 343 mtx_unlock(&Giant); 344} 345 346static void 347g_dev_strategy(struct bio *bp) 348{ 349 struct g_geom *gp; 350 struct g_consumer *cp; 351 struct bio *bp2; 352 dev_t dev; 353 354 dev = bp->bio_dev; 355 gp = dev->si_drv1; 356 cp = dev->si_drv2; 357 bp2 = g_clone_bio(bp); 358 bp2->bio_offset = (off_t)bp->bio_blkno << DEV_BSHIFT; 359 bp2->bio_length = (off_t)bp->bio_bcount; 360 bp2->bio_done = g_dev_done; 361 g_trace(G_T_BIO, 362 "g_dev_strategy(%p/%p) offset %lld length %lld data %p cmd %d", 363 bp, bp2, bp->bio_offset, bp2->bio_length, bp2->bio_data, 364 bp2->bio_cmd); 365 g_io_request(bp2, cp); 366} 367 368 369static void 370g_dev_orphan(struct g_consumer *cp) 371{ 372 struct g_geom *gp; 373 dev_t dev; 374 375 gp = cp->geom; 376 g_trace(G_T_TOPOLOGY, "g_dev_orphan(%p(%s))", cp, gp->name); 377 g_topology_assert(); 378 if (cp->biocount > 0) 379 return; 380 dev = gp->softc;
| 285 default: 286 gio = g_malloc(sizeof *gio, M_WAITOK); 287 gio->cmd = cmd; 288 gio->data = data; 289 gio->fflag = fflag; 290 gio->td = td; 291 i = sizeof *gio; 292 if (cmd & IOC_IN) 293 error = g_io_setattr("GEOM::ioctl", cp, i, gio); 294 else 295 error = g_io_getattr("GEOM::ioctl", cp, &i, gio); 296 g_free(gio); 297 break; 298 } 299 300 if (error != 0 && cmd == DIOCGDVIRGIN) { 301 g_topology_lock(); 302 gp = g_create_geomf("BSD-class", cp->provider, NULL); 303 g_topology_unlock(); 304 } 305 PICKUP_GIANT(); 306 g_rattle(); 307 if (error == ENOIOCTL) { 308 i = IOCGROUP(cmd); 309 printf("IOCTL(0x%lx) \"%s\"", cmd, gp->name); 310 if (i > ' ' && i <= '~') 311 printf(" '%c'", (int)IOCGROUP(cmd)); 312 else 313 printf(" 0x%lx", IOCGROUP(cmd)); 314 printf("/%ld ", cmd & 0xff); 315 if (cmd & IOC_IN) 316 printf("I"); 317 if (cmd & IOC_OUT) 318 printf("O"); 319 printf("(%ld) = ENOIOCTL\n", IOCPARM_LEN(cmd)); 320 error = ENOTTY; 321 } 322 return (error); 323} 324 325static int 326g_dev_psize(dev_t dev) 327{ 328 struct g_consumer *cp; 329 int i, error; 330 off_t mediasize; 331 332 cp = dev->si_drv2; 333 334 i = sizeof mediasize; 335 error = g_io_getattr("GEOM::mediasize", cp, &i, &mediasize); 336 if (error) 337 return (-1); 338 return (mediasize >> DEV_BSHIFT); 339} 340 341static void 342g_dev_done(struct bio *bp2) 343{ 344 struct bio *bp; 345 346 bp = bp2->bio_linkage; 347 bp->bio_error = bp2->bio_error; 348 if (bp->bio_error != 0) { 349 g_trace(G_T_BIO, "g_dev_done(%p) had error %d", 350 bp2, bp->bio_error); 351 bp->bio_flags |= BIO_ERROR; 352 } else { 353 g_trace(G_T_BIO, "g_dev_done(%p/%p) resid %ld completed %lld", 354 bp2, bp, bp->bio_resid, bp2->bio_completed); 355 } 356 bp->bio_resid = bp->bio_bcount - bp2->bio_completed; 357 g_destroy_bio(bp2); 358 mtx_lock(&Giant); 359 biodone(bp); 360 mtx_unlock(&Giant); 361} 362 363static void 364g_dev_strategy(struct bio *bp) 365{ 366 struct g_geom *gp; 367 struct g_consumer *cp; 368 struct bio *bp2; 369 dev_t dev; 370 371 dev = bp->bio_dev; 372 gp = dev->si_drv1; 373 cp = dev->si_drv2; 374 bp2 = g_clone_bio(bp); 375 bp2->bio_offset = (off_t)bp->bio_blkno << DEV_BSHIFT; 376 bp2->bio_length = (off_t)bp->bio_bcount; 377 bp2->bio_done = g_dev_done; 378 g_trace(G_T_BIO, 379 "g_dev_strategy(%p/%p) offset %lld length %lld data %p cmd %d", 380 bp, bp2, bp->bio_offset, bp2->bio_length, bp2->bio_data, 381 bp2->bio_cmd); 382 g_io_request(bp2, cp); 383} 384 385 386static void 387g_dev_orphan(struct g_consumer *cp) 388{ 389 struct g_geom *gp; 390 dev_t dev; 391 392 gp = cp->geom; 393 g_trace(G_T_TOPOLOGY, "g_dev_orphan(%p(%s))", cp, gp->name); 394 g_topology_assert(); 395 if (cp->biocount > 0) 396 return; 397 dev = gp->softc;
|
| 398 if (dev->si_flags & SI_DUMPDEV) 399 set_dumper(NULL);
|
381 destroy_dev(dev); 382 if (cp->acr > 0 || cp->acw > 0 || cp->ace > 0) 383 g_access_rel(cp, -cp->acr, -cp->acw, -cp->ace); 384 g_dettach(cp); 385 g_destroy_consumer(cp); 386 g_destroy_geom(gp); 387} 388 389DECLARE_GEOM_CLASS(g_dev_class, g_dev) 390
| 400 destroy_dev(dev); 401 if (cp->acr > 0 || cp->acw > 0 || cp->ace > 0) 402 g_access_rel(cp, -cp->acr, -cp->acw, -cp->ace); 403 g_dettach(cp); 404 g_destroy_consumer(cp); 405 g_destroy_geom(gp); 406} 407 408DECLARE_GEOM_CLASS(g_dev_class, g_dev) 409
|