Skip to content

Commit

Permalink
Fix unchecked return values
Browse files Browse the repository at this point in the history
Coverity complained about unchecked return values.

Different approaches were used to handle the different cases.

* cmd/zdb/zdb.c: VERIFY0 was used since the existing code had no error
  handling.

* cmd/zed/agents/zfs_retire.c: We silently return since this is a void
  function and other nvlist lookup failures already silently return.

* cmd/zpool_influxdb/zpool_influxdb.c: `(void) fnvlist_lookup_*()` was
  used since there is no error handling for the return from
  `get_vdev_desc()`.

* cmd/ztest.c: VERIFY0 was used since we want failures if something goes
  wrong in ztest.

* module/zfs/dsl_dir.c: We dismiss the return value with `(void)`
  because there is no guarantee that the zap entry will always be there.
  For example, old pools imported readonly would not have it and we do
  not want to fail here because of that.

* module/zfs/zfs_fm.c: `(void) fnvlist_lookup_*()` was used since the
  allocations sleep and thus can never fail.

* module/zfs/zvol.c: We dismiss the return value with `(void)` because
  we do not need it. This matches what is already done in the analogous
  `zfs_replay_write2()`.

Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
  • Loading branch information
ryao committed Sep 19, 2022
1 parent 48cf170 commit e5a86df
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 17 deletions.
6 changes: 3 additions & 3 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4418,9 +4418,9 @@ dump_l2arc_log_blocks(int fd, l2arc_dev_hdr_phys_t l2dhdr,
default:
abd = abd_alloc_for_io(asize, B_TRUE);
abd_copy_from_buf_off(abd, &this_lb, 0, asize);
zio_decompress_data(L2BLK_GET_COMPRESS(
VERIFY0(zio_decompress_data(L2BLK_GET_COMPRESS(
(&lbps[0])->lbp_prop), abd, &this_lb,
asize, sizeof (this_lb), NULL);
asize, sizeof (this_lb), NULL));
abd_free(abd);
break;
}
Expand Down Expand Up @@ -7586,7 +7586,7 @@ dump_mos_leaks(spa_t *spa)
} else {
dmu_object_info_t doi;
const char *name;
dmu_object_info(mos, object, &doi);
VERIFY0(dmu_object_info(mos, object, &doi));
if (doi.doi_type & DMU_OT_NEWTYPE) {
dmu_object_byteswap_t bswap =
DMU_OT_BYTESWAP(doi.doi_type);
Expand Down
5 changes: 4 additions & 1 deletion cmd/zed/agents/zfs_retire.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ zfs_retire_recv(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl,

fmd_hdl_debug(hdl, "zfs_retire_recv: '%s'", class);

nvlist_lookup_uint64(nvl, FM_EREPORT_PAYLOAD_ZFS_VDEV_STATE, &state);
if (nvlist_lookup_uint64(nvl, FM_EREPORT_PAYLOAD_ZFS_VDEV_STATE,
&state) != 0) {
return;
}

/*
* If this is a resource notifying us of device removal then simply
Expand Down
6 changes: 3 additions & 3 deletions cmd/zpool_influxdb/zpool_influxdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ get_vdev_desc(nvlist_t *nvroot, const char *parent_name)
char *vdev_type = (char *)"unknown";
uint64_t vdev_id = UINT64_MAX;
char *vdev_path = NULL;
nvlist_lookup_string(nvroot, ZPOOL_CONFIG_TYPE, &vdev_type);
nvlist_lookup_uint64(nvroot, ZPOOL_CONFIG_ID, &vdev_id);
nvlist_lookup_string(nvroot, ZPOOL_CONFIG_PATH, &vdev_path);
vdev_type = fnvlist_lookup_string(nvroot, ZPOOL_CONFIG_TYPE);
vdev_id = fnvlist_lookup_uint64(nvroot, ZPOOL_CONFIG_ID);
vdev_path = fnvlist_lookup_string(nvroot, ZPOOL_CONFIG_PATH);

if (parent_name == NULL) {
s = escape_string(vdev_type);
Expand Down
2 changes: 1 addition & 1 deletion cmd/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -2214,7 +2214,7 @@ ztest_replay_write(void *arg1, void *arg2, boolean_t byteswap)
dmu_write(os, lr->lr_foid, offset, length, data, tx);
} else {
memcpy(abuf->b_data, data, length);
dmu_assign_arcbuf_by_dbuf(db, offset, abuf, tx);
VERIFY0(dmu_assign_arcbuf_by_dbuf(db, offset, abuf, tx));
}

(void) ztest_log_write(zd, tx, lr);
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/dsl_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ dsl_dir_hold_obj(dsl_pool_t *dp, uint64_t ddobj,

if (dsl_dir_is_zapified(dd)) {
inode_timespec_t t = {0};
zap_lookup(dp->dp_meta_objset, ddobj,
(void) zap_lookup(dp->dp_meta_objset, ddobj,
DD_FIELD_SNAPSHOTS_CHANGED,
sizeof (uint64_t),
sizeof (inode_timespec_t) / sizeof (uint64_t),
Expand Down
12 changes: 6 additions & 6 deletions module/zfs/zfs_fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1389,17 +1389,17 @@ zfs_post_state_change(spa_t *spa, vdev_t *vd, uint64_t laststate)
aux = fm_nvlist_create(NULL);
if (vd && aux) {
if (vd->vdev_physpath) {
(void) nvlist_add_string(aux,
(void) fnvlist_add_string(aux,
FM_EREPORT_PAYLOAD_ZFS_VDEV_PHYSPATH,
vd->vdev_physpath);
}
if (vd->vdev_enc_sysfs_path) {
(void) nvlist_add_string(aux,
(void) fnvlist_add_string(aux,
FM_EREPORT_PAYLOAD_ZFS_VDEV_ENC_SYSFS_PATH,
vd->vdev_enc_sysfs_path);
}

(void) nvlist_add_uint64(aux,
(void) fnvlist_add_uint64(aux,
FM_EREPORT_PAYLOAD_ZFS_VDEV_LASTSTATE, laststate);
}

Expand Down Expand Up @@ -1496,12 +1496,12 @@ zfs_ereport_zvol_post(const char *subclass, const char *name,
return;

aux = fm_nvlist_create(NULL);
nvlist_add_string(aux, FM_EREPORT_PAYLOAD_ZFS_DEVICE_NAME, dev_name);
nvlist_add_string(aux, FM_EREPORT_PAYLOAD_ZFS_RAW_DEVICE_NAME,
(void) fnvlist_add_string(aux, FM_EREPORT_PAYLOAD_ZFS_DEVICE_NAME, dev_name);
(void) fnvlist_add_string(aux, FM_EREPORT_PAYLOAD_ZFS_RAW_DEVICE_NAME,
raw_name);
r = strchr(name, '/');
if (r && r[1])
nvlist_add_string(aux, FM_EREPORT_PAYLOAD_ZFS_VOLUME, &r[1]);
(void) fnvlist_add_string(aux, FM_EREPORT_PAYLOAD_ZFS_VOLUME, &r[1]);

zfs_post_common(spa, NULL, FM_RSRC_CLASS, subclass, aux);
fm_nvlist_destroy(aux, FM_NVA_FREE);
Expand Down
4 changes: 2 additions & 2 deletions module/zfs/zvol.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ zvol_replay_truncate(void *arg1, void *arg2, boolean_t byteswap)
if (error != 0) {
dmu_tx_abort(tx);
} else {
zil_replaying(zv->zv_zilog, tx);
(void) zil_replaying(zv->zv_zilog, tx);
dmu_tx_commit(tx);
error = dmu_free_long_range(zv->zv_objset, ZVOL_OBJ, offset,
length);
Expand Down Expand Up @@ -475,7 +475,7 @@ zvol_replay_write(void *arg1, void *arg2, boolean_t byteswap)
dmu_tx_abort(tx);
} else {
dmu_write(os, ZVOL_OBJ, offset, length, data, tx);
zil_replaying(zv->zv_zilog, tx);
(void) zil_replaying(zv->zv_zilog, tx);
dmu_tx_commit(tx);
}

Expand Down

0 comments on commit e5a86df

Please sign in to comment.