From owner-svn-src-head@freebsd.org Thu May 31 12:35:23 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 06A2CF7B259; Thu, 31 May 2018 12:35:23 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AA1038288E; Thu, 31 May 2018 12:35:22 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 873B21A3EF; Thu, 31 May 2018 12:35:22 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w4VCZMWr064396; Thu, 31 May 2018 12:35:22 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w4VCZM0e064394; Thu, 31 May 2018 12:35:22 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201805311235.w4VCZM0e064394@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 31 May 2018 12:35:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334423 - in head/sys/compat/linuxkpi/common: include/linux src X-SVN-Group: head X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: in head/sys/compat/linuxkpi/common: include/linux src X-SVN-Commit-Revision: 334423 X-SVN-Commit-Repository: base 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.26 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: Thu, 31 May 2018 12:35:23 -0000 Author: hselasky Date: Thu May 31 12:35:21 2018 New Revision: 334423 URL: https://svnweb.freebsd.org/changeset/base/334423 Log: Implement idr_is_empty() in the LinuxKPI and make idr_remove() API compatible with upstream Linux by returning the pointer to the removed element. Submitted by: Johannes Lundberg MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/compat/linuxkpi/common/include/linux/idr.h head/sys/compat/linuxkpi/common/src/linux_idr.c Modified: head/sys/compat/linuxkpi/common/include/linux/idr.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/idr.h Thu May 31 12:10:30 2018 (r334422) +++ head/sys/compat/linuxkpi/common/include/linux/idr.h Thu May 31 12:35:21 2018 (r334423) @@ -79,11 +79,12 @@ void idr_preload(gfp_t gfp_mask); void idr_preload_end(void); void *idr_find(struct idr *idp, int id); void *idr_get_next(struct idr *idp, int *nextid); +bool idr_is_empty(struct idr *idp); int idr_pre_get(struct idr *idp, gfp_t gfp_mask); int idr_get_new(struct idr *idp, void *ptr, int *id); int idr_get_new_above(struct idr *idp, void *ptr, int starting_id, int *id); void *idr_replace(struct idr *idp, void *ptr, int id); -void idr_remove(struct idr *idp, int id); +void *idr_remove(struct idr *idp, int id); void idr_remove_all(struct idr *idp); void idr_destroy(struct idr *idp); void idr_init(struct idr *idp); Modified: head/sys/compat/linuxkpi/common/src/linux_idr.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_idr.c Thu May 31 12:10:30 2018 (r334422) +++ head/sys/compat/linuxkpi/common/src/linux_idr.c Thu May 31 12:35:21 2018 (r334423) @@ -218,10 +218,11 @@ idr_remove_all(struct idr *idr) mtx_unlock(&idr->lock); } -static void +static void * idr_remove_locked(struct idr *idr, int id) { struct idr_layer *il; + void *res; int layer; int idx; @@ -229,7 +230,7 @@ idr_remove_locked(struct idr *idr, int id) il = idr->top; layer = idr->layers - 1; if (il == NULL || id > idr_max(idr)) - return; + return (NULL); /* * Walk down the tree to this item setting bitmaps along the way * as we know at least one item will be free along this path. @@ -249,16 +250,23 @@ idr_remove_locked(struct idr *idr, int id) if (il == NULL || (il->bitmap & (1 << idx)) != 0) panic("idr_remove: Item %d not allocated (%p, %p)\n", id, idr, il); + res = il->ary[idx]; il->ary[idx] = NULL; il->bitmap |= 1 << idx; + + return (res); } -void +void * idr_remove(struct idr *idr, int id) { + void *res; + mtx_lock(&idr->lock); - idr_remove_locked(idr, id); + res = idr_remove_locked(idr, id); mtx_unlock(&idr->lock); + + return (res); } @@ -713,6 +721,20 @@ int idr_for_each(struct idr *idp, int (*f)(int id, void *p, void *data), void *data) { return (idr_for_each_layer(idp->top, 0, idp->layers - 1, f, data)); +} + +static int +idr_has_entry(int id, void *p, void *data) +{ + + return (1); +} + +bool +idr_is_empty(struct idr *idp) +{ + + return (idr_for_each(idp, idr_has_entry, NULL) == 0); } int