Support parse raid type for mdstat#505
Conversation
|
This needs a DCO sign-off. You can use |
|
@SuperQ Sorry that I forgot the sign-off in later commits😂. And now it's added. |
SuperQ
left a comment
There was a problem hiding this comment.
I think the original checking for (...) in the word after active/inactive was better.
mdstat.go
Outdated
| } | ||
|
|
||
| func isRaidType(mdType string) bool { | ||
| return strings.HasPrefix(mdType, "raid") || mdType == "linear" |
There was a problem hiding this comment.
No, I don't think this is going to work. Like I said, there are a whole bunch of other types other than raid.... Since this can change depending on the kernel/mdadm version. We can't support an exhaustive list here.
mdstat.go
Outdated
| state := deviceFields[2] // active or inactive | ||
|
|
||
| mdType := "unknown" | ||
| if len(deviceFields) > 3 && isRaidType(deviceFields[3]) { |
There was a problem hiding this comment.
If you move this to after if len(lines) <= i+3 { you can reduce the word checking to just the check for (...).
There was a problem hiding this comment.
Actually, maybe this whole piece should be moved to the evalStatusLine() function.
There was a problem hiding this comment.
len(lines) <= i+3 is the guard for lines not the fields in first line, so the move won't be helpful
|
@SuperQ There's a case that I cannot check If we only check parentheses, the type will be But maybe we can assume the type does not contain any special characters? |
|
@SuperQ I changed the code for type checking. It passes all current tests, and I hope it can work forever. |
SuperQ
left a comment
There was a problem hiding this comment.
I think we only get a type if state is active. Maybe check that first before checking the next word or two.
|
@SuperQ I considered this before. But there is another case... We can ignore the type for this, but it's here anyway and it may be useful in some case. |
|
Ahh, crap, yea, that's a problem. |
| // check if a string's format is like the mdType | ||
| // Rule 1: mdType should not be like (...) | ||
| // Rule 2: mdType should not be like sda[0] | ||
| func isRaidType(mdType string) bool { |
There was a problem hiding this comment.
Ewww hah..
There must be a better way. Is there an explicit way to query the md type? E.g by reasing another procfs file?
|
@SuperQ @discordianfish Because of the lack of some knowledge, let's keep this open and see if anyone can help. |
|
@robbat2 Sure, I will update this later this day! |
Signed-off-by: Singee <git@singee.me>
Signed-off-by: Singee <git@singee.me>
Signed-off-by: Singee <git@singee.me>
Signed-off-by: Singee <git@singee.me>
|
@robbat2 I have added the Sign-Off |
Thank you; rebased my PR now |
For something like
We can also get the raid type from /proc/mdstat