glusterfs

Форк
0
/
glusterd-gfproxyd-svc.c 
450 строк · 13.3 Кб
1
/*
2
   Copyright (c) 2014 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 <glusterfs/globals.h>
12
#include <glusterfs/run.h>
13
#include "glusterd-utils.h"
14
#include "glusterd-volgen.h"
15
#include "glusterd-gfproxyd-svc.h"
16
#include "glusterd-messages.h"
17
#include "glusterd-svc-helper.h"
18
#include "glusterd-svc-mgmt.h"
19
#include "glusterd-gfproxyd-svc-helper.h"
20
#include <glusterfs/syscall.h>
21

22
void
23
glusterd_gfproxydsvc_build(glusterd_svc_t *svc)
24
{
25
    svc->manager = glusterd_gfproxydsvc_manager;
26
    svc->start = glusterd_gfproxydsvc_start;
27
    svc->stop = glusterd_gfproxydsvc_stop;
28
    svc->reconfigure = glusterd_gfproxydsvc_reconfigure;
29
}
30

31
int
32
glusterd_gfproxydsvc_stop(glusterd_svc_t *svc, int sig)
33
{
34
    glusterd_volinfo_t *volinfo = NULL;
35
    int ret = 0;
36

37
    ret = glusterd_svc_stop(svc, sig);
38
    if (ret)
39
        goto out;
40

41
    volinfo = glusterd_gfproxyd_volinfo_from_svc(svc);
42
    volinfo->gfproxyd.port = 0;
43

44
out:
45
    return ret;
46
}
47

48
int
49
glusterd_gfproxydsvc_init(glusterd_volinfo_t *volinfo)
50
{
51
    int ret = -1;
52
    char rundir[PATH_MAX] = {
53
        0,
54
    };
55
    char sockpath[PATH_MAX] = {
56
        0,
57
    };
58
    char pidfile[PATH_MAX] = {
59
        0,
60
    };
61
    char volfile[PATH_MAX] = {
62
        0,
63
    };
64
    char logdir[PATH_MAX] = {
65
        0,
66
    };
67
    char logfile[PATH_MAX] = {
68
        0,
69
    };
70
    char volfileid[256] = {0};
71
    glusterd_svc_t *svc = NULL;
72
    glusterd_conf_t *priv = NULL;
73
    glusterd_conn_notify_t notify = NULL;
74
    xlator_t *this = THIS;
75
    char *volfileserver = NULL;
76
    int32_t len = 0;
77

78
    priv = this->private;
79
    GF_VALIDATE_OR_GOTO(this->name, priv, out);
80

81
    svc = &(volinfo->gfproxyd.svc);
82

83
    ret = snprintf(svc->name, sizeof(svc->name), "%s", gfproxyd_svc_name);
84
    if (ret < 0)
85
        goto out;
86

87
    notify = glusterd_svc_common_rpc_notify;
88

89
    glusterd_svc_build_gfproxyd_rundir(volinfo, rundir, sizeof(rundir));
90
    glusterd_svc_create_rundir(rundir);
91

92
    /* Initialize the connection mgmt */
93
    glusterd_svc_build_gfproxyd_socket_filepath(volinfo, sockpath,
94
                                                sizeof(sockpath));
95
    ret = glusterd_conn_init(&(svc->conn), sockpath, 600, notify);
96
    if (ret)
97
        goto out;
98

99
    /* Initialize the process mgmt */
100
    glusterd_svc_build_gfproxyd_pidfile(volinfo, pidfile, sizeof(pidfile));
101
    glusterd_svc_build_gfproxyd_volfile_path(volinfo, volfile, sizeof(volfile));
102
    glusterd_svc_build_gfproxyd_logdir(logdir, volinfo->volname,
103
                                       sizeof(logdir));
104
    ret = mkdir_p(logdir, 0755, _gf_true);
105
    if ((ret == -1) && (EEXIST != errno)) {
106
        gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_CREATE_DIR_FAILED,
107
               "Unable to create logdir %s", logdir);
108
        goto out;
109
    }
110
    glusterd_svc_build_gfproxyd_logfile(logfile, logdir, sizeof(logfile));
111
    len = snprintf(volfileid, sizeof(volfileid), "gfproxyd/%s",
112
                   volinfo->volname);
