summaryrefslogtreecommitdiffstats
path: root/sysfs.c
diff options
context:
space:
mode:
authorMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>2024-02-29 12:52:09 +0100
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>2024-03-11 11:07:03 +0100
commit14a8657940be34a781222b4b715bd09eb80d1057 (patch)
tree44394767f3e4f5947f585449c3e4545e3555af6d /sysfs.c
parentManage: implement manage_add_external() (diff)
downloadmdadm-14a8657940be34a781222b4b715bd09eb80d1057.tar.xz
mdadm-14a8657940be34a781222b4b715bd09eb80d1057.zip
mdadm: introduce sysfs_get_container_devnm()
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>
Diffstat (limited to 'sysfs.c')
-rw-r--r--sysfs.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/sysfs.c b/sysfs.c
index f95ef701..230b842e 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];