glusterfs

Форк
0
/
defaults-tmpl.c 
247 строк · 7.1 Кб
1
/*
2
  Copyright (c) 2008-2015 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
/* libglusterfs/src/defaults.c:
12
   This file contains functions, which are used to fill the 'fops', 'cbk'
13
   structures in the xlator structures, if they are not written. Here, all the
14
   function calls are plainly forwarded to the first child of the xlator, and
15
   all the *_cbk function does plain STACK_UNWIND of the frame, and returns.
16

17
   This function also implements *_resume () functions, which does same
18
   operation as a fop().
19

20
   All the functions are plain enough to understand.
21
*/
22

23
#ifndef _CONFIG_H
24
#define _CONFIG_H
25
#include "config.h"
26
#endif
27

28
#include "glusterfs/defaults.h"
29

30
#pragma generate
31

32
struct xlator_fops _default_fops = {
33
    .create = default_create,
34
    .open = default_open,
35
    .stat = default_stat,
36
    .readlink = default_readlink,
37
    .mknod = default_mknod,
38
    .mkdir = default_mkdir,
39
    .unlink = default_unlink,
40
    .rmdir = default_rmdir,
41
    .symlink = default_symlink,
42
    .rename = default_rename,
43
    .link = default_link,
44
    .truncate = default_truncate,
45
    .readv = default_readv,
46
    .writev = default_writev,
47
    .statfs = default_statfs,
48
    .flush = default_flush,
49
    .fsync = default_fsync,
50
    .setxattr = default_setxattr,
51
    .getxattr = default_getxattr,
52
    .fsetxattr = default_fsetxattr,
53
    .fgetxattr = default_fgetxattr,
54
    .removexattr = default_removexattr,
55
    .fremovexattr = default_fremovexattr,
56
    .opendir = default_opendir,
57
    .readdir = default_readdir,
58
    .readdirp = default_readdirp,
59
    .fsyncdir = default_fsyncdir,
60
    .access = default_access,
61
    .ftruncate = default_ftruncate,
62
    .fstat = default_fstat,
63
    .lk = default_lk,
64
    .inodelk = default_inodelk,
65
    .finodelk = default_finodelk,
66
    .entrylk = default_entrylk,
67
    .fentrylk = default_fentrylk,
68
    .lookup = default_lookup,
69
    .rchecksum = default_rchecksum,
70
    .xattrop = default_xattrop,
71
    .fxattrop = default_fxattrop,
72
    .setattr = default_setattr,
73
    .fsetattr = default_fsetattr,
74
    .fallocate = default_fallocate,
75
    .discard = default_discard,
76
    .zerofill = default_zerofill,
77
    .ipc = default_ipc,
78
    .seek = default_seek,
79

80
    .getspec = default_getspec,
81
    .getactivelk = default_getactivelk,
82
    .setactivelk = default_setactivelk,
83
    .put = default_put,
84
    .icreate = default_icreate,
85
    .namelink = default_namelink,
86
    .copy_file_range = default_copy_file_range,
87
};
88
struct xlator_fops *default_fops = &_default_fops;
89

90
/*
91
 * Remaining functions don't follow the fop calling conventions, so they're
92
 * not generated.
93
 */
94

95
int32_t
96
default_forget(xlator_t *this, inode_t *inode)
97
{
98
    gf_log_callingfn(this->name, GF_LOG_DEBUG,
99
                     "xlator does not "
100
                     "implement forget_cbk");
101
    return 0;
102
}
103

104
int32_t
105
default_releasedir(xlator_t *this, fd_t *fd)
106
{
107
    gf_log_callingfn(this->name, GF_LOG_DEBUG,
108
                     "xlator does not "
109
                     "implement releasedir_cbk");
110
    return 0;
111
}
112

113
int32_t
114
default_release(xlator_t *this, fd_t *fd)
115
{
116
    gf_log_callingfn(this->name, GF_LOG_DEBUG,
117
                     "xlator does not "
118
                     "implement release_cbk");
119
    return 0;
120
}
121