113
    if ((len < 0) || (len >= sizeof(volfileid))) {
114
        ret = -1;
115
        goto out;
116
    }
117

118
    if (dict_get_str(this->options, "transport.socket.bind-address",
119
                     &volfileserver) != 0) {
120
        volfileserver = "localhost";
121
    }
122
    ret = glusterd_proc_init(&(svc->proc), gfproxyd_svc_name, pidfile, logdir,
123
                             logfile, volfile, volfileid, volfileserver);
124

125
out:
126
    gf_msg_debug(this->name, 0, "Returning %d", ret);
127
    return ret;
128
}
129

130
static int
131
glusterd_gfproxydsvc_create_volfile(glusterd_volinfo_t *volinfo)
132
{
133
    int ret = -1;
134
    xlator_t *this = THIS;
135

136
    ret = glusterd_generate_gfproxyd_volfile(volinfo);
137
    if (ret) {
138
        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLFILE_CREATE_FAIL,
139
               "Failed to create volfile");
140
    }
141

142
    gf_msg_debug(this->name, 0, "Returning %d", ret);
143

144
    return ret;
145
}
146

147
int
148
glusterd_gfproxydsvc_manager(glusterd_svc_t *svc, void *data, int flags)
149
{
150
    int ret = -1;
151
    glusterd_volinfo_t *volinfo = NULL;
152
    xlator_t *this = THIS;
153

154
    volinfo = data;
155
    GF_VALIDATE_OR_GOTO(this->name, data, out);
156

157
    if (!svc->inited) {
158
        ret = glusterd_gfproxydsvc_init(volinfo);
159
        if (ret) {
160
            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_FAILED_INIT_QUOTASVC,
161
                   "Failed to init "
162
                   "gfproxyd service");
163
            goto out;
164
        } else {
165
            svc->inited = _gf_true;
166
            gf_msg_debug(this->name, 0,
167
                         "gfproxyd service "
168
                         "initialized");
169
        }
170
    }
171

172
    ret = glusterd_is_gfproxyd_enabled(volinfo);
173
    if (ret == -1) {
174
        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLINFO_GET_FAIL,
175
               "Failed to read volume "
176
               "options");
177
        goto out;
178
    }
179

180
    if (ret) {
181
        if (!glusterd_is_volume_started(volinfo)) {
182
            if (glusterd_proc_is_running(&svc->proc)) {
183
                ret = svc->stop(svc, SIGTERM);
184
                if (ret)
185
                    gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_STOP_FAIL,
186
                           "Couldn't stop gfproxyd for "
187
                           "volume: %s",
188
                           volinfo->volname);
189
            } else {
190
                /* Since gfproxyd is not running set ret to 0 */
191
                ret = 0;
192
            }
193
            goto out;
194
        }
195

196
        ret = glusterd_gfproxydsvc_create_volfile(volinfo);
197
        if (ret) {
198
            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_CREATE_FAIL,
199
                   "Couldn't create "
200
                   "gfroxyd volfile for volume: %s",
201
                   volinfo->volname);
202
            goto out;
203
        }
204
        ret = svc->stop(svc, SIGTERM);
205
        if (ret) {
206
            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_START_FAIL,
207
                   "Couldn't stop "
208
                   "gfproxyd for volume: %s",
209
                   volinfo->volname);
210
            goto out;
211
        }
212

213
        ret = svc->start(svc, flags);
214
        if (ret) {
215
            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_START_FAIL,
216
                   "Couldn't start "
217
                   "gfproxyd for volume: %s",
218
                   volinfo->volname);
219
            goto out;
220
        }
221

222
        glusterd_volinfo_ref(volinfo);
223
        ret = glusterd_conn_connect(&(svc->conn));
224
        if (ret) {
225
            glusterd_volinfo_unref(volinfo);
226
            volinfo = NULL;
227
            goto out;
228
        }
229

230
    } else if (glusterd_proc_is_running(&svc->proc)) {
231
        ret = svc->stop(svc, SIGTERM);
232
        if (ret) {
233
            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_STOP_FAIL,
234
                   "Couldn't stop gfproxyd for volume: %s", volinfo->volname);
235
            goto out;
236
        }
237
    }
238

