* Prepare a virtual device for access. */
| 1772 | * Prepare a virtual device for access. |
| 1773 | */ |
| 1774 | int |
| 1775 | vdev_open(vdev_t *vd) |
| 1776 | { |
| 1777 | spa_t *spa = vd->vdev_spa; |
| 1778 | int error; |
| 1779 | uint64_t osize = 0; |
| 1780 | uint64_t max_osize = 0; |
| 1781 | uint64_t asize, max_asize, psize; |
| 1782 | uint64_t logical_ashift = 0; |
| 1783 | uint64_t physical_ashift = 0; |
| 1784 | |
| 1785 | ASSERT(vd->vdev_open_thread == curthread || |
| 1786 | spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL); |
| 1787 | ASSERT(vd->vdev_state == VDEV_STATE_CLOSED || |
| 1788 | vd->vdev_state == VDEV_STATE_CANT_OPEN || |
| 1789 | vd->vdev_state == VDEV_STATE_OFFLINE); |
| 1790 | |
| 1791 | vd->vdev_stat.vs_aux = VDEV_AUX_NONE; |
| 1792 | vd->vdev_cant_read = B_FALSE; |
| 1793 | vd->vdev_cant_write = B_FALSE; |
| 1794 | vd->vdev_min_asize = vdev_get_min_asize(vd); |
| 1795 | |
| 1796 | /* |
| 1797 | * If this vdev is not removed, check its fault status. If it's |
| 1798 | * faulted, bail out of the open. |
| 1799 | */ |
| 1800 | if (!vd->vdev_removed && vd->vdev_faulted) { |
| 1801 | ASSERT(vd->vdev_children == 0); |
| 1802 | ASSERT(vd->vdev_label_aux == VDEV_AUX_ERR_EXCEEDED || |
| 1803 | vd->vdev_label_aux == VDEV_AUX_EXTERNAL); |
| 1804 | vdev_set_state(vd, B_TRUE, VDEV_STATE_FAULTED, |
| 1805 | vd->vdev_label_aux); |
| 1806 | return (SET_ERROR(ENXIO)); |
| 1807 | } else if (vd->vdev_offline) { |
| 1808 | ASSERT(vd->vdev_children == 0); |
| 1809 | vdev_set_state(vd, B_TRUE, VDEV_STATE_OFFLINE, VDEV_AUX_NONE); |
| 1810 | return (SET_ERROR(ENXIO)); |
| 1811 | } |
| 1812 | |
| 1813 | error = vd->vdev_ops->vdev_op_open(vd, &osize, &max_osize, |
| 1814 | &logical_ashift, &physical_ashift); |
| 1815 | /* |
| 1816 | * Physical volume size should never be larger than its max size, unless |
| 1817 | * the disk has shrunk while we were reading it or the device is buggy |
| 1818 | * or damaged: either way it's not safe for use, bail out of the open. |
| 1819 | */ |
| 1820 | if (osize > max_osize) { |
| 1821 | vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN, |
| 1822 | VDEV_AUX_OPEN_FAILED); |
| 1823 | return (SET_ERROR(ENXIO)); |
| 1824 | } |
| 1825 | |
| 1826 | /* |
| 1827 | * Reset the vdev_reopening flag so that we actually close |
| 1828 | * the vdev on error. |
| 1829 | */ |
| 1830 | vd->vdev_reopening = B_FALSE; |
| 1831 | if (zio_injection_enabled && error == 0) |
no test coverage detected