Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp352243rwb; Thu, 22 Sep 2022 19:41:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5R4hAJe9zCHXsD5nBF7QP1iZ5ILBlzLb60JUMjhzxRT6uxlA2QP7gXSS4i8iL4k4gqWSqP X-Received: by 2002:a05:6402:d6b:b0:44e:82bf:28e5 with SMTP id ec43-20020a0564020d6b00b0044e82bf28e5mr6184108edb.83.1663900862176; Thu, 22 Sep 2022 19:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663900862; cv=none; d=google.com; s=arc-20160816; b=mYgHTcslTDDmLo6iVYlRjpQv5QioqC/L5pfRstaQKpcQC8m5giFdwpjIFN4bElrnKi fC+NNLH7ZcIgkMa6gAQTWc0x8fAPccgVW3Z9aWnz/QtxbOeTM7asR2kS98L2JfHTui1b yumbQI9jHnZZvFOVgQxHyPcqoGWjb/DoffN8zQqWyp9Et0npyxw55y7QdJARKrDo6PcO /NW4DCf9bj6d4veTdpXv3Qt1NRRilXQhmSIhNBi4lppf4B0y7UdbJXa8Ol1WTJlkJur0 bOVQUuS81EGyeHQteO2FQXJemFYGfQ9lemvl8W6+zgsVszovgMsdmbD2B34ASWpjIel5 Jj7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=vwUVTMNJdUY08yTTECybKGTU6NckjfNhNJyoI52Zo0U=; b=vuQ9T5DetYH60p6/lZFoCQit54+iRS4IxTPugrd7wMjat7dnbBWgYjA0X2XsYfyMSe fOQsTZYOOvEQqIF7tKyDZ84Xtwl4xJLnOqDR2fkDkZMWNGFIt1lVaezM2VCA3PyNFMw/ 08TjyTHqW5R4tVIApMOgcqydUacM/7oFmAlbjp7dc3zeTa6/8DFJSK/7Ds41QLBEailD HnInYhA4+L/4JI6eLg1y4mmS7pWWpIel9Y//GBKvcf+jPq9PArqi448UYGUEmTDuLeuq 8+4LuJQJ0CGpfxMfkynjW8jkHN9CdqKK9a+9QB6CSu27ZUBLh7dctKGopNFvxW4ilXGk zMtw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr16-20020a1709073f9000b0076fbaba1addsi6806584ejc.896.2022.09.22.19.40.37; Thu, 22 Sep 2022 19:41:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232087AbiIWCDj (ORCPT + 99 others); Thu, 22 Sep 2022 22:03:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232225AbiIWCDh (ORCPT ); Thu, 22 Sep 2022 22:03:37 -0400 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F92D118B37; Thu, 22 Sep 2022 19:03:36 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R951e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=ziyangzhang@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0VQUivRf_1663898613; Received: from 30.97.56.82(mailfrom:ZiyangZhang@linux.alibaba.com fp:SMTPD_---0VQUivRf_1663898613) by smtp.aliyun-inc.com; Fri, 23 Sep 2022 10:03:34 +0800 Message-ID: Date: Fri, 23 Sep 2022 10:03:32 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH V5 6/7] ublk_drv: allow new process to open ublk chardev with recovery feature enabled Content-Language: en-US To: ming.lei@redhat.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220922061734.21625-1-ZiyangZhang@linux.alibaba.com> <20220922061734.21625-7-ZiyangZhang@linux.alibaba.com> From: Ziyang Zhang In-Reply-To: <20220922061734.21625-7-ZiyangZhang@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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.