forked from pool/mdadm
849a39cd07
- Update mdadm for SLE15, for bug fixes and new feature enhancement - 1000-The-mdcheck-script-now-adds-messages-to-the-system.patch is removed because upstream has similar fix with almost identical funcationality. - The following patches are not deleted indeed, they are renamed and added into all other new-added patches with different perfix numbers, 0038-Create-Fixup-bad-placement-of-logical-in-multi-line-.patch 0039-Create-Fixup-various-whitespace-issues.patch 0040-mdadm.c-fix-compile-warning-mdfd-is-uninitialized.patch 0041-mdopen-use-parameters-new_array-to-create-arrays-whe.patch 0042-mdadm-manpage-update-manpage-for-readonly-parameter.patch 0043-mdadm-manpage-clustered-arrays-don-t-support-array-s.patch 0044-maps-Terminate-modes-map-correctly.patch 0045-Grow_continue_command-ensure-content-is-properly-ini.patch 0046-systemd-mdadm-last-resort-use-ConditionPathExists-in.patch 0047-Detail-ensure-export-names-are-acceptable-as-shell-v.patch 0048-Grow-set-component-size-prior-to-array-size.patch 0049-Grow-don-t-allow-to-enable-PPL-when-reshape-is-in-pr.patch 0050-Grow-don-t-allow-array-geometry-change-with-ppl-enab.patch 0051-IMSM-Correct-examine-output-for-4k-disks.patch 0052-imsm-allow-drives-in-a-container-regardless-of-secto.patch 0053-imsm-allocate-buffer-to-support-maximum-sector-size.patch 0054-imsm-don-t-allow-disks-with-different-sector-size-in.patch 0055-Allow-more-spare-selection-criteria.patch 0056-Add-sector-size-as-spare-selection-criterion.patch 0057-super1-fix-sb-max_dev-when-adding-a-new-disk-in-line.patch 0058-super1-only-set-clustered-flag-when-bitmap-is-presen.patch 0059-To-support-clustered-raid10.patch 0060-udev-rules-introduce-rules-for-cluster-md-to-confirm.patch - The following patche set includes the above renamed patches, they have bug fixes for bsc#1068030, bsc#1069165, bsc#1069167, and some other fixes and enhancement for raid5 ppl, imsm, and general mdadm code, 0038-mdadm-Create-declaring-an-existing-struct-within-sam.patch 0039-Create-Fixup-bad-placement-of-logical-in-multi-line-.patch 0040-Create-Fixup-various-whitespace-issues.patch 0041-mdadm.c-fix-compile-warning-mdfd-is-uninitialized.patch 0042-mdopen-use-parameters-new_array-to-create-arrays-whe.patch 0043-mdadm-manpage-update-manpage-for-readonly-parameter.patch 0044-mdadm-manpage-clustered-arrays-don-t-support-array-s.patch 0045-maps-Terminate-modes-map-correctly.patch 0046-Grow_continue_command-ensure-content-is-properly-ini.patch 0047-systemd-mdadm-last-resort-use-ConditionPathExists-in.patch 0048-Detail-ensure-export-names-are-acceptable-as-shell-v.patch 0049-Grow-set-component-size-prior-to-array-size.patch 0050-Grow-don-t-allow-to-enable-PPL-when-reshape-is-in-pr.patch 0051-Grow-don-t-allow-array-geometry-change-with-ppl-enab.patch 0052-IMSM-Correct-examine-output-for-4k-disks.patch 0053-imsm-allow-drives-in-a-container-regardless-of-secto.patch 0054-imsm-allocate-buffer-to-support-maximum-sector-size.patch 0055-imsm-don-t-allow-disks-with-different-sector-size-in.patch 0056-mdadm-mdmon-deleted-the-abort_reshape-never-invoked.patch 0057-util-Introduce-md_get_array_info.patch 0058-Incremental-Remove-redundant-call-for-GET_ARRAY_INFO.patch 0059-util-Introduce-md_get_disk_info.patch 0060-util-Introduce-md_set_array_info.patch 0061-md_u-Remove-some-unused-ioctl-declarations.patch 0062-mdadm-grow-reshape-would-be-stuck-from-raid1-to-raid.patch 0063-sysfs-Use-the-presence-of-sys-block-dev-md-as-indica.patch 0064-sysfs-Make-sysfs_init-return-an-error-code.patch 0065-util-must_be_container-Use-sysfs_read-GET_VERSION-to.patch 0066-util-set_array_info-Simplify-code-since-md_get_versi.patch 0067-Assemble-Assemble-Stop-checking-kernel-md-driver-ver.patch 0068-Build-Stop-bothering-about-supporting-md-driver-olde.patch 0069-Grow-Stop-bothering-about-md-driver-versions-older-t.patch 0070-Detail-Stop-bothering-about-md-drivers-older-than-0..patch 0071-Create-Remove-all-attemps-to-handle-md-driver-older-.patch 0072-Manage-Remove-all-references-to-md_get_version.patch 0073-Query-Remove-all-references-to-md_get_version.patch 0074-bitmap-Remove-use-of-md_get_version.patch 0075-mdmon-Stop-bothering-about-md_get_version.patch 0076-mdopen-open_mddev-Use-md_get_array_info-to-determine.patch 0077-mdassemble-Use-md_get_array_info-to-check-for-valid-.patch 0078-Assemble-Assemble-Get-rid-of-last-use-of-md_get_vers.patch 0079-util-Finally-kill-off-md_get_version.patch 0080-mdadm-Fail-for-kernels-older-than-2.6.15.patch 0081-Revert-mdadm-grow-reshape-would-be-stuck-from-raid1-.patch 0082-Retire-mdassemble.patch 0083-super1-Clean-up-various-style-abuses.patch 0084-Detail-Remove-pre-2.6-code-for-printing-info-on-rebu.patch 0085-Assemble-Remove-obsolete-test-for-kernels-older-than.patch 0086-Detail-Fixup-ugly-if-foo-abuse.patch 0087-Query-Handle-error-returned-by-fstat.patch 0088-Query-Use-sysfs-to-obtain-data-if-possible.patch 0089-sysfs-Parse-array_state-in-sysfs_read.patch 0090-util-Introduce-md_array_active-helper.patch 0091-maps-Use-keyvalue-for-null-terminator-to-indicate-un.patch 0092-util-Get-rid-of-unused-enough_fd.patch 0093-mdadm-retire-mdassemble-in-make-everything.patch 0094-Query-Quiet-gcc-since-it-cannot-know-errno-0-in-this.patch 0095-Makefile-Default-to-O2-optimization.patch 0096-maps-Simplify-implementation-of-map_name.patch 0097-Don-t-use-UnSet-with-consistency_policy.patch 0098-Detail-determine-array-state-from-sysfs.patch 0099-Detail-Respect-code-lines-are-80-character-wide.patch 0100-Detail-Reinstate-support-for-not-having-sysfs.patch 0101-Incremental-Use-md_array_active-where-applicable.patch 0102-Incremental-Cleanup-some-if-statement-spaghetti.patch 0103-Create-tell-udev-md-device-is-not-ready-when-first-c.patch 0104-Incremental-Use-md_array_active-to-determine-state-o.patch 0105-Manage-Manage_ro-Use-md_array_active.patch 0106-IMSM-Initialize-my_vol_raid_dev_num-during-vol-creat.patch 0107-Grow-Grow_continue_command-Avoid-aliasing-array-vari.patch 0108-change-back-0644-permission-for-Grow.c.patch 0109-util-md_array_valid-Introduce-md_array_valid-helper.patch 0110-kernel-patch-Remove-obsolete-kernel-patches-against-.patch 0111-mdassemble-Kill-off-the-last-remains.patch 0112-mdadm-util-unify-fstat-checking-blkdev-into-function.patch 0113-mdadm-util-unify-stat-checking-blkdev-into-function.patch 0114-Fix-typo-in-new-udev-rule.patch 0115-Incremental-return-is-not-a-function.patch 0116-sysfs-sysfs_read-Count-active_disks-and-failed_disks.patch 0117-container_members_max_degradation-Switch-to-using-sy.patch 0118-IncrementalScan-Use-md_array_active-instead-of-md_ge.patch 0119-Mention-endian-in-documentation-for-update-byte-orde.patch 0120-Monitor-Use-md_array_active-instead-of-manually-fidd.patch 0121-Monitor-Code-is-80-characters-per-line.patch 0122-mdadm-md.4-set-page-length-as-1000-to-avoid-warnings.patch 0123-Allow-more-spare-selection-criteria.patch 0124-Add-sector-size-as-spare-selection-criterion.patch 0125-Monitor-check_array-Centralize-exit-path.patch 0126-Monitor-check_array-Reduce-duplicated-error-handling.patch 0127-Monitor-check_array-Declate-mdinfo-instance-globally.patch 0128-Monitor-check_array-Read-sysfs-entry-earlier.patch 0129-Monitor-check_array-Obtain-RAID-level-from-syfs.patch 0130-Monitor-check_array-Get-failed_disks-from-sysfs.patch 0131-Monitor-check_array-Get-array_disks-from-sysfs.patch 0132-Monitor-check_array-Get-nr_disks-active_disks-and-sp.patch 0133-sysfs-sysfs_read-Count-working_disks.patch 0134-Monitor-check_array-Use-working_disks-from-sysfs.patch 0135-retire-the-APIs-that-driver-no-longer-supports.patch 0136-Monitor-Not-much-point-declaring-mdlist-in-both-fork.patch 0137-Monitor-mailfrom-is-initialized-correctly.patch 0138-Monitor-Fixup-a-pile-of-whitespace-issues.patch 0139-mdadm-Uninitialized-variable-rdev.patch 0140-super-ddf-sysfs_read-takes-a-pointer-as-device-name-.patch 0141-mdadm-Fixup-a-large-number-of-bad-formatting-of-logi.patch 0142-mdadm-Fixup-more-broken-logical-operator-formatting.patch 0143-mdadm-Fix-broken-formatting.patch 0144-mdadm-Fixup-broken-formatting.patch 0145-Detail-don-t-exit-if-ioctl-has-been-successful.patch 0146-super1-fix-sb-max_dev-when-adding-a-new-disk-in-line.patch 0147-md_u-Remove-unused-ioctl-declaration-of-START_ARRAY.patch 0148-Get-failed-disk-count-from-array-state.patch 0149-Monitor-don-t-assume-mdadm-parameter-is-a-block-devi.patch 0150-super1-Always-round-data-offset-to-1M.patch 0151-mdadm-r5cache-allow-adding-journal-to-array-without-.patch 0152-udev-rules-introduce-rules-for-cluster-md-to-confirm.patch 0153-Detail-correct-output-for-active-arrays.patch 0154-imsm-rebuild-from-2-disk-RAID10.patch (bsc#1069165) 0155-Error-messages-should-end-with-a-newline-character.patch 0156-Use-correct-syntax-for-passing-DEVLINKS-to-mdadm-fro.patch 0157-super1-only-set-clustered-flag-when-bitmap-is-presen.patch 0158-Don-t-use-exit-ERANGE.patch 0159-Monitor-containers-don-t-have-the-same-sysfs-propert.patch 0160-Monitor-Include-containers-in-spare-migration.patch 0161-Detail-differentiate-between-container-and-inactive-.patch 0162-mdadm-install-two-more-udev-rules-in-mdadm.spec.patch 0163-mdadm-set-journal_clean-after-scanning-all-disks.patch 0164-mdadm-bitmap-examine-bitmap-failed-when-bitmap-is-ex.patch 0165-mdopen-call-modprobe-md_mod-if-it-might-be-needed.patch 0166-lib-devid2kname-should-take-a-dev_t.patch 0167-sysfs_init_dev-take-a-dev_t-argument.patch 0168-Manage_subdevs-Use-a-dev_t.patch 0169-util-Code-is-80-characters-wide.patch 0170-Close-mdfd-before-returning-main-function.patch 0171-Grow-stop-previous-reshape-process-first.patch 0172-imsm-New-disk-controller-domains.patch 0173-Monitor-Check-redundancy-for-arrays.patch 0174-mdadm-grow-Component-size-must-be-larger-than-chunk-.patch 0175-mdadm-manpage-disable-bitmap_resize-for-external-fil.patch 0176-mdadm-fixes-some-trivial-typos-in-comments.patch (The following 12 patches are specifically for bsc#1068030) 0177-Don-t-abort-starting-the-array-if-kernel-does-not-su.patch 0178-super1-Add-support-for-multiple-ppls.patch 0179-imsm-Add-support-for-multiple-ppls.patch 0180-imsm-validate-multiple-ppls-during-assemble.patch 0181-Zeroout-whole-ppl-space-during-creation-force-assemb.patch 0182-imsm-switch-to-multiple-ppls-automatically-during-as.patch 0183-Grow-fix-switching-on-PPL-during-recovery.patch 0184-imsm-don-t-skip-resync-when-an-invalid-ppl-header-is.patch 0185-imsm-Write-empty-PPL-header-if-assembling-regular-cl.patch 0186-imsm-always-do-ppl-recovery-when-starting-a-rebuildi.patch 0187-imsm-use-correct-map-when-validating-ppl.patch 0188-imsm-write-initial-ppl-on-a-disk-added-for-rebuild.patch 0189-Grow-Use-all-80-characters.patch 0190-imsm-Set-disk-slot-number.patch (The following 1 patch is specifically for bsc#1069167) 0191-mdmon-get-safe-mode-delay-file-descriptor-early.patch 0192-mdadm-mdstat-fixup-a-number-of-broken-formatting.patch 0193-mdadm-mdstat-correct-the-strncmp-number-4-as-6.patch 0194-mdcheck-add-some-logging.patch 0195-mdcheck-improve-cleanup.patch 0196-Move-mdadm_env.sh-out-of-usr-lib-systemd.patch 0197-mdadm-grow-adding-a-test-to-ensure-resize-was-requir.patch 0198-mdadm-mdopen-create-new-function-create_named_array-.patch 0199-systemd-add-I-to-description-of-mdadm-last-resort-se.patch 0200-Incremental-Use-validate_geometry-instead-of-avail_s.patch 0201-imsm-fix-reading-scsi-serial.patch 0202-To-support-clustered-raid10.patch 0203-imsm-More-precise-message-when-spanned-raid-is-creat.patch 0204-sysfs-include-faulty-drive-in-disk-count.patch 0205-Monitor-msg-Don-t-print-error-message-if-mdmon-doesn.patch 0206-imsm-continue-resync-on-3-disk-RAID10.patch OBS-URL: https://build.opensuse.org/request/show/548207 OBS-URL: https://build.opensuse.org/package/show/Base:System/mdadm?expand=0&rev=156
444 lines
14 KiB
Diff
444 lines
14 KiB
Diff
From 0a6bff09d41650f27136d56a0604c9af46b6f583 Mon Sep 17 00:00:00 2001
|
|
From: Zhilong Liu <zlliu@suse.com>
|
|
Date: Thu, 4 May 2017 20:16:21 +0800
|
|
Subject: [PATCH] mdadm/util: unify fstat checking blkdev into function
|
|
Git-commit: 0a6bff09d41650f27136d56a0604c9af46b6f583
|
|
Patch-mainline: mdadm-4.0+
|
|
References: bsc#1069165, bsc#1069167, bsc#1068030
|
|
|
|
declare function fstat_is_blkdev() to integrate repeated fstat
|
|
checking block device operations, it returns true/1 when it is
|
|
a block device, and returns false/0 when it isn't.
|
|
The fd and devname are necessary parameters, *rdev is optional,
|
|
parse the pointer of dev_t *rdev, if valid, assigned the device
|
|
number to dev_t *rdev, if NULL, ignores.
|
|
|
|
Signed-off-by: Zhilong Liu <zlliu@suse.com>
|
|
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
|
|
Signed-off-by: Coly Li <colyli@suse.de>
|
|
|
|
---
|
|
Assemble.c | 19 +++++++------------
|
|
Build.c | 5 +++--
|
|
Create.c | 23 ++++++++++-------------
|
|
Grow.c | 10 ++++------
|
|
Incremental.c | 33 ++++++++++++---------------------
|
|
Manage.c | 2 +-
|
|
bitmap.c | 13 ++++---------
|
|
mdadm.h | 1 +
|
|
super-intel.c | 13 +++----------
|
|
util.c | 17 +++++++++++++++++
|
|
10 files changed, 62 insertions(+), 74 deletions(-)
|
|
|
|
diff --git a/Assemble.c b/Assemble.c
|
|
index a9442c8..9d0a89f 100644
|
|
--- a/Assemble.c
|
|
+++ b/Assemble.c
|
|
@@ -149,6 +149,7 @@ static int select_devices(struct mddev_dev *devlist,
|
|
struct mdinfo *content = NULL;
|
|
int report_mismatch = ((inargv && c->verbose >= 0) || c->verbose > 0);
|
|
struct domainlist *domains = NULL;
|
|
+ dev_t rdev;
|
|
|
|
tmpdev = devlist; num_devs = 0;
|
|
while (tmpdev) {
|
|
@@ -169,7 +170,6 @@ static int select_devices(struct mddev_dev *devlist,
|
|
tmpdev = tmpdev ? tmpdev->next : NULL) {
|
|
char *devname = tmpdev->devname;
|
|
int dfd;
|
|
- struct stat stb;
|
|
struct supertype *tst;
|
|
struct dev_policy *pol = NULL;
|
|
int found_container = 0;
|
|
@@ -204,14 +204,7 @@ static int select_devices(struct mddev_dev *devlist,
|
|
pr_err("cannot open device %s: %s\n",
|
|
devname, strerror(errno));
|
|
tmpdev->used = 2;
|
|
- } else if (fstat(dfd, &stb)< 0) {
|
|
- /* Impossible! */
|
|
- pr_err("fstat failed for %s: %s\n",
|
|
- devname, strerror(errno));
|
|
- tmpdev->used = 2;
|
|
- } else if ((stb.st_mode & S_IFMT) != S_IFBLK) {
|
|
- pr_err("%s is not a block device.\n",
|
|
- devname);
|
|
+ } else if (!fstat_is_blkdev(dfd, devname, &rdev)) {
|
|
tmpdev->used = 2;
|
|
} else if (must_be_container(dfd)) {
|
|
if (st) {
|
|
@@ -234,7 +227,8 @@ static int select_devices(struct mddev_dev *devlist,
|
|
devname);
|
|
tmpdev->used = 2;
|
|
} else if (auto_assem &&
|
|
- !conf_test_metadata(tst->ss->name, (pol = devid_policy(stb.st_rdev)),
|
|
+ !conf_test_metadata(tst->ss->name,
|
|
+ (pol = devid_policy(rdev)),
|
|
tst->ss->match_home(tst, c->homehost) == 1)) {
|
|
if (report_mismatch)
|
|
pr_err("%s has metadata type %s for which auto-assembly is disabled\n",
|
|
@@ -261,7 +255,8 @@ static int select_devices(struct mddev_dev *devlist,
|
|
tst->ss->name, devname);
|
|
tmpdev->used = 2;
|
|
} else if (auto_assem && st == NULL &&
|
|
- !conf_test_metadata(tst->ss->name, (pol = devid_policy(stb.st_rdev)),
|
|
+ !conf_test_metadata(tst->ss->name,
|
|
+ (pol = devid_policy(rdev)),
|
|
tst->ss->match_home(tst, c->homehost) == 1)) {
|
|
if (report_mismatch)
|
|
pr_err("%s has metadata type %s for which auto-assembly is disabled\n",
|
|
@@ -484,7 +479,7 @@ static int select_devices(struct mddev_dev *devlist,
|
|
/* Collect domain information from members only */
|
|
if (tmpdev && tmpdev->used == 1) {
|
|
if (!pol)
|
|
- pol = devid_policy(stb.st_rdev);
|
|
+ pol = devid_policy(rdev);
|
|
domain_merge(&domains, pol, tst?tst->ss->name:NULL);
|
|
}
|
|
dev_policy_free(pol);
|
|
diff --git a/Build.c b/Build.c
|
|
index 665d906..2d84b96 100644
|
|
--- a/Build.c
|
|
+++ b/Build.c
|
|
@@ -42,6 +42,7 @@ int Build(char *mddev, struct mddev_dev *devlist,
|
|
*/
|
|
int i;
|
|
struct stat stb;
|
|
+ dev_t rdev;
|
|
int subdevs = 0, missing_disks = 0;
|
|
struct mddev_dev *dv;
|
|
int bitmap_fd;
|
|
@@ -126,8 +127,8 @@ int Build(char *mddev, struct mddev_dev *devlist,
|
|
array.nr_disks = s->raiddisks;
|
|
array.raid_disks = s->raiddisks;
|
|
array.md_minor = 0;
|
|
- if (fstat(mdfd, &stb) == 0)
|
|
- array.md_minor = minor(stb.st_rdev);
|
|
+ if (fstat_is_blkdev(mdfd, mddev, &rdev))
|
|
+ array.md_minor = minor(rdev);
|
|
array.not_persistent = 1;
|
|
array.state = 0; /* not clean, but no errors */
|
|
if (s->assume_clean)
|
|
diff --git a/Create.c b/Create.c
|
|
index df1bc20..239545f 100644
|
|
--- a/Create.c
|
|
+++ b/Create.c
|
|
@@ -89,8 +89,8 @@ int Create(struct supertype *st, char *mddev,
|
|
char *maxdisc = NULL;
|
|
int dnum, raid_disk_num;
|
|
struct mddev_dev *dv;
|
|
+ dev_t rdev;
|
|
int fail = 0, warn = 0;
|
|
- struct stat stb;
|
|
int first_missing = subdevs * 2;
|
|
int second_missing = subdevs * 2;
|
|
int missing_disks = 0;
|
|
@@ -325,11 +325,8 @@ int Create(struct supertype *st, char *mddev,
|
|
dname, strerror(errno));
|
|
exit(2);
|
|
}
|
|
- if (fstat(dfd, &stb) != 0 ||
|
|
- (stb.st_mode & S_IFMT) != S_IFBLK) {
|
|
+ if (!fstat_is_blkdev(dfd, dname, NULL)) {
|
|
close(dfd);
|
|
- pr_err("%s is not a block device\n",
|
|
- dname);
|
|
exit(2);
|
|
}
|
|
close(dfd);
|
|
@@ -641,8 +638,8 @@ int Create(struct supertype *st, char *mddev,
|
|
* with, but it chooses to trust me instead. Sigh
|
|
*/
|
|
info.array.md_minor = 0;
|
|
- if (fstat(mdfd, &stb) == 0)
|
|
- info.array.md_minor = minor(stb.st_rdev);
|
|
+ if (fstat_is_blkdev(mdfd, mddev, &rdev))
|
|
+ info.array.md_minor = minor(rdev);
|
|
info.array.not_persistent = 0;
|
|
|
|
if (((s->level == 4 || s->level == 5) &&
|
|
@@ -841,7 +838,6 @@ int Create(struct supertype *st, char *mddev,
|
|
for (dnum = 0, raid_disk_num = 0, dv = devlist; dv;
|
|
dv = (dv->next) ? (dv->next) : moved_disk, dnum++) {
|
|
int fd;
|
|
- struct stat stb2;
|
|
struct mdinfo *inf = &infos[dnum];
|
|
|
|
if (dnum >= total_slots)
|
|
@@ -897,9 +893,10 @@ int Create(struct supertype *st, char *mddev,
|
|
dv->devname);
|
|
goto abort_locked;
|
|
}
|
|
- fstat(fd, &stb2);
|
|
- inf->disk.major = major(stb2.st_rdev);
|
|
- inf->disk.minor = minor(stb2.st_rdev);
|
|
+ if (!fstat_is_blkdev(fd, dv->devname, &rdev))
|
|
+ return 1;
|
|
+ inf->disk.major = major(rdev);
|
|
+ inf->disk.minor = minor(rdev);
|
|
}
|
|
if (fd >= 0)
|
|
remove_partitions(fd);
|
|
@@ -920,8 +917,8 @@ int Create(struct supertype *st, char *mddev,
|
|
|
|
if (!have_container) {
|
|
/* getinfo_super might have lost these ... */
|
|
- inf->disk.major = major(stb2.st_rdev);
|
|
- inf->disk.minor = minor(stb2.st_rdev);
|
|
+ inf->disk.major = major(rdev);
|
|
+ inf->disk.minor = minor(rdev);
|
|
}
|
|
break;
|
|
case 2:
|
|
diff --git a/Grow.c b/Grow.c
|
|
index f4bd301..a527436 100644
|
|
--- a/Grow.c
|
|
+++ b/Grow.c
|
|
@@ -109,7 +109,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
|
|
*/
|
|
struct mdinfo info;
|
|
|
|
- struct stat stb;
|
|
+ dev_t rdev;
|
|
int nfd, fd2;
|
|
int d, nd;
|
|
struct supertype *st = NULL;
|
|
@@ -145,9 +145,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
|
|
free(st);
|
|
return 1;
|
|
}
|
|
- fstat(nfd, &stb);
|
|
- if ((stb.st_mode & S_IFMT) != S_IFBLK) {
|
|
- pr_err("%s is not a block device!\n", newdev);
|
|
+ if (!fstat_is_blkdev(nfd, newdev, &rdev)) {
|
|
close(nfd);
|
|
free(st);
|
|
return 1;
|
|
@@ -198,8 +196,8 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
|
|
*/
|
|
|
|
info.disk.number = d;
|
|
- info.disk.major = major(stb.st_rdev);
|
|
- info.disk.minor = minor(stb.st_rdev);
|
|
+ info.disk.major = major(rdev);
|
|
+ info.disk.minor = minor(rdev);
|
|
info.disk.raid_disk = d;
|
|
info.disk.state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE);
|
|
st->ss->update_super(st, &info, "linear-grow-new", newdev,
|
|
diff --git a/Incremental.c b/Incremental.c
|
|
index 8909f2f..11a34e7 100644
|
|
--- a/Incremental.c
|
|
+++ b/Incremental.c
|
|
@@ -87,6 +87,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
|
|
* start the array (auto-readonly).
|
|
*/
|
|
struct stat stb;
|
|
+ dev_t rdev;
|
|
struct mdinfo info, dinfo;
|
|
struct mdinfo *sra = NULL, *d;
|
|
struct mddev_ident *match;
|
|
@@ -174,21 +175,11 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
|
|
/* 2/ Find metadata, reject if none appropriate (check
|
|
* version/name from args) */
|
|
|
|
- if (fstat(dfd, &stb) < 0) {
|
|
- if (c->verbose >= 0)
|
|
- pr_err("fstat failed for %s: %s.\n",
|
|
- devname, strerror(errno));
|
|
- goto out;
|
|
- }
|
|
- if ((stb.st_mode & S_IFMT) != S_IFBLK) {
|
|
- if (c->verbose >= 0)
|
|
- pr_err("%s is not a block device.\n",
|
|
- devname);
|
|
+ if (!fstat_is_blkdev(dfd, devname, &rdev))
|
|
goto out;
|
|
- }
|
|
|
|
- dinfo.disk.major = major(stb.st_rdev);
|
|
- dinfo.disk.minor = minor(stb.st_rdev);
|
|
+ dinfo.disk.major = major(rdev);
|
|
+ dinfo.disk.minor = minor(rdev);
|
|
|
|
policy = disk_policy(&dinfo);
|
|
have_target = policy_check_path(&dinfo, &target_array);
|
|
@@ -339,8 +330,8 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
|
|
}
|
|
|
|
dinfo = info;
|
|
- dinfo.disk.major = major(stb.st_rdev);
|
|
- dinfo.disk.minor = minor(stb.st_rdev);
|
|
+ dinfo.disk.major = major(rdev);
|
|
+ dinfo.disk.minor = minor(rdev);
|
|
if (add_disk(mdfd, st, &info, &dinfo) != 0) {
|
|
pr_err("failed to add %s to new array %s: %s.\n",
|
|
devname, chosen_name, strerror(errno));
|
|
@@ -441,8 +432,8 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
|
|
goto out_unlock;
|
|
}
|
|
}
|
|
- info.disk.major = major(stb.st_rdev);
|
|
- info.disk.minor = minor(stb.st_rdev);
|
|
+ info.disk.major = major(rdev);
|
|
+ info.disk.minor = minor(rdev);
|
|
/* add disk needs to know about containers */
|
|
if (st->ss->external)
|
|
sra->array.level = LEVEL_CONTAINER;
|
|
@@ -863,12 +854,12 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
|
|
* Return 0 on success, or some exit code on failure, probably 1.
|
|
*/
|
|
int rv = 1;
|
|
- struct stat stb;
|
|
+ dev_t rdev;
|
|
struct map_ent *mp, *map = NULL;
|
|
struct mdinfo *chosen = NULL;
|
|
int dfd = *dfdp;
|
|
|
|
- if (fstat(dfd, &stb) != 0)
|
|
+ if (!fstat_is_blkdev(dfd, devname, &rdev))
|
|
return 1;
|
|
|
|
/*
|
|
@@ -1038,8 +1029,8 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
|
|
devlist.writemostly = FlagDefault;
|
|
devlist.failfast = FlagDefault;
|
|
devlist.devname = chosen_devname;
|
|
- sprintf(chosen_devname, "%d:%d", major(stb.st_rdev),
|
|
- minor(stb.st_rdev));
|
|
+ sprintf(chosen_devname, "%d:%d", major(rdev),
|
|
+ minor(rdev));
|
|
devlist.disposition = 'a';
|
|
close(dfd);
|
|
*dfdp = -1;
|
|
diff --git a/Manage.c b/Manage.c
|
|
index 230309b..af55266 100644
|
|
--- a/Manage.c
|
|
+++ b/Manage.c
|
|
@@ -1513,7 +1513,7 @@ int Manage_subdevs(char *devname, int fd,
|
|
struct stat stb;
|
|
tfd = dev_open(dv->devname, O_RDONLY);
|
|
if (tfd >= 0) {
|
|
- fstat(tfd, &stb);
|
|
+ fstat_is_blkdev(tfd, dv->devname, &rdev);
|
|
close(tfd);
|
|
} else {
|
|
int open_err = errno;
|
|
diff --git a/bitmap.c b/bitmap.c
|
|
index 16a6b73..3653660 100644
|
|
--- a/bitmap.c
|
|
+++ b/bitmap.c
|
|
@@ -183,7 +183,6 @@ static int
|
|
bitmap_file_open(char *filename, struct supertype **stp, int node_num)
|
|
{
|
|
int fd;
|
|
- struct stat stb;
|
|
struct supertype *st = *stp;
|
|
|
|
fd = open(filename, O_RDONLY|O_DIRECT);
|
|
@@ -193,14 +192,7 @@ bitmap_file_open(char *filename, struct supertype **stp, int node_num)
|
|
return -1;
|
|
}
|
|
|
|
- if (fstat(fd, &stb) < 0) {
|
|
- pr_err("failed to determine bitmap file/device type: %s\n",
|
|
- strerror(errno));
|
|
- close(fd);
|
|
- return -1;
|
|
- }
|
|
-
|
|
- if ((stb.st_mode & S_IFMT) == S_IFBLK) {
|
|
+ if (fstat_is_blkdev(fd, filename, NULL)) {
|
|
/* block device, so we are probably after an internal bitmap */
|
|
if (!st)
|
|
st = guess_super(fd);
|
|
@@ -221,6 +213,9 @@ bitmap_file_open(char *filename, struct supertype **stp, int node_num)
|
|
}
|
|
|
|
*stp = st;
|
|
+ } else {
|
|
+ close(fd);
|
|
+ return -1;
|
|
}
|
|
|
|
return fd;
|
|
diff --git a/mdadm.h b/mdadm.h
|
|
index 07ee963..4adb840 100644
|
|
--- a/mdadm.h
|
|
+++ b/mdadm.h
|
|
@@ -1434,6 +1434,7 @@ extern int check_raid(int fd, char *name);
|
|
extern int check_partitions(int fd, char *dname,
|
|
unsigned long long freesize,
|
|
unsigned long long size);
|
|
+extern int fstat_is_blkdev(int fd, char *devname, dev_t *rdev);
|
|
|
|
extern int get_mdp_major(void);
|
|
extern int get_maj_min(char *dev, int *major, int *minor);
|
|
diff --git a/super-intel.c b/super-intel.c
|
|
index 36f77d3..c4196ea 100644
|
|
--- a/super-intel.c
|
|
+++ b/super-intel.c
|
|
@@ -6562,7 +6562,7 @@ count_volumes_list(struct md_list *devlist, char *homehost,
|
|
|
|
for (tmpdev = devlist; tmpdev; tmpdev = tmpdev->next) {
|
|
char *devname = tmpdev->devname;
|
|
- struct stat stb;
|
|
+ dev_t rdev;
|
|
struct supertype *tst;
|
|
int dfd;
|
|
if (tmpdev->used > 1)
|
|
@@ -6578,14 +6578,7 @@ count_volumes_list(struct md_list *devlist, char *homehost,
|
|
dprintf("cannot open device %s: %s\n",
|
|
devname, strerror(errno));
|
|
tmpdev->used = 2;
|
|
- } else if (fstat(dfd, &stb)< 0) {
|
|
- /* Impossible! */
|
|
- dprintf("fstat failed for %s: %s\n",
|
|
- devname, strerror(errno));
|
|
- tmpdev->used = 2;
|
|
- } else if ((stb.st_mode & S_IFMT) != S_IFBLK) {
|
|
- dprintf("%s is not a block device.\n",
|
|
- devname);
|
|
+ } else if (!fstat_is_blkdev(dfd, devname, &rdev)) {
|
|
tmpdev->used = 2;
|
|
} else if (must_be_container(dfd)) {
|
|
struct supertype *cst;
|
|
@@ -6607,7 +6600,7 @@ count_volumes_list(struct md_list *devlist, char *homehost,
|
|
if (cst)
|
|
cst->ss->free_super(cst);
|
|
} else {
|
|
- tmpdev->st_rdev = stb.st_rdev;
|
|
+ tmpdev->st_rdev = rdev;
|
|
if (tst->ss->load_super(tst,dfd, NULL)) {
|
|
dprintf("no RAID superblock on %s\n",
|
|
devname);
|
|
diff --git a/util.c b/util.c
|
|
index c7585ac..a92faf8 100644
|
|
--- a/util.c
|
|
+++ b/util.c
|
|
@@ -730,6 +730,23 @@ int check_raid(int fd, char *name)
|
|
return 1;
|
|
}
|
|
|
|
+int fstat_is_blkdev(int fd, char *devname, dev_t *rdev)
|
|
+{
|
|
+ struct stat stb;
|
|
+
|
|
+ if (fstat(fd, &stb) != 0) {
|
|
+ pr_err("fstat failed for %s: %s\n", devname, strerror(errno));
|
|
+ return 0;
|
|
+ }
|
|
+ if ((S_IFMT & stb.st_mode) != S_IFBLK) {
|
|
+ pr_err("%s is not a block device.\n", devname);
|
|
+ return 0;
|
|
+ }
|
|
+ if (rdev)
|
|
+ *rdev = stb.st_rdev;
|
|
+ return 1;
|
|
+}
|
|
+
|
|
int ask(char *mesg)
|
|
{
|
|
char *add = "";
|
|
--
|
|
2.13.6
|
|
|