From owner-svn-src-head@FreeBSD.ORG Sat May 2 18:03:49 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E2B24691; Sat, 2 May 2015 18:03:48 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D0B2D12B9; Sat, 2 May 2015 18:03:48 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t42I3m6a005939; Sat, 2 May 2015 18:03:48 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t42I3lcD005934; Sat, 2 May 2015 18:03:47 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201505021803.t42I3lcD005934@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski Date: Sat, 2 May 2015 18:03:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r282347 - in head: lib/libnv sys/kern sys/sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 May 2015 18:03:49 -0000 Author: oshogbo Date: Sat May 2 18:03:47 2015 New Revision: 282347 URL: https://svnweb.freebsd.org/changeset/base/282347 Log: Introduce the NV_FLAG_NO_UNIQUE flag. When set, it allows to store multiple values using the same key in a nvlist. Approved by: pjd (mentor) Obtained from: WHEEL Systems (http://www.wheelsystems.com) Update man page. Reviewed by: AllanJude Approved by: pjd (mentor) Modified: head/lib/libnv/nv.3 head/sys/kern/subr_nvlist.c head/sys/kern/subr_nvpair.c head/sys/sys/nv.h Modified: head/lib/libnv/nv.3 ============================================================================== --- head/lib/libnv/nv.3 Sat May 2 17:45:52 2015 (r282346) +++ head/lib/libnv/nv.3 Sat May 2 18:03:47 2015 (r282347) @@ -232,6 +232,8 @@ The following flag can be provided: .Bl -tag -width "NV_FLAG_IGNORE_CASE" -compact -offset indent .It Dv NV_FLAG_IGNORE_CASE Perform case-insensitive lookups of provided names. +.It Dv NV_FLAG_NO_UNIQUE +Names in the nvlist do not have to be unique. .El .Pp The Modified: head/sys/kern/subr_nvlist.c ============================================================================== --- head/sys/kern/subr_nvlist.c Sat May 2 17:45:52 2015 (r282346) +++ head/sys/kern/subr_nvlist.c Sat May 2 18:03:47 2015 (r282347) @@ -88,7 +88,7 @@ __FBSDID("$FreeBSD$"); #endif #define NV_FLAG_PRIVATE_MASK (NV_FLAG_BIG_ENDIAN) -#define NV_FLAG_PUBLIC_MASK (NV_FLAG_IGNORE_CASE) +#define NV_FLAG_PUBLIC_MASK (NV_FLAG_IGNORE_CASE | NV_FLAG_NO_UNIQUE) #define NV_FLAG_ALL_MASK (NV_FLAG_PRIVATE_MASK | NV_FLAG_PUBLIC_MASK) #define NVLIST_MAGIC 0x6e766c /* "nvl" */ @@ -1074,10 +1074,12 @@ nvlist_add_nvpair(nvlist_t *nvl, const n ERRNO_SET(nvlist_error(nvl)); return; } - if (nvlist_exists(nvl, nvpair_name(nvp))) { - nvl->nvl_error = EEXIST; - ERRNO_SET(nvlist_error(nvl)); - return; + if ((nvl->nvl_flags & NV_FLAG_NO_UNIQUE) == 0) { + if (nvlist_exists(nvl, nvpair_name(nvp))) { + nvl->nvl_error = EEXIST; + ERRNO_SET(nvlist_error(nvl)); + return; + } } newnvp = nvpair_clone(nvp); @@ -1266,11 +1268,13 @@ nvlist_move_nvpair(nvlist_t *nvl, nvpair ERRNO_SET(nvlist_error(nvl)); return; } - if (nvlist_exists(nvl, nvpair_name(nvp))) { - nvpair_free(nvp); - nvl->nvl_error = EEXIST; - ERRNO_SET(nvl->nvl_error); - return; + if ((nvl->nvl_flags & NV_FLAG_NO_UNIQUE) == 0) { + if (nvlist_exists(nvl, nvpair_name(nvp))) { + nvpair_free(nvp); + nvl->nvl_error = EEXIST; + ERRNO_SET(nvl->nvl_error); + return; + } } nvpair_insert(&nvl->nvl_head, nvp, nvl); Modified: head/sys/kern/subr_nvpair.c ============================================================================== --- head/sys/kern/subr_nvpair.c Sat May 2 17:45:52 2015 (r282346) +++ head/sys/kern/subr_nvpair.c Sat May 2 18:03:47 2015 (r282347) @@ -143,7 +143,8 @@ nvpair_insert(struct nvl_head *head, nvp NVPAIR_ASSERT(nvp); PJDLOG_ASSERT(nvp->nvp_list == NULL); - PJDLOG_ASSERT(!nvlist_exists(nvl, nvpair_name(nvp))); + PJDLOG_ASSERT((nvlist_flags(nvl) & NV_FLAG_NO_UNIQUE) != 0 || + !nvlist_exists(nvl, nvpair_name(nvp))); TAILQ_INSERT_TAIL(head, nvp, nvp_next); nvp->nvp_list = nvl; Modified: head/sys/sys/nv.h ============================================================================== --- head/sys/sys/nv.h Sat May 2 17:45:52 2015 (r282346) +++ head/sys/sys/nv.h Sat May 2 18:03:47 2015 (r282347) @@ -64,6 +64,10 @@ typedef struct nvlist nvlist_t; * Perform case-insensitive lookups of provided names. */ #define NV_FLAG_IGNORE_CASE 0x01 +/* + * Names don't have to be unique. + */ +#define NV_FLAG_NO_UNIQUE 0x02 #if defined(_KERNEL) && defined(MALLOC_DECLARE) MALLOC_DECLARE(M_NVLIST);