mdadm/0053-util-remove-obsolete-code-from-get_md_name.patch
Coly Li 2e05bd3f7b Accepting request 1082557 from home:colyli:branches:openSUSE:Factory
- Fixes for mdmon to ensure it run at the right time in the
  fight mount namespace.  This fixes various problems with 
  IMSM raid arrays in 15-SP4 (bsc#1205493, bsc#1205830)
  - mdmon: fix segfault
    0052-mdmon-fix-segfault.patch
  - util: remove obsolete code from get_md_name
    0053-util-remove-obsolete-code-from-get_md_name.patch
  - mdmon: don't test both 'all' and 'container_name'.
    0054-mdmon-don-t-test-both-all-and-container_name.patch
  - mdmon: change systemd unit file to use --foreground
    0055-mdmon-change-systemd-unit-file-to-use-foreground.patch
  - mdmon: Remove need for KillMode=none
    0056-mdmon-Remove-need-for-KillMode-none.patch
  - mdmon: Improve switchroot interactions.
    0057-mdmon-Improve-switchroot-interactions.patch
  - mdopen: always try create_named_array()
    0058-mdopen-always-try-create_named_array.patch
  - Improvements for IMSM_NO_PLATFORM testing
    0059-Improvements-for-IMSM_NO_PLATFORM-testing.patch

OBS-URL: https://build.opensuse.org/request/show/1082557
OBS-URL: https://build.opensuse.org/package/show/Base:System/mdadm?expand=0&rev=223
2023-04-26 15:45:39 +00:00

118 lines
3.1 KiB
Diff

From b938519e7719c992dae2d61c796c45fe49e6b71b Mon Sep 17 00:00:00 2001
From: Mateusz Kusiak <mateusz.kusiak@intel.com>
Date: Mon, 2 Jan 2023 09:46:22 +0100
Subject: [PATCH] util: remove obsolete code from get_md_name
get_md_name() is used only with mdstat entries.
Remove dead code and simplyfy function.
Remove redundadnt checks from mdmon.c
Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
Signed-off-by: Coly Li <colyli@suse.de>
---
mdmon.c | 8 +++-----
util.c | 51 +++++++++++++++++----------------------------------
2 files changed, 20 insertions(+), 39 deletions(-)
diff --git a/mdmon.c b/mdmon.c
index ecf52dc..60ba318 100644
--- a/mdmon.c
+++ b/mdmon.c
@@ -366,7 +366,7 @@ int main(int argc, char *argv[])
if (argv[optind]) {
container_name = get_md_name(argv[optind]);
if (!container_name)
- container_name = argv[optind];
+ return 1;
}
}
@@ -403,11 +403,9 @@ int main(int argc, char *argv[])
return status;
} else {
- int mdfd = open_mddev(container_name, 1);
-
- if (mdfd < 0)
- return 1;
+ int mdfd = open_mddev(container_name, 0);
devnm = fd2devnm(mdfd);
+
close(mdfd);
}
diff --git a/util.c b/util.c
index 26ffdce..9cd89fa 100644
--- a/util.c
+++ b/util.c
@@ -968,47 +968,30 @@ dev_t devnm2devid(char *devnm)
return 0;
}
+/**
+ * get_md_name() - Get main dev node of the md device.
+ * @devnm: Md device name or path.
+ *
+ * Function checks if the full name was passed and returns md name
+ * if it is the MD device.
+ *
+ * Return: Main dev node of the md device or NULL if not found.
+ */
char *get_md_name(char *devnm)
{
- /* find /dev/md%d or /dev/md/%d or make a device /dev/.tmp.md%d */
- /* if dev < 0, want /dev/md/d%d or find mdp in /proc/devices ... */
-
- static char devname[50];
+ static char devname[NAME_MAX];
struct stat stb;
- dev_t rdev = devnm2devid(devnm);
- char *dn;
- if (rdev == 0)
- return 0;
- if (strncmp(devnm, "md_", 3) == 0) {
- snprintf(devname, sizeof(devname), "/dev/md/%s",
- devnm + 3);
- if (stat(devname, &stb) == 0 &&
- (S_IFMT&stb.st_mode) == S_IFBLK && (stb.st_rdev == rdev))
- return devname;
- }
- snprintf(devname, sizeof(devname), "/dev/%s", devnm);
- if (stat(devname, &stb) == 0 && (S_IFMT&stb.st_mode) == S_IFBLK &&
- (stb.st_rdev == rdev))
- return devname;
+ if (strncmp(devnm, "/dev/", 5) == 0)
+ snprintf(devname, sizeof(devname), "%s", devnm);
+ else
+ snprintf(devname, sizeof(devname), "/dev/%s", devnm);
- snprintf(devname, sizeof(devname), "/dev/md/%s", devnm+2);
- if (stat(devname, &stb) == 0 && (S_IFMT&stb.st_mode) == S_IFBLK &&
- (stb.st_rdev == rdev))
+ if (!is_mddev(devname))
+ return NULL;
+ if (stat(devname, &stb) == 0 && (S_IFMT&stb.st_mode) == S_IFBLK)
return devname;
- dn = map_dev(major(rdev), minor(rdev), 0);
- if (dn)
- return dn;
- snprintf(devname, sizeof(devname), "/dev/.tmp.%s", devnm);
- if (mknod(devname, S_IFBLK | 0600, rdev) == -1)
- if (errno != EEXIST)
- return NULL;
-
- if (stat(devname, &stb) == 0 && (S_IFMT&stb.st_mode) == S_IFBLK &&
- (stb.st_rdev == rdev))
- return devname;
- unlink(devname);
return NULL;
}
--
2.35.3