From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Wilcox Subject: [PATCH v10 13/62] xarray: Add xa_destroy Date: Thu, 29 Mar 2018 20:41:56 -0700 Message-ID: <20180330034245.10462-14-willy@infradead.org> References: <20180330034245.10462-1-willy@infradead.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=I5spoRkQI9bHYtbJrx7+6RehfRR8T5y+1gxY9jEReTk=; b=Honbr70y09/LKcqggBluYKQN9P 0s/Uicd88iZgwnKX0tbUQxpqMaZIftBaToipwo5pHB+qRcNvQWgemrJ2oDzqje61SYzRSiT4E6Ybs Ts9LmI3TvVSb0RQpoyxoeIBG0YAcMa49/uR0kbrcJQDoOVMqWa5XgnDd9rjWHIFnDGxI=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To :MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=I5spoRkQI9bHYtbJrx7+6RehfRR8T5y+1gxY9jEReTk=; b=jxXcjHIZzWVAOcLtbrxdE9EkUp gOUZQBcesfiTw1bLxrwjPC9ELUpuO1mYnn3lgcBlQsbURSexZrAAPKblfRSf2gTmjdRwBu4jHp0RO lvLeb5h3AKCK306fjYSAhUu29VJb1gIlPbB8J3bImL0Te3QZnpibC+oHaWVT1USebyC0=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=I5spoRkQI9bHYtbJrx7+6RehfRR8T5y+1gxY9jEReTk=; b=OXPMrO7FEf2Y6pqqRxHVEfmrR mf9+zwj9RX5OvLLxOj9Xsr8hw2xLqI3DVRluCVmpBbsjluwWLaYVStIXbYcwL8yPQASV+wFXZzWVw AAPitZSEP1M9uc7g73mr4LRle67HbN+NDQo+SPP6h5K7KuXE8FZTBsb988hmpulN8/iGtjxjTxzti vHAuyN4S2EChhnlXq/Y8PZykkCyiUPow8/+PpBOQN9qOSHD+L/PORCaFkMllaIgGaFVwNR1mbZfwz FFhb885+XuWcVNROsnvrNpCoVuvruRLkEmznJ5UoUES0jClqSzB+MzuQfNBRpxcSOSB/A4sADGNpk GDkTxuY5A==; In-Reply-To: <20180330034245.10462-1-willy@infradead.org> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Cc: linux-nilfs@vger.kernel.org, Jan Kara , Jeff Layton , Matthew Wilcox , James Simmons , Jaegeuk Kim , Andreas Dilger , Nicholas Piggin , linux-f2fs-devel@lists.sourceforge.net, Oleg Drokin , Ryusuke Konishi , Lukas Czerner , Ross Zwisler , Christoph Hellwig , Goldwyn Rodrigues , Mike Kravetz From: Matthew Wilcox This function frees all the internal memory allocated to the xarray and reinitialises it to be empty. Signed-off-by: Matthew Wilcox --- include/linux/xarray.h | 1 + lib/xarray.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/linux/xarray.h b/include/linux/xarray.h index 864f16660785..cd451a293905 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h @@ -229,6 +229,7 @@ void *xa_find_after(struct xarray *xa, unsigned long *index, unsigned long max, xa_tag_t) __attribute__((nonnull(2))); unsigned int xa_extract(struct xarray *, void **dst, unsigned long start, unsigned long max, unsigned int n, xa_tag_t); +void xa_destroy(struct xarray *); /** * xa_init() - Initialise an empty XArray. diff --git a/lib/xarray.c b/lib/xarray.c index 77133bc5419f..940d22d8e76c 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1482,6 +1482,34 @@ unsigned int xa_extract(struct xarray *xa, void **dst, unsigned long start, } EXPORT_SYMBOL(xa_extract); +/** + * xa_destroy() - Free all internal data structures. + * @xa: XArray. + * + * After calling this function, the XArray is empty and has freed all memory + * allocated for its internal data structures. You are responsible for + * freeing the objects referenced by the XArray. + * + * Context: Any context. Takes and releases the xa_lock, interrupt-safe. + */ +void xa_destroy(struct xarray *xa) +{ + XA_STATE(xas, xa, 0); + unsigned long flags; + void *entry; + + xas.xa_node = NULL; + xas_lock_irqsave(&xas, flags); + entry = xa_head_locked(xa); + RCU_INIT_POINTER(xa->xa_head, NULL); + xas_init_tags(&xas); + /* lockdep checks we're still holding the lock in xas_free_nodes() */ + if (xa_is_node(entry)) + xas_free_nodes(&xas, xa_to_node(entry)); + xas_unlock_irqrestore(&xas, flags); +} +EXPORT_SYMBOL(xa_destroy); + #ifdef XA_DEBUG void xa_dump_node(const struct xa_node *node) { -- 2.16.2 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot