Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Jul 2018 15:02:21 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r336346 - in stable/11: lib/libmd lib/libnv/tests share/man/man9 sys/contrib/libnv sys/sys
Message-ID:  <201807161502.w6GF2LXw050533@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Mon Jul 16 15:02:21 2018
New Revision: 336346
URL: https://svnweb.freebsd.org/changeset/base/336346

Log:
  MFC r304910, r304912, r304915, r304952, r325019, r328164, r331094, r332664,
  r335341-r335345, r335347, r335379-r335380, r335382
  
  r304910:
  Introduce cnv man page.
  
  r304912:
  Add missed header file for cnv.h .
  
  r304915:
  Bump date in the man page.
  
  r304952:
  Remove duplicated declaration.
  
  r325019:
  Introduce cnvlist_name() and cnvlist_type() functions.
  
  Those function can be used when we are iterating over nvlist to reduce
  amount of extra variables we need to declare.
  
  r328164:
  libnv: Use mallocarray(9) for the nv_calloc.
  
  r331094:
  Fix formatting errors that resulted in apropos(1) output looking weird.
  
  r332664:
  Add missing argument in the cnv man page.
  
  r335341:
  libnv: change name of cookie from cookiep to cookie.
  
  The name was inconsistent with rest of the library.
  No functional change intended.
  
  r335342:
  libnv: add const to cookies arguments
  
  r335343:
  libnv: Remove nvlist argument from cnvlist_{take,free}_* functions.
  
  All information which are need for those operations is already stored in
  the cookie.
  
  We decided not to bump libnv version because this API is not used yet in the
  base system.
  
  r335344:
  libnv: clean parent in nvlist_array when removing it.
  
  When we are removing element form the nvlist we should also clean parent,
  because the array is not a part of the nvlist anymore.
  
  r335345:
  libnv: add regression test for r335344.
  
  r335347:
  libnv: Add nvlist_append_*_array() family of functions.
  
  The nvlist_append_{bool,number,string,nvlist,descriptor}_array() functions
  allows to dynamically extend array stored in the nvlist.
  
  r335379:
  Set prev to NULL so its garaunteed to have a value of some kind and
  gcc doesn't explode.  Feel free to fix this correctly or whatever for
  gcc builds.
  
  This *should* quiesce tinderbox after r335347 for the gcc builds.
  
  r335380:
  style(9) fix, I was also going to silence gcc.
  
  r335382:
  Really fix the style.

Added:
  stable/11/lib/libnv/tests/nvlist_append_test.c
     - copied unchanged from r335347, head/lib/libnv/tests/nvlist_append_test.c
  stable/11/share/man/man9/cnv.9
     - copied, changed from r304910, head/share/man/man9/cnv.9
  stable/11/sys/sys/cnv.h
     - copied, changed from r304912, head/sys/sys/cnv.h
Modified:
  stable/11/lib/libmd/sha512.3
  stable/11/lib/libnv/tests/Makefile
  stable/11/lib/libnv/tests/cnv_tests.cc
  stable/11/lib/libnv/tests/nv_array_tests.cc
  stable/11/share/man/man9/Makefile
  stable/11/share/man/man9/nv.9
  stable/11/share/man/man9/owll.9
  stable/11/share/man/man9/rwlock.9
  stable/11/share/man/man9/zone.9
  stable/11/sys/contrib/libnv/cnvlist.c
  stable/11/sys/contrib/libnv/nv_impl.h
  stable/11/sys/contrib/libnv/nvlist.c
  stable/11/sys/contrib/libnv/nvpair.c
  stable/11/sys/sys/nv.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libmd/sha512.3
==============================================================================
--- stable/11/lib/libmd/sha512.3	Mon Jul 16 14:56:30 2018	(r336345)
+++ stable/11/lib/libmd/sha512.3	Mon Jul 16 15:02:21 2018	(r336346)
@@ -26,7 +26,7 @@
 .Nm SHA384_End ,
 .Nm SHA384_File ,
 .Nm SHA384_FileChunk ,
-.Nm SHA384_Data,
+.Nm SHA384_Data ,
 .Nm SHA512_256_Init ,
 .Nm SHA512_256_Update ,
 .Nm SHA512_256_Final ,

Modified: stable/11/lib/libnv/tests/Makefile
==============================================================================
--- stable/11/lib/libnv/tests/Makefile	Mon Jul 16 14:56:30 2018	(r336345)
+++ stable/11/lib/libnv/tests/Makefile	Mon Jul 16 15:02:21 2018	(r336346)
@@ -7,6 +7,7 @@ ATF_TESTS_CXX=	\
 	nv_tests \
 
 TAP_TESTS_C+=	nvlist_add_test
+TAP_TESTS_C+=	nvlist_append_test
 TAP_TESTS_C+=	nvlist_exists_test
 TAP_TESTS_C+=	nvlist_free_test
 TAP_TESTS_C+=	nvlist_get_test

Modified: stable/11/lib/libnv/tests/cnv_tests.cc
==============================================================================
--- stable/11/lib/libnv/tests/cnv_tests.cc	Mon Jul 16 14:56:30 2018	(r336345)
+++ stable/11/lib/libnv/tests/cnv_tests.cc	Mon Jul 16 15:02:21 2018	(r336346)
@@ -575,7 +575,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_bool)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	ATF_REQUIRE_EQ(cnvlist_take_bool(nvl, cookie), value);
+	ATF_REQUIRE_EQ(cnvlist_take_bool(cookie), value);
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -618,7 +618,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_number)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	ATF_REQUIRE_EQ(cnvlist_take_number(nvl, cookie), value);
+	ATF_REQUIRE_EQ(cnvlist_take_number(cookie), value);
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -662,7 +662,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_string)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	out_string = cnvlist_take_string(nvl, cookie);
+	out_string = cnvlist_take_string(cookie);
 	ATF_REQUIRE(out_string != NULL);
 	ATF_REQUIRE_EQ(strcmp(out_string, value), 0);
 
