summaryrefslogtreecommitdiffstats
path: root/xlators/experimental/fdl/src/recon-tmpl.c
blob: 523bda39418f10f99eb15320c85816ddb6eba7d7 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#pragma fragment PROLOG
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif

#include "glusterfs.h"
#include "fd.h"
#include "iatt.h"
#include "syncop.h"
#include "xlator.h"
#include "glfs-internal.h"

#include "jnl-types.h"

#define GFAPI_SUCCESS 0

inode_t *
recon_get_inode (glfs_t *fs, uuid_t gfid)
{
        inode_t         *inode;
        loc_t           loc     = {NULL,};
        struct iatt     iatt;
        int             ret;
        inode_t         *newinode;

        inode = inode_find (fs->active_subvol->itable, gfid);
        if (inode) {
                printf ("=== FOUND %s IN TABLE\n", uuid_utoa(gfid));
                return inode;
        }

        loc.inode = inode_new (fs->active_subvol->itable);
        if (!loc.inode) {
                return NULL;
        }
        gf_uuid_copy (loc.inode->gfid, gfid);
        gf_uuid_copy (loc.gfid, gfid);

        printf ("=== DOING LOOKUP FOR %s\n", uuid_utoa(gfid));

        ret = syncop_lookup (fs->active_subvol, &loc, &iatt,
                             NULL, NULL, NULL);
        if (ret != GFAPI_SUCCESS) {
                fprintf (stderr, "syncop_lookup failed (%d)\n", ret);
                return NULL;
        }

        newinode = inode_link (loc.inode, NULL, NULL, &iatt);
        if (newinode) {
                inode_lookup (newinode);
        }

        return newinode;
}

#pragma fragment DICT
        dict_t  *@ARGNAME@;

        @ARGNAME@ = dict_new();
        if (!@ARGNAME@) {
                goto *err_label;
        }
        err_label = &&cleanup_@ARGNAME@;

        {
                int     key_len, data_len;
                char    *key_ptr;
                int     garbage;
                for (;;) {
                        key_len = *((int *)new_meta);
                        new_meta += sizeof(int);
                        if (!key_len) {
                                break;
                        }
                        key_ptr = new_meta;
                        new_meta += key_len;
                        data_len = *((int *)new_meta);
                        new_meta += sizeof(int);
                        garbage = dict_set_static_bin (@ARGNAME@, key_ptr,
                                                       new_meta, data_len);
                        /* TBD: check error from dict_set_static_bin */
                        (void)garbage;
                        new_meta += data_len;
                }
        }

#pragma fragment DICT_CLEANUP
cleanup_@ARGNAME@:
        dict_unref (@ARGNAME@);

#pragma fragment DOUBLE
        @ARGTYPE@       @ARGNAME@       = *((@ARGTYPE@ *)new_meta);
        new_meta += sizeof(uint64_t);

#pragma fragment FD
        inode_t *@ARGNAME@_ino;
        fd_t    *@ARGNAME@;

        @ARGNAME@_ino = recon_get_inode (fs, *((uuid_t *)new_meta));
        new_meta += 16;
        if (!@ARGNAME@_ino) {
                goto *err_label;
        }
        err_label = &&cleanup_@ARGNAME@_ino;

        @ARGNAME@ = fd_anonymous (@ARGNAME@_ino);
        if (!@ARGNAME@) {
                goto *err_label;
        }
        err_label = &&cleanup_@ARGNAME@;

#pragma fragment FD_CLEANUP
cleanup_@ARGNAME@:
        fd_unref (@ARGNAME@);
cleanup_@ARGNAME@_ino:
        inode_unref (@ARGNAME@_ino);

#pragma fragment NEW_FD
        /*
         * This pseudo-type is only used for create, and in that case we know
         * we'll be using loc.inode, so it's not worth generalizing to take an
         * extra argument.
         */
        fd_t    *@ARGNAME@      = fd_anonymous (loc.inode);

        if (!fd) {
                goto *err_label;
        }
        err_label = &&cleanup_@ARGNAME@;
        new_meta += 16;

#pragma fragment NEW_FD_CLEANUP
cleanup_@ARGNAME@:
        fd_unref (@ARGNAME@);

#pragma fragment INTEGER
        @ARGTYPE@       @ARGNAME@       = *((@ARGTYPE@ *)new_meta);

        new_meta += sizeof(@ARGTYPE@);

#pragma fragment LOC
        loc_t           @ARGNAME@       = { NULL, };

        @ARGNAME@.inode = recon_get_inode (fs, *((uuid_t *)new_meta));
        if (!@ARGNAME@.inode) {
                goto *err_label;
        }
        err_label = &&cleanup_@ARGNAME@;
        gf_uuid_copy (@ARGNAME@.gfid, @ARGNAME@.inode->gfid);
        new_meta += 16;
        new_meta += 16; /* skip over pargfid */
        if (*(new_meta++)) {
                @ARGNAME@.name = new_meta;
                new_meta += strlen(new_meta) + 1;
        }

