Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2452775imm; Sat, 16 Jun 2018 19:11:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIwKpaqdV3DS44yqQ++jAv0nGhFUUa0pvtpMbji8R0Nq1xqKSrNBhfo1nxwMV5BZbeCCtNq X-Received: by 2002:a63:8f19:: with SMTP id n25-v6mr6744963pgd.344.1529201517318; Sat, 16 Jun 2018 19:11:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529201517; cv=none; d=google.com; s=arc-20160816; b=ClX5NumFqkVaIPo385LQtls9ZnRPO04/w0pIS3pUg2VUU2M/ATGgyX9xMbr8b3Rz5Y 3za4dn4z3m4uB7dLLX0mIqmh1mUyGq+64Fn4MApoxzOXF4Zp0rajoS+CUpFe9RXJSHio 720MTSlAq7JTUcY6c1t5LOztw6Zz1O4ZwjfGd5tOYs9FLMMH1+aQJLySiNqJqVghZx7Y E0oy2w/ydXHaK+e+z/kViORylJvwSk5N7M1kreNWxr0VlZ2yTs3OE+/2/h0mLfGtECKW bjwOVWt+eBg7gUsm0TJ3yYghJztw+WUq7zUfac6C50OPM2UJGq709jNx2O1H2D4R1oYo TYGw== 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=06qd/xlJg/OzH4I18kD3SK7TPii4ugk5m7Ua6YGXEhI=; b=c/VivkIpXtyG2wJAg5AIJwDKQsbIQEQyXUsz51lyI57zfdyVpYMx6wGUhkXHyW2HRU Mx3/bMQp/LEp5N4HwYs7JF1X7Mo4xuqGo2gDowkz8sxuXjuFE4yyoi5XvuSJQOVI76i1 dImGRaRZCh8U3q1gnimeDCtUpcmkn9HQYpsMjvcR/Glp4DbhrDZQtjv93IQBIFSU/G9F j/NXirqw5AZOoZnseVL24dk+HT3b3xFPcqpp/C0t0Db9HtYxSMF4OfGFPg6CXcyFXrZO UhrLTq0lLYERWfAeFJ2grSUEm+rfbiRoSwgshYGoQwzXV5+fckOGGLThMTKzZz+YSMnz RgQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=ZRmlSBK9; 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 p3-v6si9745693pgr.156.2018.06.16.19.11.42; Sat, 16 Jun 2018 19:11:57 -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=ZRmlSBK9; 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 S936398AbeFQCKD (ORCPT + 99 others); Sat, 16 Jun 2018 22:10:03 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:59102 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933933AbeFQCBH (ORCPT ); Sat, 16 Jun 2018 22:01:07 -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=06qd/xlJg/OzH4I18kD3SK7TPii4ugk5m7Ua6YGXEhI=; b=ZRmlSBK92lq0ByjszBgzabJBy aN+v+EI3JNlMVXilNUWIQFVrfnJW3WWV80YUVEOmF/MeDPK2aYwOmxGlpmgR0+CBwALn0TRsOSQgh YTgKc7CZvvGIwIDDu0udK860oheV4TKYTQnDcoNf33oPV0YMk9UgyVZLb3jQXD+4IRRf1Xu4hFtOC jUpEWOWfOkpnmczEkeOjirw7TGBaQAJa2U9NEV3kVWdiCcpRUpS3cx9Q3PWtu8r52SmaRSrIaWacN sKTeeRUK12AvQWdFXuJmVfN5VfAzTrrswe1Y05hw6yfj6JRdP5z/I9RX0W2HCPN/YR9KKqsof817B mpdXxOE4w==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fUMzw-0001GW-Qs; Sun, 17 Jun 2018 02:00:56 +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 v14 15/74] xarray: Destroy an XArray Date: Sat, 16 Jun 2018 18:59:53 -0700 Message-Id: <20180617020052.4759-16-willy@infradead.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180617020052.4759-1-willy@infradead.org> References: <20180617020052.4759-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 6f398732b664..fa36a0670988 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 1e15ead40d78..e90ba76404ae 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1493,6 +1493,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