glusterfs

Форк
0
/
glusterd-scrub-svc.c 
179 строк · 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-scrub-svc.h"
16
#include "glusterd-svc-helper.h"
17

18
char *scrub_svc_name = "scrub";
19

20
void
21
glusterd_scrubsvc_build(glusterd_svc_t *svc)
22
{
23
    svc->manager = glusterd_scrubsvc_manager;
24
    svc->start = glusterd_genericsvc_start;
25
    svc->stop = glusterd_scrubsvc_stop;
26
}
27

28
int
29
glusterd_scrubsvc_init(glusterd_svc_t *svc)
30
{
31
    return glusterd_svc_init(svc, scrub_svc_name);
32
}
33

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

44
    conf = this->private;
45
    GF_ASSERT(conf);
46

47
    glusterd_svc_build_volfile_path(scrub_svc_name, conf->workdir, filepath,
48
                                    sizeof(filepath));
49

50
    ret = glusterd_create_global_volfile(build_scrub_graph, filepath, NULL);
51
    if (ret) {
52
        gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_VOLFILE_CREATE_FAIL,
53
               "Failed to create volfile");
54
        goto out;
55
    }
56

57
out:
58
    gf_msg_debug(this->name, 0, "Returning %d", ret);
59

60
    return ret;
61
}
62

63
int
64
glusterd_scrubsvc_manager(glusterd_svc_t *svc, void *data, int flags)
65
{
66
    int ret = -EINVAL;
67
    xlator_t *this = THIS;
68

69
    if (!svc->inited) {
70
        ret = glusterd_scrubsvc_init(svc);
71
        if (ret) {
72
            gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_SCRUB_INIT_FAIL,
73
                   "Failed to init "
74
                   "scrub service");
75
            goto out;
76
        } else {
77
            svc->inited = _gf_true;
78
            gf_msg_debug(this->name, 0,
79
                         "scrub service "
80
                         "initialized");
81
        }
82
    }
83

84
    if (glusterd_should_i_stop_bitd()) {
85
        ret = svc->stop(svc, SIGTERM);
86
    } else {
87
        ret = glusterd_scrubsvc_create_volfile();
88
        if (ret)
89
            goto out;
90

91
        ret = svc->stop(svc, SIGKILL);
92
        if (ret)
93
            goto out;
94

95
        ret = svc->start(svc, flags);
96
        if (ret)
97
            goto out;
98

99
        ret = glusterd_conn_connect(&(svc->conn));
100
        if (ret)
101
            goto out;
102
    }
103

104
out:
105
    if (ret)
106
        gf_event(EVENT_SVC_MANAGER_FAILED, "svc_name=%s", svc->name);
107
    gf_msg_debug(this->name, 0, "Returning %d", ret);
108

109
    return ret;
110
}
111

112
int
113
glusterd_scrubsvc_stop(glusterd_svc_t *svc, int sig)
114
{
115
    return glusterd_svc_stop(svc, sig);
116
}
117

118
int
119
glusterd_scrubsvc_reconfigure(void)
120
{
121
    int ret = -1;
122
    xlator_t *this = THIS;
123
    glusterd_conf_t *priv = NULL;
124
    gf_boolean_t identical = _gf_false;
125

126
    priv = this->private;
127
    GF_VALIDATE_OR_GOTO(this->name, priv, out);
128

129
    if (glusterd_should_i_stop_bitd())
130
        goto manager;
131

132
    /*
133
     * Check both OLD and NEW volfiles, if they are SAME by size
134
     * and cksum i.e. "character-by-character". If YES, then
135
     * NOTHING has been changed, just return.
136
     */
137
    ret = glusterd_svc_check_volfile_identical(priv->scrub_svc.name,
138
                                               build_scrub_graph, &identical);
139
    if (ret)
140
        goto out;
141

142
    if (identical) {
143
        ret = 0;
144
        goto out;
145
    }
146

147
    /*
148
     * They are not identical. Find out if the topology is changed
149
     * OR just the volume options. If just the options which got
150
     * changed, then inform the xlator to reconfigure the options.
151
     */
152
    identical = _gf_false; /* RESET the FLAG */
153
    ret = glusterd_svc_check_topology_identical(priv->scrub_svc.name,
154
                                                build_scrub_graph, &identical);
155
    if (ret)
156
        goto out;
157

158
    /* Topology is not changed, but just the options. But write the
159
     * options to scrub volfile, so that scrub will be reconfigured.
160
     */
161
    if (identical) {
162
        ret = glusterd_scrubsvc_create_volfile();
163
        if (ret == 0) { /* Only if above PASSES */
164
            ret = glusterd_fetchspec_notify(THIS);
165
        }
166
        goto out;
167
    }
168

169
manager:
170
    /*
171
     * scrub volfile's topology has been changed. scrub server needs
172
     * to be RESTARTED to ACT on the changed volfile.
173
     */
174
    ret = priv->scrub_svc.manager(&(priv->scrub_svc), NULL, PROC_START_NO_WAIT);
175

176
out:
177
    gf_msg_debug(this->name, 0, "Returning %d", ret);
178
    return ret;
179
}
180

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

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

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

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