122
/* notify */
123
int
124
default_notify(xlator_t *this, int32_t event, void *data, ...)
125
{
126
    GF_UNUSED int ret = 0;
127
    xlator_t *victim = data;
128

129
    glusterfs_graph_t *graph = NULL;
130

131
    GF_VALIDATE_OR_GOTO("notify", this, out);
132
    graph = this->graph;
133
    GF_VALIDATE_OR_GOTO(this->name, graph, out);
134

135
    switch (event) {
136
        case GF_EVENT_PARENT_UP:
137
        case GF_EVENT_PARENT_DOWN: {
138
            xlator_list_t *list = this->children;
139

140
            while (list) {
141
                if (victim && victim->cleanup_starting)
142
                    xlator_notify(list->xlator, event, victim);
143
                else
144
                    xlator_notify(list->xlator, event, this);
145
                list = list->next;
146
            }
147
        } break;
148
        case GF_EVENT_CHILD_CONNECTING:
149
        case GF_EVENT_CHILD_DOWN:
150
        case GF_EVENT_CHILD_UP:
151
        case GF_EVENT_AUTH_FAILED: {
152
            xlator_list_t *parent = this->parents;
153

154
            /*
155
             * Handle case of CHILD_* & AUTH_FAILED event specially, send
156
             * it to fuse.
157
             */
158
            if (!parent && this->ctx && this->ctx->root) {
159
                xlator_notify(this->ctx->root, event, this->graph, NULL);
160
            }
161

162
            while (parent) {
163
                if (parent->xlator->init_succeeded)
164
                    xlator_notify(parent->xlator, event, this, NULL);
165
                parent = parent->next;
166
            }
167

168
            if (event == GF_EVENT_CHILD_DOWN &&
169
                !(this->ctx && this->ctx->root) && (graph->top == this)) {
170
                /* Make sure this is not a daemon with root xlator */
171
                pthread_mutex_lock(&graph->mutex);
172
                {
173
                    if (graph->parent_down ==
174
                        graph_total_client_xlator(graph)) {
175
                        graph->used = 0;
176
                        pthread_cond_broadcast(&graph->child_down_cond);
177
                    }
178
                }
179
                pthread_mutex_unlock(&graph->mutex);
180
            }
181
        } break;
182
        case GF_EVENT_UPCALL: {
183
            xlator_list_t *parent = this->parents;
184

185
            if (!parent && this->ctx && this->ctx->root)
186
                xlator_notify(this->ctx->root, event, data, NULL);
187

188
            while (parent) {
189
                if (parent->xlator->init_succeeded)
190
                    xlator_notify(parent->xlator, event, data, NULL);
191
                parent = parent->next;
192
            }
193
        } break;
194
        case GF_EVENT_CHILD_PING: {
195
            xlator_list_t *parent = this->parents;
196

197
            while (parent) {
198
                if (parent->xlator->init_succeeded)
199
                    XLATOR_NOTIFY(ret, parent->xlator, event, this, data);
200
                parent = parent->next;
201
            }
202
        } break;
203
        case GF_EVENT_SIGHUP:
204
        case GF_EVENT_CLEANUP: {
205
            xlator_list_t *list = this->children;
206

207
            while (list) {
208
                xlator_notify(list->xlator, event, this);
209
                list = list->next;
210
            }
211
        } break;
212

213
        default: {
214
            xlator_list_t *parent = this->parents;
215

216
            while (parent) {
217
                if (parent->xlator->init_succeeded)
218
                    xlator_notify(parent->xlator, event, this, NULL);
219
                parent = parent->next;
220
            }
221
        }
222
            /*
223
             * Apparently our picky-about-everything else coding standard allows
224
             * adjacent same-indendation-level close braces.  Clearly it has
225
             * nothing to do with readability.
226
             */
227
    }
228
out:
229
    return 0;
230
}
231

232
int32_t
233
default_mem_acct_init(xlator_t *this)
234
{
235
    int ret = -1;
236

237
    ret = xlator_mem_acct_init(this, gf_common_mt_end);
238

239
    return ret;
240
}
241

242
void
243
default_fini(xlator_t *this)
244
{
245
    if (this && this->private)
246
        GF_FREE(this->private);
247
}
248

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

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

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

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