Use kmem_vasprintf() in log_internal()

An attempt to debug zfsonlinux/zfs#2781 revealed that this code could be
simplified by using kmem_asprintf(). It is not clear that switching to
kmem_asprintf() addresses zfsonlinux/zfs#2781. However, switching to
kmem_asprintf() is cleanup that simplifies debugging such that it would
become clear that this is a bug in glibc should the issue persist.

It also brings this function almost back in sync with Illumos.  This
was possible due to the recently reworked kmem code which allows us
to use KM_SLEEP in the same fashion as Illumos.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #2791
Issue #2781
This commit is contained in:
Richard Yao 2014-10-11 11:01:37 -04:00 committed by Brian Behlendorf
parent 3c832b8cc1
commit 841c9d43c7

View File

@ -436,8 +436,6 @@ log_internal(nvlist_t *nvl, const char *operation, spa_t *spa,
dmu_tx_t *tx, const char *fmt, va_list adx) dmu_tx_t *tx, const char *fmt, va_list adx)
{ {
char *msg; char *msg;
va_list adx1;
int size;
/* /*
* If this is part of creating a pool, not everything is * If this is part of creating a pool, not everything is
@ -449,15 +447,9 @@ log_internal(nvlist_t *nvl, const char *operation, spa_t *spa,
return; return;
} }
va_copy(adx1, adx); msg = kmem_vasprintf(fmt, adx);
size = vsnprintf(NULL, 0, fmt, adx1) + 1;
msg = kmem_alloc(size, KM_SLEEP);
va_end(adx1);
va_copy(adx1, adx);
(void) vsprintf(msg, fmt, adx1);
va_end(adx1);
fnvlist_add_string(nvl, ZPOOL_HIST_INT_STR, msg); fnvlist_add_string(nvl, ZPOOL_HIST_INT_STR, msg);
kmem_free(msg, size); strfree(msg);
fnvlist_add_string(nvl, ZPOOL_HIST_INT_NAME, operation); fnvlist_add_string(nvl, ZPOOL_HIST_INT_NAME, operation);
fnvlist_add_uint64(nvl, ZPOOL_HIST_TXG, tx->tx_txg); fnvlist_add_uint64(nvl, ZPOOL_HIST_TXG, tx->tx_txg);