]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
sysfs: fix uuid endianness mismatch issue in sysfs_rules_apply()
authorAbirami0904 <abimeenakshi2692@gmail.com>
Mon, 9 Mar 2026 14:13:52 +0000 (19:43 +0530)
committerMariusz Tkaczyk <mtkaczyk@kernel.org>
Wed, 11 Mar 2026 07:46:33 +0000 (08:46 +0100)
Issue:
sync_speed_max configured in mdadm.conf is not applied to sysfs due
to a UUID endianness mismatch in sysfs_rules_apply().

Observed behavior:
The sysfs parameter is applied via sysfs_set_str(), which is invoked
from sysfs_rules_apply(). Whether this function is called depends on
a memcmp() comparison between the UUIDs stored in
struct dev_sysfs_rule *rules and struct mdinfo *dev.

This comparison fails due to inconsistent byte ordering of the UUIDs.

Due to this endianness mismatch, the memcmp() comparison in
sysfs_rules_apply() fails, and therefore sysfs_set_str() is not
invoked to update sync_speed_max in sysfs.

Proposed fix:
To resolve this issue, same_uuid() logic is used.

Signed-off-by: Abirami0904 <abimeenakshi2692@gmail.com>
Assemble.c
Incremental.c
mdadm.h
sysfs.c

index 73f3ae3db9aa73406812690d98f3481045b03c31..c7563ab2b2de493765b617b93349f563760028a4 100644 (file)
@@ -1104,7 +1104,7 @@ static int start_array(int mdfd,
        }
 
        if (is_container(content->array.level)) {
-               sysfs_rules_apply(mddev, content);
+               sysfs_rules_apply(mddev, content, st);
                if (c->verbose >= 0) {
                        pr_err("Container %s has been assembled with %d drive%s",
                               mddev, okcnt + sparecnt + journalcnt,
@@ -1184,7 +1184,7 @@ static int start_array(int mdfd,
                        rv = ioctl(mdfd, RUN_ARRAY, NULL);
                reopen_mddev(mdfd); /* drop O_EXCL */
                if (rv == 0) {
-                       sysfs_rules_apply(mddev, content);
+                       sysfs_rules_apply(mddev, content, st);
                        if (c->verbose >= 0) {
                                pr_info("%s has been started with %d drive%s",
                                       mddev, okcnt, okcnt==1?"":"s");
@@ -2222,7 +2222,7 @@ int assemble_container_content(struct supertype *st, int mdfd,
        else {
                set_array_assembly_status(c, result, INCR_YES, &array);
                wait_for(chosen_name, mdfd);
-               sysfs_rules_apply(chosen_name, content);
+               sysfs_rules_apply(chosen_name, content, st);
        }
 
        return err;
index 28f95a7d5b5f6c6e085f966f96e4d76fb9796ee5..f717c9c31b21ef1f0d37996deacfe32435dd45b4 100644 (file)
@@ -468,7 +468,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
                        pr_err("container %s now has %d device%s\n",
                               chosen_name, info.array.working_disks,
                               info.array.working_disks == 1?"":"s");
-               sysfs_rules_apply(chosen_name, &info);
+               sysfs_rules_apply(chosen_name, &info, st);
                wait_for(chosen_name, mdfd);
                if (st->ss->external)
                        strcpy(devnm, fd2devnm(mdfd));
diff --git a/mdadm.h b/mdadm.h
index 055d31e98c494b29ea1f8d5041f9a7d71cba0553..78f498a7a6b2690b04f4e6c6d461cb944282b16d 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -1484,7 +1484,7 @@ void domain_add(struct domainlist **domp, char *domain);
 extern void policy_save_path(char *id_path, struct map_ent *array);
 extern int policy_check_path(struct mdinfo *disk, struct map_ent *array);
 
-extern void sysfs_rules_apply(char *devnm, struct mdinfo *dev);
+extern void sysfs_rules_apply(char *devnm, struct mdinfo *dev, const struct supertype *st);
 extern void sysfsline(char *line);
 
 #if __GNUC__ < 3
diff --git a/sysfs.c b/sysfs.c
index e60adc9f549fe4125685e7ab7ad192de00965fb2..7589e944c8e690335c19fba5b1e1d3f4aa446ec0 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -1127,7 +1127,7 @@ int sysfs_rules_apply_check(const struct mdinfo *sra,
 
 static struct dev_sysfs_rule *sysfs_rules;
 
-void sysfs_rules_apply(char *devnm, struct mdinfo *dev)
+void sysfs_rules_apply(char *devnm, struct mdinfo *dev, const struct supertype *st)
 {
        struct dev_sysfs_rule *rules = sysfs_rules;
 
@@ -1139,10 +1139,8 @@ void sysfs_rules_apply(char *devnm, struct mdinfo *dev)
                        if (rules->devname)
                                match = strcmp(devnm, rules->devname) == 0;
                } else {
-                       match = memcmp(dev->uuid, rules->uuid,
-                                      sizeof(int[4])) == 0;
+                       match = same_uuid(dev->uuid, rules->uuid, st->ss->swapuuid);
                }
-
                while (match && ent) {
                        if (sysfs_rules_apply_check(dev, ent) < 0)
                                pr_err("SYSFS: failed to write '%s' to '%s'\n",