-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathsrv_obj_migrate.c
3823 lines (3348 loc) · 108 KB
/
srv_obj_migrate.c
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 2019-2024 Intel Corporation.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
/**
* migrate: migrate objects between servers.
*
*/
#define D_LOGFAC DD_FAC(server)
#include <daos_srv/pool.h>
#include <daos/btree_class.h>
#include <daos/pool_map.h>
#include <daos/rpc.h>
#include <daos/object.h>
#include <daos/container.h>
#include <daos/pool.h>
#include <daos_srv/container.h>
#include <daos_srv/daos_engine.h>
#include <daos_srv/vos.h>
#include <daos_srv/dtx_srv.h>
#include <daos_srv/srv_csum.h>
#include <daos_srv/rebuild.h>
#include <daos_srv/object.h>
#include "obj_rpc.h"
#include "srv_internal.h"
#if D_HAS_WARNING(4, "-Wframe-larger-than=")
#pragma GCC diagnostic ignored "-Wframe-larger-than="
#endif
/* Max in-flight data size per xstream */
/* Set the total in-flight size to be 25% of MAX DMA size for
* the moment, will adjust it later if needed.
*/
#define MIGRATE_MAX_SIZE (1 << 28)
/* Max migrate ULT number on the server */
#define MIGRATE_MAX_ULT 512
struct migrate_one {
daos_key_t mo_dkey;
uint64_t mo_dkey_hash;
uuid_t mo_pool_uuid;
uuid_t mo_cont_uuid;
daos_unit_oid_t mo_oid;
daos_epoch_t mo_obj_punch_eph;
daos_epoch_t mo_dkey_punch_eph;
/* minimum epoch from mo_iods & mo_iods_from_parity, used
* as the updated epoch for replication extent rebuild.
*/
daos_epoch_t mo_min_epoch;
daos_epoch_t mo_epoch;
/* Epochs per recx in mo_iods, used for parity extent rebuild. */
daos_epoch_t **mo_iods_update_ephs;
/* IOD for replicate recxs migration */
daos_iod_t *mo_iods;
/* IOD for recxs gotten from parity rebuild. During EC rebuild, it
* will first rebuild mo_iods_from_parity then rebuild mo_iods to
* avoid parity corruption.
*/
daos_iod_t *mo_iods_from_parity;
daos_epoch_t **mo_iods_update_ephs_from_parity;
daos_iod_t *mo_punch_iods;
daos_epoch_t *mo_akey_punch_ephs;
daos_epoch_t mo_rec_punch_eph;
struct dcs_iod_csums *mo_iods_csums;
d_sg_list_t *mo_sgls;
struct daos_oclass_attr mo_oca;
unsigned int mo_iod_num;
unsigned int mo_punch_iod_num;
unsigned int mo_iod_alloc_num;
unsigned int mo_rec_num;
uint64_t mo_size;
uint64_t mo_version;
uint32_t mo_pool_tls_version;
uint32_t mo_iods_num_from_parity;
uint32_t mo_layout_version;
uint32_t mo_generation;
d_list_t mo_list;
d_iov_t mo_csum_iov;
};
struct migrate_obj_key {
daos_unit_oid_t oid;
daos_epoch_t eph;
uint32_t tgt_idx;
};
/* Argument for container iteration and migrate */
struct iter_cont_arg {
struct migrate_pool_tls *pool_tls;
uuid_t pool_uuid;
uuid_t pool_hdl_uuid;
uuid_t cont_uuid;
uuid_t cont_hdl_uuid;
struct tree_cache_root *cont_root;
unsigned int yield_freq;
uint64_t *snaps;
uint32_t snap_cnt;
uint32_t version;
uint32_t ref_cnt;
};
/* Argument for object iteration and migrate */
struct iter_obj_arg {
uuid_t pool_uuid;
uuid_t cont_uuid;
daos_unit_oid_t oid;
daos_epoch_t epoch;
daos_epoch_t punched_epoch;
unsigned int shard;
unsigned int tgt_idx;
uint64_t *snaps;
uint32_t snap_cnt;
uint32_t version;
uint32_t generation;
};
static int
obj_tree_destory_cb(daos_handle_t ih, d_iov_t *key_iov,
d_iov_t *val_iov, void *data)
{
struct tree_cache_root *root = val_iov->iov_buf;
int rc;
rc = dbtree_destroy(root->root_hdl, NULL);
if (rc)
D_ERROR("dbtree_destroy, cont "DF_UUID" failed: "DF_RC"\n",
DP_UUID(*(uuid_t *)key_iov->iov_buf), DP_RC(rc));
return rc;
}
int
obj_tree_destroy(daos_handle_t btr_hdl)
{
int rc;
rc = dbtree_iterate(btr_hdl, DAOS_INTENT_PUNCH, false,
obj_tree_destory_cb, NULL);
if (rc) {
D_ERROR("dbtree iterate failed: "DF_RC"\n", DP_RC(rc));
goto out;
}
rc = dbtree_destroy(btr_hdl, NULL);
out:
return rc;
}
static int
obj_tree_create(daos_handle_t toh, void *key, size_t key_size,
uint32_t class, uint64_t feats, struct tree_cache_root **rootp)
{
d_iov_t key_iov;
d_iov_t val_iov;
struct umem_attr uma;
struct tree_cache_root root = { 0 };
struct tree_cache_root *tmp_root;
int rc, rc2;
d_iov_set(&key_iov, key, key_size);
d_iov_set(&val_iov, &root, sizeof(root));
rc = dbtree_update(toh, &key_iov, &val_iov);
if (rc)
return rc;
d_iov_set(&val_iov, NULL, 0);
rc = dbtree_lookup(toh, &key_iov, &val_iov);
if (rc)
D_GOTO(out, rc);
tmp_root = val_iov.iov_buf;
memset(&uma, 0, sizeof(uma));
uma.uma_id = UMEM_CLASS_VMEM;
rc = dbtree_create_inplace(class, feats, 32, &uma, &tmp_root->btr_root,
&tmp_root->root_hdl);
if (rc) {
D_ERROR("failed to create rebuild tree: "DF_RC"\n", DP_RC(rc));
D_GOTO(out, rc);
}
*rootp = tmp_root;
out:
if (rc < 0) {
rc2 = dbtree_delete(toh, BTR_PROBE_EQ, &key_iov, NULL);
if (rc2)
D_WARN("failed to delete "DF_KEY": "DF_RC"\n",
DP_KEY(&key_iov), DP_RC(rc2));
}
return rc;
}
int
obj_tree_lookup(daos_handle_t toh, uuid_t co_uuid, daos_unit_oid_t oid,
d_iov_t *val_iov)
{
struct tree_cache_root *cont_root = NULL;
d_iov_t key_iov;
d_iov_t tmp_iov;
int rc;
/* locate the container first */
d_iov_set(&key_iov, co_uuid, sizeof(uuid_t));
d_iov_set(&tmp_iov, NULL, 0);
rc = dbtree_lookup(toh, &key_iov, &tmp_iov);
if (rc < 0) {
if (rc != -DER_NONEXIST)
D_ERROR("lookup cont "DF_UUID" failed, "DF_RC"\n",
DP_UUID(co_uuid), DP_RC(rc));
else
D_DEBUG(DB_TRACE, "Container "DF_UUID" not exist\n",
DP_UUID(co_uuid));
return rc;
}
cont_root = tmp_iov.iov_buf;
/* Then try to insert the object under the container */
d_iov_set(&key_iov, &oid, sizeof(oid));
rc = dbtree_lookup(cont_root->root_hdl, &key_iov, val_iov);
if (rc < 0) {
if (rc != -DER_NONEXIST)
D_ERROR(DF_UUID"/"DF_UOID" "DF_RC"\n",
DP_UUID(co_uuid), DP_UOID(oid), DP_RC(rc));
else
D_DEBUG(DB_TRACE, DF_UUID"/"DF_UOID " not exist\n",
DP_UUID(co_uuid), DP_UOID(oid));
}
return rc;
}
int
obj_tree_insert(daos_handle_t toh, uuid_t co_uuid, uint64_t tgt_id, daos_unit_oid_t oid,
d_iov_t *val_iov)
{
struct tree_cache_root *cont_root = NULL;
d_iov_t key_iov;
d_iov_t tmp_iov;
int rc;
/* locate the container first */
d_iov_set(&key_iov, co_uuid, sizeof(uuid_t));
d_iov_set(&tmp_iov, NULL, 0);
rc = dbtree_lookup(toh, &key_iov, &tmp_iov);
if (rc < 0) {
if (rc != -DER_NONEXIST) {
D_ERROR("lookup cont "DF_UUID" failed: "DF_RC"\n",
DP_UUID(co_uuid), DP_RC(rc));
return rc;
}
D_DEBUG(DB_TRACE, "Create cont "DF_UUID" tree\n", DP_UUID(co_uuid));
if (tgt_id != (uint64_t)(-1))
rc = obj_tree_create(toh, co_uuid, sizeof(uuid_t), DBTREE_CLASS_IFV,
BTR_FEAT_UINT_KEY, &cont_root);
else
rc = obj_tree_create(toh, co_uuid, sizeof(uuid_t), DBTREE_CLASS_NV,
BTR_FEAT_DIRECT_KEY, &cont_root);
if (rc) {
D_ERROR("tree_create cont "DF_UUID" failed: "DF_RC"\n",
DP_UUID(co_uuid), DP_RC(rc));
return rc;
}
} else {
cont_root = tmp_iov.iov_buf;
}
/* Then try to insert the object under the container */
if (tgt_id != (uint64_t)(-1)) {
d_iov_set(&key_iov, &tgt_id, sizeof(tgt_id));
d_iov_set(&tmp_iov, NULL, 0);
rc = dbtree_lookup(cont_root->root_hdl, &key_iov, &tmp_iov);
if (rc < 0) {
if (rc != -DER_NONEXIST) {
D_ERROR("lookup tgt "DF_U64" failed: "DF_RC"\n",
tgt_id, DP_RC(rc));
return rc;
}
D_DEBUG(DB_TRACE, "Create tgt "DF_U64" tree\n", tgt_id);
rc = obj_tree_create(cont_root->root_hdl, &tgt_id, sizeof(tgt_id),
DBTREE_CLASS_NV, BTR_FEAT_DIRECT_KEY, &cont_root);
if (rc) {
D_ERROR("tree_create tgt "DF_U64" failed: "DF_RC"\n",
tgt_id, DP_RC(rc));
return rc;
}
} else {
cont_root = tmp_iov.iov_buf;
}
}
/* Then try to insert the object under the container */
d_iov_set(&key_iov, &oid, sizeof(oid));
rc = dbtree_lookup(cont_root->root_hdl, &key_iov, val_iov);
if (rc == 0) {
D_DEBUG(DB_TRACE, DF_UOID"/"DF_UUID" already exits\n",
DP_UOID(oid), DP_UUID(co_uuid));
return -DER_EXIST;
}
rc = dbtree_update(cont_root->root_hdl, &key_iov, val_iov);
if (rc < 0) {
D_ERROR("failed to insert "DF_UOID": "DF_RC"\n",
DP_UOID(oid), DP_RC(rc));
return rc;
}
cont_root->count++;
D_DEBUG(DB_TRACE, "insert "DF_UOID"/"DF_UUID"/"DF_U64" in"
" root %p count %d\n", DP_UOID(oid),
DP_UUID(co_uuid), tgt_id, cont_root, cont_root->count);
return rc;
}
void
migrate_pool_tls_destroy(struct migrate_pool_tls *tls)
{
if (!tls)
return;
d_list_del(&tls->mpt_list);
D_DEBUG(DB_REBUILD, "TLS destroy for "DF_UUID" ver %d\n",
DP_UUID(tls->mpt_pool_uuid), tls->mpt_version);
if (tls->mpt_pool)
ds_pool_child_put(tls->mpt_pool);
if (tls->mpt_svc_list.rl_ranks)
D_FREE(tls->mpt_svc_list.rl_ranks);
if (tls->mpt_done_eventual)
ABT_eventual_free(&tls->mpt_done_eventual);
if (tls->mpt_inflight_cond)
ABT_cond_free(&tls->mpt_inflight_cond);
if (tls->mpt_inflight_mutex)
ABT_mutex_free(&tls->mpt_inflight_mutex);
if (tls->mpt_init_cond)
ABT_cond_free(&tls->mpt_init_cond);
if (tls->mpt_init_mutex)
ABT_mutex_free(&tls->mpt_init_mutex);
if (daos_handle_is_valid(tls->mpt_root_hdl))
obj_tree_destroy(tls->mpt_root_hdl);
if (daos_handle_is_valid(tls->mpt_migrated_root_hdl))
obj_tree_destroy(tls->mpt_migrated_root_hdl);
D_FREE(tls);
}
void
migrate_pool_tls_get(struct migrate_pool_tls *tls)
{
if (!tls)
return;
tls->mpt_refcount++;
}
void
migrate_pool_tls_put(struct migrate_pool_tls *tls)
{
if (!tls)
return;
tls->mpt_refcount--;
if (tls->mpt_fini && tls->mpt_refcount == 1)
ABT_eventual_set(tls->mpt_done_eventual, NULL, 0);
if (tls->mpt_refcount == 0)
migrate_pool_tls_destroy(tls);
}
struct migrate_pool_tls *
migrate_pool_tls_lookup(uuid_t pool_uuid, unsigned int ver, uint32_t gen)
{
struct obj_tls *tls = obj_tls_get();
struct migrate_pool_tls *pool_tls;
struct migrate_pool_tls *found = NULL;
D_ASSERT(tls != NULL);
/* Only 1 thread will access the list, no need lock */
d_list_for_each_entry(pool_tls, &tls->ot_pool_list, mpt_list) {
if (uuid_compare(pool_tls->mpt_pool_uuid, pool_uuid) == 0 &&
(ver == (unsigned int)(-1) || ver == pool_tls->mpt_version) &&
(gen == (unsigned int)(-1) || gen == pool_tls->mpt_generation)) {
migrate_pool_tls_get(pool_tls);
found = pool_tls;
break;
}
}
return found;
}
struct migrate_pool_tls_create_arg {
uuid_t pool_uuid;
uuid_t pool_hdl_uuid;
uuid_t co_hdl_uuid;
d_rank_list_t *svc_list;
uint64_t max_eph;
unsigned int version;
unsigned int generation;
uint32_t opc;
uint32_t new_layout_ver;
};
int
migrate_pool_tls_create_one(void *data)
{
struct migrate_pool_tls_create_arg *arg = data;
struct obj_tls *tls = obj_tls_get();
struct migrate_pool_tls *pool_tls;
int rc;
pool_tls = migrate_pool_tls_lookup(arg->pool_uuid, arg->version, arg->generation);
if (pool_tls != NULL) {
/* Some one else already created, because collective function
* might yield xstream.
*/
migrate_pool_tls_put(pool_tls);
return 0;
}
D_ALLOC_PTR(pool_tls);
if (pool_tls == NULL)
D_GOTO(out, rc = -DER_NOMEM);
rc = ABT_eventual_create(0, &pool_tls->mpt_done_eventual);
if (rc != ABT_SUCCESS)
D_GOTO(out, rc = dss_abterr2der(rc));
rc = ABT_cond_create(&pool_tls->mpt_inflight_cond);
if (rc != ABT_SUCCESS)
D_GOTO(out, rc = dss_abterr2der(rc));
rc = ABT_mutex_create(&pool_tls->mpt_inflight_mutex);
if (rc != ABT_SUCCESS)
D_GOTO(out, rc = dss_abterr2der(rc));
uuid_copy(pool_tls->mpt_pool_uuid, arg->pool_uuid);
uuid_copy(pool_tls->mpt_poh_uuid, arg->pool_hdl_uuid);
uuid_copy(pool_tls->mpt_coh_uuid, arg->co_hdl_uuid);
pool_tls->mpt_version = arg->version;
pool_tls->mpt_generation = arg->generation;
pool_tls->mpt_rec_count = 0;
pool_tls->mpt_obj_count = 0;
pool_tls->mpt_size = 0;
pool_tls->mpt_generated_ult = 0;
pool_tls->mpt_executed_ult = 0;
pool_tls->mpt_root_hdl = DAOS_HDL_INVAL;
pool_tls->mpt_max_eph = arg->max_eph;
pool_tls->mpt_pool = ds_pool_child_lookup(arg->pool_uuid);
pool_tls->mpt_new_layout_ver = arg->new_layout_ver;
pool_tls->mpt_opc = arg->opc;
pool_tls->mpt_inflight_max_size = MIGRATE_MAX_SIZE;
pool_tls->mpt_inflight_max_ult = MIGRATE_MAX_ULT;
pool_tls->mpt_inflight_size = 0;
pool_tls->mpt_refcount = 1;
if (arg->svc_list) {
rc = daos_rank_list_copy(&pool_tls->mpt_svc_list, arg->svc_list);
if (rc)
D_GOTO(out, rc);
}
D_DEBUG(DB_REBUILD, "TLS %p create for "DF_UUID" "DF_UUID"/"DF_UUID
" ver %d "DF_RC"\n", pool_tls, DP_UUID(pool_tls->mpt_pool_uuid),
DP_UUID(arg->pool_hdl_uuid), DP_UUID(arg->co_hdl_uuid),
arg->version, DP_RC(rc));
d_list_add(&pool_tls->mpt_list, &tls->ot_pool_list);
out:
if (rc && pool_tls)
migrate_pool_tls_destroy(pool_tls);
return rc;
}
static int
migrate_pool_tls_lookup_create(struct ds_pool *pool, unsigned int version, unsigned int generation,
uuid_t pool_hdl_uuid, uuid_t co_hdl_uuid, uint64_t max_eph,
uint32_t new_layout_ver, uint32_t opc, struct migrate_pool_tls **p_tls)
{
struct migrate_pool_tls *tls = NULL;
struct migrate_pool_tls_create_arg arg = { 0 };
daos_prop_t *prop = NULL;
struct daos_prop_entry *entry;
int rc = 0;
D_ASSERT(dss_get_module_info()->dmi_xs_id == 0);
tls = migrate_pool_tls_lookup(pool->sp_uuid, version, generation);
if (tls) {
if (tls->mpt_init_tls) {
ABT_mutex_lock(tls->mpt_init_mutex);
ABT_cond_wait(tls->mpt_init_cond, tls->mpt_init_mutex);
ABT_mutex_unlock(tls->mpt_init_mutex);
if (tls->mpt_init_failed) {
migrate_pool_tls_put(tls);
rc = -DER_NOMEM;
}
}
if (rc == 0)
*p_tls = tls;
return rc;
}
D_ASSERT(generation != (unsigned int)(-1));
uuid_copy(arg.pool_uuid, pool->sp_uuid);
uuid_copy(arg.pool_hdl_uuid, pool_hdl_uuid);
uuid_copy(arg.co_hdl_uuid, co_hdl_uuid);
arg.version = version;
arg.opc = opc;
arg.max_eph = max_eph;
arg.new_layout_ver = new_layout_ver;
arg.generation = generation;
/* dss_task_collective does not do collective on xstream 0 */
rc = migrate_pool_tls_create_one(&arg);
if (rc)
D_GOTO(out, rc);
tls = migrate_pool_tls_lookup(pool->sp_uuid, version, generation);
D_ASSERT(tls != NULL);
pool->sp_rebuilding++;
rc = ABT_cond_create(&tls->mpt_init_cond);
if (rc != ABT_SUCCESS)
D_GOTO(out, rc = dss_abterr2der(rc));
rc = ABT_mutex_create(&tls->mpt_init_mutex);
if (rc != ABT_SUCCESS)
D_GOTO(out, rc = dss_abterr2der(rc));
tls->mpt_init_tls = 1;
D_ALLOC_PTR(prop);
if (prop == NULL)
D_GOTO(out, rc = -DER_NOMEM);
rc = ds_pool_iv_prop_fetch(pool, prop);
if (rc)
D_GOTO(out, rc);
entry = daos_prop_entry_get(prop, DAOS_PROP_PO_SVC_LIST);
D_ASSERT(entry != NULL);
arg.svc_list = (d_rank_list_t *)entry->dpe_val_ptr;
rc = dss_task_collective(migrate_pool_tls_create_one, &arg, 0);
if (rc != 0) {
D_ERROR(DF_UUID": failed to create migrate tls: "DF_RC"\n",
DP_UUID(pool->sp_uuid), DP_RC(rc));
D_GOTO(out, rc);
}
out:
if (tls != NULL && tls->mpt_init_tls) {
tls->mpt_init_tls = 0;
/* Set init failed, so the waiting lookup(above) can be notified */
if (rc != 0)
tls->mpt_init_failed = 1;
ABT_mutex_lock(tls->mpt_init_mutex);
ABT_cond_broadcast(tls->mpt_init_cond);
ABT_mutex_unlock(tls->mpt_init_mutex);
}
D_DEBUG(DB_TRACE, "create tls "DF_UUID": "DF_RC"\n",
DP_UUID(pool->sp_uuid), DP_RC(rc));
if (rc != 0) {
if (tls != NULL)
migrate_pool_tls_put(tls);
} else {
*p_tls = tls;
}
if (prop != NULL)
daos_prop_free(prop);
return rc;
}
static void
mrone_recx_daos_vos_internal(struct migrate_one *mrone, bool daos2vos, int shard,
daos_iod_t *iods, int iods_num)
{
daos_iod_t *iod;
int cell_nr;
int stripe_nr;
int j;
int k;
D_ASSERT(daos_oclass_is_ec(&mrone->mo_oca));
cell_nr = obj_ec_cell_rec_nr(&mrone->mo_oca);
stripe_nr = obj_ec_stripe_rec_nr(&mrone->mo_oca);
/* Convert the DAOS to VOS EC offset */
for (j = 0; j < iods_num; j++) {
iod = &iods[j];
if (iod->iod_type == DAOS_IOD_SINGLE)
continue;
for (k = 0; k < iod->iod_nr; k++) {
daos_recx_t *recx;
recx = &iod->iod_recxs[k];
D_ASSERTF(recx->rx_nr <= cell_nr, DF_U64"/"DF_U64"cell nr %d "DF_UOID"\n",
recx->rx_idx, recx->rx_nr, cell_nr, DP_UOID(mrone->mo_oid));
if (daos2vos)
recx->rx_idx = obj_ec_idx_daos2vos(recx->rx_idx,
stripe_nr,
cell_nr);
else
recx->rx_idx = obj_ec_idx_vos2daos(recx->rx_idx,
stripe_nr,
cell_nr,
shard);
D_DEBUG(DB_REBUILD, "j %d k %d "DF_U64"/"DF_U64"\n",
j, k, recx->rx_idx, recx->rx_nr);
}
}
}
static void
mrone_recx_daos2_vos(struct migrate_one *mrone, daos_iod_t *iods, int iods_num)
{
mrone_recx_daos_vos_internal(mrone, true, -1, iods, iods_num);
}
static void
mrone_recx_vos2_daos(struct migrate_one *mrone, int shard, daos_iod_t *iods, int iods_num)
{
shard = obj_ec_shard_off_by_layout_ver(mrone->mo_oid.id_layout_ver, mrone->mo_dkey_hash,
&mrone->mo_oca, shard);
D_ASSERT(shard < obj_ec_data_tgt_nr(&mrone->mo_oca));
mrone_recx_daos_vos_internal(mrone, false, shard, iods, iods_num);
}
static int
mrone_obj_fetch(struct migrate_one *mrone, daos_handle_t oh, d_sg_list_t *sgls,
daos_iod_t *iods, int iod_num, daos_epoch_t eph, uint32_t flags,
d_iov_t *csum_iov_fetch)
{
struct migrate_pool_tls *tls;
int rc = 0;
tls = migrate_pool_tls_lookup(mrone->mo_pool_uuid,
mrone->mo_pool_tls_version, mrone->mo_generation);
if (tls == NULL || tls->mpt_fini) {
D_WARN("some one abort the rebuild "DF_UUID"\n",
DP_UUID(mrone->mo_pool_uuid));
D_GOTO(out, rc = -DER_SHUTDOWN);
}
if (daos_oclass_grp_size(&mrone->mo_oca) > 1)
flags |= DIOF_TO_LEADER;
rc = dsc_obj_fetch(oh, eph, &mrone->mo_dkey,
iod_num, iods, sgls, NULL,
flags, NULL, csum_iov_fetch);
if (rc != 0)
D_GOTO(out, rc);
if (csum_iov_fetch != NULL &&
csum_iov_fetch->iov_len > csum_iov_fetch->iov_buf_len) {
/** retry dsc_obj_fetch with appropriate csum_iov
* buf length
*/
void *p;
D_REALLOC(p, csum_iov_fetch->iov_buf,
csum_iov_fetch->iov_buf_len, csum_iov_fetch->iov_len);
if (p == NULL)
D_GOTO(out, rc = -DER_NOMEM);
csum_iov_fetch->iov_buf_len = csum_iov_fetch->iov_len;
csum_iov_fetch->iov_len = 0;
csum_iov_fetch->iov_buf = p;
rc = dsc_obj_fetch(oh, eph, &mrone->mo_dkey, iod_num, iods, sgls,
NULL, flags, NULL, csum_iov_fetch);
}
out:
migrate_pool_tls_put(tls);
return rc;
}
static int
migrate_csum_calc(struct daos_csummer *csummer, struct migrate_one *mrone, daos_iod_t *iods,
int iod_num, d_sg_list_t *sgls, d_iov_t *csum_iov,
struct dcs_iod_csums **iod_csums)
{
d_iov_t tmp_csum_iov;
d_iov_t *p_csum_iov;
int rc;
if (daos_oclass_is_ec(&mrone->mo_oca)) {
D_DEBUG(DB_CSUM, DF_C_UOID_DKEY" REBUILD: Calculating csums. IOD count: %d\n",
DP_C_UOID_DKEY(mrone->mo_oid, &mrone->mo_dkey), iod_num);
rc = daos_csummer_calc_iods(csummer, sgls, iods, NULL, iod_num, false, NULL,
-1, iod_csums);
return rc;
}
D_DEBUG(DB_CSUM, DF_C_UOID_DKEY" REBUILD: Using packed csums\n",
DP_C_UOID_DKEY(mrone->mo_oid, &mrone->mo_dkey));
/** make a copy of the iov because it will be modified while
* iterating over the csums
*/
D_ASSERT(csum_iov != NULL);
tmp_csum_iov = *csum_iov;
p_csum_iov = &tmp_csum_iov;
rc = daos_csummer_alloc_iods_csums_with_packed(csummer, iods, iod_num,
p_csum_iov, iod_csums);
if (rc != 0)
D_ERROR("Failed to alloc iod csums: "DF_RC"\n", DP_RC(rc));
return rc;
}
#define MIGRATE_STACK_SIZE 131072
#define MAX_BUF_SIZE 2048
#define CSUM_BUF_SIZE 256
/**
* allocate the memory for the iods_csums and unpack the csum_iov into the
* into the iods_csums.
* Note: the csum_iov is modified so a shallow copy should be sent instead of
* the original.
*/
static int
migrate_fetch_update_inline(struct migrate_one *mrone, daos_handle_t oh,
struct ds_cont_child *ds_cont)
{
d_sg_list_t sgls[OBJ_ENUM_UNPACK_MAX_IODS];
d_iov_t iov[OBJ_ENUM_UNPACK_MAX_IODS];
struct daos_csummer *csummer = NULL;
struct dcs_iod_csums *iod_csums = NULL;
int iod_cnt = 0;
int start;
char iov_buf[OBJ_ENUM_UNPACK_MAX_IODS][MAX_BUF_SIZE];
bool fetch = false;
int i;
int rc = 0;
d_iov_t *p_csum_iov = NULL;
d_iov_t csum_iov = {0};
D_ASSERT(mrone->mo_iod_num <= OBJ_ENUM_UNPACK_MAX_IODS);
for (i = 0; i < mrone->mo_iod_num; i++) {
if (mrone->mo_iods[i].iod_size == 0)
continue;
/* Let's do real fetch for all EC object, since the
* checksum needs to be re-calculated for EC rebuild,
* and we do not have checksum information yet.
*/
if ((mrone->mo_sgls != NULL && mrone->mo_sgls[i].sg_nr > 0) &&
!daos_oclass_is_ec(&mrone->mo_oca)) {
sgls[i] = mrone->mo_sgls[i];
} else {
sgls[i].sg_nr = 1;
sgls[i].sg_nr_out = 1;
d_iov_set(&iov[i], iov_buf[i], MAX_BUF_SIZE);
sgls[i].sg_iovs = &iov[i];
fetch = true;
}
}
D_DEBUG(DB_REBUILD, DF_UOID " mrone %p dkey " DF_KEY " nr %d eph " DF_U64 " fetch %s\n",
DP_UOID(mrone->mo_oid), mrone, DP_KEY(&mrone->mo_dkey), mrone->mo_iod_num,
mrone->mo_epoch, fetch ? "yes" : "no");
if (DAOS_FAIL_CHECK(DAOS_REBUILD_NO_UPDATE))
return 0;
if (DAOS_FAIL_CHECK(DAOS_REBUILD_UPDATE_FAIL))
return -DER_INVAL;
if (fetch) {
if (!daos_oclass_is_ec(&mrone->mo_oca)) {
rc = daos_iov_alloc(&csum_iov, CSUM_BUF_SIZE, false);
if (rc != 0)
D_GOTO(out, rc);
p_csum_iov = &csum_iov;
}
rc = mrone_obj_fetch(mrone, oh, sgls, mrone->mo_iods, mrone->mo_iod_num,
mrone->mo_epoch, DIOF_FOR_MIGRATION, p_csum_iov);
if (rc) {
D_ERROR("mrone_obj_fetch "DF_RC"\n", DP_RC(rc));
D_GOTO(out, rc);
}
}
if (daos_oclass_is_ec(&mrone->mo_oca) &&
!is_ec_parity_shard_by_layout_ver(mrone->mo_oid.id_layout_ver, mrone->mo_dkey_hash,
&mrone->mo_oca, mrone->mo_oid.id_shard))
mrone_recx_daos2_vos(mrone, mrone->mo_iods, mrone->mo_iod_num);
csummer = dsc_cont2csummer(dc_obj_hdl2cont_hdl(oh));
for (i = 0, start = 0; i < mrone->mo_iod_num; i++) {
daos_iod_t *iods = mrone->mo_iods;
if (iods[i].iod_size > 0) {
iod_cnt++;
continue;
}
/* skip empty record */
if (iod_cnt == 0) {
D_DEBUG(DB_TRACE, "i %d iod_size = 0\n", i);
continue;
}
D_DEBUG(DB_TRACE, "update start %d cnt %d\n", start, iod_cnt);
rc = migrate_csum_calc(csummer, mrone, &iods[start], iod_cnt, &sgls[start],
fetch ? &csum_iov : &mrone->mo_csum_iov, &iod_csums);
if (rc != 0) {
D_ERROR("Error calculating checksums: "DF_RC"\n", DP_RC(rc));
break;
}
rc = vos_obj_update(ds_cont->sc_hdl, mrone->mo_oid,
mrone->mo_min_epoch, mrone->mo_version,
VOS_OF_REBUILD, &mrone->mo_dkey, iod_cnt, &iods[start],
iod_csums, &sgls[start]);
daos_csummer_free_ic(csummer, &iod_csums);
if (rc) {
D_ERROR("migrate failed: "DF_RC"\n", DP_RC(rc));
break;
}
iod_cnt = 0;
start = i + 1;
}
if (iod_cnt > 0) {
rc = migrate_csum_calc(csummer, mrone, &mrone->mo_iods[start], iod_cnt,
&sgls[start], fetch ? &csum_iov : &mrone->mo_csum_iov,
&iod_csums);
if (rc != 0) {
D_ERROR("Error calculating checksums: "DF_RC"\n", DP_RC(rc));
D_GOTO(out, rc);
}
rc = vos_obj_update(ds_cont->sc_hdl, mrone->mo_oid,
mrone->mo_min_epoch, mrone->mo_version,
VOS_OF_REBUILD, &mrone->mo_dkey, iod_cnt,
&mrone->mo_iods[start], iod_csums,
&sgls[start]);
if (rc) {
D_ERROR("migrate failed: "DF_RC"\n", DP_RC(rc));
D_GOTO(out, rc);
}
daos_csummer_free_ic(csummer, &iod_csums);
}
out:
if (csum_iov.iov_buf != NULL)
D_FREE(csum_iov.iov_buf);
return rc;
}
static int
migrate_update_parity(struct migrate_one *mrone, daos_epoch_t parity_eph,
struct ds_cont_child *ds_cont, unsigned char *buffer,
daos_off_t offset, daos_size_t size, daos_iod_t *iod,
unsigned char *p_bufs[], struct daos_csummer *csummer, bool encode)
{
struct daos_oclass_attr *oca = &mrone->mo_oca;
daos_size_t stride_nr = obj_ec_stripe_rec_nr(oca);
daos_size_t cell_nr = obj_ec_cell_rec_nr(oca);
daos_size_t split_size;
daos_recx_t tmp_recx;
d_iov_t tmp_iov;
d_sg_list_t tmp_sgl;
daos_size_t write_nr;
struct dcs_iod_csums *iod_csums = NULL;
int rc = 0;
split_size = encode ? stride_nr : cell_nr;
tmp_sgl.sg_nr = tmp_sgl.sg_nr_out = 1;
while (size > 0) {
if (offset % split_size != 0)
write_nr = min(roundup(offset, split_size) - offset, size);
else
write_nr = min(split_size, size);
if (write_nr == stride_nr) {
unsigned int shard;
D_ASSERT(encode);
shard = obj_ec_shard_off_by_layout_ver(mrone->mo_oid.id_layout_ver,
mrone->mo_dkey_hash, &mrone->mo_oca,
mrone->mo_oid.id_shard);
D_ASSERT(shard >= obj_ec_data_tgt_nr(oca));
shard -= obj_ec_data_tgt_nr(oca);
D_ASSERT(shard < obj_ec_parity_tgt_nr(oca));
rc = obj_ec_encode_buf(mrone->mo_oid.id_pub,
oca, iod->iod_size, buffer,
p_bufs);
if (rc)
D_GOTO(out, rc);
tmp_recx.rx_idx = obj_ec_idx_daos2vos(offset, stride_nr,
cell_nr);
tmp_recx.rx_idx |= PARITY_INDICATOR;
tmp_recx.rx_nr = cell_nr;
d_iov_set(&tmp_iov, p_bufs[shard],
cell_nr * iod->iod_size);
D_DEBUG(DB_IO, "parity "DF_X64"/"DF_U64" "DF_U64"\n",
tmp_recx.rx_idx, tmp_recx.rx_nr, iod->iod_size);
} else {
tmp_recx.rx_idx = offset;
tmp_recx.rx_nr = write_nr;
d_iov_set(&tmp_iov, buffer, write_nr * iod->iod_size);
D_DEBUG(DB_IO, "replicate "DF_U64"/"DF_U64" "
DF_U64"\n", tmp_recx.rx_idx,
tmp_recx.rx_nr, iod->iod_size);
}
tmp_sgl.sg_iovs = &tmp_iov;
iod->iod_recxs = &tmp_recx;
iod->iod_nr = 1;
rc = daos_csummer_calc_iods(csummer, &tmp_sgl, iod, NULL, 1,
false, NULL, 0, &iod_csums);
if (rc != 0) {
D_ERROR("Error calculating checksums: "DF_RC"\n",
DP_RC(rc));
D_GOTO(out, rc);
}
rc = vos_obj_update(ds_cont->sc_hdl, mrone->mo_oid,
parity_eph, mrone->mo_version,
VOS_OF_REBUILD, &mrone->mo_dkey, 1, iod, iod_csums,
&tmp_sgl);
if (rc != 0)
D_GOTO(out, rc);
size -= write_nr;
offset += write_nr;
buffer += write_nr * iod->iod_size;
}
out:
daos_csummer_free_ic(csummer, &iod_csums);
return rc;
}
static int
__migrate_fetch_update_parity(struct migrate_one *mrone, daos_handle_t oh,
daos_iod_t *iods, daos_epoch_t fetch_eph,
daos_epoch_t **ephs, uint32_t iods_num,
struct ds_cont_child *ds_cont, bool encode)
{
d_sg_list_t sgls[OBJ_ENUM_UNPACK_MAX_IODS];
d_iov_t iov[OBJ_ENUM_UNPACK_MAX_IODS] = { 0 };
char *data;
daos_size_t size;
unsigned int p = obj_ec_parity_tgt_nr(&mrone->mo_oca);
daos_size_t stride_nr = obj_ec_stripe_rec_nr(&mrone->mo_oca);
unsigned char *p_bufs[OBJ_EC_MAX_P] = { 0 };
struct daos_csummer *csummer = NULL;
unsigned char *ptr;
int i;
int rc;
D_ASSERT(iods_num <= OBJ_ENUM_UNPACK_MAX_IODS);
for (i = 0; i < iods_num; i++) {
size = daos_iods_len(&iods[i], 1);
D_ALLOC(data, size);
if (data == NULL)
D_GOTO(out, rc = -DER_NOMEM);
d_iov_set(&iov[i], data, size);
sgls[i].sg_nr = 1;
sgls[i].sg_nr_out = 1;
sgls[i].sg_iovs = &iov[i];
}
D_DEBUG(DB_REBUILD, DF_UOID" mrone %p dkey "DF_KEY" nr %d eph "DF_U64"\n",
DP_UOID(mrone->mo_oid), mrone, DP_KEY(&mrone->mo_dkey), iods_num, mrone->mo_epoch);
rc = mrone_obj_fetch(mrone, oh, sgls, iods, iods_num, fetch_eph, DIOF_FOR_MIGRATION,
NULL);
if (rc) {
D_ERROR("migrate dkey "DF_KEY" failed: "DF_RC"\n",
DP_KEY(&mrone->mo_dkey), DP_RC(rc));
D_GOTO(out, rc);
}
csummer = dsc_cont2csummer(dc_obj_hdl2cont_hdl(oh));
for (i = 0; i < iods_num; i++) {
daos_off_t offset;
daos_iod_t tmp_iod;
daos_epoch_t parity_eph;
int j;
offset = iods[i].iod_recxs[0].rx_idx;
size = iods[i].iod_recxs[0].rx_nr;
/* Use stable epoch for partial parity update to make sure
* these partial updates are not below stable epoch boundary,