Received: by 10.223.164.202 with SMTP id h10csp666539wrb; Wed, 22 Nov 2017 13:20:56 -0800 (PST) X-Google-Smtp-Source: AGs4zMa9t1SDlVyUnVGN49rmjfMe82j0zYiIwaiHUA40lay0q8nQmy5PZaGa3uKJ+1vyCIlJxHGm X-Received: by 10.98.60.27 with SMTP id j27mr20564670pfa.68.1511385656626; Wed, 22 Nov 2017 13:20:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511385656; cv=none; d=google.com; s=arc-20160816; b=JF11SjcqL9HaeLWjo1td3mNlQEXuWpglPbuFBAR1vFQJ1b/zEBQWiy/vbjMs4YgEOu AcXmrJkvE6Z929HmylG1cz43zpfOhCBoWMpR7jgM9p5UujBqHhAU8RIbnTFKpkng9dSy kSAKBuifFIUJsbNi1f1gpcFY/5Sv4SCda+9d7unUOv1NtzGcaJoTDe0mhifuKvAc8aZ0 R6ydBEviN8+45yk+o/G0DFPuZGDKgAWZTTeg5D75Io3ApoQND6BbE2M9dc4X/BwHaR0S cTdk6WIGKg6by0Mdr/nHCB4p2SAB7XvPacrzNrE1nqY9jAh1GgbOTOSwhhUBi7BVykTs 5r3Q== 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=kZDCAvE/ERK5fJ0X5N6zuDKjsUxSMI6ED29uHAl49qs=; b=MEQeY2DVcl1jUXGwEsaFP/hosNyfwrzpnAO8tOTNgq7jVkxL762OCByDEETUh4+yIT RRCuKntgq50MT6wrotI2X7NuFSIYPFRsnCRpI5FnbrSKWymF83bwY15X4eV+fDq0V4i1 2+y/u7Rw+20u6Ldh8UJUl8Q44okyuGeDb2PYf2drsUuJJ4MSrawAEIiEYSRoMHrsJXYl wslEPdyrTsyLIhBO/FeXU4cyfabyBfRofzpEgAWJKEwjIiraO8iowwU03QwXnVPd1xri HEPdT1HLE7kz+HRfbpM79UClH6e7S9VfwZChBvQZ+//RmnJMSarD1toWaQZznQFZTlem 4M1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=u+YUBOmj; 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 t8si14318930plo.439.2017.11.22.13.20.45; Wed, 22 Nov 2017 13:20:56 -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=u+YUBOmj; 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 S1752147AbdKVVTu (ORCPT + 77 others); Wed, 22 Nov 2017 16:19:50 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:57291 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751761AbdKVVIS (ORCPT ); Wed, 22 Nov 2017 16:08:18 -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=kZDCAvE/ERK5fJ0X5N6zuDKjsUxSMI6ED29uHAl49qs=; b=u+YUBOmjfWaLpphS/BSzKZ41O Z071TmkMhMvhINvEQwt85iOsSzwZfEW3zu6vmiL3aa0sXcmsqHWpA8p1xbUpGzKlULH/MbxBeI1rq h+yiDIvUNiDhpvQHBvwC6YKpt96jRPF0YoI7haVmeq0DL7m7LUQXtP86VVToV4IgwJqZZBS+GoNMZ j/uhtLTAVNvvtNgoFggctjZeBxqvJhZ6rqWi4CCx0RtjahkklCOLmH5+II4p2Ai+z7yKA6dTKK0nx HKgx07ELNLuOUu2QCuoBrdvrHuzZOKMJlQHhU4pSiQ2AcgpPGc1eI7KICQgsekpqR6ICq8I5wveTc aaFzvQ6JQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eHcFl-0007uZ-SB; Wed, 22 Nov 2017 21:08:17 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox Subject: [PATCH 28/62] xarray: Add xa_destroy Date: Wed, 22 Nov 2017 13:07:05 -0800 Message-Id: <20171122210739.29916-29-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171122210739.29916-1-willy@infradead.org> References: <20171122210739.29916-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 | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/linux/xarray.h b/include/linux/xarray.h index a48e7aa6406c..347347499652 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h @@ -98,6 +98,7 @@ void *xa_load(struct xarray *, unsigned long index); void *xa_store(struct xarray *, unsigned long index, void *entry, gfp_t); void *xa_cmpxchg(struct xarray *, unsigned long index, void *old, void *entry, gfp_t); +void xa_destroy(struct xarray *); /** * xa_empty() - Determine if an array has any present entries diff --git a/lib/xarray.c b/lib/xarray.c index 9577a70495c0..4fc1073f9454 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1312,3 +1312,29 @@ int xa_get_tagged(struct xarray *xa, void **dst, unsigned long start, return i; } EXPORT_SYMBOL(xa_get_tagged); + +/** + * 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. + */ +void xa_destroy(struct xarray *xa) +{ + XA_STATE(xas, 0); + unsigned long flags; + void *entry; + + xas.xa_node = NULL; + xa_lock_irqsave(xa, flags); + entry = xa_head_locked(xa); + RCU_INIT_POINTER(xa->xa_head, NULL); + xas_init_tags(xa, &xas); + /* lockdep checks we're still holding the lock in xas_free_nodes() */ + if (xa_is_node(entry)) + xas_free_nodes(xa, &xas, xa_to_node(entry)); + xa_unlock_irqrestore(xa, flags); +} +EXPORT_SYMBOL(xa_destroy); -- 2.15.0 From 1584802480824091776@xxx Wed Nov 22 21:17:02 +0000 2017 X-GM-THRID: 1584802480824091776 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread