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.
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.
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]
22 * Copyright (c) 2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
23 * All rights reserved.
25 * Portions Copyright (c) 2012 Martin Matuska <mm@FreeBSD.org>
28 #include <sys/zfs_context.h>
29 #include <sys/param.h>
30 #include <sys/kernel.h>
34 #include <sys/spa_impl.h>
35 #include <sys/vdev_impl.h>
36 #include <sys/fs/zfs.h>
38 #include <geom/geom.h>
39 #include <geom/geom_int.h>
42 * Virtual device vector for GEOM.
45 static g_attrchanged_t vdev_geom_attrchanged;
46 struct g_class zfs_vdev_class = {
49 .attrchanged = vdev_geom_attrchanged,
52 DECLARE_GEOM_CLASS(zfs_vdev_class, zfs_vdev);
54 SYSCTL_DECL(_vfs_zfs_vdev);
55 /* Don't send BIO_FLUSH. */
56 static int vdev_geom_bio_flush_disable;
57 SYSCTL_INT(_vfs_zfs_vdev, OID_AUTO, bio_flush_disable, CTLFLAG_RWTUN,
58 &vdev_geom_bio_flush_disable, 0, "Disable BIO_FLUSH");
59 /* Don't send BIO_DELETE. */
60 static int vdev_geom_bio_delete_disable;
61 SYSCTL_INT(_vfs_zfs_vdev, OID_AUTO, bio_delete_disable, CTLFLAG_RWTUN,
62 &vdev_geom_bio_delete_disable, 0, "Disable BIO_DELETE");
64 /* Declare local functions */
65 static void vdev_geom_detach(struct g_consumer *cp, boolean_t open_for_read);
68 * Thread local storage used to indicate when a thread is probing geoms
69 * for their guids. If NULL, this thread is not tasting geoms. If non NULL,
70 * it is looking for a replacement for the vdev_t* that is its value.
72 uint_t zfs_geom_probe_vdev_key;
75 vdev_geom_set_rotation_rate(vdev_t *vd, struct g_consumer *cp)
80 error = g_getattr("GEOM::rotation_rate", cp, &rate);
82 vd->vdev_rotation_rate = rate;
84 vd->vdev_rotation_rate = VDEV_RATE_UNKNOWN;
88 vdev_geom_attrchanged(struct g_consumer *cp, const char *attr)
93 int error, physpath_len;
99 if (strcmp(attr, "GEOM::rotation_rate") == 0) {
100 vdev_geom_set_rotation_rate(vd, cp);
104 if (strcmp(attr, "GEOM::physpath") != 0)
107 if (g_access(cp, 1, 0, 0) != 0)
111 * Record/Update physical path information for this device.
114 physpath_len = MAXPATHLEN;
115 physpath = g_malloc(physpath_len, M_WAITOK|M_ZERO);
116 error = g_io_getattr("GEOM::physpath", cp, &physpath_len, physpath);
117 g_access(cp, -1, 0, 0);
121 /* g_topology lock ensures that vdev has not been closed */
123 old_physpath = vd->vdev_physpath;
124 vd->vdev_physpath = spa_strdup(physpath);
125 spa_async_request(spa, SPA_ASYNC_CONFIG_UPDATE);
127 if (old_physpath != NULL)
128 spa_strfree(old_physpath);
134 vdev_geom_orphan(struct g_consumer *cp)
142 /* Vdev close in progress. Ignore the event. */
147 * Orphan callbacks occur from the GEOM event thread.
148 * Concurrent with this call, new I/O requests may be
149 * working their way through GEOM about to find out
150 * (only once executed by the g_down thread) that we've
151 * been orphaned from our disk provider. These I/Os
152 * must be retired before we can detach our consumer.
153 * This is most easily achieved by acquiring the
154 * SPA ZIO configuration lock as a writer, but doing
155 * so with the GEOM topology lock held would cause
156 * a lock order reversal. Instead, rely on the SPA's
157 * async removal support to invoke a close on this
158 * vdev once it is safe to do so.
160 vd->vdev_remove_wanted = B_TRUE;
161 spa_async_request(vd->vdev_spa, SPA_ASYNC_REMOVE);
164 static struct g_consumer *
165 vdev_geom_attach(struct g_provider *pp, vdev_t *vd)
168 struct g_consumer *cp;
173 ZFS_LOG(1, "Attaching to %s.", pp->name);
175 if (pp->sectorsize > VDEV_PAD_SIZE || !ISP2(pp->sectorsize)) {
176 ZFS_LOG(1, "Failing attach of %s. Incompatible sectorsize %d\n",
177 pp->name, pp->sectorsize);
179 } else if (pp->mediasize < SPA_MINDEVSIZE) {
180 ZFS_LOG(1, "Failing attach of %s. Incompatible mediasize %ju\n",
181 pp->name, pp->mediasize);
185 /* Do we have geom already? No? Create one. */
186 LIST_FOREACH(gp, &zfs_vdev_class.geom, geom) {
187 if (gp->flags & G_GEOM_WITHER)
189 if (strcmp(gp->name, "zfs::vdev") != 0)
194 gp = g_new_geomf(&zfs_vdev_class, "zfs::vdev");
195 gp->orphan = vdev_geom_orphan;
196 gp->attrchanged = vdev_geom_attrchanged;
197 cp = g_new_consumer(gp);
198 error = g_attach(cp, pp);
200 ZFS_LOG(1, "%s(%d): g_attach failed: %d\n", __func__,
202 vdev_geom_detach(cp, B_FALSE);
205 error = g_access(cp, 1, 0, 1);
207 ZFS_LOG(1, "%s(%d): g_access failed: %d\n", __func__,
209 vdev_geom_detach(cp, B_FALSE);
212 ZFS_LOG(1, "Created geom and consumer for %s.", pp->name);
214 /* Check if we are already connected to this provider. */
215 LIST_FOREACH(cp, &gp->consumer, consumer) {
216 if (cp->provider == pp) {
217 ZFS_LOG(1, "Found consumer for %s.", pp->name);
222 cp = g_new_consumer(gp);
223 error = g_attach(cp, pp);
225 ZFS_LOG(1, "%s(%d): g_attach failed: %d\n",
226 __func__, __LINE__, error);
227 vdev_geom_detach(cp, B_FALSE);
230 error = g_access(cp, 1, 0, 1);
232 ZFS_LOG(1, "%s(%d): g_access failed: %d\n",
233 __func__, __LINE__, error);
234 vdev_geom_detach(cp, B_FALSE);
237 ZFS_LOG(1, "Created consumer for %s.", pp->name);
239 error = g_access(cp, 1, 0, 1);
241 ZFS_LOG(1, "%s(%d): g_access failed: %d\n",
242 __func__, __LINE__, error);
245 ZFS_LOG(1, "Used existing consumer for %s.", pp->name);
250 * BUG: cp may already belong to a vdev. This could happen if:
251 * 1) That vdev is a shared spare, or
252 * 2) We are trying to reopen a missing vdev and we are scanning by
253 * guid. In that case, we'll ultimately fail to open this consumer,
254 * but not until after setting the private field.
255 * The solution is to:
256 * 1) Don't set the private field until after the open succeeds, and
257 * 2) Set it to a linked list of vdevs, not just a single vdev
263 cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
268 vdev_geom_detach(struct g_consumer *cp, boolean_t open_for_read)
275 ZFS_LOG(1, "Detaching consumer. Provider %s.",
276 cp->provider && cp->provider->name ? cp->provider->name : "NULL");
283 g_access(cp, -1, 0, -1);
284 /* Destroy consumer on last close. */
285 if (cp->acr == 0 && cp->ace == 0) {
287 g_access(cp, 0, -cp->acw, 0);
288 if (cp->provider != NULL) {
289 ZFS_LOG(1, "Destroying consumer to %s.",
290 cp->provider->name ? cp->provider->name : "NULL");
293 g_destroy_consumer(cp);
295 /* Destroy geom if there are no consumers left. */
296 if (LIST_EMPTY(&gp->consumer)) {
297 ZFS_LOG(1, "Destroyed geom %s.", gp->name);
298 g_wither_geom(gp, ENXIO);
303 vdev_geom_close_locked(vdev_t *vd)
305 struct g_consumer *cp;
311 vd->vdev_delayed_close = B_FALSE;
315 ZFS_LOG(1, "Closing access to %s.", cp->provider->name);
317 vdev_geom_detach(cp, B_TRUE);
321 nvlist_get_guids(nvlist_t *list, uint64_t *pguid, uint64_t *vguid)
324 (void) nvlist_lookup_uint64(list, ZPOOL_CONFIG_GUID, vguid);
325 (void) nvlist_lookup_uint64(list, ZPOOL_CONFIG_POOL_GUID, pguid);
329 * Issue one or more bios to the vdev in parallel
330 * cmds, datas, offsets, errors, and sizes are arrays of length ncmds. Each IO
331 * operation is described by parallel entries from each array. There may be
332 * more bios actually issued than entries in the array
335 vdev_geom_io(struct g_consumer *cp, int *cmds, void **datas, off_t *offsets,
336 off_t *sizes, int *errors, int ncmds)
340 off_t off, maxio, s, end;
344 maxio = MAXPHYS - (MAXPHYS % cp->provider->sectorsize);
347 /* How many bios are required for all commands ? */
348 for (i = 0; i < ncmds; i++)
349 n_bios += (sizes[i] + maxio - 1) / maxio;
351 /* Allocate memory for the bios */
352 bios_size = n_bios * sizeof(struct bio*);
353 bios = kmem_zalloc(bios_size, KM_SLEEP);
355 /* Prepare and issue all of the bios */
356 for (i = j = 0; i < ncmds; i++) {
361 ASSERT((off % cp->provider->sectorsize) == 0);
362 ASSERT((s % cp->provider->sectorsize) == 0);
364 for (; off < end; off += maxio, p += maxio, s -= maxio, j++) {
365 bios[j] = g_alloc_bio();
366 bios[j]->bio_cmd = cmds[i];
367 bios[j]->bio_done = NULL;
368 bios[j]->bio_offset = off;
369 bios[j]->bio_length = MIN(s, maxio);
370 bios[j]->bio_data = p;
371 g_io_request(bios[j], cp);
376 /* Wait for all of the bios to complete, and clean them up */
377 for (i = j = 0; i < ncmds; i++) {
382 for (; off < end; off += maxio, s -= maxio, j++) {
383 errors[i] = biowait(bios[j], "vdev_geom_io") || errors[i];
384 g_destroy_bio(bios[j]);
387 kmem_free(bios, bios_size);
391 vdev_geom_read_config(struct g_consumer *cp, nvlist_t **config)
393 struct g_provider *pp;
394 vdev_phys_t *vdev_lists[VDEV_LABELS];
397 uint64_t psize, state, txg;
398 off_t offsets[VDEV_LABELS];
400 off_t sizes[VDEV_LABELS];
401 int cmds[VDEV_LABELS];
402 int errors[VDEV_LABELS];
405 g_topology_assert_not();
408 ZFS_LOG(1, "Reading config from %s...", pp->name);
410 psize = pp->mediasize;
411 psize = P2ALIGN(psize, (uint64_t)sizeof(vdev_label_t));
413 size = sizeof(*vdev_lists[0]) + pp->sectorsize -
414 ((sizeof(*vdev_lists[0]) - 1) % pp->sectorsize) - 1;
416 buflen = sizeof(vdev_lists[0]->vp_nvlist);
419 /* Create all of the IO requests */
420 for (l = 0; l < VDEV_LABELS; l++) {
422 vdev_lists[l] = kmem_alloc(size, KM_SLEEP);
423 offsets[l] = vdev_label_offset(psize, l, 0) + VDEV_SKIP_SIZE;
426 ASSERT(offsets[l] % pp->sectorsize == 0);
429 /* Issue the IO requests */
430 vdev_geom_io(cp, cmds, (void**)vdev_lists, offsets, sizes, errors,
433 /* Parse the labels */
434 for (l = 0; l < VDEV_LABELS; l++) {
438 buf = vdev_lists[l]->vp_nvlist;
440 if (nvlist_unpack(buf, buflen, config, 0) != 0)
443 if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_STATE,
444 &state) != 0 || state > POOL_STATE_L2CACHE) {
445 nvlist_free(*config);
450 if (state != POOL_STATE_SPARE &&
451 state != POOL_STATE_L2CACHE &&
452 (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_TXG,
453 &txg) != 0 || txg == 0)) {
454 nvlist_free(*config);
462 /* Free the label storage */
463 for (l = 0; l < VDEV_LABELS; l++)
464 kmem_free(vdev_lists[l], size);
466 return (*config == NULL ? ENOENT : 0);
470 resize_configs(nvlist_t ***configs, uint64_t *count, uint64_t id)
472 nvlist_t **new_configs;
477 new_configs = kmem_zalloc((id + 1) * sizeof(nvlist_t *),
479 for (i = 0; i < *count; i++)
480 new_configs[i] = (*configs)[i];
481 if (*configs != NULL)
482 kmem_free(*configs, *count * sizeof(void *));
483 *configs = new_configs;
488 process_vdev_config(nvlist_t ***configs, uint64_t *count, nvlist_t *cfg,
489 const char *name, uint64_t* known_pool_guid)
493 uint64_t vdev_guid, known_guid;
494 uint64_t id, txg, known_txg;
498 if (nvlist_lookup_string(cfg, ZPOOL_CONFIG_POOL_NAME, &pname) != 0 ||
499 strcmp(pname, name) != 0)
502 if (nvlist_lookup_uint64(cfg, ZPOOL_CONFIG_POOL_GUID, &pool_guid) != 0)
505 if (nvlist_lookup_uint64(cfg, ZPOOL_CONFIG_TOP_GUID, &vdev_guid) != 0)
508 if (nvlist_lookup_nvlist(cfg, ZPOOL_CONFIG_VDEV_TREE, &vdev_tree) != 0)
511 if (nvlist_lookup_uint64(vdev_tree, ZPOOL_CONFIG_ID, &id) != 0)
514 VERIFY(nvlist_lookup_uint64(cfg, ZPOOL_CONFIG_POOL_TXG, &txg) == 0);
516 if (*known_pool_guid != 0) {
517 if (pool_guid != *known_pool_guid)
520 *known_pool_guid = pool_guid;
522 resize_configs(configs, count, id);
524 if ((*configs)[id] != NULL) {
525 VERIFY(nvlist_lookup_uint64((*configs)[id],
526 ZPOOL_CONFIG_POOL_TXG, &known_txg) == 0);
527 if (txg <= known_txg)
529 nvlist_free((*configs)[id]);
532 (*configs)[id] = cfg;
540 vdev_geom_read_pool_label(const char *name,
541 nvlist_t ***configs, uint64_t *count)
545 struct g_provider *pp;
546 struct g_consumer *zcp;
557 LIST_FOREACH(mp, &g_classes, class) {
558 if (mp == &zfs_vdev_class)
560 LIST_FOREACH(gp, &mp->geom, geom) {
561 if (gp->flags & G_GEOM_WITHER)
563 LIST_FOREACH(pp, &gp->provider, provider) {
564 if (pp->flags & G_PF_WITHER)
566 zcp = vdev_geom_attach(pp, NULL);
570 error = vdev_geom_read_config(zcp, &vdev_cfg);
572 vdev_geom_detach(zcp, B_TRUE);
575 ZFS_LOG(1, "successfully read vdev config");
577 process_vdev_config(configs, count,
578 vdev_cfg, name, &pool_guid);
585 return (*count > 0 ? 0 : ENOENT);
589 vdev_geom_read_guids(struct g_consumer *cp, uint64_t *pguid, uint64_t *vguid)
593 g_topology_assert_not();
597 if (vdev_geom_read_config(cp, &config) == 0) {
598 nvlist_get_guids(config, pguid, vguid);
604 vdev_attach_ok(vdev_t *vd, struct g_provider *pp)
608 struct g_consumer *zcp;
612 zcp = vdev_geom_attach(pp, NULL);
614 ZFS_LOG(1, "Unable to attach tasting instance to %s.",
619 vdev_geom_read_guids(zcp, &pool_guid, &vdev_guid);
621 vdev_geom_detach(zcp, B_TRUE);
624 * Check that the label's vdev guid matches the desired guid. If the
625 * label has a pool guid, check that it matches too. (Inactive spares
626 * and L2ARCs do not have any pool guid in the label.)
628 if ((pool_guid == 0 || pool_guid == spa_guid(vd->vdev_spa)) &&
629 vdev_guid == vd->vdev_guid) {
630 ZFS_LOG(1, "guids match for provider %s.", vd->vdev_path);
633 ZFS_LOG(1, "guid mismatch for provider %s: "
634 "%ju:%ju != %ju:%ju.", vd->vdev_path,
635 (uintmax_t)spa_guid(vd->vdev_spa),
636 (uintmax_t)vd->vdev_guid,
637 (uintmax_t)pool_guid, (uintmax_t)vdev_guid);
642 static struct g_consumer *
643 vdev_geom_attach_by_guids(vdev_t *vd)
647 struct g_provider *pp;
648 struct g_consumer *cp;
653 LIST_FOREACH(mp, &g_classes, class) {
654 if (mp == &zfs_vdev_class)
656 LIST_FOREACH(gp, &mp->geom, geom) {
657 if (gp->flags & G_GEOM_WITHER)
659 LIST_FOREACH(pp, &gp->provider, provider) {
660 if (!vdev_attach_ok(vd, pp))
662 cp = vdev_geom_attach(pp, vd);
664 printf("ZFS WARNING: Unable to "
665 "attach to %s.\n", pp->name);
680 static struct g_consumer *
681 vdev_geom_open_by_guids(vdev_t *vd)
683 struct g_consumer *cp;
689 ZFS_LOG(1, "Searching by guids [%ju:%ju].",
690 (uintmax_t)spa_guid(vd->vdev_spa), (uintmax_t)vd->vdev_guid);
691 cp = vdev_geom_attach_by_guids(vd);
693 len = strlen(cp->provider->name) + strlen("/dev/") + 1;
694 buf = kmem_alloc(len, KM_SLEEP);
696 snprintf(buf, len, "/dev/%s", cp->provider->name);
697 spa_strfree(vd->vdev_path);
700 ZFS_LOG(1, "Attach by guid [%ju:%ju] succeeded, provider %s.",
701 (uintmax_t)spa_guid(vd->vdev_spa),
702 (uintmax_t)vd->vdev_guid, vd->vdev_path);
704 ZFS_LOG(1, "Search by guid [%ju:%ju] failed.",
705 (uintmax_t)spa_guid(vd->vdev_spa),
706 (uintmax_t)vd->vdev_guid);
712 static struct g_consumer *
713 vdev_geom_open_by_path(vdev_t *vd, int check_guid)
715 struct g_provider *pp;
716 struct g_consumer *cp;
721 pp = g_provider_by_name(vd->vdev_path + sizeof("/dev/") - 1);
723 ZFS_LOG(1, "Found provider by name %s.", vd->vdev_path);
724 if (!check_guid || vdev_attach_ok(vd, pp))
725 cp = vdev_geom_attach(pp, vd);
732 vdev_geom_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
733 uint64_t *logical_ashift, uint64_t *physical_ashift)
735 struct g_provider *pp;
736 struct g_consumer *cp;
740 /* Set the TLS to indicate downstack that we should not access zvols*/
741 VERIFY(tsd_set(zfs_geom_probe_vdev_key, vd) == 0);
744 * We must have a pathname, and it must be absolute.
746 if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
747 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
757 if (vd->vdev_spa->spa_splitting_newspa ||
758 (vd->vdev_prevstate == VDEV_STATE_UNKNOWN &&
759 vd->vdev_spa->spa_load_state == SPA_LOAD_NONE)) {
761 * We are dealing with a vdev that hasn't been previously
762 * opened (since boot), and we are not loading an
763 * existing pool configuration. This looks like a
764 * vdev add operation to a new or existing pool.
765 * Assume the user knows what he/she is doing and find
766 * GEOM provider by its name, ignoring GUID mismatches.
768 * XXPOLICY: It would be safer to only allow a device
769 * that is unlabeled or labeled but missing
770 * GUID information to be opened in this fashion,
771 * unless we are doing a split, in which case we
772 * should allow any guid.
774 cp = vdev_geom_open_by_path(vd, 0);
777 * Try using the recorded path for this device, but only
778 * accept it if its label data contains the expected GUIDs.
780 cp = vdev_geom_open_by_path(vd, 1);
783 * The device at vd->vdev_path doesn't have the
784 * expected GUIDs. The disks might have merely
785 * moved around so try all other GEOM providers
786 * to find one with the right GUIDs.
788 cp = vdev_geom_open_by_guids(vd);
792 /* Clear the TLS now that tasting is done */
793 VERIFY(tsd_set(zfs_geom_probe_vdev_key, NULL) == 0);
796 ZFS_LOG(1, "Provider %s not found.", vd->vdev_path);
798 } else if (cp->provider->sectorsize > VDEV_PAD_SIZE ||
799 !ISP2(cp->provider->sectorsize)) {
800 ZFS_LOG(1, "Provider %s has unsupported sectorsize.",
803 vdev_geom_close_locked(vd);
806 } else if (cp->acw == 0 && (spa_mode(vd->vdev_spa) & FWRITE) != 0) {
809 for (i = 0; i < 5; i++) {
810 error = g_access(cp, 0, 1, 0);
814 tsleep(vd, 0, "vdev", hz / 2);
818 printf("ZFS WARNING: Unable to open %s for writing (error=%d).\n",
819 vd->vdev_path, error);
820 vdev_geom_close_locked(vd);
825 /* Fetch initial physical path information for this device. */
827 vdev_geom_attrchanged(cp, "GEOM::physpath");
832 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
838 * Determine the actual size of the device.
840 *max_psize = *psize = pp->mediasize;
843 * Determine the device's minimum transfer size and preferred
846 *logical_ashift = highbit(MAX(pp->sectorsize, SPA_MINBLOCKSIZE)) - 1;
847 *physical_ashift = 0;
848 if (pp->stripesize > (1 << *logical_ashift) && ISP2(pp->stripesize) &&
849 pp->stripesize <= (1 << SPA_MAXASHIFT) && pp->stripeoffset == 0)
850 *physical_ashift = highbit(pp->stripesize) - 1;
853 * Clear the nowritecache settings, so that on a vdev_reopen()
856 vd->vdev_nowritecache = B_FALSE;
859 * Determine the device's rotation rate.
861 vdev_geom_set_rotation_rate(vd, cp);
867 vdev_geom_close(vdev_t *vd)
872 vdev_geom_close_locked(vd);
878 vdev_geom_io_intr(struct bio *bp)
883 zio = bp->bio_caller1;
885 zio->io_error = bp->bio_error;
886 if (zio->io_error == 0 && bp->bio_resid != 0)
887 zio->io_error = SET_ERROR(EIO);
889 switch(zio->io_error) {
892 * If we get ENOTSUP for BIO_FLUSH or BIO_DELETE we know
893 * that future attempts will never succeed. In this case
894 * we set a persistent flag so that we don't bother with
895 * requests in the future.
897 switch(bp->bio_cmd) {
899 vd->vdev_nowritecache = B_TRUE;
902 vd->vdev_notrim = B_TRUE;
907 if (!vd->vdev_remove_wanted) {
909 * If provider's error is set we assume it is being
912 if (bp->bio_to->error != 0) {
913 vd->vdev_remove_wanted = B_TRUE;
914 spa_async_request(zio->io_spa,
916 } else if (!vd->vdev_delayed_close) {
917 vd->vdev_delayed_close = B_TRUE;
923 zio_delay_interrupt(zio);
927 vdev_geom_io_start(zio_t *zio)
930 struct g_consumer *cp;
936 switch (zio->io_type) {
939 if (!vdev_readable(vd)) {
940 zio->io_error = SET_ERROR(ENXIO);
944 switch (zio->io_cmd) {
945 case DKIOCFLUSHWRITECACHE:
946 if (zfs_nocacheflush || vdev_geom_bio_flush_disable)
948 if (vd->vdev_nowritecache) {
949 zio->io_error = SET_ERROR(ENOTSUP);
954 zio->io_error = SET_ERROR(ENOTSUP);
961 if (vd->vdev_notrim) {
962 zio->io_error = SET_ERROR(ENOTSUP);
963 } else if (!vdev_geom_bio_delete_disable) {
970 ASSERT(zio->io_type == ZIO_TYPE_READ ||
971 zio->io_type == ZIO_TYPE_WRITE ||
972 zio->io_type == ZIO_TYPE_FREE ||
973 zio->io_type == ZIO_TYPE_IOCTL);
977 zio->io_error = SET_ERROR(ENXIO);
982 bp->bio_caller1 = zio;
983 switch (zio->io_type) {
986 zio->io_target_timestamp = zio_handle_io_delay(zio);
987 bp->bio_cmd = zio->io_type == ZIO_TYPE_READ ? BIO_READ : BIO_WRITE;
988 bp->bio_data = zio->io_data;
989 bp->bio_offset = zio->io_offset;
990 bp->bio_length = zio->io_size;
993 bp->bio_cmd = BIO_DELETE;
995 bp->bio_offset = zio->io_offset;
996 bp->bio_length = zio->io_size;
999 bp->bio_cmd = BIO_FLUSH;
1000 bp->bio_flags |= BIO_ORDERED;
1001 bp->bio_data = NULL;
1002 bp->bio_offset = cp->provider->mediasize;
1006 bp->bio_done = vdev_geom_io_intr;
1008 g_io_request(bp, cp);
1012 vdev_geom_io_done(zio_t *zio)
1017 vdev_geom_hold(vdev_t *vd)
1022 vdev_geom_rele(vdev_t *vd)
1026 vdev_ops_t vdev_geom_ops = {
1035 VDEV_TYPE_DISK, /* name of this vdev type */
1036 B_TRUE /* leaf vdev */