static void log_internal(history_internal_events_t event, spa_t *spa, dmu_tx_t *tx, const char *fmt, va_list adx) { history_arg_t *ha; va_list adx_copy; /* * If this is part of creating a pool, not everything is * initialized yet, so don't bother logging the internal events. */ if (tx->tx_txg == TXG_INITIAL) return; ha = kmem_alloc(sizeof (history_arg_t), KM_SLEEP); va_copy(adx_copy, adx); ha->ha_history_str = kmem_vasprintf(fmt, adx_copy); va_end(adx_copy); ha->ha_log_type = LOG_INTERNAL; ha->ha_event = event; ha->ha_zone = NULL; ha->ha_uid = 0; if (dmu_tx_is_syncing(tx)) { spa_history_log_sync(spa, ha, tx); } else { dsl_sync_task_do_nowait(spa_get_dsl(spa), NULL, spa_history_log_sync, spa, ha, 0, tx); } /* spa_history_log_sync() will free ha and strings */ }
/* * The nvlist will be consumed by this call. */ static void log_internal(nvlist_t *nvl, const char *operation, spa_t *spa, dmu_tx_t *tx, const char *fmt, va_list adx) { char *msg; /* * If this is part of creating a pool, not everything is * initialized yet, so don't bother logging the internal events. * Likewise if the pool is not writeable. */ if (tx->tx_txg == TXG_INITIAL || !spa_writeable(spa)) { fnvlist_free(nvl); return; } msg = kmem_vasprintf(fmt, adx); fnvlist_add_string(nvl, ZPOOL_HIST_INT_STR, msg); strfree(msg); fnvlist_add_string(nvl, ZPOOL_HIST_INT_NAME, operation); fnvlist_add_uint64(nvl, ZPOOL_HIST_TXG, tx->tx_txg); if (dmu_tx_is_syncing(tx)) { spa_history_log_sync(nvl, tx); } else { dsl_sync_task_nowait(spa_get_dsl(spa), spa_history_log_sync, nvl, 0, ZFS_SPACE_CHECK_NONE, tx); } /* spa_history_log_sync() will free nvl */ }
void spa_history_internal_log(history_internal_events_t event, spa_t *spa, dmu_tx_t *tx, cred_t *cr, const char *fmt, ...) { history_arg_t *hap; char *str; va_list adx; hap = kmem_alloc(sizeof (history_arg_t), KM_SLEEP); str = kmem_alloc(HIS_MAX_RECORD_LEN, KM_SLEEP); va_start(adx, fmt); (void) vsnprintf(str, HIS_MAX_RECORD_LEN, fmt, adx); va_end(adx); hap->ha_log_type = LOG_INTERNAL; hap->ha_history_str = str; hap->ha_event = event; hap->ha_zone[0] = '\0'; if (dmu_tx_is_syncing(tx)) { spa_history_log_sync(spa, hap, cr, tx); } else { dsl_sync_task_do_nowait(spa_get_dsl(spa), NULL, spa_history_log_sync, spa, hap, 0, tx); } /* spa_history_log_sync() will free hap and str */ }
static void log_internal(history_internal_events_t event, spa_t *spa, dmu_tx_t *tx, const char *fmt, va_list adx) { history_arg_t *ha; /* * If this is part of creating a pool, not everything is * initialized yet, so don't bother logging the internal events. */ if (tx->tx_txg == TXG_INITIAL) return; ha = kmem_alloc(sizeof (history_arg_t), KM_SLEEP); #ifdef __DARWIN__ /* * vsnprintf(NULL, 0, ...) is broken on darwin! */ { char *buf = kmem_alloc(HIS_MAX_RECORD_LEN, KM_SLEEP); (void) vsnprintf(buf, HIS_MAX_RECORD_LEN, fmt, adx); ha->ha_history_str = strdup(buf); kmem_free(buf, HIS_MAX_RECORD_LEN); } #else ha->ha_history_str = kmem_alloc(vsnprintf(NULL, 0, fmt, adx) + 1, KM_SLEEP); (void) vsprintf(ha->ha_history_str, fmt, adx); #endif /* __DARWIN__ */ ha->ha_log_type = LOG_INTERNAL; ha->ha_event = event; ha->ha_zone = NULL; ha->ha_uid = 0; if (dmu_tx_is_syncing(tx)) { spa_history_log_sync(spa, ha, tx); } else { dsl_sync_task_do_nowait(spa_get_dsl(spa), NULL, spa_history_log_sync, spa, ha, 0, tx); } /* spa_history_log_sync() will free ha and strings */ }
/* * The nvlist will be consumed by this call. */ static void log_internal(nvlist_t *nvl, const char *operation, spa_t *spa, dmu_tx_t *tx, const char *fmt, va_list adx) { char *msg; va_list adx1; int size; /* * If this is part of creating a pool, not everything is * initialized yet, so don't bother logging the internal events. * Likewise if the pool is not writeable. */ if (tx->tx_txg == TXG_INITIAL || !spa_writeable(spa)) { fnvlist_free(nvl); return; } va_copy(adx1, adx); size = vsnprintf(NULL, 0, fmt, adx1) + 1; msg = kmem_alloc(size, KM_PUSHPAGE); va_end(adx1); va_copy(adx1, adx); (void) vsprintf(msg, fmt, adx1); va_end(adx1); fnvlist_add_string(nvl, ZPOOL_HIST_INT_STR, msg); kmem_free(msg, size); fnvlist_add_string(nvl, ZPOOL_HIST_INT_NAME, operation); fnvlist_add_uint64(nvl, ZPOOL_HIST_TXG, tx->tx_txg); if (dmu_tx_is_syncing(tx)) { spa_history_log_sync(nvl, tx); } else { dsl_sync_task_nowait(spa_get_dsl(spa), spa_history_log_sync, nvl, 0, tx); } /* spa_history_log_sync() will free nvl */ }