239
out:
240
    if (ret) {
241
        if (volinfo) {
242
            gf_event(EVENT_SVC_MANAGER_FAILED, "volume=%s;svc_name=%s",
243
                     volinfo->volname, svc->name);
244
        }
245
    }
246

247
    gf_msg_debug("glusterd", 0, "Returning %d", ret);
248

249
    return ret;
250
}
251

252
int
253
glusterd_gfproxydsvc_start(glusterd_svc_t *svc, int flags)
254
{
255
    int ret = -1;
256
    runner_t runner = {
257
        0,
258
    };
259
    glusterd_conf_t *priv = NULL;
260
    xlator_t *this = THIS;
261
    char valgrind_logfile[PATH_MAX] = {0};
262
    int gfproxyd_port = 0;
263
    char msg[1024] = {
264
        0,
265
    };
266
    char gfproxyd_id[PATH_MAX] = {
267
        0,
268
    };
269
    glusterd_volinfo_t *volinfo = NULL;
270
    char *localtime_logging = NULL;
271
    int32_t len = 0;
272

273
    priv = this->private;
274
    GF_VALIDATE_OR_GOTO(this->name, priv, out);
275

276
    volinfo = glusterd_gfproxyd_volinfo_from_svc(svc);
277
    if (!volinfo)
278
        goto out;
279

280
    ret = sys_access(svc->proc.volfile, F_OK);
281
    if (ret) {
282
        gf_msg(this->name, GF_LOG_DEBUG, 0, GD_MSG_VOLINFO_GET_FAIL,
283
               "gfproxyd Volfile %s is not present", svc->proc.volfile);
284
        ret = glusterd_gfproxydsvc_create_volfile(volinfo);
285
        if (ret) {
286
            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLFILE_CREATE_FAIL,
287
                   "Couldn't create "
288
                   "gfproxyd volfile for volume: %s",
289
                   volinfo->volname);
290
            goto out;
291
        }
292
    }
293
    runinit(&runner);
294

295
    if (this->ctx->cmd_args.vgtool != _gf_none) {
296
        len = snprintf(valgrind_logfile, PATH_MAX, "%s/valgrind-%s",
297
                       svc->proc.logdir, svc->proc.logfile);
298
        if ((len < 0) || (len >= PATH_MAX)) {
299
            ret = -1;
300
            goto out;
301
        }
302

303
        if (this->ctx->cmd_args.vgtool == _gf_memcheck)
304
            runner_add_args(&runner, "valgrind", "--leak-check=full",
305
                            "--trace-children=yes", "--track-origins=yes",
306
                            NULL);
307
        else
308
            runner_add_args(&runner, "valgrind", "--tool=drd", NULL);
309

310
        runner_argprintf(&runner, "--log-file=%s", valgrind_logfile);
311
    }
312

313
    snprintf(gfproxyd_id, sizeof(gfproxyd_id), "gfproxyd-%s", volinfo->volname);
314
    runner_add_args(&runner, SBIN_DIR "/glusterfsd", "-s",
315
                    svc->proc.volfileserver, "--volfile-id",
316
                    svc->proc.volfileid, "-p", svc->proc.pidfile, "-l",
317
                    svc->proc.logfile, "--brick-name", gfproxyd_id, "-S",
318
                    svc->conn.sockpath, NULL);
319

320
    if (volinfo->memory_accounting)
321
        runner_add_arg(&runner, "--mem-accounting");
322
    if (dict_get_str(priv->opts, GLUSTERD_LOCALTIME_LOGGING_KEY,
323
                     &localtime_logging) == 0) {
324
        if (strcmp(localtime_logging, "enable") == 0)
325
            runner_add_arg(&runner, "--localtime-logging");
326
    }
327

328
    gfproxyd_port = pmap_assign_port(this, volinfo->gfproxyd.port, gfproxyd_id);
329
    volinfo->gfproxyd.port = gfproxyd_port;
330

331
    runner_add_arg(&runner, "--brick-port");
332
    runner_argprintf(&runner, "%d", gfproxyd_port);
333
    runner_add_arg(&runner, "--xlator-option");
334
    runner_argprintf(&runner, "%s-server.listen-port=%d", volinfo->volname,
335
                     gfproxyd_port);
336

