runc update: handle duplicated devs properly

In case there's a duplicate in the device list, the latter entry
overrides the former one.

So, we need to modify the last entry, not the first one. To do that,
use slices.Backward.

Amend the test case to test the fix.

Reported-by: lifubang <lifubang@acmcoder.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 0b01dccfbb)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2025-06-12 13:52:17 -07:00
parent 80da60e12d
commit f14cad5a43
2 changed files with 15 additions and 2 deletions
+8
View File
@@ -904,6 +904,14 @@ EOF
echo "==="
skip "can't get device major number from /proc/partitions (got $major)"
fi
# Add an entry to check that
# - existing devices can be updated;
# - duplicates are handled properly;
# (see func upsert* in update.go).
update_config ' .linux.resources.blockIO.throttleReadBpsDevice |= [
{ major: '"$major"', minor: 0, rate: 485760 },
{ major: '"$major"', minor: 0, rate: 485760 }
]'
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]