
static int io_rsrc_ref_quiesce(struct fixed_rsrc_data *data,
			       struct io_ring_ctx *ctx,
			       void (*rsrc_put)(struct io_ring_ctx *ctx,
			                        struct io_rsrc_put *prsrc))
{
	struct fixed_rsrc_ref_node *backup_node;
	int ret;

	if (data->quiesce)
		return -ENXIO;

	data->quiesce = true;
	do {
		ret = -ENOMEM;
		backup_node = alloc_fixed_rsrc_ref_node(ctx);
		if (!backup_node)
			break;
		backup_node->rsrc_data = data;
		backup_node->rsrc_put = rsrc_put;

		io_sqe_rsrc_kill_node(ctx, data);
		percpu_ref_kill(&data->refs);
		flush_delayed_work(&ctx->rsrc_put_work);

		ret = wait_for_completion_interruptible(&data->done);
		if (!ret)
			break;

		percpu_ref_resurrect(&data->refs);
		io_sqe_rsrc_set_node(ctx, data, backup_node);
		backup_node = NULL;
		reinit_completion(&data->done);
		mutex_unlock(&ctx->uring_lock);
		ret = io_run_task_work_sig();
		mutex_lock(&ctx->uring_lock);
	} while (ret >= 0);
	data->quiesce = false;

	if (backup_node)
		destroy_fixed_rsrc_ref_node(backup_node);
	return ret;

static int io_rsrc_ref_quiesce(struct fixed_rsrc_data *data,
			       struct io_ring_ctx *ctx,
			       void (*rsrc_put)(struct io_ring_ctx *ctx,
			                        struct io_rsrc_put *prsrc))
{
	struct fixed_rsrc_ref_node *backup_node;
	int ret;

	if (data->quiesce)
		return -ENXIO;

	data->quiesce = true;
	do {
		ret = -ENOMEM;
		backup_node = alloc_fixed_rsrc_ref_node(ctx);
		if (!backup_node)
			break;
		backup_node->rsrc_data = data;
		backup_node->rsrc_put = rsrc_put;

		io_sqe_rsrc_kill_node(ctx, data);
		percpu_ref_kill(&data->refs);
		flush_delayed_work(&ctx->rsrc_put_work);

		ret = wait_for_completion_interruptible(&data->done);
		if (!ret)
			break;

		percpu_ref_resurrect(&data->refs);
		io_sqe_rsrc_set_node(ctx, data, backup_node);
		backup_node = NULL;
		reinit_completion(&data->done);
		mutex_unlock(&ctx->uring_lock);
		ret = io_run_task_work_sig();
		mutex_lock(&ctx->uring_lock);
	} while (ret >= 0);
	data->quiesce = false;

	if (backup_node)
		destroy_fixed_rsrc_ref_node(backup_node);
	return ret;