From: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
To: jes@trained-monkey.org
Cc: linux-raid@vger.kernel.org,
Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Subject: [PATCH 05/13] mdadm: introduce sysfs_get_container_devnm()
Date: Thu, 29 Feb 2024 12:52:09 +0100 [thread overview]
Message-ID: <20240229115217.26543-6-mariusz.tkaczyk@linux.intel.com> (raw)
In-Reply-To: <20240229115217.26543-1-mariusz.tkaczyk@linux.intel.com>
There at least two places where it is done directly, so replace them
with function. Print message about creating external array, add "/dev/"
prefix to refer directly to devnode.
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
---
Create.c | 21 ++++++++++-----------
Manage.c | 14 ++++----------
mdadm.h | 2 ++
sysfs.c | 23 +++++++++++++++++++++++
4 files changed, 39 insertions(+), 21 deletions(-)
diff --git a/Create.c b/Create.c
index 7e9170b6a1ac..0b7762661c76 100644
--- a/Create.c
+++ b/Create.c
@@ -1142,24 +1142,23 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
if (did_default && c->verbose >= 0) {
if (is_subarray(info.text_version)) {
- char devnm[32];
- char *ep;
+ char devnm[MD_NAME_MAX];
struct mdinfo *mdi;
- strncpy(devnm, info.text_version+1, 32);
- devnm[31] = 0;
- ep = strchr(devnm, '/');
- if (ep)
- *ep = 0;
+ sysfs_get_container_devnm(&info, devnm);
mdi = sysfs_read(-1, devnm, GET_VERSION);
+ if (!mdi) {
+ pr_err("Cannot open sysfs for container %s\n", devnm);
+ goto abort_locked;
+ }
+
+ pr_info("Creating array inside %s container /dev/%s\n", mdi->text_version,
+ devnm);
- pr_info("Creating array inside %s container %s\n",
- mdi?mdi->text_version:"managed", devnm);
sysfs_free(mdi);
} else
- pr_info("Defaulting to version %s metadata\n",
- info.text_version);
+ pr_info("Defaulting to version %s metadata\n", info.text_version);
}
map_update(&map, fd2devnm(mdfd), info.text_version,
diff --git a/Manage.c b/Manage.c
index b3e216cbcec6..969d0ea9d81f 100644
--- a/Manage.c
+++ b/Manage.c
@@ -178,7 +178,7 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry)
struct map_ent *map = NULL;
struct mdinfo *mdi;
char devnm[32];
- char container[32];
+ char container[MD_NAME_MAX] = {0};
int err;
int count;
char buf[SYSFS_MAX_BUF_SIZE];
@@ -192,15 +192,9 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry)
* to stop is probably a bad idea.
*/
mdi = sysfs_read(fd, NULL, GET_LEVEL|GET_COMPONENT|GET_VERSION);
- if (mdi && is_subarray(mdi->text_version)) {
- char *sl;
- strncpy(container, mdi->text_version+1, sizeof(container));
- container[sizeof(container)-1] = 0;
- sl = strchr(container, '/');
- if (sl)
- *sl = 0;
- } else
- container[0] = 0;
+ if (mdi && is_subarray(mdi->text_version))
+ sysfs_get_container_devnm(mdi, container);
+
close(fd);
count = 5;
while (((fd = ((devname[0] == '/')
diff --git a/mdadm.h b/mdadm.h
index cbc586f5e3ef..39b86bd08029 100644
--- a/mdadm.h
+++ b/mdadm.h
@@ -777,6 +777,8 @@ enum sysfs_read_flags {
#define SYSFS_MAX_BUF_SIZE 64
+extern void sysfs_get_container_devnm(struct mdinfo *mdi, char *buf);
+
/* If fd >= 0, get the array it is open on,
* else use devnm.
*/
diff --git a/sysfs.c b/sysfs.c
index f95ef7013e84..230b842e4117 100644
--- a/sysfs.c
+++ b/sysfs.c
@@ -74,6 +74,29 @@ void sysfs_free(struct mdinfo *sra)
}
}
+/**
+ * sysfs_get_container_devnm() - extract container device name.
+ * @mdi: md_info describes member array, with GET_VERSION option.
+ * @buf: buf to fill, must be MD_NAME_MAX.
+ *
+ * External array version is in format {/,-}<container_devnm>/<array_index>
+ * Extract container_devnm from it and safe it in @buf.
+ */
+void sysfs_get_container_devnm(struct mdinfo *mdi, char *buf)
+{
+ char *p;
+
+ assert(is_subarray(mdi->text_version));
+
+ /* Skip first special sign */
+ snprintf(buf, MD_NAME_MAX, "%s", mdi->text_version + 1);
+
+ /* Remove array index */
+ p = strchr(buf, '/');
+ if (p)
+ *p = 0;
+}
+
int sysfs_open(char *devnm, char *devname, char *attr)
{
char fname[MAX_SYSFS_PATH_LEN];
--
2.35.3
next prev parent reply other threads:[~2024-02-29 11:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-29 11:52 [PATCH 00/13] Custom drives policies verification Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 01/13] mdadm: Add functions for spare criteria verification Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 02/13] mdadm: drop get_required_spare_criteria() Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 03/13] Manage: fix check after dereference issue Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 04/13] Manage: implement manage_add_external() Mariusz Tkaczyk
2024-02-29 11:52 ` Mariusz Tkaczyk [this message]
2024-02-29 11:52 ` [PATCH 06/13] mdadm.h: Introduce custom device policies Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 07/13] mdadm: test_and_add device policies implementation Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 08/13] Create: Use device policies Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 09/13] Manage: check device policies in manage_add_external() Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 10/13] Monitor, Incremental: use device policies Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 11/13] imsm: test_and_add_device_policies() implementation Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 12/13] mdadm: drop get_disk_controller_domain() Mariusz Tkaczyk
2024-02-29 11:52 ` [PATCH 13/13] Revert "policy.c: Avoid to take spare without defined domain by imsm" Mariusz Tkaczyk
2024-03-11 10:05 ` [PATCH 00/13] Custom drives policies verification Mariusz Tkaczyk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240229115217.26543-6-mariusz.tkaczyk@linux.intel.com \
--to=mariusz.tkaczyk@linux.intel.com \
--cc=jes@trained-monkey.org \
--cc=linux-raid@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).