1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * This file and its contents are supplied under the terms of the 4 * Common Development and Distribution License ("CDDL"), version 1.0. 5 * You may only use this file in accordance with the terms of version 6 * 1.0 of the CDDL. 7 * 8 * A full copy of the text of the CDDL should have accompanied this 9 * source. A copy of the CDDL is also available via the Internet at 10 * https://opensource.org/license/CDDL-1.0. 11 */ 12 /* 13 * Copyright (c) 2018, Intel Corporation. 14 * Copyright (c) 2020 by Lawrence Livermore National Security, LLC. 15 */ 16 17 #ifndef _SYS_VDEV_REBUILD_H 18 #define _SYS_VDEV_REBUILD_H 19 20 #include <sys/spa.h> 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /* 27 * Number of entries in the physical vdev_rebuild_phys structure. This 28 * state is stored per top-level as VDEV_ZAP_TOP_VDEV_REBUILD_PHYS. 29 */ 30 #define REBUILD_PHYS_ENTRIES 12 31 32 /* 33 * On-disk rebuild configuration and state. When adding new fields they 34 * must be added to the end of the structure. 35 */ 36 typedef struct vdev_rebuild_phys { 37 uint64_t vrp_rebuild_state; /* vdev_rebuild_state_t */ 38 uint64_t vrp_last_offset; /* last rebuilt offset */ 39 uint64_t vrp_min_txg; /* minimum missing txg */ 40 uint64_t vrp_max_txg; /* maximum missing txg */ 41 uint64_t vrp_start_time; /* start time */ 42 uint64_t vrp_end_time; /* end time */ 43 uint64_t vrp_scan_time_ms; /* total run time in ms */ 44 uint64_t vrp_bytes_scanned; /* alloc bytes scanned */ 45 uint64_t vrp_bytes_issued; /* read bytes rebuilt */ 46 uint64_t vrp_bytes_rebuilt; /* rebuilt bytes */ 47 uint64_t vrp_bytes_est; /* total bytes to scan */ 48 uint64_t vrp_errors; /* errors during rebuild */ 49 } vdev_rebuild_phys_t; 50 51 /* 52 * The vdev_rebuild_t describes the current state and how a top-level vdev 53 * should be rebuilt. The core elements are the top-vdev, the metaslab being 54 * rebuilt, range tree containing the allocated extents and the on-disk state. 55 */ 56 typedef struct vdev_rebuild { 57 vdev_t *vr_top_vdev; /* top-level vdev to rebuild */ 58 metaslab_t *vr_scan_msp; /* scanning disabled metaslab */ 59 /* scan ranges (in metaslab) */ 60 zfs_range_tree_t *vr_scan_tree; 61 kmutex_t vr_io_lock; /* inflight IO lock */ 62 kcondvar_t vr_io_cv; /* inflight IO cv */ 63 uint64_t vr_last_txg; /* last used txg */ 64 65 /* In-core state and progress */ 66 uint64_t vr_scan_offset[TXG_SIZE]; 67 uint64_t vr_prev_scan_time_ms; /* any previous scan time */ 68 uint64_t vr_bytes_inflight_max; /* maximum bytes inflight */ 69 uint64_t vr_bytes_inflight; /* current bytes inflight */ 70 71 /* Per-rebuild pass statistics for calculating bandwidth */ 72 uint64_t vr_pass_start_time; 73 uint64_t vr_pass_bytes_scanned; 74 uint64_t vr_pass_bytes_issued; 75 uint64_t vr_pass_bytes_skipped; 76 77 /* On-disk state updated by vdev_rebuild_zap_update_sync() */ 78 vdev_rebuild_phys_t vr_rebuild_phys; 79 } vdev_rebuild_t; 80 81 boolean_t vdev_rebuild_active(vdev_t *); 82 83 int vdev_rebuild_load(vdev_t *); 84 void vdev_rebuild(vdev_t *, uint64_t); 85 void vdev_rebuild_txgs(vdev_t *, uint64_t *, uint64_t *); 86 void vdev_rebuild_stop_wait(vdev_t *); 87 void vdev_rebuild_stop_all(spa_t *); 88 void vdev_rebuild_restart(spa_t *); 89 void vdev_rebuild_clear_sync(void *, dmu_tx_t *); 90 int vdev_rebuild_get_stats(vdev_t *, vdev_rebuild_stat_t *); 91 92 #ifdef __cplusplus 93 } 94 #endif 95 96 #endif /* _SYS_VDEV_REBUILD_H */ 97