glusterfs

Форк
0
/
glusterd-bitd-svc.c 
173 строки · 4.5 Кб
1
/*
2
  Copyright (c) 2006-2012 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-bitd-svc.h"
16
#include "glusterd-svc-helper.h"
17

18
void
19
glusterd_bitdsvc_build(glusterd_svc_t *svc)
20
{
21
    svc->manager = glusterd_bitdsvc_manager;
22
    svc->start = glusterd_genericsvc_start;
23
    svc->stop = glusterd_bitdsvc_stop;
24
}
25

26
int
27
glusterd_bitdsvc_init(glusterd_svc_t *svc)
28
{
29
    return glusterd_svc_init(svc, bitd_svc_name);
30
}
31

32
static int
33
glusterd_bitdsvc_create_volfile(void)
34
{
35
    char filepath[PATH_MAX] = {
36
        0,
37
    };
38
    int ret = -1;
39
    glusterd_conf_t *conf = NULL;
40
    xlator_t *this = THIS;
41

42
    conf = this->private;
43
    GF_ASSERT(conf);
44

45
    glusterd_svc_build_volfile_path(bitd_svc_name, conf->workdir, filepath,
46
                                    sizeof(filepath));
47

48
    ret = glusterd_create_global_volfile(build_bitd_graph, filepath, NULL);
49
    if (ret) {
50
        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLFILE_CREATE_FAIL,
51
               "Failed to create volfile");
52
    }
53

54
    gf_msg_debug(this->name, 0, "Returning %d", ret);
55
    return ret;
56
}
57

58
int
59
glusterd_bitdsvc_manager(glusterd_svc_t *svc, void *data, int flags)
60
{
61
    int ret = 0;
62
    xlator_t *this = THIS;
63

64
    if (!svc->inited) {
65
        ret = glusterd_bitdsvc_init(svc);
66
        if (ret) {
67
            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BITD_INIT_FAIL,
68
                   "Failed to init "
69
                   "bitd service");
70
            goto out;
71
        } else {
72
            svc->inited = _gf_true;
73
            gf_msg_debug(this->name, 0,
74
                         "BitD service "
75
                         "initialized");
76
        }
77
    }
78

79
    if (glusterd_should_i_stop_bitd()) {
80
        ret = svc->stop(svc, SIGTERM);
81
    } else {
82
        ret = glusterd_bitdsvc_create_volfile();
83
        if (ret)
84
            goto out;
85

86
        ret = svc->stop(svc, SIGKILL);
87
        if (ret)
88
            goto out;
89

90
        ret = svc->start(svc, flags);
91
        if (ret)
92
            goto out;
93

94
        ret = glusterd_conn_connect(&(svc->conn));
95
        if (ret)
96
            goto out;
97
    }
98

99
out:
100
    if (ret)
101
        gf_event(EVENT_SVC_MANAGER_FAILED, "svc_name=%s", svc->name);
102

103
    gf_msg_debug(this->name, 0, "Returning %d", ret);
104

105
    return ret;
106
}
107

108
int
109
glusterd_bitdsvc_stop(glusterd_svc_t *svc, int sig)
110
{
111
    return glusterd_svc_stop(svc, sig);
112
}
113

114
int
115
glusterd_bitdsvc_reconfigure(void)
116
{
117
    int ret = -1;
118
    xlator_t *this = THIS;
119
    glusterd_conf_t *priv = NULL;
120
    gf_boolean_t identical = _gf_false;
121

122
    priv = this->private;
123
    GF_VALIDATE_OR_GOTO(this->name, priv, out);
124

125
    if (glusterd_should_i_stop_bitd())
126
        goto manager;
127
    /*
128
     * Check both OLD and NEW volfiles, if they are SAME by size
129
     * and cksum i.e. "character-by-character". If YES, then
130
     * NOTHING has been changed, just return.
131
     */
132
    ret = glusterd_svc_check_volfile_identical(priv->bitd_svc.name,
133
                                               build_bitd_graph, &identical);
134
    if (ret)
135
        goto out;
136
    if (identical) {
137
        ret = 0;
138
        goto out;
139
    }
140

141
    /*
142
     * They are not identical. Find out if the topology is changed
143
     * OR just the volume options. If just the options which got
144
     * changed, then inform the xlator to reconfigure the options.
145
     */
146
    identical = _gf_false; /* RESET the FLAG */
147
    ret = glusterd_svc_check_topology_identical(priv->bitd_svc.name,
148
                                                build_bitd_graph, &identical);
149
    if (ret)
150
        goto out; /*not able to compare due to some corruption */
151

152
    /* Topology is not changed, but just the options. But write the
153
     * options to bitd volfile, so that bitd will be reconfigured.
154
     */
155
    if (identical) {
156
        ret = glusterd_bitdsvc_create_volfile();
157
        if (ret == 0) { /* Only if above PASSES */
158
            ret = glusterd_fetchspec_notify(THIS);
159
        }
160
        goto out;
161
    }
162

163
manager:
164
    /*
165
     * bitd volfile's topology has been changed. bitd server needs
166
     * to be RESTARTED to ACT on the changed volfile.
167
     */
168
    ret = priv->bitd_svc.manager(&(priv->bitd_svc), NULL, PROC_START_NO_WAIT);
169

170
out:
171
    gf_msg_debug(this->name, 0, "Returning %d", ret);
172
    return ret;
173
}
174

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

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

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

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