xref: /spdk/lib/ftl/ftl_debug.h (revision 106ad3793f953d7353e5a5a1fa67fa6a82d13747)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2018 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #ifndef FTL_DEBUG_H
7 #define FTL_DEBUG_H
8 
9 #include "ftl_internal.h"
10 #include "ftl_band.h"
11 #include "ftl_core.h"
12 
13 #if defined(DEBUG)
14 void ftl_band_validate_md(struct ftl_band *band, ftl_band_validate_md_cb cb);
15 void ftl_dev_dump_bands(struct spdk_ftl_dev *dev);
16 static inline void
ftl_debug_inject_trim_error(void)17 ftl_debug_inject_trim_error(void)
18 {
19 	static int trim_no = 0;
20 
21 	if (getenv("FTL_CRASH_ON_TRIM") && trim_no++ == 256) {
22 		abort();
23 	}
24 }
25 #else
26 
27 static void
_validate_cb(void * ctx)28 _validate_cb(void *ctx)
29 {
30 	struct ftl_band *band = ctx;
31 
32 	band->validate_cb(band, true);
33 }
34 
35 static inline void
ftl_band_validate_md(struct ftl_band * band,ftl_band_validate_md_cb cb)36 ftl_band_validate_md(struct ftl_band *band, ftl_band_validate_md_cb cb)
37 {
38 	/* For release builds this is a NOP operation, but should still be asynchronous to keep the behavior consistent */
39 	band->validate_cb = cb;
40 	spdk_thread_send_msg(band->dev->core_thread, _validate_cb, band);
41 }
42 
43 static inline void
ftl_dev_dump_bands(struct spdk_ftl_dev * dev)44 ftl_dev_dump_bands(struct spdk_ftl_dev *dev)
45 {
46 }
47 static inline void
ftl_debug_inject_trim_error(void)48 ftl_debug_inject_trim_error(void)
49 {
50 }
51 #endif
52 
53 void ftl_dev_dump_stats(const struct spdk_ftl_dev *dev);
54 
55 #endif /* FTL_DEBUG_H */
56