glusterfs

Форк
0
/
glusterd-nfs-svc.c 
225 строк · 5.7 Кб
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
#ifdef BUILD_GNFS
12

13
#include <glusterfs/globals.h>
14
#include <glusterfs/run.h>
15
#include <glusterfs/syscall.h>
16
#include "glusterd.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"
22

23
static gf_boolean_t
24
glusterd_nfssvc_need_start(void)
25
{
26
    glusterd_conf_t *priv = NULL;
27
    gf_boolean_t start = _gf_false;
28
    glusterd_volinfo_t *volinfo = NULL;
29

30
    priv = THIS->private;
31

32
    cds_list_for_each_entry(volinfo, &priv->volumes, vol_list)
33
    {
34
        if (!glusterd_is_volume_started(volinfo))
35
            continue;
36

37
        if (dict_get_str_boolean(volinfo->dict, NFS_DISABLE_MAP_KEY, 1))
38
            continue;
39
        start = _gf_true;
40
        break;
41
    }
42

43
    return start;
44
}
45

46
static int
47
glusterd_nfssvc_create_volfile(void)
48
{
49
    char filepath[PATH_MAX] = {
50
        0,
51
    };
52
    glusterd_conf_t *conf = THIS->private;
53

54
    glusterd_svc_build_volfile_path(conf->nfs_svc.name, conf->workdir, filepath,
55
                                    sizeof(filepath));
56
    return glusterd_create_global_volfile(build_nfs_graph, filepath, NULL);
57
}
58

59
static int
60
glusterd_nfssvc_manager(glusterd_svc_t *svc, void *data, int flags)
61
{
62
    int ret = -1;
63

64
    if (!svc->inited) {
65
        ret = glusterd_svc_init(svc, "nfs");
66
        if (ret) {
67
            gf_msg(THIS->name, GF_LOG_ERROR, 0, GD_MSG_FAILED_INIT_NFSSVC,
68
                   "Failed to init nfs service");
69
            goto out;
70
        } else {
71
            svc->inited = _gf_true;
72
            gf_msg_debug(THIS->name, 0, "nfs service initialized");
73
        }
74
    }
75

76
    ret = svc->stop(svc, SIGKILL);
77
    if (ret)
78
        goto out;
79

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");
84
        goto out;
85
    }
86

87
    ret = glusterd_nfssvc_create_volfile();
88
    if (ret)
89
        goto out;
90

91
    if (glusterd_nfssvc_need_start()) {
92
        ret = svc->start(svc, flags);
93
        if (ret)
94
            goto out;
95

96
        ret = glusterd_conn_connect(&(svc->conn));
97
        if (ret)
98
            goto out;
99
    }
100
out:
101
    if (ret)
102
        gf_event(EVENT_SVC_MANAGER_FAILED, "svc_name=%s", svc->name);
103

104
    gf_msg_debug(THIS->name, 0, "Returning %d", ret);
105

106
    return ret;
107
}
108

109
static int
110
glusterd_nfssvc_start(glusterd_svc_t *svc, int flags)
111
{
112
    return glusterd_svc_start(svc, flags, NULL);
113
}
114

115
static int
116
glusterd_nfssvc_stop(glusterd_svc_t *svc, int sig)
117
{
118
    int ret = -1;
119
    gf_boolean_t deregister = _gf_false;
120

121
    if (glusterd_proc_is_running(&(svc->proc)))
122
        deregister = _gf_true;
123

124
    ret = glusterd_svc_stop(svc, sig);
125
    if (ret)
126
        goto out;
127
    if (deregister)
128
        glusterd_nfs_pmap_deregister();
129

130
out:
131
    gf_msg_debug(THIS->name, 0, "Returning %d", ret);
132

133
    return ret;
134
}
135

136
void
137
glusterd_nfssvc_build(glusterd_svc_t *svc)
138
{
139
    svc->manager = glusterd_nfssvc_manager;
140
    svc->start = glusterd_nfssvc_start;
141
    svc->stop = glusterd_nfssvc_stop;
142
}
143

144
int
145
glusterd_nfssvc_reconfigure(void)
146
{
147
    int ret = -1;
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;
153

154
    priv = this->private;
155
    GF_VALIDATE_OR_GOTO(this->name, priv, out);
156

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");
161
        ret = 0;
162
        goto out;
163
    }
164

165
    cds_list_for_each_entry(volinfo, &priv->volumes, vol_list)
166
    {
167
        if (GLUSTERD_STATUS_STARTED == volinfo->status) {
168
            vol_started = _gf_true;
169
            break;
170
        }
171
    }
172
    if (!vol_started) {
173
        ret = 0;
174
        goto out;
175
    }
176

177
    /*
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.
181
     */
182

183
    ret = glusterd_svc_check_volfile_identical(priv->nfs_svc.name,
184
                                               build_nfs_graph, &identical);
185
    if (ret)
186
        goto out;
187

188
    if (identical) {
189
        ret = 0;
190
        goto out;
191
    }
192

193
    /*
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.
197
     */
198
    identical = _gf_false; /* RESET the FLAG */
199
    ret = glusterd_svc_check_topology_identical(priv->nfs_svc.name,
200
                                                build_nfs_graph, &identical);
201
    if (ret)
202
        goto out;
203

204
    /* Topology is not changed, but just the options. But write the
205
     * options to NFS volfile, so that NFS will be reconfigured.
206
     */
207
    if (identical) {
208
        ret = glusterd_nfssvc_create_volfile();
209
        if (ret == 0) { /* Only if above PASSES */
210
            ret = glusterd_fetchspec_notify(THIS);
211
        }
212
        goto out;
213
    }
214

215
    /*
216
     * NFS volfile's topology has been changed. NFS server needs
217
     * to be RESTARTED to ACT on the changed volfile.
218
     */
219
    ret = priv->nfs_svc.manager(&(priv->nfs_svc), NULL, PROC_START_NO_WAIT);
220

221
out:
222
    gf_msg_debug(this->name, 0, "Returning %d", ret);
223
    return ret;
224
}
225
#endif
226

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

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

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

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