1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * CDDL HEADER START 4 * 5 * This file and its contents are supplied under the terms of the 6 * Common Development and Distribution License ("CDDL"), version 1.0. 7 * You may only use this file in accordance with the terms of version 8 * 1.0 of the CDDL. 9 * 10 * A full copy of the text of the CDDL should have accompanied this 11 * source. A copy of the CDDL is also available via the Internet at 12 * http://www.illumos.org/license/CDDL. 13 * 14 * CDDL HEADER END 15 */ 16 /* 17 * Copyright (C) 2017 by Lawrence Livermore National Security, LLC. 18 */ 19 20 #ifndef _SYS_MMP_H 21 #define _SYS_MMP_H 22 23 #include <sys/spa.h> 24 #include <sys/zfs_context.h> 25 #include <sys/uberblock_impl.h> 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 #define MMP_MIN_INTERVAL 100 /* ms */ 32 #define MMP_DEFAULT_INTERVAL 1000 /* ms */ 33 #define MMP_DEFAULT_IMPORT_INTERVALS 20 34 #define MMP_DEFAULT_FAIL_INTERVALS 10 35 #define MMP_MIN_FAIL_INTERVALS 2 /* min if != 0 */ 36 #define MMP_IMPORT_VERIFY_ITERS 10 37 #define MMP_IMPORT_SAFETY_FACTOR 200 /* pct */ 38 #define MMP_INTERVAL_OK(interval) MAX(interval, MMP_MIN_INTERVAL) 39 #define MMP_FAIL_INTVS_OK(fails) (fails == 0 ? 0 : MAX(fails, \ 40 MMP_MIN_FAIL_INTERVALS)) 41 42 typedef struct mmp_thread { 43 kmutex_t mmp_thread_lock; /* protect thread mgmt fields */ 44 kcondvar_t mmp_thread_cv; 45 kthread_t *mmp_thread; 46 uint8_t mmp_thread_exiting; 47 kmutex_t mmp_io_lock; /* protect below */ 48 hrtime_t mmp_last_write; /* last successful MMP write */ 49 uint64_t mmp_delay; /* decaying avg ns between MMP writes */ 50 uberblock_t mmp_ub; /* last ub written by sync */ 51 zio_t *mmp_zio_root; /* root of mmp write zios */ 52 uint64_t mmp_kstat_id; /* unique id for next MMP write kstat */ 53 int mmp_skip_error; /* reason for last skipped write */ 54 vdev_t *mmp_last_leaf; /* last mmp write sent here */ 55 uint64_t mmp_leaf_last_gen; /* last mmp write sent here */ 56 uint32_t mmp_seq; /* intra-second update counter */ 57 uint64_t mmp_tryimport_ns; /* tryimport activity check time */ 58 uint64_t mmp_import_ns; /* import activity check time */ 59 uint64_t mmp_claim_ns; /* claim activity check time */ 60 } mmp_thread_t; 61 62 63 extern void mmp_init(struct spa *spa); 64 extern void mmp_fini(struct spa *spa); 65 extern void mmp_thread_start(struct spa *spa); 66 extern void mmp_thread_stop(struct spa *spa); 67 extern void mmp_update_uberblock(struct spa *spa, struct uberblock *ub); 68 extern void mmp_signal_all_threads(void); 69 extern int mmp_claim_uberblock(spa_t *spa, vdev_t *vd, uberblock_t *ub); 70 71 /* Global tuning */ 72 extern int param_set_multihost_interval(ZFS_MODULE_PARAM_ARGS); 73 extern uint64_t zfs_multihost_interval; 74 extern uint_t zfs_multihost_fail_intervals; 75 extern uint_t zfs_multihost_import_intervals; 76 77 #ifdef __cplusplus 78 } 79 #endif 80 81 #endif /* _SYS_MMP_H */ 82