Skip to content

Commit

Permalink
DAOS-13711 client: several coverity silencing fixes (#12415) (#12454)
Browse files Browse the repository at this point in the history
- Fix for coverity: 1449753 1449752 1449751 709506 1449749 1449748 1443160.
- Remove some uneeded allocations in array set size when adding 1 record.
- init recx to 0 for key query when passed by 0 since EC expects it to be.

Signed-off-by: Mohamad Chaarawi <mohamad.chaarawi@intel.com>
  • Loading branch information
mchaarawi authored Jun 21, 2023
1 parent 5d3d0b7 commit 702c989
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 86 deletions.
1 change: 0 additions & 1 deletion src/client/api/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ daos_eq_free(struct d_hlink *hlink)
crt_context_t
daos_get_crt_ctx()
{
D_ASSERT(eq_ref > 0);
return daos_eq_ctx;
}

Expand Down
74 changes: 46 additions & 28 deletions src/client/array/dc_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct io_params {
uint64_t dkey_val;
daos_iod_t iod;
d_sg_list_t sgl;
d_iov_t sg_iov; /** for 1 record updates on set_size */
daos_iom_t iom; /** used on fetch only */
daos_size_t cell_size;
daos_size_t chunk_size;
Expand Down Expand Up @@ -739,7 +740,7 @@ dc_array_open(tse_task_t *task)
/** Create task to open object */
rc = daos_task_create(DAOS_OPC_OBJ_OPEN, tse_task2sched(task), 0, NULL, &open_task);
if (rc != 0) {
D_ERROR("Failed to open object_open task "DF_RC"\n", DP_RC(rc));
D_ERROR("Failed to create object_open task "DF_RC"\n", DP_RC(rc));
D_GOTO(err_ptask, rc);
}

Expand Down Expand Up @@ -2124,6 +2125,7 @@ check_record_cb(tse_task_t *task, void *data)
d_sg_list_t *sgl;
daos_key_t *dkey;
char *val;
bool free_params = true, free_val = true;
int rc = task->dt_result;

D_ASSERT(params);
Expand All @@ -2132,7 +2134,6 @@ check_record_cb(tse_task_t *task, void *data)
/** Last record is there, no need to add it */
if (rc || params->iod.iod_size != 0) {
D_FREE(iod->iod_recxs);
D_FREE(params);
D_GOTO(out, rc);
}

Expand All @@ -2145,17 +2146,20 @@ check_record_cb(tse_task_t *task, void *data)

/** set memory location */
D_ALLOC(val, params->cell_size);
if (val == NULL)
D_GOTO(out, rc = -DER_NOMEM);
sgl->sg_nr = 1;
D_ALLOC_PTR(sgl->sg_iovs);
sgl->sg_iovs = &params->sg_iov;
d_iov_set(&sgl->sg_iovs[0], val, params->cell_size);
params->user_sgl_used = true;

D_DEBUG(DB_IO, "update record (%zu, %zu), iod_size %zu.\n",
iod->iod_recxs[0].rx_idx, iod->iod_recxs[0].rx_nr,
iod->iod_size);
rc = daos_task_create(DAOS_OPC_OBJ_UPDATE, tse_task2sched(task), 0, NULL, &io_task);
if (rc) {
D_ERROR("Task create failed "DF_RC"\n", DP_RC(rc));
D_GOTO(out, rc);
D_GOTO(err_free, rc);
}

io_arg = daos_task_get_args(io_task);
Expand All @@ -2168,31 +2172,37 @@ check_record_cb(tse_task_t *task, void *data)

rc = tse_task_register_comp_cb(io_task, free_io_params_cb, &params, sizeof(params));
if (rc)
D_GOTO(err, rc);

D_GOTO(err_task, rc);
free_params = false;
rc = tse_task_register_comp_cb(io_task, free_val_cb, &val, sizeof(val));
if (rc)
D_GOTO(err, rc);
D_GOTO(err_task, rc);
free_val = false;

/* params->task is the original task of dc_array_set_size, should make
* io_task as dep task of params->task rather than the passed in task
* (which is the check_record's OBJ_FETCH task) to make sure the io_task
* complete before original task of dc_array_set_size's completion.
/*
* params->task is the original task of dc_array_set_size, should make io_task as dep task
* of params->task rather than the passed in task (which is the check_record's OBJ_FETCH
* task) to make sure the io_task complete before original task of dc_array_set_size's
* completion.
*/
rc = tse_task_register_deps(params->task, 1, &io_task);
if (rc)
D_GOTO(err, rc);
D_GOTO(err_task, rc);

rc = tse_task_schedule(io_task, true);
if (rc)
D_GOTO(err, rc);

D_GOTO(err_free, rc);
return rc;
err:

err_task:
if (io_task)
tse_task_complete(io_task, rc);
err_free:
if (free_val)
D_FREE(val);
out:
D_FREE(params);
if (free_params)
D_FREE(params);
return rc;
}

Expand Down Expand Up @@ -2274,7 +2284,8 @@ add_record(daos_handle_t oh, daos_handle_t th, struct set_size_props *props, d_l
d_sg_list_t *sgl;
daos_key_t *dkey;
struct io_params *params = NULL;
tse_task_t *io_task = NULL;
tse_task_t *io_task;
bool free_iod_recxs = true;
int rc;

D_ALLOC_PTR(params);
Expand All @@ -2287,30 +2298,33 @@ add_record(daos_handle_t oh, daos_handle_t th, struct set_size_props *props, d_l

params->akey_val = '0';
params->next = NULL;
params->user_sgl_used = false;
params->dkey_val = props->dkey_val;
d_iov_set(dkey, &params->dkey_val, sizeof(uint64_t));

/** set memory location */
/** set memory location - freed in free_set_size_cb (already registered) */
D_ALLOC(props->val, props->cell_size);
if (props->val == NULL)
D_GOTO(err, rc = -DER_NOMEM);
sgl->sg_nr = 1;
D_ALLOC_PTR(sgl->sg_iovs);
sgl->sg_iovs = &params->sg_iov;
d_iov_set(&sgl->sg_iovs[0], props->val, props->cell_size);
params->user_sgl_used = true;

/* set descriptor for KV object */
d_iov_set(&iod->iod_name, &params->akey_val, 1);
iod->iod_nr = 1;
iod->iod_size = props->cell_size;
iod->iod_type = DAOS_IOD_ARRAY;
D_ALLOC_PTR(iod->iod_recxs);
D_ALLOC_PTR(iod->iod_recxs); /** freed in free_io_params_cb */
if (iod->iod_recxs == NULL)
D_GOTO(err, rc = -DER_NOMEM);
iod->iod_recxs[0].rx_idx = props->record_i;
iod->iod_recxs[0].rx_nr = 1;

rc = daos_task_create(DAOS_OPC_OBJ_UPDATE, tse_task2sched(props->ptask), 0, NULL, &io_task);
if (rc) {
D_FREE(sgl->sg_iovs);
if (rc)
D_GOTO(err, rc);
}

io_arg = daos_task_get_args(io_task);
io_arg->oh = oh;
io_arg->th = th;
Expand All @@ -2321,21 +2335,25 @@ add_record(daos_handle_t oh, daos_handle_t th, struct set_size_props *props, d_l

rc = tse_task_register_comp_cb(io_task, free_io_params_cb, &params, sizeof(params));
if (rc)
D_GOTO(err, rc);
D_GOTO(err_task, rc);
free_iod_recxs = false;

rc = tse_task_register_deps(props->ptask, 1, &io_task);
if (rc)
D_GOTO(err, rc);
D_GOTO(err_task, rc);

/* decref in adjust_array_size_task_process() */
tse_task_addref(io_task);
tse_task_list_add(io_task, task_list);
return rc;

err:
D_FREE(params);
err_task:
if (io_task)
tse_task_complete(io_task, rc);
err:
D_FREE(params);
if (free_iod_recxs)
D_FREE(iod->iod_recxs);
return rc;
}

Expand Down
5 changes: 2 additions & 3 deletions src/client/ds3/bucket.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,6 @@ ds3_bucket_set_info(struct ds3_bucket_info *info, ds3_bucket_t *ds3b, daos_event
{
int rc = 0;
char const *const names[] = {RGW_BUCKET_INFO};
void const *const values[] = {info->encoded};
size_t const sizes[] = {info->encoded_length};
daos_handle_t coh;

if (ds3b == NULL || info == NULL)
Expand All @@ -280,7 +278,8 @@ ds3_bucket_set_info(struct ds3_bucket_info *info, ds3_bucket_t *ds3b, daos_event
if (rc != 0)
return -rc;

rc = daos_cont_set_attr(coh, 1, names, values, sizes, ev);
rc = daos_cont_set_attr(coh, 1, names, (void *const)(&info->encoded),
&info->encoded_length, ev);
rc = daos_der2errno(rc);
dfs_cont_put(ds3b->dfs, coh);
return -rc;
Expand Down
Loading

0 comments on commit 702c989

Please sign in to comment.