linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V3 1/3] percpu_ref: add percpu_ref_inited() for MD
       [not found] <20200908012351.1092986-1-ming.lei@redhat.com>
@ 2020-09-08  1:23 ` Ming Lei
  2020-09-09  0:48   ` Song Liu
  2020-09-09  1:41   ` Bart Van Assche
  0 siblings, 2 replies; 4+ messages in thread
From: Ming Lei @ 2020-09-08  1:23 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Ming Lei, Veronika Kabatova, Song Liu, linux-raid,
	Sagi Grimberg, Tejun Heo, Christoph Hellwig, Bart Van Assche

MD code uses perpcu-refcount internal to check if this percpu-refcount
variable is initialized, this way is a hack.

Add percpu_ref_inited() for MD so that the hack can be avoided.

Suggested-by: Jens Axboe <axboe@kernel.dk>
Tested-by: Veronika Kabatova <vkabatov@redhat.com>
Cc: Song Liu <song@kernel.org>
Cc: linux-raid@vger.kernel.org
Cc: Sagi Grimberg <sagi@grimberg.me>
Cc: Tejun Heo <tj@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Ming Lei <ming.lei@redhat.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 9562ef598ae1..a7c2429949fb 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -5632,7 +5632,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_inited(&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..aed01562387b 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_inited(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..9e7c4ab5b7bb 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_inited(struct percpu_ref *ref)
+{
+	return percpu_count_ptr(ref) != NULL;
+}
+EXPORT_SYMBOL_GPL(percpu_ref_inited);
+
 /**
  * percpu_ref_exit - undo percpu_ref_init()
  * @ref: percpu_ref to exit
-- 
2.25.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V3 1/3] percpu_ref: add percpu_ref_inited() for MD
  2020-09-08  1:23 ` [PATCH V3 1/3] percpu_ref: add percpu_ref_inited() for MD Ming Lei
@ 2020-09-09  0:48   ` Song Liu
  2020-09-09  1:41   ` Bart Van Assche
  1 sibling, 0 replies; 4+ messages in thread
From: Song Liu @ 2020-09-09  0:48 UTC (permalink / raw)
  To: Ming Lei
  Cc: Jens Axboe, linux-block, Veronika Kabatova, linux-raid,
	Sagi Grimberg, Tejun Heo, Christoph Hellwig, Bart Van Assche

On Mon, Sep 7, 2020 at 6:24 PM Ming Lei <ming.lei@redhat.com> wrote:
>
> MD code uses perpcu-refcount internal to check if this percpu-refcount
> variable is initialized, this way is a hack.
>
> Add percpu_ref_inited() for MD so that the hack can be avoided.
>
> Suggested-by: Jens Axboe <axboe@kernel.dk>
> Tested-by: Veronika Kabatova <vkabatov@redhat.com>
> Cc: Song Liu <song@kernel.org>
> Cc: linux-raid@vger.kernel.org
> Cc: Sagi Grimberg <sagi@grimberg.me>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Jens Axboe <axboe@kernel.dk>
> Cc: Bart Van Assche <bvanassche@acm.org>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>

Acked-by: Song Liu <song@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V3 1/3] percpu_ref: add percpu_ref_inited() for MD
  2020-09-08  1:23 ` [PATCH V3 1/3] percpu_ref: add percpu_ref_inited() for MD Ming Lei
  2020-09-09  0:48   ` Song Liu
@ 2020-09-09  1:41   ` Bart Van Assche
  2020-09-09  6:04     ` Christoph Hellwig
  1 sibling, 1 reply; 4+ messages in thread
From: Bart Van Assche @ 2020-09-09  1:41 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe
  Cc: linux-block, Veronika Kabatova, Song Liu, linux-raid,
	Sagi Grimberg, Tejun Heo, Christoph Hellwig

On 2020-09-07 18:23, Ming Lei wrote:
> +bool percpu_ref_inited(struct percpu_ref *ref)
> +{
> +	return percpu_count_ptr(ref) != NULL;
> +}
> +EXPORT_SYMBOL_GPL(percpu_ref_inited);

Wouldn't percpu_ref_initialized() be a better name?

How about adding kernel-doc documentation?

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH V3 1/3] percpu_ref: add percpu_ref_inited() for MD
  2020-09-09  1:41   ` Bart Van Assche
@ 2020-09-09  6:04     ` Christoph Hellwig
  0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2020-09-09  6:04 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Ming Lei, Jens Axboe, linux-block, Veronika Kabatova, Song Liu,
	linux-raid, Sagi Grimberg, Tejun Heo, Christoph Hellwig

On Tue, Sep 08, 2020 at 06:41:48PM -0700, Bart Van Assche wrote:
> On 2020-09-07 18:23, Ming Lei wrote:
> > +bool percpu_ref_inited(struct percpu_ref *ref)
> > +{
> > +	return percpu_count_ptr(ref) != NULL;
> > +}
> > +EXPORT_SYMBOL_GPL(percpu_ref_inited);
> 
> Wouldn't percpu_ref_initialized() be a better name?

Or maybe even percpu_ref_is_initialized

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-09  6:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20200908012351.1092986-1-ming.lei@redhat.com>
2020-09-08  1:23 ` [PATCH V3 1/3] percpu_ref: add percpu_ref_inited() for MD Ming Lei
2020-09-09  0:48   ` Song Liu
2020-09-09  1:41   ` Bart Van Assche
2020-09-09  6:04     ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).