Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1979984ybh; Tue, 14 Jul 2020 12:11:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBjFovxZnXj4yA5Eju4+66hsTDnutuNSStkGfkwNZZZdhNKslqCoIAvL+FmO/8Ihbo/vPP X-Received: by 2002:a50:9b18:: with SMTP id o24mr6191004edi.335.1594753872412; Tue, 14 Jul 2020 12:11:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594753872; cv=none; d=google.com; s=arc-20160816; b=zji02XXK+8JFvDhb2d4a2wL+jX1eCQiM/UmNuXrlL3NH9OPm0AW6eFDi3mSGR+i2U1 C+/iBkZ8NWjW7ilE2o1qHwwVpoqTQyB6uE8LrDxkAQ3jAfbxrrS0Pm7ObO2U4fG11T+0 jjZuHWVtWxnCUToFWZ7qyb4YyjaD1Mc+9Qq6PCcd9J30a6idwkwPeV1x4jOa4kjxY36t lMKZIGRe1DfIkawmAO896HscqmiF/7ACWIfS3zt7+u4wBF/4maUPBI+f+HJ3RHKwe9H7 FH7OC8akJbJXukrA/zNOplTfRwdVUTgOAWdRPb7MNt61aOVDBZbBxyQReieIKTU+Ex9G vJxw== 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=coa7A11I6J0G4iER3rlCNPw/aWxiSnKv3sMdMKmI36w=; b=mram1E+BI1Fi+7Nl00WBAvUlxVIC1hOVLgFQnFLBajU3YAEhOugIdOzIKJVK+ktdcu /SYQqXSNC9hRYToVcPDNOJxQ/309zHArtfF96AL9G+TISbwBzjZjWYwOf7MtiCDqUCIc AVeG+o5zlw1sykvJbxt/0EjTKp0TV0vR1c//nAwdX6RZYgCzZBPJadI6kXgELgxOB2lv AhdgediwtJ2coQIxqomxrj0gNk7LLjzRksSeqKpkIV53C4kqt+GqJ9rlUF7Vcn+xC83p u0vDyI1YSHXonXsZPOnbmLYf+KjekJ5qrOGRKslkUHGZVEr2SP0SZohLUt8hyqDXZt8T igIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=uNWpmhH5; 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 g4si11316980edq.459.2020.07.14.12.10.49; Tue, 14 Jul 2020 12:11: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=fail header.i=@infradead.org header.s=casper.20170209 header.b=uNWpmhH5; 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 S1731492AbgGNTKq (ORCPT + 99 others); Tue, 14 Jul 2020 15:10:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731253AbgGNTJC (ORCPT ); Tue, 14 Jul 2020 15:09:02 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27CB1C061755; Tue, 14 Jul 2020 12:09:02 -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=coa7A11I6J0G4iER3rlCNPw/aWxiSnKv3sMdMKmI36w=; b=uNWpmhH5Gc6lX6cAB74UuI1UIs l0DyhCXO7oVbwFtvveNze9pTowzTWMnD7BOU5rjo55F0ytBkF5aYJfZvRqFWcSwguq6JEKIehc3Px J9viANZqmzRYLofiSeq+f0xDev4UjrfJjOitRJdQ6X+jHiLdQzoAPuF6bBD6yERSAR46F23GbnNMt IkaZOq78Z5/kD8l/Ko45DyYd1pnQJ0ALjbldwy6KUW9PCevbNpg7PGNBBjgvXWvh3n2Ya+C3yEQQJ TaevvW4LN7CGZPLA0n7itCzXoEtGS/JxOTeTHgcUqJPTIu/DGFA/fOqbq84woQt/flbHiNpOrBvO0 jh/z0ZLg==; Received: from [2001:4bb8:188:5f50:f037:8cfe:627e:7028] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvQIV-0005qg-Jm; Tue, 14 Jul 2020 19:09:00 +0000 From: Christoph Hellwig To: linux-kernel@vger.kernel.org Cc: "H. Peter Anvin" , Song Liu , Al Viro , Linus Torvalds , linux-raid@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 08/23] md: simplify md_setup_drive Date: Tue, 14 Jul 2020 21:04:12 +0200 Message-Id: <20200714190427.4332-9-hch@lst.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714190427.4332-1-hch@lst.de> References: <20200714190427.4332-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 Move the loop over the possible arrays into the caller to remove a level of indentation for the whole function. Signed-off-by: Christoph Hellwig Acked-by: Song Liu --- drivers/md/md-autodetect.c | 203 ++++++++++++++++++------------------- 1 file changed, 101 insertions(+), 102 deletions(-) diff --git a/drivers/md/md-autodetect.c b/drivers/md/md-autodetect.c index 6bc9b734eee6ff..a43a8f1580584c 100644 --- a/drivers/md/md-autodetect.c +++ b/drivers/md/md-autodetect.c @@ -27,7 +27,7 @@ static int __initdata raid_noautodetect=1; #endif static int __initdata raid_autopart; -static struct { +static struct md_setup_args { int minor; int partitioned; int level; @@ -126,122 +126,117 @@ static inline int create_dev(char *name, dev_t dev) return ksys_mknod(name, S_IFBLK|0600, new_encode_dev(dev)); } -static void __init md_setup_drive(void) +static void __init md_setup_drive(struct md_setup_args *args) { - int minor, i, ent, partitioned; + int minor, i, partitioned; dev_t dev; dev_t devices[MD_SB_DISKS+1]; + int fd; + int err = 0; + char *devname; + mdu_disk_info_t dinfo; + char name[16]; - for (ent = 0; ent < md_setup_ents ; ent++) { - int fd; - int err = 0; - char *devname; - mdu_disk_info_t dinfo; - char name[16]; + minor = args->minor; + partitioned = args->partitioned; + devname = args->device_names; - minor = md_setup_args[ent].minor; - partitioned = md_setup_args[ent].partitioned; - devname = md_setup_args[ent].device_names; + sprintf(name, "/dev/md%s%d", partitioned?"_d":"", minor); + if (partitioned) + dev = MKDEV(mdp_major, minor << MdpMinorShift); + else + dev = MKDEV(MD_MAJOR, minor); + create_dev(name, dev); + for (i = 0; i < MD_SB_DISKS && devname != NULL; i++) { + struct kstat stat; + char *p; + char comp_name[64]; - sprintf(name, "/dev/md%s%d", partitioned?"_d":"", minor); - if (partitioned) - dev = MKDEV(mdp_major, minor << MdpMinorShift); - else - dev = MKDEV(MD_MAJOR, minor); - create_dev(name, dev); - for (i = 0; i < MD_SB_DISKS && devname != NULL; i++) { - struct kstat stat; - char *p; - char comp_name[64]; + p = strchr(devname, ','); + if (p) + *p++ = 0; - p = strchr(devname, ','); - if (p) - *p++ = 0; + dev = name_to_dev_t(devname); + if (strncmp(devname, "/dev/", 5) == 0) + devname += 5; + snprintf(comp_name, 63, "/dev/%s", devname); + if (vfs_stat(comp_name, &stat) == 0 && S_ISBLK(stat.mode)) + dev = new_decode_dev(stat.rdev); + if (!dev) { + printk(KERN_WARNING "md: Unknown device name: %s\n", devname); + break; + } - dev = name_to_dev_t(devname); - if (strncmp(devname, "/dev/", 5) == 0) - devname += 5; - snprintf(comp_name, 63, "/dev/%s", devname); - if (vfs_stat(comp_name, &stat) == 0 && - S_ISBLK(stat.mode)) - dev = new_decode_dev(stat.rdev); - if (!dev) { - printk(KERN_WARNING "md: Unknown device name: %s\n", devname); - break; - } + devices[i] = dev; + devname = p; + } + devices[i] = 0; - devices[i] = dev; + if (!i) + return; - devname = p; - } - devices[i] = 0; + printk(KERN_INFO "md: Loading md%s%d: %s\n", + partitioned ? "_d" : "", minor, + args->device_names); - if (!i) - continue; + fd = ksys_open(name, 0, 0); + if (fd < 0) { + printk(KERN_ERR "md: open failed - cannot start " + "array %s\n", name); + return; + } + if (ksys_ioctl(fd, SET_ARRAY_INFO, 0) == -EBUSY) { + printk(KERN_WARNING + "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n", + minor); + ksys_close(fd); + return; + } - printk(KERN_INFO "md: Loading md%s%d: %s\n", - partitioned ? "_d" : "", minor, - md_setup_args[ent].device_names); + if (args->level != LEVEL_NONE) { + /* non-persistent */ + mdu_array_info_t ainfo; + ainfo.level = args->level; + ainfo.size = 0; + ainfo.nr_disks =0; + ainfo.raid_disks =0; + while (devices[ainfo.raid_disks]) + ainfo.raid_disks++; + ainfo.md_minor =minor; + ainfo.not_persistent = 1; - fd = ksys_open(name, 0, 0); - if (fd < 0) { - printk(KERN_ERR "md: open failed - cannot start " - "array %s\n", name); - continue; - } - if (ksys_ioctl(fd, SET_ARRAY_INFO, 0) == -EBUSY) { - printk(KERN_WARNING - "md: Ignoring md=%d, already autodetected. (Use raid=noautodetect)\n", - minor); - ksys_close(fd); - continue; + ainfo.state = (1 << MD_SB_CLEAN); + ainfo.layout = 0; + ainfo.chunk_size = args->chunk; + err = ksys_ioctl(fd, SET_ARRAY_INFO, (long)&ainfo); + for (i = 0; !err && i <= MD_SB_DISKS; i++) { + dev = devices[i]; + if (!dev) + break; + dinfo.number = i; + dinfo.raid_disk = i; + dinfo.state = (1<