summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2008-09-18 16:01:55 +1000
committerNeilBrown <neilb@suse.de>2008-09-18 16:01:55 +1000
commitf35f25259279573c6274e2783536c0b0a399bdd4 (patch)
treefc464d06069d7cf50b642dce3bc01ec6d5f08677 /util.c
parent7801ac209240ca5d5159d2ab990dd8d5573e2195 (diff)
Move calls to SET_ARRAY_INFO to common helper.
When we assemble an array, there are three different approaches depending on whether metadata is internal or external, and on kernel version. Move all this to a common helper instead of duplicating in 3 places. Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'util.c')
-rw-r--r--util.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/util.c b/util.c
index 7469fca4..b63251f4 100644
--- a/util.c
+++ b/util.c
@@ -1009,10 +1009,15 @@ int add_disk(int mdfd, struct supertype *st,
rv = sysfs_add_disk(sra, info);
if (! rv) {
struct mdinfo *sd2;
- sd2 = malloc(sizeof(*sd2));
- *sd2 = *info;
- sd2->next = sra->devs;
- sra->devs = sd2;
+ for (sd2 = sra->devs; sd2; sd2=sd2->next)
+ if (sd2 == info)
+ break;
+ if (sd2 == NULL) {
+ sd2 = malloc(sizeof(*sd2));
+ *sd2 = *info;
+ sd2->next = sra->devs;
+ sra->devs = sd2;
+ }
}
} else
#endif
@@ -1020,6 +1025,31 @@ int add_disk(int mdfd, struct supertype *st,
return rv;
}
+int set_array_info(int mdfd, struct supertype *st, struct mdinfo *info)
+{
+ /* Initialise kernel's knowledge of array.
+ * This varies between externally managed arrays
+ * and older kernels
+ */
+ int vers = md_get_version(mdfd);
+ int rv;
+
+#ifndef MDASSEMBLE
+ if (st->ss->external)
+ rv = sysfs_set_array(info, vers);
+ else
+#endif
+ if ((vers % 100) >= 1) { /* can use different versions */
+ mdu_array_info_t inf;
+ memset(&inf, 0, sizeof(inf));
+ inf.major_version = info->array.major_version;
+ inf.minor_version = info->array.minor_version;
+ rv = ioctl(mdfd, SET_ARRAY_INFO, &inf);
+ } else
+ rv = ioctl(mdfd, SET_ARRAY_INFO, NULL);
+ return rv;
+}
+
char *devnum2devname(int num)
{
char name[100];