-
Notifications
You must be signed in to change notification settings - Fork 353
Expand file tree
/
Copy pathddb_vos.c
More file actions
2359 lines (1949 loc) · 56.3 KB
/
Copy pathddb_vos.c
File metadata and controls
2359 lines (1949 loc) · 56.3 KB
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
/**
* (C) Copyright 2022-2025 Intel Corporation.
* (C) Copyright 2025 Vdura Inc.
* (C) Copyright 2025-2026 Hewlett Packard Enterprise Development LP.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
#define D_LOGFAC DD_FAC(ddb)
#include <sys/mount.h>
#include <string.h>
#include <sys/vfs.h>
#include <libpmemobj.h>
#include <daos_srv/vos.h>
#include <daos_srv/smd.h>
#include <vos_internal.h>
#include <bio_wal.h>
#include "ddb_common.h"
#include "ddb_parse.h"
#include "ddb_mgmt.h"
#include "ddb_vos.h"
#include "ddb_spdk.h"
#define ddb_vos_iterate(param, iter_type, recursive, anchors, cb, args) \
vos_iterate(param, iter_type, recursive, \
anchors, cb, NULL, args, NULL)
static int
create_vos_file_parts(const char *path, const char *db_path, struct vos_file_parts **vf_ptr)
{
struct vos_file_parts *vf;
int rc;
D_ALLOC_PTR(vf);
if (vf == NULL) {
D_ERROR("Unable to allocate memory for pool path\n");
rc = -DER_NOMEM;
goto out;
}
rc = parse_vos_file_parts(path, db_path, vf);
if (SUCCESS(rc)) {
*vf_ptr = vf;
} else {
D_ERROR("Unable to parse VOS pool path '%s' and DB path '%s'\n", path,
db_path ? db_path : "(null)");
D_FREE(vf);
}
out:
return rc;
}
bool
vmd_wa_can_proceed(struct ddb_ctx *ctx, const char *db_path);
int
dv_pool_open(const char *path, const char *db_path, daos_handle_t *poh, uint32_t flags,
bool write_mode)
{
int rc;
struct vos_file_parts *vf;
rc = create_vos_file_parts(path, db_path, &vf);
if (!SUCCESS(rc))
goto out;
/**
* When the user requests read‑only mode (write_mode == false), DDB itself will not attempt
* to modify the pool. However, PMEMOBJ performs several operations that do modify the pool
* during open and/or close, for example:
* - Internal bookkeeping required to ensure resilience in case of an ADR failure (SDS).
* - ULOG replay, which restores the pool to a consistent state.
* These mechanisms cannot be disabled because they are essential for PMEMOBJ to maintain
* the consistency of the pool.
*
* However, since none of these changes need to be persisted when the pool is opened in
* read‑only mode (write_mode == false), we can work around this by mapping the pool using
* copy‑on‑write. Copy‑on‑write allows pages to be read normally, but when a page is
* modified, a new private copy is allocated. As a result, any changes made to
* the mapped memory do not propagate to the persistent medium.
*/
if (!write_mode) {
int cow_val = 1;
rc = pmemobj_ctl_set(NULL, "copy_on_write.at_open", &cow_val);
if (rc != 0) {
rc = daos_errno2der(errno);
goto out_vf;
}
}
rc = vos_self_init(vf->vf_db_path, true, vf->vf_target_idx);
if (!SUCCESS(rc)) {
D_ERROR("Failed to initialize VOS with DB path '%s': " DF_RC "\n", vf->vf_db_path,
DP_RC(rc));
goto out_cow;
}
rc = vos_pool_open(vf->vf_vos_file_path, vf->vf_pool_uuid, flags, poh);
if (!SUCCESS(rc)) {
D_ERROR("Failed to open pool: "DF_RC"\n", DP_RC(rc));
vos_self_fini();
}
out_cow:
if (!write_mode) {
/** Restore the default value. */
int cow_val = 0;
pmemobj_ctl_set(NULL, "copy_on_write.at_open", &cow_val);
}
out_vf:
D_FREE(vf);
out:
return rc;
}
int
dv_pool_destroy(const char *path, const char *db_path, struct ddb_ctx *ctx)
{
struct vos_file_parts *vf;
int flags = 0;
int rc;
rc = create_vos_file_parts(path, db_path, &vf);
if (!SUCCESS(rc))
goto out;
if (!vmd_wa_can_proceed(ctx, vf->vf_db_path)) {
rc = -DER_NO_SERVICE;
goto out_vf;
}
rc = vos_self_init(vf->vf_db_path, true, vf->vf_target_idx);
if (!SUCCESS(rc)) {
D_ERROR("Failed to initialize VOS with DB path '%s': " DF_RC "\n", vf->vf_db_path,
DP_RC(rc));
goto out_vf;
}
if (strncmp(vf->vf_vos_file_name, "rdb", 3) == 0)
flags |= VOS_POF_RDB;
rc = vos_pool_destroy_ex(vf->vf_vos_file_path, vf->vf_pool_uuid, flags);
if (!SUCCESS(rc))
D_ERROR("Failed to destroy pool: " DF_RC "\n", DP_RC(rc));
vos_self_fini();
out_vf:
D_FREE(vf);
out:
return rc;
}
int
dv_pool_close(daos_handle_t poh)
{
int rc;
rc = vos_pool_close(poh);
vos_self_fini();
return rc;
}
int
dv_cont_open(daos_handle_t poh, uuid_t uuid, daos_handle_t *coh)
{
return vos_cont_open(poh, uuid, coh);
}
int
dv_cont_close(daos_handle_t *coh)
{
int rc;
D_ASSERT(coh);
if (daos_handle_is_inval(*coh))
return 0;
rc = vos_cont_close(*coh);
*coh = DAOS_HDL_INVAL;
return rc;
}
struct search_args {
uint32_t sa_idx;
uint32_t sa_current;
uuid_t sa_uuid;
daos_unit_oid_t sa_uoid;
daos_key_t sa_key;
daos_recx_t sa_recx;
};
static int
get_by_idx_cb(daos_handle_t ih, vos_iter_entry_t *entry, vos_iter_type_t type,
vos_iter_param_t *param, void *cb_arg, unsigned int *acts)
{
struct search_args *args = cb_arg;
/* not found yet */
if (args->sa_idx != args->sa_current) {
args->sa_current++;
return 0;
}
switch (type) {
case VOS_ITER_COUUID:
uuid_copy(args->sa_uuid, entry->ie_couuid);
break;
case VOS_ITER_OBJ:
args->sa_uoid = entry->ie_oid;
break;
case VOS_ITER_DKEY:
args->sa_key = entry->ie_key;
break;
case VOS_ITER_AKEY:
args->sa_key = entry->ie_key;
break;
case VOS_ITER_SINGLE:
break;
case VOS_ITER_RECX:
args->sa_recx = entry->ie_orig_recx;
break;
case VOS_ITER_DTX:
break;
case VOS_ITER_NONE:
break;
}
return 1;
}
static int
get_by_idx(daos_handle_t hdl, uint32_t idx, struct search_args *args, daos_unit_oid_t *uoid,
daos_key_t *dkey, daos_key_t *akey, vos_iter_type_t type)
{
vos_iter_param_t param = {0};
struct vos_iter_anchors anchors = {0};
int rc;
bool found;
args->sa_idx = idx;
param.ip_hdl = hdl;
param.ip_epr.epr_hi = DAOS_EPOCH_MAX;
if (uoid)
param.ip_oid = *uoid;
if (dkey)
param.ip_dkey = *dkey;
if (akey)
param.ip_akey = *akey;
rc = vos_iterate(¶m, type, false, &anchors, get_by_idx_cb, NULL, args, NULL);
if (rc < 0)
return rc;
found = rc == 1;
if (!found)
return -DER_NONEXIST;
return 0;
}
int
dv_get_cont_uuid(daos_handle_t poh, uint32_t idx, uuid_t uuid)
{
struct search_args args = {0};
int rc;
rc = get_by_idx(poh, idx, &args, NULL, NULL, NULL, VOS_ITER_COUUID);
if (SUCCESS(rc))
uuid_copy(uuid, args.sa_uuid);
return rc;
}
static int
get_cont_idx_cb(daos_handle_t ih, vos_iter_entry_t *entry, vos_iter_type_t type,
vos_iter_param_t *param, void *cb_arg, unsigned int *acts)
{
struct search_args *args = cb_arg;
D_ASSERT(type == VOS_ITER_COUUID);
if (uuid_compare(args->sa_uuid, entry->ie_couuid) == 0) {
/* found */
return 1;
}
args->sa_idx++;
return 0;
}
int
dv_get_cont_idx(daos_handle_t poh, uuid_t uuid)
{
struct search_args args = {0};
vos_iter_param_t param = {0};
struct vos_iter_anchors anchors = {0};
int found;
uuid_copy(args.sa_uuid, uuid);
param.ip_hdl = poh;
param.ip_epr.epr_hi = DAOS_EPOCH_MAX;
found = vos_iterate(¶m, VOS_ITER_COUUID, false, &anchors, get_cont_idx_cb, NULL,
&args, NULL);
if (found)
return args.sa_idx;
return -DDBER_INVALID_CONT;
}
int
dv_get_object_oid(daos_handle_t coh, uint32_t idx, daos_unit_oid_t *uoid)
{
struct search_args args = {0};
int rc;
D_ASSERT(uoid != NULL);
if (daos_handle_is_inval(coh))
return -DER_INVAL;
rc = get_by_idx(coh, idx, &args, NULL, NULL, NULL, VOS_ITER_OBJ);
if (SUCCESS(rc))
*uoid = args.sa_uoid;
return rc;
}
int
dv_get_dkey(daos_handle_t coh, daos_unit_oid_t uoid, uint32_t idx, daos_key_t *dkey)
{
struct search_args args = {0};
int rc;
D_ASSERT(dkey != NULL);
if (daos_handle_is_inval(coh) || daos_unit_oid_is_null(uoid))
return -DER_INVAL;
rc = get_by_idx(coh, idx, &args, &uoid, NULL, NULL, VOS_ITER_DKEY);
if (SUCCESS(rc))
daos_iov_copy(dkey, &args.sa_key);
return rc;
}
int
dv_get_akey(daos_handle_t coh, daos_unit_oid_t uoid, daos_key_t *dkey, uint32_t idx,
daos_key_t *akey)
{
struct search_args args = {0};
int rc;
D_ASSERT(dkey != NULL);
D_ASSERT(akey != NULL);
if (daos_handle_is_inval(coh) || daos_unit_oid_is_null(uoid))
return -DER_INVAL;
rc = get_by_idx(coh, idx, &args, &uoid, dkey, NULL, VOS_ITER_AKEY);
if (SUCCESS(rc))
daos_iov_copy(akey, &args.sa_key);
return rc;
}
int
dv_get_recx(daos_handle_t coh, daos_unit_oid_t uoid, daos_key_t *dkey, daos_key_t *akey,
uint32_t idx, daos_recx_t *recx)
{
struct search_args args = {0};
int rc;
D_ASSERT(dkey != NULL);
D_ASSERT(akey != NULL);
D_ASSERT(recx != NULL);
if (daos_handle_is_inval(coh) || daos_unit_oid_is_null(uoid))
return -DER_INVAL;
rc = get_by_idx(coh, idx, &args, &uoid, dkey, akey, VOS_ITER_RECX);
if (SUCCESS(rc))
*recx = args.sa_recx;
return rc;
}
#define daos_recx_match(a, b) ((a).rx_idx == (b.rx_idx) && (a).rx_nr == (b).rx_nr)
struct path_verify_args {
struct dv_indexed_tree_path *pva_itp;
uint32_t pva_current_idx;
uint32_t pva_current_idxs[PATH_PART_END];
};
static bool
compare_oid(vos_iter_entry_t *entry, union itp_part_type *part)
{
return daos_unit_oid_compare(part->itp_oid, entry->ie_oid) == 0;
}
static bool
compare_key(vos_iter_entry_t *entry, union itp_part_type *part)
{
return daos_key_match(&part->itp_key, &entry->ie_key);
}
static bool
compare_recx(vos_iter_entry_t *entry, union itp_part_type *part)
{
return daos_recx_match(part->itp_recx, entry->ie_orig_recx);
}
static bool
vos_vtp_compare(struct dv_indexed_tree_path *vtp, vos_iter_entry_t *entry, enum path_parts part_key)
{
bool (*cmp_fn[PATH_PART_END])(vos_iter_entry_t *entry, union itp_part_type *part) = {
NULL, /* Won't be comparing containers */
compare_oid,
compare_key,
compare_key,
compare_recx,
};
D_ASSERT(part_key < PATH_PART_END);
D_ASSERT(cmp_fn[part_key] != NULL);
return cmp_fn[part_key](entry, &vtp->itp_parts[part_key].itp_part_value);
}
static void
set_oid(vos_iter_entry_t *entry, struct indexed_tree_path_part *part)
{
itp_part_set_obj(part, &entry->ie_oid);
}
static void
set_key(vos_iter_entry_t *entry, struct indexed_tree_path_part *part)
{
itp_part_set_key(part, &entry->ie_key);
}
static void
set_recx(vos_iter_entry_t *entry, struct indexed_tree_path_part *part)
{
itp_part_set_recx(part, &entry->ie_orig_recx);
}
static void
vos_itp_set(struct dv_indexed_tree_path *itp, vos_iter_entry_t *entry, enum path_parts part_key)
{
void (*set_fn[PATH_PART_END])(vos_iter_entry_t *entry,
struct indexed_tree_path_part *part) = {
NULL, /* Won't set containers */
set_oid, set_key, set_key, set_recx,
};
D_ASSERT(part_key < PATH_PART_END);
D_ASSERT(set_fn[part_key] != NULL);
set_fn[part_key](entry, &itp->itp_parts[part_key]);
itp->itp_parts[part_key].itp_has_part_value = true;
}
#define VOS_ITER_LARGEST VOS_ITER_DTX
static enum path_parts
vos_iterator_type_to_path_part(vos_iter_type_t type)
{
int map[VOS_ITER_LARGEST] = {0};
map[VOS_ITER_COUUID] = PATH_PART_CONT;
map[VOS_ITER_OBJ] = PATH_PART_OBJ;
map[VOS_ITER_DKEY] = PATH_PART_DKEY;
map[VOS_ITER_AKEY] = PATH_PART_AKEY;
map[VOS_ITER_RECX] = PATH_PART_RECX;
map[VOS_ITER_SINGLE] = PATH_PART_SV;
return map[type];
}
static enum path_parts
vos_enum_to_path_part(vos_iter_type_t t)
{
enum path_parts map[VOS_ITER_LARGEST] = {0};
map[VOS_ITER_OBJ] = PATH_PART_OBJ;
map[VOS_ITER_DKEY] = PATH_PART_DKEY;
map[VOS_ITER_AKEY] = PATH_PART_AKEY;
map[VOS_ITER_RECX] = PATH_PART_RECX;
map[VOS_ITER_SINGLE] = PATH_PART_END; /* nothing for single value */
return map[t];
}
static enum path_parts
vos_enum_to_parent_path_part(vos_iter_type_t t)
{
int map[VOS_ITER_LARGEST] = {0};
map[VOS_ITER_OBJ] = PATH_PART_CONT;
map[VOS_ITER_DKEY] = PATH_PART_OBJ;
map[VOS_ITER_AKEY] = PATH_PART_DKEY;
map[VOS_ITER_RECX] = PATH_PART_AKEY;
map[VOS_ITER_SINGLE] = PATH_PART_AKEY;
return map[t];
}
static int
verify_path_pre_cb(daos_handle_t ih, vos_iter_entry_t *entry, vos_iter_type_t type,
vos_iter_param_t *param, void *cb_arg, unsigned int *acts)
{
struct path_verify_args *args = cb_arg;
struct dv_indexed_tree_path *itp = args->pva_itp;
if (!(type == VOS_ITER_OBJ ||
type == VOS_ITER_DKEY ||
type == VOS_ITER_AKEY ||
type == VOS_ITER_RECX))
return 0; /* these are the only parts of the path */
if (itp_has_complete(itp, vos_enum_to_parent_path_part(type))) {
enum path_parts part_key = vos_enum_to_path_part(type);
if (itp_has_idx(itp, part_key)) {
if (itp_idx(itp, part_key) == args->pva_current_idxs[part_key]) {
/* set the part */
vos_itp_set(itp, entry, part_key);
itp->itp_child_type =
vos_iterator_type_to_path_part(entry->ie_child_type);
args->pva_current_idx = 0;
} else {
/* looking for index, but not found yet */
args->pva_current_idxs[part_key]++;
args->pva_current_idx++;
*acts = VOS_ITER_CB_SKIP;
}
} else if (itp_has_part_value(itp, part_key)) {
if (vos_vtp_compare(itp, entry, part_key)) {
/* need to verify part and capture index */
itp_idx_set(itp, part_key, args->pva_current_idxs[part_key]);
itp->itp_child_type =
vos_iterator_type_to_path_part(entry->ie_child_type);
args->pva_current_idx = 0;
} else {
*acts = VOS_ITER_CB_SKIP;
args->pva_current_idx++;
args->pva_current_idxs[part_key]++;
}
}
}
return 0;
}
static int
verify_path_post_cb(daos_handle_t ih, vos_iter_entry_t *entry, vos_iter_type_t type,
vos_iter_param_t *param, void *cb_arg, unsigned int *acts)
{
struct path_verify_args *args = cb_arg;
struct dv_indexed_tree_path *itp = args->pva_itp;
switch (type) {
case VOS_ITER_NONE:
break;
case VOS_ITER_COUUID:
break;
case VOS_ITER_OBJ:
if (itp_has_obj_complete(itp))
*acts = VOS_ITER_CB_ABORT;
break;
case VOS_ITER_DKEY:
if (itp_has_dkey_complete(itp))
*acts = VOS_ITER_CB_ABORT;
break;
case VOS_ITER_AKEY:
if (itp_has_akey_complete(itp))
*acts = VOS_ITER_CB_ABORT;
break;
case VOS_ITER_SINGLE:
break;
case VOS_ITER_RECX:
if (itp_has_recx_complete(itp))
*acts = VOS_ITER_CB_ABORT;
break;
case VOS_ITER_DTX:
break;
}
return 0;
}
int
dv_path_verify(daos_handle_t poh, struct dv_indexed_tree_path *itp)
{
vos_iter_param_t param = {0};
struct vos_iter_anchors anchors = {0};
struct path_verify_args args = {0};
daos_handle_t coh = {0};
int rc = 0;
/* empty path is fine */
if (!itp_has_cont(itp))
return 0;
if (itp_has_idx(itp, PATH_PART_CONT)) {
uuid_t uuid;
rc = dv_get_cont_uuid(poh, itp_idx(itp, PATH_PART_CONT), uuid);
if (!SUCCESS(rc)) {
D_ERROR("Unable to get container index %d\n", itp_idx(itp, PATH_PART_CONT));
if (rc == -DER_NONEXIST)
rc = -DDBER_INVALID_CONT;
return rc;
}
itp_set_cont_part_value(itp, uuid);
} else {
rc = dv_get_cont_idx(poh, itp_cont(itp));
if (rc < 0)
return rc;
itp_set_cont_idx(itp, rc);
}
rc = dv_cont_open(poh, itp_cont(itp), &coh);
if (!SUCCESS(rc)) {
D_ERROR("Unable to open container "DF_UUIDF"\n",
itp->itp_parts[PATH_PART_CONT].itp_part_value.itp_uuid);
if (rc == -DER_NONEXIST)
rc = -DDBER_INVALID_CONT;
return rc;
}
args.pva_current_idx = 0;
args.pva_itp = itp;
param.ip_hdl = coh;
param.ip_epr.epr_hi = DAOS_EPOCH_MAX;
param.ip_flags = VOS_IT_FOR_CHECK;
rc = vos_iterate(¶m, VOS_ITER_OBJ, true, &anchors,
verify_path_pre_cb, verify_path_post_cb, &args, NULL);
dv_cont_close(&coh);
if (!SUCCESS(rc)) {
D_ERROR("Issue verifying path: "DF_RC"\n", DP_RC(rc));
return rc;
}
return itp_verify(itp);
}
struct ddb_iter_ctx {
struct dv_indexed_tree_path itp;
daos_handle_t poh;
struct vos_tree_handlers *handlers;
void *handler_args;
uuid_t current_cont;
uint32_t cont_seen;
daos_unit_oid_t current_obj;
uint32_t obj_seen;
daos_key_t current_dkey;
uint32_t dkey_seen;
daos_key_t current_akey;
uint32_t akey_seen;
uint32_t value_seen;
};
static int
handle_cont(struct ddb_iter_ctx *ctx, vos_iter_entry_t *entry, vos_iter_param_t *param)
{
struct ddb_cont cont = {0};
D_ASSERT(ctx && ctx->handlers && ctx->handlers->ddb_cont_handler);
itp_set_cont(&ctx->itp, entry->ie_couuid, ctx->cont_seen);
cont.ddbc_path = &ctx->itp;
itp_unset_obj(&ctx->itp);
uuid_copy(ctx->current_cont, entry->ie_couuid);
uuid_copy(cont.ddbc_cont_uuid, entry->ie_couuid);
cont.ddbc_idx = ctx->cont_seen++;
/* Restart object count for container */
ctx->obj_seen = 0;
return ctx->handlers->ddb_cont_handler(&cont, ctx->handler_args);
}
static void
get_object_type(enum daos_otype_t type, char *type_str)
{
switch (type) {
case DAOS_OT_MULTI_HASHED:
strcpy(type_str, "DAOS_OT_MULTI_HASHED");
break;
case DAOS_OT_OIT:
strcpy(type_str, "DAOS_OT_OIT");
break;
case DAOS_OT_DKEY_UINT64:
strcpy(type_str, "DAOS_OT_DKEY_UINT64");
break;
case DAOS_OT_AKEY_UINT64:
strcpy(type_str, "DAOS_OT_AKEY_UINT64");
break;
case DAOS_OT_MULTI_UINT64:
strcpy(type_str, "DAOS_OT_MULTI_UINT64");
break;
case DAOS_OT_DKEY_LEXICAL:
strcpy(type_str, "DAOS_OT_DKEY_LEXICAL");
break;
case DAOS_OT_AKEY_LEXICAL:
strcpy(type_str, "DAOS_OT_AKEY_LEXICAL");
break;
case DAOS_OT_MULTI_LEXICAL:
strcpy(type_str, "DAOS_OT_MULTI_LEXICAL");
break;
case DAOS_OT_KV_HASHED:
strcpy(type_str, "DAOS_OT_KV_HASHED");
break;
case DAOS_OT_KV_UINT64:
strcpy(type_str, "DAOS_OT_KV_UINT64");
break;
case DAOS_OT_KV_LEXICAL:
strcpy(type_str, "DAOS_OT_KV_LEXICAL");
break;
case DAOS_OT_ARRAY:
strcpy(type_str, "DAOS_OT_ARRAY");
break;
case DAOS_OT_ARRAY_ATTR:
strcpy(type_str, "DAOS_OT_ARRAY_ATTR");
break;
case DAOS_OT_ARRAY_BYTE:
strcpy(type_str, "DAOS_OT_ARRAY_BYTE");
break;
default:
strcpy(type_str, "UNKNOWN");
break;
}
}
void
dv_oid_to_obj(daos_obj_id_t oid, struct ddb_obj *obj)
{
obj->ddbo_oid = oid;
obj->ddbo_nr_grps = daos_obj_id2grp_nr(oid);
/*
* It would be nice to get the object class name, but currently that is client
* functionality and this tool is being installed as a server binary. If that changes, the
* following code might be used ...
* char obj_class_name[32];
* int rc = obj_class_init();
* daos_oclass_id_t oclass;
* oclass = daos_obj_id2class(obj->ddbo_oid);
* if (!SUCCESS(rc))
* return rc;
* daos_oclass_id2name(oclass, obj_class_name);
* obj_class_fini();
*/
get_object_type(daos_obj_id2type(oid), obj->ddbo_otype_str);
}
static int
handle_obj(struct ddb_iter_ctx *ctx, vos_iter_entry_t *entry)
{
struct ddb_obj obj = {0};
D_ASSERT(ctx && ctx->handlers && ctx->handlers->ddb_obj_handler);
dv_oid_to_obj(entry->ie_oid.id_pub, &obj);
itp_set_obj(&ctx->itp, entry->ie_oid, ctx->obj_seen);
itp_unset_dkey(&ctx->itp);
obj.ddbo_path = &ctx->itp;
obj.ddbo_idx = ctx->obj_seen++;
ctx->current_obj = entry->ie_oid;
/* Restart dkey count for the object */
ctx->dkey_seen = 0;
itp_unset_dkey(&ctx->itp);
return ctx->handlers->ddb_obj_handler(&obj, ctx->handler_args);
}
static int
handle_dkey(struct ddb_iter_ctx *ctx, vos_iter_entry_t *entry)
{
struct ddb_key dkey = {0};
int rc;
D_ASSERT(ctx && ctx->handlers && ctx->handlers->ddb_dkey_handler);
itp_unset_dkey(&ctx->itp); /* make sure dkey is freed from any previous handle */
itp_set_dkey(&ctx->itp, &entry->ie_key, ctx->dkey_seen);
dkey.ddbk_path = &ctx->itp;
dkey.ddbk_idx = ctx->dkey_seen++;
dkey.ddbk_key = entry->ie_key;
dkey.ddbk_otype = daos_obj_id2type(ctx->current_obj.id_pub);
dkey.ddbk_child_type = entry->ie_child_type;
ctx->current_dkey = entry->ie_key;
/* Restart the akey count for the dkey */
ctx->akey_seen = 0;
itp_unset_akey(&ctx->itp);
rc = ctx->handlers->ddb_dkey_handler(&dkey, ctx->handler_args);
return rc;
}
static int
handle_akey(struct ddb_iter_ctx *ctx, vos_iter_entry_t *entry)
{
struct ddb_key akey = {0};
int rc;
D_ASSERT(ctx && ctx->handlers && ctx->handlers->ddb_akey_handler);
itp_unset_akey(&ctx->itp); /* make sure akey is freed from any previous handle */
itp_set_akey(&ctx->itp, &entry->ie_key, ctx->akey_seen);
itp_unset_recx(&ctx->itp);
akey.ddbk_path = &ctx->itp;
akey.ddbk_idx = ctx->akey_seen++;
akey.ddbk_key = entry->ie_key;
akey.ddbk_otype = daos_obj_id2type(ctx->current_obj.id_pub);
akey.ddbk_child_type = entry->ie_child_type;
ctx->current_akey = entry->ie_key;
/* Restart the values seen for the akey */
ctx->value_seen = 0;
rc = ctx->handlers->ddb_akey_handler(&akey, ctx->handler_args);
return rc;
}
static int
handle_sv(struct ddb_iter_ctx *ctx, vos_iter_entry_t *entry)
{
struct ddb_sv value = {0};
D_ASSERT(ctx && ctx->handlers && ctx->handlers->ddb_sv_handler);
value.ddbs_record_size = entry->ie_rsize;
value.ddbs_epoch = entry->ie_epoch;
value.ddbs_idx = ctx->value_seen++;
value.ddbs_path = &ctx->itp;
return ctx->handlers->ddb_sv_handler(&value, ctx->handler_args);
}
static int
handle_array(struct ddb_iter_ctx *ctx, vos_iter_entry_t *entry)
{
struct ddb_array value = {0};
D_ASSERT(ctx && ctx->handlers && ctx->handlers->ddb_array_handler);
itp_set_recx(&ctx->itp, &entry->ie_orig_recx, ctx->value_seen);
value.ddba_path = &ctx->itp;
value.ddba_record_size = entry->ie_rsize;
value.ddba_recx = entry->ie_orig_recx;
value.ddba_epoch = entry->ie_epoch;
value.ddba_idx = ctx->value_seen++;
return ctx->handlers->ddb_array_handler(&value, ctx->handler_args);
}
static int
handle_iter_cb(daos_handle_t ih, vos_iter_entry_t *entry, vos_iter_type_t type,
vos_iter_param_t *param, void *cb_arg, unsigned int *acts)
{
switch (type) {
case VOS_ITER_COUUID:
return handle_cont(cb_arg, entry, param);
case VOS_ITER_OBJ:
return handle_obj(cb_arg, entry);
case VOS_ITER_DKEY:
return handle_dkey(cb_arg, entry);
case VOS_ITER_AKEY:
return handle_akey(cb_arg, entry);
case VOS_ITER_SINGLE:
return handle_sv(cb_arg, entry);
case VOS_ITER_RECX:
return handle_array(cb_arg, entry);
case VOS_ITER_DTX:
D_ASSERT(1); /* shouldn't get here */
break;
case VOS_ITER_NONE:
break;
}
return 0;
}
static int
iter_cont_recurse_cb(daos_handle_t ih, vos_iter_entry_t *entry, vos_iter_type_t type,
vos_iter_param_t *param, void *cb_arg, unsigned int *acts)
{
vos_iter_param_t cont_param = {0};
struct vos_iter_anchors anchors = {0};
daos_handle_t coh;
int rc;
D_ASSERT(type == VOS_ITER_COUUID);
rc = handle_cont(cb_arg, entry, param);
if (!SUCCESS(rc))
return rc;
/* recursively iterate the objects in the container */
rc = vos_cont_open(param->ip_hdl, entry->ie_couuid, &coh);
if (!SUCCESS(rc))
return rc;
cont_param.ip_hdl = coh;
cont_param.ip_epr.epr_hi = DAOS_EPOCH_MAX;
rc = ddb_vos_iterate(&cont_param, VOS_ITER_OBJ, true, &anchors, handle_iter_cb, cb_arg);
if (rc != 0)
D_ERROR("vos_iterate error: "DF_RC"\n", DP_RC(rc));
rc = vos_cont_close(coh);
return rc;
}
static int
iter_cont_recurse(vos_iter_param_t *param, struct ddb_iter_ctx *ctx)
{
struct vos_iter_anchors anchors = {0};
return ddb_vos_iterate(param, VOS_ITER_COUUID, false, &anchors, iter_cont_recurse_cb, ctx);
}
int
dv_iterate(daos_handle_t poh, struct dv_tree_path *path, bool recursive,
struct vos_tree_handlers *handlers, void *handler_args,
struct dv_indexed_tree_path *itp)
{
vos_iter_param_t param = {0};
struct vos_iter_anchors anchors = {0};
int rc;
daos_handle_t coh = DAOS_HDL_INVAL;
vos_iter_type_t type;
struct ddb_iter_ctx ctx = {0};
ctx.handlers = handlers;
ctx.handler_args = handler_args;
ctx.poh = poh;
ctx.current_obj = path->vtp_oid;
itp_copy(&ctx.itp, itp);
param.ip_epr.epr_hi = DAOS_EPOCH_MAX;
if (uuid_is_null(path->vtp_cont)) {
param.ip_hdl = poh;
if (recursive) {
/*
* currently vos_iterate doesn't handle recursive iteration starting with a
* container. This works around that limitation.
*/
rc = iter_cont_recurse(¶m, &ctx);
itp_free(&ctx.itp);
return rc;
}
rc =
ddb_vos_iterate(¶m, VOS_ITER_COUUID, false, &anchors, handle_iter_cb, &ctx);
itp_free(&ctx.itp);
return rc;
}
rc = vos_cont_open(poh, path->vtp_cont, &coh);
if (!SUCCESS(rc)) {
itp_free(&ctx.itp);
return rc;
}
param.ip_hdl = coh;
param.ip_oid = path->vtp_oid;
param.ip_dkey = path->vtp_dkey;
param.ip_akey = path->vtp_akey;
if (!dv_has_obj(path))
type = VOS_ITER_OBJ;
else if (!dv_has_dkey(path))
type = VOS_ITER_DKEY;
else if (!dv_has_akey(path))
type = VOS_ITER_AKEY;
else if (path->vtp_is_recx)
type = VOS_ITER_RECX;
else
type = VOS_ITER_SINGLE;
rc = ddb_vos_iterate(¶m, type, recursive, &anchors, handle_iter_cb, &ctx);
itp_free(&ctx.itp);
if (!daos_handle_is_inval(coh))
vos_cont_close(coh);
return rc;
}