Merge branch 'linux-kernel-mem' into refs/top-bases/linux-zfs-branch

This commit is contained in:
Brian Behlendorf 2010-06-28 11:31:03 -07:00
commit 759df09df2
3 changed files with 20 additions and 14 deletions

View File

@ -504,6 +504,7 @@ typedef struct callb_cpr {
#define zone_dataset_visible(x, y) (1) #define zone_dataset_visible(x, y) (1)
#define INGLOBALZONE(z) (1) #define INGLOBALZONE(z) (1)
extern char *kmem_vasprintf(const char *fmt, va_list adx);
extern char *kmem_asprintf(const char *fmt, ...); extern char *kmem_asprintf(const char *fmt, ...);
#define strfree(str) kmem_free((str), strlen(str)+1) #define strfree(str) kmem_free((str), strlen(str)+1)

View File

@ -1120,25 +1120,27 @@ ksiddomain_rele(ksiddomain_t *ksid)
umem_free(ksid, sizeof (ksiddomain_t)); umem_free(ksid, sizeof (ksiddomain_t));
} }
/* char *
* Do not change the length of the returned string; it must be freed kmem_vasprintf(const char *fmt, va_list adx)
* with strfree(). {
*/ char *buf = NULL;
va_list adx_copy;
va_copy(adx_copy, adx);
VERIFY(vasprintf(&buf, fmt, adx_copy) != -1);
va_end(adx_copy);
return (buf);
}
char * char *
kmem_asprintf(const char *fmt, ...) kmem_asprintf(const char *fmt, ...)
{ {
int size; char *buf = NULL;
va_list adx; va_list adx;
char *buf;
va_start(adx, fmt); va_start(adx, fmt);
size = vsnprintf(NULL, 0, fmt, adx) + 1; VERIFY(vasprintf(&buf, fmt, adx) != -1);
va_end(adx);
buf = kmem_alloc(size, KM_SLEEP);
va_start(adx, fmt);
size = vsnprintf(buf, size, fmt, adx);
va_end(adx); va_end(adx);
return (buf); return (buf);

View File

@ -432,6 +432,7 @@ log_internal(history_internal_events_t event, spa_t *spa,
dmu_tx_t *tx, const char *fmt, va_list adx) dmu_tx_t *tx, const char *fmt, va_list adx)
{ {
history_arg_t *ha; history_arg_t *ha;
va_list adx_copy;
/* /*
* If this is part of creating a pool, not everything is * If this is part of creating a pool, not everything is
@ -441,7 +442,9 @@ log_internal(history_internal_events_t event, spa_t *spa,
return; return;
ha = kmem_alloc(sizeof (history_arg_t), KM_SLEEP); ha = kmem_alloc(sizeof (history_arg_t), KM_SLEEP);
ha->ha_history_str = kmem_asprintf(fmt, adx); 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_log_type = LOG_INTERNAL;
ha->ha_event = event; ha->ha_event = event;
ha->ha_zone = NULL; ha->ha_zone = NULL;