Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5169751pxv; Tue, 20 Jul 2021 22:02:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyH/nFcNrkspeVlMc8K+24oViWAX8uohfE1IX8kGAfEX4bU7Dycuaj2qaunINIxWWScy0J X-Received: by 2002:a5d:89ce:: with SMTP id a14mr16975701iot.127.1626843732846; Tue, 20 Jul 2021 22:02:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626843732; cv=none; d=google.com; s=arc-20160816; b=A54rWOgfCH36X/ifOYMTSLVyr9qpX7k/jtqJupDULnC2eZV7qtEuKFz3sqLeKGdkC0 OwuHO1jfTyk5Y8wZ5n1u7Wk8kBysSgc6WTe3tYeTAIKQlydPBEtwXLVuSTAEUeRrFvce bKflJ5xsCB+4vhPMCY/pXgHI+VxXQE4bSpWsqekG7nRN6foezfbOq4LDn5vwRGhV38At FE1XCwxKi4/mSJauYT9g7KX5i+FLTdNksLmvMGGnwTKuInqnTcixDJPPCLtqGEazuSmV KlaD3G7V5Kdutwa+J6exsADjUgYA6tTaxz7L4Qmhal+zZg2LSOe5FcTFuIvOwkJrVkT8 O1uA== 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=IctsTVrtwipEv00mkrFyUnMJXKowudn2hKnX1KBUBjo=; b=ABnzAyMDSWRAM9wnsOYBC0/pwBxJBjR7FrmpzYaZRQ1n4o03iASI1IfJNztHxPaMMw RPRZuI3xf8y+wXHcNH4EAgk8RcXx0Tf/b3JACaZCXspu+GyOuNupBcMi566gEWQkWfUD w6LjN6I1YfFd7JRDMlNKig6IokGhHnrUQA5zYiH+48vfj+llbl+zdv1kpXF5pm0bHRSt TwewtqyMx+9tyvTZi560tjAt/8ZmvciK+wA0iudhGUjjHYCnyqQX4b6WW7ozek0MxRhj lOVA3v2Dv/bYLbBeWGcjzstGNSU4kT2gAcpPC74Nj7DVr8YX/7TajhQRV4YzeLBwHLgn 38VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=IXImCDQ2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e20si19211388iow.6.2021.07.20.22.02.01; Tue, 20 Jul 2021 22:02:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=IXImCDQ2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232514AbhGUETt (ORCPT + 99 others); Wed, 21 Jul 2021 00:19:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232359AbhGUETi (ORCPT ); Wed, 21 Jul 2021 00:19:38 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B714EC061574; Tue, 20 Jul 2021 22:00:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=IctsTVrtwipEv00mkrFyUnMJXKowudn2hKnX1KBUBjo=; b=IXImCDQ2qlkdgYwRnUusz3CUhb x3Uir6PJDYrIuiJWCCbQXFXPwpEh8Ygz9na3CmtqFlPzGL7QyppNWm2BPlCToQ+A8xvJAk9vE5uh5 SmXfvm9o7alqEz7CzZ9hE+WCFs8/IRthEYy0GhaTwoi2aByAbp4fIOzC1OtpxtElaeI182YIe5yyr 2otH1MtdwlbtYQ3ZpnEB691t+X9zOoV3WzOESfm2kC81aZxjog/LnuaMAZ75Bhf+6xdE1dox/IBgG X23ZNHb9LrkQ+bWZ9FMOdPlIpuAefmEUeqKDp4krHV4W4ZEpvuJy2WUsRNRemRf6CGm7/0nHH6VRD KxmAJmOw==; Received: from hch by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m64KU-008o8T-0m; Wed, 21 Jul 2021 04:59:39 +0000 Date: Wed, 21 Jul 2021 05:59:34 +0100 From: Christoph Hellwig To: Luis Chamberlain Cc: axboe@kernel.dk, hare@suse.de, bvanassche@acm.org, ming.lei@redhat.com, hch@infradead.org, jack@suse.cz, osandov@fb.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/5] block: add flag for add_disk() completion notation Message-ID: References: <20210720182048.1906526-1-mcgrof@kernel.org> <20210720182048.1906526-2-mcgrof@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210720182048.1906526-2-mcgrof@kernel.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 20, 2021 at 11:20:44AM -0700, Luis Chamberlain wrote: > Often drivers may have complex setups where it is not > clear if their disk completed their respective *add_disk*() > call. They either have to invent a setting or, they > incorrectly use GENHD_FL_UP. Using GENHD_FL_UP however is > used internally so we know when we can add / remove > partitions safely. We can easily fail along the way > prior to add_disk() completing and still have > GENHD_FL_UP set, so it would not be correct in that case > to call del_gendisk() on the disk. > > Provide a new flag then which allows us to check if > *add_disk*() completed, and conversely just make > del_gendisk() check for this for drivers so that > they can safely call del_gendisk() and we'll figure > it out if it is safe for you to call this. > > Signed-off-by: Luis Chamberlain > --- > block/genhd.c | 8 ++++++++ > include/linux/genhd.h | 11 ++++++++++- > 2 files changed, 18 insertions(+), 1 deletion(-) > > diff --git a/block/genhd.c b/block/genhd.c > index af4d2ab4a633..a858eed05e55 100644 > --- a/block/genhd.c > +++ b/block/genhd.c > @@ -539,6 +539,8 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, > > disk_add_events(disk); > blk_integrity_add(disk); > + > + disk->flags |= GENHD_FL_DISK_ADDED; I guess I failed to mention it last time - but I think this needs to go into disk->state as dynamic state. > + * Drivers can safely call this even if they are not sure if the respective > + * __device_add_disk() call succeeded. > + * > * Drivers exist which depend on the release of the gendisk to be synchronous, > * it should not be deferred. > * > @@ -578,6 +583,9 @@ void del_gendisk(struct gendisk *disk) > { > might_sleep(); > > + if (!blk_disk_added(disk)) > + return; I still very much disagree with this check. It just leads to really bad driver code. In genral we need to _fix_ the existing abuses of the UP check in drivers, not spread this kind of sloppyness further.