Skip to content

Commit

Permalink
glusterd-utils.c: skip checksum when possible.
Browse files Browse the repository at this point in the history
We only need to calculate and write the checksum in case of
!is_quota_conf .

Align the code in accordance.
Also, use a smaller buffer (to write few chars).

Change-Id: I40c83ce10447df77ff9975d314d768ec2c0087c2
updates: bz#1193929
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
  • Loading branch information
Yaniv Kaul authored and Atin Mukherjee committed May 23, 2019
1 parent e1d2ce0 commit 3b5eb59
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions xlators/mgmt/glusterd/src/glusterd-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2728,20 +2728,16 @@ glusterd_volume_compute_cksum(glusterd_volinfo_t *volinfo, char *cksum_path,
int fd = -1;
int sort_fd = 0;
char sort_filepath[PATH_MAX] = "";
char *cksum_path_final = NULL;
char buf[4096] = "";
char buf[32];
gf_boolean_t unlink_sortfile = _gf_false;
glusterd_conf_t *priv = NULL;
xlator_t *this = NULL;
glusterd_conf_t *priv = THIS->private;
xlator_t *this = THIS;
mode_t orig_umask = 0;

GF_ASSERT(volinfo);
this = THIS;
priv = THIS->private;
GF_ASSERT(priv);

fd = open(cksum_path, O_RDWR | O_APPEND | O_CREAT | O_TRUNC, 0600);

if (-1 == fd) {
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED,
"Unable to open %s,"
Expand All @@ -2758,7 +2754,7 @@ glusterd_volume_compute_cksum(glusterd_volinfo_t *volinfo, char *cksum_path,
orig_umask = umask(S_IRWXG | S_IRWXO);
sort_fd = mkstemp(sort_filepath);
umask(orig_umask);
if (sort_fd < 0) {
if (-1 == sort_fd) {
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED,
"Could not generate "
"temp file, reason: %s for volume: %s",
Expand All @@ -2781,30 +2777,30 @@ glusterd_volume_compute_cksum(glusterd_volinfo_t *volinfo, char *cksum_path,
ret = sys_close(sort_fd);
if (ret)
goto out;
}

cksum_path_final = is_quota_conf ? filepath : sort_filepath;
ret = get_checksum_for_path(sort_filepath, &cksum, priv->op_version);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_CKSUM_GET_FAIL,
"unable to get "
"checksum for path: %s",
sort_filepath);
goto out;
}

ret = get_checksum_for_path(cksum_path_final, &cksum, priv->op_version);
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_CKSUM_GET_FAIL,
"unable to get "
"checksum for path: %s",
cksum_path_final);
goto out;
}
if (!is_quota_conf) {
snprintf(buf, sizeof(buf), "%s=%u\n", "info", cksum);
ret = sys_write(fd, buf, strlen(buf));
ret = snprintf(buf, sizeof(buf), "info=%u\n", cksum);
ret = sys_write(fd, buf, ret);
if (ret <= 0) {
ret = -1;
goto out;
}
}

ret = get_checksum_for_file(fd, &cksum, priv->op_version);
if (ret)
if (ret) {
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_CKSUM_GET_FAIL,
"unable to get checksum for path: %s", filepath);
goto out;
}

*cs = cksum;

Expand Down

0 comments on commit 3b5eb59

Please sign in to comment.