Skip to content

Commit

Permalink
logging: Avoiding a call to strerror while logging
Browse files Browse the repository at this point in the history
As strerror is already printed if there is an errnum
avoiding a redundant call to it while logging.

Fixes: gluster#782

Change-Id: I1cde45342e439f821e2d19ca8d90e54906f7a5b2
Signed-off-by: Rinku Kothiya <rkothiya@redhat.com>
  • Loading branch information
Rinku Kothiya committed Feb 18, 2021
1 parent 1ce8e8f commit caf6906
Show file tree
Hide file tree
Showing 20 changed files with 119 additions and 184 deletions.
24 changes: 6 additions & 18 deletions libglusterfs/src/common-utils.c
Expand Up @@ -4722,10 +4722,8 @@ recursive_rmdir(const char *delete_path)

dir = sys_opendir(delete_path);
if (!dir) {
gf_msg_debug(this->name, 0,
"Failed to open directory %s. "
"Reason : %s",
delete_path, strerror(errno));
gf_msg_debug(this->name, errno, "Failed to open directory %s.",
delete_path);
ret = 0;
goto out;
}
Expand All @@ -4736,10 +4734,7 @@ recursive_rmdir(const char *delete_path)
snprintf(path, PATH_MAX, "%s/%s", delete_path, entry->d_name);
ret = sys_lstat(path, &st);
if (ret == -1) {
gf_msg_debug(this->name, 0,
"Failed to stat entry %s :"
" %s",
path, strerror(errno));
gf_msg_debug(this->name, errno, "Failed to stat entry %s", path);
(void)sys_closedir(dir);
goto out;
}
Expand All @@ -4750,10 +4745,7 @@ recursive_rmdir(const char *delete_path)
ret = sys_unlink(path);

if (ret) {
gf_msg_debug(this->name, 0,
" Failed to remove %s. "
"Reason : %s",
path, strerror(errno));
gf_msg_debug(this->name, errno, " Failed to remove %s. ", path);
}

