Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D1EFC6FD1D for ; Mon, 20 Mar 2023 15:46:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232179AbjCTPqU (ORCPT ); Mon, 20 Mar 2023 11:46:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232193AbjCTPpz (ORCPT ); Mon, 20 Mar 2023 11:45:55 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 921163B0E8 for ; Mon, 20 Mar 2023 08:36:46 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8E25D21A0D; Mon, 20 Mar 2023 15:36:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1679326605; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/2n2RlldOmjidiqmJZshvaRk8rKCC5U+gVFlarmkiE0=; b=T0hOx8jT8I00OBBO5tPmDAIDF57gkB7nlOki2xVWKdzemFXF+H7Ek6xjTEbbh0wkTPOu+6 mv2eN6Bh72gIhgoGmo88QecB4/xFvpu780Bpu4r0CxUuRDNMmn+my+outmXjC203YJEypV upVGnu0dzoehURV1I1f/xqm0NvdPWRY= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 3A8B113416; Mon, 20 Mar 2023 15:36:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ZLndDI19GGQTTAAAMHmgww (envelope-from ); Mon, 20 Mar 2023 15:36:45 +0000 Message-ID: Subject: Re: [QUESTION] How to fix the race of "mdadm --add" and "mdadm mdadm --incremental --export" From: Martin Wilck To: Mariusz Tkaczyk Cc: Li Xiao Keng , Song Liu , Jes Sorensen , Paul Menzel , Coly Li , linux-raid@vger.kernel.org, linfeilong , louhongxiang@huawei.com, "liuzhiqiang (I)" , miaoguanqin Date: Mon, 20 Mar 2023 16:36:44 +0100 In-Reply-To: <20230316114314.00003004@linux.intel.com> References: <252cdcda-afcd-ce76-00cf-c138136e70ab@huawei.com> <20230314165938.00003030@linux.intel.com> <04a4cc6aac10cd24d5bc0b3485d47f6ccb752eab.camel@suse.com> <20230315111027.0000372d@linux.intel.com> <5fe3dfca-10ad-989a-717d-3007b04163ed@huawei.com> <20230316114314.00003004@linux.intel.com> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org On Thu, 2023-03-16 at 11:44 +0100, Mariusz Tkaczyk wrote: > On Wed, 15 Mar 2023 16:01:26 +0100 > Martin Wilck wrote: > >=20 > > Normally this is what you want to happen if a change uevent for a > > MD > > member device is processed. > >=20 > > The case you're looking at is the exception, as another instance of > > mdamn is handling the device right at this point in time. > >=20 > > Martin > >=20 > Hi, > Code snipped from Incremental, devname seems to be our disk: >=20 > =A0=A0=A0=A0=A0=A0=A0=A0/* 4/ Check if array exists. > =A0=A0=A0=A0=A0=A0=A0=A0 */ > =A0=A0=A0=A0=A0=A0=A0=A0if (map_lock(&map)) > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0pr_err("failed to get exc= lusive lock on mapfile\n"); > =A0=A0=A0=A0=A0=A0=A0=A0/* Now check we can get O_EXCL.=A0 If not, probab= ly "mdadm -A" > has > =A0=A0=A0=A0=A0=A0=A0=A0 * taken over > =A0=A0=A0=A0=A0=A0=A0=A0 */ > =A0=A0=A0=A0=A0=A0=A0=A0dfd =3D dev_open(devname, O_RDONLY|O_EXCL); >=20 > The map_lock in --add should resolve your issue. It seems to be > simplest > option. I we cannot lock udev effectively then it seems to be the > best one. > We need to control adding the device because external metadata is > quite > different and for example in IMSM the initial metadata doesn't point > to > container wanted by user. Hope it clarifies all objections here. >=20 > I don't see any blocker from using locking mechanism for --add. AFAICS it would only help if the code snipped above did not only pr_err() but exit if it can't get an exclusive lock. Martin