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) 2017 by Lawrence Livermore National Security, LLC. 14 */ 15 16 #ifndef _SYS_MMP_H 17 #define _SYS_MMP_H 18 19 #include <sys/spa.h> 20 #include <sys/zfs_context.h> 21 #include <sys/uberblock_impl.h> 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #define MMP_MIN_INTERVAL 100 /* ms */ 28 #define MMP_DEFAULT_INTERVAL 1000 /* ms */ 29 #define MMP_DEFAULT_IMPORT_INTERVALS 20 30 #define MMP_DEFAULT_FAIL_INTERVALS 10 31 #define MMP_MIN_FAIL_INTERVALS 2 /* min if != 0 */ 32 #define MMP_IMPORT_VERIFY_ITERS 10 33 #define MMP_IMPORT_SAFETY_FACTOR 200 /* pct */ 34 #define MMP_INTERVAL_OK(interval) MAX(interval, MMP_MIN_INTERVAL) 35 #define MMP_FAIL_INTVS_OK(fails) (fails == 0 ? 0 : MAX(fails, \ 36 MMP_MIN_FAIL_INTERVALS)) 37 38 typedef struct mmp_thread { 39 kmutex_t mmp_thread_lock; /* protect thread mgmt fields */ 40 kcondvar_t mmp_thread_cv; 41 kthread_t *mmp_thread; 42 uint8_t mmp_thread_exiting; 43 kmutex_t mmp_io_lock; /* protect below */ 44 hrtime_t mmp_last_write; /* last successful MMP write */ 45 uint64_t mmp_delay; /* decaying avg ns between MMP writes */ 46 uberblock_t mmp_ub; /* last ub written by sync */ 47 zio_t *mmp_zio_root; /* root of mmp write zios */ 48 uint64_t mmp_kstat_id; /* unique id for next MMP write kstat */ 49 int mmp_skip_error; /* reason for last skipped write */ 50 vdev_t *mmp_last_leaf; /* last mmp write sent here */ 51 uint64_t mmp_leaf_last_gen; /* last mmp write sent here */ 52 uint32_t mmp_seq; /* intra-second update counter */ 53 uint64_t mmp_tryimport_ns; /* tryimport activity check time */ 54 uint64_t mmp_import_ns; /* import activity check time */ 55 uint64_t mmp_claim_ns; /* claim activity check time */ 56 } mmp_thread_t; 57 58 59 extern void mmp_init(struct spa *spa); 60 extern void mmp_fini(struct spa *spa); 61 extern void mmp_thread_start(struct spa *spa); 62 extern void mmp_thread_stop(struct spa *spa); 63 extern void mmp_update_uberblock(struct spa *spa, struct uberblock *ub); 64 extern void mmp_signal_all_threads(void); 65 extern int mmp_claim_uberblock(spa_t *spa, vdev_t *vd, uberblock_t *ub); 66 67 /* Global tuning */ 68 extern int param_set_multihost_interval(ZFS_MODULE_PARAM_ARGS); 69 extern uint64_t zfs_multihost_interval; 70 extern uint_t zfs_multihost_fail_intervals; 71 extern uint_t zfs_multihost_import_intervals; 72 73 #ifndef _KERNEL 74 /* Manual recovery only, see the comment in mmp.c. Never in the module. */ 75 extern boolean_t mmp_claim_relaxed; 76 #endif 77 78 #ifdef __cplusplus 79 } 80 #endif 81 82 #endif /* _SYS_MMP_H */ 83