2
Copyright (c) 2014 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.
13
#include <glusterfs/globals.h>
14
#include <glusterfs/run.h>
15
#include <glusterfs/syscall.h>
17
#include "glusterd-utils.h"
18
#include "glusterd-volgen.h"
19
#include "glusterd-nfs-svc.h"
20
#include "glusterd-messages.h"
21
#include "glusterd-svc-helper.h"
24
glusterd_nfssvc_need_start(void)
26
glusterd_conf_t *priv = NULL;
27
gf_boolean_t start = _gf_false;
28
glusterd_volinfo_t *volinfo = NULL;
32
cds_list_for_each_entry(volinfo, &priv->volumes, vol_list)
34
if (!glusterd_is_volume_started(volinfo))
37
if (dict_get_str_boolean(volinfo->dict, NFS_DISABLE_MAP_KEY, 1))
47
glusterd_nfssvc_create_volfile(void)
49
char filepath[PATH_MAX] = {
52
glusterd_conf_t *conf = THIS->private;
54
glusterd_svc_build_volfile_path(conf->nfs_svc.name, conf->workdir, filepath,
56
return glusterd_create_global_volfile(build_nfs_graph, filepath, NULL);
60
glusterd_nfssvc_manager(glusterd_svc_t *svc, void *data, int flags)
65
ret = glusterd_svc_init(svc, "nfs");
67
gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_FAILED_INIT_NFSSVC,
68
"Failed to init nfs service");
71
svc->inited = _gf_true;
72
gf_msg_debug(THIS->name, 0, "nfs service initialized");
76
ret = svc->stop(svc, SIGKILL);
80
/* not an error, or a (very) soft error at best */
81
if (sys_access(XLATORDIR "/nfs/server.so", R_OK) != 0) {
82
gf_msg(THIS->name, GF_LOG_INFO, 0, GD_MSG_GNFS_XLATOR_NOT_INSTALLED,
83
"nfs/server.so xlator is not installed");
87
ret = glusterd_nfssvc_create_volfile();
91
if (glusterd_nfssvc_need_start()) {
92
ret = svc->start(svc, flags);
96
ret = glusterd_conn_connect(&(svc->conn));
102
gf_event(EVENT_SVC_MANAGER_FAILED, "svc_name=%s", svc->name);
104
gf_msg_debug(THIS->name, 0, "Returning %d", ret);
110
glusterd_nfssvc_start(glusterd_svc_t *svc, int flags)
112
return glusterd_svc_start(svc, flags, NULL);
116
glusterd_nfssvc_stop(glusterd_svc_t *svc, int sig)
119
gf_boolean_t deregister = _gf_false;
121
if (glusterd_proc_is_running(&(svc->proc)))
122
deregister = _gf_true;
124
ret = glusterd_svc_stop(svc, sig);
128
glusterd_nfs_pmap_deregister();
131
gf_msg_debug(THIS->name, 0, "Returning %d", ret);
137
glusterd_nfssvc_build(glusterd_svc_t *svc)
139
svc->manager = glusterd_nfssvc_manager;
140
svc->start = glusterd_nfssvc_start;
141
svc->stop = glusterd_nfssvc_stop;
145
glusterd_nfssvc_reconfigure(void)
148
xlator_t *this = THIS;
149
glusterd_conf_t *priv = NULL;
150
gf_boolean_t identical = _gf_false;
151
gf_boolean_t vol_started = _gf_false;
152
glusterd_volinfo_t *volinfo = NULL;
154
priv = this->private;
155
GF_VALIDATE_OR_GOTO(this->name, priv, out);
157
/* not an error, or a (very) soft error at best */
158
if (sys_access(XLATORDIR "/nfs/server.so", R_OK) != 0) {
159
gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_GNFS_XLATOR_NOT_INSTALLED,
160
"nfs/server.so xlator is not installed");
165
cds_list_for_each_entry(volinfo, &priv->volumes, vol_list)
167
if (GLUSTERD_STATUS_STARTED == volinfo->status) {
168
vol_started = _gf_true;
178
* Check both OLD and NEW volfiles, if they are SAME by size
179
* and cksum i.e. "character-by-character". If YES, then
180
* NOTHING has been changed, just return.
183
ret = glusterd_svc_check_volfile_identical(priv->nfs_svc.name,
184
build_nfs_graph, &identical);
194
* They are not identical. Find out if the topology is changed
195
* OR just the volume options. If just the options which got
196
* changed, then inform the xlator to reconfigure the options.
198
identical = _gf_false; /* RESET the FLAG */
199
ret = glusterd_svc_check_topology_identical(priv->nfs_svc.name,
200
build_nfs_graph, &identical);
204
/* Topology is not changed, but just the options. But write the
205
* options to NFS volfile, so that NFS will be reconfigured.
208
ret = glusterd_nfssvc_create_volfile();
209
if (ret == 0) { /* Only if above PASSES */
210
ret = glusterd_fetchspec_notify(THIS);
216
* NFS volfile's topology has been changed. NFS server needs
217
* to be RESTARTED to ACT on the changed volfile.
219
ret = priv->nfs_svc.manager(&(priv->nfs_svc), NULL, PROC_START_NO_WAIT);
222
gf_msg_debug(this->name, 0, "Returning %d", ret);