Date: Thu, 31 May 2018 12:35:22 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> 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 Message-ID: <201805311235.w4VCZM0e064394@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <johalun0@gmail.com> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201805311235.w4VCZM0e064394>