[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200927062654.2750277-2-ming.lei@redhat.com>
Date: Sun, 27 Sep 2020 14:26:52 +0800
From: Ming Lei <ming.lei@...hat.com>
To: linux-kernel@...r.kernel.org, linux-block@...r.kernel.org
Cc: Ming Lei <ming.lei@...hat.com>, Song Liu <song@...nel.org>,
Jens Axboe <axboe@...nel.dk>,
Veronika Kabatova <vkabatov@...hat.com>,
linux-raid@...r.kernel.org, Sagi Grimberg <sagi@...mberg.me>,
Tejun Heo <tj@...nel.org>, Christoph Hellwig <hch@....de>,
Bart Van Assche <bvanassche@....org>
Subject: [PATCH V5 1/3] percpu_ref: add percpu_ref_is_initialized for MD
MD code uses perpcu-refcount internal to check if this percpu-refcount
variable is initialized, this way is a hack.
Add percpu_ref_is_initialized for MD so that the hack can be avoided.
Acked-by: Song Liu <song@...nel.org>
Suggested-by: Jens Axboe <axboe@...nel.dk>
Tested-by: Veronika Kabatova <vkabatov@...hat.com>
Cc: Song Liu <song@...nel.org>
Cc: linux-raid@...r.kernel.org
Cc: Sagi Grimberg <sagi@...mberg.me>
Cc: Tejun Heo <tj@...nel.org>
Cc: Christoph Hellwig <hch@....de>
Cc: Jens Axboe <axboe@...nel.dk>
Cc: Bart Van Assche <bvanassche@....org>
Signed-off-by: Ming Lei <ming.lei@...hat.com>
---
drivers/md/md.c | 2 +-
include/linux/percpu-refcount.h | 1 +
lib/percpu-refcount.c | 6 ++++++
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index de8419b7ae98..241ff618d84e 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -5631,7 +5631,7 @@ static void no_op(struct percpu_ref *r) {}
int mddev_init_writes_pending(struct mddev *mddev)
{
- if (mddev->writes_pending.percpu_count_ptr)
+ if (percpu_ref_is_initialized(&mddev->writes_pending))
return 0;
if (percpu_ref_init(&mddev->writes_pending, no_op,
PERCPU_REF_ALLOW_REINIT, GFP_KERNEL) < 0)
diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h
index 87d8a38bdea1..2dfdf870f2d0 100644
--- a/include/linux/percpu-refcount.h
+++ b/include/linux/percpu-refcount.h
@@ -109,6 +109,7 @@ struct percpu_ref {
int __must_check percpu_ref_init(struct percpu_ref *ref,
percpu_ref_func_t *release, unsigned int flags,
gfp_t gfp);
+bool percpu_ref_is_initialized(struct percpu_ref *ref);
void percpu_ref_exit(struct percpu_ref *ref);
void percpu_ref_switch_to_atomic(struct percpu_ref *ref,
percpu_ref_func_t *confirm_switch);
diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
index 0ba686b8fe57..db2ec682e0f7 100644
--- a/lib/percpu-refcount.c
+++ b/lib/percpu-refcount.c
@@ -93,6 +93,12 @@ int percpu_ref_init(struct percpu_ref *ref, percpu_ref_func_t *release,
}
EXPORT_SYMBOL_GPL(percpu_ref_init);
+bool percpu_ref_is_initialized(struct percpu_ref *ref)
+{
+ return percpu_count_ptr(ref) != NULL;
+}
+EXPORT_SYMBOL_GPL(percpu_ref_is_initialized);
+
/**
* percpu_ref_exit - undo percpu_ref_init()
* @ref: percpu_ref to exit
--
2.25.2
Powered by blists - more mailing lists