Skip to content

Commit 2d73c23

Browse files
Better logging for codelet validation (#125)
Better logging for validation
1 parent 36aa144 commit 2d73c23

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

src/core/jbpf.c

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ validate_string_param(char* param_name, char* param, uint32_t param_maxlen, jbpf
274274
static int
275275
validate_codeletset(struct jbpf_codeletset_load_req* load_req, jbpf_codeletset_load_error_s* err)
276276
{
277-
278277
if (!load_req) {
279278
char msg[JBPF_MAX_ERR_MSG_SIZE];
280279
sprintf(msg, "load_req is NULL\n");
@@ -286,7 +285,7 @@ validate_codeletset(struct jbpf_codeletset_load_req* load_req, jbpf_codeletset_l
286285
}
287286

288287
if (validate_string_param("codeletset_id.name", load_req->codeletset_id.name, JBPF_CODELETSET_NAME_LEN, err) != 1) {
289-
return JBPF_CODELET_PARAM_INVALID;
288+
goto err;
290289
}
291290

292291
if (load_req->num_codelet_descriptors == 0) {
@@ -296,7 +295,7 @@ validate_codeletset(struct jbpf_codeletset_load_req* load_req, jbpf_codeletset_l
296295
if (err) {
297296
strcpy(err->err_msg, msg);
298297
}
299-
return JBPF_CODELET_PARAM_INVALID;
298+
goto err;
300299
}
301300

302301
if (load_req->num_codelet_descriptors > JBPF_MAX_CODELETS_IN_CODELETSET) {
@@ -306,39 +305,39 @@ validate_codeletset(struct jbpf_codeletset_load_req* load_req, jbpf_codeletset_l
306305
if (err) {
307306
strcpy(err->err_msg, msg);
308307
}
309-
return JBPF_CODELET_PARAM_INVALID;
308+
goto err;
310309
}
311310

312311
for (int i = 0; i < load_req->num_codelet_descriptors; ++i) {
313312

314313
// validate codelet_name
315314
if (validate_string_param(
316315
"codelet_name", load_req->codelet_descriptor[i].codelet_name, JBPF_CODELET_NAME_LEN, err) != 1) {
317-
return JBPF_CODELET_PARAM_INVALID;
316+
goto err;
318317
}
319318

320319
// validate hook_name
321320
if (validate_string_param("hook_name", load_req->codelet_descriptor[i].hook_name, JBPF_HOOK_NAME_LEN, err) !=
322321
1) {
323-
return JBPF_CODELET_PARAM_INVALID;
322+
goto err;
324323
}
325324

326325
// validate codelet_path
327326
if (validate_string_param("codelet_path", load_req->codelet_descriptor[i].codelet_path, JBPF_PATH_LEN, err) !=
328327
1) {
329-
return JBPF_CODELET_PARAM_INVALID;
328+
goto err;
330329
}
331330

332331
// validate in_io_channel
333332
for (int ch = 0; ch < load_req->codelet_descriptor[i].num_in_io_channel; ch++) {
334333
jbpf_io_channel_desc_s* chan = &load_req->codelet_descriptor[i].in_io_channel[ch];
335-
if (validate_string_param("in_io_channel.name ", chan->name, JBPF_IO_CHANNEL_NAME_LEN, err) != 1) {
336-
return JBPF_CODELET_PARAM_INVALID;
334+
if (validate_string_param("in_io_channel.name", chan->name, JBPF_IO_CHANNEL_NAME_LEN, err) != 1) {
335+
goto err;
337336
}
338337
#ifdef JBPF_EXPERIMENTAL_FEATURES
339338
if (chan->has_serde) {
340339
if (validate_string_param("in_io_channel.serde ", chan->serde.file_path, JBPF_PATH_LEN, err) != 1) {
341-
return JBPF_CODELET_PARAM_INVALID;
340+
goto err;
342341
}
343342
// check Serde file exists
344343
FILE* file = fopen(chan->serde.file_path, "rb");
@@ -349,7 +348,7 @@ validate_codeletset(struct jbpf_codeletset_load_req* load_req, jbpf_codeletset_l
349348
if (err) {
350349
strcpy(err->err_msg, msg);
351350
}
352-
return JBPF_CODELET_PARAM_INVALID;
351+
goto err;
353352
}
354353
fclose(file);
355354
}
@@ -359,13 +358,13 @@ validate_codeletset(struct jbpf_codeletset_load_req* load_req, jbpf_codeletset_l
359358
// validate out_io_channel
360359
for (int ch = 0; ch < load_req->codelet_descriptor[i].num_out_io_channel; ch++) {
361360
jbpf_io_channel_desc_s* chan = &load_req->codelet_descriptor[i].out_io_channel[ch];
362-
if (validate_string_param("out_io_channel.name ", chan->name, JBPF_IO_CHANNEL_NAME_LEN, err) != 1) {
363-
return JBPF_CODELET_PARAM_INVALID;
361+
if (validate_string_param("out_io_channel.name", chan->name, JBPF_IO_CHANNEL_NAME_LEN, err) != 1) {
362+
goto err;
364363
}
365364
#ifdef JBPF_EXPERIMENTAL_FEATURES
366365
if (chan->has_serde) {
367366
if (validate_string_param("out_io_channel.serde ", chan->serde.file_path, JBPF_PATH_LEN, err) != 1) {
368-
return JBPF_CODELET_PARAM_INVALID;
367+
goto err;
369368
}
370369
// check Serde file exists
371370
FILE* file = fopen(chan->serde.file_path, "rb");
@@ -376,7 +375,7 @@ validate_codeletset(struct jbpf_codeletset_load_req* load_req, jbpf_codeletset_l
376375
if (err) {
377376
strcpy(err->err_msg, msg);
378377
}
379-
return JBPF_CODELET_PARAM_INVALID;
378+
goto err;
380379
}
381380
fclose(file);
382381
}
@@ -386,17 +385,17 @@ validate_codeletset(struct jbpf_codeletset_load_req* load_req, jbpf_codeletset_l
386385
// validate linked_maps
387386
for (int m = 0; m < load_req->codelet_descriptor[i].num_linked_maps; m++) {
388387
jbpf_linked_map_descriptor_s* map = &load_req->codelet_descriptor[i].linked_maps[m];
389-
if (validate_string_param("linked_maps.map_name ", map->map_name, JBPF_MAP_NAME_LEN, err) != 1) {
390-
return JBPF_CODELET_PARAM_INVALID;
388+
if (validate_string_param("linked_maps.map_name", map->map_name, JBPF_MAP_NAME_LEN, err) != 1) {
389+
goto err;
391390
}
392391
if (validate_string_param(
393-
"linked_maps.linked_codelet_name ", map->linked_codelet_name, JBPF_CODELET_NAME_LEN, err) != 1) {
394-
return JBPF_CODELET_PARAM_INVALID;
392+
"linked_maps.linked_codelet_name", map->linked_codelet_name, JBPF_CODELET_NAME_LEN, err) != 1) {
393+
goto err;
395394
}
396395

397-
if (validate_string_param("linked_maps.linked_map_name ", map->linked_map_name, JBPF_MAP_NAME_LEN, err) !=
396+
if (validate_string_param("linked_maps.linked_map_name", map->linked_map_name, JBPF_MAP_NAME_LEN, err) !=
398397
1) {
399-
return JBPF_CODELET_PARAM_INVALID;
398+
goto err;
400399
}
401400
}
402401
// check that a codelet does not link to itself
@@ -415,7 +414,7 @@ validate_codeletset(struct jbpf_codeletset_load_req* load_req, jbpf_codeletset_l
415414
if (err) {
416415
strcpy(err->err_msg, msg);
417416
}
418-
return JBPF_CODELET_PARAM_INVALID;
417+
goto err;
419418
}
420419
}
421420
// check that map_name is unique
@@ -431,7 +430,7 @@ validate_codeletset(struct jbpf_codeletset_load_req* load_req, jbpf_codeletset_l
431430
if (err) {
432431
strcpy(err->err_msg, msg);
433432
}
434-
return JBPF_CODELET_PARAM_INVALID;
433+
goto err;
435434
}
436435
}
437436
}
@@ -454,7 +453,7 @@ validate_codeletset(struct jbpf_codeletset_load_req* load_req, jbpf_codeletset_l
454453
if (err) {
455454
strcpy(err->err_msg, msg);
456455
}
457-
return JBPF_CODELET_PARAM_INVALID;
456+
goto err;
458457
}
459458
}
460459
}
@@ -468,19 +467,23 @@ validate_codeletset(struct jbpf_codeletset_load_req* load_req, jbpf_codeletset_l
468467
char msg[JBPF_MAX_ERR_MSG_SIZE];
469468
sprintf(
470469
msg,
471-
"codelet_name %s is not unique. Unloading codeletset %s\n",
470+
"codelet_name %s is not unique (codeletset %s)\n",
472471
load_req->codelet_descriptor[i].codelet_name,
473472
load_req->codeletset_id.name);
474473
jbpf_logger(JBPF_ERROR, "%s", msg);
475474
if (err) {
476475
strcpy(err->err_msg, msg);
477476
}
478-
return JBPF_CODELET_PARAM_INVALID;
477+
goto err;
479478
}
480479
}
481480
}
482481

483482
return JBPF_CODELET_LOAD_SUCCESS;
483+
484+
err:
485+
jbpf_logger(JBPF_ERROR, "Codeletset %s validation failed.\n", load_req->codeletset_id.name);
486+
return JBPF_CODELET_PARAM_INVALID;
484487
}
485488

486489
static void*

0 commit comments

Comments
 (0)