]> git.proxmox.com Git - mirror_zfs.git/blobdiff - module/zfs/zio.c
OpenZFS 7614, 9064 - zfs device evacuation/removal
[mirror_zfs.git] / module / zfs / zio.c
index 37259ad8ec282ead29a2150f5defbf6b7c21a18b..5259a0c6f01df9b5bf5d698730d3f6835e3f6cf7 100644 (file)
@@ -506,7 +506,7 @@ error:
         * the io_error. If this was not a speculative zio, create an ereport.
         */
        if (ret == ECKSUM) {
-               ret = SET_ERROR(EIO);
+               zio->io_error = SET_ERROR(EIO);
                if ((zio->io_flags & ZIO_FLAG_SPECULATIVE) == 0) {
                        zfs_ereport_post(FM_EREPORT_ZFS_AUTHENTICATION,
                            spa, NULL, &zio->io_bookmark, zio, 0, 0);
@@ -614,21 +614,26 @@ zio_remove_child(zio_t *pio, zio_t *cio, zio_link_t *zl)
 }
 
 static boolean_t
-zio_wait_for_children(zio_t *zio, enum zio_child child, enum zio_wait_type wait)
+zio_wait_for_children(zio_t *zio, uint8_t childbits, enum zio_wait_type wait)
 {
-       uint64_t *countp = &zio->io_children[child][wait];
        boolean_t waiting = B_FALSE;
 
        mutex_enter(&zio->io_lock);
        ASSERT(zio->io_stall == NULL);
-       if (*countp != 0) {
-               zio->io_stage >>= 1;
-               ASSERT3U(zio->io_stage, !=, ZIO_STAGE_OPEN);
-               zio->io_stall = countp;
-               waiting = B_TRUE;
+       for (int c = 0; c < ZIO_CHILD_TYPES; c++) {
+               if (!(ZIO_CHILD_BIT_IS_SET(childbits, c)))
+                       continue;
+
+               uint64_t *countp = &zio->io_children[c][wait];
+               if (*countp != 0) {
+                       zio->io_stage >>= 1;
+                       ASSERT3U(zio->io_stage, !=, ZIO_STAGE_OPEN);
+                       zio->io_stall = countp;
+                       waiting = B_TRUE;
+                       break;
+               }
        }
        mutex_exit(&zio->io_lock);
-
        return (waiting);
 }
 
@@ -1013,6 +1018,8 @@ void
 zio_free(spa_t *spa, uint64_t txg, const blkptr_t *bp)
 {
 
+       zfs_blkptr_verify(spa, bp);
+
        /*
         * The check for EMBEDDED is a performance optimization.  We
         * process the free here (by ignoring it) rather than
@@ -1076,7 +1083,7 @@ zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, const blkptr_t *bp,
 {
        zio_t *zio;
 
-       dprintf_bp(bp, "claiming in txg %llu", txg);
+       zfs_blkptr_verify(spa, bp);
 
        if (BP_IS_EMBEDDED(bp))
                return (zio_null(pio, spa, NULL, NULL, NULL, 0));
@@ -1195,8 +1202,26 @@ zio_vdev_child_io(zio_t *pio, blkptr_t *bp, vdev_t *vd, uint64_t offset,
        enum zio_stage pipeline = ZIO_VDEV_CHILD_PIPELINE;
        zio_t *zio;
 
-       ASSERT(vd->vdev_parent ==
-           (pio->io_vd ? pio->io_vd : pio->io_spa->spa_root_vdev));
+       /*
+        * vdev child I/Os do not propagate their error to the parent.
+        * Therefore, for correct operation the caller *must* check for
+        * and handle the error in the child i/o's done callback.
+        * The only exceptions are i/os that we don't care about
+        * (OPTIONAL or REPAIR).
+        */
+       ASSERT((flags & ZIO_FLAG_OPTIONAL) || (flags & ZIO_FLAG_IO_REPAIR) ||
+           done != NULL);
+
+       /*
+        * In the common case, where the parent zio was to a normal vdev,
+        * the child zio must be to a child vdev of that vdev.  Otherwise,
+        * the child zio must be to a top-level vdev.
+        */
+       if (pio->io_vd != NULL && pio->io_vd->vdev_ops != &vdev_indirect_ops) {
+               ASSERT3P(vd->vdev_parent, ==, pio->io_vd);
+       } else {
+               ASSERT3P(vd, ==, vd->vdev_top);
+       }
 
        if (type == ZIO_TYPE_READ && bp != NULL) {
                /*
@@ -1209,10 +1234,12 @@ zio_vdev_child_io(zio_t *pio, blkptr_t *bp, vdev_t *vd, uint64_t offset,
                pio->io_pipeline &= ~ZIO_STAGE_CHECKSUM_VERIFY;
        }
 
-       if (vd->vdev_children == 0)
+       if (vd->vdev_ops->vdev_op_leaf) {
+               ASSERT0(vd->vdev_children);
                offset += VDEV_LABEL_START_SIZE;
+       }
 
-       flags |= ZIO_VDEV_CHILD_FLAGS(pio) | ZIO_FLAG_DONT_PROPAGATE;
+       flags |= ZIO_VDEV_CHILD_FLAGS(pio);
 
        /*
         * If we've decided to do a repair, the write is not speculative --
@@ -1313,6 +1340,8 @@ zio_read_bp_init(zio_t *zio)
        uint64_t psize =
            BP_IS_EMBEDDED(bp) ? BPE_GET_PSIZE(bp) : BP_GET_PSIZE(bp);
 
+       ASSERT3P(zio->io_bp, ==, &zio->io_bp_copy);
+
        if (BP_GET_COMPRESS(bp) != ZIO_COMPRESS_OFF &&
            zio->io_child_type == ZIO_CHILD_LOGICAL &&
            !(zio->io_flags & ZIO_FLAG_RAW_COMPRESS)) {
@@ -1336,6 +1365,7 @@ zio_read_bp_init(zio_t *zio)
                abd_return_buf_copy(zio->io_abd, data, psize);
        } else {
                ASSERT(!BP_IS_EMBEDDED(bp));
+               ASSERT3P(zio->io_bp, ==, &zio->io_bp_copy);
        }
 
        if (!DMU_OT_IS_METADATA(BP_GET_TYPE(bp)) && BP_GET_LEVEL(bp) == 0)
@@ -1425,9 +1455,10 @@ zio_write_compress(zio_t *zio)
         * If our children haven't all reached the ready stage,
         * wait for them and then repeat this pipeline stage.
         */
-       if (zio_wait_for_children(zio, ZIO_CHILD_GANG, ZIO_WAIT_READY) ||
-           zio_wait_for_children(zio, ZIO_CHILD_LOGICAL, ZIO_WAIT_READY))
+       if (zio_wait_for_children(zio, ZIO_CHILD_LOGICAL_BIT |
+           ZIO_CHILD_GANG_BIT, ZIO_WAIT_READY)) {
                return (ZIO_PIPELINE_STOP);
+       }
 
        if (!IO_IS_ALLOCATING(zio))
                return (ZIO_PIPELINE_CONTINUE);
@@ -1526,9 +1557,21 @@ zio_write_compress(zio_t *zio)
                *bp = zio->io_bp_orig;
                zio->io_pipeline = zio->io_orig_pipeline;
 
+       } else if ((zio->io_flags & ZIO_FLAG_RAW_ENCRYPT) != 0 &&
+           zp->zp_type == DMU_OT_DNODE) {
+               /*
+                * The DMU actually relies on the zio layer's compression
+                * to free metadnode blocks that have had all contained
+                * dnodes freed. As a result, even when doing a raw
+                * receive, we must check whether the block can be compressed
+                * to a hole.
+                */
+               psize = zio_compress_data(ZIO_COMPRESS_EMPTY,
+                   zio->io_abd, NULL, lsize);
+               if (psize == 0)
+                       compress = ZIO_COMPRESS_OFF;
        } else {
                ASSERT3U(psize, !=, 0);
-
        }
 
        /*
@@ -1596,6 +1639,8 @@ zio_free_bp_init(zio_t *zio)
                        zio->io_pipeline = ZIO_DDT_FREE_PIPELINE;
        }
 
+       ASSERT3P(zio->io_bp, ==, &zio->io_bp_copy);
+
        return (ZIO_PIPELINE_CONTINUE);
 }
 
@@ -2074,7 +2119,7 @@ zio_reexecute(zio_t *pio)
 }
 
 void
-zio_suspend(spa_t *spa, zio_t *zio)
+zio_suspend(spa_t *spa, zio_t *zio, zio_suspend_reason_t reason)
 {
        if (spa_get_failmode(spa) == ZIO_FAILURE_MODE_PANIC)
                fm_panic("Pool '%s' has encountered an uncorrectable I/O "
@@ -2094,7 +2139,7 @@ zio_suspend(spa_t *spa, zio_t *zio)
                    ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE |
                    ZIO_FLAG_GODFATHER);
 
-       spa->spa_suspended = B_TRUE;
+       spa->spa_suspended = reason;
 
        if (zio != NULL) {
                ASSERT(!(zio->io_flags & ZIO_FLAG_GODFATHER));
@@ -2117,7 +2162,7 @@ zio_resume(spa_t *spa)
         * Reexecute all previously suspended i/o.
         */
        mutex_enter(&spa->spa_suspend_lock);
-       spa->spa_suspended = B_FALSE;
+       spa->spa_suspended = ZIO_SUSPEND_NONE;
        cv_broadcast(&spa->spa_suspend_cv);
        pio = spa->spa_suspend_zio_root;
        spa->spa_suspend_zio_root = NULL;
@@ -2442,8 +2487,9 @@ zio_gang_issue(zio_t *zio)
 {
        blkptr_t *bp = zio->io_bp;
 
-       if (zio_wait_for_children(zio, ZIO_CHILD_GANG, ZIO_WAIT_DONE))
+       if (zio_wait_for_children(zio, ZIO_CHILD_GANG_BIT, ZIO_WAIT_DONE)) {
                return (ZIO_PIPELINE_STOP);
+       }
 
        ASSERT(BP_IS_GANG(bp) && zio->io_gang_leader == zio);
        ASSERT(zio->io_child_type > ZIO_CHILD_GANG);
@@ -2784,8 +2830,9 @@ zio_ddt_read_done(zio_t *zio)
 {
        blkptr_t *bp = zio->io_bp;
 
-       if (zio_wait_for_children(zio, ZIO_CHILD_DDT, ZIO_WAIT_DONE))
+       if (zio_wait_for_children(zio, ZIO_CHILD_DDT_BIT, ZIO_WAIT_DONE)) {
                return (ZIO_PIPELINE_STOP);
+       }
 
        ASSERT(BP_GET_DEDUP(bp));
        ASSERT(BP_GET_PSIZE(bp) == zio->io_size);
@@ -3427,6 +3474,15 @@ zio_vdev_io_start(zio_t *zio)
        }
 
        ASSERT3P(zio->io_logical, !=, zio);
+       if (zio->io_type == ZIO_TYPE_WRITE && zio->io_vd->vdev_removing) {
+               /*
+                * Note: the code can handle other kinds of writes,
+                * but we don't expect them.
+                */
+               ASSERT(zio->io_flags &
+                   (ZIO_FLAG_PHYSICAL | ZIO_FLAG_SELF_HEAL |
+                   ZIO_FLAG_INDUCE_DAMAGE));
+       }
 
        align = 1ULL << vd->vdev_top->vdev_ashift;
 
@@ -3511,8 +3567,9 @@ zio_vdev_io_done(zio_t *zio)
        vdev_ops_t *ops = vd ? vd->vdev_ops : &vdev_mirror_ops;
        boolean_t unexpected_error = B_FALSE;
 
-       if (zio_wait_for_children(zio, ZIO_CHILD_VDEV, ZIO_WAIT_DONE))
+       if (zio_wait_for_children(zio, ZIO_CHILD_VDEV_BIT, ZIO_WAIT_DONE)) {
                return (ZIO_PIPELINE_STOP);
+       }
 
        ASSERT(zio->io_type == ZIO_TYPE_READ || zio->io_type == ZIO_TYPE_WRITE);
 
@@ -3610,8 +3667,9 @@ zio_vdev_io_assess(zio_t *zio)
 {
        vdev_t *vd = zio->io_vd;
 
-       if (zio_wait_for_children(zio, ZIO_CHILD_VDEV, ZIO_WAIT_DONE))
+       if (zio_wait_for_children(zio, ZIO_CHILD_VDEV_BIT, ZIO_WAIT_DONE)) {
                return (ZIO_PIPELINE_STOP);
+       }
 
        if (vd == NULL && !(zio->io_flags & ZIO_FLAG_CONFIG_WRITER))
                spa_config_exit(zio->io_spa, SCL_ZIO, zio);
@@ -3983,9 +4041,10 @@ zio_ready(zio_t *zio)
        zio_t *pio, *pio_next;
        zio_link_t *zl = NULL;
 
-       if (zio_wait_for_children(zio, ZIO_CHILD_GANG, ZIO_WAIT_READY) ||
-           zio_wait_for_children(zio, ZIO_CHILD_DDT, ZIO_WAIT_READY))
+       if (zio_wait_for_children(zio, ZIO_CHILD_GANG_BIT | ZIO_CHILD_DDT_BIT,
+           ZIO_WAIT_READY)) {
                return (ZIO_PIPELINE_STOP);
+       }
 
        if (zio->io_ready) {
                ASSERT(IO_IS_ALLOCATING(zio));
@@ -4125,11 +4184,9 @@ zio_done(zio_t *zio)
         * If our children haven't all completed,
         * wait for them and then repeat this pipeline stage.
         */
-       if (zio_wait_for_children(zio, ZIO_CHILD_VDEV, ZIO_WAIT_DONE) ||
-           zio_wait_for_children(zio, ZIO_CHILD_GANG, ZIO_WAIT_DONE) ||
-           zio_wait_for_children(zio, ZIO_CHILD_DDT, ZIO_WAIT_DONE) ||
-           zio_wait_for_children(zio, ZIO_CHILD_LOGICAL, ZIO_WAIT_DONE))
+       if (zio_wait_for_children(zio, ZIO_CHILD_ALL_BITS, ZIO_WAIT_DONE)) {
                return (ZIO_PIPELINE_STOP);
+       }
 
        /*
         * If the allocation throttle is enabled, then update the accounting.
@@ -4369,7 +4426,7 @@ zio_done(zio_t *zio)
                         * We'd fail again if we reexecuted now, so suspend
                         * until conditions improve (e.g. device comes online).
                         */
-                       zio_suspend(zio->io_spa, zio);
+                       zio_suspend(zio->io_spa, zio, ZIO_SUSPEND_IOERR);
                } else {
                        /*
                         * Reexecution is potentially a huge amount of work.