]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_geom.c
MFC r241286,r242135: zfs_mount: taste geom providers for root pool config
[FreeBSD/stable/9.git] / sys / cddl / contrib / opensolaris / uts / common / fs / zfs / vdev_geom.c
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
23  * All rights reserved.
24  *
25  * Portions Copyright (c) 2012 Martin Matuska <mm@FreeBSD.org>
26  */
27
28 #include <sys/zfs_context.h>
29 #include <sys/param.h>
30 #include <sys/kernel.h>
31 #include <sys/bio.h>
32 #include <sys/disk.h>
33 #include <sys/spa.h>
34 #include <sys/spa_impl.h>
35 #include <sys/vdev_impl.h>
36 #include <sys/fs/zfs.h>
37 #include <sys/zio.h>
38 #include <geom/geom.h>
39 #include <geom/geom_int.h>
40
41 /*
42  * Virtual device vector for GEOM.
43  */
44
45 struct g_class zfs_vdev_class = {
46         .name = "ZFS::VDEV",
47         .version = G_VERSION,
48 };
49
50 DECLARE_GEOM_CLASS(zfs_vdev_class, zfs_vdev);
51
52 /*
53  * Don't send BIO_FLUSH.
54  */
55 static int vdev_geom_bio_flush_disable = 0;
56 TUNABLE_INT("vfs.zfs.vdev.bio_flush_disable", &vdev_geom_bio_flush_disable);
57 SYSCTL_DECL(_vfs_zfs_vdev);
58 SYSCTL_INT(_vfs_zfs_vdev, OID_AUTO, bio_flush_disable, CTLFLAG_RW,
59     &vdev_geom_bio_flush_disable, 0, "Disable BIO_FLUSH");
60
61 static void
62 vdev_geom_orphan(struct g_consumer *cp)
63 {
64         vdev_t *vd;
65
66         g_topology_assert();
67
68         vd = cp->private;
69
70         /*
71          * Orphan callbacks occur from the GEOM event thread.
72          * Concurrent with this call, new I/O requests may be
73          * working their way through GEOM about to find out
74          * (only once executed by the g_down thread) that we've
75          * been orphaned from our disk provider.  These I/Os
76          * must be retired before we can detach our consumer.
77          * This is most easily achieved by acquiring the
78          * SPA ZIO configuration lock as a writer, but doing
79          * so with the GEOM topology lock held would cause
80          * a lock order reversal.  Instead, rely on the SPA's
81          * async removal support to invoke a close on this
82          * vdev once it is safe to do so.
83          */
84         zfs_post_remove(vd->vdev_spa, vd);
85         vd->vdev_remove_wanted = B_TRUE;
86         spa_async_request(vd->vdev_spa, SPA_ASYNC_REMOVE);
87 }
88
89 static struct g_consumer *
90 vdev_geom_attach(struct g_provider *pp)
91 {
92         struct g_geom *gp;
93         struct g_consumer *cp;
94
95         g_topology_assert();
96
97         ZFS_LOG(1, "Attaching to %s.", pp->name);
98         /* Do we have geom already? No? Create one. */
99         LIST_FOREACH(gp, &zfs_vdev_class.geom, geom) {
100                 if (gp->flags & G_GEOM_WITHER)
101                         continue;
102                 if (strcmp(gp->name, "zfs::vdev") != 0)
103                         continue;
104                 break;
105         }
106         if (gp == NULL) {
107                 gp = g_new_geomf(&zfs_vdev_class, "zfs::vdev");
108                 gp->orphan = vdev_geom_orphan;
109                 cp = g_new_consumer(gp);
110                 if (g_attach(cp, pp) != 0) {
111                         g_wither_geom(gp, ENXIO);
112                         return (NULL);
113                 }
114                 if (g_access(cp, 1, 0, 1) != 0) {
115                         g_wither_geom(gp, ENXIO);
116                         return (NULL);
117                 }
118                 ZFS_LOG(1, "Created geom and consumer for %s.", pp->name);
119         } else {
120                 /* Check if we are already connected to this provider. */
121                 LIST_FOREACH(cp, &gp->consumer, consumer) {
122                         if (cp->provider == pp) {
123                                 ZFS_LOG(1, "Found consumer for %s.", pp->name);
124                                 break;
125                         }
126                 }
127                 if (cp == NULL) {
128                         cp = g_new_consumer(gp);
129                         if (g_attach(cp, pp) != 0) {
130                                 g_destroy_consumer(cp);
131                                 return (NULL);
132                         }
133                         if (g_access(cp, 1, 0, 1) != 0) {
134                                 g_detach(cp);
135                                 g_destroy_consumer(cp);
136                                 return (NULL);
137                         }
138                         ZFS_LOG(1, "Created consumer for %s.", pp->name);
139                 } else {
140                         if (g_access(cp, 1, 0, 1) != 0)
141                                 return (NULL);
142                         ZFS_LOG(1, "Used existing consumer for %s.", pp->name);
143                 }
144         }
145         return (cp);
146 }
147
148 static void
149 vdev_geom_detach(void *arg, int flag __unused)
150 {
151         struct g_geom *gp;
152         struct g_consumer *cp;
153
154         g_topology_assert();
155         cp = arg;
156         gp = cp->geom;
157
158         ZFS_LOG(1, "Closing access to %s.", cp->provider->name);
159         g_access(cp, -1, 0, -1);
160         /* Destroy consumer on last close. */
161         if (cp->acr == 0 && cp->ace == 0) {
162                 ZFS_LOG(1, "Destroyed consumer to %s.", cp->provider->name);
163                 if (cp->acw > 0)
164                         g_access(cp, 0, -cp->acw, 0);
165                 g_detach(cp);
166                 g_destroy_consumer(cp);
167         }
168         /* Destroy geom if there are no consumers left. */
169         if (LIST_EMPTY(&gp->consumer)) {
170                 ZFS_LOG(1, "Destroyed geom %s.", gp->name);
171                 g_wither_geom(gp, ENXIO);
172         }
173 }
174
175 static uint64_t
176 nvlist_get_guid(nvlist_t *list)
177 {
178         uint64_t value;
179
180         value = 0;
181         nvlist_lookup_uint64(list, ZPOOL_CONFIG_GUID, &value);
182         return (value);
183 }
184
185 static int
186 vdev_geom_io(struct g_consumer *cp, int cmd, void *data, off_t offset, off_t size)
187 {
188         struct bio *bp;
189         u_char *p;
190         off_t off, maxio;
191         int error;
192
193         ASSERT((offset % cp->provider->sectorsize) == 0);
194         ASSERT((size % cp->provider->sectorsize) == 0);
195
196         bp = g_alloc_bio();
197         off = offset;
198         offset += size;
199         p = data;
200         maxio = MAXPHYS - (MAXPHYS % cp->provider->sectorsize);
201         error = 0;
202
203         for (; off < offset; off += maxio, p += maxio, size -= maxio) {
204                 bzero(bp, sizeof(*bp));
205                 bp->bio_cmd = cmd;
206                 bp->bio_done = NULL;
207                 bp->bio_offset = off;
208                 bp->bio_length = MIN(size, maxio);
209                 bp->bio_data = p;
210                 g_io_request(bp, cp);
211                 error = biowait(bp, "vdev_geom_io");
212                 if (error != 0)
213                         break;
214         }
215
216         g_destroy_bio(bp);
217         return (error);
218 }
219
220 static void
221 vdev_geom_taste_orphan(struct g_consumer *cp)
222 {
223
224         KASSERT(1 == 0, ("%s called while tasting %s.", __func__,
225             cp->provider->name));
226 }
227
228 static int
229 vdev_geom_read_config(struct g_consumer *cp, nvlist_t **config)
230 {
231         struct g_provider *pp;
232         vdev_label_t *label;
233         char *p, *buf;
234         size_t buflen;
235         uint64_t psize;
236         off_t offset, size;
237         uint64_t guid, state, txg;
238         int error, l, len;
239
240         g_topology_assert_not();
241
242         pp = cp->provider;
243         ZFS_LOG(1, "Reading config from %s...", pp->name);
244
245         psize = pp->mediasize;
246         psize = P2ALIGN(psize, (uint64_t)sizeof(vdev_label_t));
247
248         size = sizeof(*label) + pp->sectorsize -
249             ((sizeof(*label) - 1) % pp->sectorsize) - 1;
250
251         guid = 0;
252         label = kmem_alloc(size, KM_SLEEP);
253         buflen = sizeof(label->vl_vdev_phys.vp_nvlist);
254
255         *config = NULL;
256         for (l = 0; l < VDEV_LABELS; l++) {
257
258                 offset = vdev_label_offset(psize, l, 0);
259                 if ((offset % pp->sectorsize) != 0)
260                         continue;
261
262                 if (vdev_geom_io(cp, BIO_READ, label, offset, size) != 0)
263                         continue;
264                 buf = label->vl_vdev_phys.vp_nvlist;
265
266                 if (nvlist_unpack(buf, buflen, config, 0) != 0)
267                         continue;
268
269                 if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_STATE,
270                     &state) != 0 || state == POOL_STATE_DESTROYED ||
271                     state > POOL_STATE_L2CACHE) {
272                         nvlist_free(*config);
273                         *config = NULL;
274                         continue;
275                 }
276
277                 if (state != POOL_STATE_SPARE && state != POOL_STATE_L2CACHE &&
278                     (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_TXG,
279                     &txg) != 0 || txg == 0)) {
280                         nvlist_free(*config);
281                         *config = NULL;
282                         continue;
283                 }
284
285                 break;
286         }
287
288         kmem_free(label, size);
289         return (*config == NULL ? ENOENT : 0);
290 }
291
292 static int
293 vdev_geom_check_config(nvlist_t *config, const char *name, uint64_t *best_txg)
294 {
295         uint64_t vdev_guid;
296         uint64_t txg;
297         char *pname;
298
299         if (nvlist_lookup_string(config, ZPOOL_CONFIG_POOL_NAME, &pname) != 0 ||
300             strcmp(pname, name) != 0)
301                 return (ENOENT);
302
303         ZFS_LOG(1, "found pool: %s", pname);
304
305         txg = 0;
306         nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_TXG, &txg);
307         if (txg <= *best_txg)
308                 return (ENOENT);
309         *best_txg = txg;
310         ZFS_LOG(1, "txg: %ju", (uintmax_t)*best_txg);
311
312         return (0);
313 }
314
315 static int
316 vdev_geom_attach_taster(struct g_consumer *cp, struct g_provider *pp)
317 {
318         int error;
319
320         if (pp->flags & G_PF_WITHER)
321                 return (EINVAL);
322         if (pp->sectorsize > VDEV_PAD_SIZE || !ISP2(pp->sectorsize))
323                 return (EINVAL);
324         g_attach(cp, pp);
325         error = g_access(cp, 1, 0, 0);
326         if (error != 0)
327                 g_detach(cp);
328         return (error);
329 }
330
331 static void
332 vdev_geom_dettach_taster(struct g_consumer *cp)
333 {
334         g_access(cp, -1, 0, 0);
335         g_detach(cp);
336 }
337
338 int
339 vdev_geom_read_pool_label(const char *name, nvlist_t **config)
340 {
341         struct g_class *mp;
342         struct g_geom *gp, *zgp;
343         struct g_provider *pp;
344         struct g_consumer *zcp;
345         nvlist_t *vdev_cfg;
346         uint64_t best_txg;
347         int error;
348
349         DROP_GIANT();
350         g_topology_lock();
351
352         zgp = g_new_geomf(&zfs_vdev_class, "zfs::vdev::taste");
353         /* This orphan function should be never called. */
354         zgp->orphan = vdev_geom_taste_orphan;
355         zcp = g_new_consumer(zgp);
356
357         best_txg = 0;
358         *config = NULL;
359         LIST_FOREACH(mp, &g_classes, class) {
360                 if (mp == &zfs_vdev_class)
361                         continue;
362                 LIST_FOREACH(gp, &mp->geom, geom) {
363                         if (gp->flags & G_GEOM_WITHER)
364                                 continue;
365                         LIST_FOREACH(pp, &gp->provider, provider) {
366                                 if (pp->flags & G_PF_WITHER)
367                                         continue;
368                                 if (vdev_geom_attach_taster(zcp, pp) != 0)
369                                         continue;
370                                 g_topology_unlock();
371                                 error = vdev_geom_read_config(zcp, &vdev_cfg);
372                                 g_topology_lock();
373                                 vdev_geom_dettach_taster(zcp);
374                                 if (error)
375                                         continue;
376                                 ZFS_LOG(1, "successfully read vdev config");
377
378                                 error = vdev_geom_check_config(vdev_cfg, name,
379                                     &best_txg);
380                                 if (error != 0) {
381                                         nvlist_free(vdev_cfg);
382                                         continue;
383                                 }
384                                 nvlist_free(*config);
385                                 *config = vdev_cfg;
386                         }
387                 }
388         }
389
390         g_destroy_consumer(zcp);
391         g_destroy_geom(zgp);
392         g_topology_unlock();
393         PICKUP_GIANT();
394         return (*config == NULL ? ENOENT : 0);
395 }
396
397 static uint64_t
398 vdev_geom_read_guid(struct g_consumer *cp)
399 {
400         nvlist_t *config;
401         uint64_t guid;
402
403         g_topology_assert_not();
404
405         guid = 0;
406         if (vdev_geom_read_config(cp, &config) == 0) {
407                 guid = nvlist_get_guid(config);
408                 nvlist_free(config);
409         }
410         return (guid);
411 }
412
413 static struct g_consumer *
414 vdev_geom_attach_by_guid(uint64_t guid)
415 {
416         struct g_class *mp;
417         struct g_geom *gp, *zgp;
418         struct g_provider *pp;
419         struct g_consumer *cp, *zcp;
420         uint64_t pguid;
421
422         g_topology_assert();
423
424         zgp = g_new_geomf(&zfs_vdev_class, "zfs::vdev::taste");
425         /* This orphan function should be never called. */
426         zgp->orphan = vdev_geom_taste_orphan;
427         zcp = g_new_consumer(zgp);
428
429         cp = NULL;
430         LIST_FOREACH(mp, &g_classes, class) {
431                 if (mp == &zfs_vdev_class)
432                         continue;
433                 LIST_FOREACH(gp, &mp->geom, geom) {
434                         if (gp->flags & G_GEOM_WITHER)
435                                 continue;
436                         LIST_FOREACH(pp, &gp->provider, provider) {
437                                 if (vdev_geom_attach_taster(zcp, pp) != 0)
438                                         continue;
439                                 g_topology_unlock();
440                                 pguid = vdev_geom_read_guid(zcp);
441                                 g_topology_lock();
442                                 vdev_geom_dettach_taster(zcp);
443                                 if (pguid != guid)
444                                         continue;
445                                 cp = vdev_geom_attach(pp);
446                                 if (cp == NULL) {
447                                         printf("ZFS WARNING: Unable to attach to %s.\n",
448                                             pp->name);
449                                         continue;
450                                 }
451                                 break;
452                         }
453                         if (cp != NULL)
454                                 break;
455                 }
456                 if (cp != NULL)
457                         break;
458         }
459 end:
460         g_destroy_consumer(zcp);
461         g_destroy_geom(zgp);
462         return (cp);
463 }
464
465 static struct g_consumer *
466 vdev_geom_open_by_guid(vdev_t *vd)
467 {
468         struct g_consumer *cp;
469         char *buf;
470         size_t len;
471
472         g_topology_assert();
473
474         ZFS_LOG(1, "Searching by guid [%ju].", (uintmax_t)vd->vdev_guid);
475         cp = vdev_geom_attach_by_guid(vd->vdev_guid);
476         if (cp != NULL) {
477                 len = strlen(cp->provider->name) + strlen("/dev/") + 1;
478                 buf = kmem_alloc(len, KM_SLEEP);
479
480                 snprintf(buf, len, "/dev/%s", cp->provider->name);
481                 spa_strfree(vd->vdev_path);
482                 vd->vdev_path = buf;
483
484                 ZFS_LOG(1, "Attach by guid [%ju] succeeded, provider %s.",
485                     (uintmax_t)vd->vdev_guid, vd->vdev_path);
486         } else {
487                 ZFS_LOG(1, "Search by guid [%ju] failed.",
488                     (uintmax_t)vd->vdev_guid);
489         }
490
491         return (cp);
492 }
493
494 static struct g_consumer *
495 vdev_geom_open_by_path(vdev_t *vd, int check_guid)
496 {
497         struct g_provider *pp;
498         struct g_consumer *cp;
499         uint64_t guid;
500
501         g_topology_assert();
502
503         cp = NULL;
504         pp = g_provider_by_name(vd->vdev_path + sizeof("/dev/") - 1);
505         if (pp != NULL) {
506                 ZFS_LOG(1, "Found provider by name %s.", vd->vdev_path);
507                 cp = vdev_geom_attach(pp);
508                 if (cp != NULL && check_guid && ISP2(pp->sectorsize) &&
509                     pp->sectorsize <= VDEV_PAD_SIZE) {
510                         g_topology_unlock();
511                         guid = vdev_geom_read_guid(cp);
512                         g_topology_lock();
513                         if (guid != vd->vdev_guid) {
514                                 vdev_geom_detach(cp, 0);
515                                 cp = NULL;
516                                 ZFS_LOG(1, "guid mismatch for provider %s: "
517                                     "%ju != %ju.", vd->vdev_path,
518                                     (uintmax_t)vd->vdev_guid, (uintmax_t)guid);
519                         } else {
520                                 ZFS_LOG(1, "guid match for provider %s.",
521                                     vd->vdev_path);
522                         }
523                 }
524         }
525
526         return (cp);
527 }
528
529 static int
530 vdev_geom_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
531     uint64_t *ashift)
532 {
533         struct g_provider *pp;
534         struct g_consumer *cp;
535         size_t bufsize;
536         int error;
537
538         /*
539          * We must have a pathname, and it must be absolute.
540          */
541         if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
542                 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
543                 return (EINVAL);
544         }
545
546         vd->vdev_tsd = NULL;
547
548         DROP_GIANT();
549         g_topology_lock();
550         error = 0;
551
552         /*
553          * If we're creating or splitting a pool, just find the GEOM provider
554          * by its name and ignore GUID mismatches.
555          */
556         if (vd->vdev_spa->spa_load_state == SPA_LOAD_NONE ||
557             vd->vdev_spa->spa_splitting_newspa == B_TRUE)
558                 cp = vdev_geom_open_by_path(vd, 0);
559         else {
560                 cp = vdev_geom_open_by_path(vd, 1);
561                 if (cp == NULL) {
562                         /*
563                          * The device at vd->vdev_path doesn't have the
564                          * expected guid. The disks might have merely
565                          * moved around so try all other GEOM providers
566                          * to find one with the right guid.
567                          */
568                         cp = vdev_geom_open_by_guid(vd);
569                 }
570         }
571
572         if (cp == NULL) {
573                 ZFS_LOG(1, "Provider %s not found.", vd->vdev_path);
574                 error = ENOENT;
575         } else if (cp->provider->sectorsize > VDEV_PAD_SIZE ||
576             !ISP2(cp->provider->sectorsize)) {
577                 ZFS_LOG(1, "Provider %s has unsupported sectorsize.",
578                     vd->vdev_path);
579                 vdev_geom_detach(cp, 0);
580                 error = EINVAL;
581                 cp = NULL;
582         } else if (cp->acw == 0 && (spa_mode(vd->vdev_spa) & FWRITE) != 0) {
583                 int i;
584
585                 for (i = 0; i < 5; i++) {
586                         error = g_access(cp, 0, 1, 0);
587                         if (error == 0)
588                                 break;
589                         g_topology_unlock();
590                         tsleep(vd, 0, "vdev", hz / 2);
591                         g_topology_lock();
592                 }
593                 if (error != 0) {
594                         printf("ZFS WARNING: Unable to open %s for writing (error=%d).\n",
595                             vd->vdev_path, error);
596                         vdev_geom_detach(cp, 0);
597                         cp = NULL;
598                 }
599         }
600         g_topology_unlock();
601         PICKUP_GIANT();
602         if (cp == NULL) {
603                 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
604                 return (error);
605         }
606
607         cp->private = vd;
608         vd->vdev_tsd = cp;
609         pp = cp->provider;
610
611         /*
612          * Determine the actual size of the device.
613          */
614         *max_psize = *psize = pp->mediasize;
615
616         /*
617          * Determine the device's minimum transfer size.
618          */
619         *ashift = highbit(MAX(pp->sectorsize, SPA_MINBLOCKSIZE)) - 1;
620
621         /*
622          * Clear the nowritecache bit, so that on a vdev_reopen() we will
623          * try again.
624          */
625         vd->vdev_nowritecache = B_FALSE;
626
627         if (vd->vdev_physpath != NULL)
628                 spa_strfree(vd->vdev_physpath);
629         bufsize = sizeof("/dev/") + strlen(pp->name);
630         vd->vdev_physpath = kmem_alloc(bufsize, KM_SLEEP);
631         snprintf(vd->vdev_physpath, bufsize, "/dev/%s", pp->name);
632
633         return (0);
634 }
635
636 static void
637 vdev_geom_close(vdev_t *vd)
638 {
639         struct g_consumer *cp;
640
641         cp = vd->vdev_tsd;
642         if (cp == NULL)
643                 return;
644         vd->vdev_tsd = NULL;
645         vd->vdev_delayed_close = B_FALSE;
646         g_post_event(vdev_geom_detach, cp, M_WAITOK, NULL);
647 }
648
649 static void
650 vdev_geom_io_intr(struct bio *bp)
651 {
652         vdev_t *vd;
653         zio_t *zio;
654
655         zio = bp->bio_caller1;
656         vd = zio->io_vd;
657         zio->io_error = bp->bio_error;
658         if (zio->io_error == 0 && bp->bio_resid != 0)
659                 zio->io_error = EIO;
660         if (bp->bio_cmd == BIO_FLUSH && bp->bio_error == ENOTSUP) {
661                 /*
662                  * If we get ENOTSUP, we know that no future
663                  * attempts will ever succeed.  In this case we
664                  * set a persistent bit so that we don't bother
665                  * with the ioctl in the future.
666                  */
667                 vd->vdev_nowritecache = B_TRUE;
668         }
669         if (zio->io_error == EIO && !vd->vdev_remove_wanted) {
670                 /*
671                  * If provider's error is set we assume it is being
672                  * removed.
673                  */
674                 if (bp->bio_to->error != 0) {
675                         /*
676                          * We post the resource as soon as possible, instead of
677                          * when the async removal actually happens, because the
678                          * DE is using this information to discard previous I/O
679                          * errors.
680                          */
681                         /* XXX: zfs_post_remove() can sleep. */
682                         zfs_post_remove(zio->io_spa, vd);
683                         vd->vdev_remove_wanted = B_TRUE;
684                         spa_async_request(zio->io_spa, SPA_ASYNC_REMOVE);
685                 } else if (!vd->vdev_delayed_close) {
686                         vd->vdev_delayed_close = B_TRUE;
687                 }
688         }
689         g_destroy_bio(bp);
690         zio_interrupt(zio);
691 }
692
693 static int
694 vdev_geom_io_start(zio_t *zio)
695 {
696         vdev_t *vd;
697         struct g_consumer *cp;
698         struct bio *bp;
699         int error;
700
701         vd = zio->io_vd;
702
703         if (zio->io_type == ZIO_TYPE_IOCTL) {
704                 /* XXPOLICY */
705                 if (!vdev_readable(vd)) {
706                         zio->io_error = ENXIO;
707                         return (ZIO_PIPELINE_CONTINUE);
708                 }
709
710                 switch (zio->io_cmd) {
711
712                 case DKIOCFLUSHWRITECACHE:
713
714                         if (zfs_nocacheflush || vdev_geom_bio_flush_disable)
715                                 break;
716
717                         if (vd->vdev_nowritecache) {
718                                 zio->io_error = ENOTSUP;
719                                 break;
720                         }
721
722                         goto sendreq;
723                 default:
724                         zio->io_error = ENOTSUP;
725                 }
726
727                 return (ZIO_PIPELINE_CONTINUE);
728         }
729 sendreq:
730         cp = vd->vdev_tsd;
731         if (cp == NULL) {
732                 zio->io_error = ENXIO;
733                 return (ZIO_PIPELINE_CONTINUE);
734         }
735         bp = g_alloc_bio();
736         bp->bio_caller1 = zio;
737         switch (zio->io_type) {
738         case ZIO_TYPE_READ:
739         case ZIO_TYPE_WRITE:
740                 bp->bio_cmd = zio->io_type == ZIO_TYPE_READ ? BIO_READ : BIO_WRITE;
741                 bp->bio_data = zio->io_data;
742                 bp->bio_offset = zio->io_offset;
743                 bp->bio_length = zio->io_size;
744                 break;
745         case ZIO_TYPE_IOCTL:
746                 bp->bio_cmd = BIO_FLUSH;
747                 bp->bio_flags |= BIO_ORDERED;
748                 bp->bio_data = NULL;
749                 bp->bio_offset = cp->provider->mediasize;
750                 bp->bio_length = 0;
751                 break;
752         }
753         bp->bio_done = vdev_geom_io_intr;
754
755         g_io_request(bp, cp);
756
757         return (ZIO_PIPELINE_STOP);
758 }
759
760 static void
761 vdev_geom_io_done(zio_t *zio)
762 {
763 }
764
765 static void
766 vdev_geom_hold(vdev_t *vd)
767 {
768 }
769
770 static void
771 vdev_geom_rele(vdev_t *vd)
772 {
773 }
774
775 vdev_ops_t vdev_geom_ops = {
776         vdev_geom_open,
777         vdev_geom_close,
778         vdev_default_asize,
779         vdev_geom_io_start,
780         vdev_geom_io_done,
781         NULL,
782         vdev_geom_hold,
783         vdev_geom_rele,
784         VDEV_TYPE_DISK,         /* name of this vdev type */
785         B_TRUE                  /* leaf vdev */
786 };