Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4254094imm; Mon, 11 Jun 2018 09:17:55 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJDCxN0b1dRk27DUQqI3VfBLKwUM7gVlpRqS/Q886uBzWKqr9uXFkCoc27RkpftVP4UYW3g X-Received: by 2002:a62:3c15:: with SMTP id j21-v6mr18342210pfa.7.1528733874961; Mon, 11 Jun 2018 09:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528733874; cv=none; d=google.com; s=arc-20160816; b=yuaUn4KcX1XcH/jyiwxbIb0FupzKmnYY5EcZwmDpIjv//cos6GkGx/Um6nhCQz3rwV N7YmJIzhkrnzwWjLpAfMNibdtYZn9epnBw5HyjHiRpZ1t9RohAhe3M+jzLWE81cBnaro DsG1hNgh9kkmnEYBAmkZ23tKkwSWbuXeY5qOLHmKAklIZh7lFK+Qs+GLQboP8ym2S4qt E3p4HLTDZSY/yCoEtGOA6chrHUnCIrUyKFj2TrB7M13CwC73Vw3hqlF4aMit1gsuwcrS hKMT8L/JMXs3F0ttSLnjIQGmNsYxO9Pm9HG7vZRW0mA4XjzRafHZt2Fx1mEawMAzPOio sCZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=nbY05u5jx+2zgCzyQJUXznqPWLWRJUQUQdOdMyGJxM0=; b=g39x5JHpH6E4TNXpbhhExRmxXso/dMZtL8My1gKBMTIMuMmK44wtPllUhjjdT4Ehw6 /K7ofp8QlDNpl0YRWow1PnIFzO1Gaq6p3Wry/9ZHTvI1HWtq8/QbQCmYLobAigIKTfym pmqjXtlxy/BoP5OGcMJVSrLrxd0RHBYow+NjxkHIslz8ezVnAxim4YdnMHaEYjOkOjxq LREL2q99hOO16oyEN254T2KTOB2BC/PdWjiShN+I6Kv9FL3fe0l1BN8wbs5CRjjPW/+X 7cmcmApL+VD1RtNtyCWiuu4GSwkCAzTQc9iVH1bL9zowVQzNgWftKg4Ux2igsndA2PxQ Vv7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=g/V8+Pfo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w28-v6si24799707pge.329.2018.06.11.09.17.40; Mon, 11 Jun 2018 09:17:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=g/V8+Pfo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934162AbeFKOWI (ORCPT + 99 others); Mon, 11 Jun 2018 10:22:08 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:44972 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933469AbeFKOGp (ORCPT ); Mon, 11 Jun 2018 10:06:45 -0400 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=nbY05u5jx+2zgCzyQJUXznqPWLWRJUQUQdOdMyGJxM0=; b=g/V8+PfoP8BltXy7w9VxGblMc bHxjfhX2P31FEMyWo9VMWyvAnNJNnZVUCjyZovcJw03DPkveKbIBNwpsX6ujCgnKZ9v/50TyDJtPh yxMElhWR1fnHBSInlF1ezsyQwQ7imvbb+tyup3agX8SistDby+PvtlYAUa0IY1/YQgLxZWhP0bn1c YgxIwj6HIKAGafE1yEuomIXBO3rl99flAOwx2u9zupkAQDVKkI1I1iJp0Vhz9CYWuF+RTJjl7ppHh Y9LOKwxJ/tc5zJEnOpp2pCG5vRHGHReR4laDC44DPiq7QDBSQv4UHEGv126D2cC7p1Mp296YHITuH NasiHLpoQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSNT3-0004aN-6U; Mon, 11 Jun 2018 14:06:45 +0000 From: Matthew Wilcox To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Jan Kara , Jeff Layton , Lukas Czerner , Ross Zwisler , Christoph Hellwig , Goldwyn Rodrigues , Nicholas Piggin , Ryusuke Konishi , linux-nilfs@vger.kernel.org, Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH v13 14/72] xarray: Add xa_destroy Date: Mon, 11 Jun 2018 07:05:41 -0700 Message-Id: <20180611140639.17215-15-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180611140639.17215-1-willy@infradead.org> References: <20180611140639.17215-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 3764f4b4c1a8..6273dd222fda 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 c3a53f09aa88..c505084ad43a 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1507,6 +1507,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.17.1