From patchwork Wed Nov 22 21:07:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10071177 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 64D4360353 for ; Wed, 22 Nov 2017 21:20:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5837629D96 for ; Wed, 22 Nov 2017 21:20:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AA6C29DA4; Wed, 22 Nov 2017 21:20:50 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C845F29D96 for ; Wed, 22 Nov 2017 21:20:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752170AbdKVVUe (ORCPT ); Wed, 22 Nov 2017 16:20:34 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:35105 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751755AbdKVVIS (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=WKb6cY7oXxOJL1SFLi/2igLC1fFjcRbSupwEBMzuu/g=; b=hFYQ1hu3mDy+DOEJPixelKn9l aTJkWcdQxHlDzDqQ4xhQuRTHgpd8xRdkuu+gMR9H/6Qiskx+LGorSx4gUS7bOZFFjM/2ISwi9Cdtn p5kAZbTqnNO1xd4G4O9xyzjMeIM/cy7BxKPRafJc3YdYUxs/1XrZkr729fVtj3I2J+IZNWu1x7ctC BIWO00OjCETRkTTK0HxjBoLYYq4cl6HqSMXvxpgd+SwZTEeN7OaAizhUswpgcg1WcjpgGyM/iPW2g JAZt/xumW2ucn8i/d5QxTM6xTqlHcjS1PeLTGwzwvsDSXmbfpUZP/6ovHv6cam7+nimKvfszeCNeH FaGseRfeQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eHcFl-0007uB-LC; 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 25/62] xarray: Add xa_init Date: Wed, 22 Nov 2017 13:07:02 -0800 Message-Id: <20171122210739.29916-26-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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matthew Wilcox For initialising xarrays in code rather than data. Signed-off-by: Matthew Wilcox --- include/linux/xarray.h | 13 +++++++++++++ lib/xarray.c | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/linux/xarray.h b/include/linux/xarray.h index 08ddad60a43d..19a3974fdc4f 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h @@ -81,6 +81,19 @@ struct xarray { #define DEFINE_XARRAY(name) struct xarray name = XARRAY_INIT(name) +void __xa_init(struct xarray *, gfp_t flags); + +/** + * xa_init() - Initialise an empty XArray. + * @xa: XArray. + * + * An empty XArray is full of NULL entries. + */ +static inline void xa_init(struct xarray *xa) +{ + __xa_init(xa, 0); +} + 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, diff --git a/lib/xarray.c b/lib/xarray.c index 5409048e8b44..59f45c07988f 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -868,6 +868,21 @@ void *xas_find(struct xarray *xa, struct xa_state *xas, unsigned long max) } EXPORT_SYMBOL_GPL(xas_find); +/** + * __xa_init() - Initialise an empty XArray + * @xa: XArray. + * @flags: XA_FLAG_ values + * + * An empty XArray is full of NULL pointers. + */ +void __xa_init(struct xarray *xa, gfp_t flags) +{ + spin_lock_init(&xa->xa_lock); + xa->xa_flags = flags; + xa->xa_head = NULL; +} +EXPORT_SYMBOL(__xa_init); + /** * xa_load() - Load an entry from an XArray. * @xa: XArray.