337
    snprintf(msg, sizeof(msg), "Starting the gfproxyd service for volume %s",
338
             volinfo->volname);
339
    runner_log(&runner, this->name, GF_LOG_DEBUG, msg);
340

341
    if (flags == PROC_START_NO_WAIT) {
342
        ret = runner_run_nowait(&runner);
343
    } else {
344
        synclock_unlock(&priv->big_lock);
345
        {
346
            ret = runner_run(&runner);
347
        }
348
        synclock_lock(&priv->big_lock);
349
    }
350

351
out:
352
    return ret;
353
}
354

355
int
356
glusterd_gfproxydsvc_restart(void)
357
{
358
    glusterd_volinfo_t *volinfo = NULL;
359
    glusterd_volinfo_t *tmp = NULL;
360
    int ret = -1;
361
    xlator_t *this = THIS;
362
    glusterd_conf_t *conf = NULL;
363
    glusterd_svc_t *svc = NULL;
364

365
    conf = this->private;
366
    GF_VALIDATE_OR_GOTO(this->name, conf, out);
367

368
    cds_list_for_each_entry_safe(volinfo, tmp, &conf->volumes, vol_list)
369
    {
370
        /* Start per volume gfproxyd svc */
371
        if (volinfo->status == GLUSTERD_STATUS_STARTED) {
372
            svc = &(volinfo->gfproxyd.svc);
373
            ret = svc->manager(svc, volinfo, PROC_START_NO_WAIT);
374
            if (ret) {
375
                gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_START_FAIL,
376
                       "Couldn't resolve gfproxyd for "
377
                       "vol: %s on restart",
378
                       volinfo->volname);
379
                gf_event(EVENT_SVC_MANAGER_FAILED, "volume=%s;svc_name=%s",
380
                         volinfo->volname, svc->name);
381
                goto out;
382
            }
383
        }
384
    }
385
out:
386
    return ret;
387
}
388

389
int
390
glusterd_gfproxydsvc_reconfigure(glusterd_volinfo_t *volinfo)
391
{
392
    int ret = -1;
393
    gf_boolean_t identical = _gf_false;
394

395
    if (!volinfo->gfproxyd.svc.inited)
396
        goto manager;
397

398
    if (!glusterd_is_gfproxyd_enabled(volinfo))
399
        goto manager;
400
    else if (!glusterd_proc_is_running(&volinfo->gfproxyd.svc.proc))
401
        goto manager;
402

403
    /*
404
     * Check both OLD and NEW volfiles, if they are SAME by size
405
     * and cksum i.e. "character-by-character". If YES, then
406
     * NOTHING has been changed, just return.
407
     */
408
    ret = glusterd_svc_check_gfproxyd_volfile_identical(
409
        volinfo->gfproxyd.svc.name, volinfo, &identical);
410
    if (ret)
411
        goto out;
412

413
    if (identical) {
414
        ret = 0;
415
        goto out;
416
    }
417

418
    /*
419
     * They are not identical. Find out if the topology is changed
420
     * OR just the volume options. If just the options which got
421
     * changed, then inform the xlator to reconfigure the options.
422
     */
423
    identical = _gf_false; /* RESET the FLAG */
424
    ret = glusterd_svc_check_gfproxyd_topology_identical(
425
        volinfo->gfproxyd.svc.name, volinfo, &identical);
426
    if (ret)
427
        goto out;
428

429
    /* Topology is not changed, but just the options. But write the
430
     * options to gfproxyd volfile, so that gfproxyd will be reconfigured.
431
     */
432
    if (identical) {
433
        ret = glusterd_gfproxydsvc_create_volfile(volinfo);
434
        if (ret == 0) { /* Only if above PASSES */
435
            ret = glusterd_fetchspec_notify(THIS);
436
        }
437
        goto out;
438
    }
439
manager:
440
    /*
441
     * gfproxyd volfile's topology has been changed. gfproxyd server needs
442
     * to be RESTARTED to ACT on the changed volfile.
443
     */
444
    ret = volinfo->gfproxyd.svc.manager(&(volinfo->gfproxyd.svc), volinfo,
445
                                        PROC_START_NO_WAIT);
446

447
out:
448
    gf_msg_debug("glusterd", 0, "Returning %d", ret);
449
    return ret;
450
}
451

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

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

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

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