[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <caf0bfbf-18d2-e936-4bbd-3e728a567de5@linux.alibaba.com>
Date: Fri, 23 Sep 2022 10:03:32 +0800
From: Ziyang Zhang <ZiyangZhang@...ux.alibaba.com>
To: ming.lei@...hat.com
Cc: linux-block@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH V5 6/7] ublk_drv: allow new process to open ublk chardev
with recovery feature enabled
On 2022/9/22 14:17, ZiyangZhang wrote:
> With recovery feature enabled, if ublk chardev is ready to be released
> and quiesce_work has been scheduled, we:
> (1) reinit all ubqs, including:
> (a) put the task_struct and reset ->ubq_daemon to NULL.
> (b) reset all ublk_io.
> (2) reset ub->mm to NULL.
> Then ublk chardev is released and new process can open it.
>
> RECOVER_DEV is introduced as a new ctrl-cmd for recovery feature.
> After the chardev is opened and all ubqs are ready, user should send
> RECOVER_DEV to:
> (1) wait until all new ubq_daemons getting ready.
> (2) update ublksrv_pid
> (3) unquiesce the request queue and expect incoming ublk_queue_rq()
> (4) convert ub's state to UBLK_S_DEV_LIVE
> (5) reschedule monitor_work
>
> Signed-off-by: ZiyangZhang <ZiyangZhang@...ux.alibaba.com>
> ---
> drivers/block/ublk_drv.c | 67 +++++++++++++++++++++++++++++++++++
> include/uapi/linux/ublk_cmd.h | 1 +
> 2 files changed, 68 insertions(+)
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 3977869d2bc4..ac8bf497567f 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -898,10 +898,40 @@ static int ublk_ch_open(struct inode *inode, struct file *filp)
> return 0;
> }
>
> +static void ublk_queue_reinit(struct ublk_device *ub, struct ublk_queue *ubq)
> +{
> + int i;
> +
> + /* old daemon is PF_EXITING, put it now */
> + if (ubq->ubq_daemon) {
> + put_task_struct(ubq->ubq_daemon);
> + /* We have to reset it to NULL, otherwise ub won't accept new FETCH_REQ */
> + ubq->ubq_daemon = NULL;
> + }
> +
> + for (i = 0; i < ubq->q_depth; i++) {
> + struct ublk_io *io = &ubq->ios[i];
> +
> + /* forget everything now and be ready for new FETCH_REQ */
> + io->flags = 0;
> + io->cmd = NULL;
> + io->addr = 0;
> + }
> + ubq->nr_io_ready = 0;
> +}
> +
> static int ublk_ch_release(struct inode *inode, struct file *filp)
> {
> struct ublk_device *ub = filp->private_data;
> + int i;
>
> + pr_devel("%s: reinit queues for dev id %d.\n", __func__, ub->dev_info.dev_id);
> + for (i = 0; i < ub->dev_info.nr_hw_queues; i++)
> + ublk_queue_reinit(ub, ublk_get_queue(ub, i));
> + /* set to NULL, otherwise new ubq_daemon cannot mmap the io_cmd_buf */
> + ub->mm = NULL;
> + ub->nr_queues_ready = 0;
> + init_completion(&ub->completion);
> clear_bit(UB_STATE_OPEN, &ub->state);
> return 0;
> }
This one is not correct. I will figure out how to correctly
put_task_struct(ubq->ubq_daemon) with recovery feature enabled.
Powered by blists - more mailing lists