From c1b08ba720486e74461f0ec94a204c1ba4014c06 Mon Sep 17 00:00:00 2001 From: Wangda Tan Date: Thu, 19 Oct 2017 14:45:44 -0700 Subject: [PATCH] YARN-7345. GPU Isolation: Incorrect minor device numbers written to devices.deny file. (Jonathan Hung via wangda) --- .../impl/modules/gpu/gpu-module.c | 2 +- .../test/modules/gpu/test-gpu-module.cc | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/modules/gpu/gpu-module.c b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/modules/gpu/gpu-module.c index f96645d397..1a1b164f2b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/modules/gpu/gpu-module.c +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/modules/gpu/gpu-module.c @@ -108,7 +108,7 @@ static int internal_handle_gpu_request( char param_value[128]; memset(param_value, 0, sizeof(param_value)); snprintf(param_value, sizeof(param_value), "c %d:%d rwm", - major_device_number, i); + major_device_number, minor_devices[i]); int rc = update_cgroups_parameters_func_p("devices", "deny", container_id, param_value); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/modules/gpu/test-gpu-module.cc b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/modules/gpu/test-gpu-module.cc index 7e41fb43d1..b3d93dcecf 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/modules/gpu/test-gpu-module.cc +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/test/modules/gpu/test-gpu-module.cc @@ -165,6 +165,19 @@ TEST_F(TestGpuModule, test_verify_gpu_module_calls_cgroup_parameter) { // Verify cgroups parameters verify_param_updated_to_cgroups(0, NULL); + + /* Test case 3: block 2 non-sequential devices */ + cgroups_parameters_invoked.clear(); + char* argv_2[] = { (char*) "--module-gpu", (char*) "--excluded_gpus", (char*) "1,3", + (char*) "--container_id", container_id }; + rc = handle_gpu_request(&mock_update_cgroups_parameters, + "gpu", 5, argv_2); + ASSERT_EQ(0, rc) << "Should success.\n"; + + // Verify cgroups parameters + const char* expected_cgroups_argv_2[] = { "devices", "deny", container_id, "c 195:1 rwm", + "devices", "deny", container_id, "c 195:3 rwm"}; + verify_param_updated_to_cgroups(8, expected_cgroups_argv_2); } TEST_F(TestGpuModule, test_illegal_cli_parameters) {