feat(nvgpu): Add —overwrite-exists flag for profile creation

When running this in a script on startup to ensure
whatever configuration is required to be created is
created, this avoids several commands to first
check if the profile exists, delete it, then re-create it.
This commit is contained in:
icex2 2025-02-19 19:39:10 +01:00
parent c3a337ceb4
commit c6180bdf47

View File

@ -333,7 +333,7 @@ static bool _nv_info(const nv_api_t *nv_api)
return true;
}
static bool _profile_create(const nv_api_t *nv_api, const char *profile_name)
static bool _profile_create(const nv_api_t *nv_api, const char *profile_name, bool overwrite_exists)
{
NvDRSSessionHandle session;
NVDRS_PROFILE profile;
@ -358,6 +358,26 @@ static bool _profile_create(const nv_api_t *nv_api, const char *profile_name)
status = nv_api->NvAPI_DRS_CreateProfile(session, &profile, &profile_handle);
if (status == NVAPI_PROFILE_NAME_IN_USE && overwrite_exists) {
printfln_err("Profile %s already exists, enabled overwrite existing...", profile_name);
if (!_profile_get(nv_api, profile_name, session, &profile_handle)) {
_session_destroy(nv_api, session);
return false;
}
status = nv_api->NvAPI_DRS_DeleteProfile(session, profile_handle);
if (status != NVAPI_OK) {
PRINT_ERR_WITH_NVAPI_MESSAGE(status, "ERROR: Deleting existing profile");
return false;
}
// Retry
status = nv_api->NvAPI_DRS_CreateProfile(session, &profile, &profile_handle);
}
if (status != NVAPI_OK) {
PRINT_ERR_WITH_NVAPI_MESSAGE(status, "ERROR: Creating driver profile");
@ -1294,6 +1314,7 @@ static bool _cmd_nv_info(const nv_api_t *nv_api)
static bool _cmd_profile_create(const nv_api_t *nv_api, int argc, char **argv)
{
const char *profile_name;
bool overwrite_exists;
if (argc < 1) {
_print_synopsis();
@ -1303,7 +1324,15 @@ static bool _cmd_profile_create(const nv_api_t *nv_api, int argc, char **argv)
profile_name = argv[0];
return _profile_create(nv_api, profile_name);
overwrite_exists = false;
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--overwrite-exists")) {
overwrite_exists = true;
}
}
return _profile_create(nv_api, profile_name, overwrite_exists);
}
static bool _cmd_profile_delete(const nv_api_t *nv_api, int argc, char **argv)