glusterfs

Форк
0
/
glfs-primary.c 
181 строка · 4.0 Кб
1
/*
2
  Copyright (c) 2012-2016 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 <stdio.h>
12

13
#include "glfs-internal.h"
14
#include "glfs-mem-types.h"
15
#include "gfapi-messages.h"
16

17
int
18
graph_setup(struct glfs *fs, glusterfs_graph_t *graph)
19
{
20
    xlator_t *new_subvol = NULL;
21
    xlator_t *old_subvol = NULL;
22
    inode_table_t *itable = NULL;
23
    int ret = -1;
24

25
    new_subvol = graph->top;
26

27
    /* This is called in a bottom-up context, it should specifically
28
       NOT be glfs_lock()
29
    */
30
    pthread_mutex_lock(&fs->mutex);
31
    {
32
        if (new_subvol->switched || new_subvol == fs->active_subvol ||
33
            new_subvol == fs->next_subvol || new_subvol == fs->mip_subvol) {
34
            /* Spurious CHILD_UP event on old graph */
35
            ret = 0;
36
            goto unlock;
37
        }
38

39
        if (!new_subvol->itable) {
40
            itable = inode_table_new(131072, new_subvol, 0, 0);
41
            if (!itable) {
42
                errno = ENOMEM;
43
                ret = -1;
44
                goto unlock;
45
            }
46

47
            new_subvol->itable = itable;
48
        }
49

50
        old_subvol = fs->next_subvol;
51
        fs->next_subvol = new_subvol;
52
        fs->next_subvol->winds++; /* first ref */
53
        ret = 0;
54
    }
55
unlock:
56
    pthread_mutex_unlock(&fs->mutex);
57

58
    if (old_subvol)
59
        /* wasn't picked up so far, skip */
60
        glfs_subvol_done(fs, old_subvol);
61

62
    return ret;
63
}
64

65
int
66
notify(xlator_t *this, int event, void *data, ...)
67
{
68
    glusterfs_graph_t *graph = NULL;
69
    struct glfs *fs = NULL;
70

71
    graph = data;
72
    fs = this->private;
73

74
    switch (event) {
75
        case GF_EVENT_GRAPH_NEW:
76
            gf_smsg(this->name, GF_LOG_INFO, 0, API_MSG_NEW_GRAPH,
77
                    "graph-uuid=%s",
78
                    uuid_utoa((unsigned char *)graph->graph_uuid), "id=%d",
79
                    graph->id, NULL);
80
            break;
81
        case GF_EVENT_CHILD_UP:
82
            pthread_mutex_lock(&fs->mutex);
83
            {
84
                graph->used = 1;
85
            }
86
            pthread_mutex_unlock(&fs->mutex);
87
            graph_setup(fs, graph);
88
            glfs_init_done(fs, 0);
89
            break;
90
        case GF_EVENT_CHILD_DOWN:
91
            pthread_mutex_lock(&fs->mutex);
92
            {
93
                graph->used = 0;
94
                pthread_cond_broadcast(&fs->child_down_cond);
95
            }
96
            pthread_mutex_unlock(&fs->mutex);
97
            glfs_init_done(fs, 1);
98
            break;
99
        case GF_EVENT_CHILD_CONNECTING:
100
            break;
101
        case GF_EVENT_UPCALL:
102
            glfs_process_upcall_event(fs, data);
103
            break;
104
        default:
105
            gf_msg_debug(this->name, 0, "got notify event %d", event);
106
            break;
107
    }
108

109
    return 0;
110
}
111

112
int
113
mem_acct_init(xlator_t *this)
114
{
115
    int ret = -1;
116

117
    if (!this)
118
        return ret;
119

120
    ret = xlator_mem_acct_init(this, glfs_mt_end + 1);
121
    if (ret) {
122
        gf_smsg(this->name, GF_LOG_ERROR, ENOMEM, API_MSG_MEM_ACCT_INIT_FAILED,
123
                NULL);
124
        return ret;
125
    }
126

127
    return 0;
128
}
129

130
int
131
init(xlator_t *this)
132
{
133
    return 0;
134
}
135

136
void
137
fini(xlator_t *this)
138
{
139
}
140

141
/* place-holder fops */
142
int
143
glfs_forget(xlator_t *this, inode_t *inode)
144
{
145
    return 0;
146
}
147

148
int
149
glfs_release(xlator_t *this, fd_t *fd)
150
{
151
    return 0;
152
}
153

154
int
155
glfs_releasedir(xlator_t *this, fd_t *fd)
156
{
157
    return 0;
158
}
159

160
struct xlator_dumpops dumpops;
161

162
struct xlator_fops fops;
163

164
struct xlator_cbks cbks = {
165
    .forget = glfs_forget,
166
    .release = glfs_release,
167
    .releasedir = glfs_releasedir,
168
};
169

170
xlator_api_t xlator_api = {
171
    .init = init,
172
    .fini = fini,
173
    .notify = notify,
174
    .mem_acct_init = mem_acct_init,
175
    .op_version = {1},
176
    .dumpops = &dumpops,
177
    .fops = &fops,
178
    .cbks = &cbks,
179
    .identifier = "glfs-api",
180
    .category = GF_MAINTAINED,
181
};
182

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

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

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

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