#pragma fragment LOC_CLEANUP
cleanup_@ARGNAME@:
        loc_wipe (&@ARGNAME@);

#pragma fragment PARENT_LOC
        loc_t           @ARGNAME@       = { NULL, };

        new_meta += 16; /* skip over gfid */
        @ARGNAME@.parent = recon_get_inode (fs, *((uuid_t *)new_meta));
        if (!@ARGNAME@.parent) {
                goto *err_label;
        }
        err_label = &&cleanup_@ARGNAME@;
        gf_uuid_copy (@ARGNAME@.pargfid, @ARGNAME@.parent->gfid);
        new_meta += 16;
        if (!*(new_meta++)) {
                goto *err_label;
        }
        @ARGNAME@.name = new_meta;
        new_meta += strlen(new_meta) + 1;

        @ARGNAME@.inode = inode_new (fs->active_subvol->itable);
        if (!@ARGNAME@.inode) {
                goto *err_label;
        }

#pragma fragment PARENT_LOC_CLEANUP
cleanup_@ARGNAME@:
        loc_wipe (&@ARGNAME@);

#pragma fragment STRING
        char    *@ARGNAME@;
        if (*(new_meta++)) {
                @ARGNAME@ = new_meta;
                new_meta += (strlen(new_meta) + 1);
        }
        else {
                goto *err_label;
        }

#pragma fragment VECTOR
        struct iovec    @ARGNAME@;

        @ARGNAME@.iov_len = *((size_t *)new_meta);
        new_meta += sizeof(@ARGNAME@.iov_len);
        @ARGNAME@.iov_base = new_data;
        new_data += @ARGNAME@.iov_len;

#pragma fragment IATT
        struct iatt     @ARGNAME@;
        {
                @ARGNAME@.ia_prot = *((ia_prot_t *)new_meta);
                new_meta += sizeof(ia_prot_t);
                uint32_t *myints = (uint32_t *)new_meta;
                @ARGNAME@.ia_uid = myints[0];
                @ARGNAME@.ia_gid = myints[1];
                @ARGNAME@.ia_atime = myints[2];
                @ARGNAME@.ia_atime_nsec = myints[3];
                @ARGNAME@.ia_mtime = myints[4];
                @ARGNAME@.ia_mtime_nsec = myints[5];
                new_meta += sizeof(*myints) * 6;
        }

#pragma fragment IOBREF
        struct iobref   *@ARGNAME@;

        @ARGNAME@ = iobref_new();
        if (!@ARGNAME@) {
                goto *err_label;
        }
        err_label = &&cleanup_@ARGNAME@;

#pragma fragment IOBREF_CLEANUP
cleanup_@ARGNAME@:
        iobref_unref (@ARGNAME@);

#pragma fragment LINK
        /* TBD: check error */
        inode_t *new_inode = inode_link (@INODE_ARG@, NULL, NULL, @IATT_ARG@);
        if (new_inode) {
                inode_lookup (new_inode);
        }

#pragma fragment FOP
int
fdl_replay_@NAME@ (glfs_t *fs, char **old_meta, char **old_data)
{
        char    *new_meta	= *old_meta;
        char	*new_data	= *old_data;
        int     ret;
        int     status          = 0xbad;
        void    *err_label      = &&done;

@FUNCTION_BODY@

        ret = syncop_@NAME@ (fs->active_subvol, @SYNCOP_ARGS@, NULL);
        if (ret != @SUCCESS_VALUE@) {
                fprintf (stderr, "syncop_@NAME@ returned %d", ret);
                goto *err_label;
        }

@LINKS@

        status = 0;

@CLEANUPS@

done:
        *old_meta = new_meta;
        *old_data = new_data;
        return status;
}

#pragma fragment CASE
        case GF_FOP_@UPNAME@:
                printf ("=== GF_FOP_@UPNAME@\n");
                if (fdl_replay_@NAME@ (fs, &new_meta, &new_data) != 0) {
                        goto done;
                }
                recognized = 1;
                break;

#pragma fragment EPILOG
int
recon_execute (glfs_t *fs, char **old_meta, char **old_data)
{
        char            *new_meta       = *old_meta;
        char            *new_data       = *old_data;
        int             recognized      = 0;
        event_header_t  *eh;

        eh = (event_header_t *)new_meta;
        new_meta += sizeof (*eh);

        /* TBD: check event_type instead of assuming NEW_REQUEST */

        switch (eh->fop_type) {
@SWITCH_BODY@

        default:
                printf ("unknown fop %u\n", eh->fop_type);
        }

done:
        *old_meta = new_meta;
        *old_data = new_data;
        return recognized;
}