From patchwork Mon Jun 11 14:05:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10457881 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A94F66020F for ; Mon, 11 Jun 2018 14:07:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9643F2846D for ; Mon, 11 Jun 2018 14:07:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A6682846F; Mon, 11 Jun 2018 14:07:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1786B28478 for ; Mon, 11 Jun 2018 14:07:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B99E36B0266; Mon, 11 Jun 2018 10:06:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AF7A76B0271; Mon, 11 Jun 2018 10:06:48 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 685306B026B; Mon, 11 Jun 2018 10:06:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id E489B6B026C for ; Mon, 11 Jun 2018 10:06:47 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id s3-v6so10786402plp.21 for ; Mon, 11 Jun 2018 07:06:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=nbY05u5jx+2zgCzyQJUXznqPWLWRJUQUQdOdMyGJxM0=; b=bspMnEWnnf6X5phFwFCj5dUXmd6P/Tlalp3/cSBvCBGcXdgBcND73v8ClKLdZ2GcME /ZUCfWR96VT1mMIi8tLQl4aZKOJsC5ApSxUeyJiIobhtqalEol+n+N/IbPLRoWfevU0k Ic908+gNAhFJCXFfdneOioWhQ93ovVm7y7xWKCZGS2rKKrI5/7TSWB/zZoX+YpG+nnTq L+2MZc4FFw3IOsZ0b4PDndt6TxVrRuIhwotCxhTGVnO68SL67xeinRZxUkcWYkFtpNoU 0sNkQBRNa4oXNcD/wlqUSY7bsn3fXxMgk5QtN6Xs9JkdvCxctV+fadMRM+rKnQfnyVL/ ggFQ== X-Gm-Message-State: APt69E2Zo7anQgnSVU/QGXmJQXSDAot45OaMQpbCU/DsB6FpmNg2SHdX 4nIIzTEqMASYRAs/RxF8ijJmK6e3kUF1s9Mz5WfZrFBOb/O/+Q1fJccWm3/tjznOaBAdlbvgokK O9r+g2hcj4Jg9MrSwiM6m0f5P1B/INPeImsHC0lypHq+qMHFtllI/g1vwRiXl4jJ8lA== X-Received: by 2002:a62:830e:: with SMTP id h14-v6mr18031558pfe.64.1528726007619; Mon, 11 Jun 2018 07:06:47 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJVBFWqc6kcvwKKFO9VNayiLk2xOZ3YT/jYTdmI/rCaOC5iPWO5yOtKuIG8p2C5BZv8bjnb X-Received: by 2002:a62:830e:: with SMTP id h14-v6mr18031474pfe.64.1528726006458; Mon, 11 Jun 2018 07:06:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528726006; cv=none; d=google.com; s=arc-20160816; b=p7Yy6ePezvwT2lOT7e2VZfRr4ngJhi5LpmCQrAHPLRdRtLz/w8rVab0Oa6MkNG4VHG HXR948j2DuN+erN43JC7b1MeNtMEtxwu7GujhvoE2ndwjpl6ko96H5WHPv7TUj52aILn hwVtxCtWy2r/BrfyShNAa0E8+KtXUnOyO0ZAxI2mgmWnfKIeICb4DeLNZTror11w456t dCDbjSe1Hhozm+J3PFydUNvEShIz94g0ZR4SMdD2M3UnO+hEZ2dqfW6CKqeH4EMbjHPU bht+Seb5oTvZHxTutAcH5P7WNBon/yhW8IcTYam4wkRT72kSfNnKJ+naC0gPvDPjnrDW /IvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=nbY05u5jx+2zgCzyQJUXznqPWLWRJUQUQdOdMyGJxM0=; b=urWdROIyGg9bwXObM0e69z3TKB5Gu9NXXFme/7n6yS3U653zs0AhFUWelUPdvdyV5X C9BIRL+qaoKF2m8AbzzGByn3g6iY58LPRQ9o2A0Wc/NEU+0CBpRn9/k5Nku1oMo1vUgK foMih4lnKaRB+FZzpKihvygBlkbExn7gudSfq3yjqXxAWtLp9Ugb40Q/rHBFAkdF+QDJ Du/+ULXrkYW6rDyYJY/vL5PxekcUWtdPuB6wPWnAfDeYbKqLlINLb579jUaanozVrjph s97XHyphTolWwRhinyVT4O6G41YW2qIJLB2K8B4jjfb3tlxjphMEJBY6GiFWIqlynZxB +msA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=g/V8+Pfo; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id w134-v6si17529128pfd.313.2018.06.11.07.06.45 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jun 2018 07:06:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=g/V8+Pfo; spf=pass (google.com: best guess record for domain of willy@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=willy@infradead.org 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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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) {