2
Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
3
This file is part of GlusterFS.
5
This file is licensed to you under your choice of the GNU Lesser
6
General Public License, version 3 or any later version (LGPLv3 or
7
later), or the GNU General Public License, version 2 (GPLv2), in all
8
cases as published by the Free Software Foundation.
12
#include "glusterd-utils.h"
13
#include "glusterd-tierd-svc-helper.h"
14
#include "glusterd-messages.h"
15
#include <glusterfs/syscall.h>
16
#include "glusterd-volgen.h"
19
glusterd_svc_build_tierd_rundir(glusterd_volinfo_t *volinfo, char *path,
22
char workdir[PATH_MAX] = {
25
glusterd_conf_t *priv = THIS->private;
27
GLUSTERD_GET_TIER_DIR(workdir, volinfo, priv);
29
snprintf(path, path_len, "%s/run", workdir);
33
glusterd_svc_build_tierd_socket_filepath(glusterd_volinfo_t *volinfo,
34
char *path, int path_len)
36
char sockfilepath[PATH_MAX] = {
39
char rundir[PATH_MAX] = {
44
glusterd_svc_build_tierd_rundir(volinfo, rundir, sizeof(rundir));
45
len = snprintf(sockfilepath, sizeof(sockfilepath), "%s/run-%s", rundir,
47
if ((len < 0) || (len >= sizeof(sockfilepath))) {
51
glusterd_set_socket_filepath(sockfilepath, path, path_len);
55
glusterd_svc_build_tierd_pidfile(glusterd_volinfo_t *volinfo, char *path,
58
char rundir[PATH_MAX] = {
62
glusterd_svc_build_tierd_rundir(volinfo, rundir, sizeof(rundir));
64
snprintf(path, path_len, "%s/%s-tierd.pid", rundir, volinfo->volname);
68
glusterd_svc_build_tierd_volfile_path(glusterd_volinfo_t *volinfo, char *path,
71
char workdir[PATH_MAX] = {
74
glusterd_conf_t *priv = THIS->private;
76
GLUSTERD_GET_VOLUME_DIR(workdir, volinfo, priv);
78
snprintf(path, path_len, "%s/%s-tierd.vol", workdir, volinfo->volname);
82
glusterd_svc_build_tierd_logdir(char *logdir, char *volname, size_t len)
84
glusterd_conf_t *conf = THIS->private;
85
snprintf(logdir, len, "%s/tier/%s", priv->logdir, volname);
89
glusterd_svc_build_tierd_logfile(char *logfile, char *logdir, size_t len)
91
snprintf(logfile, len, "%s/tierd.log", logdir);
95
glusterd_svc_check_tier_volfile_identical(char *svc_name,
96
glusterd_volinfo_t *volinfo,
97
gf_boolean_t *identical)
99
char orgvol[PATH_MAX] = {
103
xlator_t *this = THIS;
108
GF_VALIDATE_OR_GOTO(this->name, identical, out);
110
glusterd_svc_build_tierd_volfile_path(volinfo, orgvol, sizeof(orgvol));
112
ret = gf_asprintf(&tmpvol, "/tmp/g%s-XXXXXX", svc_name);
117
/* coverity[SECURE_TEMP] mkstemp uses 0600 as the mode and is safe */
118
tmp_fd = mkstemp(tmpvol);
120
gf_msg(this->name, GF_LOG_WARNING, errno, GD_MSG_FILE_OP_FAILED,
121
"Unable to create temp file"
123
tmpvol, strerror(errno));
129
ret = build_rebalance_volfile(volinfo, tmpvol, NULL);
133
ret = glusterd_check_files_identical(orgvol, tmpvol, identical);
151
glusterd_svc_check_tier_topology_identical(char *svc_name,
152
glusterd_volinfo_t *volinfo,
153
gf_boolean_t *identical)
155
char orgvol[PATH_MAX] = {
159
glusterd_conf_t *conf = NULL;
160
xlator_t *this = THIS;
165
if ((!identical) || (!this->private))
168
conf = this->private;
169
GF_VALIDATE_OR_GOTO(this->name, conf, out);
171
glusterd_svc_build_tierd_volfile_path(volinfo, orgvol, sizeof(orgvol));
173
ret = gf_asprintf(&tmpvol, "/tmp/g%s-XXXXXX", svc_name);
178
/* coverity[SECURE_TEMP] mkstemp uses 0600 as the mode and is safe */
179
tmpfd = mkstemp(tmpvol);
181
gf_msg(this->name, GF_LOG_WARNING, errno, GD_MSG_FILE_OP_FAILED,
182
"Unable to create temp file"
184
tmpvol, strerror(errno));
189
tmpclean = 1; /* SET the flag to unlink() tmpfile */
190
ret = build_rebalance_volfile(volinfo, tmpvol, NULL);
194
/* Compare the topology of volfiles */
195
ret = glusterd_check_topology_identical(orgvol, tmpvol, identical);