Received: by 10.223.164.202 with SMTP id h10csp667395wrb; Wed, 22 Nov 2017 13:21:58 -0800 (PST) X-Google-Smtp-Source: AGs4zMYr5O2zwn5PCSd66UsuyAIBa8aM5mNKASPEbhe2+SokfKvzJhL8iihReI3kGS1zqx11XQBj X-Received: by 10.84.136.131 with SMTP id 3mr7547632pll.430.1511385718034; Wed, 22 Nov 2017 13:21:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511385718; cv=none; d=google.com; s=arc-20160816; b=tCmdr+ujLaPRoF+Z8F6clZ0jj7EZrTOfGl+0ZME2/i6RVQSxzO5NwvTk4MSIB45zlY Si6ZZe30obu2k/BxrqqFIrsVDBW3gIoilGtIuLtltOvzHSaT4ognGFask2RNz12Vow8W px3TEBsIUHDCIq1sNnOthO3kmWiYf8JZU7L9GTfHYgNhHGSFpWUxHp7nyoumoCCGr3D2 XleRftCX1t+h+O/XxfqtR0e+MT9rzDLyZU4xmeElQQGoSSHqolziWcbkD0NDz9muiyLY 0xUZP8ncHGYWQIzyxWR5xcXn3nTqxdCM1hkxu8+QZlqaQ0VO5d2cFrtWESqRs39HxLRx L9Jg== 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=xKz1N/6oM9N3C5hNpsU/OBw1/MGEejx8qAvH+By+bLk=; b=Wvdq7jtH4Rvu25lxqXU71kVbcPaXaiSwKDkpFr3E/NJqGhvPJ5z5oPNyATm1DAWRcg VVWha3AoYCRWxVC9rclFe8zy1mwLp1FJZ6mmbw3H4IkLDtNMllI2cnCd9DW1tKCPZa7E pqGJE7NXQTLEGoU/BjmPdMEphD+KBDF92+Yz013ppugUku3muK2oRvajHVP/dAJniXUI OWL0g7KnE24T2zrRexQ46S5oeGosea1wTcVhGjHSifR+OuN0/gR4pzeajgp78/UmQDT6 h6iO0m2W6V5VRrTOJen0CX0v5kRbfcYoOa9ewUW3OLbSxBzpdAcW17XbYm+JcfbLB5el 4M5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=qF+4j4Qu; 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 134si14022945pgg.733.2017.11.22.13.21.45; Wed, 22 Nov 2017 13:21:57 -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=qF+4j4Qu; 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 S1752236AbdKVVTw (ORCPT + 77 others); Wed, 22 Nov 2017 16:19:52 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:44522 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751760AbdKVVIS (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=xKz1N/6oM9N3C5hNpsU/OBw1/MGEejx8qAvH+By+bLk=; b=qF+4j4QuTSlAwQdSfMz9dhRyi QrYgHbmWnrMRrW0W7cqzK32y1IKG9WCuZu8f/EuwUGMZ3oRMlfCDk9NvBUROJhs/KHenDHQZT+Teh 1splvvMrifr+XcI1FhIKVyTZCFYNAe76gx7Ft163ZMMc8Bys3G59uJWvdCy0e9ZBjLFVbW6hKtGaJ DVZSgSNoYhl76GjoAl+9/3EcgwR/J/0JWta437RETclWca7RvjKYJf3rznLhk0XxHtDw05N+TVZYb S67Lq9vG/+QaoXHUZbLVky375wJ3SqNj0iIpszqld/U+gHIiqDLwsMk8SdnUoztgP/9t9hhvWvNJx ZqxaRsoGQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1eHcFl-0007uS-QM; 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 27/62] xarray: Add xa_get_entries and xa_get_tagged Date: Wed, 22 Nov 2017 13:07:04 -0800 Message-Id: <20171122210739.29916-28-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 These functions allow a range of xarray entries to be extracted into a compact normal array. Signed-off-by: Matthew Wilcox --- include/linux/xarray.h | 4 +++ lib/xarray.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/include/linux/xarray.h b/include/linux/xarray.h index 427c792ddb2a..a48e7aa6406c 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h @@ -145,6 +145,10 @@ void *xa_clear_tag(struct xarray *, unsigned long index, xa_tag_t); void *xa_find(struct xarray *xa, unsigned long *index, unsigned long max); void *xa_next(struct xarray *xa, unsigned long *index, unsigned long max); +int xa_get_entries(struct xarray *, void **dst, unsigned long start, + unsigned long max, unsigned int n); +int xa_get_tagged(struct xarray *, void **dst, unsigned long start, + unsigned long max, unsigned int n, xa_tag_t); /** * xa_for_each() - Iterate over a portion of an XArray. diff --git a/lib/xarray.c b/lib/xarray.c index ea2dbd343380..9577a70495c0 100644 --- a/lib/xarray.c +++ b/lib/xarray.c @@ -1243,3 +1243,72 @@ void *xa_next(struct xarray *xa, unsigned long *indexp, unsigned long max) return entry; } EXPORT_SYMBOL(xa_next); + +/** + * xa_get_entries() - Copy entries from the xarray into a normal array + * @xa: The source XArray to copy from + * @dst: The buffer to copy pointers into + * @start: The first index in the XArray eligible to be copied from + * @max: The last index in the XArray eligible to be copied from + * @n: The maximum number of entries to copy + * + * Return: The number of entries copied. + */ +int xa_get_entries(struct xarray *xa, void **dst, unsigned long start, + unsigned long max, unsigned int n) +{ + XA_STATE(xas, start); + void *entry; + unsigned int i = 0; + + if (!n) + return 0; + + rcu_read_lock(); + xas_for_each(xa, &xas, entry, max) { + if (xas_retry(&xas, entry)) + continue; + dst[i++] = entry; + if (i == n) + break; + } + rcu_read_unlock(); + + return i; +} +EXPORT_SYMBOL(xa_get_entries); + +/** + * xa_get_tagged() - Copy tagged entries from the xarray into a normal array. + * @xa: The source XArray to copy from. + * @dst: The buffer to copy pointers into. + * @start: The first index in the XArray eligible to be copied from. + * @max: The last index in the XArray eligible to be copied from + * @n: The maximum number of entries to copy. + * @tag: Tag number. + * + * Return: The number of entries copied. + */ +int xa_get_tagged(struct xarray *xa, void **dst, unsigned long start, + unsigned long max, unsigned int n, xa_tag_t tag) +{ + XA_STATE(xas, start); + void *entry; + unsigned int i = 0; + + if (!n) + return 0; + + rcu_read_lock(); + xas_for_each_tag(xa, &xas, entry, max, tag) { + if (xas_retry(&xas, entry)) + continue; + dst[i++] = entry; + if (i == n) + break; + } + rcu_read_unlock(); + + return i; +} +EXPORT_SYMBOL(xa_get_tagged); -- 2.15.0 From 1584771275132024085@xxx Wed Nov 22 13:01:02 +0000 2017 X-GM-THRID: 1584771275132024085 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread