diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2019-05-07 13:33:30 +0300 |
---|---|---|
committer | Atin Mukherjee <amukherj@redhat.com> | 2019-05-23 09:56:00 +0000 |
commit | 3b5eb592f543e15e16996ba83182635a4e07ab74 (patch) | |
tree | 2bed82ad4ce994b4f43aabccfd9462d87a3833f9 /xlators/mgmt | |
parent | e1d2ce02135819898f166de9d9903404eb812046 (diff) |
glusterd-utils.c: skip checksum when possible.
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>
Diffstat (limited to 'xlators/mgmt')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index b8caa782008..d46d01fc522 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -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," @@ -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", @@ -2781,21 +2777,18 @@ 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; @@ -2803,8 +2796,11 @@ glusterd_volume_compute_cksum(glusterd_volinfo_t *volinfo, char *cksum_path, } 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; |