summaryrefslogtreecommitdiffstats
path: root/xlators/features/snapview-client/src/snapview-client.h
blob: 9973458884b64420ba13bcd2bd50f76fa99b13f9 (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
 /*
   Copyright (c) 2014 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 __SNAP_VIEW_CLIENT_H__
#define __SNAP_VIEW_CLIENT_H__

#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif

#include "glusterfs.h"
#include "logging.h"
#include "dict.h"
#include "xlator.h"
#include "defaults.h"
#include "snapview-client-mem-types.h"

struct __svc_local {
        loc_t loc;
        xlator_t *subvolume;
        fd_t     *fd;
        void *cookie;
        dict_t *xdata;
};
typedef struct __svc_local svc_local_t;

void
svc_local_free (svc_local_t *local);

#define SVC_STACK_UNWIND(fop, frame, params ...) do {           \
                svc_local_t *__local = NULL;                    \
                if (frame) {                                    \
                        __local      = frame->local;            \
                        frame->local = NULL;                    \
                }                                               \
                STACK_UNWIND_STRICT (fop, frame, params);       \
                svc_local_free (__local);                       \
        } while (0)

#define SVC_ENTRY_POINT_SET(this, xdata, op_ret, op_errno, new_xdata,   \
                            priv, ret, label)                           \
        do {                                                            \
                if (!xdata) {                                           \
                        xdata = new_xdata = dict_new ();                \
                        if (!new_xdata) {                               \
                                gf_log (this->name, GF_LOG_ERROR,       \
                                        "failed to allocate new dict"); \
                                op_ret = -1;                            \
                                op_errno = ENOMEM;                      \
                                goto label;                             \
                        }                                               \
                }                                                       \
                ret = dict_set_str (xdata, "entry-point", "true");      \
                if (ret) {                                              \
                        gf_log (this->name, GF_LOG_ERROR,               \
                                "failed to set dict");                  \
                        op_ret = -1;                                    \
                        op_errno = ENOMEM;                              \
                        goto label;                                     \
                }                                                       \
        } while (0);

#define SVC_GET_SUBVOL_FROM_CTX(this, op_ret, op_errno, inode_type, ret, \
                                inode, subvolume, label)                \
        do {                                                            \
                ret = svc_inode_ctx_get (this, inode, &inode_type);     \
                if (ret < 0) {                                          \
                        gf_log (this->name, GF_LOG_ERROR,               \
                                "inode context not found for gfid %s",  \
                                uuid_utoa (inode->gfid));               \
                        op_ret = -1;                                    \
                        op_errno = EINVAL;                              \
                        goto label;                                     \
                }                                                       \
                                                                        \
                subvolume = svc_get_subvolume (this, inode_type);       \
        }  while (0);

struct svc_private {
        char *path;
        char *special_dir; /* needed for samba */
        gf_boolean_t show_entry_point;
};
typedef struct svc_private svc_private_t;

struct svc_fd {
        off_t last_offset;
        gf_boolean_t entry_point_handled;
        gf_boolean_t special_dir;
};
typedef struct svc_fd svc_fd_t;

typedef enum {
        NORMAL_INODE = 1,
        VIRTUAL_INODE
} inode_type_t;

void svc_local_free (svc_local_t *local);

xlator_t *
svc_get_subvolume (xlator_t *this, int inode_type);

int
__svc_inode_ctx_get (xlator_t *this, inode_t *inode, int *inode_type);

int
svc_inode_ctx_get (xlator_t *this, inode_t *inode, int *inode_type);

int32_t
svc_inode_ctx_set (xlator_t *this, inode_t *inode, int inode_type);

void
svc_local_free (svc_local_t *local);

gf_boolean_t
svc_readdir_on_special_dir (call_frame_t *frame, void *cookie, xlator_t *this,
                            int32_t op_ret, int32_t op_errno,
                            gf_dirent_t *entries, dict_t *xdata);
#endif /* __SNAP_VIEW_CLIENT_H__ */