@@ -725,7 +725,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_nvlist)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	result = cnvlist_take_nvlist(nvl, cookie);
+	result = cnvlist_take_nvlist(cookie);
 	ATF_REQUIRE(!nvlist_exists_nvlist(nvl, key));
 	ATF_REQUIRE(result == value);
 
@@ -784,7 +784,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_bool_array)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	out_array = cnvlist_take_bool_array(nvl, cookie, &nitems);
+	out_array = cnvlist_take_bool_array(cookie, &nitems);
 	ATF_REQUIRE_EQ(nitems, 16);
 	ATF_REQUIRE(out_array != NULL);
 	for (i = 0; i < 16; i++)
@@ -836,7 +836,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_number_array)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	out_array = cnvlist_take_number_array(nvl, cookie, &nitems);
+	out_array = cnvlist_take_number_array(cookie, &nitems);
 
 	ATF_REQUIRE(out_array != NULL);
 	ATF_REQUIRE_EQ(nitems, 16);
@@ -885,7 +885,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_string_array)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	out_array = cnvlist_take_string_array(nvl, cookie, &nitems);
+	out_array = cnvlist_take_string_array(cookie, &nitems);
 	ATF_REQUIRE_EQ(nitems, 4);
 	for (i = 0; i < 4; i++) {
 		ATF_REQUIRE(out_array[i] != NULL);
@@ -957,7 +957,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_nvlist_array)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	result = cnvlist_take_nvlist_array(nvl, cookie, &num_items);
+	result = cnvlist_take_nvlist_array(cookie, &num_items);
 
 	ATF_REQUIRE(result != NULL);
 	ATF_REQUIRE_EQ(num_items, 8);
@@ -1022,7 +1022,7 @@ ATF_TEST_CASE_BODY(cnvlist_take_binary)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	out_binary = cnvlist_take_binary(nvl, cookie, &out_size);
+	out_binary = cnvlist_take_binary(cookie, &out_size);
 	ATF_REQUIRE_EQ(out_size, in_size);
 	ATF_REQUIRE_EQ(memcmp(in_binary, out_binary, out_size), 0);
 
@@ -1069,7 +1069,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_bool)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	cnvlist_free_bool(nvl, cookie);
+	cnvlist_free_bool(cookie);
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1112,7 +1112,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_number)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	cnvlist_free_number(nvl, cookie);
+	cnvlist_free_number(cookie);
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1155,7 +1155,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_string)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	cnvlist_free_string(nvl, cookie);
+	cnvlist_free_string(cookie);
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1215,7 +1215,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_nvlist)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	cnvlist_free_nvlist(nvl, cookie);
+	cnvlist_free_nvlist(cookie);
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1262,7 +1262,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_binary)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	cnvlist_free_binary(nvl, cookie);
+	cnvlist_free_binary(cookie);
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1309,7 +1309,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_bool_array)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	cnvlist_free_bool_array(nvl, cookie);
+	cnvlist_free_bool_array(cookie);
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1354,7 +1354,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_number_array)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	cnvlist_free_number_array(nvl, cookie);
+	cnvlist_free_number_array(cookie);
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1396,7 +1396,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_string_array)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	cnvlist_free_string_array(nvl, cookie);
+	cnvlist_free_string_array(cookie);
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
@@ -1459,7 +1459,7 @@ ATF_TEST_CASE_BODY(cnvlist_free_nvlist_array)
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(strcmp(key, nvlist_next(nvl, &type, &cookie)), 0);
-	cnvlist_free_nvlist_array(nvl, cookie);
+	cnvlist_free_nvlist_array(cookie);
 
 	cookie = NULL;
 	ATF_REQUIRE_EQ(nvlist_error(nvl), 0);

Modified: stable/11/lib/libnv/tests/nv_array_tests.cc
==============================================================================
--- stable/11/lib/libnv/tests/nv_array_tests.cc	Mon Jul 16 14:56:30 2018	(r336345)
+++ stable/11/lib/libnv/tests/nv_array_tests.cc	Mon Jul 16 15:02:21 2018	(r336346)
@@ -312,6 +312,7 @@ ATF_TEST_CASE_BODY(nvlist_nvlist_array__basic)
 	for (i = 0; i < num_items; i++) {
 		ATF_REQUIRE_EQ(nvlist_error(result[i]), 0);
 		ATF_REQUIRE(nvlist_get_array_next(result[i]) == NULL);
+		ATF_REQUIRE(nvlist_get_parent(result[i], NULL) == NULL);
 		ATF_REQUIRE(nvlist_get_array_next(const_result[i]) == NULL);
 		ATF_REQUIRE(!nvlist_in_array(const_result[i]));
 	}

