From 520faf5ddcb1a9536f53438963d1c96678040466 Mon Sep 17 00:00:00 2001 From: gaurkuma Date: Wed, 9 Aug 2017 11:04:41 -0700 Subject: [PATCH] Crash in dbuf_evict_one with DTRACE_PROBE Update the dbuf__evict__one() tracepoint so that it can safely handle a NULL dmu_buf_impl_t pointer. Reviewed-by: Brian Behlendorf Reviewed-by: Giuseppe Di Natale Reviewed-by: George Melikov Reviewed-by: loli10K Signed-off-by: gaurkuma Closes #6463 --- include/sys/trace_dbuf.h | 58 +++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/include/sys/trace_dbuf.h b/include/sys/trace_dbuf.h index edaa77fa6..c3e70c371 100644 --- a/include/sys/trace_dbuf.h +++ b/include/sys/trace_dbuf.h @@ -33,6 +33,10 @@ #include #include +#ifndef TRACE_DBUF_MSG_MAX +#define TRACE_DBUF_MSG_MAX 512 +#endif + /* * Generic support for two argument tracepoints of the form: * @@ -42,8 +46,7 @@ */ #define DBUF_TP_STRUCT_ENTRY \ - __string(os_spa, \ - spa_name(DB_DNODE(db)->dn_objset->os_spa)) \ + __dynamic_array(char, os_spa, TRACE_DBUF_MSG_MAX) \ __field(uint64_t, ds_object) \ __field(uint64_t, db_object) \ __field(uint64_t, db_level) \ @@ -52,21 +55,38 @@ __field(uint64_t, db_size) \ __field(uint64_t, db_state) \ __field(int64_t, db_holds) \ - -#define DBUF_TP_FAST_ASSIGN \ - __assign_str(os_spa, \ - spa_name(DB_DNODE(db)->dn_objset->os_spa)); \ - \ - __entry->ds_object = db->db_objset->os_dsl_dataset ? \ - db->db_objset->os_dsl_dataset->ds_object : 0; \ - \ - __entry->db_object = db->db.db_object; \ - __entry->db_level = db->db_level; \ - __entry->db_blkid = db->db_blkid; \ - __entry->db_offset = db->db.db_offset; \ - __entry->db_size = db->db.db_size; \ - __entry->db_state = db->db_state; \ - __entry->db_holds = refcount_count(&db->db_holds); + __dynamic_array(char, msg, TRACE_DBUF_MSG_MAX) + +#define DBUF_TP_FAST_ASSIGN \ + if (db != NULL) { \ + __assign_str(os_spa, \ + spa_name(DB_DNODE(db)->dn_objset->os_spa)); \ + \ + __entry->ds_object = db->db_objset->os_dsl_dataset ? \ + db->db_objset->os_dsl_dataset->ds_object : 0; \ + \ + __entry->db_object = db->db.db_object; \ + __entry->db_level = db->db_level; \ + __entry->db_blkid = db->db_blkid; \ + __entry->db_offset = db->db.db_offset; \ + __entry->db_size = db->db.db_size; \ + __entry->db_state = db->db_state; \ + __entry->db_holds = refcount_count(&db->db_holds); \ + snprintf(__get_str(msg), TRACE_DBUF_MSG_MAX, \ + DBUF_TP_PRINTK_FMT, DBUF_TP_PRINTK_ARGS); \ + } else { \ + __assign_str(os_spa, "NULL") \ + __entry->ds_object = 0; \ + __entry->db_object = 0; \ + __entry->db_level = 0; \ + __entry->db_blkid = 0; \ + __entry->db_offset = 0; \ + __entry->db_size = 0; \ + __entry->db_state = 0; \ + __entry->db_holds = 0; \ + snprintf(__get_str(msg), TRACE_DBUF_MSG_MAX, \ + "dbuf { NULL }"); \ + } #define DBUF_TP_PRINTK_FMT \ "dbuf { spa \"%s\" objset %llu object %llu level %llu " \ @@ -84,7 +104,7 @@ DECLARE_EVENT_CLASS(zfs_dbuf_class, TP_ARGS(db, zio), TP_STRUCT__entry(DBUF_TP_STRUCT_ENTRY), TP_fast_assign(DBUF_TP_FAST_ASSIGN), - TP_printk(DBUF_TP_PRINTK_FMT, DBUF_TP_PRINTK_ARGS) + TP_printk("%s", __get_str(msg)) ); /* END CSTYLED */ @@ -102,7 +122,7 @@ DECLARE_EVENT_CLASS(zfs_dbuf_evict_one_class, TP_ARGS(db, mls), TP_STRUCT__entry(DBUF_TP_STRUCT_ENTRY), TP_fast_assign(DBUF_TP_FAST_ASSIGN), - TP_printk(DBUF_TP_PRINTK_FMT, DBUF_TP_PRINTK_ARGS) + TP_printk("%s", __get_str(msg)) ); /* END CSTYLED */ -- 2.40.0