Skip to content

Commit 989292a

Browse files
committed
intelrdt: factor common code in a new function
Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent f7e1211 commit 989292a

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/libcrun/intelrdt.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ compare_rdt_configurations (const char *a, const char *b)
167167
return 0;
168168
}
169169

170+
static int
171+
get_resctrl_path (char **path, const char *file, const char *name, libcrun_error_t *err)
172+
{
173+
if (file)
174+
return append_paths (path, err, INTEL_RDT_MOUNT_POINT, name, file, NULL);
175+
else
176+
return append_paths (path, err, INTEL_RDT_MOUNT_POINT, name, NULL);
177+
}
178+
170179
static int
171180
validate_rdt_configuration (const char *name, const char *l3_cache_schema, const char *mem_bw_schema, libcrun_error_t *err)
172181
{
@@ -175,7 +184,7 @@ validate_rdt_configuration (const char *name, const char *l3_cache_schema, const
175184
char *it, *end;
176185
int ret;
177186

178-
ret = append_paths (&path, err, INTEL_RDT_MOUNT_POINT, name, SCHEMATA_FILE, NULL);
187+
ret = get_resctrl_path (&path, SCHEMATA_FILE, name, err);
179188
if (UNLIKELY (ret < 0))
180189
return ret;
181190

@@ -258,7 +267,7 @@ resctl_create (const char *name, bool explicit_clos_id, bool *created, const cha
258267
if (ret == 0)
259268
return crun_make_error (err, 0, "the resctl file system is not mounted");
260269

261-
ret = append_paths (&path, err, INTEL_RDT_MOUNT_POINT, name, NULL);
270+
ret = get_resctrl_path (&path, NULL, name, err);
262271
if (UNLIKELY (ret < 0))
263272
return ret;
264273

@@ -300,7 +309,7 @@ resctl_move_task_to (const char *name, pid_t pid, libcrun_error_t *err)
300309
int len;
301310
int ret;
302311

303-
ret = append_paths (&path, err, INTEL_RDT_MOUNT_POINT, name, TASKS_FILE, NULL);
312+
ret = get_resctrl_path (&path, TASKS_FILE, name, err);
304313
if (UNLIKELY (ret < 0))
305314
return ret;
306315

@@ -325,7 +334,7 @@ resctl_update (const char *name, const char *l3_cache_schema, const char *mem_bw
325334
if (l3_cache_schema == NULL && mem_bw_schema == NULL && schemata == NULL)
326335
return 0;
327336

328-
ret = append_paths (&path, err, INTEL_RDT_MOUNT_POINT, name, SCHEMATA_FILE, NULL);
337+
ret = get_resctrl_path (&path, SCHEMATA_FILE, name, err);
329338
if (UNLIKELY (ret < 0))
330339
return ret;
331340

@@ -348,7 +357,7 @@ resctl_destroy (const char *name, libcrun_error_t *err)
348357
cleanup_free char *path = NULL;
349358
int ret;
350359

351-
ret = append_paths (&path, err, INTEL_RDT_MOUNT_POINT, name, NULL);
360+
ret = get_resctrl_path (&path, NULL, name, err);
352361
if (UNLIKELY (ret < 0))
353362
return ret;
354363

0 commit comments

Comments
 (0)