Take undef enum into account for correct array index comparison
PATCH 1/1 Take undef enum into account for correct array index comparison
Previously this would compare to the wrong index
since the enum has an additional UNDEF entry
--- libmultipath/dict.c | 2 ++ 1 file changed, 2 insertions(+)
libmultipath/dict.c +2 -0
@@ -550,6 +550,7 @@ static int snprint_def_partition_delim(struct config *conf, struct strbuf *buff, }static const char *const find_multipaths_optvals[] = { + [FIND_MULTIPATHS_UNDEF ] ="undef" , [FIND_MULTIPATHS_OFF ] ="off" , [FIND_MULTIPATHS_ON ] ="on" , [FIND_MULTIPATHS_STRICT ] ="strict" ,
@@ -793,6 +794,7 @@ declare_def_snprint(allow_usb_devices, print_yes_no)static const char *const flush_on_last_del_optvals[] = { + [FLUSH_UNDEF ] ="undef" , [FLUSH_NEVER ] ="never" , [FLUSH_ALWAYS ] ="always" , [FLUSH_UNUSED ] ="unused" ,
Signature · 1 line
2.50.1
Benjamin Marzinski
maintainerQuoted 2 lines · Alex Kalenyuk
Previously this would compare to the wrong index
since the enum has an additional UNDEF entry
Are you actually seeing multipath getting misconfigured here, because the code doesn't look wrong to me. We didn't and the "undef" elements because we don't want to accept "undef" as a valid value from the config file.
This code is admittedly a little confusing. We aren't looping from 0 to the last value, we are looping from FIND_MULTIPATHS_OFF or FLUSH_NEVER (which have the value of 1). The way the loop works, we won't even check the config text against the array elements you added. We intentionally only set elements in those arrays at the values we want to start checking at: FIND_MULTIPATHS_OFF and FLUSH_NEVER. As long as the text in the optvals array is correct for the value we are using as its index, if we match the config text with the optvals text, 'i' must be equal to the value we want (since the value we want is array index of the matching text).
If you are seeing a configuration issue, we do want to hear about it. I'm not saying there isn't a bug, but unless I'm missing something, I don't think that this is it. Also multipath's configuration priority isn't always super intuitive, so sometimes it is working as designed, but not you might intuitively expect.
-Ben
Quoted 28 lines
Signed-off-by Alex Kalenyuk <[email protected]>--- libmultipath/dict.c | 2 ++ 1 file changed, 2 insertions(+)libmultipath/dict.c +2
-0@@ -550,6 +550,7 @@ static int snprint_def_partition_delim(struct config *conf, struct strbuf *buff, }static const char *const find_multipaths_optvals[] = { + [FIND_MULTIPATHS_UNDEF ] ="undef" , [FIND_MULTIPATHS_OFF ] ="off" , [FIND_MULTIPATHS_ON ] ="on" , [FIND_MULTIPATHS_STRICT ] ="strict" ,@@ -793,6 +794,7 @@ declare_def_snprint(allow_usb_devices, print_yes_no)static const char *const flush_on_last_del_optvals[] = { + [FLUSH_UNDEF ] ="undef" , [FLUSH_NEVER ] ="never" , [FLUSH_ALWAYS ] ="always" , [FLUSH_UNUSED ] ="unused" ,Signature · 1 line
2.50.1
You're totally right, I had an older multipath running on my system, and I did not realize (only yes/no in flush_last_del).
This commit can be safely ignored, everything is working as expected, thank you!
Quoted 58 lines · Benjamin Marzinski
Quoted 2 lines · Alex Kalenyuk
Previously this would compare to the wrong index
since the enum has an additional UNDEF entryAre you actually seeing multipath getting misconfigured here, because the code doesn't look wrong to me. We didn't and the "undef" elements because we don't want to accept "undef" as a valid value from the config file.
This code is admittedly a little confusing. We aren't looping from 0 to the last value, we are looping from
FIND_MULTIPATHS_OFForFLUSH_NEVER(which have the value of 1). The way the loop works, we won't even check the config text against the array elements you added. We intentionally only set elements in those arrays at the values we want to start checking at:FIND_MULTIPATHS_OFFandFLUSH_NEVER. As long as the text in the optvals array is correct for the value we are using as its index, if we match the config text with the optvals text, 'i' must be equal to the value we want (since the value we want is array index of the matching text).If you are seeing a configuration issue, we do want to hear about it. I'm not saying there isn't a bug, but unless I'm missing something, I don't think that this is it. Also multipath's configuration priority isn't always super intuitive, so sometimes it is working as designed, but not you might intuitively expect.
-Ben
Quoted 28 lines
Signed-off-by Alex Kalenyuk <[email protected]>--- libmultipath/dict.c | 2 ++ 1 file changed, 2 insertions(+)libmultipath/dict.c +2
-1@@ -550,6 +550,7 @@ static int snprint_def_partition_delim(struct config *conf, struct strbuf *buff, }static const char *const find_multipaths_optvals[] = { + [FIND_MULTIPATHS_UNDEF ] ="undef" , [FIND_MULTIPATHS_OFF ] ="off" , [FIND_MULTIPATHS_ON ] ="on" , [FIND_MULTIPATHS_STRICT ] ="strict" ,@@ -793,6 +794,7 @@ declare_def_snprint(allow_usb_devices, print_yes_no)static const char *const flush_on_last_del_optvals[] = { + [FLUSH_UNDEF ] ="undef" , [FLUSH_NEVER ] ="never" , [FLUSH_ALWAYS ] ="always" , [FLUSH_UNUSED ] ="unused" , --2.50.1