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_set_physpath(struct g_consumer *cp, boolean_t do_null_update)
90 boolean_t needs_update;
93 int error, physpath_len;
95 if (g_access(cp, 1, 0, 0) != 0)
99 physpath_len = MAXPATHLEN;
100 physpath = g_malloc(physpath_len, M_WAITOK|M_ZERO);
101 error = g_io_getattr("GEOM::physpath", cp, &physpath_len, physpath);
102 g_access(cp, -1, 0, 0);
106 /* g_topology lock ensures that vdev has not been closed */
108 old_physpath = vd->vdev_physpath;
109 vd->vdev_physpath = spa_strdup(physpath);
111 if (old_physpath != NULL) {
112 needs_update = (strcmp(old_physpath,
113 vd->vdev_physpath) != 0);
114 spa_strfree(old_physpath);
116 needs_update = do_null_update;
121 * If the physical path changed, update the config.
122 * Only request an update for previously unset physpaths if
123 * requested by the caller.
126 spa_async_request(vd->vdev_spa, SPA_ASYNC_CONFIG_UPDATE);
131 vdev_geom_attrchanged(struct g_consumer *cp, const char *attr)
141 if (strcmp(attr, "GEOM::rotation_rate") == 0) {
142 vdev_geom_set_rotation_rate(vd, cp);
146 if (strcmp(attr, "GEOM::physpath") == 0) {
147 vdev_geom_set_physpath(cp, /*do_null_update*/B_TRUE);
153 vdev_geom_orphan(struct g_consumer *cp)
161 /* Vdev close in progress. Ignore the event. */
166 * Orphan callbacks occur from the GEOM event thread.
167 * Concurrent with this call, new I/O requests may be
168 * working their way through GEOM about to find out
169 * (only once executed by the g_down thread) that we've
170 * been orphaned from our disk provider. These I/Os
171 * must be retired before we can detach our consumer.
172 * This is most easily achieved by acquiring the
173 * SPA ZIO configuration lock as a writer, but doing
174 * so with the GEOM topology lock held would cause
175 * a lock order reversal. Instead, rely on the SPA's
176 * async removal support to invoke a close on this
177 * vdev once it is safe to do so.
179 vd->vdev_remove_wanted = B_TRUE;
180 spa_async_request(vd->vdev_spa, SPA_ASYNC_REMOVE);
183 static struct g_consumer *
184 vdev_geom_attach(struct g_provider *pp, vdev_t *vd)
187 struct g_consumer *cp;
192 ZFS_LOG(1, "Attaching to %s.", pp->name);
194 if (pp->sectorsize > VDEV_PAD_SIZE || !ISP2(pp->sectorsize)) {
195 ZFS_LOG(1, "Failing attach of %s. Incompatible sectorsize %d\n",
196 pp->name, pp->sectorsize);
198 } else if (pp->mediasize < SPA_MINDEVSIZE) {
199 ZFS_LOG(1, "Failing attach of %s. Incompatible mediasize %ju\n",
200 pp->name, pp->mediasize);
204 /* Do we have geom already? No? Create one. */
205 LIST_FOREACH(gp, &zfs_vdev_class.geom, geom) {
206 if (gp->flags & G_GEOM_WITHER)
208 if (strcmp(gp->name, "zfs::vdev") != 0)
213 gp = g_new_geomf(&zfs_vdev_class, "zfs::vdev");
214 gp->orphan = vdev_geom_orphan;
215 gp->attrchanged = vdev_geom_attrchanged;
216 cp = g_new_consumer(gp);
217 error = g_attach(cp, pp);
219 ZFS_LOG(1, "%s(%d): g_attach failed: %d\n", __func__,
221 vdev_geom_detach(cp, B_FALSE);
224 error = g_access(cp, 1, 0, 1);
226 ZFS_LOG(1, "%s(%d): g_access failed: %d\n", __func__,
228 vdev_geom_detach(cp, B_FALSE);
231 ZFS_LOG(1, "Created geom and consumer for %s.", pp->name);
233 /* Check if we are already connected to this provider. */
234 LIST_FOREACH(cp, &gp->consumer, consumer) {
235 if (cp->provider == pp) {
236 ZFS_LOG(1, "Found consumer for %s.", pp->name);
241 cp = g_new_consumer(gp);
242 error = g_attach(cp, pp);
244 ZFS_LOG(1, "%s(%d): g_attach failed: %d\n",
245 __func__, __LINE__, error);
246 vdev_geom_detach(cp, B_FALSE);
249 error = g_access(cp, 1, 0, 1);
251 ZFS_LOG(1, "%s(%d): g_access failed: %d\n",
252 __func__, __LINE__, error);
253 vdev_geom_detach(cp, B_FALSE);
256 ZFS_LOG(1, "Created consumer for %s.", pp->name);
258 error = g_access(cp, 1, 0, 1);
260 ZFS_LOG(1, "%s(%d): g_access failed: %d\n",
261 __func__, __LINE__, error);
264 ZFS_LOG(1, "Used existing consumer for %s.", pp->name);
269 * BUG: cp may already belong to a vdev. This could happen if:
270 * 1) That vdev is a shared spare, or
271 * 2) We are trying to reopen a missing vdev and we are scanning by
272 * guid. In that case, we'll ultimately fail to open this consumer,
273 * but not until after setting the private field.
274 * The solution is to:
275 * 1) Don't set the private field until after the open succeeds, and
276 * 2) Set it to a linked list of vdevs, not just a single vdev
281 vdev_geom_set_physpath(cp, /*do_null_update*/B_FALSE);
284 cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
289 vdev_geom_detach(struct g_consumer *cp, boolean_t open_for_read)
296 ZFS_LOG(1, "Detaching consumer. Provider %s.",
297 cp->provider && cp->provider->name ? cp->provider->name : "NULL");
304 g_access(cp, -1, 0, -1);
305 /* Destroy consumer on last close. */
306 if (cp->acr == 0 && cp->ace == 0) {
308 g_access(cp, 0, -cp->acw, 0);
309 if (cp->provider != NULL) {
310 ZFS_LOG(1, "Destroying consumer to %s.",
311 cp->provider->name ? cp->provider->name : "NULL");
314 g_destroy_consumer(cp);
316 /* Destroy geom if there are no consumers left. */
317 if (LIST_EMPTY(&gp->consumer)) {
318 ZFS_LOG(1, "Destroyed geom %s.", gp->name);
319 g_wither_geom(gp, ENXIO);
324 vdev_geom_close_locked(vdev_t *vd)
326 struct g_consumer *cp;
332 vd->vdev_delayed_close = B_FALSE;
336 ZFS_LOG(1, "Closing access to %s.", cp->provider->name);
338 vdev_geom_detach(cp, B_TRUE);
342 nvlist_get_guids(nvlist_t *list, uint64_t *pguid, uint64_t *vguid)
345 (void) nvlist_lookup_uint64(list, ZPOOL_CONFIG_GUID, vguid);
346 (void) nvlist_lookup_uint64(list, ZPOOL_CONFIG_POOL_GUID, pguid);
350 * Issue one or more bios to the vdev in parallel
351 * cmds, datas, offsets, errors, and sizes are arrays of length ncmds. Each IO
352 * operation is described by parallel entries from each array. There may be
353 * more bios actually issued than entries in the array
356 vdev_geom_io(struct g_consumer *cp, int *cmds, void **datas, off_t *offsets,
357 off_t *sizes, int *errors, int ncmds)
361 off_t off, maxio, s, end;
365 maxio = MAXPHYS - (MAXPHYS % cp->provider->sectorsize);
368 /* How many bios are required for all commands ? */
369 for (i = 0; i < ncmds; i++)
370 n_bios += (sizes[i] + maxio - 1) / maxio;
372 /* Allocate memory for the bios */
373 bios_size = n_bios * sizeof(struct bio*);
374 bios = kmem_zalloc(bios_size, KM_SLEEP);
376 /* Prepare and issue all of the bios */
377 for (i = j = 0; i < ncmds; i++) {
382 ASSERT((off % cp->provider->sectorsize) == 0);
383 ASSERT((s % cp->provider->sectorsize) == 0);
385 for (; off < end; off += maxio, p += maxio, s -= maxio, j++) {
386 bios[j] = g_alloc_bio();
387 bios[j]->bio_cmd = cmds[i];
388 bios[j]->bio_done = NULL;
389 bios[j]->bio_offset = off;
390 bios[j]->bio_length = MIN(s, maxio);
391 bios[j]->bio_data = p;
392 g_io_request(bios[j], cp);
397 /* Wait for all of the bios to complete, and clean them up */
398 for (i = j = 0; i < ncmds; i++) {
403 for (; off < end; off += maxio, s -= maxio, j++) {
404 errors[i] = biowait(bios[j], "vdev_geom_io") || errors[i];
405 g_destroy_bio(bios[j]);
408 kmem_free(bios, bios_size);
412 vdev_geom_read_config(struct g_consumer *cp, nvlist_t **config)
414 struct g_provider *pp;
415 vdev_phys_t *vdev_lists[VDEV_LABELS];
418 uint64_t psize, state, txg;
419 off_t offsets[VDEV_LABELS];
421 off_t sizes[VDEV_LABELS];
422 int cmds[VDEV_LABELS];
423 int errors[VDEV_LABELS];
426 g_topology_assert_not();
429 ZFS_LOG(1, "Reading config from %s...", pp->name);
431 psize = pp->mediasize;
432 psize = P2ALIGN(psize, (uint64_t)sizeof(vdev_label_t));
434 size = sizeof(*vdev_lists[0]) + pp->sectorsize -
435 ((sizeof(*vdev_lists[0]) - 1) % pp->sectorsize) - 1;
437 buflen = sizeof(vdev_lists[0]->vp_nvlist);
440 /* Create all of the IO requests */
441 for (l = 0; l < VDEV_LABELS; l++) {
443 vdev_lists[l] = kmem_alloc(size, KM_SLEEP);
444 offsets[l] = vdev_label_offset(psize, l, 0) + VDEV_SKIP_SIZE;
447 ASSERT(offsets[l] % pp->sectorsize == 0);
450 /* Issue the IO requests */
451 vdev_geom_io(cp, cmds, (void**)vdev_lists, offsets, sizes, errors,
454 /* Parse the labels */
455 for (l = 0; l < VDEV_LABELS; l++) {
459 buf = vdev_lists[l]->vp_nvlist;
461 if (nvlist_unpack(buf, buflen, config, 0) != 0)
464 if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_STATE,
465 &state) != 0 || state > POOL_STATE_L2CACHE) {
466 nvlist_free(*config);
471 if (state != POOL_STATE_SPARE &&
472 state != POOL_STATE_L2CACHE &&
473 (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_TXG,
474 &txg) != 0 || txg == 0)) {
475 nvlist_free(*config);
483 /* Free the label storage */
484 for (l = 0; l < VDEV_LABELS; l++)
485 kmem_free(vdev_lists[l], size);
487 return (*config == NULL ? ENOENT : 0);
491 resize_configs(nvlist_t ***configs, uint64_t *count, uint64_t id)
493 nvlist_t **new_configs;
498 new_configs = kmem_zalloc((id + 1) * sizeof(nvlist_t *),
500 for (i = 0; i < *count; i++)
501 new_configs[i] = (*configs)[i];
502 if (*configs != NULL)
503 kmem_free(*configs, *count * sizeof(void *));
504 *configs = new_configs;
509 process_vdev_config(nvlist_t ***configs, uint64_t *count, nvlist_t *cfg,
510 const char *name, uint64_t* known_pool_guid)
514 uint64_t vdev_guid, known_guid;
515 uint64_t id, txg, known_txg;
519 if (nvlist_lookup_string(cfg, ZPOOL_CONFIG_POOL_NAME, &pname) != 0 ||
520 strcmp(pname, name) != 0)
523 if (nvlist_lookup_uint64(cfg, ZPOOL_CONFIG_POOL_GUID, &pool_guid) != 0)
526 if (nvlist_lookup_uint64(cfg, ZPOOL_CONFIG_TOP_GUID, &vdev_guid) != 0)
529 if (nvlist_lookup_nvlist(cfg, ZPOOL_CONFIG_VDEV_TREE, &vdev_tree) != 0)
532 if (nvlist_lookup_uint64(vdev_tree, ZPOOL_CONFIG_ID, &id) != 0)
535 VERIFY(nvlist_lookup_uint64(cfg, ZPOOL_CONFIG_POOL_TXG, &txg) == 0);
537 if (*known_pool_guid != 0) {
538 if (pool_guid != *known_pool_guid)
541 *known_pool_guid = pool_guid;
543 resize_configs(configs, count, id);
545 if ((*configs)[id] != NULL) {
546 VERIFY(nvlist_lookup_uint64((*configs)[id],
547 ZPOOL_CONFIG_POOL_TXG, &known_txg) == 0);
548 if (txg <= known_txg)
550 nvlist_free((*configs)[id]);
553 (*configs)[id] = cfg;
561 vdev_geom_read_pool_label(const char *name,
562 nvlist_t ***configs, uint64_t *count)
566 struct g_provider *pp;
567 struct g_consumer *zcp;
578 LIST_FOREACH(mp, &g_classes, class) {
579 if (mp == &zfs_vdev_class)
581 LIST_FOREACH(gp, &mp->geom, geom) {
582 if (gp->flags & G_GEOM_WITHER)
584 LIST_FOREACH(pp, &gp->provider, provider) {
585 if (pp->flags & G_PF_WITHER)
587 zcp = vdev_geom_attach(pp, NULL);
591 error = vdev_geom_read_config(zcp, &vdev_cfg);
593 vdev_geom_detach(zcp, B_TRUE);
596 ZFS_LOG(1, "successfully read vdev config");
598 process_vdev_config(configs, count,
599 vdev_cfg, name, &pool_guid);
606 return (*count > 0 ? 0 : ENOENT);
610 vdev_geom_read_guids(struct g_consumer *cp, uint64_t *pguid, uint64_t *vguid)
614 g_topology_assert_not();
618 if (vdev_geom_read_config(cp, &config) == 0) {
619 nvlist_get_guids(config, pguid, vguid);
625 vdev_attach_ok(vdev_t *vd, struct g_provider *pp)
629 struct g_consumer *zcp;
633 zcp = vdev_geom_attach(pp, NULL);
635 ZFS_LOG(1, "Unable to attach tasting instance to %s.",
640 vdev_geom_read_guids(zcp, &pool_guid, &vdev_guid);
642 vdev_geom_detach(zcp, B_TRUE);
645 * Check that the label's vdev guid matches the desired guid. If the
646 * label has a pool guid, check that it matches too. (Inactive spares
647 * and L2ARCs do not have any pool guid in the label.)
649 if ((pool_guid == 0 || pool_guid == spa_guid(vd->vdev_spa)) &&
650 vdev_guid == vd->vdev_guid) {
651 ZFS_LOG(1, "guids match for provider %s.", vd->vdev_path);
654 ZFS_LOG(1, "guid mismatch for provider %s: "
655 "%ju:%ju != %ju:%ju.", vd->vdev_path,
656 (uintmax_t)spa_guid(vd->vdev_spa),
657 (uintmax_t)vd->vdev_guid,
658 (uintmax_t)pool_guid, (uintmax_t)vdev_guid);
663 static struct g_consumer *
664 vdev_geom_attach_by_guids(vdev_t *vd)
668 struct g_provider *pp;
669 struct g_consumer *cp;
674 LIST_FOREACH(mp, &g_classes, class) {
675 if (mp == &zfs_vdev_class)
677 LIST_FOREACH(gp, &mp->geom, geom) {
678 if (gp->flags & G_GEOM_WITHER)
680 LIST_FOREACH(pp, &gp->provider, provider) {
681 if (!vdev_attach_ok(vd, pp))
683 cp = vdev_geom_attach(pp, vd);
685 printf("ZFS WARNING: Unable to "
686 "attach to %s.\n", pp->name);
701 static struct g_consumer *
702 vdev_geom_open_by_guids(vdev_t *vd)
704 struct g_consumer *cp;
710 ZFS_LOG(1, "Searching by guids [%ju:%ju].",
711 (uintmax_t)spa_guid(vd->vdev_spa), (uintmax_t)vd->vdev_guid);
712 cp = vdev_geom_attach_by_guids(vd);
714 len = strlen(cp->provider->name) + strlen("/dev/") + 1;
715 buf = kmem_alloc(len, KM_SLEEP);
717 snprintf(buf, len, "/dev/%s", cp->provider->name);
718 spa_strfree(vd->vdev_path);
721 ZFS_LOG(1, "Attach by guid [%ju:%ju] succeeded, provider %s.",
722 (uintmax_t)spa_guid(vd->vdev_spa),
723 (uintmax_t)vd->vdev_guid, vd->vdev_path);
725 ZFS_LOG(1, "Search by guid [%ju:%ju] failed.",
726 (uintmax_t)spa_guid(vd->vdev_spa),
727 (uintmax_t)vd->vdev_guid);
733 static struct g_consumer *
734 vdev_geom_open_by_path(vdev_t *vd, int check_guid)
736 struct g_provider *pp;
737 struct g_consumer *cp;
742 pp = g_provider_by_name(vd->vdev_path + sizeof("/dev/") - 1);
744 ZFS_LOG(1, "Found provider by name %s.", vd->vdev_path);
745 if (!check_guid || vdev_attach_ok(vd, pp))
746 cp = vdev_geom_attach(pp, vd);
753 vdev_geom_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
754 uint64_t *logical_ashift, uint64_t *physical_ashift)
756 struct g_provider *pp;
757 struct g_consumer *cp;
761 /* Set the TLS to indicate downstack that we should not access zvols*/
762 VERIFY(tsd_set(zfs_geom_probe_vdev_key, vd) == 0);
765 * We must have a pathname, and it must be absolute.
767 if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
768 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
778 if (vd->vdev_spa->spa_splitting_newspa ||
779 (vd->vdev_prevstate == VDEV_STATE_UNKNOWN &&
780 vd->vdev_spa->spa_load_state == SPA_LOAD_NONE)) {
782 * We are dealing with a vdev that hasn't been previously
783 * opened (since boot), and we are not loading an
784 * existing pool configuration. This looks like a
785 * vdev add operation to a new or existing pool.
786 * Assume the user knows what he/she is doing and find
787 * GEOM provider by its name, ignoring GUID mismatches.
789 * XXPOLICY: It would be safer to only allow a device
790 * that is unlabeled or labeled but missing
791 * GUID information to be opened in this fashion,
792 * unless we are doing a split, in which case we
793 * should allow any guid.
795 cp = vdev_geom_open_by_path(vd, 0);
798 * Try using the recorded path for this device, but only
799 * accept it if its label data contains the expected GUIDs.
801 cp = vdev_geom_open_by_path(vd, 1);
804 * The device at vd->vdev_path doesn't have the
805 * expected GUIDs. The disks might have merely
806 * moved around so try all other GEOM providers
807 * to find one with the right GUIDs.
809 cp = vdev_geom_open_by_guids(vd);
813 /* Clear the TLS now that tasting is done */
814 VERIFY(tsd_set(zfs_geom_probe_vdev_key, NULL) == 0);
817 ZFS_LOG(1, "Provider %s not found.", vd->vdev_path);
819 } else if (cp->provider->sectorsize > VDEV_PAD_SIZE ||
820 !ISP2(cp->provider->sectorsize)) {
821 ZFS_LOG(1, "Provider %s has unsupported sectorsize.",
824 vdev_geom_close_locked(vd);
827 } else if (cp->acw == 0 && (spa_mode(vd->vdev_spa) & FWRITE) != 0) {
830 for (i = 0; i < 5; i++) {
831 error = g_access(cp, 0, 1, 0);
835 tsleep(vd, 0, "vdev", hz / 2);
839 printf("ZFS WARNING: Unable to open %s for writing (error=%d).\n",
840 vd->vdev_path, error);
841 vdev_geom_close_locked(vd);
846 /* Fetch initial physical path information for this device. */
848 vdev_geom_attrchanged(cp, "GEOM::physpath");
853 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
859 * Determine the actual size of the device.
861 *max_psize = *psize = pp->mediasize;
864 * Determine the device's minimum transfer size and preferred
867 *logical_ashift = highbit(MAX(pp->sectorsize, SPA_MINBLOCKSIZE)) - 1;
868 *physical_ashift = 0;
869 if (pp->stripesize > (1 << *logical_ashift) && ISP2(pp->stripesize) &&
870 pp->stripesize <= (1 << SPA_MAXASHIFT) && pp->stripeoffset == 0)
871 *physical_ashift = highbit(pp->stripesize) - 1;
874 * Clear the nowritecache settings, so that on a vdev_reopen()
877 vd->vdev_nowritecache = B_FALSE;
880 * Determine the device's rotation rate.
882 vdev_geom_set_rotation_rate(vd, cp);
888 vdev_geom_close(vdev_t *vd)
893 vdev_geom_close_locked(vd);
899 vdev_geom_io_intr(struct bio *bp)
904 zio = bp->bio_caller1;
906 zio->io_error = bp->bio_error;
907 if (zio->io_error == 0 && bp->bio_resid != 0)
908 zio->io_error = SET_ERROR(EIO);
910 switch(zio->io_error) {
913 * If we get ENOTSUP for BIO_FLUSH or BIO_DELETE we know
914 * that future attempts will never succeed. In this case
915 * we set a persistent flag so that we don't bother with
916 * requests in the future.
918 switch(bp->bio_cmd) {
920 vd->vdev_nowritecache = B_TRUE;
923 vd->vdev_notrim = B_TRUE;
928 if (!vd->vdev_remove_wanted) {
930 * If provider's error is set we assume it is being
933 if (bp->bio_to->error != 0) {
934 vd->vdev_remove_wanted = B_TRUE;
935 spa_async_request(zio->io_spa,
937 } else if (!vd->vdev_delayed_close) {
938 vd->vdev_delayed_close = B_TRUE;
944 zio_delay_interrupt(zio);
948 vdev_geom_io_start(zio_t *zio)
951 struct g_consumer *cp;
957 switch (zio->io_type) {
960 if (!vdev_readable(vd)) {
961 zio->io_error = SET_ERROR(ENXIO);
965 switch (zio->io_cmd) {
966 case DKIOCFLUSHWRITECACHE:
967 if (zfs_nocacheflush || vdev_geom_bio_flush_disable)
969 if (vd->vdev_nowritecache) {
970 zio->io_error = SET_ERROR(ENOTSUP);
975 zio->io_error = SET_ERROR(ENOTSUP);
982 if (vd->vdev_notrim) {
983 zio->io_error = SET_ERROR(ENOTSUP);
984 } else if (!vdev_geom_bio_delete_disable) {
991 ASSERT(zio->io_type == ZIO_TYPE_READ ||
992 zio->io_type == ZIO_TYPE_WRITE ||
993 zio->io_type == ZIO_TYPE_FREE ||
994 zio->io_type == ZIO_TYPE_IOCTL);
998 zio->io_error = SET_ERROR(ENXIO);
1003 bp->bio_caller1 = zio;
1004 switch (zio->io_type) {
1006 case ZIO_TYPE_WRITE:
1007 zio->io_target_timestamp = zio_handle_io_delay(zio);
1008 bp->bio_cmd = zio->io_type == ZIO_TYPE_READ ? BIO_READ : BIO_WRITE;
1009 bp->bio_data = zio->io_data;
1010 bp->bio_offset = zio->io_offset;
1011 bp->bio_length = zio->io_size;
1014 bp->bio_cmd = BIO_DELETE;
1015 bp->bio_data = NULL;
1016 bp->bio_offset = zio->io_offset;
1017 bp->bio_length = zio->io_size;
1019 case ZIO_TYPE_IOCTL:
1020 bp->bio_cmd = BIO_FLUSH;
1021 bp->bio_flags |= BIO_ORDERED;
1022 bp->bio_data = NULL;
1023 bp->bio_offset = cp->provider->mediasize;
1027 bp->bio_done = vdev_geom_io_intr;
1029 g_io_request(bp, cp);
1033 vdev_geom_io_done(zio_t *zio)
1038 vdev_geom_hold(vdev_t *vd)
1043 vdev_geom_rele(vdev_t *vd)
1047 vdev_ops_t vdev_geom_ops = {
1056 VDEV_TYPE_DISK, /* name of this vdev type */
1057 B_TRUE /* leaf vdev */