summaryrefslogtreecommitdiffstats
path: root/xlators/meta/src/meta.h
blob: 652ebd7321ce577654e0b212b897f63b6b882598 (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 __META_H__
#define __META_H__

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

#include "strfd.h"

#define DEFAULT_META_DIR_NAME ".meta"

#define META_ROOT_GFID "ba926388-bb9c-4eec-ad60-79dba4cc083a"

#define IS_META_ROOT_GFID(g) (strcmp (uuid_utoa(g), META_ROOT_GFID) == 0)

typedef int (*meta_hook_t) (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata);

typedef struct {
	dict_t *xdata;
} meta_local_t;

typedef struct {
	char *meta_dir_name;
} meta_priv_t;

struct meta_dirent {
	const char *name;
	ia_type_t type;
	meta_hook_t hook;
};

#define DOT_DOTDOT { .name = ".", .type = IA_IFDIR }, { .name = "..", .type = IA_IFDIR }

struct meta_ops {
	struct meta_dirent *fixed_dirents;
	int (*dir_fill) (xlator_t *this, inode_t *dir, struct meta_dirent **entries);
	int (*file_fill) (xlator_t *this, inode_t *file, strfd_t *strfd);
	int (*iatt_fill) (xlator_t *this, inode_t *inode, struct iatt *iatt);
	int (*link_fill) (xlator_t *this, inode_t *inode, strfd_t *strfd);
	int (*file_write) (xlator_t *this, fd_t *fd, struct iovec *iov, int count);
	struct xlator_fops fops;
	struct xlator_cbks cbks;
};

typedef struct {
	char *data;
	struct meta_dirent *dirents;
	size_t size;
} meta_fd_t;


#define COUNT(arr) (sizeof(arr)/sizeof(arr[0]))

#define META_HOOK(loc) (__is_root_gfid (loc->pargfid) && !strcmp (loc->name, META_PRIV(THIS)->meta_dir_name))

#define META_PRIV(t) ((meta_priv_t *)(t->private))

#define META_STACK_UNWIND(fop, frame, params ...)		\
        do {                                                    \
                meta_local_t *__local = NULL;			\
                xlator_t    *__this = NULL;                     \
                if (frame) {                                    \
                        __local = frame->local;                 \
                        __this = frame->this;                   \
                        frame->local = NULL;                    \
                }                                               \
                STACK_UNWIND_STRICT (fop, frame, params);       \
                if (__local) {                                  \
                        meta_local_cleanup (__local, __this);	\
                }                                               \
        } while (0)


#define META_FOP(i, fop, fr, t, params ...) {	\
	struct xlator_fops *_fops = NULL;	\
						\
	_fops = meta_fops_get (i, t);		\
						\
	_fops->fop (fr, t, params);		\
	} while (0)


void meta_iatt_fill (struct iatt *iatt, inode_t *inode, ia_type_t type);

int meta_inode_discover (call_frame_t *frame, xlator_t *this, loc_t *loc,
			 dict_t *xdata);

int meta_ops_set (inode_t *inode, xlator_t *this, struct meta_ops *ops);

struct xlator_fops *meta_fops_get (inode_t *inode, xlator_t *this);
struct xlator_cbks *meta_cbks_get (inode_t *inode, xlator_t *this);
struct meta_ops *meta_ops_get (inode_t *inode, xlator_t *this);

int meta_ctx_set (inode_t *inode, xlator_t *this, void *ctx);

void *meta_ctx_get (inode_t *inode, xlator_t *this);


void meta_local_cleanup (meta_local_t *local, xlator_t *this);

struct xlator_fops *meta_defaults_init (struct xlator_fops *fops);

meta_fd_t *meta_fd_get (fd_t *fd, xlator_t *this);

int meta_fd_release (fd_t *fd, xlator_t *this);

dict_t *meta_direct_io_mode (dict_t *xdata, call_frame_t *frame);

meta_local_t *meta_local (call_frame_t *frame);

int meta_file_fill (xlator_t *this, fd_t *fd);

int meta_dir_fill (xlator_t *this, fd_t *fd);

int fixed_dirents_len (struct meta_dirent *dirents);
#endif /* __META_H__ */