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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
|
/*
Copyright (c) 2008-2012 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.
*/
#include "xlator.h"
#include <dlfcn.h>
#include <netdb.h>
#include <fnmatch.h>
#include "defaults.h"
#include "libglusterfs-messages.h"
#define SET_DEFAULT_FOP(fn) \
do { \
if (!xl->fops->fn) \
xl->fops->fn = default_##fn; \
if (!xl->pass_through_fops->fn) \
xl->pass_through_fops->fn = default_##fn; \
} while (0)
#define SET_DEFAULT_CBK(fn) \
do { \
if (!xl->cbks->fn) \
xl->cbks->fn = default_##fn; \
} while (0)
pthread_mutex_t xlator_init_mutex = PTHREAD_MUTEX_INITIALIZER;
void
xlator_init_lock(void)
{
(void)pthread_mutex_lock(&xlator_init_mutex);
}
void
xlator_init_unlock(void)
{
(void)pthread_mutex_unlock(&xlator_init_mutex);
}
static struct xlator_cbks default_cbks = {};
struct volume_options default_options[] = {
{
.key = {"log-level"},
.type = GF_OPTION_TYPE_STR,
.op_version = {GD_OP_VERSION_6_0},
.flags = OPT_FLAG_SETTABLE,
.tags = {"generic"},
.value = {"DEBUG", "WARNING", "ERROR", "INFO", "CRITICAL", "NONE",
"TRACE"},
.description = "Option to set log-level of given translator",
},
{
.key = {NULL},
},
};
/* Handle the common options in each translator */
void
handle_default_options(xlator_t *xl, dict_t *options)
{
int ret;
char *value;
/* log-level */
ret = dict_get_str(options, "log-level", &value);
if (!ret) {
int log_level = glusterd_check_log_level(value);
if (log_level != -1) {
xl->loglevel = log_level;
}
}
}
static void
fill_defaults(xlator_t *xl)
{
if (xl == NULL) {
gf_msg_callingfn("xlator", GF_LOG_WARNING, EINVAL, LG_MSG_INVALID_ARG,
"invalid argument");
return;
}
if (!xl->pass_through_fops)
xl->pass_through_fops = default_fops;
SET_DEFAULT_FOP(create);
SET_DEFAULT_FOP(open);
SET_DEFAULT_FOP(stat);
SET_DEFAULT_FOP(readlink);
SET_DEFAULT_FOP(mknod);
SET_DEFAULT_FOP(mkdir);
SET_DEFAULT_FOP(unlink);
SET_DEFAULT_FOP(rmdir);
SET_DEFAULT_FOP(symlink);
SET_DEFAULT_FOP(rename);
SET_DEFAULT_FOP(link);
SET_DEFAULT_FOP(truncate);
SET_DEFAULT_FOP(readv);
SET_DEFAULT_FOP(writev);
SET_DEFAULT_FOP(statfs);
SET_DEFAULT_FOP(flush);
SET_DEFAULT_FOP(fsync);
SET_DEFAULT_FOP(setxattr);
SET_DEFAULT_FOP(getxattr);
SET_DEFAULT_FOP(fsetxattr);
SET_DEFAULT_FOP(fgetxattr);
SET_DEFAULT_FOP(removexattr);
SET_DEFAULT_FOP(fremovexattr);
SET_DEFAULT_FOP(opendir);
SET_DEFAULT_FOP(readdir);
SET_DEFAULT_FOP(readdirp);
SET_DEFAULT_FOP(fsyncdir);
SET_DEFAULT_FOP(access);
SET_DEFAULT_FOP(ftruncate);
SET_DEFAULT_FOP(fstat);
SET_DEFAULT_FOP(lk);
SET_DEFAULT_FOP(inodelk);
SET_DEFAULT_FOP(finodelk);
SET_DEFAULT_FOP(entrylk);
SET_DEFAULT_FOP(fentrylk);
SET_DEFAULT_FOP(lookup);
SET_DEFAULT_FOP(rchecksum);
SET_DEFAULT_FOP(xattrop);
SET_DEFAULT_FOP(fxattrop);
SET_DEFAULT_FOP(setattr);
SET_DEFAULT_FOP(fsetattr);
SET_DEFAULT_FOP(fallocate);
SET_DEFAULT_FOP(discard);
SET_DEFAULT_FOP(zerofill);
SET_DEFAULT_FOP(ipc);
SET_DEFAULT_FOP(seek);
SET_DEFAULT_FOP(lease);
SET_DEFAULT_FOP(getactivelk);
SET_DEFAULT_FOP(setactivelk);
SET_DEFAULT_FOP(put);
SET_DEFAULT_FOP(getspec);
SET_DEFAULT_FOP(icreate);
SET_DEFAULT_FOP(namelink);
if (!xl->cbks)
xl->cbks = &default_cbks;
SET_DEFAULT_CBK(release);
SET_DEFAULT_CBK(releasedir);
SET_DEFAULT_CBK(forget);
if (!xl->fini)
xl->fini = default_fini;
if (!xl->notify)
xl->notify = default_notify;
if (!xl->mem_acct_init)
xl->mem_acct_init = default_mem_acct_init;
return;
}
int
xlator_set_type_virtual(xlator_t *xl, const char *type)
{
GF_VALIDATE_OR_GOTO("xlator", xl, out);
GF_VALIDATE_OR_GOTO("xlator", type, out);
xl->type = gf_strdup(type);
if (xl->type)
return 0;
out:
return -1;
}
int
xlator_volopt_dynload(char *xlator_type, void **dl_handle,
volume_opt_list_t *opt_list)
{
int ret = -1;
char *name = NULL;
void *handle = NULL;
xlator_api_t *xlapi = NULL;
GF_VALIDATE_OR_GOTO("xlator", xlator_type, out);
/* socket.so doesn't fall under the default xlator directory, hence we
* need this check */
if (!strstr(xlator_type, "rpc-transport"))
ret = gf_asprintf(&name, "%s/%s.so", XLATORDIR, xlator_type);
else
ret = gf_asprintf(&name, "%s/%s.so", XLATORPARENTDIR, xlator_type);
if (-1 == ret) {
goto out;
}
ret = -1;
gf_msg_trace("xlator", 0, "attempt to load file %s", name);
handle = dlopen(name, RTLD_NOW);
if (!handle) {
gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLOPEN_FAILED, "%s",
dlerror());
goto out;
}
/* check new struct first, and then check this */
xlapi = dlsym(handle, "xlator_api");
if (!xlapi) {
gf_msg("xlator", GF_LOG_DEBUG, 0, LG_MSG_DLSYM_ERROR,
"dlsym(xlator_api) on %s. "
"Fall back to old symbols",
dlerror());
/* This case is not an error for now, so allow it
to fall back to old methods. */
opt_list->given_opt = dlsym(handle, "options");
if (!opt_list->given_opt) {
dlerror();
gf_msg("xlator", GF_LOG_ERROR, 0, LG_MSG_LOAD_FAILED,
"Failed to load xlator opt table");
goto out;
}
} else {
opt_list->given_opt = xlapi->options;
if (!opt_list->given_opt) {
gf_msg("xlator", GF_LOG_ERROR, 0, LG_MSG_LOAD_FAILED,
"Failed to load xlator options table");
goto out;
}
}
*dl_handle = handle;
handle = NULL;
ret = 0;
out:
GF_FREE(name);
if (handle)
dlclose(handle);
gf_msg_debug("xlator", 0, "Returning %d", ret);
return ret;
}
int
xlator_dynload_oldway(xlator_t *xl)
{
int i = 0;
int ret = -1;
void *handle = NULL;
volume_opt_list_t *vol_opt = NULL;
class_methods_t *vtbl = NULL;
handle = xl->dlhandle;
xl->fops = dlsym(handle, "fops");
if (!xl->fops) {
gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR,
"dlsym(fops) on %s", dlerror());
goto out;
}
xl->cbks = dlsym(handle, "cbks");
if (!xl->cbks) {
gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR,
"dlsym(cbks) on %s", dlerror());
goto out;
}
/*
* If class_methods exists, its contents override any definitions of
* init or fini for that translator. Otherwise, we fall back to the
* older method of looking for init and fini directly.
*/
vtbl = dlsym(handle, "class_methods");
if (vtbl) {
xl->init = vtbl->init;
xl->fini = vtbl->fini;
xl->reconfigure = vtbl->reconfigure;
xl->notify = vtbl->notify;
} else {
if (!(*VOID(&xl->init) = dlsym(handle, "init"))) {
gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR,
"dlsym(init) on %s", dlerror());
goto out;
}
if (!(*VOID(&(xl->fini)) = dlsym(handle, "fini"))) {
gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR,
"dlsym(fini) on %s", dlerror());
goto out;
}
if (!(*VOID(&(xl->reconfigure)) = dlsym(handle, "reconfigure"))) {
gf_msg_trace("xlator", 0,
"dlsym(reconfigure) on %s "
"-- neglecting",
dlerror());
}
if (!(*VOID(&(xl->notify)) = dlsym(handle, "notify"))) {
gf_msg_trace("xlator", 0,
"dlsym(notify) on %s -- "
"neglecting",
dlerror());
}
}
if (!(xl->dumpops = dlsym(handle, "dumpops"))) {
gf_msg_trace("xlator", 0,
"dlsym(dumpops) on %s -- "
"neglecting",
dlerror());
}
if (!(*VOID(&(xl->mem_acct_init)) = dlsym(handle, "mem_acct_init"))) {
gf_msg_trace(xl->name, 0,
"dlsym(mem_acct_init) on %s -- "
"neglecting",
dlerror());
}
vol_opt = GF_CALLOC(1, sizeof(volume_opt_list_t),
gf_common_mt_volume_opt_list_t);
if (!vol_opt) {
goto out;
}
INIT_LIST_HEAD(&vol_opt->list);
vol_opt->given_opt = dlsym(handle, "options");
if (!vol_opt->given_opt) {
vol_opt->given_opt = default_options;
}
list_add_tail(&vol_opt->list, &xl->volume_options);
/* make sure 'min' is set to high value, so it would be
properly set later */
for (i = 0; i < GF_FOP_MAXVALUE; i++) {
xl->stats.interval.latencies[i].min = 0xffffffff;
}
ret = 0;
out:
return ret;
}
int
xlator_dynload_newway(xlator_t *xl)
{
int ret = -1;
void *handle = NULL;
volume_opt_list_t *vol_opt = NULL;
xlator_api_t *xlapi = NULL;
handle = xl->dlhandle;
xlapi = dlsym(handle, "xlator_api");
if (!xlapi) {
gf_msg("xlator", GF_LOG_INFO, 0, LG_MSG_DLSYM_ERROR,
"dlsym(xlator_api) on %s. "
"Fall back to old symbols",
dlerror());
/* This case is not an error for now, so allow it
to fall back to old methods. */
ret = 1;
goto out;
}
xl->fops = xlapi->fops;
if (!xl->fops) {
gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR,
"%s: struct missing (fops)", xl->name);
goto out;
}
xl->cbks = xlapi->cbks;
if (!xl->cbks) {
gf_msg_trace("xlator", 0, "%s: struct missing (cbks)", xl->name);
}
xl->init = xlapi->init;
if (!xl->init) {
gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLSYM_ERROR,
"%s: method missing (init)", xl->name);
goto out;
}
xl->fini = xlapi->fini;
if (!xl->fini) {
gf_msg_trace("xlator", 0, "%s: method missing (fini)", xl->name);
}
xl->reconfigure = xlapi->reconfigure;
if (!xl->reconfigure) {
gf_msg_trace("xlator", 0, "%s: method missing (reconfigure)", xl->name);
}
xl->notify = xlapi->notify;
if (!xl->notify) {
gf_msg_trace("xlator", 0, "%s: method missing (notify)", xl->name);
}
xl->dumpops = xlapi->dumpops;
if (!xl->dumpops) {
gf_msg_trace("xlator", 0, "%s: method missing (dumpops)", xl->name);
}
xl->mem_acct_init = xlapi->mem_acct_init;
if (!xl->mem_acct_init) {
gf_msg_trace("xlator", 0, "%s: method missing (mem_acct_init)",
xl->name);
}
xl->dump_metrics = xlapi->dump_metrics;
if (!xl->dump_metrics) {
gf_msg_trace("xlator", 0, "%s: method missing (dump_metrics)",
xl->name);
}
xl->pass_through_fops = xlapi->pass_through_fops;
if (!xl->pass_through_fops) {
gf_msg_trace("xlator", 0,
"%s: method missing (pass_through_fops), "
"falling back to default",
xl->name);
}
vol_opt = GF_CALLOC(1, sizeof(volume_opt_list_t),
gf_common_mt_volume_opt_list_t);
if (!vol_opt) {
goto out;
}
INIT_LIST_HEAD(&vol_opt->list);
vol_opt->given_opt = default_options;
list_add_tail(&vol_opt->list, &xl->volume_options);
if (xlapi->options) {
vol_opt = GF_CALLOC(1, sizeof(volume_opt_list_t),
gf_common_mt_volume_opt_list_t);
if (!vol_opt) {
goto out;
}
INIT_LIST_HEAD(&vol_opt->list);
vol_opt->given_opt = xlapi->options;
list_add_tail(&vol_opt->list, &xl->volume_options);
}
xl->id = xlapi->xlator_id;
xl->flags = xlapi->flags;
xl->identifier = xlapi->identifier;
xl->category = xlapi->category;
memcpy(xl->op_version, xlapi->op_version,
sizeof(uint32_t) * GF_MAX_RELEASES);
ret = 0;
out:
return ret;
}
int
xlator_dynload(xlator_t *xl)
{
int ret = -1;
char *name = NULL;
void *handle = NULL;
GF_VALIDATE_OR_GOTO("xlator", xl, out);
INIT_LIST_HEAD(&xl->volume_options);
ret = gf_asprintf(&name, "%s/%s.so", XLATORDIR, xl->type);
if (-1 == ret) {
goto out;
}
ret = -1;
gf_msg_trace("xlator", 0, "attempt to load file %s", name);
handle = dlopen(name, RTLD_NOW);
if (!handle) {
gf_msg("xlator", GF_LOG_WARNING, 0, LG_MSG_DLOPEN_FAILED, "%s",
dlerror());
goto out;
}
xl->dlhandle = handle;
ret = xlator_dynload_newway(xl);
if (-1 == ret)
goto out;
if (1 == ret) {
/* it means we don't find the new symbol in xlator code */
ret = xlator_dynload_oldway(xl);
if (-1 == ret)
goto out;
}
fill_defaults(xl);
ret = 0;
out:
GF_FREE(name);
return ret;
}
int
xlator_set_type(xlator_t *xl, const char *type)
{
int ret = 0;
/* Handle 'global' translator differently */
if (!strncmp(GF_GLOBAL_XLATOR_NAME, type, SLEN(GF_GLOBAL_XLATOR_NAME))) {
volume_opt_list_t *vol_opt = NULL;
/* set the required values from Global xlator */
xl->type = gf_strdup(GF_GLOBAL_XLATOR_NAME);
xl->cbks = global_xlator.cbks;
xl->fops = global_xlator.fops;
xl->init = global_xlator.init;
xl->fini = global_xlator.fini;
xl->reconfigure = global_xlator.reconfigure;
vol_opt = GF_CALLOC(1, sizeof(volume_opt_list_t),
gf_common_mt_volume_opt_list_t);
if (!vol_opt) {
ret = -1;
goto out;
}
vol_opt->given_opt = global_xl_options;
INIT_LIST_HEAD(&xl->volume_options);
INIT_LIST_HEAD(&vol_opt->list);
list_add_tail(&vol_opt->list, &xl->volume_options);
fill_defaults(xl);
ret = 0;
goto out;
}
ret = xlator_set_type_virtual(xl, type);
if (!ret)
ret = xlator_dynload(xl);
out:
return ret;
}
void
xlator_set_inode_lru_limit(xlator_t *this, void *data)
{
int inode_lru_limit = 0;
if (this->itable) {
if (!data) {
gf_msg(this->name, GF_LOG_WARNING, 0, LG_MSG_INVALID_ENTRY,
"input data is NULL. "
"Cannot update the lru limit of the inode"
" table. Continuing with older value");
goto out;
}
inode_lru_limit = *(int *)data;
inode_table_set_lru_limit(this->itable, inode_lru_limit);
}
out:
return;
}
void
xlator_foreach(xlator_t *this, void (*fn)(xlator_t *each, void *data),
void *data)
{
xlator_t *first = NULL;
xlator_t *old_THIS = NULL;
GF_VALIDATE_OR_GOTO("xlator", this, out);
GF_VALIDATE_OR_GOTO("xlator", fn, out);
first = this;
while (first->prev)
first = first->prev;
while (first) {
old_THIS = THIS;
THIS = first;
fn(first, data);
THIS = old_THIS;
first = first->next;
}
out:
return;
}
void
xlator_foreach_depth_first(xlator_t *this,
void (*fn)(xlator_t *each, void *data), void *data)
{
xlator_list_t *subv = NULL;
subv = this->children;
while (subv) {
xlator_foreach_depth_first(subv->xlator, fn, data);
subv = subv->next;
}
fn(this, data);
}
xlator_t *
xlator_search_by_name(xlator_t *any, const char *name)
{
xlator_t *search = NULL;
GF_VALIDATE_OR_GOTO("xlator", any, out);
GF_VALIDATE_OR_GOTO("xlator", name, out);
search = any;
while (search->prev)
search = search->prev;
while (search) {
if (!strcmp(search->name, name))
break;
search = search->next;
}
out:
return search;
}
/*
* With brick multiplexing, we sort of have multiple graphs, so
* xlator_search_by_name might not find what we want. Also, the translator
* we're looking for might not be a direct child if something else was put in
* between (as already happened with decompounder before that was fixed) and
* it's hard to debug why our translator wasn't found. Using a recursive tree
* search instead of a linear search works around both problems.
*/
static xlator_t *
get_xlator_by_name_or_type(xlator_t *this, char *target, int is_name)
{
xlator_list_t *trav;
xlator_t *child_xl;
char *value;
for (trav = this->children; trav; trav = trav->next) {
value = is_name ? trav->xlator->name : trav->xlator->type;
if (!strcmp(value, target) && !trav->xlator->cleanup_starting) {
return trav->xlator;
}
child_xl = get_xlator_by_name_or_type(trav->xlator, target, is_name);
if (child_xl) {
/*
* If the xlator we're looking for is somewhere down
* the stack, get_xlator_by_name expects to get a
* pointer to the top of its subtree (child of "this")
* while get_xlator_by_type expects a pointer to what
* we actually found. Handle both cases here.
*
* TBD: rename the functions and fix callers to better
* reflect the difference in semantics.
*/
return is_name ? trav->xlator : child_xl;
}
}
return NULL;
}
xlator_t *
get_xlator_by_name(xlator_t *this, char *target)
{
return get_xlator_by_name_or_type(this, target, 1);
}
xlator_t *
get_xlator_by_type(xlator_t *this, char *target)
{
return get_xlator_by_name_or_type(this, target, 0);
}
static int
__xlator_init(xlator_t *xl)
{
xlator_t *old_THIS = NULL;
int ret = 0;
int fop_idx = 0;
old_THIS = THIS;
THIS = xl;
/* initialize the metrics related locks */
for (fop_idx = 0; fop_idx < GF_FOP_MAXVALUE; fop_idx++) {
GF_ATOMIC_INIT(xl->stats.total.metrics[fop_idx].fop, 0);
GF_ATOMIC_INIT(xl->stats.total.metrics[fop_idx].cbk, 0);
GF_ATOMIC_INIT(xl->stats.interval.metrics[fop_idx].fop, 0);
GF_ATOMIC_INIT(xl->stats.interval.metrics[fop_idx].cbk, 0);
}
GF_ATOMIC_INIT(xl->stats.total.count, 0);
GF_ATOMIC_INIT(xl->stats.interval.count, 0);
xlator_init_lock();
handle_default_options(xl, xl->options);
ret = xl->init(xl);
xlator_init_unlock();
THIS = old_THIS;
return ret;
}
int
xlator_init(xlator_t *xl)
{
int32_t ret = -1;
GF_VALIDATE_OR_GOTO("xlator", xl, out);
if (xl->mem_acct_init)
xl->mem_acct_init(xl);
xl->instance_name = NULL;
GF_ATOMIC_INIT(xl->xprtrefcnt, 0);
GF_ATOMIC_INIT(xl->fd_cnt, 0);
if (!xl->init) {
gf_msg(xl->name, GF_LOG_WARNING, 0, LG_MSG_INIT_FAILED,
"No init() found");
goto out;
}
ret = __xlator_init(xl);
if (ret) {
gf_msg(xl->name, GF_LOG_ERROR, 0, LG_MSG_VOLUME_ERROR,
"Initialization of volume '%s' failed,"
" review your volfile again",
xl->name);
goto out;
}
xl->init_succeeded = 1;
/*xl->cleanup_starting = 0;
xl->call_cleanup = 0;
*/
ret = 0;
out:
return ret;
}
static void
xlator_fini_rec(xlator_t *xl)
{
xlator_list_t *trav = NULL;
xlator_t *old_THIS = NULL;
GF_VALIDATE_OR_GOTO("xlator", xl, out);
trav = xl->children;
while (trav) {
if (!trav->xlator->init_succeeded) {
break;
}
xlator_fini_rec(trav->xlator);
gf_msg_debug(trav->xlator->name, 0, "fini done");
trav = trav->next;
}
if (xl->init_succeeded) {
if (xl->fini) {
old_THIS = THIS;
THIS = xl;
xl->fini(xl);
if (xl->local_pool)
mem_pool_destroy(xl->local_pool);
THIS = old_THIS;
} else {
gf_msg_debug(xl->name, 0, "No fini() found");
}
xl->init_succeeded = 0;
}
out:
return;
}
int
xlator_notify(xlator_t *xl, int event, void *data, ...)
{
xlator_t *old_THIS = NULL;
int ret = 0;
old_THIS = THIS;
THIS = xl;
ret = xl->notify(xl, event, data);
THIS = old_THIS;
return ret;
}
int
xlator_mem_acct_init(xlator_t *xl, int num_types)
{
int i = 0;
int ret = 0;
if (!xl)
return -1;
if (!xl->ctx)
return -1;
if (!xl->ctx->mem_acct_enable)
return 0;
xl->mem_acct = MALLOC(sizeof(struct mem_acct) +
sizeof(struct mem_acct_rec) * num_types);
if (!xl->mem_acct) {
return -1;
}
xl->mem_acct->num_types = num_types;
GF_ATOMIC_INIT(xl->mem_acct->refcnt, 1);
for (i = 0; i < num_types; i++) {
memset(&xl->mem_acct->rec[i], 0, sizeof(struct mem_acct_rec));
ret = LOCK_INIT(&(xl->mem_acct->rec[i].lock));
if (ret) {
fprintf(stderr, "Unable to lock..errno : %d", errno);
}
#ifdef DEBUG
INIT_LIST_HEAD(&(xl->mem_acct->rec[i].obj_list));
#endif
}
return 0;
}
void
xlator_tree_fini(xlator_t *xl)
{
xlator_t *top = NULL;
GF_VALIDATE_OR_GOTO("xlator", xl, out);
top = xl;
xlator_fini_rec(top);
out:
return;
}
int
xlator_list_destroy(xlator_list_t *list)
{
xlator_list_t *next = NULL;
while (list) {
next = list->next;
GF_FREE(list);
list = next;
}
return 0;
}
int
xlator_memrec_free(xlator_t *xl)
{
uint32_t i = 0;
struct mem_acct *mem_acct = NULL;
if (!xl) {
return 0;
}
mem_acct = xl->mem_acct;
if (mem_acct) {
for (i = 0; i < mem_acct->num_types; i++) {
LOCK_DESTROY(&(mem_acct->rec[i].lock));
}
if (GF_ATOMIC_DEC(mem_acct->refcnt) == 0) {
FREE(mem_acct);
xl->mem_acct = NULL;
}
}
return 0;
}
static int
xlator_members_free(xlator_t *xl)
{
volume_opt_list_t *vol_opt = NULL;
volume_opt_list_t *tmp = NULL;
if (!xl)
return 0;
GF_FREE(xl->name);
GF_FREE(xl->type);
if (!(xl->ctx && xl->ctx->cmd_args.valgrind) && xl->dlhandle)
dlclose(xl->dlhandle);
if (xl->options)
dict_unref(xl->options);
xlator_list_destroy(xl->children);
xlator_list_destroy(xl->parents);
list_for_each_entry_safe(vol_opt, tmp, &xl->volume_options, list)
{
list_del_init(&vol_opt->list);
GF_FREE(vol_opt);
}
return 0;
}
/* This function destroys all the xlator members except for the
* xlator strcuture and its mem accounting field.
*
* If otherwise, it would destroy the master xlator object as well
* its mem accounting, which would mean after calling glusterfs_graph_destroy()
* there cannot be any reference to GF_FREE() from the master xlator, this is
* not possible because of the following dependencies:
* - glusterfs_ctx_t will have mem pools allocated by the master xlators
* - xlator objects will have references to those mem pools(g: dict)
*
* Ordering the freeing in any of the order will also not solve the dependency:
* - Freeing xlator objects(including memory accounting) before mem pools
* destruction will mean not use GF_FREE while destroying mem pools.
* - Freeing mem pools and then destroying xlator objects would lead to crashes
* when xlator tries to unref dict or other mem pool objects.
*
* Hence the way chosen out of this interdependency is to split xlator object
* free into two stages:
* - Free all the xlator members excpet for its mem accounting structure
* - Free all the mem accouting structures of xlator along with the xlator
* object itself.
*
* This two stages of destruction, is mainly required for glfs_fini().
*/
int
xlator_tree_free_members(xlator_t *tree)
{
xlator_t *trav = tree;
xlator_t *prev = tree;
if (!tree) {
gf_msg("parser", GF_LOG_ERROR, 0, LG_MSG_TREE_NOT_FOUND,
"Translator tree not found");
return -1;
}
while (prev) {
trav = prev->next;
xlator_members_free(prev);
prev = trav;
}
return 0;
}
int
xlator_tree_free_memacct(xlator_t *tree)
{
xlator_t *trav = tree;
xlator_t *prev = tree;
if (!tree) {
gf_msg("parser", GF_LOG_ERROR, 0, LG_MSG_TREE_NOT_FOUND,
"Translator tree not found");
return -1;
}
while (prev) {
trav = prev->next;
xlator_memrec_free(prev);
GF_FREE(prev);
prev = trav;
}
return 0;
}
static int
xlator_mem_free(xlator_t *xl)
{
volume_opt_list_t *vol_opt = NULL;
volume_opt_list_t *tmp = NULL;
if (!xl)
return 0;
if (xl->options) {
dict_ref(xl->options);
dict_unref(xl->options);
xl->options = NULL;
}
list_for_each_entry_safe(vol_opt, tmp, &xl->volume_options, list)
{
list_del_init(&vol_opt->list);
GF_FREE(vol_opt);
}
xlator_memrec_free(xl);
return 0;
}
static void
xlator_call_fini(xlator_t *this)
{
if (!this || this->cleanup_starting)
return;
this->cleanup_starting = 1;
this->call_cleanup = 1;
xlator_call_fini(this->next);
this->fini(this);
}
void
xlator_mem_cleanup(xlator_t *this)
{
xlator_list_t *list = this->children;
xlator_t *trav = list->xlator;
inode_table_t *inode_table = NULL;
xlator_t *prev = trav;
glusterfs_ctx_t *ctx = NULL;
xlator_list_t **trav_p = NULL;
xlator_t *top = NULL;
xlator_t *victim = NULL;
if (this->call_cleanup || !this->ctx)
return;
this->call_cleanup = 1;
ctx = this->ctx;
xlator_call_fini(trav);
while (prev) {
trav = prev->next;
xlator_mem_free(prev);
prev = trav;
}
inode_table = this->itable;
if (inode_table) {
inode_table_destroy(inode_table);
this->itable = NULL;
}
if (this->fini) {
this->fini(this);
}
xlator_mem_free(this);
if (ctx->active) {
top = ctx->active->first;
LOCK(&ctx->volfile_lock);
/* TODO here we have leak for xlator node in a graph */
/* Need to move only top xlator from a graph */
for (trav_p = &top->children; *trav_p; trav_p = &(*trav_p)->next) {
victim = (*trav_p)->xlator;
if (victim->call_cleanup && !strcmp(victim->name, this->name)) {
(*trav_p) = (*trav_p)->next;
break;
}
}
UNLOCK(&ctx->volfile_lock);
}
}
void
loc_wipe(loc_t *loc)
{
if (loc->inode) {
inode_unref(loc->inode);
loc->inode = NULL;
}
if (loc->path) {
GF_FREE((char *)loc->path);
loc->path = NULL;
}
if (loc->parent) {
inode_unref(loc->parent);
loc->parent = NULL;
}
memset(loc, 0, sizeof(*loc));
}
int
loc_path(loc_t *loc, const char *bname)
{
int ret = 0;
if (loc->path)
goto out;
ret = -1;
if (bname && !strlen(bname))
bname = NULL;
if (!bname)
goto inode_path;
if (loc->parent && !gf_uuid_is_null(loc->parent->gfid)) {
ret = inode_path(loc->parent, bname, (char **)&loc->path);
} else if (!gf_uuid_is_null(loc->pargfid)) {
ret = gf_asprintf((char **)&loc->path, INODE_PATH_FMT "/%s",
uuid_utoa(loc->pargfid), bname);
}
if (loc->path)
goto out;
inode_path:
if (loc->inode && !gf_uuid_is_null(loc->inode->gfid)) {
ret = inode_path(loc->inode, NULL, (char **)&loc->path);
} else if (!gf_uuid_is_null(loc->gfid)) {
ret = gf_asprintf((char **)&loc->path, INODE_PATH_FMT,
uuid_utoa(loc->gfid));
}
out:
return ret;
}
void
loc_gfid(loc_t *loc, uuid_t gfid)
{
if (!gfid)
goto out;
gf_uuid_clear(gfid);
if (!loc)
goto out;
else if (!gf_uuid_is_null(loc->gfid))
gf_uuid_copy(gfid, loc->gfid);
else if (loc->inode && (!gf_uuid_is_null(loc->inode->gfid)))
gf_uuid_copy(gfid, loc->inode->gfid);
out:
return;
}
void
loc_pargfid(loc_t *loc, uuid_t gfid)
{
if (!gfid)
goto out;
gf_uuid_clear(gfid);
if (!loc)
goto out;
else if (!gf_uuid_is_null(loc->pargfid))
gf_uuid_copy(gfid, loc->pargfid);
else if (loc->parent && (!gf_uuid_is_null(loc->parent->gfid)))
gf_uuid_copy(gfid, loc->parent->gfid);
out:
return;
}
char *
loc_gfid_utoa(loc_t *loc)
{
uuid_t gfid = {
0,
};
loc_gfid(loc, gfid);
return uuid_utoa(gfid);
}
int
loc_touchup(loc_t *loc, const char *name)
{
char *path = NULL;
int ret = 0;
if (loc->path)
goto out;
if (loc->parent && name && strlen(name)) {
ret = inode_path(loc->parent, name, &path);
if (path) /*Guaranteed to have trailing '/' */
loc->name = strrchr(path, '/') + 1;
if (gf_uuid_is_null(loc->pargfid))
gf_uuid_copy(loc->pargfid, loc->parent->gfid);
} else if (loc->inode) {
ret = inode_path(loc->inode, 0, &path);
if (gf_uuid_is_null(loc->gfid))
gf_uuid_copy(loc->gfid, loc->inode->gfid);
}
if (ret < 0 || !path) {
ret = -ENOMEM;
goto out;
}
loc->path = path;
ret = 0;
out:
return ret;
}
int
loc_copy_overload_parent(loc_t *dst, loc_t *src, inode_t *parent)
{
int ret = -1;
GF_VALIDATE_OR_GOTO("xlator", dst, err);
GF_VALIDATE_OR_GOTO("xlator", src, err);
GF_VALIDATE_OR_GOTO("xlator", parent, err);
gf_uuid_copy(dst->gfid, src->gfid);
gf_uuid_copy(dst->pargfid, parent->gfid);
if (src->inode)
dst->inode = inode_ref(src->inode);
if (parent)
dst->parent = inode_ref(parent);
if (src->path) {
dst->path = gf_strdup(src->path);
if (!dst->path)
goto out;
if (src->name)
dst->name = strrchr(dst->path, '/');
if (dst->name)
dst->name++;
} else if (src->name) {
dst->name = src->name;
}
ret = 0;
out:
if (ret == -1)
loc_wipe(dst);
err:
return ret;
}
int
loc_copy(loc_t *dst, loc_t *src)
{
int ret = -1;
GF_VALIDATE_OR_GOTO("xlator", dst, err);
GF_VALIDATE_OR_GOTO("xlator", src, err);
if (!gf_uuid_is_null(src->gfid))
gf_uuid_copy(dst->gfid, src->gfid);
else if (src->inode && !gf_uuid_is_null(src->inode->gfid))
gf_uuid_copy(dst->gfid, src->inode->gfid);
gf_uuid_copy(dst->pargfid, src->pargfid);
if (src->inode)
dst->inode = inode_ref(src->inode);
if (src->parent)
dst->parent = inode_ref(src->parent);
if (src->path) {
dst->path = gf_strdup(src->path);
if (!dst->path)
goto out;
if (src->name)
dst->name = strrchr(dst->path, '/');
if (dst->name)
dst->name++;
} else if (src->name) {
dst->name = src->name;
}
ret = 0;
out:
if (ret == -1)
loc_wipe(dst);
err:
return ret;
}
gf_boolean_t
loc_is_root(loc_t *loc)
{
if (loc && __is_root_gfid(loc->gfid)) {
return _gf_true;
} else if (loc && loc->inode && __is_root_gfid(loc->inode->gfid)) {
return _gf_true;
}
return _gf_false;
}
int32_t
loc_build_child(loc_t *child, loc_t *parent, char *name)
{
int32_t ret = -1;
GF_VALIDATE_OR_GOTO("xlator", child, out);
GF_VALIDATE_OR_GOTO("xlator", parent, out);
GF_VALIDATE_OR_GOTO("xlator", name, out);
loc_gfid(parent, child->pargfid);
if (strcmp(parent->path, "/") == 0)
ret = gf_asprintf((char **)&child->path, "/%s", name);
else
ret = gf_asprintf((char **)&child->path, "%s/%s", parent->path, name);
if (ret < 0 || !child->path) {
ret = -1;
goto out;
}
child->name = strrchr(child->path, '/') + 1;
child->parent = inode_ref(parent->inode);
child->inode = inode_new(parent->inode->table);
if (!child->inode) {
ret = -1;
goto out;
}
ret = 0;
out:
if ((ret < 0) && child)
loc_wipe(child);
return ret;
}
gf_boolean_t
loc_is_nameless(loc_t *loc)
{
gf_boolean_t ret = _gf_false;
GF_VALIDATE_OR_GOTO("xlator", loc, out);
if ((!loc->parent && gf_uuid_is_null(loc->pargfid)) || !loc->name)
ret = _gf_true;
out:
return ret;
}
int
xlator_destroy(xlator_t *xl)
{
if (!xl)
return 0;
xlator_members_free(xl);
xlator_memrec_free(xl);
GF_FREE(xl);
return 0;
}
int
is_gf_log_command(xlator_t *this, const char *name, char *value)
{
xlator_t *trav = NULL;
char key[1024] = {
0,
};
int ret = -1;
int log_level = -1;
gf_boolean_t syslog_flag = 0;
glusterfs_ctx_t *ctx = NULL;
if (!strcmp("trusted.glusterfs.syslog", name)) {
ret = gf_string2boolean(value, &syslog_flag);
if (ret) {
ret = EOPNOTSUPP;
goto out;
}
if (syslog_flag)
gf_log_enable_syslog();
else
gf_log_disable_syslog();
goto out;
}
if (fnmatch("trusted.glusterfs*set-log-level", name, FNM_NOESCAPE))
goto out;
log_level = glusterd_check_log_level(value);
if (log_level == -1) {
ret = EOPNOTSUPP;
goto out;
}
/* Some crude way to change the log-level of process */
if (!strcmp(name, "trusted.glusterfs.set-log-level")) {
gf_msg("glusterfs", gf_log_get_loglevel(), 0, LG_MSG_SET_LOG_LEVEL,
"setting log level to %d (old-value=%d)", log_level,
gf_log_get_loglevel());
gf_log_set_loglevel(this->ctx, log_level);
ret = 0;
goto out;
}
if (!strcmp(name, "trusted.glusterfs.fuse.set-log-level")) {
/* */
gf_msg(this->name, gf_log_get_xl_loglevel(this), 0,
LG_MSG_SET_LOG_LEVEL, "setting log level to %d (old-value=%d)",
log_level, gf_log_get_xl_loglevel(this));
gf_log_set_xl_loglevel(this, log_level);
ret = 0;
goto out;
}
ctx = this->ctx;
if (!ctx)
goto out;
if (!ctx->active)
goto out;
trav = ctx->active->top;
while (trav) {
snprintf(key, 1024, "trusted.glusterfs.%s.set-log-level", trav->name);
if (fnmatch(name, key, FNM_NOESCAPE) == 0) {
gf_msg(trav->name, gf_log_get_xl_loglevel(trav), 0,
LG_MSG_SET_LOG_LEVEL,
"setting log level to %d (old-value=%d)", log_level,
gf_log_get_xl_loglevel(trav));
gf_log_set_xl_loglevel(trav, log_level);
ret = 0;
}
trav = trav->next;
}
out:
return ret;
}
int
glusterd_check_log_level(const char *value)
{
int log_level = -1;
if (!strcasecmp(value, "CRITICAL")) {
log_level = GF_LOG_CRITICAL;
} else if (!strcasecmp(value, "ERROR")) {
log_level = GF_LOG_ERROR;
} else if (!strcasecmp(value, "WARNING")) {
log_level = GF_LOG_WARNING;
} else if (!strcasecmp(value, "INFO")) {
log_level = GF_LOG_INFO;
} else if (!strcasecmp(value, "DEBUG")) {
log_level = GF_LOG_DEBUG;
} else if (!strcasecmp(value, "TRACE")) {
log_level = GF_LOG_TRACE;
} else if (!strcasecmp(value, "NONE")) {
log_level = GF_LOG_NONE;
}
if (log_level == -1)
gf_msg(THIS->name, GF_LOG_ERROR, 0, LG_MSG_INIT_FAILED,
"Invalid log-level. possible values are "
"DEBUG|WARNING|ERROR|CRITICAL|NONE|TRACE");
return log_level;
}
int
xlator_subvolume_count(xlator_t *this)
{
int i = 0;
xlator_list_t *list = NULL;
for (list = this->children; list; list = list->next)
i++;
return i;
}
static int
_copy_opt_to_child(dict_t *options, char *key, data_t *value, void *data)
{
xlator_t *child = data;
gf_log(__func__, GF_LOG_DEBUG, "copying %s to child %s", key, child->name);
dict_set(child->options, key, value);
return 0;
}
int
copy_opts_to_child(xlator_t *src, xlator_t *dst, char *glob)
{
return dict_foreach_fnmatch(src->options, glob, _copy_opt_to_child, dst);
}
int
glusterfs_delete_volfile_checksum(glusterfs_ctx_t *ctx, const char *volfile_id)
{
gf_volfile_t *volfile_tmp = NULL;
gf_volfile_t *volfile_obj = NULL;
list_for_each_entry(volfile_tmp, &ctx->volfile_list, volfile_list)
{
if (!strcmp(volfile_id, volfile_tmp->vol_id)) {
list_del_init(&volfile_tmp->volfile_list);
volfile_obj = volfile_tmp;
break;
}
}
if (volfile_obj) {
GF_FREE(volfile_obj);
} else {
gf_log(THIS->name, GF_LOG_ERROR,
"failed to get volfile "
"checksum for volfile id %s.",
volfile_id);
}
return 0;
}
/*
The function is required to take dict ref for every xlator at graph.
At the time of compare graph topology create a graph and populate
key values in the dictionary, after finished graph comparison we do destroy
the new graph.At the time of construct graph we don't take any reference
so to avoid dict leak at the of destroying graph due to ref counter underflow
we need to call dict_ref here.
*/
void
gluster_graph_take_reference(xlator_t *tree)
{
xlator_t *trav = tree;
xlator_t *prev = tree;
if (!tree) {
gf_msg("parser", GF_LOG_ERROR, 0, LG_MSG_TREE_NOT_FOUND,
"Translator tree not found");
return;
}
while (prev) {
trav = prev->next;
if (prev->options)
dict_ref(prev->options);
prev = trav;
}
return;
}
|