Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp358233pxk; Thu, 3 Sep 2020 01:15:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxx4BcDShLxSPXlr4xy6S8nfLJ9PesbxyR2Qsgk2pJVnLFdqCt5VL/wDJo9q2+vxp+1fZx1 X-Received: by 2002:a17:906:cb94:: with SMTP id mf20mr1008181ejb.8.1599120944192; Thu, 03 Sep 2020 01:15:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599120944; cv=none; d=google.com; s=arc-20160816; b=DKoRJUSWsK0IeZ3Bxn69M91oQH3LIEdyeM6ETwEMLRDqxSGhHPMCBxrQU5chNYJ8dz XsqunfXG6hVm7gr+hRFmi1K1bZTb8mar4ubYm4+1gJcuOfJ6RgIX5+qXrDfQbgf4hnCh vbn5DoWjZvyM9GSRi1X5q6AoQlEhRUm/EZf4h8OlV9uY67GQS0HYk1q+1j/CCEEDu3e/ WqHd44eqKtRFlpfzvdufp8dhsgl+tkMj4wEmhCSnec4SbTy/JCKcSZNc87wbh5mN6yr2 4F5MrVit9a5wpSQJtX/8YmNP8bmDf/7J7hIjdI1t82S10fE6tu/YEXsivM0wc+rb+gBk BQLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gTvoN30CdkKLQtIKPaFxicLUsCyMtAXc2Ckoop6VvpU=; b=P8pZ6PiUyrtPD33jeg0gewZ9EWvxB3DZb4+44VQR3NnhBtl/8En33yEmYXCLl+7CdA +YJG87TjAFgZQ9fmohRcU6XSbR82vMa74VuOMp0tJC4bqQTBZtQ7oiW37mFw0Y9Y3bSh JQgPbc6HPVmC0QCm2+oA0zgrzoLyi9qlfmvGAwKVASeV2u+MGzRtONj1lWDspyeq/Vuq odgELAmSEW4mwn20GBOrDE8lxLFy/xP4zb+yFS/Q0N7GCKkEbhYaXUeNzWMjF7xe8iNt XX2wVJp5lxMzmgoYChagFCIe3/yQZksBXmH/piMUaCRuae8QPUzxP6zwKVODxtPtN5Ul ywtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=pcGloet3; 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 n24si1335589ejs.611.2020.09.03.01.15.20; Thu, 03 Sep 2020 01:15:44 -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=fail header.i=@infradead.org header.s=casper.20170209 header.b=pcGloet3; 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 S1728851AbgICINr (ORCPT + 99 others); Thu, 3 Sep 2020 04:13:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728299AbgICIBq (ORCPT ); Thu, 3 Sep 2020 04:01:46 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75275C061244; Thu, 3 Sep 2020 01:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=gTvoN30CdkKLQtIKPaFxicLUsCyMtAXc2Ckoop6VvpU=; b=pcGloet3zWNds23vPERqx7e9zk ZtPB+QB3xFyPt3BhthLrn3D65KwYrvM0b74bQaAYEV79jwkwXVO4nJcxHKiooMf0cSknGY1622AkX vRiT4ycFTmiG9vH3/hRfaSuQnfk0Xv++GdVDLNulMLWNnVsAtRkFks5rQk+IDx6AInzYQYup/Rp8q 6fpHuMd3fR/wbby0c3Z42hJ287ISaa7Y/mNLiEZzzVctZbbTyrrbZuxKrZI7OZvzoCR/X1nFzdH6r 0qmpiP9/HTOAqR3d82rNPqy19VdYYk0piirzgV38mDMTypxmp3xjovRQrk9LroAT57wjE0qA6IdCm h+X6p4WQ==; Received: from [2001:4bb8:184:af1:c70:4a89:bc61:2] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDkBd-0006cQ-T6; Thu, 03 Sep 2020 08:01:38 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Denis Efremov , "David S. Miller" , Song Liu , Al Viro , Finn Thain , Michael Schmitz , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org, linux-raid@vger.kernel.org, linux-scsi@vger.kernel.org, linux-m68k@lists.linux-m68k.org Subject: [PATCH 12/19] md: use __register_blkdev to allocate devices on demand Date: Thu, 3 Sep 2020 10:01:12 +0200 Message-Id: <20200903080119.441674-13-hch@lst.de> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200903080119.441674-1-hch@lst.de> References: <20200903080119.441674-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the simpler mechanism attached to major_name to allocate a brd device when a currently unregistered minor is accessed. Signed-off-by: Christoph Hellwig Acked-by: Song Liu --- drivers/md/md.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 9562ef598ae1f4..be3625acf67d7e 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -5766,11 +5766,12 @@ static int md_alloc(dev_t dev, char *name) return error; } -static struct kobject *md_probe(dev_t dev, int *part, void *data) +static void md_probe(dev_t dev) { + if (MAJOR(dev) == MD_MAJOR && MINOR(dev) >= 512) + return; if (create_on_open) md_alloc(dev, NULL); - return NULL; } static int add_named_array(const char *val, const struct kernel_param *kp) @@ -6536,7 +6537,7 @@ static void autorun_devices(int part) break; } - md_probe(dev, NULL, NULL); + md_probe(dev); mddev = mddev_find(dev); if (!mddev || !mddev->gendisk) { if (mddev) @@ -9548,18 +9549,15 @@ static int __init md_init(void) if (!md_misc_wq) goto err_rdev_misc_wq; - if ((ret = register_blkdev(MD_MAJOR, "md")) < 0) + ret = __register_blkdev(MD_MAJOR, "md", md_probe); + if (ret < 0) goto err_md; - if ((ret = register_blkdev(0, "mdp")) < 0) + ret = __register_blkdev(0, "mdp", md_probe); + if (ret < 0) goto err_mdp; mdp_major = ret; - blk_register_region(MKDEV(MD_MAJOR, 0), 512, THIS_MODULE, - md_probe, NULL, NULL); - blk_register_region(MKDEV(mdp_major, 0), 1UL<