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 = B_FALSE;
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", __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 from %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 for %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 * Issue one or more bios to the vdev in parallel
343 * cmds, datas, offsets, errors, and sizes are arrays of length ncmds. Each IO
344 * operation is described by parallel entries from each array. There may be
345 * more bios actually issued than entries in the array
348 vdev_geom_io(struct g_consumer *cp, int *cmds, void **datas, off_t *offsets,
349 off_t *sizes, int *errors, int ncmds)
353 off_t off, maxio, s, end;
357 maxio = MAXPHYS - (MAXPHYS % cp->provider->sectorsize);
360 /* How many bios are required for all commands ? */
361 for (i = 0; i < ncmds; i++)
362 n_bios += (sizes[i] + maxio - 1) / maxio;
364 /* Allocate memory for the bios */
365 bios_size = n_bios * sizeof(struct bio*);
366 bios = kmem_zalloc(bios_size, KM_SLEEP);
368 /* Prepare and issue all of the bios */
369 for (i = j = 0; i < ncmds; i++) {
374 ASSERT((off % cp->provider->sectorsize) == 0);
375 ASSERT((s % cp->provider->sectorsize) == 0);
377 for (; off < end; off += maxio, p += maxio, s -= maxio, j++) {
378 bios[j] = g_alloc_bio();
379 bios[j]->bio_cmd = cmds[i];
380 bios[j]->bio_done = NULL;
381 bios[j]->bio_offset = off;
382 bios[j]->bio_length = MIN(s, maxio);
383 bios[j]->bio_data = p;
384 g_io_request(bios[j], cp);
389 /* Wait for all of the bios to complete, and clean them up */
390 for (i = j = 0; i < ncmds; i++) {
395 for (; off < end; off += maxio, s -= maxio, j++) {
396 errors[i] = biowait(bios[j], "vdev_geom_io") || errors[i];
397 g_destroy_bio(bios[j]);
400 kmem_free(bios, bios_size);
404 vdev_geom_read_config(struct g_consumer *cp, nvlist_t **config)
406 struct g_provider *pp;
407 vdev_phys_t *vdev_lists[VDEV_LABELS];
410 uint64_t psize, state, txg;
411 off_t offsets[VDEV_LABELS];
413 off_t sizes[VDEV_LABELS];
414 int cmds[VDEV_LABELS];
415 int errors[VDEV_LABELS];
418 g_topology_assert_not();
421 ZFS_LOG(1, "Reading config from %s...", pp->name);
423 psize = pp->mediasize;
424 psize = P2ALIGN(psize, (uint64_t)sizeof(vdev_label_t));
426 size = sizeof(*vdev_lists[0]) + pp->sectorsize -
427 ((sizeof(*vdev_lists[0]) - 1) % pp->sectorsize) - 1;
429 buflen = sizeof(vdev_lists[0]->vp_nvlist);
432 /* Create all of the IO requests */
433 for (l = 0; l < VDEV_LABELS; l++) {
435 vdev_lists[l] = kmem_alloc(size, KM_SLEEP);
436 offsets[l] = vdev_label_offset(psize, l, 0) + VDEV_SKIP_SIZE;
439 ASSERT(offsets[l] % pp->sectorsize == 0);
442 /* Issue the IO requests */
443 vdev_geom_io(cp, cmds, (void**)vdev_lists, offsets, sizes, errors,
446 /* Parse the labels */
447 for (l = 0; l < VDEV_LABELS; l++) {
451 buf = vdev_lists[l]->vp_nvlist;
453 if (nvlist_unpack(buf, buflen, config, 0) != 0)
456 if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_STATE,
457 &state) != 0 || state > POOL_STATE_L2CACHE) {
458 nvlist_free(*config);
463 if (state != POOL_STATE_SPARE &&
464 state != POOL_STATE_L2CACHE &&
465 (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_TXG,
466 &txg) != 0 || txg == 0)) {
467 nvlist_free(*config);
475 /* Free the label storage */
476 for (l = 0; l < VDEV_LABELS; l++)
477 kmem_free(vdev_lists[l], size);
479 return (*config == NULL ? ENOENT : 0);
483 resize_configs(nvlist_t ***configs, uint64_t *count, uint64_t id)
485 nvlist_t **new_configs;
490 new_configs = kmem_zalloc((id + 1) * sizeof(nvlist_t *),
492 for (i = 0; i < *count; i++)
493 new_configs[i] = (*configs)[i];
494 if (*configs != NULL)
495 kmem_free(*configs, *count * sizeof(void *));
496 *configs = new_configs;
501 process_vdev_config(nvlist_t ***configs, uint64_t *count, nvlist_t *cfg,
502 const char *name, uint64_t* known_pool_guid)
506 uint64_t vdev_guid, known_guid;
507 uint64_t id, txg, known_txg;
511 if (nvlist_lookup_string(cfg, ZPOOL_CONFIG_POOL_NAME, &pname) != 0 ||
512 strcmp(pname, name) != 0)
515 if (nvlist_lookup_uint64(cfg, ZPOOL_CONFIG_POOL_GUID, &pool_guid) != 0)
518 if (nvlist_lookup_uint64(cfg, ZPOOL_CONFIG_TOP_GUID, &vdev_guid) != 0)
521 if (nvlist_lookup_nvlist(cfg, ZPOOL_CONFIG_VDEV_TREE, &vdev_tree) != 0)
524 if (nvlist_lookup_uint64(vdev_tree, ZPOOL_CONFIG_ID, &id) != 0)
527 VERIFY(nvlist_lookup_uint64(cfg, ZPOOL_CONFIG_POOL_TXG, &txg) == 0);
529 if (*known_pool_guid != 0) {
530 if (pool_guid != *known_pool_guid)
533 *known_pool_guid = pool_guid;
535 resize_configs(configs, count, id);
537 if ((*configs)[id] != NULL) {
538 VERIFY(nvlist_lookup_uint64((*configs)[id],
539 ZPOOL_CONFIG_POOL_TXG, &known_txg) == 0);
540 if (txg <= known_txg)
542 nvlist_free((*configs)[id]);
545 (*configs)[id] = cfg;
553 vdev_geom_read_pool_label(const char *name,
554 nvlist_t ***configs, uint64_t *count)
558 struct g_provider *pp;
559 struct g_consumer *zcp;
570 LIST_FOREACH(mp, &g_classes, class) {
571 if (mp == &zfs_vdev_class)
573 LIST_FOREACH(gp, &mp->geom, geom) {
574 if (gp->flags & G_GEOM_WITHER)
576 LIST_FOREACH(pp, &gp->provider, provider) {
577 if (pp->flags & G_PF_WITHER)
579 zcp = vdev_geom_attach(pp, NULL);
583 error = vdev_geom_read_config(zcp, &vdev_cfg);
585 vdev_geom_detach(zcp, B_TRUE);
588 ZFS_LOG(1, "successfully read vdev config");
590 process_vdev_config(configs, count,
591 vdev_cfg, name, &pool_guid);
598 return (*count > 0 ? 0 : ENOENT);
608 vdev_attach_ok(vdev_t *vd, struct g_provider *pp)
611 uint64_t pool_guid, top_guid, vdev_guid;
612 struct g_consumer *cp;
614 cp = vdev_geom_attach(pp, NULL);
616 ZFS_LOG(1, "Unable to attach tasting instance to %s.",
621 if (vdev_geom_read_config(cp, &config) != 0) {
623 vdev_geom_detach(cp, B_TRUE);
624 ZFS_LOG(1, "Unable to read config from %s.", pp->name);
628 vdev_geom_detach(cp, B_TRUE);
631 (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &pool_guid);
633 (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_TOP_GUID, &top_guid);
635 (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_GUID, &vdev_guid);
639 * Check that the label's pool guid matches the desired guid.
640 * Inactive spares and L2ARCs do not have any pool guid in the label.
642 if (pool_guid != 0 && pool_guid != spa_guid(vd->vdev_spa)) {
643 ZFS_LOG(1, "pool guid mismatch for provider %s: %ju != %ju.",
645 (uintmax_t)spa_guid(vd->vdev_spa), (uintmax_t)pool_guid);
650 * Check that the label's vdev guid matches the desired guid.
651 * The second condition handles possible race on vdev detach, when
652 * remaining vdev receives GUID of destroyed top level mirror vdev.
654 if (vdev_guid == vd->vdev_guid) {
655 ZFS_LOG(1, "guids match for provider %s.", pp->name);
657 } else if (top_guid == vd->vdev_guid && vd == vd->vdev_top) {
658 ZFS_LOG(1, "top vdev guid match for provider %s.", pp->name);
661 ZFS_LOG(1, "vdev guid mismatch for provider %s: %ju != %ju.",
662 pp->name, (uintmax_t)vd->vdev_guid, (uintmax_t)vdev_guid);
666 static struct g_consumer *
667 vdev_geom_attach_by_guids(vdev_t *vd)
671 struct g_provider *pp;
672 struct g_consumer *cp;
678 LIST_FOREACH(mp, &g_classes, class) {
679 if (mp == &zfs_vdev_class)
681 LIST_FOREACH(gp, &mp->geom, geom) {
682 if (gp->flags & G_GEOM_WITHER)
684 LIST_FOREACH(pp, &gp->provider, provider) {
685 m = vdev_attach_ok(vd, pp);
690 vdev_geom_detach(cp, B_TRUE);
694 cp = vdev_geom_attach(pp, vd);
696 printf("ZFS WARNING: Unable to "
697 "attach to %s.\n", pp->name);
708 static struct g_consumer *
709 vdev_geom_open_by_guids(vdev_t *vd)
711 struct g_consumer *cp;
717 ZFS_LOG(1, "Searching by guids [%ju:%ju].",
718 (uintmax_t)spa_guid(vd->vdev_spa), (uintmax_t)vd->vdev_guid);
719 cp = vdev_geom_attach_by_guids(vd);
721 len = strlen(cp->provider->name) + strlen("/dev/") + 1;
722 buf = kmem_alloc(len, KM_SLEEP);
724 snprintf(buf, len, "/dev/%s", cp->provider->name);
725 spa_strfree(vd->vdev_path);
728 ZFS_LOG(1, "Attach by guid [%ju:%ju] succeeded, provider %s.",
729 (uintmax_t)spa_guid(vd->vdev_spa),
730 (uintmax_t)vd->vdev_guid, vd->vdev_path);
732 ZFS_LOG(1, "Search by guid [%ju:%ju] failed.",
733 (uintmax_t)spa_guid(vd->vdev_spa),
734 (uintmax_t)vd->vdev_guid);
740 static struct g_consumer *
741 vdev_geom_open_by_path(vdev_t *vd, int check_guid)
743 struct g_provider *pp;
744 struct g_consumer *cp;
749 pp = g_provider_by_name(vd->vdev_path + sizeof("/dev/") - 1);
751 ZFS_LOG(1, "Found provider by name %s.", vd->vdev_path);
752 if (!check_guid || vdev_attach_ok(vd, pp) == FULL_MATCH)
753 cp = vdev_geom_attach(pp, vd);
760 vdev_geom_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
761 uint64_t *logical_ashift, uint64_t *physical_ashift)
763 struct g_provider *pp;
764 struct g_consumer *cp;
768 /* Set the TLS to indicate downstack that we should not access zvols*/
769 VERIFY(tsd_set(zfs_geom_probe_vdev_key, vd) == 0);
772 * We must have a pathname, and it must be absolute.
774 if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
775 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
780 * Reopen the device if it's not currently open. Otherwise,
781 * just update the physical size of the device.
783 if ((cp = vd->vdev_tsd) != NULL) {
784 ASSERT(vd->vdev_reopening);
792 if (vd->vdev_spa->spa_splitting_newspa ||
793 (vd->vdev_prevstate == VDEV_STATE_UNKNOWN &&
794 vd->vdev_spa->spa_load_state == SPA_LOAD_NONE ||
795 vd->vdev_spa->spa_load_state == SPA_LOAD_CREATE)) {
797 * We are dealing with a vdev that hasn't been previously
798 * opened (since boot), and we are not loading an
799 * existing pool configuration. This looks like a
800 * vdev add operation to a new or existing pool.
801 * Assume the user knows what he/she is doing and find
802 * GEOM provider by its name, ignoring GUID mismatches.
804 * XXPOLICY: It would be safer to only allow a device
805 * that is unlabeled or labeled but missing
806 * GUID information to be opened in this fashion,
807 * unless we are doing a split, in which case we
808 * should allow any guid.
810 cp = vdev_geom_open_by_path(vd, 0);
813 * Try using the recorded path for this device, but only
814 * accept it if its label data contains the expected GUIDs.
816 cp = vdev_geom_open_by_path(vd, 1);
819 * The device at vd->vdev_path doesn't have the
820 * expected GUIDs. The disks might have merely
821 * moved around so try all other GEOM providers
822 * to find one with the right GUIDs.
824 cp = vdev_geom_open_by_guids(vd);
828 /* Clear the TLS now that tasting is done */
829 VERIFY(tsd_set(zfs_geom_probe_vdev_key, NULL) == 0);
832 ZFS_LOG(1, "Provider %s not found.", vd->vdev_path);
834 } else if (cp->provider->sectorsize > VDEV_PAD_SIZE ||
835 !ISP2(cp->provider->sectorsize)) {
836 ZFS_LOG(1, "Provider %s has unsupported sectorsize.",
839 vdev_geom_close_locked(vd);
842 } else if (cp->acw == 0 && (spa_mode(vd->vdev_spa) & FWRITE) != 0) {
845 for (i = 0; i < 5; i++) {
846 error = g_access(cp, 0, 1, 0);
850 tsleep(vd, 0, "vdev", hz / 2);
854 printf("ZFS WARNING: Unable to open %s for writing (error=%d).\n",
855 vd->vdev_path, error);
856 vdev_geom_close_locked(vd);
861 /* Fetch initial physical path information for this device. */
863 vdev_geom_attrchanged(cp, "GEOM::physpath");
868 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
875 * Determine the actual size of the device.
877 *max_psize = *psize = pp->mediasize;
880 * Determine the device's minimum transfer size and preferred
883 *logical_ashift = highbit(MAX(pp->sectorsize, SPA_MINBLOCKSIZE)) - 1;
884 *physical_ashift = 0;
885 if (pp->stripesize > (1 << *logical_ashift) && ISP2(pp->stripesize) &&
886 pp->stripesize <= (1 << SPA_MAXASHIFT) && pp->stripeoffset == 0)
887 *physical_ashift = highbit(pp->stripesize) - 1;
890 * Clear the nowritecache settings, so that on a vdev_reopen()
893 vd->vdev_nowritecache = B_FALSE;
896 * Determine the device's rotation rate.
898 vdev_geom_set_rotation_rate(vd, cp);
904 vdev_geom_close(vdev_t *vd)
907 if (vd->vdev_reopening)
912 vdev_geom_close_locked(vd);
918 vdev_geom_io_intr(struct bio *bp)
923 zio = bp->bio_caller1;
925 zio->io_error = bp->bio_error;
926 if (zio->io_error == 0 && bp->bio_resid != 0)
927 zio->io_error = SET_ERROR(EIO);
929 switch(zio->io_error) {
932 * If we get ENOTSUP for BIO_FLUSH or BIO_DELETE we know
933 * that future attempts will never succeed. In this case
934 * we set a persistent flag so that we don't bother with
935 * requests in the future.
937 switch(bp->bio_cmd) {
939 vd->vdev_nowritecache = B_TRUE;
942 vd->vdev_notrim = B_TRUE;
947 if (!vd->vdev_remove_wanted) {
949 * If provider's error is set we assume it is being
952 if (bp->bio_to->error != 0) {
953 vd->vdev_remove_wanted = B_TRUE;
954 spa_async_request(zio->io_spa,
956 } else if (!vd->vdev_delayed_close) {
957 vd->vdev_delayed_close = B_TRUE;
963 zio_delay_interrupt(zio);
967 vdev_geom_io_start(zio_t *zio)
970 struct g_consumer *cp;
976 switch (zio->io_type) {
979 if (!vdev_readable(vd)) {
980 zio->io_error = SET_ERROR(ENXIO);
984 switch (zio->io_cmd) {
985 case DKIOCFLUSHWRITECACHE:
986 if (zfs_nocacheflush || vdev_geom_bio_flush_disable)
988 if (vd->vdev_nowritecache) {
989 zio->io_error = SET_ERROR(ENOTSUP);
994 zio->io_error = SET_ERROR(ENOTSUP);
1001 if (vd->vdev_notrim) {
1002 zio->io_error = SET_ERROR(ENOTSUP);
1003 } else if (!vdev_geom_bio_delete_disable) {
1010 ASSERT(zio->io_type == ZIO_TYPE_READ ||
1011 zio->io_type == ZIO_TYPE_WRITE ||
1012 zio->io_type == ZIO_TYPE_FREE ||
1013 zio->io_type == ZIO_TYPE_IOCTL);
1017 zio->io_error = SET_ERROR(ENXIO);
1022 bp->bio_caller1 = zio;
1023 switch (zio->io_type) {
1025 case ZIO_TYPE_WRITE:
1026 zio->io_target_timestamp = zio_handle_io_delay(zio);
1027 bp->bio_cmd = zio->io_type == ZIO_TYPE_READ ? BIO_READ : BIO_WRITE;
1028 bp->bio_data = zio->io_data;
1029 bp->bio_offset = zio->io_offset;
1030 bp->bio_length = zio->io_size;
1033 bp->bio_cmd = BIO_DELETE;
1034 bp->bio_data = NULL;
1035 bp->bio_offset = zio->io_offset;
1036 bp->bio_length = zio->io_size;
1038 case ZIO_TYPE_IOCTL:
1039 bp->bio_cmd = BIO_FLUSH;
1040 bp->bio_flags |= BIO_ORDERED;
1041 bp->bio_data = NULL;
1042 bp->bio_offset = cp->provider->mediasize;
1046 bp->bio_done = vdev_geom_io_intr;
1048 g_io_request(bp, cp);
1052 vdev_geom_io_done(zio_t *zio)
1057 vdev_geom_hold(vdev_t *vd)
1062 vdev_geom_rele(vdev_t *vd)
1066 vdev_ops_t vdev_geom_ops = {
1075 VDEV_TYPE_DISK, /* name of this vdev type */
1076 B_TRUE /* leaf vdev */