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