From owner-svn-src-all@freebsd.org Thu Jun 7 07:47:02 2018 Return-Path: Delivered-To: svn-src-all@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 DD0FDFD3A0E; Thu, 7 Jun 2018 07:47:01 +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 3815B832D8; Thu, 7 Jun 2018 07:44:55 +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 1A79D1D463; Thu, 7 Jun 2018 07:44:55 +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 w577isft061953; Thu, 7 Jun 2018 07:44:54 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w577isDg061951; Thu, 7 Jun 2018 07:44:54 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201806070744.w577isDg061951@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 7 Jun 2018 07:44:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r334764 - in stable/11/sys/compat/linuxkpi/common: include/linux src X-SVN-Group: stable-11 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: in stable/11/sys/compat/linuxkpi/common: include/linux src X-SVN-Commit-Revision: 334764 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jun 2018 07:47:02 -0000 Author: hselasky Date: Thu Jun 7 07:44:54 2018 New Revision: 334764 URL: https://svnweb.freebsd.org/changeset/base/334764 Log: MFC r334423: 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 Sponsored by: Mellanox Technologies Modified: stable/11/sys/compat/linuxkpi/common/include/linux/idr.h stable/11/sys/compat/linuxkpi/common/src/linux_idr.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/compat/linuxkpi/common/include/linux/idr.h ============================================================================== --- stable/11/sys/compat/linuxkpi/common/include/linux/idr.h Thu Jun 7 07:43:58 2018 (r334763) +++ stable/11/sys/compat/linuxkpi/common/include/linux/idr.h Thu Jun 7 07:44:54 2018 (r334764) @@ -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: stable/11/sys/compat/linuxkpi/common/src/linux_idr.c ============================================================================== --- stable/11/sys/compat/linuxkpi/common/src/linux_idr.c Thu Jun 7 07:43:58 2018 (r334763) +++ stable/11/sys/compat/linuxkpi/common/src/linux_idr.c Thu Jun 7 07:44:54 2018 (r334764) @@ -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