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
|
/*
Copyright (c) 2015 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 __BIT_ROT_STUB_H__
#define __BIT_ROT_STUB_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 "call-stub.h"
#include "bit-rot-common.h"
typedef int (br_stub_version_cbk) (call_frame_t *, void *,
xlator_t *, int32_t, int32_t, dict_t *);
typedef struct br_stub_inode_ctx {
int need_writeback; /* does the inode need
a writeback to disk? */
unsigned long currentversion; /* ongoing version */
struct release {
int32_t ordflags;
unsigned long opencount; /* number of open()s before
final release() */
unsigned long releasecount; /* number of release()s */
} releasectx;
#define BR_STUB_REQUIRE_RELEASE_CBK 0x0E0EA0E
} br_stub_inode_ctx_t;
#define I_DIRTY (1<<0) /* inode needs writeback */
#define WRITEBACK_DURABLE 1 /* writeback is durable */
/**
* This could just have been a plain struct without unions and all,
* but we may need additional things in the future.
*/
typedef struct br_stub_local {
call_stub_t *fopstub; /* stub for original fop */
int versioningtype; /* not much used atm */
union {
struct br_stub_ctx {
fd_t *fd;
uuid_t gfid;
inode_t *inode;
unsigned long version;
gf_boolean_t markdirty;
} context;
} u;
} br_stub_local_t;
#define BR_STUB_FULL_VERSIONING (1<<0)
#define BR_STUB_INCREMENTAL_VERSIONING (1<<1)
typedef struct br_stub_private {
gf_boolean_t go;
uint32_t boot[2];
char export[PATH_MAX];
struct mem_pool *local_pool;
} br_stub_private_t;
/* inode writeback helpers */
static inline void
__br_stub_mark_inode_dirty (br_stub_inode_ctx_t *ctx)
{
ctx->need_writeback |= I_DIRTY;
}
static inline void
__br_stub_mark_inode_synced (br_stub_inode_ctx_t *ctx)
{
ctx->need_writeback &= ~I_DIRTY;
}
static inline int
__br_stub_is_inode_dirty (br_stub_inode_ctx_t *ctx)
{
return (ctx->need_writeback & I_DIRTY);
}
static inline int
br_stub_require_release_call (xlator_t *this, fd_t *fd)
{
int32_t ret = 0;
ret = fd_ctx_set (fd, this,
(uint64_t)(long)BR_STUB_REQUIRE_RELEASE_CBK);
if (ret)
gf_log (this->name, GF_LOG_WARNING,
"could not set fd context (for release callback");
return ret;
}
/* get/set inode context helpers */
static inline int
__br_stub_get_inode_ctx (xlator_t *this,
inode_t *inode, uint64_t *ctx)
{
return __inode_ctx_get (inode, this, ctx);
}
static inline int
br_stub_get_inode_ctx (xlator_t *this,
inode_t *inode, uint64_t *ctx)
{
return inode_ctx_get (inode, this, ctx);
}
static inline int
br_stub_set_inode_ctx (xlator_t *this,
inode_t *inode, br_stub_inode_ctx_t *ctx)
{
uint64_t ctx_addr = (uint64_t) ctx;
return inode_ctx_set (inode, this, &ctx_addr);
}
/* version get/set helpers */
static inline unsigned long
__br_stub_writeback_version (br_stub_inode_ctx_t *ctx)
{
return (ctx->currentversion + 1);
}
static inline void
__br_stub_set_ongoing_version (br_stub_inode_ctx_t *ctx, unsigned long version)
{
ctx->currentversion = version;
}
static inline void
__br_stub_reset_release_counters (br_stub_inode_ctx_t *ctx)
{
ctx->releasectx.ordflags = 0;
ctx->releasectx.opencount = 0;
ctx->releasectx.releasecount = 0;
}
static inline void
__br_stub_track_release (br_stub_inode_ctx_t *ctx)
{
++ctx->releasectx.releasecount;
}
static inline void
___br_stub_track_open (br_stub_inode_ctx_t *ctx)
{
++ctx->releasectx.opencount;
}
static inline void
___br_stub_track_open_flags (fd_t *fd, br_stub_inode_ctx_t *ctx)
{
ctx->releasectx.ordflags |= fd->flags;
}
static inline void
__br_stub_track_openfd (fd_t *fd, br_stub_inode_ctx_t *ctx)
{
___br_stub_track_open (ctx);
___br_stub_track_open_flags (fd, ctx);
}
static inline int
__br_stub_can_trigger_release (inode_t *inode,
br_stub_inode_ctx_t *ctx,
unsigned long *version, int32_t *flags)
{
if (list_empty (&inode->fd_list)
&& (ctx->releasectx.releasecount == ctx->releasectx.opencount)) {
if (flags)
*flags = htonl (ctx->releasectx.ordflags);
if (version)
*version = htonl (ctx->currentversion);
__br_stub_reset_release_counters (ctx);
return 1;
}
return 0;
}
static inline int32_t
br_stub_get_ongoing_version (xlator_t *this,
inode_t *inode, unsigned long *version)
{
int32_t ret = 0;
uint64_t ctx_addr = 0;
br_stub_inode_ctx_t *ctx = NULL;
LOCK (&inode->lock);
{
ret = __inode_ctx_get (inode, this, &ctx_addr);
if (ret < 0)
goto unblock;
ctx = (br_stub_inode_ctx_t *) (long) ctx_addr;
*version = ctx->currentversion;
}
unblock:
UNLOCK (&inode->lock);
return ret;
}
/**
* fetch the current version from inode and return the context.
* inode->lock should be held before invoking this as context
* *needs* to be valid in the caller.
*/
static inline br_stub_inode_ctx_t *
__br_stub_get_ongoing_version_ctx (xlator_t *this,
inode_t *inode, unsigned long *version)
{
int32_t ret = 0;
uint64_t ctx_addr = 0;
br_stub_inode_ctx_t *ctx = NULL;
ret = __inode_ctx_get (inode, this, &ctx_addr);
if (ret < 0)
return NULL;
ctx = (br_stub_inode_ctx_t *) (long) ctx_addr;
if (version)
*version = ctx->currentversion;
return ctx;
}
/* filter for xattr fetch */
static inline int
br_stub_is_internal_xattr (const char *name)
{
if (name
&& ((strncmp (name, BITROT_CURRENT_VERSION_KEY,
strlen (BITROT_CURRENT_VERSION_KEY)) == 0)
|| (strncmp (name, BITROT_SIGNING_VERSION_KEY,
strlen (BITROT_SIGNING_VERSION_KEY)) == 0)))
return 1;
return 0;
}
static inline void
br_stub_remove_vxattrs (dict_t *xattr)
{
if (xattr) {
dict_del (xattr, BITROT_CURRENT_VERSION_KEY);
dict_del (xattr, BITROT_SIGNING_VERSION_KEY);
dict_del (xattr, BITROT_SIGNING_XATTR_SIZE_KEY);
}
}
#endif /* __BIT_ROT_STUB_H__ */
|