-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathsrv_target.c
2588 lines (2183 loc) · 67.5 KB
/
srv_target.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 2016-2023 Intel Corporation.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
/**
* ds_cont: Target Operations
*
* This file contains the server API methods and the RPC handlers that are both
* related target states.
*
* Data structures used here:
*
* Pool Container
*
* Global ds_pool
* ds_pool_hdl
*
* Thread-local ds_pool_child ds_cont_child
* ds_cont_hdl
*/
#define D_LOGFAC DD_FAC(container)
#include <daos_srv/container.h>
#include <daos_srv/security.h>
#include <daos/checksum.h>
#include <daos/rpc.h>
#include <daos_srv/pool.h>
#include <daos_srv/vos.h>
#include <daos_srv/iv.h>
#include <daos_srv/srv_obj_ec.h>
#include "rpc.h"
#include "srv_internal.h"
#include <daos/cont_props.h>
#include <daos/dedup.h>
/* Per VOS container aggregation ULT ***************************************/
static inline struct sched_request *
cont2req(struct ds_cont_child *cont, bool vos_agg)
{
return vos_agg ? cont->sc_agg_req : cont->sc_ec_agg_req;
}
int
agg_rate_ctl(void *arg)
{
struct agg_param *param = arg;
struct ds_cont_child *cont = param->ap_cont;
struct ds_pool *pool = cont->sc_pool->spc_pool;
struct sched_request *req = cont2req(cont, param->ap_vos_agg);
uint32_t msecs;
/* Abort current round of aggregation */
if (dss_ult_exiting(req) || pool->sp_reclaim == DAOS_RECLAIM_DISABLED)
return -1;
/*
* XXX temporary workaround: EC aggregation needs to be paused during rebuilding
* to avoid the race between EC rebuild and EC aggregation.
**/
if (pool->sp_rebuilding && cont->sc_ec_agg_active && !param->ap_vos_agg)
return -1;
/* When system is idle or under space pressure, let aggregation run in tight mode */
if (!dss_xstream_is_busy() || sched_req_space_check(req) != SCHED_SPACE_PRESS_NONE) {
sched_req_yield(req);
return 0;
}
msecs = (pool->sp_reclaim == DAOS_RECLAIM_LAZY) ? 1000 : 50;
sched_req_sleep(req, msecs);
/* System is busy and no space pressure, let aggregation run in slack mode */
return 1;
}
int
ds_cont_get_props(struct cont_props *cont_props, uuid_t pool_uuid,
uuid_t cont_uuid)
{
daos_prop_t *props;
int rc;
/* The provided prop entry types should cover the types used in
* daos_props_2cont_props().
*/
props = daos_prop_alloc(17);
if (props == NULL)
return -DER_NOMEM;
props->dpp_entries[0].dpe_type = DAOS_PROP_CO_CSUM;
props->dpp_entries[1].dpe_type = DAOS_PROP_CO_CSUM_CHUNK_SIZE;
props->dpp_entries[2].dpe_type = DAOS_PROP_CO_CSUM_SERVER_VERIFY;
props->dpp_entries[3].dpe_type = DAOS_PROP_CO_DEDUP;
props->dpp_entries[4].dpe_type = DAOS_PROP_CO_DEDUP_THRESHOLD;
props->dpp_entries[5].dpe_type = DAOS_PROP_CO_COMPRESS;
props->dpp_entries[6].dpe_type = DAOS_PROP_CO_ENCRYPT;
props->dpp_entries[7].dpe_type = DAOS_PROP_CO_REDUN_FAC;
props->dpp_entries[8].dpe_type = DAOS_PROP_CO_ALLOCED_OID;
props->dpp_entries[9].dpe_type = DAOS_PROP_CO_EC_CELL_SZ;
props->dpp_entries[10].dpe_type = DAOS_PROP_CO_EC_PDA;
props->dpp_entries[11].dpe_type = DAOS_PROP_CO_RP_PDA;
props->dpp_entries[12].dpe_type = DAOS_PROP_CO_GLOBAL_VERSION;
props->dpp_entries[13].dpe_type = DAOS_PROP_CO_REDUN_LVL;
props->dpp_entries[14].dpe_type = DAOS_PROP_CO_OBJ_VERSION;
props->dpp_entries[15].dpe_type = DAOS_PROP_CO_STATUS;
props->dpp_entries[16].dpe_type = DAOS_PROP_CO_PERF_DOMAIN;
rc = cont_iv_prop_fetch(pool_uuid, cont_uuid, props);
if (rc == DER_SUCCESS)
daos_props_2cont_props(props, cont_props);
daos_prop_free(props);
return rc;
}
int
ds_cont_csummer_init(struct ds_cont_child *cont)
{
uint32_t csum_val;
int rc;
struct cont_props *cont_props;
bool dedup_only = false;
D_ASSERT(cont != NULL);
cont_props = &cont->sc_props;
if (cont->sc_props_fetched)
return 0;
/** Get the container csum related properties
* Need the pool for the IV namespace
*/
D_ASSERT(cont->sc_csummer == NULL);
rc = ds_cont_get_props(cont_props, cont->sc_pool_uuid, cont->sc_uuid);
if (rc != 0)
goto done;
/* Check again since IV fetch yield */
if (cont->sc_props_fetched)
goto done;
cont->sc_props_fetched = 1;
csum_val = cont_props->dcp_csum_type;
if (!daos_cont_csum_prop_is_enabled(csum_val)) {
dedup_only = true;
csum_val = dedup_get_csum_algo(cont_props);
}
/** If enabled, initialize the csummer for the container */
if (daos_cont_csum_prop_is_enabled(csum_val)) {
rc = daos_csummer_init_with_type(&cont->sc_csummer,
daos_contprop2hashtype(csum_val),
cont_props->dcp_chunksize,
cont_props->dcp_srv_verify);
if (dedup_only)
dedup_configure_csummer(cont->sc_csummer, cont_props);
}
done:
return rc;
}
static bool
cont_aggregate_runnable(struct ds_cont_child *cont, struct sched_request *req,
bool vos_agg)
{
struct ds_pool *pool = cont->sc_pool->spc_pool;
if (unlikely(pool->sp_map == NULL) || pool->sp_stopping) {
/* If it does not get the pool map from the pool leader,
* see pool_iv_pre_sync(), the IV fetch from the following
* ds_cont_csummer_init() will fail anyway.
*/
D_DEBUG(DB_EPC, DF_CONT": skip aggregation "
"No pool map yet or stopping %d\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid),
pool->sp_stopping);
return false;
}
if (pool->sp_rebuilding && !vos_agg) {
cont->sc_ec_agg_active = 0;
D_DEBUG(DB_EPC, DF_CONT": skip EC aggregation during rebuild %d.\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid),
pool->sp_rebuilding);
return false;
}
if (vos_agg) {
if (!cont->sc_vos_agg_active)
D_DEBUG(DB_EPC, DF_CONT": resume VOS aggregation after reintegration.\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid));
cont->sc_vos_agg_active = 1;
} else {
if (!cont->sc_ec_agg_active)
D_DEBUG(DB_EPC, DF_CONT": resume EC aggregation after reintegration.\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid));
cont->sc_ec_agg_active = 1;
}
if (!cont->sc_props_fetched)
ds_cont_csummer_init(cont);
if (cont->sc_props.dcp_dedup_enabled ||
cont->sc_props.dcp_compress_enabled ||
cont->sc_props.dcp_encrypt_enabled) {
D_DEBUG(DB_EPC, DF_CONT": skip aggregation for "
"deduped/compressed/encrypted container\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid));
return false;
}
/* snapshot list isn't fetched yet */
if (cont->sc_aggregation_max == 0) {
D_DEBUG(DB_EPC, "No aggregation before snapshots fetched\n");
/* fetch snapshot list */
if (dss_get_module_info()->dmi_tgt_id == 0)
ds_cont_tgt_snapshots_refresh(cont->sc_pool->spc_uuid,
cont->sc_uuid);
return false;
}
if (pool->sp_reclaim == DAOS_RECLAIM_DISABLED) {
D_DEBUG(DB_EPC, "Pool reclaim strategy is disabled\n");
return false;
}
/*
* EC aggregation must proceed no matter if the target is busy or not,
* otherwise, the global EC boundary won't be bumped promptly, and that
* will impact VOS aggregation on every target.
*/
if (!vos_agg)
return true;
if (pool->sp_reclaim == DAOS_RECLAIM_LAZY && dss_xstream_is_busy() &&
sched_req_space_check(req) == SCHED_SPACE_PRESS_NONE) {
D_DEBUG(DB_EPC, "Pool reclaim strategy is lazy, service is "
"busy and no space pressure\n");
return false;
}
return true;
}
/* Get HAE (Highest Aggregate Epoch) for EC/VOS aggregation */
static uint64_t
get_hae(struct ds_cont_child *cont, bool vos_agg)
{
vos_cont_info_t cinfo;
int rc;
/* EC aggregation */
if (!vos_agg)
return cont->sc_ec_agg_eph;
/*
* Query the 'Highest Aggregated Epoch', the HAE will be bumped
* in vos_aggregate()
*/
rc = vos_cont_query(cont->sc_hdl, &cinfo);
if (rc) {
D_ERROR("cont query failed: rc: %d\n", rc);
return 0;
}
return cinfo.ci_hae;
}
/* Adjust the calculated EC/VOS aggregation upper bound */
static inline void
adjust_upper_bound(struct ds_cont_child *cont, bool vos_agg, uint64_t *upper_bound)
{
/* Cap the upper bound when taking snapshot */
if (*upper_bound >= cont->sc_aggregation_max)
*upper_bound = cont->sc_aggregation_max - 1;
/* Adjust EC aggregation upper bound, or EC aggregation disabled */
if (!vos_agg || unlikely(ec_agg_disabled))
return;
/* Cap VOS aggregation upper bound to EC aggregation HAE */
*upper_bound = min(*upper_bound, cont->sc_ec_agg_eph_boundary);
}
#define MAX_SNAPSHOT_LOCAL 16
static int
cont_child_aggregate(struct ds_cont_child *cont, cont_aggregate_cb_t agg_cb,
struct agg_param *param)
{
daos_epoch_t epoch_max, epoch_min;
daos_epoch_range_t epoch_range;
struct sched_request *req = cont2req(cont, param->ap_vos_agg);
uint64_t hlc = d_hlc_get();
uint64_t change_hlc;
uint64_t interval;
uint64_t snapshots_local[MAX_SNAPSHOT_LOCAL] = { 0 };
uint64_t *snapshots = NULL;
int snapshots_nr;
int tgt_id = dss_get_module_info()->dmi_tgt_id;
uint32_t flags = 0;
int i, rc = 0;
change_hlc = max(cont->sc_snapshot_delete_hlc,
cont->sc_pool->spc_rebuild_end_hlc);
if (param->ap_full_scan_hlc < change_hlc) {
/* Snapshot has been deleted or rebuild happens since the last
* aggregation, let's restart from 0.
*/
epoch_min = 0;
flags |= VOS_AGG_FL_FORCE_SCAN;
D_DEBUG(DB_EPC, "change hlc "DF_X64" > full "DF_X64"\n",
change_hlc, param->ap_full_scan_hlc);
} else {
epoch_min = get_hae(cont, param->ap_vos_agg);
}
if (unlikely(DAOS_FAIL_CHECK(DAOS_FORCE_EC_AGG) ||
DAOS_FAIL_CHECK(DAOS_FORCE_EC_AGG_FAIL) ||
DAOS_FAIL_CHECK(DAOS_FORCE_EC_AGG_PEER_FAIL)))
interval = 0;
else
interval = d_sec2hlc(DAOS_AGG_THRESHOLD);
D_ASSERT(hlc > (interval * 2));
/*
* Assume the epoch of 'current hlc - interval' as the highest stable view:
* - Most transactions under this epoch are either committed or aborted;
* - No new transactions would happen under this epoch;
*/
epoch_max = hlc - interval;
/*
* When there isn't space pressure, don't aggregate too often, otherwise,
* aggregation will be inefficient because the data to be aggregated could
* be changed by new update very soon.
*/
if (epoch_min > epoch_max - interval &&
sched_req_space_check(req) == SCHED_SPACE_PRESS_NONE)
return 0;
adjust_upper_bound(cont, param->ap_vos_agg, &epoch_max);
if (epoch_min >= epoch_max) {
D_DEBUG(DB_EPC, "epoch min "DF_X64" >= max "DF_X64"\n", epoch_min, epoch_max);
return 0;
}
D_DEBUG(DB_EPC, "hlc "DF_X64" epoch "DF_X64"/"DF_X64" agg max "DF_X64"\n",
hlc, epoch_max, epoch_min, cont->sc_aggregation_max);
if (cont->sc_snapshots_nr + 1 < MAX_SNAPSHOT_LOCAL) {
snapshots = snapshots_local;
} else {
D_ALLOC(snapshots, (cont->sc_snapshots_nr + 1) *
sizeof(daos_epoch_t));
if (snapshots == NULL)
return -DER_NOMEM;
}
if (cont->sc_pool->spc_rebuild_fence != 0) {
uint64_t rebuild_fence = cont->sc_pool->spc_rebuild_fence;
int j;
int insert_idx;
/* insert rebuild_fetch into the snapshot list */
D_DEBUG(DB_EPC, "rebuild fence "DF_X64"\n", rebuild_fence);
for (j = 0, insert_idx = 0; j < cont->sc_snapshots_nr; j++) {
if (cont->sc_snapshots[j] < rebuild_fence) {
snapshots[j] = cont->sc_snapshots[j];
insert_idx++;
} else {
snapshots[j + 1] = cont->sc_snapshots[j];
}
}
snapshots[insert_idx] = rebuild_fence;
snapshots_nr = cont->sc_snapshots_nr + 1;
} else {
/* Since sc_snapshots might be freed by other ULT, let's
* always copy here.
*/
snapshots_nr = cont->sc_snapshots_nr;
if (snapshots_nr > 0)
memcpy(snapshots, cont->sc_snapshots,
snapshots_nr * sizeof(daos_epoch_t));
}
/* Find highest snapshot less than last aggregated epoch. */
for (i = 0; i < snapshots_nr && snapshots[i] < epoch_min; ++i)
;
if (i == 0)
epoch_range.epr_lo = 0;
else
epoch_range.epr_lo = snapshots[i - 1] + 1;
if (epoch_range.epr_lo >= epoch_max)
D_GOTO(free, rc = 0);
D_DEBUG(DB_EPC, DF_CONT"[%d]: MIN: "DF_X64"; HLC: "DF_X64"\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid),
tgt_id, epoch_min, hlc);
for ( ; i < snapshots_nr && snapshots[i] < epoch_max; ++i) {
epoch_range.epr_hi = snapshots[i];
D_DEBUG(DB_EPC, DF_CONT"[%d]: Aggregating {"DF_X64" -> "
DF_X64"}\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid),
tgt_id, epoch_range.epr_lo, epoch_range.epr_hi);
flags |= VOS_AGG_FL_FORCE_MERGE;
rc = agg_cb(cont, &epoch_range, flags, param);
if (rc)
D_GOTO(free, rc);
epoch_range.epr_lo = epoch_range.epr_hi + 1;
}
D_ASSERT(epoch_range.epr_lo <= epoch_max);
if (epoch_range.epr_lo == epoch_max)
goto out;
epoch_range.epr_hi = epoch_max;
D_DEBUG(DB_EPC, DF_CONT"[%d]: Aggregating {"DF_X64" -> "DF_X64"}\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid),
tgt_id, epoch_range.epr_lo, epoch_range.epr_hi);
if (dss_xstream_is_busy())
flags &= ~VOS_AGG_FL_FORCE_MERGE;
rc = agg_cb(cont, &epoch_range, flags, param);
out:
if (rc == 0 && epoch_min == 0)
param->ap_full_scan_hlc = hlc;
D_DEBUG(DB_EPC, DF_CONT "[%d]: Aggregating finished. %d\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid), tgt_id, rc);
free:
if (snapshots != NULL && snapshots != snapshots_local)
D_FREE(snapshots);
return rc;
}
void
cont_aggregate_interval(struct ds_cont_child *cont, cont_aggregate_cb_t cb,
struct agg_param *param)
{
struct dss_module_info *dmi = dss_get_module_info();
struct sched_request *req = cont2req(cont, param->ap_vos_agg);
int rc = 0;
D_DEBUG(DB_EPC, DF_CONT"[%d]: Aggregation ULT started\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid),
dmi->dmi_tgt_id);
if (req == NULL)
goto out;
while (!dss_ult_exiting(req)) {
/*
* Sleep 2 seconds before next round when:
* - Aggregation isn't runnable yet, or;
* - Last round of aggregation failed, or;
* - There is no space pressure;
*/
uint64_t msecs = 2000;
if (!cont_aggregate_runnable(cont, req, param->ap_vos_agg))
goto next;
rc = cont_child_aggregate(cont, cb, param);
if (rc == -DER_SHUTDOWN) {
break; /* pool destroyed */
} else if (rc < 0) {
DL_CDEBUG(rc == -DER_BUSY, DB_EPC, DLOG_ERR, rc,
DF_CONT ": VOS aggregate failed",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid));
} else if (sched_req_space_check(req) != SCHED_SPACE_PRESS_NONE) {
/* Don't sleep too long when there is space pressure */
msecs = 2ULL * 100;
}
next:
if (dss_ult_exiting(req))
break;
sched_req_sleep(req, msecs);
}
out:
D_DEBUG(DB_EPC, DF_CONT"[%d]: Aggregation ULT stopped\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid),
dmi->dmi_tgt_id);
}
static int
cont_vos_aggregate_cb(struct ds_cont_child *cont, daos_epoch_range_t *epr,
uint32_t flags, struct agg_param *param)
{
int rc;
rc = vos_aggregate(cont->sc_hdl, epr, agg_rate_ctl, param, flags);
/* Suppress csum error and continue on other epoch ranges */
if (rc == -DER_CSUM)
rc = 0;
/* Wake up GC ULT */
sched_req_wakeup(cont->sc_pool->spc_gc_req);
return rc;
}
static void
cont_agg_ult(void *arg)
{
struct ds_cont_child *cont = arg;
struct agg_param param = { 0 };
D_DEBUG(DB_EPC, "start VOS aggregation "DF_UUID"\n",
DP_UUID(cont->sc_uuid));
param.ap_cont = cont;
param.ap_vos_agg = true;
cont_aggregate_interval(cont, cont_vos_aggregate_cb, ¶m);
}
static void
cont_ec_agg_ult(void *arg)
{
struct ds_cont_child *cont = arg;
D_DEBUG(DB_EPC, "start EC aggregation "DF_UUID"\n",
DP_UUID(cont->sc_uuid));
ds_obj_ec_aggregate(arg);
}
static void
cont_stop_agg(struct ds_cont_child *cont)
{
if (cont->sc_ec_agg_req != NULL) {
D_DEBUG(DB_EPC, DF_CONT"[%d]: Stopping EC aggregation ULT\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid),
dss_get_module_info()->dmi_tgt_id);
sched_req_wait(cont->sc_ec_agg_req, true);
sched_req_put(cont->sc_ec_agg_req);
cont->sc_ec_agg_req = NULL;
}
if (cont->sc_agg_req != NULL) {
D_DEBUG(DB_EPC, DF_CONT"[%d]: Stopping VOS aggregation ULT\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid),
dss_get_module_info()->dmi_tgt_id);
sched_req_wait(cont->sc_agg_req, true);
sched_req_put(cont->sc_agg_req);
cont->sc_agg_req = NULL;
}
}
static int
cont_start_agg(struct ds_cont_child *cont)
{
struct dss_module_info *dmi = dss_get_module_info();
struct sched_req_attr attr;
sched_req_attr_init(&attr, SCHED_REQ_GC, &cont->sc_pool->spc_uuid);
if (likely(!ec_agg_disabled)) {
D_ASSERT(cont->sc_ec_agg_req == NULL);
cont->sc_ec_agg_req = sched_create_ult(&attr, cont_ec_agg_ult, cont,
DSS_DEEP_STACK_SZ);
if (cont->sc_ec_agg_req == NULL) {
D_ERROR(DF_CONT"[%d]: Failed to create EC aggregation ULT.\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid), dmi->dmi_tgt_id);
return -DER_NOMEM;
}
}
D_ASSERT(cont->sc_agg_req == NULL);
cont->sc_agg_req = sched_create_ult(&attr, cont_agg_ult, cont, DSS_DEEP_STACK_SZ);
if (cont->sc_agg_req == NULL) {
D_ERROR(DF_CONT"[%d]: Failed to create VOS aggregation ULT.\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid), dmi->dmi_tgt_id);
cont_stop_agg(cont);
return -DER_NOMEM;
}
return 0;
}
/* ds_cont_child *******************************************************/
static inline struct ds_cont_child *
cont_child_obj(struct daos_llink *llink)
{
return container_of(llink, struct ds_cont_child, sc_list);
}
static int
cont_child_alloc_ref(void *co_uuid, unsigned int ksize, void *po_uuid,
struct daos_llink **link)
{
struct ds_cont_child *cont;
int rc;
D_ASSERT(po_uuid != NULL);
D_DEBUG(DB_MD, DF_CONT": opening\n", DP_CONT(po_uuid, co_uuid));
D_ALLOC_PTR(cont);
if (cont == NULL)
return -DER_NOMEM;
rc = ABT_mutex_create(&cont->sc_mutex);
if (rc != ABT_SUCCESS) {
rc = dss_abterr2der(rc);
goto out;
}
rc = ABT_cond_create(&cont->sc_dtx_resync_cond);
if (rc != ABT_SUCCESS) {
rc = dss_abterr2der(rc);
goto out_mutex;
}
rc = ABT_cond_create(&cont->sc_scrub_cond);
if (rc != ABT_SUCCESS) {
rc = dss_abterr2der(rc);
goto out_resync_cond;
}
rc = ABT_cond_create(&cont->sc_rebuild_cond);
if (rc != ABT_SUCCESS) {
rc = dss_abterr2der(rc);
goto out_scrub_cond;
}
cont->sc_pool = ds_pool_child_lookup(po_uuid);
if (cont->sc_pool == NULL) {
rc = -DER_NO_HDL;
goto out_rebuild_cond;
}
rc = vos_cont_open(cont->sc_pool->spc_hdl, co_uuid, &cont->sc_hdl);
if (rc != 0)
goto out_pool;
/* sc_uuid, sc_pool_uuid contiguous in memory within the structure */
D_CASSERT(offsetof(struct ds_cont_child, sc_uuid) + sizeof(uuid_t) ==
offsetof(struct ds_cont_child, sc_pool_uuid));
uuid_copy(cont->sc_uuid, co_uuid);
uuid_copy(cont->sc_pool_uuid, po_uuid);
/* prevent aggregation till snapshot iv refreshed */
cont->sc_aggregation_max = 0;
cont->sc_snapshots_nr = 0;
cont->sc_snapshots = NULL;
cont->sc_dtx_cos_hdl = DAOS_HDL_INVAL;
D_INIT_LIST_HEAD(&cont->sc_link);
D_INIT_LIST_HEAD(&cont->sc_open_hdls);
*link = &cont->sc_list;
return 0;
out_pool:
ds_pool_child_put(cont->sc_pool);
out_rebuild_cond:
ABT_cond_free(&cont->sc_rebuild_cond);
out_scrub_cond:
ABT_cond_free(&cont->sc_scrub_cond);
out_resync_cond:
ABT_cond_free(&cont->sc_dtx_resync_cond);
out_mutex:
ABT_mutex_free(&cont->sc_mutex);
out:
D_FREE(cont);
return rc;
}
static void
cont_child_free_ref(struct daos_llink *llink)
{
struct ds_cont_child *cont = cont_child_obj(llink);
D_ASSERT(cont->sc_pool != NULL);
D_ASSERT(daos_handle_is_valid(cont->sc_hdl));
D_ASSERT(d_list_empty(&cont->sc_open_hdls));
D_DEBUG(DB_MD, DF_CONT": freeing\n",
DP_CONT(cont->sc_pool->spc_uuid, cont->sc_uuid));
vos_cont_close(cont->sc_hdl);
ds_pool_child_put(cont->sc_pool);
daos_csummer_destroy(&cont->sc_csummer);
D_FREE(cont->sc_snapshots);
ABT_cond_free(&cont->sc_dtx_resync_cond);
ABT_cond_free(&cont->sc_scrub_cond);
ABT_cond_free(&cont->sc_rebuild_cond);
ABT_mutex_free(&cont->sc_mutex);
D_FREE(cont);
}
static bool
cont_child_cmp_keys(const void *key, unsigned int ksize,
struct daos_llink *llink)
{
const void *key_cuuid = key;
const void *key_puuid = (const char *)key + sizeof(uuid_t);
struct ds_cont_child *cont = cont_child_obj(llink);
/* Key is a concatenation of cont UUID followed by pool UUID */
D_ASSERTF(ksize == (2 * sizeof(uuid_t)), "%u\n", ksize);
return ((uuid_compare(key_cuuid, cont->sc_uuid) == 0) &&
(uuid_compare(key_puuid, cont->sc_pool_uuid) == 0));
}
static uint32_t
cont_child_rec_hash(struct daos_llink *llink)
{
struct ds_cont_child *cont = cont_child_obj(llink);
/* Key is a concatenation of cont/pool UUIDs.
* i.e., ds_cont-child contiguous members sc_uuid + sc_pool_uuid
*/
return d_hash_string_u32((const char *)cont->sc_uuid,
2 * sizeof(uuid_t));
}
static struct daos_llink_ops cont_child_cache_ops = {
.lop_alloc_ref = cont_child_alloc_ref,
.lop_free_ref = cont_child_free_ref,
.lop_cmp_keys = cont_child_cmp_keys,
.lop_rec_hash = cont_child_rec_hash,
};
int
ds_cont_child_cache_create(struct daos_lru_cache **cache)
{
/*
* ds_cont_child isn't cached in LRU, it'll be removed from hash table
* then freed on last user putting reference count.
*/
return daos_lru_cache_create(-1 /* no lru cache */, D_HASH_FT_NOLOCK,
&cont_child_cache_ops, cache);
}
void
ds_cont_child_cache_destroy(struct daos_lru_cache *cache)
{
daos_lru_cache_destroy(cache);
}
static void
cont_child_put(struct daos_lru_cache *cache, struct ds_cont_child *cont)
{
daos_lru_ref_release(cache, &cont->sc_list);
}
/*
* If create == false, then this is assumed to be a pure lookup. In this case,
* -DER_NONEXIST is returned if the ds_cont_child object does not exist.
*/
static int
cont_child_lookup(struct daos_lru_cache *cache, const uuid_t co_uuid,
const uuid_t po_uuid, bool create,
struct ds_cont_child **cont)
{
struct daos_llink *llink;
uuid_t key[2]; /* HT key is cuuid+puuid */
int rc;
uuid_copy(key[0], co_uuid);
uuid_copy(key[1], po_uuid);
rc = daos_lru_ref_hold(cache, (void *)key, sizeof(key),
create ? (void *)po_uuid : NULL, &llink);
if (rc != 0) {
if (rc == -DER_NONEXIST)
D_DEBUG(DB_MD, DF_CONT": failed to lookup%s "
"container: "DF_RC"\n",
DP_CONT(po_uuid, co_uuid),
po_uuid == NULL ? "" : "/create", DP_RC(rc));
else
D_ERROR(DF_CONT": failed to lookup%s container: "
""DF_RC"\n", DP_CONT(po_uuid, co_uuid),
po_uuid == NULL ? "" : "/create", DP_RC(rc));
return rc;
}
*cont = cont_child_obj(llink);
return 0;
}
static inline bool
cont_child_started(struct ds_cont_child *cont_child)
{
/* Started container is linked in spc_cont_list */
return !d_list_empty(&cont_child->sc_link);
}
static int cont_close_hdl(uuid_t cont_hdl_uuid);
static void
cont_child_stop(struct ds_cont_child *cont_child)
{
struct ds_cont_hdl *hdl;
while ((hdl = d_list_pop_entry(&cont_child->sc_open_hdls,
struct ds_cont_hdl, sch_link)) != NULL) {
D_DEBUG(DB_MD, "Force closing container open handle "DF_UUID"/"DF_UUID"\n",
DP_UUID(cont_child->sc_uuid), DP_UUID(hdl->sch_uuid));
cont_close_hdl(hdl->sch_uuid);
}
/* Some ds_cont_child will only created by ds_cont_child_lookup().
* never be started at all
*/
cont_child->sc_stopping = 1;
if (cont_child_started(cont_child)) {
D_DEBUG(DB_MD, DF_CONT"[%d]: Stopping container\n",
DP_CONT(cont_child->sc_pool->spc_uuid,
cont_child->sc_uuid),
dss_get_module_info()->dmi_tgt_id);
d_list_del_init(&cont_child->sc_link);
dtx_cont_deregister(cont_child);
D_ASSERT(cont_child->sc_dtx_registered == 0);
/* cont_stop_agg() may yield */
cont_stop_agg(cont_child);
ds_cont_child_put(cont_child);
}
}
void
ds_cont_child_stop_all(struct ds_pool_child *pool_child)
{
d_list_t *cont_list;
struct ds_cont_child *cont_child;
D_DEBUG(DB_MD, DF_UUID"[%d]: Stopping all containers\n",
DP_UUID(pool_child->spc_uuid),
dss_get_module_info()->dmi_tgt_id);
cont_list = &pool_child->spc_cont_list;
while (!d_list_empty(cont_list)) {
cont_child = d_list_entry(cont_list->next,
struct ds_cont_child, sc_link);
cont_child_stop(cont_child);
}
}
void
ds_cont_child_reset_ec_agg_eph_all(struct ds_pool_child *pool_child)
{
struct ds_cont_child *cont_child;
D_DEBUG(DB_MD, DF_UUID"[%d]: reset all containers EC aggregate epoch.\n",
DP_UUID(pool_child->spc_uuid), dss_get_module_info()->dmi_tgt_id);
d_list_for_each_entry(cont_child, &pool_child->spc_cont_list, sc_link)
cont_child->sc_ec_agg_eph = cont_child->sc_ec_agg_eph_boundary;
}
static int
cont_child_start(struct ds_pool_child *pool_child, const uuid_t co_uuid,
bool *started, struct ds_cont_child **cont_out)
{
struct dsm_tls *tls = dsm_tls_get();
struct ds_cont_child *cont_child;
int tgt_id = dss_get_module_info()->dmi_tgt_id;
int rc;
D_DEBUG(DB_MD, DF_CONT"[%d]: Starting container\n",
DP_CONT(pool_child->spc_uuid, co_uuid), tgt_id);
rc = cont_child_lookup(tls->dt_cont_cache, co_uuid,
pool_child->spc_uuid, true /* create */,
&cont_child);
if (rc) {
DL_CDEBUG(rc != -DER_NONEXIST, DLOG_ERR, DB_MD, rc,
DF_CONT "[%d]: Load container error",
DP_CONT(pool_child->spc_uuid, co_uuid), tgt_id);
return rc;
}
/*
* The container is in stopping because:
* 1. Container is going to be destroyed, or;
* 2. Pool is going to be destroyed, or;
* 3. Pool service is going to be stopped;
*/
if (cont_child->sc_stopping) {
D_ERROR(DF_CONT"[%d]: Container is in stopping\n",
DP_CONT(pool_child->spc_uuid, co_uuid), tgt_id);
rc = -DER_SHUTDOWN;
} else if (!cont_child_started(cont_child)) {
rc = cont_start_agg(cont_child);
if (rc != 0)
goto out;
rc = dtx_cont_register(cont_child);
if (rc != 0) {
cont_stop_agg(cont_child);
goto out;
}
d_list_add_tail(&cont_child->sc_link, &pool_child->spc_cont_list);
ds_cont_child_get(cont_child);
if (started)
*started = true;
}
if (!rc && cont_out != NULL) {
*cont_out = cont_child;
ds_cont_child_get(cont_child);
}
out:
/* Put the ref from cont_child_lookup() */
ds_cont_child_put(cont_child);
return rc;
}
static int
cont_child_start_cb(daos_handle_t ih, vos_iter_entry_t *entry,
vos_iter_type_t type, vos_iter_param_t *iter_param,
void *data, unsigned *acts)
{
struct ds_pool_child *pool_child = data;
return cont_child_start(pool_child, entry->ie_couuid, NULL, NULL);
}
int
ds_cont_child_start_all(struct ds_pool_child *pool_child)
{
vos_iter_param_t iter_param = { 0 };
struct vos_iter_anchors anchors = { 0 };
int rc;
D_DEBUG(DB_MD, DF_UUID"[%d]: Starting all containers\n",
DP_UUID(pool_child->spc_uuid),
dss_get_module_info()->dmi_tgt_id);
iter_param.ip_hdl = pool_child->spc_hdl;
/* The quantity of container is small, no need to yield */
rc = vos_iterate(&iter_param, VOS_ITER_COUUID, false, &anchors,
cont_child_start_cb, NULL, (void *)pool_child, NULL);
return rc;
}
/* ds_cont_hdl ****************************************************************/
static inline struct ds_cont_hdl *
cont_hdl_obj(d_list_t *rlink)
{
return container_of(rlink, struct ds_cont_hdl, sch_entry);
}
static bool
cont_hdl_key_cmp(struct d_hash_table *htable, d_list_t *rlink,
const void *key, unsigned int ksize)
{
struct ds_cont_hdl *hdl = cont_hdl_obj(rlink);
D_ASSERTF(ksize == sizeof(uuid_t), "%u\n", ksize);
return uuid_compare(hdl->sch_uuid, key) == 0;
}
static void
cont_hdl_rec_addref(struct d_hash_table *htable, d_list_t *rlink)
{
cont_hdl_obj(rlink)->sch_ref++;
}
static bool
cont_hdl_rec_decref(struct d_hash_table *htable, d_list_t *rlink)
{
struct ds_cont_hdl *hdl = cont_hdl_obj(rlink);
hdl->sch_ref--;
return hdl->sch_ref == 0;
}
static void
cont_hdl_rec_free(struct d_hash_table *htable, d_list_t *rlink)
{
struct ds_cont_hdl *hdl = cont_hdl_obj(rlink);
struct dsm_tls *tls = dsm_tls_get();
D_ASSERT(d_hash_rec_unlinked(&hdl->sch_entry));
D_ASSERTF(hdl->sch_ref == 0, "%d\n", hdl->sch_ref);
D_ASSERT(d_list_empty(&hdl->sch_link));
D_DEBUG(DB_MD, "freeing "DF_UUID"\n", DP_UUID(hdl->sch_uuid));
/* The sch_cont is NULL for global rebuild cont handle */
if (hdl->sch_cont != NULL) {
D_DEBUG(DB_MD, DF_CONT": freeing\n",
DP_CONT(hdl->sch_cont->sc_pool->spc_uuid,
hdl->sch_cont->sc_uuid));