Message ID | 1615563895-28565-2-git-send-email-sergei.shtepa@veeam.com (mailing list archive) |
---|---|
State | Changes Requested, archived |
Delegated to: | Mike Snitzer |
Headers | show |
Series | block device interposer | expand |
On Fri, Mar 12 2021 at 10:44am -0500, Sergei Shtepa <sergei.shtepa@veeam.com> wrote: > blk_mq_is_queue_frozen() allow to assert that the queue is frozen. > > Signed-off-by: Sergei Shtepa <sergei.shtepa@veeam.com> > --- > block/blk-mq.c | 13 +++++++++++++ > include/linux/blk-mq.h | 1 + > 2 files changed, 14 insertions(+) > > diff --git a/block/blk-mq.c b/block/blk-mq.c > index d4d7c1caa439..2f188a865024 100644 > --- a/block/blk-mq.c > +++ b/block/blk-mq.c > @@ -161,6 +161,19 @@ int blk_mq_freeze_queue_wait_timeout(struct request_queue *q, > } > EXPORT_SYMBOL_GPL(blk_mq_freeze_queue_wait_timeout); > > +bool blk_mq_is_queue_frozen(struct request_queue *q) > +{ > + bool frozen; > + > + mutex_lock(&q->mq_freeze_lock); > + frozen = percpu_ref_is_dying(&q->q_usage_counter) && > + percpu_ref_is_zero(&q->q_usage_counter); > + mutex_unlock(&q->mq_freeze_lock); > + > + return frozen; > +} > +EXPORT_SYMBOL_GPL(blk_mq_is_queue_frozen); > + This is returning a frozen state that is immediately stale. I don't think any code calling this is providing the guarantees you think it does due to the racey nature of this state once the mutex is dropped. > /* > * Guarantee no request is in use, so we can change any data structure of > * the queue afterward. > diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h > index 2c473c9b8990..6f01971abf7b 100644 > --- a/include/linux/blk-mq.h > +++ b/include/linux/blk-mq.h > @@ -533,6 +533,7 @@ void blk_freeze_queue_start(struct request_queue *q); > void blk_mq_freeze_queue_wait(struct request_queue *q); > int blk_mq_freeze_queue_wait_timeout(struct request_queue *q, > unsigned long timeout); > +bool blk_mq_is_queue_frozen(struct request_queue *q); > > int blk_mq_map_queues(struct blk_mq_queue_map *qmap); > void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues); > -- > 2.20.1 > -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel
On Fri, Mar 12, 2021 at 02:06:41PM -0500, Mike Snitzer wrote: > This is returning a frozen state that is immediately stale. I don't > think any code calling this is providing the guarantees you think it > does due to the racey nature of this state once the mutex is dropped. The code only uses it for asserts in the form of WARN_ONs. -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel
The 03/14/2021 12:14, Christoph Hellwig wrote: > On Fri, Mar 12, 2021 at 02:06:41PM -0500, Mike Snitzer wrote: > > This is returning a frozen state that is immediately stale. I don't > > think any code calling this is providing the guarantees you think it > > does due to the racey nature of this state once the mutex is dropped. > > The code only uses it for asserts in the form of WARN_ONs. But perhaps it is possible to come up with a more elegant solution? I'll think about it.
diff --git a/block/blk-mq.c b/block/blk-mq.c index d4d7c1caa439..2f188a865024 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -161,6 +161,19 @@ int blk_mq_freeze_queue_wait_timeout(struct request_queue *q, } EXPORT_SYMBOL_GPL(blk_mq_freeze_queue_wait_timeout); +bool blk_mq_is_queue_frozen(struct request_queue *q) +{ + bool frozen; + + mutex_lock(&q->mq_freeze_lock); + frozen = percpu_ref_is_dying(&q->q_usage_counter) && + percpu_ref_is_zero(&q->q_usage_counter); + mutex_unlock(&q->mq_freeze_lock); + + return frozen; +} +EXPORT_SYMBOL_GPL(blk_mq_is_queue_frozen); + /* * Guarantee no request is in use, so we can change any data structure of * the queue afterward. diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 2c473c9b8990..6f01971abf7b 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -533,6 +533,7 @@ void blk_freeze_queue_start(struct request_queue *q); void blk_mq_freeze_queue_wait(struct request_queue *q); int blk_mq_freeze_queue_wait_timeout(struct request_queue *q, unsigned long timeout); +bool blk_mq_is_queue_frozen(struct request_queue *q); int blk_mq_map_queues(struct blk_mq_queue_map *qmap); void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues);
blk_mq_is_queue_frozen() allow to assert that the queue is frozen. Signed-off-by: Sergei Shtepa <sergei.shtepa@veeam.com> --- block/blk-mq.c | 13 +++++++++++++ include/linux/blk-mq.h | 1 + 2 files changed, 14 insertions(+)