summaryrefslogtreecommitdiffstats
path: root/xlators/features/utime/src/utime-gen-fops-c.py
blob: a8637ffe6f6b522571cbf3151eabb1f479df5bfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/python3

from __future__ import print_function
import os
import sys

curdir = os.path.dirname(sys.argv[0])
gendir = os.path.join(curdir, '../../../../libglusterfs/src')
sys.path.append(gendir)
from generator import ops, fop_subs, cbk_subs, generate

FOPS_COMMON_TEMPLATE = """
int32_t
gf_utime_@NAME@ (call_frame_t *frame, xlator_t *this,
                @LONG_ARGS@)
{
        gl_timespec_get(&frame->root->ctime);

        (void) utime_update_attribute_flags(frame, this, GF_FOP_@UPNAME@);
        STACK_WIND (frame, gf_utime_@NAME@_cbk, FIRST_CHILD(this),
                    FIRST_CHILD(this)->fops->@NAME@, @SHORT_ARGS@);
        return 0;
}
"""

FOPS_CBK_COMMON_TEMPLATE = """
int32_t
gf_utime_@NAME@_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
                     int32_t op_ret, int32_t op_errno,
                    @LONG_ARGS@)
{
        STACK_UNWIND_STRICT (@NAME@, frame, op_ret, op_errno, @SHORT_ARGS@);
        return 0;
}
"""

FOPS_READ_TEMPLATE = """
int32_t
gf_utime_@NAME@ (call_frame_t *frame, xlator_t *this,
                @LONG_ARGS@)
{
        gl_timespec_get(&frame->root->ctime);

        (void) utime_update_attribute_flags(frame, this, GF_FOP_READ);
        STACK_WIND (frame, gf_utime_@NAME@_cbk, FIRST_CHILD(this),
                    FIRST_CHILD(this)->fops->@NAME@, @SHORT_ARGS@);
        return 0;
}
"""

FOPS_WRITE_TEMPLATE = """
int32_t
gf_utime_@NAME@ (call_frame_t *frame, xlator_t *this,
                @LONG_ARGS@)
{
        gl_timespec_get(&frame->root->ctime);

        (void) utime_update_attribute_flags(frame, this, GF_FOP_WRITE);
        STACK_WIND (frame, gf_utime_@NAME@_cbk, FIRST_CHILD(this),
                    FIRST_CHILD(this)->fops->@NAME@, @SHORT_ARGS@);
        return 0;
}
"""

FOPS_COPY_FILE_RANGE_TEMPLATE = """
int32_t
gf_utime_@NAME@ (call_frame_t *frame, xlator_t *this,
                @LONG_ARGS@)
{
        gl_timespec_get(&frame->root->ctime);

        (void) utime_update_attribute_flags(frame, this, GF_FOP_COPY_FILE_RANGE);
        STACK_WIND (frame, gf_utime_@NAME@_cbk, FIRST_CHILD(this),
                    FIRST_CHILD(this)->fops->@NAME@, @SHORT_ARGS@);
        return 0;
}
"""

FOPS_SETATTR_TEMPLATE = """
int32_t
gf_utime_@NAME@ (call_frame_t *frame, xlator_t *this,
             @LONG_ARGS@)
{
        gl_timespec_get(&frame->root->ctime);
        frame->root->flags |= MDATA_CTIME;

        STACK_WIND (frame, gf_utime_@NAME@_cbk, FIRST_CHILD(this),
                    FIRST_CHILD(this)->fops->@NAME@, @SHORT_ARGS@);
        return 0;
}
"""

utime_ops = ['fallocate', 'zerofill', 'opendir', 'mknod', 'mkdir',
             'unlink', 'rmdir', 'symlink', 'rename', 'link', 'truncate',
             'ftruncate', 'create', 'open', 'removexattr', 'fremovexattr']

utime_read_op = ['readv']
utime_write_op = ['writev']
utime_setattr_ops = ['setattr', 'fsetattr']
utime_copy_file_range_ops = ['copy_file_range']

def gen_defaults():
    for name in ops:
        if name in utime_ops:
            print(generate(FOPS_CBK_COMMON_TEMPLATE, name, cbk_subs))
            print(generate(FOPS_COMMON_TEMPLATE, name, fop_subs))
        if name in utime_read_op:
            print(generate(FOPS_CBK_COMMON_TEMPLATE, name, cbk_subs))
            print(generate(FOPS_READ_TEMPLATE, name, fop_subs))
        if name in utime_write_op:
            print(generate(FOPS_CBK_COMMON_TEMPLATE, name, cbk_subs))
            print(generate(FOPS_WRITE_TEMPLATE, name, fop_subs))
        if name in utime_setattr_ops:
            print(generate(FOPS_CBK_COMMON_TEMPLATE, name, cbk_subs))
            print(generate(FOPS_SETATTR_TEMPLATE, name, fop_subs))
        if name in utime_copy_file_range_ops:
            print(generate(FOPS_CBK_COMMON_TEMPLATE, name, cbk_subs))
            print(generate(FOPS_COPY_FILE_RANGE_TEMPLATE, name, fop_subs))

for l in open(sys.argv[1], 'r').readlines():
    if l.find('#pragma generate') != -1:
        print("/* BEGIN GENERATED CODE - DO NOT MODIFY */")
        gen_defaults()
        print("/* END GENERATED CODE */")
    else:
        print(l[:-1])