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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
|
/*
Copyright (c) 2008-2010 Gluster, Inc. <http://www.gluster.com>
This file is part of GlusterFS.
GlusterFS is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.
GlusterFS is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif
#include "glusterfs.h"
#include "xlator.h"
#include "compat.h"
#include "dht-common.h"
int
dht_linkfile_xattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int op_ret, int op_errno)
{
dht_local_t *local = NULL;
local = frame->local;
local->linkfile.linkfile_cbk (frame, cookie, this, op_ret, op_errno,
local->linkfile.inode,
&local->linkfile.stbuf, NULL, NULL);
return 0;
}
int
dht_linkfile_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int op_ret, int op_errno, inode_t *inode,
struct iatt *stbuf, struct iatt *preparent,
struct iatt *postparent)
{
dht_local_t *local = NULL;
call_frame_t *prev = NULL;
dict_t *xattr = NULL;
data_t *str_data = NULL;
int ret = -1;
local = frame->local;
prev = cookie;
if (op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING,
"%s: failed to create link file (%s)",
local->linkfile.loc.path, strerror (op_errno));
goto err;
}
xattr = get_new_dict ();
if (!xattr) {
op_errno = ENOMEM;
goto err;
}
local->linkfile.xattr = dict_ref (xattr);
local->linkfile.inode = inode_ref (inode);
str_data = str_to_data (local->linkfile.srcvol->name);
if (!str_data) {
op_errno = ENOMEM;
goto err;
}
ret = dict_set (xattr, "trusted.glusterfs.dht.linkto", str_data);
if (ret < 0) {
gf_log (this->name, GF_LOG_INFO,
"%s: failed to initialize linkfile data",
local->linkfile.loc.path);
}
str_data = NULL;
local->linkfile.stbuf = *stbuf;
if (uuid_is_null (local->linkfile.loc.inode->gfid))
uuid_copy (local->linkfile.loc.gfid, stbuf->ia_gfid);
STACK_WIND (frame, dht_linkfile_xattr_cbk,
prev->this, prev->this->fops->setxattr,
&local->linkfile.loc, local->linkfile.xattr, 0);
return 0;
err:
if (str_data) {
data_destroy (str_data);
str_data = NULL;
}
local->linkfile.linkfile_cbk (frame, cookie, this, op_ret, op_errno,
inode, stbuf, preparent, postparent);
return 0;
}
int
dht_linkfile_create (call_frame_t *frame, fop_mknod_cbk_t linkfile_cbk,
xlator_t *tovol, xlator_t *fromvol, loc_t *loc)
{
dht_local_t *local = NULL;
dict_t *dict = NULL;
int ret = 0;
local = frame->local;
local->linkfile.linkfile_cbk = linkfile_cbk;
local->linkfile.srcvol = tovol;
loc_copy (&local->linkfile.loc, loc);
if (!uuid_is_null (local->gfid)) {
dict = dict_new ();
if (!dict)
goto out;
ret = dict_set_static_bin (dict, "gfid-req", local->gfid, 16);
if (ret)
gf_log ("dht-linkfile", GF_LOG_INFO,
"%s: gfid set failed", loc->path);
} else if (local->params) {
dict = dict_ref (local->params);
}
if (!dict)
gf_log (frame->this->name, GF_LOG_INFO,
"dict is NULL, need to make sure gfid's are same");
STACK_WIND (frame, dht_linkfile_create_cbk,
fromvol, fromvol->fops->mknod, loc,
S_IFREG | DHT_LINKFILE_MODE, 0, dict);
if (dict)
dict_unref (dict);
return 0;
out:
local->linkfile.linkfile_cbk (frame, NULL, frame->this, -1, ENOMEM,
loc->inode, NULL, NULL, NULL);
return 0;
}
int
dht_linkfile_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
struct iatt *preparent, struct iatt *postparent)
{
dht_local_t *local = NULL;
call_frame_t *prev = NULL;
xlator_t *subvol = NULL;
local = frame->local;
prev = cookie;
subvol = prev->this;
if (op_ret == -1) {
gf_log (this->name, GF_LOG_INFO,
"unlinking linkfile %s on %s failed (%s)",
local->loc.path, subvol->name, strerror (op_errno));
}
DHT_STACK_DESTROY (frame);
return 0;
}
int
dht_linkfile_unlink (call_frame_t *frame, xlator_t *this,
xlator_t *subvol, loc_t *loc)
{
call_frame_t *unlink_frame = NULL;
dht_local_t *unlink_local = NULL;
unlink_frame = copy_frame (frame);
if (!unlink_frame) {
goto err;
}
unlink_local = dht_local_init (unlink_frame);
if (!unlink_local) {
goto err;
}
loc_copy (&unlink_local->loc, loc);
STACK_WIND (unlink_frame, dht_linkfile_unlink_cbk,
subvol, subvol->fops->unlink,
&unlink_local->loc);
return 0;
err:
if (unlink_frame)
DHT_STACK_DESTROY (unlink_frame);
return -1;
}
xlator_t *
dht_linkfile_subvol (xlator_t *this, inode_t *inode, struct iatt *stbuf,
dict_t *xattr)
{
dht_conf_t *conf = NULL;
xlator_t *subvol = NULL;
void *volname = NULL;
int i = 0, ret = 0;
conf = this->private;
if (!xattr)
goto out;
ret = dict_get_ptr (xattr, "trusted.glusterfs.dht.linkto", &volname);
if ((-1 == ret) || !volname)
goto out;
for (i = 0; i < conf->subvolume_cnt; i++) {
if (strcmp (conf->subvolumes[i]->name, (char *)volname) == 0) {
subvol = conf->subvolumes[i];
break;
}
}
out:
return subvol;
}
int
dht_recreate_linkfile_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t op_ret, int32_t op_errno,
struct iatt *preparent, struct iatt *postparent)
{
dht_local_t *local = NULL;
xlator_t *subvol = NULL;
xlator_t *src_cached = NULL;
xlator_t *dst_hashed = NULL;
call_frame_t *prev = NULL;
loc_t *loc = NULL;
GF_VALIDATE_OR_GOTO ("dht", frame, err);
GF_VALIDATE_OR_GOTO ("dht", this, err);
GF_VALIDATE_OR_GOTO ("dht", frame->local, err);
local = frame->local;
prev = cookie;
subvol = prev->this;
src_cached = local->src_cached;
dst_hashed = local->dst_hashed;
loc = &local->loc;
if (!src_cached || !dst_hashed) {
gf_log (this->name, GF_LOG_ERROR, "src_cached or dst_hashed"
"subvol is null");
local->op_ret = -1;
local->op_errno = EINVAL;
goto out;
}
if (op_ret == -1) {
gf_log (this->name, GF_LOG_ERROR,
"unlinking linkfile %s on %s failed (%s)",
loc->path, subvol->name, strerror (op_errno));
local->op_ret = op_ret;
local->op_errno = op_errno;
goto out;
}
gf_log (this->name, GF_LOG_DEBUG, "unlink successfull. Proceeding with"
" creation of link file %s", loc->path);
dht_linkfile_create (frame, local->linkfile.linkfile_cbk,
src_cached, dst_hashed, loc);
return 0;
out:
local->linkfile.linkfile_cbk (frame, NULL, frame->this, -1, EINVAL,
local->loc.inode, NULL, NULL, NULL);
err:
return -1;
}
int
dht_linkfile_recreate_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int op_ret, int op_errno,
inode_t *inode, struct iatt *stbuf, dict_t *xattr,
struct iatt *postparent)
{
dht_local_t *local = NULL;
xlator_t *src_cached = NULL;
xlator_t *dst_hashed = NULL;
loc_t *loc = NULL;
GF_VALIDATE_OR_GOTO ("dht", frame, err);
GF_VALIDATE_OR_GOTO ("dht", this, err);
GF_VALIDATE_OR_GOTO ("dht", frame->local, err);
local = frame->local;
loc = &local->loc;
src_cached = local->src_cached;
dst_hashed = local->dst_hashed;
if (!src_cached || !dst_hashed) {
gf_log (this->name, GF_LOG_ERROR, "src_cached or dst_hashed"
" or hashed_subvol is null");
local->op_ret = -1;
local->op_errno = EINVAL;
goto out;
}
/* if link_file exists, remove it, else create it*/
if (!op_ret) {
if (!check_is_linkfile (inode, stbuf, xattr))
goto out;
gf_log (this->name, GF_LOG_DEBUG, "link file exists."
" Calling unlink on %s", loc->path);
STACK_WIND (frame, dht_recreate_linkfile_unlink_cbk,
dst_hashed, dst_hashed->fops->unlink,
loc);
} else if (op_errno == ENOENT) {
gf_log (this->name, GF_LOG_DEBUG, "link file does not exist."
" Proceeding to creation of linkfile %s", loc->path);
dht_linkfile_create (frame, local->linkfile.linkfile_cbk,
src_cached, dst_hashed, loc);
} else {
gf_log (this->name, GF_LOG_ERROR, "returned error %s",
strerror(op_errno));
local->op_ret = op_ret;
local->op_errno = op_errno;
goto out;
}
return 0;
out:
local->linkfile.linkfile_cbk (frame, NULL, frame->this, -1, EINVAL,
loc->inode, NULL, NULL, NULL);
err:
return -1;
}
int
dht_linkfile_recreate (call_frame_t *frame, fop_mknod_cbk_t linkfile_cbk,
xlator_t *tovol, xlator_t *fromvol, loc_t *loc)
{
dht_local_t *local = NULL;
GF_VALIDATE_OR_GOTO ("dht", frame, out);
GF_VALIDATE_OR_GOTO ("dht", loc, out);
GF_VALIDATE_OR_GOTO ("dht", tovol, out);
GF_VALIDATE_OR_GOTO ("dht", fromvol, out);
local = frame->local;
local->linkfile.linkfile_cbk = linkfile_cbk;
local->linkfile.srcvol = tovol;
loc_copy (&local->linkfile.loc, loc);
STACK_WIND (frame, dht_linkfile_recreate_cbk,
fromvol, fromvol->fops->lookup, loc, NULL);
return 0;
out:
linkfile_cbk (frame, NULL, frame->this, -1, EINVAL, loc->inode, NULL,
NULL, NULL);
return -1;
}
|