0

I currently have a logic to wait for the resync process to finish by looking at /sys/block/mdXXX/md/raid_state to be clean and assume that the resync has finished. However, I don't think this is correct as the raid can be in clean state while the resync is still happening.

What is a guaranteed way to ensure that newly created raid1 array using mdadm has fully completed the resync process?

Does mdadm have an inbuilt way of specifying whether we want to wait for resync to finish or not?

I have a Rust program that is orchestrating RAID creation using mdadm.

    // above create RAID-1 using mdadm --create
    loop {
        let raid_state = read_file("/sys/block/mdXXX/md/raid_state")
        let sync_complete = raid_state == RaidState::Clean;

        if sync_complete {
            // do more
        }
    }

1 Answer 1

1

Maybe use sync_action or sync_completed sys files?

I have two Debian-based machines with an MD RAID 1 each, kernel 5.19.0 and 6.1.0, respectively. Both do not have a raid_state sys file, but they both have /sys/block/mdX/md/sync_action and /sys/block/mdX/md/sync_completed.

During RAID 1 resync, they display resync state and progress:

# cat /sys/block/mdX/md/sync_action
resync
# cat /sys/block/mdX/md/sync_completed
10491763200 / 27344500736

When resync is finished, the output is like this:

# cat /sys/block/mdX/md/sync_action
idle
# cat /sys/block/mdX/md/sync_completed
none

So you could use either of these sys files to check for completion.

No "busy wait", please

On the other hand, please do not "busy wait" like in your code example, or your machine will be more busy with that loop than with the resync. I do not speak Rust, so I have no idea what would be the best way to wait some time between iterations. Depending on the volume size and disk speed, resync can take a day or more, so minutes could be okay.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .