Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1980084ybh; Tue, 14 Jul 2020 12:11:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrXYIsG32zrGTXVP3X1lIfHBF6cP3c5tJEOkP8DaEnn6oDXyE84PLeYTbAqAaHdz9F/vLh X-Received: by 2002:a05:6402:22c1:: with SMTP id dm1mr6187288edb.187.1594753880937; Tue, 14 Jul 2020 12:11:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594753880; cv=none; d=google.com; s=arc-20160816; b=XBn11tQmjfzFIy+yR6BEcKFlGB6wITEbLD/a1h/COQWJhDiAsNToqhIIuCURFFwpkA 1VI90yQHUq3oDtXicCg1DbzEP0/nUjcFwr/b/Gwnc0yzjuw+A4PokSKX95R2bJHPMDPx 1bazGF6kajnm2tUB+WhABIul25B5NFc/XoBWRj9bTwbI6Fr3aNn+H6ohY77noR+ontqQ TdexkfbnRORDwdcw5nCUFxVdvA2S0f/l5V7v0+OcYo8RolurFdr3gvszjz2KPWQeHh1j skhAe+FFgQqrCTaBOADWWPQbiQzbpLt6/MD4bSkKsEZqYyD48AP4e6Vlh0yZrixmj10U CsDQ== 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=zjYXahrc67z+U+udFYifbdyIkhxiC1vzcHw8hyKL+rM=; b=uOV0ADeuouPi+VzO9N4rXKVLPFTtLREpfADzlOWFNlFhLDrnqIZaagoU++n0/s7UeP vxVHYRkkIwKU7J7k6mnDad+n6k5eMxIprn9ApoIiDmU56LwpWrqWmSSpIO4KYAU7AA2E 1M3MHWQdC667jIeZT7t0scH/oNa7N0EqH9z7VJ0rMko/giXCDmrWNzHuLj0XKvSqeVbi DRcJ7tr8dQzta3GHU8B9Pjy6+qMUIimKusrNEGmwy3YTi/t35Sm5isGvBRDyDP3qtye8 g2O5rN2DbgZfh2BXgNG6VLQZsXWtofZw34UR1fnoR5tGeycGtgQf4gsXGq3PSP7KUzAy xxqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=EgIF51q0; 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 dk25si11779950edb.28.2020.07.14.12.10.57; Tue, 14 Jul 2020 12:11:20 -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=EgIF51q0; 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 S1731487AbgGNTKn (ORCPT + 99 others); Tue, 14 Jul 2020 15:10:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731263AbgGNTJD (ORCPT ); Tue, 14 Jul 2020 15:09:03 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87DAEC061794; Tue, 14 Jul 2020 12:09:03 -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=zjYXahrc67z+U+udFYifbdyIkhxiC1vzcHw8hyKL+rM=; b=EgIF51q0I5yPvrmW52i2hvFe5h vJ0ix+606e2nfAuezF/MpDlAhyWw5DToTdrQkb+NN5ojZgAu8tg4RbypXm5AoAzKrk+I0E6iufXJf ZcPcODQ6e5xofh1+85zT6erI6SJlyQHYVkC+1qeoNAQ95w8ZTTEDopU9oxeMZpangzEWdmWTxULbO 1YS0gqle8Bwdsnh7J5jpgajMCYeRTaInBNoulk2I8ybOZnDECf7UgObCue8K4OXCKgjlb/6WCNk3p j462X251thVk40TjjFMcwbxd96fIegcL+cjTrvWmYkRaKk5CY6BCBFq2vKhoJLYuMxb968eyDqPuX r8hR4+Ig==; 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 1jvQIX-0005r5-FB; Tue, 14 Jul 2020 19:09:01 +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 09/23] md: rewrite md_setup_drive to avoid ioctls Date: Tue, 14 Jul 2020 21:04:13 +0200 Message-Id: <20200714190427.4332-10-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 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 Acked-by: Song Liu --- 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.27.0