summaryrefslogtreecommitdiffstats
path: root/xlators/performance/decompounder/src/decompounder.h
blob: 486d0caf369dc90345b47df9db42f78a7e936a4e (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
/*
  Copyright (c) 2016 Red Hat, Inc. <http://www.redhat.com>
  This file is part of GlusterFS.

  This file is licensed to you under your choice of the GNU Lesser
  General Public License, version 3 or any later version (LGPLv3 or
  later), or the GNU General Public License, version 2 (GPLv2), in all
  cases as published by the Free Software Foundation.
*/

#ifndef __DC_H__
#define __DC_H__

#include "defaults.h"
#include "xlator.h"
#include "call-stub.h"
#include "decompounder-mem-types.h"
#include "decompounder-messages.h"

typedef struct {
    compound_args_t *compound_req;
    compound_args_cbk_t *compound_rsp;
    int counter;
    int length;
} dc_local_t;

#define DC_STACK_UNWIND(frame, op_ret, op_errno, rsp, xdata)                   \
    do {                                                                       \
        dc_local_t *__local = NULL;                                            \
                                                                               \
        if (frame) {                                                           \
            __local = frame->local;                                            \
            frame->local = NULL;                                               \
        }                                                                      \
        STACK_UNWIND_STRICT(compound, frame, op_ret, op_errno, (void *)rsp,    \
                            xdata);                                            \
        if (__local) {                                                         \
            dc_local_cleanup(__local);                                         \
            mem_put(__local);                                                  \
        }                                                                      \
    } while (0)

int32_t
dc_compound_fop_wind(call_frame_t *frame, xlator_t *this);

void
dc_local_cleanup(dc_local_t *local);

#define DC_FOP_RESPONSE_STORE_AND_WIND_NEXT(fop, frame, op_ret, op_errno,      \
                                            params...)                         \
    do {                                                                       \
        dc_local_t *__local = frame->local;                                    \
        xlator_t *__this = frame->this;                                        \
        int __ret = 0;                                                         \
        int __counter = __local->counter;                                      \
        compound_args_cbk_t *__compound_rsp = __local->compound_rsp;           \
        default_args_cbk_t *__fop_rsp = &__local->compound_rsp                 \
                                             ->rsp_list[__counter];            \
                                                                               \
        if (op_ret < 0) {                                                      \
            gf_msg(__this->name, GF_LOG_ERROR, op_errno,                       \
                   DC_MSG_ERROR_RECEIVED, "fop number %d failed. Unwinding.",  \
                   __counter + 1);                                             \
            args_##fop##_cbk_store(__fop_rsp, op_ret, op_errno, params);       \
            /*TODO : Fill the rest of the responses to -1 or NULL*/            \
            DC_STACK_UNWIND(frame, op_ret, op_errno, (void *)__compound_rsp,   \
                            NULL);                                             \
        } else {                                                               \
            args_##fop##_cbk_store(__fop_rsp, op_ret, op_errno, params);       \
            __local->counter++;                                                \
            __ret = dc_compound_fop_wind(frame, __this);                       \
            if (__ret < 0) {                                                   \
                DC_STACK_UNWIND(frame, -1, -__ret, (void *)__compound_rsp,     \
                                NULL);                                         \
            }                                                                  \
        }                                                                      \
    } while (0)
#endif /* DC_H__ */