Copied: stable/11/lib/libnv/tests/nvlist_append_test.c (from r335347, head/lib/libnv/tests/nvlist_append_test.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/11/lib/libnv/tests/nvlist_append_test.c	Mon Jul 16 15:02:21 2018	(r336346, copy of r335347, head/lib/libnv/tests/nvlist_append_test.c)
@@ -0,0 +1,120 @@
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/nv.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+static int ntest = 1;
+
+#define	CHECK(expr)	do {						\
+	if ((expr))							\
+		printf("ok # %d %s:%u\n", ntest, __FILE__, __LINE__);	\
+	else								\
+		printf("not ok # %d %s:%u\n", ntest, __FILE__, __LINE__);\
+	ntest++;							\
+} while (0)
+
+int
+main(void)
+{
+	const bool *bool_result;
+	const char * const *string_result;
+	const nvlist_t * const *nvl_result;
+	nvlist_t *nvl, *nvl1, *nvl2, **items;
+	unsigned int i;
+	size_t nitems;
+
+	printf("1..32\n");
+
+	nvl = nvlist_create(0);
+
+	for (i = 0; i < 16; i++)
+		nvlist_append_bool_array(nvl, "nvl/bool", i % 2 == 0);
+
+	CHECK(nvlist_error(nvl) == 0);
+	CHECK(!nvlist_empty(nvl));
+	CHECK(nvlist_exists_bool_array(nvl, "nvl/bool"));
+
+	bool_result = nvlist_get_bool_array(nvl, "nvl/bool", &nitems);
+	CHECK(nitems == 16);
+	CHECK(bool_result != NULL);
+	for (i = 0; i < nitems; i++)
+		CHECK(bool_result[i] == (i % 2 == 0));
+
+
+	nvlist_append_string_array(nvl, "nvl/string", "a");
+	nvlist_append_string_array(nvl, "nvl/string", "abc");
+	string_result = nvlist_get_string_array(nvl, "nvl/string", &nitems);
+	CHECK(nitems == 2);
+	CHECK(strcmp(string_result[0], "a") == 0);
+	CHECK(strcmp(string_result[1], "abc") == 0);
+
+
+	nvl1 = nvlist_create(0);
+	nvlist_add_string(nvl1, "key1", "test1");
+	nvlist_append_nvlist_array(nvl, "nvl/nvl", nvl1);
+	nvlist_destroy(nvl1);
+
+	nvl2 = nvlist_create(0);
+	nvlist_add_string(nvl2, "key2", "test2");
+	nvlist_append_nvlist_array(nvl, "nvl/nvl", nvl2);
+	nvlist_destroy(nvl2);
+
+	nvl_result = nvlist_get_nvlist_array(nvl, "nvl/nvl", &nitems);
+	CHECK(nitems == 2);
+	CHECK(strcmp(nvlist_get_string(nvl_result[0], "key1"), "test1") == 0);
+	CHECK(strcmp(nvlist_get_string(nvl_result[1], "key2"), "test2") == 0);
+
+	nvl1 = nvlist_create(0);
+	nvlist_add_number(nvl1, "key1", 10);
+	nvlist_append_nvlist_array(nvl, "nvl/nvl_array", nvl1);
+	nvlist_destroy(nvl1);
+
+	nvl2 = nvlist_create(0);
+	nvlist_add_number(nvl2, "key1", 20);
+	nvlist_append_nvlist_array(nvl, "nvl/nvl_array", nvl2);
+	nvlist_destroy(nvl2);
+
+	items = nvlist_take_nvlist_array(nvl, "nvl/nvl_array", &nitems);
+	CHECK(nvlist_get_number(items[0], "key1") == 10);
+	CHECK(nvlist_get_number(items[1], "key1") == 20);
+	CHECK(nvlist_error(items[0]) == 0);
+	CHECK(nvlist_error(items[1]) == 0);
+
+	nvlist_move_nvlist_array(nvl, "nvl/nvl_new_array", items, nitems);
+	CHECK(nvlist_error(nvl) == 0);
+
+	nvlist_destroy(nvl);
+
+	return (0);
+}

Modified: stable/11/share/man/man9/Makefile
==============================================================================
--- stable/11/share/man/man9/Makefile	Mon Jul 16 14:56:30 2018	(r336345)
+++ stable/11/share/man/man9/Makefile	Mon Jul 16 15:02:21 2018	(r336346)
@@ -57,6 +57,7 @@ MAN=	accept_filter.9 \
 	byteorder.9 \
 	casuword.9 \
 	cd.9 \
+	cnv.9 \
 	condvar.9 \
 	config_intrhook.9 \
 	contigmalloc.9 \
@@ -619,6 +620,41 @@ MLINKS+=byteorder.9 be16dec.9 \
 	byteorder.9 le64dec.9 \
 	byteorder.9 le64enc.9 \
 	byteorder.9 le64toh.9
+MLINKS+=cnv.9 cnvlist.9 \
+	cnv.9 cnvlist_free_binary.9 \
+	cnv.9 cnvlist_free_bool.9 \
+	cnv.9 cnvlist_free_bool_array.9 \
+	cnv.9 cnvlist_free_descriptor.9 \
+	cnv.9 cnvlist_free_descriptor_array.9 \
+	cnv.9 cnvlist_free_null.9 \
+	cnv.9 cnvlist_free_number.9 \
+	cnv.9 cnvlist_free_number_array.9 \
+	cnv.9 cnvlist_free_nvlist.9 \
+	cnv.9 cnvlist_free_nvlist_array.9 \
+	cnv.9 cnvlist_free_string.9 \
+	cnv.9 cnvlist_free_string_array.9 \
+	cnv.9 cnvlist_get_binary.9 \
+	cnv.9 cnvlist_get_bool.9 \
+	cnv.9 cnvlist_get_bool_array.9 \
+	cnv.9 cnvlist_get_descriptor.9 \
+	cnv.9 cnvlist_get_descriptor_array.9 \
+	cnv.9 cnvlist_get_number.9 \
+	cnv.9 cnvlist_get_number_array.9 \
+	cnv.9 cnvlist_get_nvlist.9 \
+	cnv.9 cnvlist_get_nvlist_array.9 \
+	cnv.9 cnvlist_get_string.9 \
+	cnv.9 cnvlist_get_string_array.9 \
+	cnv.9 cnvlist_take_binary.9 \
+	cnv.9 cnvlist_take_bool.9 \
+	cnv.9 cnvlist_take_bool_array.9 \
+	cnv.9 cnvlist_take_descriptor.9 \
+	cnv.9 cnvlist_take_descriptor_array.9 \
+	cnv.9 cnvlist_take_number.9 \
+	cnv.9 cnvlist_take_number_array.9 \
+	cnv.9 cnvlist_take_nvlist.9 \
+	cnv.9 cnvlist_take_nvlist_array.9 \
+	cnv.9 cnvlist_take_string.9 \
+	cnv.9 cnvlist_take_string_array.9
 MLINKS+=condvar.9 cv_broadcast.9 \
 	condvar.9 cv_broadcastpri.9 \
 	condvar.9 cv_destroy.9 \

