Received: by 10.223.185.116 with SMTP id b49csp4146634wrg; Mon, 19 Feb 2018 12:01:37 -0800 (PST) X-Google-Smtp-Source: AH8x225By0wCfTW68TIZOapvMDTP4VVeRsrsvXfMQZzMEBKdG+T/sJ76qlmKPqzlf/VpSkNdVxoJ X-Received: by 10.99.137.195 with SMTP id v186mr13055269pgd.90.1519070497035; Mon, 19 Feb 2018 12:01:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519070496; cv=none; d=google.com; s=arc-20160816; b=gh28c2jUWvcvQyCElvoyswSQPLyEEGhA+i7HkQm29PrHab/kRsXXTJaTfB7fto7w2g qCZBCgPwyOwwC6f6LWeSJdlliv1bTbfukalYJ71drrp9+8Lz/KYVTyG5XYMly6wpjQE0 Au6pXITu3CmQ3AtDqXGU/1Uu7nU0ilAYlf8WKTy6a3aHqBReqNGBkVqOo5mNpRKzDxUk bI+tFVVgj4np1xbU4t7SqZ/AQtesR14Fz+iW8NfrUF+uJnSJV0x/YqBGWbal8NJidHPR FsAJd/yZpNFel1BOeu6ou4TCZM22Z/GefWBF9smKsoCd31iCuY81L26QZUfKyrZIBhxj UvmQ== 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=jo54PkKn/xlGyOQdvkO3sEucPYC9lP5qu7RjhpEDXdHexQyK3/ifBmVJ5wr7HWM0JF 9UEVl6yjZzoqgOT7w4Kd4efU4C2dVKGFJbc0v62wpEc4AlRVCuCckylGM+p0kEfNSymI dLQ0sB/xUoYbwnMSTXYzzCSORrmSvCddDFg1dfsAGYRHQ+uDd0LCJyCJgxVzxZqB2b6Z DIAL0k2Ef7zlX94/aOxcWvRrlNyByc0pIT1dIYIyKac7veUgfFev0mF0CIL6Y2Yv2zFY zzScnm7w4eJH+H2eELJBG3p6zErVbolw7R13Ftt3+mBs/1UVcV7NujlG7xjYooj7Fxvf yX7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=U9uXIcfi; 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 j6si2263425pfb.230.2018.02.19.12.01.22; Mon, 19 Feb 2018 12:01:36 -0800 (PST) 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=U9uXIcfi; 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 S1753815AbeBSUAq (ORCPT + 99 others); Mon, 19 Feb 2018 15:00:46 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:44658 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753695AbeBSTqN (ORCPT ); Mon, 19 Feb 2018 14:46:13 -0500 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=U9uXIcfiGEXUdcWV02izwaa+K 1Q50IhFIFUGvIYS17CVXuWo87uFml/kzaoD5cZaGCOeOLM9sc/koZFMrUb9u0DooYchGpHFbd96bT 7T547ru+Yz4SoZpv+Nc+TecIw4sNbWtWGGOtkKUMWBcdxtvTTBzeHtFvNs7qu4FODiHXA1OR120Je BINVKiCTmSFMrEF7uXumYWMJ+SzmhrOYsPbkPDdlZrh4wXOaRV4ak38herQXWrM6wJx2RAHVh7K5w 4HAVLZXS9/ot30bRmHlF6gPJ66bghhVJgQaQk8p1UKVL+RHNaCcXS64ASN/1OCcISw9btC0vqiSTQ D6STG1/wg==; Received: from willy by bombadil.infradead.org with local (Exim 4.89 #1 (Red Hat Linux)) id 1enrO7-0001mw-Sc; Mon, 19 Feb 2018 19:46:11 +0000 From: Matthew Wilcox To: Andrew Morton Cc: Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v7 21/61] xarray: Add xa_destroy Date: Mon, 19 Feb 2018 11:45:16 -0800 Message-Id: <20180219194556.6575-22-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180219194556.6575-1-willy@infradead.org> References: <20180219194556.6575-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