Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6327562rwl; Wed, 22 Mar 2023 09:11:26 -0700 (PDT) X-Google-Smtp-Source: AK7set8Ft/mvzq+sIeVdSxXCZTIyybympKVX/C96wyoAdjlIjujz6jM5F3gPa0wSam4N5qwGpvmi X-Received: by 2002:a17:906:3911:b0:935:20d8:c5f with SMTP id f17-20020a170906391100b0093520d80c5fmr8412908eje.58.1679501486202; Wed, 22 Mar 2023 09:11:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679501486; cv=none; d=google.com; s=arc-20160816; b=zzXcYjW7Nvb0S3uTxVvYlmz/7TyBUFujxiqp71o1KAQIVHDPEl9uXDXFbOYpL/ICHA bybOFkmTp2htifEKfX3puuutjUMbwaPZDt3T7WWJSlF8gPNpXBxZQwu6jP4p1JmRcNWN KCqbJDb0bGX2YWyKCa5sIohMxq4o/oiPquMehq+8BvBhxj4sEINYQHDsJ3+muj8yeyHb TIUaxchcy0StR4iE6H2JeWpQYZHUUVlXTN3YLBr/0BdWKYOeYOxKjX0leJFk7MWFYhgG RWAG4pwhtJZaCcA0ab6+dqsBNeR38bVm2oYwCYeOZZK7hSMSBxJ6YVq+5jo9dLuxF1ny /fVQ== 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=1bX4swPuNAE8QO6vwyly7Hj41GaBwCiM8/ocxk1BKj4=; b=K2M2XzdKB17MoFu3yHyJh56D85ARSDyizw25nzGiem2RDtKjO6MJeKhXYqdkZaqYFl Zvc8gzKeEBJo6Ol1k2Xhu2VMKwxCDp02mZqcD4Lkm5jOG57xxxvZo8RdLaeiURBd2iLO Znnj32Ql/1dcRyJmN/nCi+SzE4SXMUMK22Ju00Sg5zc5SVW2WWJn2hRXPKO889v4LIHj NCQ8eqD1bWxT16tQPLwuYC9+tVb4JX8YiVS0QyKN4ychEIv7+jaTNgr9QnbNPGDgzCjk Ygcr8MOMXBpk4JhToph86FwcplLNUC8ibfEgBPP5EDwWnfC++xBRmHCACirkESvg/t8b 8fHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OIx7RNDY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z15-20020a170906944f00b0092aedd45e14si14426043ejx.329.2023.03.22.09.11.02; Wed, 22 Mar 2023 09:11:26 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OIx7RNDY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230345AbjCVQKX (ORCPT + 99 others); Wed, 22 Mar 2023 12:10:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229854AbjCVQKS (ORCPT ); Wed, 22 Mar 2023 12:10:18 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A34765C4F for ; Wed, 22 Mar 2023 09:09:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679501351; 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=1bX4swPuNAE8QO6vwyly7Hj41GaBwCiM8/ocxk1BKj4=; b=OIx7RNDYef+PgAs77Q6rocjFkEUKG4eiOHIJWJI6+4ORCXwBdi9YDNBFN0GdoZKUL8QyZZ bC1PTP38DtJgmLcL+IGIue949l9SZPg1aFnCXSDt81OLO/mE3fbkAIg4+2m4LmmzAT+B55 fQsB2fvhG/rHh7a34VW6jm3M8V3hT5I= 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-240-ZxPoGhpZNJi8CF_LsICsCw-1; Wed, 22 Mar 2023 12:09:05 -0400 X-MC-Unique: ZxPoGhpZNJi8CF_LsICsCw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4F5C68030D6; Wed, 22 Mar 2023 16:09:04 +0000 (UTC) Received: from ovpn-8-17.pek2.redhat.com (ovpn-8-18.pek2.redhat.com [10.72.8.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A89D41410F1E; Wed, 22 Mar 2023 16:08:57 +0000 (UTC) Date: Thu, 23 Mar 2023 00:08:51 +0800 From: Ming Lei To: Jan Kara Cc: Yu Kuai , hch@infradead.org, axboe@kernel.dk, yukuai3@huawei.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, Xiao Ni , linux-raid@vger.kernel.org, ming.lei@redhat.com Subject: Re: [PATCH] block: don't set GD_NEED_PART_SCAN if scan partition failed Message-ID: References: <20230322035926.1791317-1-yukuai1@huaweicloud.com> <20230322094707.7xsexupiijmxxlom@quack3> <20230322130709.7zp7spmhcmjbfjvm@quack3> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230322130709.7zp7spmhcmjbfjvm@quack3> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 Wed, Mar 22, 2023 at 02:07:09PM +0100, Jan Kara wrote: > On Wed 22-03-23 19:34:30, Ming Lei wrote: > > On Wed, Mar 22, 2023 at 10:47:07AM +0100, Jan Kara wrote: > > > On Wed 22-03-23 15:58:35, Ming Lei wrote: > > > > On Wed, Mar 22, 2023 at 11:59:26AM +0800, Yu Kuai wrote: > > > > > From: Yu Kuai > > > > > > > > > > Currently if disk_scan_partitions() failed, GD_NEED_PART_SCAN will still > > > > > set, and partition scan will be proceed again when blkdev_get_by_dev() > > > > > is called. However, this will cause a problem that re-assemble partitioned > > > > > raid device will creat partition for underlying disk. > > > > > > > > > > Test procedure: > > > > > > > > > > mdadm -CR /dev/md0 -l 1 -n 2 /dev/sda /dev/sdb -e 1.0 > > > > > sgdisk -n 0:0:+100MiB /dev/md0 > > > > > blockdev --rereadpt /dev/sda > > > > > blockdev --rereadpt /dev/sdb > > > > > mdadm -S /dev/md0 > > > > > mdadm -A /dev/md0 /dev/sda /dev/sdb > > > > > > > > > > Test result: underlying disk partition and raid partition can be > > > > > observed at the same time > > > > > > > > > > Note that this can still happen in come corner cases that > > > > > GD_NEED_PART_SCAN can be set for underlying disk while re-assemble raid > > > > > device. > > > > > > > > > > Fixes: e5cfefa97bcc ("block: fix scan partition for exclusively open device again") > > > > > Signed-off-by: Yu Kuai > > > > > > > > The issue still can't be avoided completely, such as, after rebooting, > > > > /dev/sda1 & /dev/md0p1 can be observed at the same time. And this one > > > > should be underlying partitions scanned before re-assembling raid, I > > > > guess it may not be easy to avoid. > > > > > > So this was always happening (before my patches, after my patches, and now > > > after Yu's patches) and kernel does not have enough information to know > > > that sda will become part of md0 device in the future. But mdadm actually > > > deals with this as far as I remember and deletes partitions for all devices > > > it is assembling the array from (and quick tracing experiment I did > > > supports this). > > > > I am testing on Fedora 37, so mdadm v4.2 doesn't delete underlying > > partitions before re-assemble. > > Strange, I'm on openSUSE Leap 15.4 and mdadm v4.1 deletes these partitions > (at least I can see mdadm do BLKPG_DEL_PARTITION ioctls). And checking > mdadm sources I can see calls to remove_partitions() from start_array() > function in Assemble.c so I'm not sure why this is not working for you... I added dump_stack() in delete_partition() for partition 1, not observe stack trace during booting. > > > Also given mdadm or related userspace has to change for avoiding > > to scan underlying partitions, just wondering why not let userspace > > to tell kernel not do it explicitly? > > Well, those userspace changes are long deployed, now you would introduce > new API that needs to proliferate again. Not very nice. Also how would that > exactly work? I mean once mdadm has underlying device open, the current > logic makes sure we do not create partitions anymore. But there's no way > how mdadm could possibly prevent creation of partitions for devices it > doesn't know about yet so it still has to delete existing partitions... I meant if mdadm has to change to delete existed partitions, why not add one ioctl to disable partition scan for this disk when deleting partitions/re-assemble, and re-enable scan after stopping array. But looks it isn't so, since you mentioned that remove_partitions is supposed to be called before starting array, however I didn't observe this behavior. I am worrying if the current approach may cause regression, one concern is that ioctl(BLKRRPART) needs exclusive open now, such as: 1) mount /dev/vdb1 /mnt 2) ioctl(BLKRRPART) may fail after removing /dev/vdb3 thanks, Ming