Copied and modified: stable/11/share/man/man9/cnv.9 (from r304910, head/share/man/man9/cnv.9)
==============================================================================
--- head/share/man/man9/cnv.9	Sat Aug 27 13:47:52 2016	(r304910, copy source)
+++ stable/11/share/man/man9/cnv.9	Mon Jul 16 15:02:21 2018	(r336346)
@@ -25,88 +25,93 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd July 26, 2016
+.Dd June 18, 2018
 .Dt CNV 9
 .Os
 .Sh NAME
-.Nm cnvlist_get,
-.Nm cnvlist_take,
-.Nm cnvlist_free,
+.Nm cnvlist_get ,
+.Nm cnvlist_take ,
+.Nm cnvlist_free
 .Nd "API for managing name/value pairs by cookie."
 .Sh LIBRARY
 .Lb libnv
 .Sh SYNOPSIS
 .In sys/cnv.h
+.Ft const char *
+.Fn cnvlist_name "const void *cookie"
+.Ft int
+.Fn cnvlist_type "const void *cookie"
+.\"
 .Ft bool
-.Fn cnvlist_get_bool "void *cookiep"
+.Fn cnvlist_get_bool "const void *cookie"
 .Ft uint64_t
-.Fn cnvlist_get_number "void *cookiep"
+.Fn cnvlist_get_number "const void *cookie"
 .Ft "const char *"
-.Fn cnvlist_get_string "void *cookiep"
+.Fn cnvlist_get_string "const void *cookie"
 .Ft "const nvlist_t *"
-.Fn cnvlist_get_nvlist "void *cookiep"
+.Fn cnvlist_get_nvlist "const void *cookie"
 .Ft "const void *"
-.Fn cnvlist_get_binary "void *cookiep" "size_t *sizep"
+.Fn cnvlist_get_binary "const void *cookie" "size_t *sizep"
 .Ft "const bool *"
-.Fn cnvlist_get_bool_array "void *cookiep" "size_t *nitemsp"
+.Fn cnvlist_get_bool_array "const void *cookie" "size_t *nitemsp"
 .Ft "const uint64_t *"
-.Fn cnvlist_get_number_array "void *cookiep" "size_t *nitemsp"
+.Fn cnvlist_get_number_array "const void *cookie" "size_t *nitemsp"
 .Ft "const char * const *"
-.Fn cnvlist_get_string_array "void *cookiep" "size_t *nitemsp"
+.Fn cnvlist_get_string_array "const void *cookie" "size_t *nitemsp"
 .Ft "const nvlist_t * const *"
-.Fn cnvlist_get_nvlist_array "void *cookiep" "size_t *nitemsp"
+.Fn cnvlist_get_nvlist_array "const void *cookie" "size_t *nitemsp"
 .Ft int
-.Fn cnvlist_get_descriptor "void *cookiep"
+.Fn cnvlist_get_descriptor "const void *cookie"
 .Ft "const int *"
-.Fn cnvlist_get_descriptor_array "void *cookiep" "size_t *nitemsp"
+.Fn cnvlist_get_descriptor_array "const void *cookie" "size_t *nitemsp"
 .\"
 .Ft bool
-.Fn cnvlist_take_bool "void *cookiep"
+.Fn cnvlist_take_bool "void *cookie"
 .Ft uint64_t
-.Fn cnvlist_take_number "void *cookiep"
+.Fn cnvlist_take_number "void *cookie"
 .Ft "const char *"
-.Fn cnvlist_take_string "void *cookiep"
+.Fn cnvlist_take_string "void *cookie"
 .Ft "const nvlist_t *"
-.Fn cnvlist_take_nvlist "void *cookiep"
+.Fn cnvlist_take_nvlist "void *cookie"
 .Ft "const void *"
-.Fn cnvlist_take_binary "void *cookiep" "size_t *sizep"
+.Fn cnvlist_take_binary "void *cookie" "size_t *sizep"
 .Ft "const bool *"
-.Fn cnvlist_take_bool_array "void *cookiep" "size_t *nitemsp"
+.Fn cnvlist_take_bool_array "void *cookie" "size_t *nitemsp"
 .Ft "const uint64_t *"
-.Fn cnvlist_take_number_array "void *cookiep" "size_t *nitemsp"
+.Fn cnvlist_take_number_array "void *cookie" "size_t *nitemsp"
 .Ft "const char * const *"
-.Fn cnvlist_take_string_array "void *cookiep" "size_t *nitemsp"
+.Fn cnvlist_take_string_array "void *cookie" "size_t *nitemsp"
 .Ft "const nvlist_t * const *"
-.Fn cnvlist_take_nvlist_array "void *cookiep" "size_t *nitemsp"
+.Fn cnvlist_take_nvlist_array "void *cookie" "size_t *nitemsp"
 .Ft int
-.Fn cnvlist_take_descriptor "void *cookiep"
+.Fn cnvlist_take_descriptor "void *cookie"
 .Ft "const int *'
-.Fn cnvlist_take_descriptor_array "void *cookiep" "size_t *nitemsp"
+.Fn cnvlist_take_descriptor_array "void *cookie" "size_t *nitemsp"
 .\"
 .Ft void
-.Fn cnvlist_free_null "nvlist_t *nvl" "void *cookiep"
+.Fn cnvlist_free_null "void *cookie"
 .Ft void
-.Fn cnvlist_free_bool "nvlist_t *nvl" "void *cookiep"
+.Fn cnvlist_free_bool "void *cookie"
 .Ft void
-.Fn cnvlist_free_number "nvlist_t *nvl" "void *cookiep"
+.Fn cnvlist_free_number "void *cookie"
 .Ft void
-.Fn cnvlist_free_string "nvlist_t *nvl" "void *cookiep"
+.Fn cnvlist_free_string "void *cookie"
 .Ft void
-.Fn cnvlist_free_nvlist "nvlist_t *nvl" "void *cookiep"
+.Fn cnvlist_free_nvlist "void *cookie"
 .Ft void