gf_msg_debug(this->name, 0, "%s %s",
Expand All @@ -4762,16 +4754,12 @@ recursive_rmdir(const char *delete_path)

ret = sys_closedir(dir);
if (ret) {
gf_msg_debug(this->name, 0,
"Failed to close dir %s. Reason :"
" %s",
delete_path, strerror(errno));
gf_msg_debug(this->name, errno, "Failed to close dir %s", delete_path);
}

ret = sys_rmdir(delete_path);
if (ret) {
gf_msg_debug(this->name, 0, "Failed to rmdir: %s,err: %s", delete_path,
strerror(errno));
gf_msg_debug(this->name, errno, "Failed to rmdir: %s", delete_path);
}

out:
Expand Down
4 changes: 2 additions & 2 deletions xlators/cluster/dht/src/dht-inode-write.c
Expand Up @@ -59,8 +59,8 @@ dht_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int op_ret,
if (op_ret == -1 && !dht_inode_missing(op_errno)) {
local->op_errno = op_errno;
local->op_ret = -1;
gf_msg_debug(this->name, 0, "subvolume %s returned -1 (%s)", prev->name,
strerror(op_errno));
gf_msg_debug(this->name, op_errno, "subvolume %s returned -1",
prev->name);
goto out;
}

Expand Down
12 changes: 6 additions & 6 deletions xlators/cluster/dht/src/dht-rename.c
Expand Up @@ -1210,8 +1210,8 @@ dht_rename_link_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
prev = cookie;

if (op_ret == -1) {
gf_msg_debug(this->name, 0, "link/file on %s failed (%s)", prev->name,
strerror(op_errno));
gf_msg_debug(this->name, op_errno, "link/file on %s failed",
prev->name);
local->op_ret = -1;
local->op_errno = op_errno;
local->added_link = _gf_false;
Expand Down Expand Up @@ -1248,8 +1248,8 @@ dht_rename_linkto_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
src_cached = local->src_cached;

if (op_ret == -1) {
gf_msg_debug(this->name, 0, "link/file on %s failed (%s)", prev->name,
strerror(op_errno));
gf_msg_debug(this->name, op_errno, "link/file on %s failed",
prev->name);
local->op_ret = -1;
local->op_errno = op_errno;
}
Expand Down Expand Up @@ -1298,8 +1298,8 @@ dht_rename_unlink_links_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
prev = cookie;

if ((op_ret == -1) && (op_errno != ENOENT)) {
gf_msg_debug(this->name, 0, "unlink of %s on %s failed (%s)",
local->loc2.path, prev->name, strerror(op_errno));
gf_msg_debug(this->name, op_errno, "unlink of %s on %s failed ",
local->loc2.path, prev->name);
local->op_ret = -1;
local->op_errno = op_errno;
}
Expand Down
39 changes: 18 additions & 21 deletions xlators/cluster/ec/src/ec-heal.c
Expand Up @@ -303,11 +303,10 @@ ec_heal_writev_cbk(call_frame_t *frame, void *cookie, xlator_t *this,

ec_trace("WRITE_CBK", cookie, "ret=%d, errno=%d", op_ret, op_errno);

gf_msg_debug(fop->xl->name, 0,
"%s: write op_ret %d, op_errno %s"
gf_msg_debug(fop->xl->name, op_errno,
"%s: write op_ret %d"
" at %" PRIu64,
uuid_utoa(heal->fd->inode->gfid), op_ret, strerror(op_errno),
heal->offset);
uuid_utoa(heal->fd->inode->gfid), op_ret, heal->offset);

ec_heal_update(cookie, 0);

Expand Down Expand Up @@ -337,11 +336,10 @@ ec_heal_readv_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
heal->offset, 0, iobref, NULL);
} else {
if (op_ret < 0) {
gf_msg_debug(fop->xl->name, 0,
"%s: read failed %s, failing "
gf_msg_debug(fop->xl->name, op_errno,
"%s: read failed, failing "
"to heal block at %" PRIu64,
uuid_utoa(heal->fd->inode->gfid), strerror(op_errno),
heal->offset);
uuid_utoa(heal->fd->inode->gfid), heal->offset);
heal->bad = 0;
}
heal->done = 1;
Expand Down Expand Up @@ -1118,9 +1116,8 @@ ec_delete_stale_name(dict_t *gfid_db, char *key, data_t *d, void *data)
dict_del(gfid_db, key);
out:
if (ret < 0) {
gf_msg_debug(ec->xl->name, 0, "%s/%s: heal failed %s",
uuid_utoa(name_data->parent->gfid), name_data->name,
strerror(-ret));
gf_msg_debug(ec->xl->name, -ret, "%s/%s: heal failed",
uuid_utoa(name_data->parent->gfid), name_data->name);
}
cluster_replies_wipe(replies, ec->nodes);
loc_wipe(&loc);
Expand Down Expand Up @@ -1310,8 +1307,8 @@ ec_create_name(call_frame_t *frame, ec_t *ec, inode_t *parent, char *name,
ret = 0;
out:
if (ret < 0)
gf_msg_debug(ec->xl->name, 0, "%s/%s: heal failed %s",
uuid_utoa(parent->gfid), name, strerror(-ret));
gf_msg_debug(ec->xl->name, -ret, "%s/%s: heal failed ",
uuid_utoa(parent->gfid), name);
cluster_replies_wipe(replies, ec->nodes);
loc_wipe(&loc);
loc_wipe(&srcloc);
Expand Down Expand Up @@ -1866,8 +1863,8 @@ __ec_heal_data_prepare(call_frame_t *frame, ec_t *ec, fd_t *fd,
cluster_replies_wipe(replies, ec->nodes);
cluster_replies_wipe(fstat_replies, ec->nodes);
if (ret < 0) {
gf_msg_debug(ec->xl->name, 0, "%s: heal failed %s",
uuid_utoa(fd->inode->gfid), strerror(-ret));
gf_msg_debug(ec->xl->name, -ret, "%s: heal failed ",
uuid_utoa(fd->inode->gfid));
} else {
gf_msg_debug(ec->xl->name, 0,
"%s: sources: %d, sinks: "
Expand Down Expand Up @@ -1939,8 +1936,8 @@ __ec_heal_mark_sinks(call_frame_t *frame, ec_t *ec, fd_t *fd,
if (xattrs)
dict_unref(xattrs);
if (ret < 0)
gf_msg_debug(ec->xl->name, 0, "%s: heal failed %s",
uuid_utoa(fd->inode->gfid), strerror(-ret));
gf_msg_debug(ec->xl->name, -ret, "%s: heal failed ",
uuid_utoa(fd->inode->gfid));
return ret;
}

Expand Down Expand Up @@ -2113,8 +2110,8 @@ ec_rebuild_data(call_frame_t *frame, ec_t *ec, fd_t *fd, uint64_t size,
LOCK_DESTROY(&heal->lock);
syncbarrier_destroy(heal->data);
if (ret < 0)
gf_msg_debug(ec->xl->name, 0, "%s: heal failed %s",
uuid_utoa(fd->inode->gfid), strerror(-ret));
gf_msg_debug(ec->xl->name, -ret, "%s: heal failed ",
uuid_utoa(fd->inode->gfid));
return ret;
}

Expand Down Expand Up @@ -2153,8 +2150,8 @@ __ec_heal_trim_sinks(call_frame_t *frame, ec_t *ec, fd_t *fd,
out:
cluster_replies_wipe(replies, ec->nodes);
if (ret < 0)
gf_msg_debug(ec->xl->name, 0, "%s: heal failed %s",
uuid_utoa(fd->inode->gfid), strerror(-ret));
gf_msg_debug(ec->xl->name, -ret, "%s: heal failed ",
uuid_utoa(fd->inode->gfid));
return ret;
}

Expand Down
12 changes: 4 additions & 8 deletions xlators/features/bit-rot/src/bitd/bit-rot.c
Expand Up @@ -452,10 +452,8 @@ br_log_object(xlator_t *this, char *op, uuid_t gfid, int32_t op_errno)
{
int softerror = br_object_sign_softerror(op_errno);
if (softerror) {
gf_msg_debug(this->name, 0,
"%s() failed on object %s "
"[reason: %s]",
op, uuid_utoa(gfid), strerror(op_errno));
gf_msg_debug(this->name, op_errno, "%s() failed on object %s ", op,
uuid_utoa(gfid));
} else {
gf_smsg(this->name, GF_LOG_ERROR, op_errno, BRB_MSG_OP_FAILED, "op=%s",
op, "gfid=%s", uuid_utoa(gfid), NULL);
Expand All @@ -467,10 +465,8 @@ br_log_object_path(xlator_t *this, char *op, const char *path, int32_t op_errno)
{
int softerror = br_object_sign_softerror(op_errno);
if (softerror) {
gf_msg_debug(this->name, 0,
"%s() failed on object %s "
"[reason: %s]",
op, path, strerror(op_errno));
gf_msg_debug(this->name, op_errno, "%s() failed on object %s ", op,
path);
} else {
gf_smsg(this->name, GF_LOG_ERROR, op_errno, BRB_MSG_OP_FAILED, "op=%s",
op, "path=%s", path, NULL);
Expand Down
6 changes: 3 additions & 3 deletions xlators/features/shard/src/shard.c
Expand Up @@ -5010,10 +5010,10 @@ shard_common_mknod_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
local->op_ret = op_ret;
local->op_errno = op_errno;
}
gf_msg_debug(this->name, 0,
gf_msg_debug(this->name, op_errno,
"mknod of shard %d "
"failed: %s",
shard_block_num, strerror(op_errno));
"failed",
shard_block_num);
goto done;
}

Expand Down
6 changes: 3 additions & 3 deletions xlators/features/snapview-server/src/snapview-server.c
Expand Up @@ -953,10 +953,10 @@ svs_getxattr(call_frame_t *frame, xlator_t *this, loc_t *loc, const char *name,
op_ret = -1;
op_errno = errno;
if (errno == ENODATA) {
gf_msg_debug(this->name, 0,
gf_msg_debug(this->name, errno,
"getxattr on "
"%s failed (ket: %s) with %s",
loc->path, name, strerror(errno));
"%s failed (ket: %s)",
loc->path, name);
} else {
gf_msg(this->name, GF_LOG_ERROR, op_errno,
SVS_MSG_GETXATTR_FAILED,
Expand Down
29 changes: 9 additions & 20 deletions xlators/mgmt/glusterd/src/glusterd-ganesha.c
Expand Up @@ -612,10 +612,8 @@ tear_down_cluster(gf_boolean_t run_teardown)
*/
dir = sys_opendir(CONFDIR);
if (!dir) {
gf_msg_debug(THIS->name, 0,
"Failed to open directory %s. "
"Reason : %s",
CONFDIR, strerror(errno));
gf_msg_debug(THIS->name, errno, "Failed to open directory %s. ",
CONFDIR);
ret = 0;
goto out;
}
Expand All @@ -626,10 +624,8 @@ tear_down_cluster(gf_boolean_t run_teardown)
snprintf(path, PATH_MAX, "%s/%s", CONFDIR, entry->d_name);
ret = sys_lstat(path, &st);
if (ret == -1) {
gf_msg_debug(THIS->name, 0,
"Failed to stat entry %s :"
" %s",
path, strerror(errno));
gf_msg_debug(THIS->name, errno,
"Failed to stat entry %s :", path);
goto out;
}

Expand All @@ -645,10 +641,7 @@ tear_down_cluster(gf_boolean_t run_teardown)
ret = sys_unlink(path);

if (ret) {
gf_msg_debug(THIS->name, 0,
" Failed to remove %s. "
"Reason : %s",
path, strerror(errno));
gf_msg_debug(THIS->name, errno, " Failed to remove %s. ", path);
}

gf_msg_debug(THIS->name, 0, "%s %s",
Expand All @@ -657,20 +650,16 @@ tear_down_cluster(gf_boolean_t run_teardown)

ret = sys_closedir(dir);
if (ret) {
gf_msg_debug(THIS->name, 0,
"Failed to close dir %s. Reason :"
" %s",
CONFDIR, strerror(errno));
gf_msg_debug(THIS->name, errno,
"Failed to close dir %s. Reason :", CONFDIR);
}
goto exit;
}

out:
if (dir && sys_closedir(dir)) {
gf_msg_debug(THIS->name, 0,
"Failed to close dir %s. Reason :"
" %s",
CONFDIR, strerror(errno));
gf_msg_debug(THIS->name, errno,
"Failed to close dir %s. Reason :", CONFDIR);
}
exit:
return ret;
Expand Down
2 changes: 1 addition & 1 deletion xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
Expand Up @@ -3999,7 +3999,7 @@ glusterd_restore_nfs_ganesha_file(glusterd_volinfo_t *src_vol,
if (ret) {
if (errno == ENOENT) {
ret = 0;
gf_msg_debug(this->name, 0, "%s not found", src_path);
gf_msg_debug(this->name, errno, "%s not found", src_path);
} else
gf_msg(this->name, GF_LOG_WARNING, errno, GD_MSG_FILE_OP_FAILED,
"Stat on %s failed with %s", src_path, strerror(errno));
Expand Down
12 changes: 5 additions & 7 deletions xlators/mgmt/glusterd/src/glusterd-snapshot.c
Expand Up @@ -676,8 +676,7 @@ glusterd_snapshot_backup_vol(glusterd_volinfo_t *volinfo)
/* Revert the changes in case of failure */
ret = sys_rmdir(pathname);
if (ret) {
gf_msg_debug(this->name, 0, "Failed to rmdir: %s,err: %s", pathname,
strerror(errno));
gf_msg_debug(this->name, errno, "Failed to rmdir: %s", pathname);
}

ret = sys_rename(delete_path, pathname);
Expand All @@ -689,8 +688,7 @@ glusterd_snapshot_backup_vol(glusterd_volinfo_t *volinfo)

ret = sys_rmdir(trashdir);
if (ret) {
gf_msg_debug(this->name, 0, "Failed to rmdir: %s, Reason: %s",
trashdir, strerror(errno));
gf_msg_debug(this->name, errno, "Failed to rmdir: %s", trashdir);
}
}

Expand Down Expand Up @@ -2617,10 +2615,10 @@ glusterd_do_lvm_snapshot_remove(glusterd_volinfo_t *snap_vol,
if (!ret)
break;

gf_msg_debug(this->name, 0,
gf_msg_debug(this->name, errno,
"umount failed for "
"path %s (brick: %s): %s. Retry(%d)",
mount_pt, brickinfo->path, strerror(errno), retry_count);
"path %s (brick: %s). Retry(%d)",
mount_pt, brickinfo->path, retry_count);

/*
* This used to be one second, but that wasn't long enough
Expand Down
9 changes: 4 additions & 5 deletions xlators/mgmt/glusterd/src/glusterd-utils.c
Expand Up @@ -1897,8 +1897,8 @@ glusterd_service_stop_nolock(const char *service, char *pidfile, int sig,

if (kill(pid, 0) < 0) {
ret = 0;
gf_msg_debug(this->name, 0, "%s process not running: (%d) %s", service,
pid, strerror(errno));
gf_msg_debug(this->name, errno, "%s process not running: (%d)", service,
pid);
goto out;
}
gf_msg_debug(this->name, 0,
Expand Down Expand Up @@ -7837,10 +7837,9 @@ glusterd_add_brick_detail_to_dict(glusterd_volinfo_t *volinfo,
ret = glusterd_add_inode_size_to_dict(dict, count);
out:
if (ret)
gf_msg_debug(this->name, 0,
gf_msg_debug(this->name, errno,
"Error adding brick"
" detail to dict: %s",
strerror(errno));
" detail to dict");
return ret;
}

Expand Down
5 changes: 2 additions & 3 deletions xlators/mgmt/glusterd/src/glusterd-volume-ops.c
Expand Up @@ -2690,10 +2690,9 @@ glusterd_clearlocks_create_mount(glusterd_volinfo_t *volinfo, char **mntpt)
snprintf(template, sizeof(template), "/tmp/%s.XXXXXX", volinfo->volname);
tmpl = mkdtemp(template);
if (!tmpl) {
gf_msg_debug(THIS->name, 0,
gf_msg_debug(THIS->name, errno,
"Couldn't create temporary "
"mount directory. Reason %s",
strerror(errno));
"mount directory.");
goto out;
}

Expand Down

0 comments on commit caf6906

Please sign in to comment.