提交 2596a4a6 编写于 作者: B Bart Van Assche 提交者: Joseph Qi

percpu-refcount: Introduce percpu_ref_resurrect()

to #26323588

commit 18c9a6bbe0645a05172a900740b9d2d379d54320 upstream.

This function will be used in a later patch to switch the struct
request_queue q_usage_counter from killed back to live. In contrast
to percpu_ref_reinit(), this new function does not require that the
refcount is zero.
Signed-off-by: NBart Van Assche <bvanassche@acm.org>
Acked-by: NTejun Heo <tj@kernel.org>
Reviewed-by: NMing Lei <ming.lei@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Jianchao Wang <jianchao.w.wang@oracle.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: NJens Axboe <axboe@kernel.dk>
Signed-off-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
Acked-by: NXiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
上级 1c501709
...@@ -116,6 +116,7 @@ void percpu_ref_switch_to_atomic_sync(struct percpu_ref *ref); ...@@ -116,6 +116,7 @@ void percpu_ref_switch_to_atomic_sync(struct percpu_ref *ref);
void percpu_ref_switch_to_percpu(struct percpu_ref *ref); void percpu_ref_switch_to_percpu(struct percpu_ref *ref);
void percpu_ref_kill_and_confirm(struct percpu_ref *ref, void percpu_ref_kill_and_confirm(struct percpu_ref *ref,
percpu_ref_func_t *confirm_kill); percpu_ref_func_t *confirm_kill);
void percpu_ref_resurrect(struct percpu_ref *ref);
void percpu_ref_reinit(struct percpu_ref *ref); void percpu_ref_reinit(struct percpu_ref *ref);
/** /**
......
...@@ -365,11 +365,35 @@ EXPORT_SYMBOL_GPL(percpu_ref_kill_and_confirm); ...@@ -365,11 +365,35 @@ EXPORT_SYMBOL_GPL(percpu_ref_kill_and_confirm);
*/ */
void percpu_ref_reinit(struct percpu_ref *ref) void percpu_ref_reinit(struct percpu_ref *ref)
{ {
WARN_ON_ONCE(!percpu_ref_is_zero(ref));
percpu_ref_resurrect(ref);
}
EXPORT_SYMBOL_GPL(percpu_ref_reinit);
/**
* percpu_ref_resurrect - modify a percpu refcount from dead to live
* @ref: perpcu_ref to resurrect
*
* Modify @ref so that it's in the same state as before percpu_ref_kill() was
* called. @ref must be dead but must not yet have exited.
*
* If @ref->release() frees @ref then the caller is responsible for
* guaranteeing that @ref->release() does not get called while this
* function is in progress.
*
* Note that percpu_ref_tryget[_live]() are safe to perform on @ref while
* this function is in progress.
*/
void percpu_ref_resurrect(struct percpu_ref *ref)
{
unsigned long __percpu *percpu_count;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&percpu_ref_switch_lock, flags); spin_lock_irqsave(&percpu_ref_switch_lock, flags);
WARN_ON_ONCE(!percpu_ref_is_zero(ref)); WARN_ON_ONCE(!(ref->percpu_count_ptr & __PERCPU_REF_DEAD));
WARN_ON_ONCE(__ref_is_percpu(ref, &percpu_count));
ref->percpu_count_ptr &= ~__PERCPU_REF_DEAD; ref->percpu_count_ptr &= ~__PERCPU_REF_DEAD;
percpu_ref_get(ref); percpu_ref_get(ref);
...@@ -377,4 +401,4 @@ void percpu_ref_reinit(struct percpu_ref *ref) ...@@ -377,4 +401,4 @@ void percpu_ref_reinit(struct percpu_ref *ref)
spin_unlock_irqrestore(&percpu_ref_switch_lock, flags); spin_unlock_irqrestore(&percpu_ref_switch_lock, flags);
} }
EXPORT_SYMBOL_GPL(percpu_ref_reinit); EXPORT_SYMBOL_GPL(percpu_ref_resurrect);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册