From patchwork Mon Nov 16 09:07:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 324967 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97ABCC4742C for ; Mon, 16 Nov 2020 09:43:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2249920782 for ; Mon, 16 Nov 2020 09:43:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gJ8Hw8W6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728477AbgKPJIZ (ORCPT ); Mon, 16 Nov 2020 04:08:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60938 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728461AbgKPJIZ (ORCPT ); Mon, 16 Nov 2020 04:08:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605517703; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cOrWYdtv2sn5+hknxf7bjqdB5haJNia72F3gWe8QNnc=; b=gJ8Hw8W6PYsnKuz6PwknEb+hp/DchS17acb/Ku6JeTNcLem2aT79PQ4WF43ouLzxHXlMLZ SUlObeOVe6pxG/0g+ZEOo69jn1ntmiBR+eDh1uG68+Ht5LkL+k63wWlGU/CQvPHAlpSLFR lDDG4lZRi2YeSd+57bpjql4EzdIPq8U= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-31-RItekd-qNEelLU-hsqMY8w-1; Mon, 16 Nov 2020 04:08:21 -0500 X-MC-Unique: RItekd-qNEelLU-hsqMY8w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 73B4F879516; Mon, 16 Nov 2020 09:08:19 +0000 (UTC) Received: from localhost (ovpn-13-166.pek2.redhat.com [10.72.13.166]) by smtp.corp.redhat.com (Postfix) with ESMTP id A834255762; Mon, 16 Nov 2020 09:08:15 +0000 (UTC) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org, "Martin K . Petersen" , linux-scsi@vger.kernel.org Cc: Ming Lei , Omar Sandoval , Kashyap Desai , Sumanesh Samanta , "Ewan D . Milne" , Hannes Reinecke Subject: [PATCH V4 05/12] sbitmap: export sbitmap_weight Date: Mon, 16 Nov 2020 17:07:30 +0800 Message-Id: <20201116090737.50989-6-ming.lei@redhat.com> In-Reply-To: <20201116090737.50989-1-ming.lei@redhat.com> References: <20201116090737.50989-1-ming.lei@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org SCSI's .device_busy will be converted to sbitmap, and sbitmap_weight is needed, so export the helper. Cc: Omar Sandoval Cc: Kashyap Desai Cc: Sumanesh Samanta Cc: Ewan D. Milne Reviewed-by: Hannes Reinecke Tested-by: Sumanesh Samanta Signed-off-by: Ming Lei --- include/linux/sbitmap.h | 9 +++++++++ lib/sbitmap.c | 11 ++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/linux/sbitmap.h b/include/linux/sbitmap.h index 103b41c03311..34343ce3ef6c 100644 --- a/include/linux/sbitmap.h +++ b/include/linux/sbitmap.h @@ -346,6 +346,15 @@ static inline int sbitmap_test_bit(struct sbitmap *sb, unsigned int bitnr) */ void sbitmap_show(struct sbitmap *sb, struct seq_file *m); + +/** + * sbitmap_weight() - Return how many real bits set in a &struct sbitmap. + * @sb: Bitmap to check. + * + * Return: How many real bits set + */ +unsigned int sbitmap_weight(const struct sbitmap *sb); + /** * sbitmap_bitmap_show() - Write a hex dump of a &struct sbitmap to a &struct * seq_file. diff --git a/lib/sbitmap.c b/lib/sbitmap.c index dcd6a89b4d2f..fb1d3c2f70a2 100644 --- a/lib/sbitmap.c +++ b/lib/sbitmap.c @@ -342,20 +342,21 @@ static unsigned int __sbitmap_weight(const struct sbitmap *sb, bool set) return weight; } -static unsigned int sbitmap_weight(const struct sbitmap *sb) +static unsigned int sbitmap_cleared(const struct sbitmap *sb) { - return __sbitmap_weight(sb, true); + return __sbitmap_weight(sb, false); } -static unsigned int sbitmap_cleared(const struct sbitmap *sb) +unsigned int sbitmap_weight(const struct sbitmap *sb) { - return __sbitmap_weight(sb, false); + return __sbitmap_weight(sb, true) - sbitmap_cleared(sb); } +EXPORT_SYMBOL_GPL(sbitmap_weight); void sbitmap_show(struct sbitmap *sb, struct seq_file *m) { seq_printf(m, "depth=%u\n", sb->depth); - seq_printf(m, "busy=%u\n", sbitmap_weight(sb) - sbitmap_cleared(sb)); + seq_printf(m, "busy=%u\n", sbitmap_weight(sb)); seq_printf(m, "cleared=%u\n", sbitmap_cleared(sb)); seq_printf(m, "bits_per_word=%u\n", 1U << sb->shift); seq_printf(m, "map_nr=%u\n", sb->map_nr);