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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
24 * Copyright (c) 2013 Joyent, Inc. All rights reserved.
27 #include <sys/zfs_context.h>
28 #include <sys/spa_impl.h>
29 #include <sys/refcount.h>
30 #include <sys/vdev_disk.h>
31 #include <sys/vdev_impl.h>
32 #include <sys/fs/zfs.h>
34 #include <sys/sunldi.h>
35 #include <sys/efi_partition.h>
36 #include <sys/fm/fs/zfs.h>
39 * Virtual device vector for disks.
42 extern ldi_ident_t zfs_li;
44 static void vdev_disk_close(vdev_t *);
46 typedef struct vdev_disk_ldi_cb {
48 ldi_callback_id_t lcb_id;
52 vdev_disk_alloc(vdev_t *vd)
56 dvd = vd->vdev_tsd = kmem_zalloc(sizeof (vdev_disk_t), KM_SLEEP);
58 * Create the LDI event callback list.
60 list_create(&dvd->vd_ldi_cbs, sizeof (vdev_disk_ldi_cb_t),
61 offsetof(vdev_disk_ldi_cb_t, lcb_next));
65 vdev_disk_free(vdev_t *vd)
67 vdev_disk_t *dvd = vd->vdev_tsd;
68 vdev_disk_ldi_cb_t *lcb;
74 * We have already closed the LDI handle. Clean up the LDI event
75 * callbacks and free vd->vdev_tsd.
77 while ((lcb = list_head(&dvd->vd_ldi_cbs)) != NULL) {
78 list_remove(&dvd->vd_ldi_cbs, lcb);
79 (void) ldi_ev_remove_callbacks(lcb->lcb_id);
80 kmem_free(lcb, sizeof (vdev_disk_ldi_cb_t));
82 list_destroy(&dvd->vd_ldi_cbs);
83 kmem_free(dvd, sizeof (vdev_disk_t));
89 vdev_disk_off_notify(ldi_handle_t lh, ldi_ev_cookie_t ecookie, void *arg,
92 vdev_t *vd = (vdev_t *)arg;
93 vdev_disk_t *dvd = vd->vdev_tsd;
96 * Ignore events other than offline.
98 if (strcmp(ldi_ev_get_type(ecookie), LDI_EV_OFFLINE) != 0)
99 return (LDI_EV_SUCCESS);
102 * All LDI handles must be closed for the state change to succeed, so
103 * call on vdev_disk_close() to do this.
105 * We inform vdev_disk_close that it is being called from offline
106 * notify context so it will defer cleanup of LDI event callbacks and
107 * freeing of vd->vdev_tsd to the offline finalize or a reopen.
109 dvd->vd_ldi_offline = B_TRUE;
113 * Now that the device is closed, request that the spa_async_thread
114 * mark the device as REMOVED and notify FMA of the removal.
116 zfs_post_remove(vd->vdev_spa, vd);
117 vd->vdev_remove_wanted = B_TRUE;
118 spa_async_request(vd->vdev_spa, SPA_ASYNC_REMOVE);
120 return (LDI_EV_SUCCESS);
125 vdev_disk_off_finalize(ldi_handle_t lh, ldi_ev_cookie_t ecookie,
126 int ldi_result, void *arg, void *ev_data)
128 vdev_t *vd = (vdev_t *)arg;
131 * Ignore events other than offline.
133 if (strcmp(ldi_ev_get_type(ecookie), LDI_EV_OFFLINE) != 0)
137 * We have already closed the LDI handle in notify.
138 * Clean up the LDI event callbacks and free vd->vdev_tsd.
143 * Request that the vdev be reopened if the offline state change was
146 if (ldi_result != LDI_EV_SUCCESS) {
147 vd->vdev_probe_wanted = B_TRUE;
148 spa_async_request(vd->vdev_spa, SPA_ASYNC_PROBE);
152 static ldi_ev_callback_t vdev_disk_off_callb = {
153 .cb_vers = LDI_EV_CB_VERS,
154 .cb_notify = vdev_disk_off_notify,
155 .cb_finalize = vdev_disk_off_finalize
160 vdev_disk_dgrd_finalize(ldi_handle_t lh, ldi_ev_cookie_t ecookie,
161 int ldi_result, void *arg, void *ev_data)
163 vdev_t *vd = (vdev_t *)arg;
166 * Ignore events other than degrade.
168 if (strcmp(ldi_ev_get_type(ecookie), LDI_EV_DEGRADE) != 0)
172 * Degrade events always succeed. Mark the vdev as degraded.
173 * This status is purely informative for the user.
175 (void) vdev_degrade(vd->vdev_spa, vd->vdev_guid, 0);
178 static ldi_ev_callback_t vdev_disk_dgrd_callb = {
179 .cb_vers = LDI_EV_CB_VERS,
181 .cb_finalize = vdev_disk_dgrd_finalize
185 vdev_disk_hold(vdev_t *vd)
190 ASSERT(spa_config_held(vd->vdev_spa, SCL_STATE, RW_WRITER));
193 * We must have a pathname, and it must be absolute.
195 if (vd->vdev_path == NULL || vd->vdev_path[0] != '/')
199 * Only prefetch path and devid info if the device has
202 if (vd->vdev_tsd != NULL)
205 if (vd->vdev_wholedisk == -1ULL) {
206 size_t len = strlen(vd->vdev_path) + 3;
207 char *buf = kmem_alloc(len, KM_SLEEP);
209 (void) snprintf(buf, len, "%ss0", vd->vdev_path);
211 (void) ldi_vp_from_name(buf, &vd->vdev_name_vp);
215 if (vd->vdev_name_vp == NULL)
216 (void) ldi_vp_from_name(vd->vdev_path, &vd->vdev_name_vp);
218 if (vd->vdev_devid != NULL &&
219 ddi_devid_str_decode(vd->vdev_devid, &devid, &minor) == 0) {
220 (void) ldi_vp_from_devid(devid, minor, &vd->vdev_devid_vp);
221 ddi_devid_str_free(minor);
222 ddi_devid_free(devid);
227 vdev_disk_rele(vdev_t *vd)
229 ASSERT(spa_config_held(vd->vdev_spa, SCL_STATE, RW_WRITER));
231 if (vd->vdev_name_vp) {
232 VN_RELE_ASYNC(vd->vdev_name_vp,
233 dsl_pool_vnrele_taskq(vd->vdev_spa->spa_dsl_pool));
234 vd->vdev_name_vp = NULL;
236 if (vd->vdev_devid_vp) {
237 VN_RELE_ASYNC(vd->vdev_devid_vp,
238 dsl_pool_vnrele_taskq(vd->vdev_spa->spa_dsl_pool));
239 vd->vdev_devid_vp = NULL;
244 vdev_disk_get_space(vdev_t *vd, uint64_t capacity, uint_t blksz)
246 ASSERT(vd->vdev_wholedisk);
248 vdev_disk_t *dvd = vd->vdev_tsd;
251 uint64_t avail_space = 0;
252 int efisize = EFI_LABEL_SIZE * 2;
254 dk_ioc.dki_data = kmem_alloc(efisize, KM_SLEEP);
256 dk_ioc.dki_length = efisize;
257 dk_ioc.dki_data_64 = (uint64_t)(uintptr_t)dk_ioc.dki_data;
258 efi = dk_ioc.dki_data;
260 if (ldi_ioctl(dvd->vd_lh, DKIOCGETEFI, (intptr_t)&dk_ioc,
261 FKIOCTL, kcred, NULL) == 0) {
262 uint64_t efi_altern_lba = LE_64(efi->efi_gpt_AlternateLBA);
264 if (capacity > efi_altern_lba)
265 avail_space = (capacity - efi_altern_lba) * blksz;
267 kmem_free(dk_ioc.dki_data, efisize);
268 return (avail_space);
272 vdev_disk_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize,
275 spa_t *spa = vd->vdev_spa;
276 vdev_disk_t *dvd = vd->vdev_tsd;
277 ldi_ev_cookie_t ecookie;
278 vdev_disk_ldi_cb_t *lcb;
279 struct dk_minfo_ext dkmext;
283 boolean_t validate_devid = B_FALSE;
287 * We must have a pathname, and it must be absolute.
289 if (vd->vdev_path == NULL || vd->vdev_path[0] != '/') {
290 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
291 return (SET_ERROR(EINVAL));
295 * Reopen the device if it's not currently open. Otherwise,
296 * just update the physical size of the device.
299 if (dvd->vd_ldi_offline && dvd->vd_lh == NULL) {
301 * If we are opening a device in its offline notify
302 * context, the LDI handle was just closed. Clean
303 * up the LDI event callbacks and free vd->vdev_tsd.
307 ASSERT(vd->vdev_reopening);
313 * Create vd->vdev_tsd.
319 * When opening a disk device, we want to preserve the user's original
320 * intent. We always want to open the device by the path the user gave
321 * us, even if it is one of multiple paths to the save device. But we
322 * also want to be able to survive disks being removed/recabled.
323 * Therefore the sequence of opening devices is:
325 * 1. Try opening the device by path. For legacy pools without the
326 * 'whole_disk' property, attempt to fix the path by appending 's0'.
328 * 2. If the devid of the device matches the stored value, return
331 * 3. Otherwise, the device may have moved. Try opening the device
332 * by the devid instead.
334 if (vd->vdev_devid != NULL) {
335 if (ddi_devid_str_decode(vd->vdev_devid, &dvd->vd_devid,
336 &dvd->vd_minor) != 0) {
337 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
338 return (SET_ERROR(EINVAL));
342 error = EINVAL; /* presume failure */
344 if (vd->vdev_path != NULL) {
346 if (vd->vdev_wholedisk == -1ULL) {
347 size_t len = strlen(vd->vdev_path) + 3;
348 char *buf = kmem_alloc(len, KM_SLEEP);
350 (void) snprintf(buf, len, "%ss0", vd->vdev_path);
352 error = ldi_open_by_name(buf, spa_mode(spa), kcred,
353 &dvd->vd_lh, zfs_li);
355 spa_strfree(vd->vdev_path);
357 vd->vdev_wholedisk = 1ULL;
364 * If we have not yet opened the device, try to open it by the
368 error = ldi_open_by_name(vd->vdev_path, spa_mode(spa),
369 kcred, &dvd->vd_lh, zfs_li);
373 * Compare the devid to the stored value.
375 if (error == 0 && vd->vdev_devid != NULL &&
376 ldi_get_devid(dvd->vd_lh, &devid) == 0) {
377 if (ddi_devid_compare(devid, dvd->vd_devid) != 0) {
378 error = SET_ERROR(EINVAL);
379 (void) ldi_close(dvd->vd_lh, spa_mode(spa),
383 ddi_devid_free(devid);
387 * If we succeeded in opening the device, but 'vdev_wholedisk'
388 * is not yet set, then this must be a slice.
390 if (error == 0 && vd->vdev_wholedisk == -1ULL)
391 vd->vdev_wholedisk = 0;
395 * If we were unable to open by path, or the devid check fails, open by
398 if (error != 0 && vd->vdev_devid != NULL) {
399 error = ldi_open_by_devid(dvd->vd_devid, dvd->vd_minor,
400 spa_mode(spa), kcred, &dvd->vd_lh, zfs_li);
404 * If all else fails, then try opening by physical path (if available)
405 * or the logical path (if we failed due to the devid check). While not
406 * as reliable as the devid, this will give us something, and the higher
407 * level vdev validation will prevent us from opening the wrong device.
410 if (vd->vdev_devid != NULL)
411 validate_devid = B_TRUE;
413 if (vd->vdev_physpath != NULL &&
414 (dev = ddi_pathname_to_dev_t(vd->vdev_physpath)) != NODEV)
415 error = ldi_open_by_dev(&dev, OTYP_BLK, spa_mode(spa),
416 kcred, &dvd->vd_lh, zfs_li);
419 * Note that we don't support the legacy auto-wholedisk support
420 * as above. This hasn't been used in a very long time and we
421 * don't need to propagate its oddities to this edge condition.
423 if (error && vd->vdev_path != NULL)
424 error = ldi_open_by_name(vd->vdev_path, spa_mode(spa),
425 kcred, &dvd->vd_lh, zfs_li);
429 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
434 * Now that the device has been successfully opened, update the devid
437 if (validate_devid && spa_writeable(spa) &&
438 ldi_get_devid(dvd->vd_lh, &devid) == 0) {
439 if (ddi_devid_compare(devid, dvd->vd_devid) != 0) {
442 vd_devid = ddi_devid_str_encode(devid, dvd->vd_minor);
443 zfs_dbgmsg("vdev %s: update devid from %s, "
444 "to %s", vd->vdev_path, vd->vdev_devid, vd_devid);
445 spa_strfree(vd->vdev_devid);
446 vd->vdev_devid = spa_strdup(vd_devid);
447 ddi_devid_str_free(vd_devid);
449 ddi_devid_free(devid);
453 * Once a device is opened, verify that the physical device path (if
454 * available) is up to date.
456 if (ldi_get_dev(dvd->vd_lh, &dev) == 0 &&
457 ldi_get_otyp(dvd->vd_lh, &otyp) == 0) {
458 char *physpath, *minorname;
460 physpath = kmem_alloc(MAXPATHLEN, KM_SLEEP);
462 if (ddi_dev_pathname(dev, otyp, physpath) == 0 &&
463 ldi_get_minor_name(dvd->vd_lh, &minorname) == 0 &&
464 (vd->vdev_physpath == NULL ||
465 strcmp(vd->vdev_physpath, physpath) != 0)) {
466 if (vd->vdev_physpath)
467 spa_strfree(vd->vdev_physpath);
468 (void) strlcat(physpath, ":", MAXPATHLEN);
469 (void) strlcat(physpath, minorname, MAXPATHLEN);
470 vd->vdev_physpath = spa_strdup(physpath);
473 kmem_free(minorname, strlen(minorname) + 1);
474 kmem_free(physpath, MAXPATHLEN);
478 * Register callbacks for the LDI offline event.
480 if (ldi_ev_get_cookie(dvd->vd_lh, LDI_EV_OFFLINE, &ecookie) ==
482 lcb = kmem_zalloc(sizeof (vdev_disk_ldi_cb_t), KM_SLEEP);
483 list_insert_tail(&dvd->vd_ldi_cbs, lcb);
484 (void) ldi_ev_register_callbacks(dvd->vd_lh, ecookie,
485 &vdev_disk_off_callb, (void *) vd, &lcb->lcb_id);
489 * Register callbacks for the LDI degrade event.
491 if (ldi_ev_get_cookie(dvd->vd_lh, LDI_EV_DEGRADE, &ecookie) ==
493 lcb = kmem_zalloc(sizeof (vdev_disk_ldi_cb_t), KM_SLEEP);
494 list_insert_tail(&dvd->vd_ldi_cbs, lcb);
495 (void) ldi_ev_register_callbacks(dvd->vd_lh, ecookie,
496 &vdev_disk_dgrd_callb, (void *) vd, &lcb->lcb_id);
500 * Determine the actual size of the device.
502 if (ldi_get_size(dvd->vd_lh, psize) != 0) {
503 vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED;
504 return (SET_ERROR(EINVAL));
508 * Determine the device's minimum transfer size.
509 * If the ioctl isn't supported, assume DEV_BSIZE.
511 if (ldi_ioctl(dvd->vd_lh, DKIOCGMEDIAINFOEXT, (intptr_t)&dkmext,
512 FKIOCTL, kcred, NULL) != 0)
513 dkmext.dki_pbsize = DEV_BSIZE;
515 *ashift = highbit64(MAX(dkmext.dki_pbsize, SPA_MINBLOCKSIZE)) - 1;
517 if (vd->vdev_wholedisk == 1) {
518 uint64_t capacity = dkmext.dki_capacity - 1;
519 uint64_t blksz = dkmext.dki_lbsize;
523 * If we own the whole disk, try to enable disk write caching.
524 * We ignore errors because it's OK if we can't do it.
526 (void) ldi_ioctl(dvd->vd_lh, DKIOCSETWCE, (intptr_t)&wce,
527 FKIOCTL, kcred, NULL);
529 *max_psize = *psize + vdev_disk_get_space(vd, capacity, blksz);
530 zfs_dbgmsg("capacity change: vdev %s, psize %llu, "
531 "max_psize %llu", vd->vdev_path, *psize, *max_psize);
537 * Clear the nowritecache bit, so that on a vdev_reopen() we will
540 vd->vdev_nowritecache = B_FALSE;
546 vdev_disk_close(vdev_t *vd)
548 vdev_disk_t *dvd = vd->vdev_tsd;
550 if (vd->vdev_reopening || dvd == NULL)
553 if (dvd->vd_minor != NULL) {
554 ddi_devid_str_free(dvd->vd_minor);
555 dvd->vd_minor = NULL;
558 if (dvd->vd_devid != NULL) {
559 ddi_devid_free(dvd->vd_devid);
560 dvd->vd_devid = NULL;
563 if (dvd->vd_lh != NULL) {
564 (void) ldi_close(dvd->vd_lh, spa_mode(vd->vdev_spa), kcred);
568 vd->vdev_delayed_close = B_FALSE;
570 * If we closed the LDI handle due to an offline notify from LDI,
571 * don't free vd->vdev_tsd or unregister the callbacks here;
572 * the offline finalize callback or a reopen will take care of it.
574 if (dvd->vd_ldi_offline)
581 vdev_disk_physio(vdev_t *vd, caddr_t data,
582 size_t size, uint64_t offset, int flags, boolean_t isdump)
584 vdev_disk_t *dvd = vd->vdev_tsd;
587 * If the vdev is closed, it's likely in the REMOVED or FAULTED state.
588 * Nothing to be done here but return failure.
590 if (dvd == NULL || (dvd->vd_ldi_offline && dvd->vd_lh == NULL))
593 ASSERT(vd->vdev_ops == &vdev_disk_ops);
596 * If in the context of an active crash dump, use the ldi_dump(9F)
597 * call instead of ldi_strategy(9F) as usual.
600 ASSERT3P(dvd, !=, NULL);
601 return (ldi_dump(dvd->vd_lh, data, lbtodb(offset),
605 return (vdev_disk_ldi_physio(dvd->vd_lh, data, size, offset, flags));
609 vdev_disk_ldi_physio(ldi_handle_t vd_lh, caddr_t data,
610 size_t size, uint64_t offset, int flags)
616 return (SET_ERROR(EINVAL));
618 ASSERT(flags & B_READ || flags & B_WRITE);
620 bp = getrbuf(KM_SLEEP);
621 bp->b_flags = flags | B_BUSY | B_NOCACHE | B_FAILFAST;
623 bp->b_un.b_addr = (void *)data;
624 bp->b_lblkno = lbtodb(offset);
625 bp->b_bufsize = size;
627 error = ldi_strategy(vd_lh, bp);
629 if ((error = biowait(bp)) == 0 && bp->b_resid != 0)
630 error = SET_ERROR(EIO);
637 vdev_disk_io_intr(buf_t *bp)
639 vdev_buf_t *vb = (vdev_buf_t *)bp;
640 zio_t *zio = vb->vb_io;
643 * The rest of the zio stack only deals with EIO, ECKSUM, and ENXIO.
644 * Rather than teach the rest of the stack about other error
645 * possibilities (EFAULT, etc), we normalize the error value here.
647 zio->io_error = (geterror(bp) != 0 ? EIO : 0);
649 if (zio->io_error == 0 && bp->b_resid != 0)
650 zio->io_error = SET_ERROR(EIO);
652 kmem_free(vb, sizeof (vdev_buf_t));
658 vdev_disk_ioctl_free(zio_t *zio)
660 kmem_free(zio->io_vsd, sizeof (struct dk_callback));
663 static const zio_vsd_ops_t vdev_disk_vsd_ops = {
664 vdev_disk_ioctl_free,
665 zio_vsd_default_cksum_report
669 vdev_disk_ioctl_done(void *zio_arg, int error)
671 zio_t *zio = zio_arg;
673 zio->io_error = error;
679 vdev_disk_io_start(zio_t *zio)
681 vdev_t *vd = zio->io_vd;
682 vdev_disk_t *dvd = vd->vdev_tsd;
684 struct dk_callback *dkc;
689 * If the vdev is closed, it's likely in the REMOVED or FAULTED state.
690 * Nothing to be done here but return failure.
692 if (dvd == NULL || (dvd->vd_ldi_offline && dvd->vd_lh == NULL)) {
693 zio->io_error = ENXIO;
694 return (ZIO_PIPELINE_CONTINUE);
697 if (zio->io_type == ZIO_TYPE_IOCTL) {
699 if (!vdev_readable(vd)) {
700 zio->io_error = SET_ERROR(ENXIO);
701 return (ZIO_PIPELINE_CONTINUE);
704 switch (zio->io_cmd) {
706 case DKIOCFLUSHWRITECACHE:
708 if (zfs_nocacheflush)
711 if (vd->vdev_nowritecache) {
712 zio->io_error = SET_ERROR(ENOTSUP);
716 zio->io_vsd = dkc = kmem_alloc(sizeof (*dkc), KM_SLEEP);
717 zio->io_vsd_ops = &vdev_disk_vsd_ops;
719 dkc->dkc_callback = vdev_disk_ioctl_done;
720 dkc->dkc_flag = FLUSH_VOLATILE;
721 dkc->dkc_cookie = zio;
723 error = ldi_ioctl(dvd->vd_lh, zio->io_cmd,
724 (uintptr_t)dkc, FKIOCTL, kcred, NULL);
728 * The ioctl will be done asychronously,
729 * and will call vdev_disk_ioctl_done()
732 return (ZIO_PIPELINE_STOP);
735 if (error == ENOTSUP || error == ENOTTY) {
737 * If we get ENOTSUP or ENOTTY, we know that
738 * no future attempts will ever succeed.
739 * In this case we set a persistent bit so
740 * that we don't bother with the ioctl in the
743 vd->vdev_nowritecache = B_TRUE;
745 zio->io_error = error;
750 zio->io_error = SET_ERROR(ENOTSUP);
753 return (ZIO_PIPELINE_CONTINUE);
756 vb = kmem_alloc(sizeof (vdev_buf_t), KM_SLEEP);
762 bp->b_flags = B_BUSY | B_NOCACHE |
763 (zio->io_type == ZIO_TYPE_READ ? B_READ : B_WRITE);
764 if (!(zio->io_flags & (ZIO_FLAG_IO_RETRY | ZIO_FLAG_TRYHARD)))
765 bp->b_flags |= B_FAILFAST;
766 bp->b_bcount = zio->io_size;
767 bp->b_un.b_addr = zio->io_data;
768 bp->b_lblkno = lbtodb(zio->io_offset);
769 bp->b_bufsize = zio->io_size;
770 bp->b_iodone = (int (*)())vdev_disk_io_intr;
772 /* ldi_strategy() will return non-zero only on programming errors */
773 VERIFY(ldi_strategy(dvd->vd_lh, bp) == 0);
775 return (ZIO_PIPELINE_STOP);
779 vdev_disk_io_done(zio_t *zio)
781 vdev_t *vd = zio->io_vd;
784 * If the device returned EIO, then attempt a DKIOCSTATE ioctl to see if
785 * the device has been removed. If this is the case, then we trigger an
786 * asynchronous removal of the device. Otherwise, probe the device and
787 * make sure it's still accessible.
789 if (zio->io_error == EIO && !vd->vdev_remove_wanted) {
790 vdev_disk_t *dvd = vd->vdev_tsd;
791 int state = DKIO_NONE;
793 if (ldi_ioctl(dvd->vd_lh, DKIOCSTATE, (intptr_t)&state,
794 FKIOCTL, kcred, NULL) == 0 && state != DKIO_INSERTED) {
796 * We post the resource as soon as possible, instead of
797 * when the async removal actually happens, because the
798 * DE is using this information to discard previous I/O
801 zfs_post_remove(zio->io_spa, vd);
802 vd->vdev_remove_wanted = B_TRUE;
803 spa_async_request(zio->io_spa, SPA_ASYNC_REMOVE);
804 } else if (!vd->vdev_delayed_close) {
805 vd->vdev_delayed_close = B_TRUE;
810 vdev_ops_t vdev_disk_ops = {
819 VDEV_TYPE_DISK, /* name of this vdev type */
820 B_TRUE /* leaf vdev */
824 * Given the root disk device devid or pathname, read the label from
825 * the device, and construct a configuration nvlist.
828 vdev_disk_read_rootlabel(char *devpath, char *devid, nvlist_t **config)
834 ddi_devid_t tmpdevid;
839 * Read the device label and build the nvlist.
841 if (devid != NULL && ddi_devid_str_decode(devid, &tmpdevid,
843 error = ldi_open_by_devid(tmpdevid, minor_name,
844 FREAD, kcred, &vd_lh, zfs_li);
845 ddi_devid_free(tmpdevid);
846 ddi_devid_str_free(minor_name);
849 if (error && (error = ldi_open_by_name(devpath, FREAD, kcred, &vd_lh,
853 if (ldi_get_size(vd_lh, &s)) {
854 (void) ldi_close(vd_lh, FREAD, kcred);
855 return (SET_ERROR(EIO));
858 size = P2ALIGN_TYPED(s, sizeof (vdev_label_t), uint64_t);
859 label = kmem_alloc(sizeof (vdev_label_t), KM_SLEEP);
862 for (l = 0; l < VDEV_LABELS; l++) {
863 uint64_t offset, state, txg = 0;
865 /* read vdev label */
866 offset = vdev_label_offset(size, l, 0);
867 if (vdev_disk_ldi_physio(vd_lh, (caddr_t)label,
868 VDEV_SKIP_SIZE + VDEV_PHYS_SIZE, offset, B_READ) != 0)
871 if (nvlist_unpack(label->vl_vdev_phys.vp_nvlist,
872 sizeof (label->vl_vdev_phys.vp_nvlist), config, 0) != 0) {
877 if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_STATE,
878 &state) != 0 || state >= POOL_STATE_DESTROYED) {
879 nvlist_free(*config);
884 if (nvlist_lookup_uint64(*config, ZPOOL_CONFIG_POOL_TXG,
885 &txg) != 0 || txg == 0) {
886 nvlist_free(*config);
894 kmem_free(label, sizeof (vdev_label_t));
895 (void) ldi_close(vd_lh, FREAD, kcred);
897 error = SET_ERROR(EIDRM);