glusterfs

Форк
0
/
glusterd-tierd-svc-helper.c 
204 строки · 5.2 Кб
1
/*
2
   Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
3
   This file is part of GlusterFS.
4

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.
9
*/
10

11
#include "glusterd.h"
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"
17

18
void
19
glusterd_svc_build_tierd_rundir(glusterd_volinfo_t *volinfo, char *path,
20
                                int path_len)
21
{
22
    char workdir[PATH_MAX] = {
23
        0,
24
    };
25
    glusterd_conf_t *priv = THIS->private;
26

27
    GLUSTERD_GET_TIER_DIR(workdir, volinfo, priv);
28

29
    snprintf(path, path_len, "%s/run", workdir);
30
}
31

32
void
33
glusterd_svc_build_tierd_socket_filepath(glusterd_volinfo_t *volinfo,
34
                                         char *path, int path_len)
35
{
36
    char sockfilepath[PATH_MAX] = {
37
        0,
38
    };
39
    char rundir[PATH_MAX] = {
40
        0,
41
    };
42
    int32_t len = 0;
43

44
    glusterd_svc_build_tierd_rundir(volinfo, rundir, sizeof(rundir));
45
    len = snprintf(sockfilepath, sizeof(sockfilepath), "%s/run-%s", rundir,
46
                   uuid_utoa(MY_UUID));
47
    if ((len < 0) || (len >= sizeof(sockfilepath))) {
48
        sockfilepath[0] = 0;
49
    }
50

51
    glusterd_set_socket_filepath(sockfilepath, path, path_len);
52
}
53

54
void
55
glusterd_svc_build_tierd_pidfile(glusterd_volinfo_t *volinfo, char *path,
56
                                 int path_len)
57
{
58
    char rundir[PATH_MAX] = {
59
        0,
60
    };
61

62
    glusterd_svc_build_tierd_rundir(volinfo, rundir, sizeof(rundir));
63

64
    snprintf(path, path_len, "%s/%s-tierd.pid", rundir, volinfo->volname);
65
}
66

67
void
68
glusterd_svc_build_tierd_volfile_path(glusterd_volinfo_t *volinfo, char *path,
69
                                      int path_len)
70
{
71
    char workdir[PATH_MAX] = {
72
        0,
73
    };
74
    glusterd_conf_t *priv = THIS->private;
75

76
    GLUSTERD_GET_VOLUME_DIR(workdir, volinfo, priv);
77

78
    snprintf(path, path_len, "%s/%s-tierd.vol", workdir, volinfo->volname);
79
}
80

81
void
82
glusterd_svc_build_tierd_logdir(char *logdir, char *volname, size_t len)
83
{
84
    glusterd_conf_t *conf = THIS->private;
85
    snprintf(logdir, len, "%s/tier/%s", priv->logdir, volname);
86
}
87

88
void
89
glusterd_svc_build_tierd_logfile(char *logfile, char *logdir, size_t len)
90
{
91
    snprintf(logfile, len, "%s/tierd.log", logdir);
92
}
93

94
int
95
glusterd_svc_check_tier_volfile_identical(char *svc_name,
96
                                          glusterd_volinfo_t *volinfo,
97
                                          gf_boolean_t *identical)
98
{
99
    char orgvol[PATH_MAX] = {
100
        0,
101
    };
102
    char *tmpvol = NULL;
103
    xlator_t *this = THIS;
104
    int ret = -1;
105
    int need_unlink = 0;
106
    int tmp_fd = -1;
107

108
    GF_VALIDATE_OR_GOTO(this->name, identical, out);
109

110
    glusterd_svc_build_tierd_volfile_path(volinfo, orgvol, sizeof(orgvol));
111

112
    ret = gf_asprintf(&tmpvol, "/tmp/g%s-XXXXXX", svc_name);
113
    if (ret < 0) {
114
        goto out;
115
    }
116

117
    /* coverity[SECURE_TEMP] mkstemp uses 0600 as the mode and is safe */
118
    tmp_fd = mkstemp(tmpvol);
119
    if (tmp_fd < 0) {
120
        gf_msg(this->name, GF_LOG_WARNING, errno, GD_MSG_FILE_OP_FAILED,
121
               "Unable to create temp file"
122
               " %s:(%s)",
123
               tmpvol, strerror(errno));
124
        ret = -1;
125
        goto out;
126
    }
127

128
    need_unlink = 1;
129
    ret = build_rebalance_volfile(volinfo, tmpvol, NULL);
130
    if (ret)
131
        goto out;
132

133
    ret = glusterd_check_files_identical(orgvol, tmpvol, identical);
134
    if (ret)
135
        goto out;
136

137
out:
138
    if (need_unlink)
139
        sys_unlink(tmpvol);
140

141
    if (tmpvol != NULL)
142
        GF_FREE(tmpvol);
143

144
    if (tmp_fd >= 0)
145
        sys_close(tmp_fd);
146

147
    return ret;
148
}
149

150
int
151
glusterd_svc_check_tier_topology_identical(char *svc_name,
152
                                           glusterd_volinfo_t *volinfo,
153
                                           gf_boolean_t *identical)
154
{
155
    char orgvol[PATH_MAX] = {
156
        0,
157
    };
158
    char *tmpvol = NULL;
159
    glusterd_conf_t *conf = NULL;
160
    xlator_t *this = THIS;
161
    int ret = -1;
162
    int tmpclean = 0;
163
    int tmpfd = -1;
164

165
    if ((!identical) || (!this->private))
166
        goto out;
167

168
    conf = this->private;
169
    GF_VALIDATE_OR_GOTO(this->name, conf, out);
170

171
    glusterd_svc_build_tierd_volfile_path(volinfo, orgvol, sizeof(orgvol));
172

173
    ret = gf_asprintf(&tmpvol, "/tmp/g%s-XXXXXX", svc_name);
174
    if (ret < 0) {
175
        goto out;
176
    }
177

178
    /* coverity[SECURE_TEMP] mkstemp uses 0600 as the mode and is safe */
179
    tmpfd = mkstemp(tmpvol);
180
    if (tmpfd < 0) {
181
        gf_msg(this->name, GF_LOG_WARNING, errno, GD_MSG_FILE_OP_FAILED,
182
               "Unable to create temp file"
183
               " %s:(%s)",
184
               tmpvol, strerror(errno));
185
        ret = -1;
186
        goto out;
187
    }
188

189
    tmpclean = 1; /* SET the flag to unlink() tmpfile */
190
    ret = build_rebalance_volfile(volinfo, tmpvol, NULL);
191
    if (ret)
192
        goto out;
193

194
    /* Compare the topology of volfiles */
195
    ret = glusterd_check_topology_identical(orgvol, tmpvol, identical);
196
out:
197
    if (tmpfd >= 0)
198
        sys_close(tmpfd);
199
    if (tmpclean)
200
        sys_unlink(tmpvol);
201
    if (tmpvol != NULL)
202
        GF_FREE(tmpvol);
203
    return ret;
204
}
205

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.