-.Fn cnvlist_free_descriptor "nvlist_t *nvl" "void *cookiep"
+.Fn cnvlist_free_descriptor "void *cookie"
 .Ft void
-.Fn cnvlist_free_binary "nvlist_t *nvl" "void *cookiep"
+.Fn cnvlist_free_binary "void *cookie"
 .Ft void
-.Fn cnvlist_free_bool_array "nvlist_t *nvl" "void *cookiep"
+.Fn cnvlist_free_bool_array "void *cookie"
 .Ft void
-.Fn cnvlist_free_number_array "nvlist_t *nvl" "void *cookiep"
+.Fn cnvlist_free_number_array "void *cookie"
 .Ft void
-.Fn cnvlist_free_string_array "nvlist_t *nvl" "void *cookiep"
+.Fn cnvlist_free_string_array "void *cookie"
 .Ft void
-.Fn cnvlist_free_nvlist_array "nvlist_t *nvl" "void *cookiep"
+.Fn cnvlist_free_nvlist_array "void *cookie"
 .Ft void
-.Fn cnvlist_free_descriptor_array "nvlist_t *nvl" "void *cookiep"
+.Fn cnvlist_free_descriptor_array "void *cookie"
 .Sh DESCRIPTION
 The
 .Nm libnv
@@ -124,6 +129,16 @@ from
 .Xr nv 9 .
 .Pp
 The
+.Fn cnvlist_name
+function returns the name of an element associated with the given cookie.
+.Pp
+The
+.Fn cnvlist_type
+function returns the type of an element associated with the given cookie.
+Types which can be returned are described in
+.Xr nv 9 .
+.Pp
+The
 .Nm cnvlist_get
 family of functions obtains the value associated with the given cookie.
 Returned strings, nvlists, descriptors, binaries, or arrays must not be modified
@@ -177,8 +192,8 @@ while (nvlist_next(nvl, &type, &cookie) != NULL) {
         }
 }
 
-name = cnvlist_take_string(nvl, scookie);
-cnvlist_free_bool(nvl, bcookie);
+name = cnvlist_take_string(scookie);
+cnvlist_free_bool(bcookie);
 
 printf("test2: %s\\n", name);
 free(name);

Modified: stable/11/share/man/man9/nv.9
==============================================================================
--- stable/11/share/man/man9/nv.9	Mon Jul 16 14:56:30 2018	(r336345)
+++ stable/11/share/man/man9/nv.9	Mon Jul 16 15:02:21 2018	(r336346)
@@ -29,7 +29,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd September 16, 2017
+.Dd June 19, 2018
 .Dt NV 9
 .Os
 .Sh NAME
@@ -55,7 +55,8 @@
 .Nm nvlist_add ,
 .Nm nvlist_move ,
 .Nm nvlist_get ,
-.Nm nvlist_take
+.Nm nvlist_take ,
+.Nm nvlist_append
 .Nd "library for name/value pairs"
 .Sh LIBRARY
 .Lb libnv
@@ -239,6 +240,17 @@
 .Fn nvlist_take_descriptor_array "nvlist_t *nvl" "const char *name" "size_t *nitems"
 .\"
 .Ft void
+.Fn nvlist_append_bool_array "nvlist_t *nvl" "const char *name" "const bool value"
+.Ft void
+.Fn nvlist_append_number_array "nvlist_t *nvl" "const char *name" "const uint64_t value"
+.Ft void
+.Fn nvlist_append_string_array "nvlist_t *nvl" "const char *name" "const char * const value"
+.Ft void
+.Fn nvlist_append_nvlist_array "nvlist_t *nvl" "const char *name" "const nvlist_t * const value"
+.Ft void
+.Fn nvlist_append_descriptor_array "nvlist_t *nvl" "const char *name" "int value"
+.\"
+.Ft void
 .Fn nvlist_free "nvlist_t *nvl" "const char *name"
 .Ft void
 .Fn nvlist_free_type "nvlist_t *nvl" "const char *name" "int type"
@@ -708,6 +720,20 @@ the array using the
 .Xr free 3
 function.
 The nvlist must not be in error state.
+.Pp
+The
+.Fn nvlist_append_bool_array ,
+.Fn nvlist_append_number_array ,
+.Fn nvlist_append_string_array ,
+.Fn nvlist_append_nvlist_array ,
+.Fn nvlist_append_descriptor_array
+functions append an element to the existing array using the same semantics
+as the add functions (i.e. the element will be copied when applicable).
+If the array for a given key does not exist, then it will be created
+as if using the
+.Fn nvlist_add_<type>_array
+function.
+The internal error is set on append failure.
 .Pp
 The
 .Fn nvlist_free

Modified: stable/11/share/man/man9/owll.9
==============================================================================
--- stable/11/share/man/man9/owll.9	Mon Jul 16 14:56:30 2018	(r336345)
+++ stable/11/share/man/man9/owll.9	Mon Jul 16 15:02:21 2018	(r336346)
@@ -29,9 +29,9 @@
 .Os
 .Sh NAME
 .Nm owll
-.Nm OWLL_WRITE_ONE,
-.Nm OWLL_WRITE_ZERO,
-.Nm OWLL_READ_DATA,
+.Nm OWLL_WRITE_ONE ,
+.Nm OWLL_WRITE_ZERO ,
+.Nm OWLL_READ_DATA ,
 .Nm OWLL_REASET_AND_PRESENCE
 .Nd Dallas Semiconductor 1-Wire Link Layer Interface
 .Sh SYNOPSIS

Modified: stable/11/share/man/man9/rwlock.9
==============================================================================
--- stable/11/share/man/man9/rwlock.9	Mon Jul 16 14:56:30 2018	(r336345)
+++ stable/11/share/man/man9/rwlock.9	Mon Jul 16 15:02:21 2018	(r336346)
@@ -30,7 +30,7 @@
 .Sh NAME
 .Nm rwlock ,
 .Nm rw_init ,
