Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp951440rdb; Tue, 30 Jan 2024 03:49:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZEiLu9qjB2CRJNczEeJhkxuJ2sQmf7TPcpuAtDG8HWjxlkBzSoUDBS/sYFtpcYucyOxbP X-Received: by 2002:a05:6214:2404:b0:685:2f2c:3ca0 with SMTP id fv4-20020a056214240400b006852f2c3ca0mr11045992qvb.61.1706615363012; Tue, 30 Jan 2024 03:49:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706615362; cv=pass; d=google.com; s=arc-20160816; b=PDYT1NaJIAVlZlVogCciUGwd3i/eQmDQbOo6mlev1FiV+Xndr2vjXvttI21LyC/Ej5 +FZT4w4GmOq6zZPwx3jmHeg42ZzHThQMJ2eyAM7FcnlWjZu7NqofAT50BQ8BYZVbsE/7 rzljuN98L67XKtwp3eY2fjy67EvTnxRewwSbqZfHDmKrYok7OWEWBC3ohW5I4nYFsSzQ ByJmv8xXKSur6YMwgDRfLMlUYQn9L/C748OhRwBdBTZ5e1qW27pR1WI3NCJxT0AjwYDC RhqTpdGiLGkgkCoJseYsOkwCXBxMwI0YUZnUEHDkVhRlOO5LXI0QQQydyIxPoDWkgwph CXBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:in-reply-to:subject:cc:to:from:date :dkim-signature; bh=XNC4RnR1LP3JLZK3mU2j4+a+R8GFkfNE9wD4WslHeU4=; fh=Sly2fACsRd1JKbkLePJDwD/5uYPRJsQP3TvuVCugr1w=; b=Djtxz10vH5G0QJBaWRy1uE6WabeX25smtDpetyl1qEuxmoWmpoGFNC5B7QdxYadMrd nKUbTm2pBY5Yqe0BxvDPVyX8tk6K4njzZvMOv7ngVq1N6YmZyrr2AgD/TW2/WHtJnWpJ 3XbnwUBZfVHN/ORnVuFMLBdamcRv2I/qIOSipAAuYmrTMN/uJD2svUbbmP8A8xUZbzdl w5Ew8tkpQskbB+qkm5OhQxQlpDUZl4cNU05ABj3ubX2UyZCcue4YuRHoMC4S5bP87uen i3X5sXxmTqIrN0/71/kfmyvXEQgxmXvC0vrLL5muMUPa1cG0ey5JDneP6kr4+/FqFWAe 1psw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iWzCyAlT; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-44546-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44546-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 13-20020a0562140d0d00b0068c4f26b721si4148896qvh.612.2024.01.30.03.49.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 03:49:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44546-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iWzCyAlT; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-44546-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44546-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B970D1C25FCF for ; Tue, 30 Jan 2024 11:49:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 326156A02C; Tue, 30 Jan 2024 11:46:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iWzCyAlT" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E11A26773C for ; Tue, 30 Jan 2024 11:46:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706615175; cv=none; b=I+paSmgdbhlZGTrsrUoRP1egfkDOy9dCeQ8venPsUxrfU6H74ntGVYSz/dk1kZykkCDExQu8rJt2aVW4WkO7Jgu+9OrfaFtHRtqoNwVvGaGf4iCUNwZG211PWgZl95sZFLRNwP93kUk7I1RV+1WJrrvIwrzMqFjKjZCITcWhqXI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706615175; c=relaxed/simple; bh=s6N1gkYvyY3hDBDbP8HT9EefNkFyTfoHZIbsaI0LxsY=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=tKSyRuUVdVQfcts+5On/G/wHdhcOrgQIgXrX3sF/46dZWS+SlVY3NtZJHQxUcpbXDYq0KBa0j/YpF7hHJQArC4sfjxB1kV3ckQnUEqiEQGVdT2bHNSinpqEEEU4T2gcq8AmZefwM5H7Cqv31oT2uZBcYxeOVFf2Itw8D+dDt4Zs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=iWzCyAlT; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706615172; 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=XNC4RnR1LP3JLZK3mU2j4+a+R8GFkfNE9wD4WslHeU4=; b=iWzCyAlTyj5JgZAdW+17FtvMeEXORatJuRd1yIJgRivdElGaE9IGMup65eBIqCe9GZnJGU LT2dh9vioQrzgfEy+gExN187K/zXUieZB+FpBp6py8IW3OTJbzaDmVZvA6KFN/ZiwVkM9/ 2EIaq8mGWbDlXz7kXaumzjFNKhs0+mw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-571-1fs-sfDbNryD18DHM1ANyA-1; Tue, 30 Jan 2024 06:46:09 -0500 X-MC-Unique: 1fs-sfDbNryD18DHM1ANyA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 04E9B85A599; Tue, 30 Jan 2024 11:46:09 +0000 (UTC) Received: from file1-rdu.file-001.prod.rdu2.dc.redhat.com (unknown [10.11.5.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C01640C95AD; Tue, 30 Jan 2024 11:46:08 +0000 (UTC) Received: by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix, from userid 12668) id 7F56B30C14EB; Tue, 30 Jan 2024 11:46:08 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by file1-rdu.file-001.prod.rdu2.dc.redhat.com (Postfix) with ESMTP id 7A9C13FB4E; Tue, 30 Jan 2024 12:46:08 +0100 (CET) Date: Tue, 30 Jan 2024 12:46:08 +0100 (CET) From: Mikulas Patocka To: Yu Kuai cc: heinzm@redhat.com, xni@redhat.com, agk@redhat.com, snitzer@kernel.org, dm-devel@lists.linux.dev, song@kernel.org, yukuai3@huawei.com, jbrassow@f14.redhat.com, neilb@suse.de, shli@fb.com, akpm@osdl.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com Subject: Re: [PATCH RFC v4 13/14] dm: wait for IO completion before removing dm device In-Reply-To: <20240130021843.3608859-14-yukuai1@huaweicloud.com> Message-ID: References: <20240130021843.3608859-1-yukuai1@huaweicloud.com> <20240130021843.3608859-14-yukuai1@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 On Tue, 30 Jan 2024, Yu Kuai wrote: > From: Yu Kuai > > __dm_destroy() guarantee that device openers is zero, and then > only call 'presuspend' and 'postsuspend' for the target. For > request-based dm, 'md->holders' will be grabbed for each rq and > __dm_destroy() will wait for 'md->holders' to be zero. However, for > bio-based device, __dm_destroy() doesn't wait for all bios to be done. > > Fix this problem by calling dm_wait_for_completion() to wail for all > inflight IO to be done, like what dm_suspend() does. If the number of openers is zero, it is guaranteed that there are no bios in flight. Therefore, we don't have to wait for them. If there are bios in flight, it is a bug in the code that issues the bios. You can put WARN_ON(dm_in_flight_bios(md)) there. Mikulas > Signed-off-by: Yu Kuai > --- > drivers/md/dm.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/md/dm.c b/drivers/md/dm.c > index 8dcabf84d866..2c0eae67d0f1 100644 > --- a/drivers/md/dm.c > +++ b/drivers/md/dm.c > @@ -58,6 +58,7 @@ static DEFINE_IDR(_minor_idr); > static DEFINE_SPINLOCK(_minor_lock); > > static void do_deferred_remove(struct work_struct *w); > +static int dm_wait_for_completion(struct mapped_device *md, unsigned int task_state); > > static DECLARE_WORK(deferred_remove_work, do_deferred_remove); > > @@ -2495,6 +2496,8 @@ static void __dm_destroy(struct mapped_device *md, bool wait) > if (!dm_suspended_md(md)) { > dm_table_presuspend_targets(map); > set_bit(DMF_SUSPENDED, &md->flags); > + if (wait) > + dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE); > set_bit(DMF_POST_SUSPENDING, &md->flags); > dm_table_postsuspend_targets(map); > } > -- > 2.39.2 >