Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1495826ybt; Thu, 9 Jul 2020 08:23:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyh8wrvy7hROkb6tyrmEiBeGqS6q/otPG+J0q7MEuIYoNp+wjj6Raz1+MV2rtx2MXLnJlrp X-Received: by 2002:aa7:d297:: with SMTP id w23mr69862283edq.49.1594308185081; Thu, 09 Jul 2020 08:23:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594308185; cv=none; d=google.com; s=arc-20160816; b=gkuldjPlBFgVNkzbBXeQg5B4VTrMevNFJfM+J4O1ITOxrTK1TyxcuJ2Qf3PobsHrpe kR5nk+RrCZg33auEOWHjZmCbv8CtD5T6ceAIL72kuQ8vjrSSeObulPWPz4mAvTxJ+MK4 jQBlkYWPNmSd0tZLktImxFdn/ZAugReWaxwEj6Xs5HMaS4q78XLT0q46Ppdhv/B2E9pF 5uJZUvvubqaq/gGWfgXnIYU70bpd/MzO7DjMVRUUxTYyplmDBOeC/FbIcp68/4xbLmJe a6W7d+5fheA4DB98oFSHhihMC8dk8WS6j54OB6oM075PNgou4lbXuCpDo34OaTaST4LK /4Hg== 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=mmQoihRRGrsmWONcJEqbEK2+186BjZeGKKMpJSHUBs0=; b=XAjuHS1qvG3Eal6fUFNdkSQqM90rCMAUm77adN1SYTEhr0pK8cStLaCQQmDPLmcvEh bjQXbvoL1W52B0M7StST07fnwqvLkl8xswAN20cG0WdOp1PNZevFkbGn0mgmP3UWemxk Zwpa6jAmosWth3lvLNQBQEDDPJkTe2FdK2VCmFJ1vG5WzWMSssYVcy2rhdG65/8EHlGS Wx9qMg86p5O/QCPNNX90K1KnDmW/qPGjCi8rHUl4jbcvKScz05XgwBrQrYe0biS+o5uz sEKBiHUYrqaXrOj0e7ccPoT0R+5clBPiZvx7HbIFhbtGnI82DFgRShk8F7OsNEGtemSo WhAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=qX0PjgBN; 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 g26si2384219edq.238.2020.07.09.08.22.41; Thu, 09 Jul 2020 08:23:05 -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=qX0PjgBN; 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 S1728374AbgGIPTg (ORCPT + 99 others); Thu, 9 Jul 2020 11:19:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728059AbgGIPS2 (ORCPT ); Thu, 9 Jul 2020 11:18:28 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1EE2C08C5CE; Thu, 9 Jul 2020 08:18:27 -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=mmQoihRRGrsmWONcJEqbEK2+186BjZeGKKMpJSHUBs0=; b=qX0PjgBN5RFR/ofj4R5gUBDiG2 Uqu0NIWJc+oxnEKx1PbujfPW5Vdmz0ytWB3G3acgBUeUtfpXGaPPKYX4Z0DdhoBU6jaCgF4Mtae7L 4LeD9XdaLuLP2wdF+xB35y2A1tjJzenlco1LVuwCnwx+mNLlfLt69vhH8RPfuaLinig7RfXuyjkjs lFk9NXmgcFbrm98NnLfOsWsWayW4Ob8pxFw3U7vGtO8NBy2JRFg4E6iANgNvhtYKnICgGDAhErYAk SprFwjBzoCJ9ehyC5eupeJ1daaj2ubrJAcztkhf65AjiTxD1LP2PkoOoyouib98bLzcyyv0soFCRv RUF2rEMw==; Received: from [2001:4bb8:188:5f50:7053:304b:bf82:82cf] (helo=localhost) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtYJe-0005L5-3v; Thu, 09 Jul 2020 15:18:26 +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 07/17] md: rewrite md_setup_drive to avoid ioctls Date: Thu, 9 Jul 2020 17:18:04 +0200 Message-Id: <20200709151814.110422-8-hch@lst.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200709151814.110422-1-hch@lst.de> References: <20200709151814.110422-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 md_setup_drive knows it works with md devices, so it is rather pointless to open a file descriptor and issue ioctls. Just call directly into the relevant low-level md routines after getting a handle to the device using blkdev_get_by_dev instead. Signed-off-by: Christoph Hellwig --- drivers/md/md-autodetect.c | 127 ++++++++++++++++--------------------- drivers/md/md.c | 20 +++--- drivers/md/md.h | 6 ++ 3 files changed, 71 insertions(+), 82 deletions(-) diff --git a/drivers/md/md-autodetect.c b/drivers/md/md-autodetect.c index a43a8f1580584c..5b24b5616d3acc 100644 --- a/drivers/md/md-autodetect.c +++ b/drivers/md/md-autodetect.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -120,37 +119,29 @@ static int __init md_setup(char *str) return 1; } -static inline int create_dev(char *name, dev_t dev) -{ - ksys_unlink(name); - return ksys_mknod(name, S_IFBLK|0600, new_encode_dev(dev)); -} - static void __init md_setup_drive(struct md_setup_args *args) { - 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 *devname = args->device_names; + dev_t devices[MD_SB_DISKS + 1], mdev; + struct mdu_array_info_s ainfo = { }; + struct block_device *bdev; + struct mddev *mddev; + int err = 0, i; char name[16]; - minor = args->minor; - partitioned = args->partitioned; - devname = args->device_names; + if (args->partitioned) { + mdev = MKDEV(mdp_major, args->minor << MdpMinorShift); + sprintf(name, "md_d%d", args->minor); + } else { + mdev = MKDEV(MD_MAJOR, args->minor); + sprintf(name, "md%d", args->minor); + } - 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]; + dev_t dev; p = strchr(devname, ','); if (p) @@ -163,7 +154,7 @@ static void __init md_setup_drive(struct md_setup_args *args) 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); + pr_warn("md: Unknown device name: %s\n", devname); break; } @@ -175,68 +166,64 @@ static void __init md_setup_drive(struct md_setup_args *args) if (!i) return; - printk(KERN_INFO "md: Loading md%s%d: %s\n", - partitioned ? "_d" : "", minor, - args->device_names); + pr_info("md: Loading %s: %s\n", name, args->device_names); - fd = ksys_open(name, 0, 0); - if (fd < 0) { - printk(KERN_ERR "md: open failed - cannot start " - "array %s\n", name); + bdev = blkdev_get_by_dev(mdev, FMODE_READ, NULL); + if (IS_ERR(bdev)) { + pr_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; + mddev = bdev->bd_disk->private_data; + + err = mddev_lock(mddev); + if (err) { + pr_err("md: failed to lock array %s\n", name); + goto out_blkdev_put; + } + + if (!list_empty(&mddev->disks) || mddev->raid_disks) { + pr_warn("md: Ignoring %s, already autodetected. (Use raid=noautodetect)\n", + name); + goto out_unlock; } 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.md_minor = args->minor; ainfo.not_persistent = 1; - 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; + while (devices[ainfo.raid_disks]) + ainfo.raid_disks++; + } + + err = md_set_array_info(mddev, &ainfo); + + for (i = 0; i <= MD_SB_DISKS && devices[i]; i++) { + struct mdu_disk_info_s dinfo = { + .major = MAJOR(devices[i]), + .minor = MINOR(devices[i]), + }; + + if (args->level != LEVEL_NONE) { dinfo.number = i; dinfo.raid_disk = i; - dinfo.state = (1<major_version != 0) { @@ -7055,7 +7054,7 @@ static int set_bitmap_file(struct mddev *mddev, int fd) } /* - * set_array_info is used two different ways + * md_set_array_info is used two different ways * The original usage is when creating a new array. * In this usage, raid_disks is > 0 and it together with * level, size, not_persistent,layout,chunksize determine the @@ -7067,9 +7066,8 @@ static int set_bitmap_file(struct mddev *mddev, int fd) * The minor and patch _version numbers are also kept incase the * super_block handler wishes to interpret them. */ -static int set_array_info(struct mddev *mddev, mdu_array_info_t *info) +int md_set_array_info(struct mddev *mddev, struct mdu_array_info_s *info) { - if (info->raid_disks == 0) { /* just setting version number for superblock loading */ if (info->major_version < 0 || @@ -7560,7 +7558,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode, err = -EBUSY; goto unlock; } - err = set_array_info(mddev, &info); + err = md_set_array_info(mddev, &info); if (err) { pr_warn("md: couldn't set array info. %d\n", err); goto unlock; @@ -7614,7 +7612,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode, /* Need to clear read-only for this */ break; else - err = add_new_disk(mddev, &info); + err = md_add_new_disk(mddev, &info); goto unlock; } break; @@ -7682,7 +7680,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode, if (copy_from_user(&info, argp, sizeof(info))) err = -EFAULT; else - err = add_new_disk(mddev, &info); + err = md_add_new_disk(mddev, &info); goto unlock; } diff --git a/drivers/md/md.h b/drivers/md/md.h index 6f8fff77ce10a5..7ee81aa2eac862 100644 --- a/drivers/md/md.h +++ b/drivers/md/md.h @@ -801,7 +801,13 @@ static inline void mddev_check_write_zeroes(struct mddev *mddev, struct bio *bio mddev->queue->limits.max_write_zeroes_sectors = 0; } +struct mdu_array_info_s; +struct mdu_disk_info_s; + extern int mdp_major; void md_autostart_arrays(int part); +int md_set_array_info(struct mddev *mddev, struct mdu_array_info_s *info); +int md_add_new_disk(struct mddev *mddev, struct mdu_disk_info_s *info); +int do_md_run(struct mddev *mddev); #endif /* _MD_MD_H */ -- 2.26.2