All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gargi Sharma <gs051095@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: riel@surriel.com, julia.lawall@lip6.fr,
	akpm@linux-foundation.org, mingo@kernel.org,
	pasha.tatashin@oracle.com, ktkhai@virtuozzo.com, oleg@redhat.com,
	Gargi Sharma <gs051095@gmail.com>
Subject: [PATCH 2/4] idr: Add a function idr_get()
Date: Mon, 25 Sep 2017 08:56:16 -0400	[thread overview]
Message-ID: <6d2d9a99d9047a38ae3b8442e537e76c54511c51.1506342921.git.gs051095@gmail.com> (raw)
In-Reply-To: <cover.1506342921.git.gs051095@gmail.com>
In-Reply-To: <cover.1506342921.git.gs051095@gmail.com>

idr_get(namespace, id) returns a NULL if id is not present
in the idr tree or returns the pointer to the struct if id is
present in the idr tree. With this function in the idr library,
code for pid allocation can be simplified by calling this function
instead of looking through the pidhash.

Signed-off-by: Gargi Sharma <gs051095@gmail.com>
---
 include/linux/idr.h |  1 +
 lib/idr.c           | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/include/linux/idr.h b/include/linux/idr.h
index 7c3a365..e12b174 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -135,6 +135,7 @@ int idr_for_each(const struct idr *,
 		 int (*fn)(int id, void *p, void *data), void *data);
 void *idr_get_next(struct idr *, int *nextid);
 void *idr_get_next_ext(struct idr *idr, unsigned long *nextid);
+void *idr_get(struct idr *idr, int *id);
 void *idr_replace(struct idr *, void *, int id);
 void *idr_replace_ext(struct idr *idr, void *ptr, unsigned long id);
 void idr_destroy(struct idr *);
diff --git a/lib/idr.c b/lib/idr.c
index f9adf48..bb76400 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -135,6 +135,17 @@ void *idr_get_next_ext(struct idr *idr, unsigned long *nextid)
 }
 EXPORT_SYMBOL(idr_get_next_ext);
 
+void * idr_get(struct idr *idr, int *id)
+{
+	struct radix_tree_node *node;
+	void __rcu **slot = NULL;
+
+	__radix_tree_lookup(&idr->idr_rt, *id, &node, &slot);
+	if (!slot)
+		return NULL;
+	return node;
+}
+
 /**
  * idr_replace - replace pointer for given id
  * @idr: idr handle
-- 
2.7.4

  parent reply	other threads:[~2017-09-25 12:57 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-25 12:56 [PATCH 0/4] Replace PID bitmap with IDR API implementation Gargi Sharma
2017-09-25 12:56 ` [PATCH 1/4] pid: Replace pid bitmap implementation with IDR API Gargi Sharma
2017-09-25 13:09   ` Rik van Riel
2017-09-25 14:59   ` Oleg Nesterov
2017-09-25 17:41     ` Gargi Sharma
2017-09-25 15:20   ` Oleg Nesterov
2017-09-25 17:41     ` Gargi Sharma
2017-09-25 12:56 ` Gargi Sharma [this message]
2017-09-25 13:20   ` [PATCH 2/4] idr: Add a function idr_get() Rik van Riel
2017-09-25 13:47     ` Christoph Hellwig
2017-09-25 14:12   ` Oleg Nesterov
2017-09-25 17:43     ` Gargi Sharma
2017-09-25 12:56 ` [PATCH 3/4] pid.c: Replace pidhash lookup with idr_get() Gargi Sharma
2017-09-25 13:20   ` Rik van Riel
2017-09-25 17:44     ` Gargi Sharma
2017-09-25 19:30       ` Rik van Riel
2017-09-25 12:56 ` [PATCH 4/4] pid: Remove pidhash Gargi Sharma
2017-09-25 13:48   ` Rik van Riel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6d2d9a99d9047a38ae3b8442e537e76c54511c51.1506342921.git.gs051095@gmail.com \
    --to=gs051095@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=julia.lawall@lip6.fr \
    --cc=ktkhai@virtuozzo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=pasha.tatashin@oracle.com \
    --cc=riel@surriel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.