]> git.proxmox.com Git - mirror_zfs.git/blobdiff - module/zfs/dmu_traverse.c
Fix hung z_zvol tasks during 'zfs receive'
[mirror_zfs.git] / module / zfs / dmu_traverse.c
index 0df12fac8c36777c21d27239e9cfbde4012a7e6c..f63903ef649dc82960c263b164484d0b170c9d28 100644 (file)
@@ -31,6 +31,7 @@
 #include <sys/dsl_pool.h>
 #include <sys/dnode.h>
 #include <sys/spa.h>
+#include <sys/spa_impl.h>
 #include <sys/zio.h>
 #include <sys/dmu_impl.h>
 #include <sys/sa.h>
@@ -39,6 +40,7 @@
 #include <sys/zfeature.h>
 
 int32_t zfs_pd_bytes_max = 50 * 1024 * 1024;   /* 50MB */
+int32_t send_holes_without_birth_time = 1;
 
 typedef struct prefetch_data {
        kmutex_t pd_mtx;
@@ -251,9 +253,10 @@ traverse_visitbp(traverse_data_t *td, const dnode_phys_t *dnp,
                 *
                 * Note that the meta-dnode cannot be reallocated.
                 */
-               if ((!td->td_realloc_possible ||
-                       zb->zb_object == DMU_META_DNODE_OBJECT) &&
-                       td->td_hole_birth_enabled_txg <= td->td_min_txg)
+               if (!send_holes_without_birth_time &&
+                   (!td->td_realloc_possible ||
+                   zb->zb_object == DMU_META_DNODE_OBJECT) &&
+                   td->td_hole_birth_enabled_txg <= td->td_min_txg)
                        return (0);
        } else if (bp->blk_birth <= td->td_min_txg) {
                return (0);
@@ -385,7 +388,7 @@ traverse_visitbp(traverse_data_t *td, const dnode_phys_t *dnp,
        }
 
        if (buf)
-               (void) arc_buf_remove_ref(buf, &buf);
+               arc_buf_destroy(buf, &buf);
 
 post:
        if (err == 0 && (td->td_flags & TRAVERSE_POST))
@@ -597,24 +600,32 @@ traverse_impl(spa_t *spa, dsl_dataset_t *ds, uint64_t objset, blkptr_t *rootbp,
 
        /* See comment on ZIL traversal in dsl_scan_visitds. */
        if (ds != NULL && !ds->ds_is_snapshot && !BP_IS_HOLE(rootbp)) {
+               enum zio_flag zio_flags = ZIO_FLAG_CANFAIL;
                uint32_t flags = ARC_FLAG_WAIT;
                objset_phys_t *osp;
                arc_buf_t *buf;
 
-               err = arc_read(NULL, td->td_spa, rootbp,
-                   arc_getbuf_func, &buf,
-                   ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, &flags, czb);
-               if (err != 0)
-                       return (err);
-
-               osp = buf->b_data;
-               traverse_zil(td, &osp->os_zil_header);
-               (void) arc_buf_remove_ref(buf, &buf);
+               err = arc_read(NULL, td->td_spa, rootbp, arc_getbuf_func,
+                   &buf, ZIO_PRIORITY_ASYNC_READ, zio_flags, &flags, czb);
+               if (err != 0) {
+                       /*
+                        * If both TRAVERSE_HARD and TRAVERSE_PRE are set,
+                        * continue to visitbp so that td_func can be called
+                        * in pre stage, and err will reset to zero.
+                        */
+                       if (!(td->td_flags & TRAVERSE_HARD) ||
+                           !(td->td_flags & TRAVERSE_PRE))
+                               return (err);
+               } else {
+                       osp = buf->b_data;
+                       traverse_zil(td, &osp->os_zil_header);
+                       arc_buf_destroy(buf, &buf);
+               }
        }
 
        if (!(flags & TRAVERSE_PREFETCH_DATA) ||
-           0 == taskq_dispatch(system_taskq, traverse_prefetch_thread,
-           td, TQ_NOQUEUE))
+           taskq_dispatch(spa->spa_prefetch_taskq, traverse_prefetch_thread,
+           td, TQ_NOQUEUE) == TASKQID_INVALID)
                pd->pd_exited = B_TRUE;
 
        err = traverse_visitbp(td, NULL, rootbp, czb);
@@ -727,4 +738,12 @@ EXPORT_SYMBOL(traverse_pool);
 
 module_param(zfs_pd_bytes_max, int, 0644);
 MODULE_PARM_DESC(zfs_pd_bytes_max, "Max number of bytes to prefetch");
+
+module_param_named(ignore_hole_birth, send_holes_without_birth_time, int, 0644);
+MODULE_PARM_DESC(ignore_hole_birth, "Alias for send_holes_without_birth_time");
+
+module_param_named(send_holes_without_birth_time,
+       send_holes_without_birth_time, int, 0644);
+MODULE_PARM_DESC(send_holes_without_birth_time,
+       "Ignore hole_birth txg for zfs send");
 #endif