-.Nm rw_init_flags,
+.Nm rw_init_flags ,
 .Nm rw_destroy ,
 .Nm rw_rlock ,
 .Nm rw_wlock ,

Modified: stable/11/share/man/man9/zone.9
==============================================================================
--- stable/11/share/man/man9/zone.9	Mon Jul 16 14:56:30 2018	(r336345)
+++ stable/11/share/man/man9/zone.9	Mon Jul 16 15:02:21 2018	(r336346)
@@ -35,10 +35,10 @@
 .Nm uma_zfree ,
 .Nm uma_zfree_arg ,
 .Nm uma_zdestroy ,
-.Nm uma_zone_set_max,
-.Nm uma_zone_get_max,
-.Nm uma_zone_get_cur,
-.Nm uma_zone_set_warning,
+.Nm uma_zone_set_max ,
+.Nm uma_zone_get_max ,
+.Nm uma_zone_get_cur ,
+.Nm uma_zone_set_warning ,
 .Nm uma_zone_set_maxaction
 .Nd zone allocator
 .Sh SYNOPSIS

Modified: stable/11/sys/contrib/libnv/cnvlist.c
==============================================================================
--- stable/11/sys/contrib/libnv/cnvlist.c	Mon Jul 16 14:56:30 2018	(r336345)
+++ stable/11/sys/contrib/libnv/cnvlist.c	Mon Jul 16 15:02:21 2018	(r336346)
@@ -53,16 +53,30 @@ __FBSDID("$FreeBSD$");
 #include "nvlist_impl.h"
 #include "nvpair_impl.h"
 
+const char *
+cnvlist_name(const void *cookie)
+{
+
+	return (nvpair_name(cookie));
+}
+
+int
+cnvlist_type(const void *cookie)
+{
+
+	return (nvpair_type(cookie));
+}
+
 #define	CNVLIST_GET(ftype, type, NVTYPE)				\
 ftype									\
