Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp120568iob; Tue, 17 May 2022 20:54:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFVxLGXU9Gz4pFU2KVBWJPyUXY8OZp0YC+6ghOLjd8AsnOnzp0WNuZcG7F+L7RHKwZDKSF X-Received: by 2002:a17:90b:4a90:b0:1dc:4122:6a70 with SMTP id lp16-20020a17090b4a9000b001dc41226a70mr27877344pjb.216.1652846078670; Tue, 17 May 2022 20:54:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652846078; cv=none; d=google.com; s=arc-20160816; b=yZkWWgCUW5nPeUbtVyB0B56iVrZI6u329nBVCh+d6Y9G9ZpwyI9P1pY1fqfgayWtEZ YFE8xXQ/VijdDbqwowywWLy4HiLA7tfOxbhoI7707RK+/E9BT0/2azUjmqRCWM8HDVJN +ZGH/iudO+tmLb3SJMuxzaKV5L2kHnpDAd+Iuiwxik9zlA4I+cP4r/U8JzgWuXQesaAM cWwgSbRTFciewu7a7c9YLJhgbhGwdQjxq3IWEtasjRd4mE6XGEEodXz1NrklcRNNmhqV zxonJqSOLjIeGt1OIXD1NPQMDmGZdvWxXjbaA/TlnIXxy2REzryEaVphXcNZjAVAd/cM ymzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=CCBYm7JRURrb8ISptdPCXIyZxDNW+RgvRlpoFcroHpc=; b=vpP6ib0gKLtP4YOiCAOCbjafqYcW8zAnELqGHiJOotHBXyR3hDSfmnilOgrskuTIC5 Gm276W0oC2n/M69mD29H8qEU4yU5aVcJrS5U7SxkptHf4pRdGeuQX6vZhaRtwmbW5KtT QuXUmyqLqB301SCvIucoIwJGPgIDUvWljNQ9rcMjVcG5R7M1JlFit6zipr/HV2bpkGLN i7pcCc24rB3yF298/Zhs3SvfPC70za5l9b3TrXC3p1/Z82slmeGndY82QPsh3zxvff+3 m+/ByZZMmhYm7gW4NBxR05ml5LVEPn6xTJJGR7zmWWJNwKb59cGNvRY2GuJRbYDMAV8m XpuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AEIzXRNh; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id a1-20020a170902710100b00153b2d1657fsi1159326pll.391.2022.05.17.20.54.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 20:54:38 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AEIzXRNh; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 79C1C7092F; Tue, 17 May 2022 20:35:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345442AbiEQMzj (ORCPT + 99 others); Tue, 17 May 2022 08:55:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236081AbiEQMzh (ORCPT ); Tue, 17 May 2022 08:55:37 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4B6D321834 for ; Tue, 17 May 2022 05:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652792135; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CCBYm7JRURrb8ISptdPCXIyZxDNW+RgvRlpoFcroHpc=; b=AEIzXRNhRi1iMKhUbrvWr6VpAK9rysTSFka8eQ2NX/GOkzFSoNODsoyk+dt9n3KirHRj1t +8wVCN6HjlOA31yFDum3XkT9Gd06pr18HzqFLnyrPvzoEDI7dJWRlsbixZCI39+4dBQlBY C3THFZTgV3I41FBeYUJJzCoHKx5g2iU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-653-QoLd5d2PMYWgONyitcW1ZQ-1; Tue, 17 May 2022 08:55:32 -0400 X-MC-Unique: QoLd5d2PMYWgONyitcW1ZQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A900C811E84; Tue, 17 May 2022 12:55:31 +0000 (UTC) Received: from T590 (ovpn-8-20.pek2.redhat.com [10.72.8.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D81F140CF8F6; Tue, 17 May 2022 12:55:25 +0000 (UTC) Date: Tue, 17 May 2022 20:55:20 +0800 From: Ming Lei To: Ziyang Zhang Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Harris James R , io-uring@vger.kernel.org, Gabriel Krisman Bertazi , Xiaoguang Wang , Stefan Hajnoczi , Jens Axboe Subject: Re: [PATCH V2 1/1] ubd: add io_uring based userspace block driver Message-ID: References: <20220517055358.3164431-1-ming.lei@redhat.com> <20220517055358.3164431-2-ming.lei@redhat.com> <55d724a8-ed7d-ae92-ca6d-3582e13587db@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <55d724a8-ed7d-ae92-ca6d-3582e13587db@linux.alibaba.com> X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Tue, May 17, 2022 at 06:00:57PM +0800, Ziyang Zhang wrote: > On 2022/5/17 13:53, Ming Lei wrote: > > > + > > +static void ubd_cancel_queue(struct ubd_queue *ubq) > > +{ > > + int i; > > + > > + for (i = 0; i < ubq->q_depth; i++) { > > + struct ubd_io *io = &ubq->ios[i]; > > + > > + if (io->flags & UBD_IO_FLAG_ACTIVE) { > > + io->flags &= ~UBD_IO_FLAG_ACTIVE; > > + io_uring_cmd_done(io->cmd, UBD_IO_RES_ABORT, 0); > > + } > > + } > > +} > > Hi Ming, > > When ubdsrv sends STOP_DEV and all active IOs in ubd_drv are done(UBD_IO_RES_ABORT), > there may be still some IOs handled by ubdsrv(UBD_IO_FLAG_ACTIVE not set). > When these IOs complete and return to ubd_drv, how to handle them? Either UBD_IO_COMMIT_AND_FETCH_REQ or UBD_IO_COMMIT_REQ will be sent to ubd_drv for completing these IOs. And finally ubd_cancel_dev() in ubd driver will cancel all pending io commands, so io_uring can be exited. I guess UBD_IO_COMMIT_REQ can be removed too. > I find that UBD_IO_FETCH_REQ are still set, > so will these IOs be issued to ubdsrv again or canceled? > (I see ubd_drv fails IOs when the daemon is dying > but maybe here the daemon is still alive) If daemon is alive, ubd_drv will rely on ubq_daemon for completing all inflight IOs. Otherwise, the monitor work will be triggered for completing/failing inflight IOs. The mechanism is actually very simple: static void ubd_stop_dev(struct ubd_device *ub) { mutex_lock(&ub->mutex); if (!disk_live(ub->ub_disk)) goto unlock; del_gendisk(ub->ub_disk); // drain & wait in-flight IOs ub->dev_info.state = UBD_S_DEV_DEAD; ub->dev_info.ubdsrv_pid = -1; ubd_cancel_dev(ub); //No IO is possible now, so cancel pending io commands unlock: mutex_unlock(&ub->mutex); cancel_delayed_work_sync(&ub->monitor_work); } When waiting for IO completion in del_gendisk(), in case that ubq_daemon is exiting/dying, monitor work will be triggered to call ubd_abort_queue() to fail in-flight requests for making forward progress. ubd_abort_queue() may looks a bit tricky to try using task work for aborting request, that is just for sync with ubd_rq_task_work_fn(). Thanks, Ming