FreeBSD/sys/cddl/contrib/opensolaris/uts/common/os/fm.c
/*
 * Create a new nv list.  A pointer to a new nv list structure is returned
 * upon success or NULL is returned to indicate that the structure could
 * not be created.  The newly created nv list is created and managed by the
 * operations installed in nva.   If nva is NULL, the default FMA nva
 * operations are installed and used.
 *
 * When called from the kernel and nva == NULL, this function must be called
 * from passive kernel context with no locks held that can prevent a
 * sleeping memory allocation from occurring.  Otherwise, this function may
 * be called from other kernel contexts as long a valid nva created via
 * fm_nva_create() is supplied.
 */
Create a new nv list.  A pointer to a new nv list structure is returned
upon success or NULL is returned to indicate that the structure could
not be created.  The newly created nv list is created and managed by the
operations installed in nva.   If nva is NULL, the default FMA nva
operations are installed and used.

When called from the kernel and nva == NULL, this function must be called
from passive kernel context with no locks held that can prevent a
sleeping memory allocation from occurring.  Otherwise, this function may
be called from other kernel contexts as long a valid nva created via
fm_nva_create() is supplied.
Create a new nv list . A pointer to a new nv list structure is returned upon success or NULL is returned to indicate that the structure could not be created . The newly created nv list is created and managed by the operations installed in nva . If nva is NULL the default FMA nva operations are installed and used . When called from the kernel and nva == NULL this function must be called from passive kernel context with no locks held that can prevent a sleeping memory allocation from occurring . Otherwise this function may be called from other kernel contexts as long a valid nva created via fm_nva_create () is supplied .
nvlist_t *
fm_nvlist_create(nv_alloc_t *nva)
{
	int hdl_alloced = 0;
	nvlist_t *nvl;
	nv_alloc_t *nvhdl;
	if (nva == NULL) {
		nvhdl = kmem_zalloc(sizeof (nv_alloc_t), KM_SLEEP);
		if (nv_alloc_init(nvhdl, &fm_mem_alloc_ops, NULL, 0) != 0) {
			kmem_free(nvhdl, sizeof (nv_alloc_t));
			return (NULL);
		}
		hdl_alloced = 1;
	} else {
		nvhdl = nva;
	}
	if (nvlist_xalloc(&nvl, NV_UNIQUE_NAME, nvhdl) != 0) {
		if (hdl_alloced) {
			nv_alloc_fini(nvhdl);
			kmem_free(nvhdl, sizeof (nv_alloc_t));
		}
		return (NULL);
	}
	return (nvl);
}
nvlist_t * fm_nvlist_create ( nv_alloc_t * nva ) { int hdl_alloced = 0 ; nvlist_t * nvl ; nv_alloc_t * nvhdl ; if ( nva == NULL ) { nvhdl = kmem_zalloc ( sizeof ( nv_alloc_t ) , KM_SLEEP ) ; if ( nv_alloc_init ( nvhdl , & fm_mem_alloc_ops , NULL , 0 ) != 0 ) { kmem_free ( nvhdl , sizeof ( nv_alloc_t ) ) ; return ( NULL ) ; } hdl_alloced = 1 ; } else { nvhdl = nva ; } if ( nvlist_xalloc ( & nvl , NV_UNIQUE_NAME , nvhdl ) != 0 ) { if ( hdl_alloced ) { nv_alloc_fini ( nvhdl ) ; kmem_free ( nvhdl , sizeof ( nv_alloc_t ) ) ; } return ( NULL ) ; } return ( nvl ) ; }
Create a new nv list.
Create a new nv list .