Received: by 10.213.65.68 with SMTP id h4csp361680imn; Tue, 13 Mar 2018 06:48:21 -0700 (PDT) X-Google-Smtp-Source: AG47ELsungaqUa8oAxCPkZZy2qL9n784qps7wWIUjUvMak1M5Gs5QfPkbFlAvCs7Veb162+nvIz/ X-Received: by 10.99.64.3 with SMTP id n3mr583402pga.316.1520948901552; Tue, 13 Mar 2018 06:48:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520948901; cv=none; d=google.com; s=arc-20160816; b=i7OqTjJgFUQ+c2oHNvboHIvQeardRZ3e0zw3gGboAzUon4WkQdTD1/WMvCihyiSgqj 7RyEjb8gWt41jXs1f/xxf6cjI7M/i8eu/qglHDROC4T/i0GaE6D7Vpmm4gyLDYcJ3/M9 FWtliPzV3k4/YwSnTHwYAo3u9FTpwXL+W5ZCjQzo0IYjTCMBq36l37TNpxAchZs8I5oN As8EtgMzTEq8aE6DmHBsBbCZSx9C39NnLS6deJkIjEIMpJAEcfU+nbBQeU6YVVav/T8p hcoUIC+wxBfwm2pnZkc5Nb95fzAu5Carzi3P+MP5ROfaeycqAh/YTV+GVG0RFyxr3NsA Tyaw== 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=aH4yrtv2qE3HK2kXGA2/w1w6dA7MUpr29nVQLaLiphU=; b=aCunVs4Jxc8dYgVTCYoT/hHBcLR/x4G8fgdCWIxV7sDjoH1GY+ZQsnQ86bzch6AZVk rF1vZ0X063vZph3JLIbHpU1EgBbbT3825lxYZDbfXvlE5xvp8kfhwERi8bSwoR0VHDLI N1ggwOAU1VKX/ABkej/4zWTHOEpUydDYgA2flozNOcc2cnhh0kF4H3+XQBispEogftwU gfp1XTwFxb6kISXpxISrCtlLu0wiEemjpqSD2y3OVMXw58AyU4Lh/KHJt41dZWx9ZTuW Hgyi69mUGPor6cZdVvdZ1rEY1dcHS8LNLDWak7HQuGt/WpV2rs5DCpRl81xnOi7BBt/X MkPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=kp2j43tQ; 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 p8-v6si105402plk.642.2018.03.13.06.48.07; Tue, 13 Mar 2018 06:48:21 -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=kp2j43tQ; 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 S1752832AbeCMNqE (ORCPT + 99 others); Tue, 13 Mar 2018 09:46:04 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:35140 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752744AbeCMN0u (ORCPT ); Tue, 13 Mar 2018 09:26:50 -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=aH4yrtv2qE3HK2kXGA2/w1w6dA7MUpr29nVQLaLiphU=; b=kp2j43tQowowa5+Cwtv1yLJva vf/Xt1EBkd860H+vQSXaNpOf2kkTgvTdb13yEbZYFyZS9g/TzHKS4H1N5TmeYa3JMzAf04NLZWIIi z9IUntb9RSGGgkMaRU2m/fpG8q4OBBvOoBlYfGbFApgo1j/mT6i1yRjSMz4a9XPWk77Ea9mThCaa2 j6wXj05DIBpTBUBEAgMA6vVg5XRLN2EOq3HlpAp5t9J77AHK1Wntt5+meDGaoLoVcU5oWwoXs6AXK Jwg8UFhd/cZewjb6J/3j5Ic0bvornAPTvQL3OtoLG1lMofYGqE5Uj0sGpPxyMCvKsYA79Ysml1Sf6 GlaplFDBQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1evjx3-0004cc-8k; Tue, 13 Mar 2018 13:26:49 +0000 From: Matthew Wilcox To: Andrew Morton Cc: Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Ryusuke Konishi , linux-nilfs@vger.kernel.org Subject: [PATCH v9 20/61] xarray: Add xa_destroy Date: Tue, 13 Mar 2018 06:25:58 -0700 Message-Id: <20180313132639.17387-21-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180313132639.17387-1-willy@infradead.org> References: <20180313132639.17387-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 85dd909586f0..96773f83ae03 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 124bbfec66ae..080ed0fc3feb 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1468,6 +1468,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.1