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>
23
glusterd_gfproxydsvc_build(glusterd_svc_t *svc)
25
svc->manager = glusterd_gfproxydsvc_manager;
26
svc->start = glusterd_gfproxydsvc_start;
27
svc->stop = glusterd_gfproxydsvc_stop;
28
svc->reconfigure = glusterd_gfproxydsvc_reconfigure;
32
glusterd_gfproxydsvc_stop(glusterd_svc_t *svc, int sig)
34
glusterd_volinfo_t *volinfo = NULL;
37
ret = glusterd_svc_stop(svc, sig);
41
volinfo = glusterd_gfproxyd_volinfo_from_svc(svc);
42
volinfo->gfproxyd.port = 0;
49
glusterd_gfproxydsvc_init(glusterd_volinfo_t *volinfo)
52
char rundir[PATH_MAX] = {
55
char sockpath[PATH_MAX] = {
58
char pidfile[PATH_MAX] = {
61
char volfile[PATH_MAX] = {
64
char logdir[PATH_MAX] = {
67
char logfile[PATH_MAX] = {
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;
79
GF_VALIDATE_OR_GOTO(this->name, priv, out);
81
svc = &(volinfo->gfproxyd.svc);
83
ret = snprintf(svc->name, sizeof(svc->name), "%s", gfproxyd_svc_name);
87
notify = glusterd_svc_common_rpc_notify;
89
glusterd_svc_build_gfproxyd_rundir(volinfo, rundir, sizeof(rundir));
90
glusterd_svc_create_rundir(rundir);
93
glusterd_svc_build_gfproxyd_socket_filepath(volinfo, sockpath,
95
ret = glusterd_conn_init(&(svc->conn), sockpath, 600, notify);
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,
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);
110
glusterd_svc_build_gfproxyd_logfile(logfile, logdir, sizeof(logfile));
111
len = snprintf(volfileid, sizeof(volfileid), "gfproxyd/%s",
113
if ((len < 0) || (len >= sizeof(volfileid))) {
118
if (dict_get_str(this->options, "transport.socket.bind-address",
119
&volfileserver) != 0) {
120
volfileserver = "localhost";
122
ret = glusterd_proc_init(&(svc->proc), gfproxyd_svc_name, pidfile, logdir,
123
logfile, volfile, volfileid, volfileserver);
126
gf_msg_debug(this->name, 0, "Returning %d", ret);
131
glusterd_gfproxydsvc_create_volfile(glusterd_volinfo_t *volinfo)
134
xlator_t *this = THIS;
136
ret = glusterd_generate_gfproxyd_volfile(volinfo);
138
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLFILE_CREATE_FAIL,
139
"Failed to create volfile");
142
gf_msg_debug(this->name, 0, "Returning %d", ret);
148
glusterd_gfproxydsvc_manager(glusterd_svc_t *svc, void *data, int flags)
151
glusterd_volinfo_t *volinfo = NULL;
152
xlator_t *this = THIS;
155
GF_VALIDATE_OR_GOTO(this->name, data, out);
158
ret = glusterd_gfproxydsvc_init(volinfo);
160
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_FAILED_INIT_QUOTASVC,
165
svc->inited = _gf_true;
166
gf_msg_debug(this->name, 0,
172
ret = glusterd_is_gfproxyd_enabled(volinfo);
174
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLINFO_GET_FAIL,
175
"Failed to read volume "
181
if (!glusterd_is_volume_started(volinfo)) {
182
if (glusterd_proc_is_running(&svc->proc)) {
183
ret = svc->stop(svc, SIGTERM);
185
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_STOP_FAIL,
186
"Couldn't stop gfproxyd for "
196
ret = glusterd_gfproxydsvc_create_volfile(volinfo);
198
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_CREATE_FAIL,
200
"gfroxyd volfile for volume: %s",
204
ret = svc->stop(svc, SIGTERM);
206
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_START_FAIL,
208
"gfproxyd for volume: %s",
213
ret = svc->start(svc, flags);
215
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_START_FAIL,
217
"gfproxyd for volume: %s",
222
glusterd_volinfo_ref(volinfo);
223
ret = glusterd_conn_connect(&(svc->conn));
225
glusterd_volinfo_unref(volinfo);
230
} else if (glusterd_proc_is_running(&svc->proc)) {
231
ret = svc->stop(svc, SIGTERM);
233
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SNAPD_STOP_FAIL,
234
"Couldn't stop gfproxyd for volume: %s", volinfo->volname);
242
gf_event(EVENT_SVC_MANAGER_FAILED, "volume=%s;svc_name=%s",
243
volinfo->volname, svc->name);
247
gf_msg_debug("glusterd", 0, "Returning %d", ret);
253
glusterd_gfproxydsvc_start(glusterd_svc_t *svc, int flags)
259
glusterd_conf_t *priv = NULL;
260
xlator_t *this = THIS;
261
char valgrind_logfile[PATH_MAX] = {0};
262
int gfproxyd_port = 0;
266
char gfproxyd_id[PATH_MAX] = {
269
glusterd_volinfo_t *volinfo = NULL;
270
char *localtime_logging = NULL;
273
priv = this->private;
274
GF_VALIDATE_OR_GOTO(this->name, priv, out);
276
volinfo = glusterd_gfproxyd_volinfo_from_svc(svc);
280
ret = sys_access(svc->proc.volfile, F_OK);
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);
286
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLFILE_CREATE_FAIL,
288
"gfproxyd volfile for volume: %s",
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)) {
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",
308
runner_add_args(&runner, "valgrind", "--tool=drd", NULL);
310
runner_argprintf(&runner, "--log-file=%s", valgrind_logfile);
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);
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");
328
gfproxyd_port = pmap_assign_port(this, volinfo->gfproxyd.port, gfproxyd_id);
329
volinfo->gfproxyd.port = gfproxyd_port;
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,
337
snprintf(msg, sizeof(msg), "Starting the gfproxyd service for volume %s",
339
runner_log(&runner, this->name, GF_LOG_DEBUG, msg);
341
if (flags == PROC_START_NO_WAIT) {
342
ret = runner_run_nowait(&runner);
344
synclock_unlock(&priv->big_lock);
346
ret = runner_run(&runner);
348
synclock_lock(&priv->big_lock);
356
glusterd_gfproxydsvc_restart(void)
358
glusterd_volinfo_t *volinfo = NULL;
359
glusterd_volinfo_t *tmp = NULL;
361
xlator_t *this = THIS;
362
glusterd_conf_t *conf = NULL;
363
glusterd_svc_t *svc = NULL;
365
conf = this->private;
366
GF_VALIDATE_OR_GOTO(this->name, conf, out);
368
cds_list_for_each_entry_safe(volinfo, tmp, &conf->volumes, vol_list)
371
if (volinfo->status == GLUSTERD_STATUS_STARTED) {
372
svc = &(volinfo->gfproxyd.svc);
373
ret = svc->manager(svc, volinfo, PROC_START_NO_WAIT);
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",
379
gf_event(EVENT_SVC_MANAGER_FAILED, "volume=%s;svc_name=%s",
380
volinfo->volname, svc->name);
390
glusterd_gfproxydsvc_reconfigure(glusterd_volinfo_t *volinfo)
393
gf_boolean_t identical = _gf_false;
395
if (!volinfo->gfproxyd.svc.inited)
398
if (!glusterd_is_gfproxyd_enabled(volinfo))
400
else if (!glusterd_proc_is_running(&volinfo->gfproxyd.svc.proc))
408
ret = glusterd_svc_check_gfproxyd_volfile_identical(
409
volinfo->gfproxyd.svc.name, volinfo, &identical);
423
identical = _gf_false;
424
ret = glusterd_svc_check_gfproxyd_topology_identical(
425
volinfo->gfproxyd.svc.name, volinfo, &identical);
433
ret = glusterd_gfproxydsvc_create_volfile(volinfo);
435
ret = glusterd_fetchspec_notify(THIS);
444
ret = volinfo->gfproxyd.svc.manager(&(volinfo->gfproxyd.svc), volinfo,
448
gf_msg_debug("glusterd", 0, "Returning %d", ret);