3
from __future__ import print_function
7
curdir = os.path.dirname(sys.argv[0])
8
gendir = os.path.join(curdir, '../../../../libglusterfs/src')
10
from generator import ops, fop_subs, cbk_subs, generate
12
FD_DATA_MODIFYING_OP_FOP_TEMPLATE = """
14
cs_@NAME@ (call_frame_t *frame, xlator_t *this,
17
int op_errno = EINVAL ;
18
cs_local_t *local = NULL;
20
cs_inode_ctx_t *ctx = NULL;
21
gf_cs_obj_state state = -1;
23
VALIDATE_OR_GOTO (frame, err);
24
VALIDATE_OR_GOTO (this, err);
25
VALIDATE_OR_GOTO (fd, err);
27
local = cs_local_init (this, frame, NULL, fd, GF_FOP_@UPNAME@);
30
gf_msg (this->name, GF_LOG_ERROR, 0, 0, "local init failed");
35
__cs_inode_ctx_get (this, fd->inode, &ctx);
38
state = __cs_get_file_state (fd->inode, ctx);
42
xdata = xdata ? dict_ref (xdata) : dict_new ();
45
gf_msg (this->name, GF_LOG_ERROR, 0, 0, "insufficient memory");
50
local->xattr_req = xdata;
52
ret = dict_set_uint32 (local->xattr_req, GF_CS_OBJECT_STATUS, 1);
54
gf_msg (this->name, GF_LOG_ERROR, 0, 0, "dict_set failed key:"
55
" %s", GF_CS_OBJECT_STATUS);
59
local->stub = fop_@NAME@_stub (frame, cs_resume_@NAME@,
62
gf_msg (this->name, GF_LOG_ERROR, 0, 0, "insufficient memory");
68
if (state == GF_CS_LOCAL) {
69
STACK_WIND (frame, cs_@NAME@_cbk,
70
FIRST_CHILD(this), FIRST_CHILD(this)->fops->@NAME@,
74
ret = locate_and_execute (frame);
84
CS_STACK_UNWIND (@NAME@, frame, -1, op_errno, @CBK_ERROR_ARGS@);
90
FD_DATA_MODIFYING_RESUME_OP_FOP_TEMPLATE = """
92
cs_resume_@NAME@ (call_frame_t *frame, xlator_t *this,
97
ret = cs_resume_postprocess (this, frame, fd->inode);
102
cs_inodelk_unlock (frame);
104
STACK_WIND (frame, cs_@NAME@_cbk,
105
FIRST_CHILD(this), FIRST_CHILD(this)->fops->@NAME@,
112
cs_inodelk_unlock (frame);
114
cs_common_cbk (frame);
119
FD_DATA_MODIFYING_OP_FOP_CBK_TEMPLATE = """
121
cs_@NAME@_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
122
int32_t op_ret, int32_t op_errno,
125
cs_local_t *local = NULL;
130
local = frame->local;
133
/* Do we need lock here? */
137
ret = dict_get_uint64 (xdata, GF_CS_OBJECT_STATUS, &val);
139
if (val == GF_CS_ERROR) {
140
gf_msg (this->name, GF_LOG_ERROR, 0, 0,
141
"could not get file state, unwinding");
146
__cs_inode_ctx_update (this, fd->inode, val);
147
gf_msg (this->name, GF_LOG_INFO, 0, 0,
148
" state = %" PRIu64, val);
150
if (local->call_cnt == 1 &&
151
(val == GF_CS_REMOTE ||
152
val == GF_CS_DOWNLOADING)) {
153
gf_msg (this->name, GF_LOG_INFO, 0,
154
0, " will repair and download "
155
"the file, current state : %"
159
gf_msg (this->name, GF_LOG_ERROR, 0, 0,
160
"second @NAME@, Unwinding");
165
gf_msg (this->name, GF_LOG_ERROR, 0, 0, "file state "
166
"could not be figured, unwinding");
170
/* successful @NAME@ => file is local */
171
__cs_inode_ctx_update (this, fd->inode, GF_CS_LOCAL);
172
gf_msg (this->name, GF_LOG_INFO, 0, 0, "state : GF_CS_LOCAL"
173
", @NAME@ successful");
179
ret = locate_and_execute (frame);
187
CS_STACK_UNWIND (@NAME@, frame, op_ret, op_errno, @SHORT_ARGS@);
193
LOC_STAT_OP_FOP_TEMPLATE = """
195
cs_@NAME@ (call_frame_t *frame, xlator_t *this,
198
int op_errno = EINVAL;
199
cs_local_t *local = NULL;
202
local = cs_local_init (this, frame, loc, NULL, GF_FOP_@UPNAME@);
204
gf_msg (this->name, GF_LOG_ERROR, 0, 0, "local is NULL");
209
if (loc->inode->ia_type == IA_IFDIR)
212
xdata = xdata ? dict_ref (xdata) : dict_new ();
215
gf_msg (this->name, GF_LOG_ERROR, 0, 0, "insufficient memory");
220
local->xattr_req = xdata;
222
ret = dict_set_uint32 (local->xattr_req, GF_CS_OBJECT_STATUS, 1);
224
gf_msg (this->name, GF_LOG_ERROR, 0, 0, "dict_set failed key:"
225
" %s", GF_CS_OBJECT_STATUS);
230
STACK_WIND (frame, cs_@NAME@_cbk, FIRST_CHILD(this),
231
FIRST_CHILD(this)->fops->@NAME@,
236
CS_STACK_UNWIND (@NAME@, frame, -1, op_errno, @CBK_ERROR_ARGS@);
242
LOC_STAT_OP_FOP_CBK_TEMPLATE = """
244
cs_@NAME@_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
245
int32_t op_ret, int32_t op_errno,
251
cs_local_t *local = NULL;
253
local = frame->local;
258
ret = dict_get_uint64 (xdata, GF_CS_OBJECT_STATUS, &val);
260
ret = __cs_inode_ctx_update (this, loc->inode, val);
262
gf_msg (this->name, GF_LOG_ERROR, 0, 0,
263
"ctx update failed");
267
cs_inode_ctx_reset (this, loc->inode);
270
CS_STACK_UNWIND (@NAME@, frame, op_ret, op_errno, @SHORT_ARGS@);
276
# All xlator FOPs are covered in the following section just to create a clarity
277
# The lists themselves are not used.
278
entry_ops = ['mknod', 'mkdir', 'unlink', 'rmdir', 'symlink', 'rename', 'link',
280
special_ops = ['statfs', 'lookup', 'ipc', 'compound', 'icreate', 'namelink']
281
ignored_ops = ['getspec']
282
inode_ops = ['stat', 'readlink', 'truncate', 'open', 'setxattr', 'getxattr',
283
'removexattr', 'opendir', 'access', 'inodelk', 'entrylk',
284
'xattrop', 'setattr', 'lease', 'getactivelk', 'setactivelk',
286
fd_ops = ['readv', 'writev', 'flush', 'fsync', 'fsyncdir', 'ftruncate',
287
'fstat', 'lk', 'readdir', 'finodelk', 'fentrylk', 'fxattrop',
288
'fsetxattr', 'fgetxattr', 'rchecksum', 'fsetattr', 'readdirp',
289
'fremovexattr', 'fallocate', 'discard', 'zerofill', 'seek']
292
# These are the current actual lists used to generate the code
294
# The following list contains fops which are fd based that modifies data
295
fd_data_modify_op_fop_template = ['writev', 'flush', 'fsync',
296
'ftruncate', 'rchecksum', 'fallocate',
297
'discard', 'zerofill', 'seek']
299
# The following list contains fops which are entry based that does not change
301
loc_stat_op_fop_template = ['lookup', 'stat', 'discover', 'access', 'setattr',
304
# These fops need a separate implementation
305
special_fops = ['statfs', 'setxattr', 'unlink', 'getxattr',
306
'truncate', 'fstat', 'readv', 'readdirp']
310
if name in fd_data_modify_op_fop_template:
311
print(generate(FD_DATA_MODIFYING_OP_FOP_CBK_TEMPLATE, name, cbk_subs))
312
print(generate(FD_DATA_MODIFYING_RESUME_OP_FOP_TEMPLATE, name, fop_subs))
313
print(generate(FD_DATA_MODIFYING_OP_FOP_TEMPLATE, name, fop_subs))
314
elif name in loc_stat_op_fop_template:
315
print(generate(LOC_STAT_OP_FOP_CBK_TEMPLATE, name, cbk_subs))
316
print(generate(LOC_STAT_OP_FOP_TEMPLATE, name, fop_subs))
318
for l in open(sys.argv[1], 'r').readlines():
319
if l.find('#pragma generate') != -1:
320
print("/* BEGIN GENERATED CODE - DO NOT MODIFY */")
322
print("/* END GENERATED CODE */")