glusterfs
247 строк · 7.1 Кб
1/*
2Copyright (c) 2008-2015 Red Hat, Inc. <http://www.redhat.com>
3This file is part of GlusterFS.
4
5This file is licensed to you under your choice of the GNU Lesser
6General Public License, version 3 or any later version (LGPLv3 or
7later), or the GNU General Public License, version 2 (GPLv2), in all
8cases as published by the Free Software Foundation.
9*/
10
11/* libglusterfs/src/defaults.c:
12This file contains functions, which are used to fill the 'fops', 'cbk'
13structures in the xlator structures, if they are not written. Here, all the
14function calls are plainly forwarded to the first child of the xlator, and
15all the *_cbk function does plain STACK_UNWIND of the frame, and returns.
16
17This function also implements *_resume () functions, which does same
18operation as a fop().
19
20All the functions are plain enough to understand.
21*/
22
23#ifndef _CONFIG_H24#define _CONFIG_H25#include "config.h"26#endif27
28#include "glusterfs/defaults.h"29
30#pragma generate31
32struct 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};88struct 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
95int32_t
96default_forget(xlator_t *this, inode_t *inode)97{
98gf_log_callingfn(this->name, GF_LOG_DEBUG,99"xlator does not "100"implement forget_cbk");101return 0;102}
103
104int32_t
105default_releasedir(xlator_t *this, fd_t *fd)106{
107gf_log_callingfn(this->name, GF_LOG_DEBUG,108"xlator does not "109"implement releasedir_cbk");110return 0;111}
112
113int32_t
114default_release(xlator_t *this, fd_t *fd)115{
116gf_log_callingfn(this->name, GF_LOG_DEBUG,117"xlator does not "118"implement release_cbk");119return 0;120}
121
122/* notify */
123int
124default_notify(xlator_t *this, int32_t event, void *data, ...)125{
126GF_UNUSED int ret = 0;127xlator_t *victim = data;128
129glusterfs_graph_t *graph = NULL;130
131GF_VALIDATE_OR_GOTO("notify", this, out);132graph = this->graph;133GF_VALIDATE_OR_GOTO(this->name, graph, out);134
135switch (event) {136case GF_EVENT_PARENT_UP:137case GF_EVENT_PARENT_DOWN: {138xlator_list_t *list = this->children;139
140while (list) {141if (victim && victim->cleanup_starting)142xlator_notify(list->xlator, event, victim);143else144xlator_notify(list->xlator, event, this);145list = list->next;146}147} break;148case GF_EVENT_CHILD_CONNECTING:149case GF_EVENT_CHILD_DOWN:150case GF_EVENT_CHILD_UP:151case GF_EVENT_AUTH_FAILED: {152xlator_list_t *parent = this->parents;153
154/*155* Handle case of CHILD_* & AUTH_FAILED event specially, send
156* it to fuse.
157*/
158if (!parent && this->ctx && this->ctx->root) {159xlator_notify(this->ctx->root, event, this->graph, NULL);160}161
162while (parent) {163if (parent->xlator->init_succeeded)164xlator_notify(parent->xlator, event, this, NULL);165parent = parent->next;166}167
168if (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 */171pthread_mutex_lock(&graph->mutex);172{173if (graph->parent_down ==174graph_total_client_xlator(graph)) {175graph->used = 0;176pthread_cond_broadcast(&graph->child_down_cond);177}178}179pthread_mutex_unlock(&graph->mutex);180}181} break;182case GF_EVENT_UPCALL: {183xlator_list_t *parent = this->parents;184
185if (!parent && this->ctx && this->ctx->root)186xlator_notify(this->ctx->root, event, data, NULL);187
188while (parent) {189if (parent->xlator->init_succeeded)190xlator_notify(parent->xlator, event, data, NULL);191parent = parent->next;192}193} break;194case GF_EVENT_CHILD_PING: {195xlator_list_t *parent = this->parents;196
197while (parent) {198if (parent->xlator->init_succeeded)199XLATOR_NOTIFY(ret, parent->xlator, event, this, data);200parent = parent->next;201}202} break;203case GF_EVENT_SIGHUP:204case GF_EVENT_CLEANUP: {205xlator_list_t *list = this->children;206
207while (list) {208xlator_notify(list->xlator, event, this);209list = list->next;210}211} break;212
213default: {214xlator_list_t *parent = this->parents;215
216while (parent) {217if (parent->xlator->init_succeeded)218xlator_notify(parent->xlator, event, this, NULL);219parent = 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}228out:229return 0;230}
231
232int32_t
233default_mem_acct_init(xlator_t *this)234{
235int ret = -1;236
237ret = xlator_mem_acct_init(this, gf_common_mt_end);238
239return ret;240}
241
242void
243default_fini(xlator_t *this)244{
245if (this && this->private)246GF_FREE(this->private);247}
248