16
#include <glusterfs/compat-uuid.h>
18
#include "rpc-common-xdr.h"
23
#include <glusterfs/call-stub.h>
24
#include <glusterfs/list.h>
25
#include <glusterfs/dict.h>
26
#include <glusterfs/options.h>
27
#include <glusterfs/compat.h>
28
#include <glusterfs/compat-errno.h>
29
#include <glusterfs/syscall.h>
30
#include "glusterd-statedump.h"
31
#include "glusterd-sm.h"
32
#include "glusterd-op-sm.h"
33
#include "glusterd-store.h"
34
#include "glusterd-hooks.h"
35
#include "glusterd-utils.h"
36
#include "glusterd-locks.h"
37
#include "glusterd-svc-mgmt.h"
38
#include "glusterd-shd-svc.h"
40
#include "glusterd-nfs-svc.h"
42
#include "glusterd-bitd-svc.h"
43
#include "glusterd-scrub-svc.h"
44
#include "glusterd-quotad-svc.h"
45
#include "glusterd-snapd-svc.h"
46
#include "glusterd-messages.h"
47
#include <glusterfs/common-utils.h>
48
#include "glusterd-geo-rep.h"
49
#include <glusterfs/run.h>
50
#include "rpc-clnt-ping.h"
52
#include <glusterfs/syncop.h>
54
#include "glusterd-mountbroker.h"
56
extern struct rpcsvc_program gluster_handshake_prog;
57
extern struct rpcsvc_program gluster_cli_getspec_prog;
58
extern struct rpcsvc_program gluster_pmap_prog;
59
extern glusterd_op_info_t opinfo;
60
extern struct rpcsvc_program gd_svc_mgmt_prog;
61
extern struct rpcsvc_program gd_svc_mgmt_v3_prog;
62
extern struct rpcsvc_program gd_svc_peer_prog;
63
extern struct rpcsvc_program gd_svc_cli_prog;
64
extern struct rpcsvc_program gd_svc_cli_trusted_progs;
65
extern struct rpc_clnt_program gd_brick_prog;
66
extern struct rpcsvc_program glusterd_mgmt_hndsk_prog;
68
extern char snap_mount_dir[VALID_GLUSTERD_PATHMAX];
70
rpcsvc_cbk_program_t glusterd_cbk_prog = {
71
.progname = "Gluster Callback",
72
.prognum = GLUSTER_CBK_PROGRAM,
73
.progver = GLUSTER_CBK_VERSION,
76
struct rpcsvc_program *gd_inet_programs[] = {
77
&gd_svc_peer_prog, &gd_svc_cli_trusted_progs,
79
&gd_svc_mgmt_prog, &gd_svc_mgmt_v3_prog, &gluster_pmap_prog,
80
&gluster_handshake_prog, &glusterd_mgmt_hndsk_prog,
82
int gd_inet_programs_count = (sizeof(gd_inet_programs) /
83
sizeof(gd_inet_programs[0]));
85
struct rpcsvc_program *gd_uds_programs[] = {
87
&gluster_cli_getspec_prog,
89
int gd_uds_programs_count = (sizeof(gd_uds_programs) /
90
sizeof(gd_uds_programs[0]));
92
const char *gd_op_list[GD_OP_MAX + 1] = {
93
[GD_OP_NONE] = "Invalid op",
94
[GD_OP_CREATE_VOLUME] = "Create",
95
[GD_OP_START_BRICK] = "Start Brick",
96
[GD_OP_STOP_BRICK] = "Stop Brick",
97
[GD_OP_DELETE_VOLUME] = "Delete",
98
[GD_OP_START_VOLUME] = "Start",
99
[GD_OP_STOP_VOLUME] = "Stop",
100
[GD_OP_DEFRAG_VOLUME] = "Rebalance",
101
[GD_OP_ADD_BRICK] = "Add brick",
102
[GD_OP_DETACH_TIER] = "Detach tier",
103
[GD_OP_TIER_MIGRATE] = "Tier migration",
104
[GD_OP_REMOVE_BRICK] = "Remove brick",
105
[GD_OP_REPLACE_BRICK] = "Replace brick",
106
[GD_OP_SET_VOLUME] = "Set",
107
[GD_OP_RESET_VOLUME] = "Reset",
108
[GD_OP_SYNC_VOLUME] = "Sync",
109
[GD_OP_LOG_ROTATE] = "Log rotate",
110
[GD_OP_GSYNC_SET] = "Geo-replication",
111
[GD_OP_PROFILE_VOLUME] = "Profile",
112
[GD_OP_QUOTA] = "Quota",
113
[GD_OP_STATUS_VOLUME] = "Status",
114
[GD_OP_REBALANCE] = "Rebalance",
115
[GD_OP_HEAL_VOLUME] = "Heal",
116
[GD_OP_STATEDUMP_VOLUME] = "Statedump",
117
[GD_OP_LIST_VOLUME] = "Lists",
118
[GD_OP_CLEARLOCKS_VOLUME] = "Clear locks",
119
[GD_OP_DEFRAG_BRICK_VOLUME] = "Rebalance",
120
[GD_OP_COPY_FILE] = "Copy File",
121
[GD_OP_SYS_EXEC] = "Execute system commands",
122
[GD_OP_GSYNC_CREATE] = "Geo-replication Create",
123
[GD_OP_SNAP] = "Snapshot",
124
[GD_OP_RESET_BRICK] = "Reset Brick",
125
[GD_OP_MAX_OPVERSION] = "Maximum supported op-version",
126
[GD_OP_MAX] = "Invalid op"};
128
#define GLUSTERD_DEFAULT_SNAPS_BRICK_DIR "/gluster/snaps"
129
#define GLUSTERD_BITD_RUN_DIR "/bitd"
130
#define GLUSTERD_SCRUB_RUN_DIR "/scrub"
131
#define GLUSTERD_NFS_RUN_DIR "/nfs"
132
#define GLUSTERD_QUOTAD_RUN_DIR "/quotad"
133
#define GLUSTERD_VAR_RUN_DIR "/var/run"
134
#define GLUSTERD_RUN_DIR "/run"
137
glusterd_opinfo_init(void)
141
opinfo.op = GD_OP_NONE;
147
glusterd_uuid_init(void)
150
xlator_t *this = THIS;
151
glusterd_conf_t *priv = NULL;
153
priv = this->private;
156
ret = glusterd_retrieve_uuid();
158
gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_RETRIEVED_UUID,
159
"retrieved UUID: %s", uuid_utoa(priv->uuid));
163
ret = glusterd_uuid_generate_save();
166
gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_UUID_GEN_STORE_FAIL,
167
"Unable to generate and save new UUID");
175
glusterd_uuid_generate_save(void)
178
glusterd_conf_t *priv = NULL;
179
xlator_t *this = THIS;
181
priv = this->private;
184
gf_uuid_generate(priv->uuid);
186
gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_GENERATED_UUID,
187
"generated UUID: %s", uuid_utoa(priv->uuid));
189
ret = glusterd_store_global_info(this);
192
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_UUID_STORE_FAIL,
193
"Unable to store the generated uuid %s", uuid_utoa(priv->uuid));
199
glusterd_options_init(xlator_t *this)
202
glusterd_conf_t *priv = NULL;
203
char *initial_version = "0";
205
priv = this->private;
207
priv->opts = dict_new();
209
gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL);
213
ret = glusterd_store_retrieve_options(this);
218
ret = dict_set_str(priv->opts, GLUSTERD_GLOBAL_OPT_VERSION,
223
ret = glusterd_store_options(this, priv->opts);
225
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VERS_STORE_FAIL,
226
"Unable to store version");
234
glusterd_client_statedump_submit_req(char *volname, char *target_ip, char *pid)
236
gf_statedump statedump_req = {
239
glusterd_conf_t *conf = NULL;
241
char *end_ptr = NULL;
242
rpc_transport_t *trans = NULL;
243
char *ip_addr = NULL;
244
xlator_t *this = THIS;
245
char tmp[UNIX_PATH_MAX] = {
249
conf = this->private;
252
if (target_ip == NULL || pid == NULL) {
253
gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_INVALID_ARGUMENT, NULL);
258
statedump_req.pid = strtol(pid, &end_ptr, 10);
260
gf_msg_debug(this->name, 0,
261
"Performing statedump on volume %s "
262
"client with pid:%d host:%s",
263
volname, statedump_req.pid, target_ip);
265
pthread_mutex_lock(&conf->xprt_lock);
267
list_for_each_entry(trans, &conf->xprt_list, list)
271
if (strncmp(volname, "all", NAME_MAX) &&
272
strncmp(trans->peerinfo.volname, volname, NAME_MAX)) {
277
strcpy(tmp, trans->peerinfo.identifier);
278
ip_addr = strtok(tmp, ":");
279
if (gf_is_same_address(ip_addr, target_ip)) {
285
gf_msg_trace(this->name, 0,
287
"statedump rpc request for %s",
288
trans->peerinfo.identifier);
289
rpcsvc_request_submit(conf->rpc, trans, &glusterd_cbk_prog,
290
GF_CBK_STATEDUMP, &statedump_req,
291
this->ctx, (xdrproc_t)xdr_gf_statedump);
295
pthread_mutex_unlock(&conf->xprt_lock);
301
glusterd_fetchspec_notify(xlator_t *this)
304
glusterd_conf_t *priv = NULL;
305
rpc_transport_t *trans = NULL;
307
priv = this->private;
309
pthread_mutex_lock(&priv->xprt_lock);
311
list_for_each_entry(trans, &priv->xprt_list, list)
313
rpcsvc_callback_submit(priv->rpc, trans, &glusterd_cbk_prog,
314
GF_CBK_FETCHSPEC, NULL, 0, NULL);
317
pthread_mutex_unlock(&priv->xprt_lock);
325
glusterd_fetchsnap_notify(xlator_t *this)
328
glusterd_conf_t *priv = NULL;
329
rpc_transport_t *trans = NULL;
331
priv = this->private;
345
pthread_mutex_lock(&priv->xprt_lock);
347
list_for_each_entry(trans, &priv->xprt_list, list)
349
rpcsvc_callback_submit(priv->rpc, trans, &glusterd_cbk_prog,
350
GF_CBK_GET_SNAPS, NULL, 0, NULL);
353
pthread_mutex_unlock(&priv->xprt_lock);
361
mem_acct_init(xlator_t *this)
368
ret = xlator_mem_acct_init(this, gf_gld_mt_end);
371
gf_msg(this->name, GF_LOG_ERROR, ENOMEM, GD_MSG_NO_MEMORY,
372
"Memory accounting init"
381
glusterd_rpcsvc_notify(rpcsvc_t *rpc, void *xl, rpcsvc_event_t event,
384
xlator_t *this = NULL;
385
rpc_transport_t *xprt = NULL;
386
glusterd_conf_t *priv = NULL;
389
gf_msg("glusterd", GF_LOG_WARNING, 0, GD_MSG_NO_INIT,
390
"Calling rpc_notify without initializing");
397
priv = this->private;
400
case RPCSVC_EVENT_ACCEPT: {
401
pthread_mutex_lock(&priv->xprt_lock);
402
list_add_tail(&xprt->list, &priv->xprt_list);
403
pthread_mutex_unlock(&priv->xprt_lock);
406
case RPCSVC_EVENT_DISCONNECT: {
412
if (list_empty(&xprt->list))
415
pthread_mutex_lock(&priv->xprt_lock);
416
list_del(&xprt->list);
417
pthread_mutex_unlock(&priv->xprt_lock);
418
pmap_port_remove(this, 0, NULL, xprt, _gf_false);
431
glusterd_program_register(xlator_t *this, rpcsvc_t *svc, rpcsvc_program_t *prog)
435
ret = rpcsvc_program_register(svc, prog, _gf_false);
437
gf_msg_debug(this->name, 0,
438
"cannot register program (name: %s, prognum:%d, "
440
prog->progname, prog->prognum, prog->progver);
449
glusterd_rpcsvc_options_build(dict_t *options)
452
uint32_t backlog = 0;
454
ret = dict_get_uint32(options, "transport.listen-backlog", &backlog);
457
backlog = GLUSTERFS_SOCKET_LISTEN_BACKLOG;
458
ret = dict_set_uint32(options, "transport.listen-backlog", backlog);
460
gf_smsg(THIS->name, GF_LOG_ERROR, -ret, GD_MSG_DICT_SET_FAILED,
461
"Key=transport.listen-backlog", NULL);
466
gf_msg_debug("glusterd", 0, "listen-backlog value: %d", backlog);
472
#if SYNCDAEMON_COMPILE
475
glusterd_check_gsync_present(int *valid_state)
477
char buff[PATH_MAX] = {
487
runner_add_args(&runner, GSYNCD_PREFIX "/gsyncd", "--version", NULL);
488
runner_redir(&runner, STDOUT_FILENO, RUN_PIPE);
489
ret = runner_start(&runner);
491
if (errno == ENOENT) {
492
gf_msg("glusterd", GF_LOG_INFO, errno, GD_MSG_MODULE_NOT_INSTALLED,
493
GEOREP " module not installed in the system");
496
gf_msg("glusterd", GF_LOG_ERROR, errno, GD_MSG_MODULE_NOT_WORKING,
497
GEOREP " module not working as desired");
503
ptr = fgets(buff, sizeof(buff), runner_chio(&runner, STDOUT_FILENO));
505
if (!strstr(buff, "gsyncd")) {
507
gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_MODULE_NOT_WORKING,
510
"working as desired");
516
gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_MODULE_NOT_WORKING,
519
"working as desired");
529
gf_msg_debug("glusterd", 0, "Returning %d", ret);
534
group_write_allow(char *path, gid_t gid)
541
ret = sys_stat(path, &st);
544
GF_ASSERT(S_ISDIR(st.st_mode));
546
ret = sys_chown(path, -1, gid);
550
ret = sys_chmod(path, (st.st_mode & ~S_IFMT) | S_IWGRP | S_IXGRP | S_ISVTX);
554
gf_msg("glusterd", GF_LOG_CRITICAL, errno,
555
GD_MSG_WRITE_ACCESS_GRANT_FAIL,
556
"failed to set up write access to %s for group %d (%s)", path,
557
gid, strerror(errno));
562
glusterd_crt_georep_folders(char *georepdir, glusterd_conf_t *conf)
564
char *greplg_s = NULL;
565
struct group *gr = NULL;
569
char logdir[PATH_MAX] = {0};
571
GF_ASSERT(georepdir);
574
if (strlen(conf->workdir) + 2 > PATH_MAX - SLEN(GEOREP)) {
576
gf_msg("glusterd", GF_LOG_CRITICAL, 0, GD_MSG_DIRPATH_TOO_LONG,
577
"directory path %s/" GEOREP " is longer than PATH_MAX",
582
len = snprintf(georepdir, PATH_MAX, "%s/" GEOREP, conf->workdir);
583
if ((len < 0) || (len >= PATH_MAX)) {
584
gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_COPY_FAIL, NULL);
588
ret = mkdir_p(georepdir, 0755, _gf_true);
590
gf_msg("glusterd", GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
591
"Unable to create " GEOREP " directory %s", georepdir);
595
ret = dict_get_str(THIS->options, GEOREP "-log-group", &greplg_s);
597
gf_smsg("glusterd", GF_LOG_ERROR, -ret, GD_MSG_DICT_GET_FAILED,
598
"Key=log-group", NULL);
601
gr = getgrnam(greplg_s);
603
gf_msg("glusterd", GF_LOG_CRITICAL, 0, GD_MSG_LOGGROUP_INVALID,
604
"group " GEOREP "-log-group %s does not exist", greplg_s);
608
if ((strlen(conf->logdir) + 2 + SLEN(GEOREP)) >= PATH_MAX) {
610
gf_msg("glusterd", GF_LOG_CRITICAL, 0, GD_MSG_DIRPATH_TOO_LONG,
611
"directory path %s/" GEOREP " is longer than PATH_MAX",
615
len = snprintf(logdir, PATH_MAX, "%s/" GEOREP, conf->logdir);
616
if ((len < 0) || (len >= PATH_MAX)) {
620
ret = mkdir_p(logdir, 0755, _gf_true);
622
gf_msg("glusterd", GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
623
"Unable to create " GEOREP " log directory");
627
gr_ret = group_write_allow(logdir, gr->gr_gid);
630
if ((strlen(conf->logdir) + 2 + SLEN(GEOREP "-secondaries")) >= PATH_MAX) {
632
gf_msg("glusterd", GF_LOG_CRITICAL, 0, GD_MSG_DIRPATH_TOO_LONG,
633
"directory path %s/" GEOREP
635
" is longer than PATH_MAX",
639
len = snprintf(logdir, PATH_MAX, "%s/" GEOREP "-secondaries", conf->logdir);
640
if ((len < 0) || (len >= PATH_MAX)) {
641
gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_COPY_FAIL, NULL);
645
ret = mkdir_p(logdir, 0755, _gf_true);
647
gf_msg("glusterd", GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
648
"Unable to create " GEOREP " secondary log directory");
652
gr_ret = group_write_allow(logdir, gr->gr_gid);
656
if ((strlen(conf->logdir) + 2 + SLEN(GEOREP "-secondaries/mbr")) >=
659
gf_msg("glusterd", GF_LOG_CRITICAL, 0, GD_MSG_DIRPATH_TOO_LONG,
660
"directory path %s/" GEOREP
662
" is longer than PATH_MAX",
667
len = snprintf(logdir, PATH_MAX, "%s/" GEOREP "-secondaries/mbr",
669
if ((len < 0) || (len >= PATH_MAX)) {
670
gf_smsg("glusterd", GF_LOG_ERROR, errno, GD_MSG_COPY_FAIL, NULL);
675
ret = mkdir_p(logdir, 0755, _gf_true);
677
gf_msg("glusterd", GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
678
"Unable to create " GEOREP
679
" mountbroker secondary log directory");
683
gr_ret = group_write_allow(logdir, gr->gr_gid);
688
gf_msg_debug("glusterd", 0, "Returning %d", ret);
693
runinit_gsyncd_setrx(runner_t *runner, glusterd_conf_t *conf)
696
runner_add_args(runner, GSYNCD_PREFIX "/gsyncd", "-c", NULL);
697
runner_argprintf(runner, "%s/" GSYNC_CONF_TEMPLATE, conf->workdir);
698
runner_add_arg(runner, "--config-set-rx");
702
run_gsyncd_cmd(runner_t *runner, xlator_t *this)
706
ret = runner_run_reuse(runner);
708
runner_log(runner, this->name, GF_LOG_ERROR, "command failed");
715
configure_syncdaemon(glusterd_conf_t *conf)
721
char georepdir[PATH_MAX] = {
725
xlator_t *this = NULL;
731
ret = setenv("_GLUSTERD_CALLED_", "1", 1);
737
ret = glusterd_check_gsync_present(&valid_state);
743
glusterd_crt_georep_folders(georepdir, conf);
754
runinit_gsyncd_setrx(&runner, conf);
755
runner_add_args(&runner, "remote-gsyncd", GSYNCD_PREFIX "/gsyncd", ".", ".",
757
ret = run_gsyncd_cmd(&runner, this);
761
runinit_gsyncd_setrx(&runner, conf);
762
runner_add_args(&runner, "remote-gsyncd", "/nonexistent/gsyncd", ".",
764
ret = run_gsyncd_cmd(&runner, this);
769
runinit_gsyncd_setrx(&runner, conf);
770
runner_add_args(&runner, "gluster-command-dir", SBIN_DIR "/", ".", ".",
772
ret = run_gsyncd_cmd(&runner, this);
777
runinit_gsyncd_setrx(&runner, conf);
778
runner_add_args(&runner, "gluster-params", "aux-gfid-mount acl", ".", ".",
780
ret = run_gsyncd_cmd(&runner, this);
785
runinit_gsyncd_setrx(&runner, conf);
786
runner_add_arg(&runner, "ssh-command");
787
runner_argprintf(&runner,
788
"ssh -oPasswordAuthentication=no "
789
"-oStrictHostKeyChecking=no "
792
runner_add_args(&runner, ".", ".", NULL);
793
ret = run_gsyncd_cmd(&runner, this);
798
runinit_gsyncd_setrx(&runner, conf);
799
runner_add_arg(&runner, "ssh-command-tar");
800
runner_argprintf(&runner,
801
"ssh -oPasswordAuthentication=no "
802
"-oStrictHostKeyChecking=no "
805
runner_add_args(&runner, ".", ".", NULL);
806
ret = run_gsyncd_cmd(&runner, this);
811
runinit_gsyncd_setrx(&runner, conf);
812
runner_add_arg(&runner, "pid-file");
814
&runner, "%s/${primaryvol}_${remotehost}_${secondaryvol}/monitor.pid",
816
runner_add_args(&runner, ".", ".", NULL);
817
ret = run_gsyncd_cmd(&runner, this);
822
runinit_gsyncd_setrx(&runner, conf);
823
runner_add_arg(&runner, "georep-session-working-dir");
824
runner_argprintf(&runner, "%s/${primaryvol}_${remotehost}_${secondaryvol}/",
826
runner_add_args(&runner, ".", ".", NULL);
827
ret = run_gsyncd_cmd(&runner, this);
832
runinit_gsyncd_setrx(&runner, conf);
833
runner_add_arg(&runner, "state-file");
836
"%s/${primaryvol}_${remotehost}_${secondaryvol}/monitor.status",
838
runner_add_args(&runner, ".", ".", NULL);
839
ret = run_gsyncd_cmd(&runner, this);
844
runinit_gsyncd_setrx(&runner, conf);
845
runner_add_arg(&runner, "state-detail-file");
846
runner_argprintf(&runner,
847
"%s/${primaryvol}_${remotehost}_${secondaryvol}/"
848
"${eSecondary}-detail.status",
850
runner_add_args(&runner, ".", ".", NULL);
851
ret = run_gsyncd_cmd(&runner, this);
856
runinit_gsyncd_setrx(&runner, conf);
857
runner_add_arg(&runner, "state-detail-file");
858
runner_argprintf(&runner,
859
"%s/${primaryvol}_${remotehost}_${secondaryvol}/"
860
"${eSecondary}-detail.status",
862
runner_add_args(&runner, ".", ".", NULL);
863
ret = run_gsyncd_cmd(&runner, this);
868
runinit_gsyncd_setrx(&runner, conf);
869
runner_add_arg(&runner, "state-socket-unencoded");
870
runner_argprintf(&runner, "%s/${primaryvol}/${eSecondary}.socket",
872
runner_add_args(&runner, ".", ".", NULL);
873
ret = run_gsyncd_cmd(&runner, this);
878
runinit_gsyncd_setrx(&runner, conf);
879
runner_add_args(&runner, "socketdir", GLUSTERD_SOCK_DIR, ".", ".", NULL);
880
ret = run_gsyncd_cmd(&runner, this);
885
runinit_gsyncd_setrx(&runner, conf);
886
runner_add_arg(&runner, "log-file");
887
runner_argprintf(&runner, "%s/" GEOREP "/${primaryvol}/${eSecondary}.log",
889
runner_add_args(&runner, ".", ".", NULL);
890
ret = run_gsyncd_cmd(&runner, this);
895
runinit_gsyncd_setrx(&runner, conf);
896
runner_add_arg(&runner, "gluster-log-file");
897
runner_argprintf(&runner,
899
"/${primaryvol}/${eSecondary}${local_id}.gluster.log",
901
runner_add_args(&runner, ".", ".", NULL);
902
ret = run_gsyncd_cmd(&runner, this);
907
runinit_gsyncd_setrx(&runner, conf);
908
runner_add_args(&runner, "ignore-deletes", "true", ".", ".", NULL);
909
ret = run_gsyncd_cmd(&runner, this);
914
runinit_gsyncd_setrx(&runner, conf);
915
runner_add_args(&runner, "special-sync-mode", "partial", ".", ".", NULL);
916
ret = run_gsyncd_cmd(&runner, this);
921
runinit_gsyncd_setrx(&runner, conf);
922
runner_add_args(&runner, "change-detector", "changelog", ".", ".", NULL);
923
ret = run_gsyncd_cmd(&runner, this);
927
runinit_gsyncd_setrx(&runner, conf);
928
runner_add_arg(&runner, "working-dir");
929
runner_argprintf(&runner, "%s/${primaryvol}/${eSecondary}",
930
DEFAULT_VAR_RUN_DIRECTORY);
931
runner_add_args(&runner, ".", ".", NULL);
932
ret = run_gsyncd_cmd(&runner, this);
941
runinit_gsyncd_setrx(&runner, conf);
942
runner_add_args(&runner, "secondary-gluster-command-dir", SBIN_DIR "/", ".",
944
ret = run_gsyncd_cmd(&runner, this);
949
runinit_gsyncd_setrx(&runner, conf);
950
runner_add_args(&runner, "gluster-params", "aux-gfid-mount acl", ".", NULL);
951
ret = run_gsyncd_cmd(&runner, this);
956
runinit_gsyncd_setrx(&runner, conf);
957
runner_add_arg(&runner, "log-file");
962
"${session_owner}:${local_node}${local_id}.${secondaryvol}.log",
964
runner_add_args(&runner, ".", ".", NULL);
965
ret = run_gsyncd_cmd(&runner, this);
970
runinit_gsyncd_setrx(&runner, conf);
971
runner_add_arg(&runner, "log-file-mbr");
976
"${session_owner}:${local_node}${local_id}.${secondaryvol}.log",
978
runner_add_args(&runner, ".", ".", NULL);
979
ret = run_gsyncd_cmd(&runner, this);
984
runinit_gsyncd_setrx(&runner, conf);
985
runner_add_arg(&runner, "gluster-log-file");
990
"${session_owner}:${local_node}${local_id}.${secondaryvol}.gluster.log",
992
runner_add_args(&runner, ".", ".", NULL);
993
ret = run_gsyncd_cmd(&runner, this);
1001
configure_syncdaemon(glusterd_conf_t *conf)
1009
check_prepare_mountbroker_root(char *mountbroker_root)
1022
ret = open(mountbroker_root, O_RDONLY);
1025
ret = sys_fstat(dfd, &st);
1027
if (ret == -1 || !S_ISDIR(st.st_mode)) {
1028
gf_msg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DIR_OP_FAILED,
1029
"cannot access mountbroker-root directory %s", mountbroker_root);
1033
if (st.st_uid != 0 || (st.st_mode & (S_IWGRP | S_IWOTH))) {
1034
gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_DIR_PERM_LIBERAL,
1035
"permissions on mountbroker-root directory %s are "
1041
if (!(st.st_mode & (S_IXGRP | S_IXOTH))) {
1042
gf_msg("glusterd", GF_LOG_WARNING, 0, GD_MSG_DIR_PERM_STRICT,
1043
"permissions on mountbroker-root directory %s are "
1044
"probably too strict",
1051
ret = sys_openat(dfd, "..", O_RDONLY, 0);
1054
ret = sys_fstat(dfd2, &st2);
1057
gf_msg("glusterd", GF_LOG_ERROR, errno, GD_MSG_DIR_OP_FAILED,
1058
"error while checking mountbroker-root ancestors "
1060
errno, strerror(errno));
1064
if (st2.st_ino == st.st_ino)
1067
if (st2.st_uid != 0 ||
1068
((st2.st_mode & (S_IWGRP | S_IWOTH)) && !(st2.st_mode & S_ISVTX))) {
1069
gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_DIR_PERM_LIBERAL,
1070
"permissions on ancestors of mountbroker-root "
1071
"directory are too liberal");
1075
if (!(st.st_mode & (S_IXGRP | S_IXOTH))) {
1076
gf_msg("glusterd", GF_LOG_WARNING, 0, GD_MSG_DIR_PERM_STRICT,
1077
"permissions on ancestors of mountbroker-root "
1078
"directory are probably too strict");
1086
ret = sys_mkdirat(dfd0, MB_HIVE, 0711);
1087
if (ret == -1 && errno == EEXIST)
1090
ret = sys_fstatat(dfd0, MB_HIVE, &st, AT_SYMLINK_NOFOLLOW);
1091
if (ret == -1 || st.st_mode != (S_IFDIR | 0711)) {
1092
gf_msg("glusterd", GF_LOG_ERROR, errno, GD_MSG_CREATE_DIR_FAILED,
1093
"failed to set up mountbroker-root directory %s",
1106
if (dfd2 != -1 && dfd != dfd2)
1113
_install_mount_spec(dict_t *opts, char *key, data_t *value, void *data)
1115
glusterd_conf_t *priv = THIS->private;
1117
gf_boolean_t georep = _gf_false;
1118
char *pdesc = value->data;
1119
char *volname = NULL;
1121
gf_mount_spec_t *mspec = NULL;
1124
label = strtail(key, "mountbroker.");
1128
label = strtail(key, "mountbroker-" GEOREP ".");
1136
mspec = GF_CALLOC(1, sizeof(*mspec), gf_gld_mt_mount_spec);
1138
gf_smsg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_NO_MEMORY, NULL);
1141
mspec->label = label;
1144
volname = gf_strdup(pdesc);
1147
user = strchr(volname, ':');
1154
rv = make_georep_mountspec(mspec, volname, user, priv->logdir);
1159
} else if (parse_mount_pattern_desc(mspec, pdesc) != 0)
1162
cds_list_add_tail(&mspec->speclist, &priv->mount_specs);
1167
gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_MOUNT_SPEC_INSTALL_FAIL,
1168
"adding %smount spec failed: label: %s desc: %s",
1169
georep ? GEOREP " " : "", label, pdesc ? pdesc : "");
1172
if (mspec->patterns) {
1173
GF_FREE(mspec->patterns->components);
1174
GF_FREE(mspec->patterns);
1184
glusterd_init_uds_listener(xlator_t *this)
1187
dict_t *options = NULL;
1188
rpcsvc_t *rpc = NULL;
1189
data_t *sock_data = NULL;
1190
char sockfile[UNIX_PATH_MAX] = {0};
1195
options = dict_new();
1197
gf_smsg(this->name, GF_LOG_ERROR, errno, GD_MSG_DICT_CREATE_FAIL, NULL);
1201
sock_data = dict_get(this->options, "glusterd-sockfile");
1202
(void)snprintf(sockfile, sizeof(sockfile), "%s",
1203
sock_data ? sock_data->data : DEFAULT_GLUSTERD_SOCKFILE);
1205
ret = rpcsvc_transport_unix_options_build(options, sockfile);
1209
rpc = rpcsvc_init(this, this->ctx, options, 8);
1215
ret = rpcsvc_register_notify(rpc, glusterd_rpcsvc_notify, this);
1217
gf_msg_debug(this->name, 0, "Failed to register notify function");
1221
ret = rpcsvc_create_listeners(rpc, options, this->name);
1223
gf_msg_debug(this->name, 0, "Failed to create listener");
1228
for (i = 0; i < gd_uds_programs_count; i++) {
1229
ret = glusterd_program_register(this, rpc, gd_uds_programs[i]);
1233
rpcsvc_program_unregister(rpc, gd_uds_programs[i]);
1241
dict_unref(options);
1244
gf_msg(this->name, GF_LOG_ERROR, 0,
1245
GD_MSG_GLUSTERD_SOCK_LISTENER_START_FAIL,
1246
"Failed to start glusterd "
1247
"unix domain socket listener.");
1257
glusterd_stop_uds_listener(xlator_t *this)
1259
glusterd_conf_t *conf = NULL;
1260
rpcsvc_listener_t *listener = NULL;
1261
rpcsvc_listener_t *next = NULL;
1262
data_t *sock_data = NULL;
1263
char sockfile[UNIX_PATH_MAX] = {0};
1266
conf = this->private;
1268
(void)rpcsvc_program_unregister(conf->uds_rpc, &gd_svc_cli_prog);
1269
(void)rpcsvc_program_unregister(conf->uds_rpc, &gluster_handshake_prog);
1271
list_for_each_entry_safe(listener, next, &conf->uds_rpc->listeners, list)
1273
rpcsvc_listener_destroy(listener);
1276
(void)rpcsvc_unregister_notify(conf->uds_rpc, glusterd_rpcsvc_notify, this);
1278
sock_data = dict_get(this->options, "glusterd-sockfile");
1279
(void)snprintf(sockfile, sizeof(sockfile), "%s",
1280
sock_data ? sock_data->data : DEFAULT_GLUSTERD_SOCKFILE);
1281
sys_unlink(sockfile);
1287
glusterd_stop_listener(xlator_t *this)
1289
glusterd_conf_t *conf = NULL;
1290
rpcsvc_listener_t *listener = NULL;
1291
rpcsvc_listener_t *next = NULL;
1294
GF_VALIDATE_OR_GOTO("glusterd", this, out);
1295
conf = this->private;
1296
GF_VALIDATE_OR_GOTO(this->name, conf, out);
1298
gf_msg_debug(this->name, 0, "%s function called ", __func__);
1300
for (i = 0; i < gd_inet_programs_count; i++) {
1301
rpcsvc_program_unregister(conf->rpc, gd_inet_programs[i]);
1304
list_for_each_entry_safe(listener, next, &conf->rpc->listeners, list)
1306
rpcsvc_listener_destroy(listener);
1309
(void)rpcsvc_unregister_notify(conf->rpc, glusterd_rpcsvc_notify, this);
1317
glusterd_find_correct_var_run_dir(xlator_t *this, char *var_run_dir)
1324
GF_VALIDATE_OR_GOTO("glusterd", this, out);
1325
GF_VALIDATE_OR_GOTO(this->name, var_run_dir, out);
1332
ret = sys_lstat(GLUSTERD_VAR_RUN_DIR, &buf);
1334
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED,
1335
"stat fails on %s, exiting. (errno = %d)", GLUSTERD_VAR_RUN_DIR,
1341
if (S_ISLNK(buf.st_mode)) {
1342
strcpy(var_run_dir, GLUSTERD_RUN_DIR);
1344
strcpy(var_run_dir, GLUSTERD_VAR_RUN_DIR);
1353
glusterd_init_var_run_dirs(xlator_t *this, char *var_run_dir,
1354
char *dir_to_be_created)
1360
char abs_path[PATH_MAX] = {
1364
GF_VALIDATE_OR_GOTO("glusterd", this, out);
1365
GF_VALIDATE_OR_GOTO(this->name, var_run_dir, out);
1366
GF_VALIDATE_OR_GOTO(this->name, dir_to_be_created, out);
1368
snprintf(abs_path, sizeof(abs_path), "%s%s", var_run_dir,
1371
ret = sys_stat(abs_path, &buf);
1372
if ((ret != 0) && (ENOENT != errno)) {
1373
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_FILE_OP_FAILED,
1374
"stat fails on %s, exiting. (errno = %d)", abs_path, errno);
1379
if ((!ret) && (!S_ISDIR(buf.st_mode))) {
1380
gf_msg(this->name, GF_LOG_CRITICAL, ENOENT, GD_MSG_DIR_NOT_FOUND,
1381
"Provided snap path %s is not a directory,"
1388
if ((-1 == ret) && (ENOENT == errno)) {
1390
ret = mkdir_p(abs_path, 0755, _gf_true);
1393
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
1394
"Unable to create directory %s"
1406
is_upgrade(dict_t *options, gf_boolean_t *upgrade)
1411
ret = dict_get_str(options, "upgrade", &type);
1413
ret = gf_string2boolean(type, upgrade);
1415
gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_STR_TO_BOOL_FAIL,
1417
"%s is not a valid boolean type",
1429
is_downgrade(dict_t *options, gf_boolean_t *downgrade)
1434
ret = dict_get_str(options, "downgrade", &type);
1436
ret = gf_string2boolean(type, downgrade);
1438
gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_STR_TO_BOOL_FAIL,
1440
"%s is not a valid boolean type",
1452
glusterd_destroy_hostname_list(struct list_head *hostname_list_head)
1454
glusterd_hostname_t *hostname_obj = NULL;
1455
glusterd_hostname_t *tmp = NULL;
1457
list_for_each_entry_safe(hostname_obj, tmp, hostname_list_head,
1460
list_del_init(&hostname_obj->hostname_list);
1461
GF_FREE(hostname_obj->hostname);
1462
GF_FREE(hostname_obj);
1467
glusterd_handle_upgrade_downgrade(dict_t *options, glusterd_conf_t *conf,
1468
gf_boolean_t upgrade, gf_boolean_t downgrade)
1471
gf_boolean_t regenerate_volfiles = _gf_false;
1472
gf_boolean_t terminate = _gf_false;
1474
if (_gf_true == upgrade)
1475
regenerate_volfiles = _gf_true;
1477
if (upgrade && downgrade) {
1478
gf_msg("glusterd", GF_LOG_ERROR, 0, GD_MSG_WRONG_OPTS_SETTING,
1479
"Both upgrade and downgrade"
1480
" options are set. Only one should be on");
1485
if (!upgrade && !downgrade)
1488
terminate = _gf_true;
1489
if (regenerate_volfiles) {
1490
ret = glusterd_recreate_volfiles(conf);
1493
if (terminate && (ret == 0))
1494
kill(getpid(), SIGTERM);
1508
rpcsvc_t *rpc = NULL;
1509
rpcsvc_t *uds_rpc = NULL;
1510
glusterd_conf_t *conf = NULL;
1511
data_t *dir_data = NULL;
1515
char storedir[PATH_MAX] = {
1518
char workdir[PATH_MAX] = {
1521
char rundir[PATH_MAX] = {
1524
char logdir[VALID_GLUSTERD_PATHMAX] = {
1527
char cmd_log_filename[PATH_MAX] = {
1530
char *mountbroker_root = NULL;
1532
int total_transport = 0;
1533
gf_valgrind_tool vgtool;
1534
char *valgrind_str = NULL;
1535
char *transport_type = NULL;
1536
char var_run_dir[PATH_MAX] = {
1539
int32_t workers = 0;
1540
gf_boolean_t upgrade = _gf_false;
1541
gf_boolean_t downgrade = _gf_false;
1542
char *localtime_logging = NULL;
1551
{ workdir, "vols" },
1553
{ workdir, "snaps" },
1554
{ workdir, "peers" },
1555
{ logdir, "bricks" },
1559
{ workdir, "bitd" },
1560
{ workdir, "scrub" },
1561
{ workdir, "glustershd" },
1562
{ workdir, "quotad" },
1563
{ workdir, "groups" },
1567
#if defined(RUN_WITH_MEMCHECK)
1568
vgtool = _gf_memcheck;
1569
#elif defined(RUN_WITH_DRD)
1575
gf_set_nofile(0, 65536);
1577
dir_data = dict_get(this->options, "run-directory");
1581
len = snprintf(rundir, PATH_MAX, "%s", DEFAULT_VAR_RUN_DIRECTORY);
1583
len = snprintf(rundir, PATH_MAX, "%s", dir_data->data);
1585
if (len < 0 || len >= PATH_MAX)
1588
dir_data = dict_get(this->options, "logging-directory");
1591
dir_data = dict_get(this->options, "cluster-test-mode");
1593
len = snprintf(logdir, VALID_GLUSTERD_PATHMAX, "%s",
1596
this->name, GF_LOG_WARNING, 0, GD_MSG_CLUSTER_RC_ENABLE,
1597
"gluster log directory is set to %s. The option "
1598
"'cluster-test-mode' is deprecated and will be removed soon. "
1599
"Please use the new option 'logging-directory' instead.",
1603
len = snprintf(logdir, VALID_GLUSTERD_PATHMAX, "%s",
1604
DEFAULT_LOG_FILE_DIRECTORY);
1607
len = snprintf(logdir, VALID_GLUSTERD_PATHMAX, "%s", dir_data->data);
1608
gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_CLUSTER_RC_ENABLE,
1609
"gluster log directory is set to %s", dir_data->data);
1611
if (len < 0 || len >= PATH_MAX)
1614
ret = mkdir_p(logdir, 0777, _gf_true);
1615
if ((ret == -1) && (EEXIST != errno)) {
1616
gf_msg(THIS->name, GF_LOG_ERROR, errno, GD_MSG_CREATE_DIR_FAILED,
1617
"Unable to create log dir %s", logdir);
1621
dir_data = dict_get(this->options, "working-directory");
1625
len = snprintf(workdir, PATH_MAX, "%s", GLUSTERD_DEFAULT_WORKDIR);
1627
len = snprintf(workdir, PATH_MAX, "%s", dir_data->data);
1629
if (len < 0 || len >= PATH_MAX)
1632
ret = sys_stat(workdir, &buf);
1633
if ((ret != 0) && (ENOENT != errno)) {
1634
gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_DIR_OP_FAILED,
1635
"stat fails on %s, exiting. (errno = %d)", workdir, errno);
1639
if ((!ret) && (!S_ISDIR(buf.st_mode))) {
1640
gf_msg(this->name, GF_LOG_CRITICAL, ENOENT, GD_MSG_DIR_NOT_FOUND,
1641
"Provided working area %s is not a directory,"
1647
if ((-1 == ret) && (ENOENT == errno)) {
1648
ret = mkdir_p(workdir, 0755, _gf_true);
1651
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
1652
"Unable to create directory %s"
1659
setenv("GLUSTERD_WORKDIR", workdir, 1);
1660
gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_CURR_WORK_DIR_INFO,
1661
"Using %s as working directory", workdir);
1663
setenv("DEFAULT_VAR_RUN_DIRECTORY", rundir, 1);
1664
gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_CURR_WORK_DIR_INFO,
1665
"Using %s as pid file working "
1669
ret = glusterd_find_correct_var_run_dir(this, var_run_dir);
1671
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_VAR_RUN_DIR_FIND_FAIL,
1673
"the correct var run dir");
1677
ret = glusterd_init_var_run_dirs(this, var_run_dir,
1678
GLUSTERD_DEFAULT_SNAPS_BRICK_DIR);
1681
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_CREATE_DIR_FAILED,
1683
"snap backend folder");
1687
len = snprintf(snap_mount_dir, sizeof(snap_mount_dir), "%s%s", var_run_dir,
1688
GLUSTERD_DEFAULT_SNAPS_BRICK_DIR);
1689
if ((len < 0) || (len >= sizeof(snap_mount_dir))) {
1690
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_DIR_OP_FAILED,
1691
"Snap mount dir too long");
1695
ret = mkdir_p(GLUSTER_SHARED_STORAGE_BRICK_DIR, 0755, _gf_true);
1697
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_DIR_OP_FAILED,
1699
"shared storage brick");
1703
ret = glusterd_init_var_run_dirs(this, rundir, GLUSTERD_BITD_RUN_DIR);
1705
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_CREATE_DIR_FAILED,
1707
"bitd running directory");
1711
ret = glusterd_init_var_run_dirs(this, rundir, GLUSTERD_SCRUB_RUN_DIR);
1713
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_CREATE_DIR_FAILED,
1715
"scrub running directory");
1720
ret = glusterd_init_var_run_dirs(this, rundir, GLUSTERD_NFS_RUN_DIR);
1722
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_CREATE_DIR_FAILED,
1724
"nfs running directory");
1729
ret = glusterd_init_var_run_dirs(this, rundir, GLUSTERD_QUOTAD_RUN_DIR);
1731
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_CREATE_DIR_FAILED,
1733
"quota running directory");
1737
snprintf(cmd_log_filename, PATH_MAX, "%s/cmd_history.log", logdir);
1738
ret = gf_cmd_log_init(cmd_log_filename);
1741
gf_msg("this->name", GF_LOG_CRITICAL, errno, GD_MSG_FILE_OP_FAILED,
1742
"Unable to create cmd log file %s", cmd_log_filename);
1747
for (p = dirs; p->base != NULL; p++) {
1748
len = snprintf(storedir, sizeof(storedir), "%s/%s", p->base, p->name);
1750
if (len < 0 || len >= sizeof(storedir)) {
1751
gf_msg(this->name, GF_LOG_CRITICAL, 0, GD_MSG_DIR_OP_FAILED,
1752
"'%s' directory name is too long", p->name);
1756
ret = sys_mkdir(storedir, 0755);
1758
if ((-1 == ret) && (errno != EEXIST)) {
1759
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_CREATE_DIR_FAILED,
1760
"unable to create directory %s", storedir);
1765
ret = glusterd_rpcsvc_options_build(this->options);
1768
rpc = rpcsvc_init(this, this->ctx, this->options, 64);
1770
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_RPC_INIT_FAIL,
1771
"failed to init rpc");
1775
ret = rpcsvc_register_notify(rpc, glusterd_rpcsvc_notify, this);
1777
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_RPCSVC_REG_NOTIFY_RETURNED,
1778
"rpcsvc_register_notify returned %d", ret);
1785
if (this->ctx->secure_mgmt) {
1786
ret = dict_set_str(this->options, "transport.socket.ssl-enabled", "on");
1788
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_SET_FAILED,
1789
"failed to set ssl-enabled in dict");
1796
this->ctx->secure_srvr = MGMT_SSL_ALWAYS;
1804
ret = dict_get_str(this->options, "transport-type", &transport_type);
1806
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
1807
"Failed to get transport type");
1812
total_transport = rpc_transport_count(transport_type);
1813
if (total_transport <= 0) {
1814
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_RPC_TRANSPORT_COUNT_GET_FAIL,
1815
"failed to get total number of available tranpsorts");
1820
ret = rpcsvc_create_listeners(rpc, this->options, this->name);
1822
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_RPC_LISTENER_CREATE_FAIL,
1823
"creation of listener failed");
1826
} else if (ret < total_transport) {
1827
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_RPC_LISTENER_CREATE_FAIL,
1828
"creation of %d listeners failed, continuing with "
1829
"succeeded transport",
1830
(total_transport - ret));
1833
for (i = 0; i < gd_inet_programs_count; i++) {
1834
ret = glusterd_program_register(this, rpc, gd_inet_programs[i]);
1838
rpcsvc_program_unregister(rpc, gd_inet_programs[i]);
1849
uds_rpc = glusterd_init_uds_listener(this);
1850
if (uds_rpc == NULL) {
1855
conf = GF_CALLOC(1, sizeof(glusterd_conf_t), gf_gld_mt_glusterd_conf_t);
1856
GF_VALIDATE_OR_GOTO(this->name, conf, out);
1858
CDS_INIT_LIST_HEAD(&conf->peers);
1859
CDS_INIT_LIST_HEAD(&conf->volumes);
1860
CDS_INIT_LIST_HEAD(&conf->snapshots);
1861
CDS_INIT_LIST_HEAD(&conf->missed_snaps_list);
1862
CDS_INIT_LIST_HEAD(&conf->brick_procs);
1863
CDS_INIT_LIST_HEAD(&conf->shd_procs);
1864
CDS_INIT_LIST_HEAD(&conf->hostnames);
1865
INIT_LIST_HEAD(&conf->remote_hostnames);
1866
pthread_mutex_init(&conf->attach_lock, NULL);
1867
pthread_mutex_init(&conf->volume_lock, NULL);
1869
pthread_mutex_init(&conf->mutex, NULL);
1871
conf->uds_rpc = uds_rpc;
1872
conf->gfs_mgmt = &gd_brick_prog;
1873
conf->restart_shd = _gf_false;
1874
this->private = conf;
1882
if (strlen(workdir) >= sizeof(conf->workdir)) {
1887
(void)strncpy(conf->workdir, workdir, sizeof(conf->workdir));
1889
if (strlen(rundir) >= sizeof(conf->rundir)) {
1894
(void)strncpy(conf->rundir, rundir, sizeof(conf->rundir));
1897
(void)strncpy(conf->logdir, logdir, sizeof(conf->logdir));
1899
synclock_init(&conf->big_lock, SYNC_LOCK_RECURSIVE);
1900
synccond_init(&conf->cond_restart_bricks);
1901
synccond_init(&conf->cond_restart_shd);
1902
synccond_init(&conf->cond_blockers);
1903
pthread_mutex_init(&conf->xprt_lock, NULL);
1904
INIT_LIST_HEAD(&conf->xprt_list);
1905
pthread_mutex_init(&conf->import_volumes, NULL);
1907
glusterd_friend_sm_init();
1908
glusterd_op_sm_init();
1909
glusterd_opinfo_init();
1910
ret = glusterd_sm_tr_log_init(
1911
&conf->op_sm_log, glusterd_op_sm_state_name_get,
1912
glusterd_op_sm_event_name_get, GLUSTERD_TR_LOG_SIZE);
1916
conf->base_port = GF_IANA_PRIV_PORTS_START;
1917
if (dict_get_uint32(this->options, "base-port", &conf->base_port) == 0) {
1918
gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_DICT_SET_FAILED,
1919
"base-port override: %d", conf->base_port);
1921
conf->max_port = GF_PORT_MAX;
1922
if (dict_get_uint32(this->options, "max-port", &conf->max_port) == 0) {
1923
gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_DICT_SET_FAILED,
1924
"max-port override: %d", conf->max_port);
1927
conf->mgmt_v3_lock_timeout = GF_LOCK_TIMER;
1928
if (dict_get_time(this->options, "lock-timer",
1929
&conf->mgmt_v3_lock_timeout) == 0) {
1930
gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_DICT_SET_FAILED,
1931
"lock-timer override: %ld", conf->mgmt_v3_lock_timeout);
1935
this->ctx->cmd_args.vgtool = vgtool;
1936
ret = dict_get_str(this->options, "run-with-valgrind", &valgrind_str);
1938
gf_msg_debug(this->name, 0, "cannot get run-with-valgrind value");
1941
gf_boolean_t vg = _gf_false;
1943
if (!strcmp(valgrind_str, "memcheck"))
1944
this->ctx->cmd_args.vgtool = _gf_memcheck;
1945
else if (!strcmp(valgrind_str, "drd"))
1946
this->ctx->cmd_args.vgtool = _gf_drd;
1947
else if (!gf_string2boolean(valgrind_str, &vg))
1948
this->ctx->cmd_args.vgtool = (vg ? _gf_memcheck : _gf_none);
1950
gf_msg(this->name, GF_LOG_WARNING, EINVAL, GD_MSG_INVALID_ENTRY,
1951
"run-with-valgrind is neither boolean"
1952
" nor one of 'memcheck' or 'drd'");
1956
ret = dict_get_time(this->options, "ping-timeout", &conf->ping_timeout);
1959
glusterd_mgmt_v3_lock_init();
1960
glusterd_mgmt_v3_lock_timer_init();
1961
glusterd_txn_opinfo_dict_init();
1964
glusterd_nfssvc_build(&conf->nfs_svc);
1966
glusterd_quotadsvc_build(&conf->quotad_svc);
1967
glusterd_bitdsvc_build(&conf->bitd_svc);
1968
glusterd_scrubsvc_build(&conf->scrub_svc);
1975
ret = glusterd_hooks_create_hooks_directory(conf->workdir);
1977
gf_msg(this->name, GF_LOG_CRITICAL, errno, GD_MSG_DIR_OP_FAILED,
1978
"Unable to create hooks directory ");
1982
CDS_INIT_LIST_HEAD(&conf->mount_specs);
1984
ret = dict_foreach(this->options, _install_mount_spec, NULL);
1987
ret = dict_get_str(this->options, "mountbroker-root", &mountbroker_root);
1991
ret = check_prepare_mountbroker_root(mountbroker_root);
1995
ret = is_upgrade(this->options, &upgrade);
1999
ret = is_downgrade(this->options, &downgrade);
2003
if (!upgrade && !downgrade) {
2004
ret = configure_syncdaemon(conf);
2018
ret = glusterd_restore_op_version(this);
2020
gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_OP_VERS_RESTORE_FAIL,
2021
"Failed to restore op_version");
2025
ret = glusterd_restore();
2029
if (dict_get_str(conf->opts, GLUSTERD_LOCALTIME_LOGGING_KEY,
2030
&localtime_logging) == 0) {
2031
int already_enabled = gf_log_get_localtime();
2033
if (strcmp(localtime_logging, "enable") == 0) {
2034
gf_log_set_localtime(1);
2035
if (!already_enabled)
2036
gf_msg(this->name, GF_LOG_INFO, 0,
2037
GD_MSG_LOCALTIME_LOGGING_ENABLE,
2038
"localtime logging enable");
2039
} else if (strcmp(localtime_logging, "disable") == 0) {
2040
gf_log_set_localtime(0);
2041
if (already_enabled)
2042
gf_msg(this->name, GF_LOG_INFO, 0,
2043
GD_MSG_LOCALTIME_LOGGING_DISABLE,
2044
"localtime logging disable");
2048
GF_ATOMIC_INIT(conf->blockers, 0);
2049
ret = glusterd_handle_upgrade_downgrade(this->options, conf, upgrade,
2054
ret = glusterd_retrieve_max_op_version(this, &op_version);
2060
if (op_version == 0 || op_version != GD_OP_VERSION_MAX) {
2061
gf_log(this->name, GF_LOG_INFO,
2062
"Regenerating volfiles due to a max op-version mismatch or "
2063
"glusterd.upgrade file not being present, op_version retrieved:"
2064
"%d, max op_version: %d",
2065
op_version, GD_OP_VERSION_MAX);
2066
glusterd_recreate_volfiles(conf);
2067
ret = glusterd_store_max_op_version(this);
2069
gf_log(this->name, GF_LOG_ERROR, "Failed to store max op-version");
2075
if (glusterd_get_peers_count() < 2)
2076
glusterd_launch_synctask(glusterd_spawn_daemons, NULL);
2078
ret = glusterd_hooks_spawn_worker(this);
2082
GF_OPTION_INIT("event-threads", workers, int32, out);
2083
if (workers > 0 && workers != conf->workers) {
2084
conf->workers = workers;
2085
ret = gf_event_reconfigure_threads(this->ctx->event_pool, workers);
2093
if (this->private != NULL) {
2094
GF_FREE(this->private);
2095
this->private = NULL;
2112
if (!this || !this->private)
2115
glusterd_conf_t *priv = NULL;
2116
priv = this->private;
2118
glusterd_stop_uds_listener(this);
2119
glusterd_stop_listener(this);
2120
glusterd_destroy_hostname_list(&priv->hostnames);
2121
glusterd_destroy_hostname_list(
2122
&priv->remote_hostnames);
2132
GF_FREE (conf->uds_rpc);
2133
GF_FREE (conf->rpc);
2136
gf_store_handle_destroy (conf->handle);
2137
glusterd_sm_tr_log_delete (&conf->op_sm_log);
2138
glusterd_mgmt_v3_lock_fini ();
2139
glusterd_mgmt_v3_lock_timer_fini ();
2140
glusterd_txn_opinfo_dict_fini ();
2143
this->private = NULL;
2157
notify(xlator_t *this, int32_t event, void *data, ...)
2162
case GF_EVENT_POLLIN:
2165
case GF_EVENT_POLLERR:
2168
case GF_EVENT_CLEANUP:
2172
default_notify(this, event, data);
2179
struct xlator_fops fops;
2181
struct xlator_cbks cbks;
2183
struct xlator_dumpops dumpops = {
2184
.priv = glusterd_dump_priv,
2187
struct volume_options options[] = {
2189
.key = {"working-directory"},
2190
.type = GF_OPTION_TYPE_PATH,
2193
.key = {"transport-type"},
2194
.type = GF_OPTION_TYPE_ANY,
2197
.key = {"transport.*"},
2198
.type = GF_OPTION_TYPE_ANY,
2201
.key = {"rpc-auth.*"},
2202
.type = GF_OPTION_TYPE_ANY,
2205
.key = {"rpc-auth-allow-insecure"},
2206
.type = GF_OPTION_TYPE_BOOL,
2210
.type = GF_OPTION_TYPE_BOOL,
2213
.key = {"downgrade"},
2214
.type = GF_OPTION_TYPE_BOOL,
2217
.key = {"bind-insecure"},
2218
.type = GF_OPTION_TYPE_BOOL,
2221
.key = {"mountbroker-root"},
2222
.type = GF_OPTION_TYPE_PATH,
2225
.key = {"mountbroker.*"},
2226
.type = GF_OPTION_TYPE_ANY,
2229
.key = {"mountbroker-" GEOREP ".*"},
2230
.type = GF_OPTION_TYPE_ANY,
2233
.key = {GEOREP "-log-group"},
2234
.type = GF_OPTION_TYPE_ANY,
2237
.key = {"run-with-valgrind"},
2238
.type = GF_OPTION_TYPE_BOOL,
2240
{.key = {"server-quorum-type"},
2241
.type = GF_OPTION_TYPE_STR,
2242
.value = {"none", "server"},
2243
.default_value = "none",
2244
.description = "It can be set to none or server. When set to server, "
2245
"this option enables the specified volume to "
2246
"participate in the server-side quorum. "
2247
"This feature is on the server-side i.e. in glusterd. "
2248
"Whenever the glusterd on a machine observes that "
2249
"the quorum is not met, it brings down the bricks to "
2250
"prevent data split-brains. When the network "
2251
"connections are brought back up and the quorum is "
2252
"restored the bricks in "
2253
"the volume are brought back up."},
2254
{.key = {"server-quorum-ratio"},
2255
.type = GF_OPTION_TYPE_PERCENT,
2256
.description = "Sets the quorum percentage for the trusted "
2258
{.key = {"glusterd-sockfile"},
2259
.type = GF_OPTION_TYPE_PATH,
2260
.description = "The socket file on which glusterd should listen for "
2261
"cli requests. Default is " DEFAULT_GLUSTERD_SOCKFILE "."},
2262
{.key = {"base-port"},
2263
.type = GF_OPTION_TYPE_INT,
2264
.description = "Sets the base port for portmap query"},
2265
{.key = {"max-port"},
2266
.type = GF_OPTION_TYPE_INT,
2268
.description = "Sets the max port for portmap query"},
2269
{.key = {"mgmt-v3-lock-timeout"},
2270
.type = GF_OPTION_TYPE_INT,
2272
.description = "Sets the mgmt-v3-lock-timeout for transactions."
2273
"Specifes the default timeout value after which "
2274
"lock acquired while performing transaction will "
2276
{.key = {"snap-brick-path"},
2277
.type = GF_OPTION_TYPE_STR,
2279
"directory where the bricks for the snapshots will be created"},
2281
.key = {"ping-timeout"},
2282
.type = GF_OPTION_TYPE_TIME,
2285
.default_value = TOSTRING(RPC_DEFAULT_PING_TIMEOUT),
2287
{.key = {"event-threads"},
2288
.type = GF_OPTION_TYPE_INT,
2289
.min = GLUSTERD_MIN_EVENT_THREADS,
2290
.max = GLUSTERD_MAX_EVENT_THREADS,
2291
.default_value = TOSTRING(STARTING_EVENT_THREADS),
2292
.description = "Specifies the number of event threads to execute "
2293
"in parallel. Larger values would help process"
2294
" responses faster, depending on available processing"
2295
" power. Range 1-32 threads."},
2299
xlator_api_t xlator_api = {
2302
.mem_acct_init = mem_acct_init,
2304
.dumpops = &dumpops,
2308
.identifier = "glusterd",
2309
.category = GF_MAINTAINED,