Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Jun 2018 07:44:54 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@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: r334764 - in stable/11/sys/compat/linuxkpi/common: include/linux src
Message-ID:  <201806070744.w577isDg061951@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <johalun0@gmail.com>
  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



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