-cnvlist_get_##type(void *cookiep)					\
+cnvlist_get_##type(const void *cookie)					\
 {									\
 									\
-	if (nvpair_type(cookiep) != NV_TYPE_##NVTYPE) {			\
+	if (nvpair_type(cookie) != NV_TYPE_##NVTYPE) {			\
 		nvlist_report_missing(NV_TYPE_##NVTYPE,			\
-		    nvpair_name(cookiep));				\
+		    nvpair_name(cookie));				\
 	}								\
-        return (nvpair_get_##type(cookiep));				\
+        return (nvpair_get_##type(cookie));				\
 }
 
 CNVLIST_GET(bool, bool, BOOL)
@@ -77,14 +91,14 @@ CNVLIST_GET(int, descriptor, DESCRIPTOR)
 
 #define	CNVLIST_GET_ARRAY(ftype, type, NVTYPE)				\
 ftype									\
-cnvlist_get_##type(void *cookiep, size_t *nitemsp)			\
+cnvlist_get_##type(const void *cookie, size_t *nitemsp)			\
 {									\
 									\
-	if (nvpair_type(cookiep) != NV_TYPE_##NVTYPE) {			\
+	if (nvpair_type(cookie) != NV_TYPE_##NVTYPE) {			\
 		nvlist_report_missing(NV_TYPE_##NVTYPE,			\
-		    nvpair_name(cookiep));				\
+		    nvpair_name(cookie));				\
 	}								\
-	return (nvpair_get_##type(cookiep, nitemsp));			\
+	return (nvpair_get_##type(cookie, nitemsp));			\
 }
 
 CNVLIST_GET_ARRAY(const bool *, bool_array, BOOL_ARRAY)
@@ -98,27 +112,29 @@ CNVLIST_GET_ARRAY(const int *, descriptor_array, DESCR
 #undef	CNVLIST_GET_ARRAY
 
 const void *
-cnvlist_get_binary(void *cookiep, size_t *sizep)
+cnvlist_get_binary(const void *cookie, size_t *sizep)
 {
 
-	if (nvpair_type(cookiep) != NV_TYPE_BINARY)
-		nvlist_report_missing(NV_TYPE_BINARY, nvpair_name(cookiep));
-	return (nvpair_get_binary(cookiep, sizep));
+	if (nvpair_type(cookie) != NV_TYPE_BINARY)
+		nvlist_report_missing(NV_TYPE_BINARY, nvpair_name(cookie));
+	return (nvpair_get_binary(cookie, sizep));
 }
 
 #define CNVLIST_TAKE(ftype, type, NVTYPE)				\
 ftype									\
-cnvlist_take_##type(nvlist_t *nvl, void *cookiep)			\
+cnvlist_take_##type(void *cookie)					\
 {									\
 	ftype value;							\
+	nvlist_t *nvl;							\
 									\
-	if (nvpair_type(cookiep) != NV_TYPE_##NVTYPE) {			\
+	if (nvpair_type(cookie) != NV_TYPE_##NVTYPE) {			\
 		nvlist_report_missing(NV_TYPE_##NVTYPE,			\
-		    nvpair_name(cookiep));				\
+		    nvpair_name(cookie));				\
 	}								\
-	value = (ftype)(intptr_t)nvpair_get_##type(cookiep);		\
-	nvlist_remove_nvpair(nvl, cookiep);				\
-	nvpair_free_structure(cookiep);					\
+	nvl = nvpair_nvlist(cookie);					\
+	value = (ftype)(intptr_t)nvpair_get_##type(cookie);		\
+	nvlist_remove_nvpair(nvl, cookie);				\
+	nvpair_free_structure(cookie);					\
 	return (value);							\
 }
 
@@ -134,17 +150,19 @@ CNVLIST_TAKE(int, descriptor, DESCRIPTOR)
 
 #define	CNVLIST_TAKE_ARRAY(ftype, type, NVTYPE)				\
 ftype									\
-cnvlist_take_##type(nvlist_t *nvl, void *cookiep, size_t *nitemsp)	\
+cnvlist_take_##type(void *cookie, size_t *nitemsp)			\
 {									\
 	ftype value;							\
+	nvlist_t *nvl;							\
 									\
-	if (nvpair_type(cookiep) != NV_TYPE_##NVTYPE) {			\
+	if (nvpair_type(cookie) != NV_TYPE_##NVTYPE) {			\
 		nvlist_report_missing(NV_TYPE_##NVTYPE,			\
-		    nvpair_name(cookiep));				\
+		    nvpair_name(cookie));				\
 	}								\
-	value = (ftype)(intptr_t)nvpair_get_##type(cookiep, nitemsp);	\
-	nvlist_remove_nvpair(nvl, cookiep);				\
-	nvpair_free_structure(cookiep);					\
+	nvl = nvpair_nvlist(cookie);					\
+	value = (ftype)(intptr_t)nvpair_get_##type(cookie, nitemsp);	\
+	nvlist_remove_nvpair(nvl, cookie);				\
+	nvpair_free_structure(cookie);					\
 	return (value);							\
 }
 
@@ -159,25 +177,27 @@ CNVLIST_TAKE_ARRAY(int *, descriptor_array, DESCRIPTOR
 #undef	CNVLIST_TAKE_ARRAY
 
 void *
-cnvlist_take_binary(nvlist_t *nvl, void *cookiep, size_t *sizep)
+cnvlist_take_binary(void *cookie, size_t *sizep)
 {
 	void *value;
+	nvlist_t *nvl;
 
-	if (nvpair_type(cookiep) != NV_TYPE_BINARY)
-		nvlist_report_missing(NV_TYPE_BINARY, nvpair_name(cookiep));
-	value = (void *)(intptr_t)nvpair_get_binary(cookiep, sizep);
-	nvlist_remove_nvpair(nvl, cookiep);
-	nvpair_free_structure(cookiep);
+	if (nvpair_type(cookie) != NV_TYPE_BINARY)
+		nvlist_report_missing(NV_TYPE_BINARY, nvpair_name(cookie));
+	nvl = nvpair_nvlist(cookie);
+	value = (void *)(intptr_t)nvpair_get_binary(cookie, sizep);
+	nvlist_remove_nvpair(nvl, cookie);
+	nvpair_free_structure(cookie);
 	return (value);
 }
 
 
 #define	CNVLIST_FREE(type)						\
 void									\
-cnvlist_free_##type(nvlist_t *nvl, void *cookiep)			\
+cnvlist_free_##type(void *cookie)					\
 {									\
 									\
-	nvlist_free_nvpair(nvl, cookiep);				\
+	nvlist_free_nvpair(nvpair_nvlist(cookie), cookie);		\
 }
 
 CNVLIST_FREE(bool)

Modified: stable/11/sys/contrib/libnv/nv_impl.h
==============================================================================
--- stable/11/sys/contrib/libnv/nv_impl.h	Mon Jul 16 14:56:30 2018	(r336345)
+++ stable/11/sys/contrib/libnv/nv_impl.h	Mon Jul 16 15:02:21 2018	(r336346)
@@ -51,7 +51,7 @@ typedef struct nvpair nvpair_t;
 
 #ifdef _KERNEL
 #define	nv_malloc(size)			malloc((size), M_NVLIST, M_WAITOK)
-#define	nv_calloc(n, size)		malloc((n) * (size), M_NVLIST, \
+#define	nv_calloc(n, size)		mallocarray((n), (size), M_NVLIST, \
 					    M_WAITOK | M_ZERO)
 #define	nv_realloc(buf, size)		realloc((buf), (size), M_NVLIST, \
 					    M_WAITOK)
@@ -140,6 +140,12 @@ nvpair_t *nvpair_move_nvlist_array(const char *name, n
 nvpair_t *nvpair_move_descriptor_array(const char *name, int *value, size_t nitems);
 nvpair_t *nvpair_move_number_array(const char *name, uint64_t *value, size_t nitems);
 nvpair_t *nvpair_move_string_array(const char *name, char **value, size_t nitems);
+
+int nvpair_append_bool_array(nvpair_t *nvp, const bool value);
+int nvpair_append_number_array(nvpair_t *nvp, const uint64_t value);
+int nvpair_append_string_array(nvpair_t *nvp, const char *value);
+int nvpair_append_nvlist_array(nvpair_t *nvp, const nvlist_t *value);
+int nvpair_append_descriptor_array(nvpair_t *nvp, const int value);
 
 bool			 nvpair_get_bool(const nvpair_t *nvp);
 uint64_t		 nvpair_get_number(const nvpair_t *nvp);

Modified: stable/11/sys/contrib/libnv/nvlist.c
==============================================================================
--- stable/11/sys/contrib/libnv/nvlist.c	Mon Jul 16 14:56:30 2018	(r336345)
+++ stable/11/sys/contrib/libnv/nvlist.c	Mon Jul 16 15:02:21 2018	(r336346)
@@ -1606,6 +1606,37 @@ NVLIST_ADD_ARRAY(const int *, descriptor)
 
 #undef	NVLIST_ADD_ARRAY
 
+#define	NVLIST_APPEND_ARRAY(vtype, type, TYPE)				\
+void									\
+nvlist_append_##type##_array(nvlist_t *nvl, const char *name, vtype value)\
+{									\
+	nvpair_t *nvp;							\
+									\
+	if (nvlist_error(nvl) != 0) {					\
+		ERRNO_SET(nvlist_error(nvl));				\
+		return;							\
+	}								\
+	nvp = nvlist_find(nvl, NV_TYPE_##TYPE##_ARRAY, name);		\
+	if (nvp == NULL) {						\
+		nvlist_add_##type##_array(nvl, name, &value, 1);	\
+		return;							\
+	}								\
+	if (nvpair_append_##type##_array(nvp, value) == -1) {		\
+		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);		\
+		ERRNO_SET(nvl->nvl_error);				\
+	}								\
+}
+
+NVLIST_APPEND_ARRAY(const bool, bool, BOOL)
+NVLIST_APPEND_ARRAY(const uint64_t, number, NUMBER)
+NVLIST_APPEND_ARRAY(const char *, string, STRING)
+NVLIST_APPEND_ARRAY(const nvlist_t *, nvlist, NVLIST)
+#ifndef _KERNEL
+NVLIST_APPEND_ARRAY(const int, descriptor, DESCRIPTOR)
+#endif
+
+#undef	NVLIST_APPEND_ARRAY
+
 bool
 nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp)
 {

Modified: stable/11/sys/contrib/libnv/nvpair.c
==============================================================================
--- stable/11/sys/contrib/libnv/nvpair.c	Mon Jul 16 14:56:30 2018	(r336345)
+++ stable/11/sys/contrib/libnv/nvpair.c	Mon Jul 16 15:02:21 2018	(r336346)
@@ -142,6 +142,28 @@ nvpair_allocv(const char *name, int type, uint64_t dat
 	return (nvp);
 }
 
+static int
+nvpair_append(nvpair_t *nvp, const void *value, size_t valsize, size_t datasize)
+{
+	void *olddata, *data, *valp;
+	size_t oldlen;
+
+	oldlen = nvp->nvp_nitems * valsize;
+	olddata = (void *)(uintptr_t)nvp->nvp_data;
+	data = nv_realloc(olddata, oldlen + valsize);
+	if (data == NULL) {
+		ERRNO_SET(ENOMEM);
+		return (-1);
+	}
+	valp = (unsigned char *)data + oldlen;
+	memcpy(valp, value, valsize);
+
+	nvp->nvp_data = (uint64_t)(uintptr_t)data;
+	nvp->nvp_datasize += datasize;
+	nvp->nvp_nitems++;
+	return (0);
+}
+
 nvlist_t *
 nvpair_nvlist(const nvpair_t *nvp)
 {
@@ -204,8 +226,10 @@ nvpair_remove_nvlist_array(nvpair_t *nvp)
 	/* XXX: DECONST is bad, mkay? */
 	nvlarray = __DECONST(nvlist_t **,
 	    nvpair_get_nvlist_array(nvp, &count));
-	for (i = 0; i < count; i++)
+	for (i = 0; i < count; i++) {
 		nvlist_set_array_next(nvlarray[i], NULL);
+		nvlist_set_parent(nvlarray[i], NULL);
+	}
 }
 
 void
@@ -1906,6 +1930,122 @@ nvpair_get_descriptor_array(const nvpair_t *nvp, size_
 		*nitems = nvp->nvp_nitems;
 
 	return ((const int *)(intptr_t)nvp->nvp_data);
+}
+#endif
+
+int
+nvpair_append_bool_array(nvpair_t *nvp, const bool value)
+{
+
+	NVPAIR_ASSERT(nvp);
+	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BOOL_ARRAY);
+	return (nvpair_append(nvp, &value, sizeof(value), sizeof(value)));
+}
+
+int
+nvpair_append_number_array(nvpair_t *nvp, const uint64_t value)
+{
+
+	NVPAIR_ASSERT(nvp);
+	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NUMBER_ARRAY);
+	return (nvpair_append(nvp, &value, sizeof(value), sizeof(value)));
+}
+
+int
+nvpair_append_string_array(nvpair_t *nvp, const char *value)
+{
+	char *str;
+
+	NVPAIR_ASSERT(nvp);
+	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_STRING_ARRAY);
+	if (value == NULL) {
+		ERRNO_SET(EINVAL);
+		return (-1);
+	}
+	str = nv_strdup(value);
+	if (str == NULL) {
+		return (-1);
+	}
+	if (nvpair_append(nvp, &str, sizeof(str), strlen(str) + 1) == -1) {
+		nv_free(str);
+		return (-1);
+	}
+	return (0);
+}
+
+int
+nvpair_append_nvlist_array(nvpair_t *nvp, const nvlist_t *value)
+{
+	nvpair_t *tmpnvp;
+	nvlist_t *nvl, *prev;
+	int flags;
+
+	NVPAIR_ASSERT(nvp);
+	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NVLIST_ARRAY);
+	if (value == NULL || nvlist_error(value) != 0 ||
+	    nvlist_get_pararr(value, NULL) != NULL) {
+		ERRNO_SET(EINVAL);
+		return (-1);
+	}
+	nvl = nvlist_clone(value);
+	if (nvl == NULL) {
+		return (-1);
+	}
+	flags = nvlist_flags(nvl) | NV_FLAG_IN_ARRAY;
+	nvlist_set_flags(nvl, flags);
+
+	tmpnvp = NULL;
+	prev = NULL;
+	if (nvp->nvp_nitems > 0) {
+		nvlist_t **nvls = (void *)(uintptr_t)nvp->nvp_data;
+
+		prev = nvls[nvp->nvp_nitems - 1];
+		PJDLOG_ASSERT(prev != NULL);
+
+		tmpnvp = nvpair_allocv(" ", NV_TYPE_NVLIST,
+		    (uint64_t)(uintptr_t)nvl, 0, 0);
+		if (tmpnvp == NULL) {
+			goto fail;
+		}
+	}
+	if (nvpair_append(nvp, &nvl, sizeof(nvl), 0) == -1) {
+		goto fail;
+	}
+	if (tmpnvp) {
+		NVPAIR_ASSERT(tmpnvp);
+		nvlist_set_array_next(prev, tmpnvp);
+	}
+	nvlist_set_parent(nvl, nvp);
+	return (0);
+fail:
+	if (tmpnvp) {
+		nvpair_free(tmpnvp);
+	}
+	nvlist_destroy(nvl);
+	return (-1);
+}
+
+#ifndef _KERNEL

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201807161502.w6GF2LXw050533>