-
Notifications
You must be signed in to change notification settings - Fork 344
Expand file tree
/
Copy pathsrv_obj.c
More file actions
6049 lines (5179 loc) · 168 KB
/
srv_obj.c
File metadata and controls
6049 lines (5179 loc) · 168 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 2016-2024 Intel Corporation.
* (C) Copyright 2025 Google LLC
* (C) Copyright 2025-2026 Hewlett Packard Enterprise Development LP
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
/**
* object server operations
*
* This file contains the server API methods and the RPC handlers that are both
* related to object.
*/
#define D_LOGFAC DD_FAC(object)
#include <uuid/uuid.h>
#include <abt.h>
#include <daos/rpc.h>
#include <daos/cont_props.h>
#include <daos_srv/pool.h>
#include <daos_srv/rebuild.h>
#include <daos_srv/container.h>
#include <daos_srv/vos.h>
#include <daos_srv/bio.h>
#include <daos_srv/daos_engine.h>
#include <daos_srv/dtx_srv.h>
#include <daos_srv/security.h>
#include <daos/checksum.h>
#include <daos_srv/srv_csum.h>
#include "obj_rpc.h"
#include "srv_internal.h"
static int
obj_verify_bio_csum(daos_obj_id_t oid, daos_iod_t *iods,
struct dcs_iod_csums *iod_csums, struct bio_desc *biod,
struct daos_csummer *csummer, uint32_t iods_nr);
static int
obj_ioc2ec_cs(struct obj_io_context *ioc)
{
return obj_ec_cell_rec_nr(&ioc->ioc_oca);
}
static int
obj_ioc2ec_ss(struct obj_io_context *ioc)
{
return obj_ec_stripe_rec_nr(&ioc->ioc_oca);
}
/* For single RDG based DTX, parse DTX participants information
* from the client given dispatch targets information that does
* NOT contains the original leader information.
*/
static int
obj_gen_dtx_mbs(uint32_t flags, uint32_t *tgt_cnt, struct daos_shard_tgt **p_tgts,
struct dtx_memberships **p_mbs)
{
struct daos_shard_tgt *tgts = *p_tgts;
struct dtx_memberships *mbs = NULL;
size_t size;
int i;
int j;
if (*tgt_cnt == 0)
return 0;
D_ASSERT(tgts != NULL);
if (!(flags & ORF_CONTAIN_LEADER)) {
D_ERROR("Miss DTX leader information, flags %x\n", flags);
return -DER_PROTO;
}
if (*tgt_cnt == 1) {
*tgt_cnt = 0;
*p_tgts = NULL;
goto out;
}
size = sizeof(struct dtx_daos_target) * *tgt_cnt;
D_ALLOC(mbs, sizeof(*mbs) + size);
if (mbs == NULL)
return -DER_NOMEM;
for (i = 0, j = 0; i < *tgt_cnt; i++) {
if (tgts[i].st_rank == DAOS_TGT_IGNORE)
continue;
mbs->dm_tgts[j++].ddt_id = tgts[i].st_tgt_id;
}
D_ASSERT(j > 0);
if (j == 1) {
D_FREE(mbs);
*tgt_cnt = 0;
*p_tgts = NULL;
goto out;
}
mbs->dm_tgt_cnt = j;
mbs->dm_grp_cnt = 1;
mbs->dm_data_size = size;
mbs->dm_flags = DMF_CONTAIN_LEADER;
--(*tgt_cnt);
*p_tgts = ++tgts;
if (!(flags & ORF_EC))
mbs->dm_flags |= DMF_SRDG_REP;
out:
*p_mbs = mbs;
return 0;
}
/**
* After bulk finish, let's send reply, then release the resource.
*/
static int
obj_rw_complete(crt_rpc_t *rpc, struct obj_io_context *ioc,
daos_handle_t ioh, int status, struct dtx_handle *dth)
{
struct obj_rw_in *orwi = crt_req_get(rpc);
int rc;
if (daos_handle_is_valid(ioh)) {
bool update = obj_rpc_is_update(rpc);
if (update) {
uint64_t time;
if (status == 0)
status = dtx_sub_init(dth, &orwi->orw_oid,
orwi->orw_dkey_hash);
time = daos_get_ntime();
rc = vos_update_end(ioh, ioc->ioc_map_ver,
&orwi->orw_dkey, status,
&ioc->ioc_io_size, dth);
if (rc == 0)
obj_update_latency(ioc->ioc_opc, VOS_LATENCY,
daos_get_ntime() - time, ioc->ioc_io_size);
} else {
rc = vos_fetch_end(ioh, &ioc->ioc_io_size, status);
}
if (rc != 0) {
if (rc == -DER_VOS_PARTIAL_UPDATE)
rc = -DER_NO_PERM;
DL_CDEBUG(rc == -DER_REC2BIG || rc == -DER_INPROGRESS ||
rc == -DER_TX_RESTART || rc == -DER_EXIST ||
rc == -DER_NONEXIST || rc == -DER_ALREADY ||
rc == -DER_CHKPT_BUSY,
DLOG_DBG, DLOG_ERR, rc, DF_UOID " %s end failed",
DP_UOID(orwi->orw_oid), update ? "Update" : "Fetch");
if (status == 0)
status = rc;
}
}
return status;
}
static void
obj_rw_reply(crt_rpc_t *rpc, int status, uint64_t epoch, bool release_input,
struct obj_io_context *ioc)
{
struct obj_rw_out *orwo = crt_reply_get(rpc);
int rc;
int i;
obj_reply_set_status(rpc, status);
obj_reply_map_version_set(rpc, ioc->ioc_map_ver);
if (DAOS_FAIL_CHECK(DAOS_DTX_START_EPOCH)) {
/* Return an stale epoch for test. */
orwo->orw_epoch = dss_get_start_epoch() -
d_hlc_epsilon_get() * 3;
} else {
/* orwo->orw_epoch possibly updated in obj_ec_recov_need_try_again(), reply
* the max so client can fetch from that epoch.
*/
orwo->orw_epoch = max(epoch, orwo->orw_epoch);
}
D_DEBUG(DB_IO, "rpc %p opc %d send reply, pmv %d, epoch "DF_X64
", status %d\n", rpc, opc_get(rpc->cr_opc),
ioc->ioc_map_ver, orwo->orw_epoch, status);
if (!ioc->ioc_lost_reply) {
if (release_input)
rc = crt_reply_send_input_free(rpc);
else
rc = crt_reply_send(rpc);
if (rc != 0)
D_ERROR("send reply failed: "DF_RC"\n", DP_RC(rc));
} else {
D_WARN("lost reply rpc %p\n", rpc);
}
if (obj_rpc_is_fetch(rpc)) {
if (orwo->orw_iod_sizes.ca_arrays != NULL) {
D_FREE(orwo->orw_iod_sizes.ca_arrays);
orwo->orw_iod_sizes.ca_count = 0;
}
if (orwo->orw_nrs.ca_arrays != NULL) {
D_FREE(orwo->orw_nrs.ca_arrays);
orwo->orw_nrs.ca_count = 0;
}
if (orwo->orw_iod_csums.ca_arrays != NULL) {
D_FREE(orwo->orw_iod_csums.ca_arrays);
orwo->orw_iod_csums.ca_count = 0;
}
if (orwo->orw_maps.ca_arrays != NULL) {
ds_iom_free(&orwo->orw_maps.ca_arrays, orwo->orw_maps.ca_count);
orwo->orw_maps.ca_count = 0;
}
daos_recx_ep_list_free(orwo->orw_rels.ca_arrays,
orwo->orw_rels.ca_count);
if (ioc->ioc_free_sgls) {
struct obj_rw_in *orw = crt_req_get(rpc);
d_sg_list_t *sgls = orwo->orw_sgls.ca_arrays;
int j;
for (i = 0; i < orw->orw_nr; i++)
for (j = 0; j < sgls[i].sg_nr; j++)
D_FREE(sgls[i].sg_iovs[j].iov_buf);
}
}
}
static int
obj_bulk_comp_cb(const struct crt_bulk_cb_info *cb_info)
{
struct obj_bulk_args *arg;
struct crt_bulk_desc *bulk_desc;
crt_rpc_t *rpc;
if (cb_info->bci_rc != 0)
D_ERROR("bulk transfer failed: %d\n", cb_info->bci_rc);
bulk_desc = cb_info->bci_bulk_desc;
rpc = bulk_desc->bd_rpc;
arg = (struct obj_bulk_args *)cb_info->bci_arg;
/**
* Note: only one thread will access arg.result, so
* it should be safe here.
**/
if (arg->result == 0)
arg->result = cb_info->bci_rc;
D_ASSERT(arg->bulks_inflight > 0);
arg->bulks_inflight--;
if (arg->bulks_inflight == 0)
ABT_eventual_set(arg->eventual, &arg->result,
sizeof(arg->result));
crt_req_decref(rpc);
return cb_info->bci_rc;
}
static inline int
bulk_cp(const struct crt_bulk_cb_info *cb_info)
{
struct crt_bulk_desc *bulk_desc;
bulk_desc = cb_info->bci_bulk_desc;
D_ASSERT(bulk_desc->bd_local_hdl != CRT_BULK_NULL);
crt_bulk_free(bulk_desc->bd_local_hdl);
bulk_desc->bd_local_hdl = CRT_BULK_NULL;
return obj_bulk_comp_cb(cb_info);
}
static inline int
cached_bulk_cp(const struct crt_bulk_cb_info *cb_info)
{
return obj_bulk_comp_cb(cb_info);
}
/**
* Simulate bulk transfer by memcpy, all data are actually dropped.
*/
static void
obj_bulk_bypass(d_sg_list_t *sgl, crt_bulk_op_t bulk_op)
{
static const int dummy_buf_len = 4096;
static char *dummy_buf;
int i;
if (!dummy_buf) {
D_ALLOC(dummy_buf, dummy_buf_len);
if (!dummy_buf)
return; /* ignore error */
}
for (i = 0; i < sgl->sg_nr_out; i++) {
char *buf;
int total, nob;
if (sgl->sg_iovs[i].iov_buf == NULL ||
sgl->sg_iovs[i].iov_len == 0)
continue;
buf = sgl->sg_iovs[i].iov_buf;
total = sgl->sg_iovs[i].iov_len;
while (total != 0) {
nob = min(dummy_buf_len, total);
if (bulk_op == CRT_BULK_PUT)
memcpy(dummy_buf, buf, nob);
else
memcpy(buf, dummy_buf, nob);
total -= nob;
buf += nob;
}
}
}
#define MAX_BULK_IOVS 1024
#define BULK_DELAY_MAX 3000
#define BULK_DELAY_STEP 1000
static int
bulk_transfer_sgl(daos_handle_t ioh, crt_rpc_t *rpc, crt_bulk_t remote_bulk,
off_t remote_off, crt_bulk_op_t bulk_op, bool bulk_bind,
d_sg_list_t *sgl, int sgl_idx, struct obj_bulk_args *p_arg)
{
struct crt_bulk_desc bulk_desc;
crt_bulk_perm_t bulk_perm;
crt_bulk_opid_t bulk_opid;
crt_bulk_t local_bulk;
unsigned int local_off;
unsigned int iov_idx = 0;
size_t remote_size;
int rc, bulk_iovs = 0;
if (remote_bulk == NULL) {
D_ERROR("Remote bulk is NULL\n");
return -DER_INVAL;
}
rc = crt_bulk_get_len(remote_bulk, &remote_size);
if (rc) {
D_ERROR("Failed to get remote bulk size "DF_RC"\n", DP_RC(rc));
return rc;
}
if (remote_off >= remote_size) {
rc = -DER_OVERFLOW;
D_ERROR("remote_bulk_off %zu >= remote_bulk_size %zu, "DF_RC"\n",
remote_off, remote_size, DP_RC(rc));
return rc;
}
if (daos_io_bypass & IOBP_SRV_BULK) {
obj_bulk_bypass(sgl, bulk_op);
return 0;
}
bulk_perm = bulk_op == CRT_BULK_PUT ? CRT_BULK_RO : CRT_BULK_RW;
while (iov_idx < sgl->sg_nr_out) {
d_sg_list_t sgl_sent;
size_t length = 0;
unsigned int start;
uint32_t delay_tot = 0;
uint32_t delay_cur;
bool cached_bulk = false;
/*
* Skip bulk transfer over IOVs with NULL buffer address,
* these NULL IOVs are 'holes' or deduped records.
*/
while (iov_idx < sgl->sg_nr_out &&
sgl->sg_iovs[iov_idx].iov_buf == NULL) {
remote_off += sgl->sg_iovs[iov_idx].iov_len;
iov_idx++;
}
if (iov_idx == sgl->sg_nr_out)
break;
if (remote_off >= remote_size) {
rc = -DER_OVERFLOW;
D_ERROR("Remote bulk is used up. off:%zu, size:%zu, "DF_RC"\n",
remote_off, remote_size, DP_RC(rc));
break;
}
local_bulk = vos_iod_bulk_at(ioh, sgl_idx, iov_idx, &local_off);
if (local_bulk != NULL) {
unsigned int tmp_off;
length = sgl->sg_iovs[iov_idx].iov_len;
iov_idx++;
cached_bulk = true;
/* Check if following IOVs are contiguous and from same bulk handle */
while (iov_idx < sgl->sg_nr_out &&
sgl->sg_iovs[iov_idx].iov_buf != NULL &&
vos_iod_bulk_at(ioh, sgl_idx, iov_idx, &tmp_off) == local_bulk &&
tmp_off == local_off) {
length += sgl->sg_iovs[iov_idx].iov_len;
iov_idx++;
};
bulk_iovs += 1;
} else {
start = iov_idx;
sgl_sent.sg_iovs = &sgl->sg_iovs[start];
/*
* For the IOVs not using cached bulk, creates bulk
* handle on-the-fly.
*/
while (iov_idx < sgl->sg_nr_out &&
sgl->sg_iovs[iov_idx].iov_buf != NULL &&
vos_iod_bulk_at(ioh, sgl_idx, iov_idx,
&local_off) == NULL) {
length += sgl->sg_iovs[iov_idx].iov_len;
iov_idx++;
/* Don't create bulk handle with too many IOVs */
if ((iov_idx - start) >= MAX_BULK_IOVS)
break;
};
D_ASSERT(iov_idx > start);
local_off = 0;
sgl_sent.sg_nr = sgl_sent.sg_nr_out = iov_idx - start;
bulk_iovs += sgl_sent.sg_nr;
again:
rc = crt_bulk_create(rpc->cr_ctx, &sgl_sent, bulk_perm,
&local_bulk);
if (rc == -DER_NOMEM) {
if (delay_tot >= BULK_DELAY_MAX) {
D_ERROR("Too many in-flight bulk handles on %d:" DF_RC "\n",
sgl_idx, DP_RC(rc));
break;
}
/*
* If there are too many in-flight bulk handles, then current
* crt_bulk_create() may hit -DER_NOMEM failure. Let it sleep
* for a while (at most 3 seconds) to give cart progress some
* chance to complete some in-flight bulk transfers.
*/
delay_cur = BULK_DELAY_MAX - delay_tot;
if (delay_cur >= BULK_DELAY_STEP)
delay_cur = d_rand() % BULK_DELAY_STEP + 1;
dss_sleep(delay_cur);
delay_tot += delay_cur;
bulk_iovs = 0;
goto again;
}
if (rc != 0) {
D_ERROR("crt_bulk_create %d error " DF_RC "\n", sgl_idx, DP_RC(rc));
break;
}
D_ASSERT(local_bulk != NULL);
}
D_ASSERT(remote_size > remote_off);
if (length > (remote_size - remote_off)) {
rc = -DER_OVERFLOW;
D_ERROR("Remote bulk isn't large enough. local_sz:%zu, remote_sz:%zu, "
"remote_off:%zu, "DF_RC"\n", length, remote_size, remote_off,
DP_RC(rc));
break;
}
crt_req_addref(rpc);
bulk_desc.bd_rpc = rpc;
bulk_desc.bd_bulk_op = bulk_op;
bulk_desc.bd_remote_hdl = remote_bulk;
bulk_desc.bd_local_hdl = local_bulk;
bulk_desc.bd_len = length;
bulk_desc.bd_remote_off = remote_off;
bulk_desc.bd_local_off = local_off;
p_arg->bulk_size += length;
p_arg->bulks_inflight++;
if (bulk_bind)
rc = crt_bulk_bind_transfer(&bulk_desc,
cached_bulk ? cached_bulk_cp : bulk_cp, p_arg,
&bulk_opid);
else
rc = crt_bulk_transfer(&bulk_desc,
cached_bulk ? cached_bulk_cp : bulk_cp, p_arg,
&bulk_opid);
if (rc < 0) {
D_ERROR("crt_bulk_transfer %d error " DF_RC "\n", sgl_idx, DP_RC(rc));
p_arg->bulks_inflight--;
if (!cached_bulk)
crt_bulk_free(local_bulk);
crt_req_decref(rpc);
break;
}
remote_off += length;
/* Give cart progress a chance to complete some in-flight bulk transfers */
if (bulk_iovs >= MAX_BULK_IOVS) {
bulk_iovs = 0;
ABT_thread_yield();
}
}
return rc;
}
/* bypass bulk rma for single value's degraded fetch */
#define OBJ_BULK_OFFSET_SKIP ((uint64_t)-1)
int
obj_bulk_transfer(crt_rpc_t *rpc, crt_bulk_op_t bulk_op, bool bulk_bind, crt_bulk_t *remote_bulks,
uint64_t *remote_offs, uint8_t *skips, daos_handle_t ioh, d_sg_list_t **sgls,
int sgl_nr, int bulk_nr, struct obj_bulk_args *p_arg)
{
struct obj_bulk_args arg = { 0 };
int i, rc, *status, ret;
int skip_nr = 0;
bool async = true;
uint64_t time = daos_get_ntime();
if (unlikely(sgl_nr > bulk_nr)) {
D_ERROR("Invalid sgl_nr vs bulk_nr: %d/%d\n", sgl_nr, bulk_nr);
return -DER_INVAL;
}
if (remote_bulks == NULL) {
D_ERROR("No remote bulks provided\n");
return -DER_INVAL;
}
if (p_arg == NULL) {
p_arg = &arg;
async = false;
}
rc = ABT_eventual_create(sizeof(*status), &p_arg->eventual);
if (rc != 0)
return dss_abterr2der(rc);
p_arg->inited = true;
D_DEBUG(DB_IO, "bulk_op %d, sgl_nr %d, bulk_nr %d\n", bulk_op, sgl_nr, bulk_nr);
p_arg->bulks_inflight++;
if (daos_handle_is_valid(ioh)) {
rc = vos_dedup_verify_init(ioh, rpc->cr_ctx, CRT_BULK_RW);
if (rc) {
D_ERROR("Dedup verify prep failed. "DF_RC"\n",
DP_RC(rc));
goto done;
}
}
for (i = 0; i < sgl_nr; i++) {
d_sg_list_t *sgl, tmp_sgl;
/* Need to consider the akey skip case as client-side bulk array with one bulk for
* every akey, but some akeys possibly be skipped in obj_get_iods_offs (number of
* akeys possibly reduced). So here need to find the corresponding bulk handle
* for non-skipped akey. The akey skip case only possible for EC object and targeted
* for multiple data shards.
* For RPC inline (non-bulk) case (bio_iod_copy) need not consider the akey skip
* because we always create bulk handle if EC object IO targeted for multiple
* data shards.
*/
while (skips != NULL && isset(skips, i + skip_nr))
skip_nr++;
D_ASSERTF(i + skip_nr < bulk_nr, "i %d, skip_nr %d, sgl_nr %d, bulk_nr %d\n",
i, skip_nr, sgl_nr, bulk_nr);
if (remote_bulks[i + skip_nr] == NULL)
continue;
if (sgls != NULL) {
sgl = sgls[i];
} else {
struct bio_sglist *bsgl;
D_ASSERT(daos_handle_is_valid(ioh));
bsgl = vos_iod_sgl_at(ioh, i);
D_ASSERT(bsgl != NULL);
sgl = &tmp_sgl;
rc = bio_sgl_convert(bsgl, sgl);
if (rc)
break;
}
/* OBJ_BULK_OFFSET_SKIP is for the case of EC single value degraded fetch,
* unnecessary to bulk transfer here, the data will be transferred back when
* data recovery (ORF_EC_RECOV).
*/
if (remote_offs == NULL || remote_offs[i] != OBJ_BULK_OFFSET_SKIP)
rc = bulk_transfer_sgl(ioh, rpc, remote_bulks[i + skip_nr],
remote_offs ? remote_offs[i] : 0, bulk_op, bulk_bind,
sgl, i, p_arg);
if (sgls == NULL)
d_sgl_fini(sgl, false);
if (rc) {
D_ERROR("bulk_transfer_sgl i %d, skip_nr %d failed, "DF_RC"\n",
i, skip_nr, DP_RC(rc));
break;
}
}
if (skips != NULL)
D_ASSERTF(skip_nr + sgl_nr <= bulk_nr,
"Unmatched skip_nr %d, sgl_nr %d, bulk_nr %d\n",
skip_nr, sgl_nr, bulk_nr);
done:
if (--(p_arg->bulks_inflight) == 0)
ABT_eventual_set(p_arg->eventual, &rc, sizeof(rc));
if (async)
return rc;
ret = ABT_eventual_wait(p_arg->eventual, (void **)&status);
if (rc == 0)
rc = ret ? dss_abterr2der(ret) : *status;
ABT_eventual_free(&p_arg->eventual);
if (rc == 0)
obj_update_latency(opc_get(rpc->cr_opc), BULK_LATENCY, daos_get_ntime() - time,
arg.bulk_size);
if (rc == 0 && p_arg->result != 0)
rc = p_arg->result;
/* After RDMA is done, corrupt the server data */
if (rc == 0 && DAOS_FAIL_CHECK(DAOS_CSUM_CORRUPT_DISK)) {
struct bio_sglist *fbsgl;
d_sg_list_t fsgl;
int *fbuffer;
D_ERROR("csum: Corrupting data after RDMA\n");
fbsgl = vos_iod_sgl_at(ioh, 0);
bio_sgl_convert(fbsgl, &fsgl);
fbuffer = (int *)fsgl.sg_iovs[0].iov_buf;
*fbuffer += 0x2;
d_sgl_fini(&fsgl, false);
}
return rc;
}
static int
obj_set_reply_sizes(crt_rpc_t *rpc, daos_iod_t *iods, int iod_nr, uint8_t *skips)
{
struct obj_rw_in *orw = crt_req_get(rpc);
struct obj_rw_out *orwo = crt_reply_get(rpc);
uint64_t *sizes = NULL;
int orw_iod_nr = orw->orw_nr;
int i, idx;
D_ASSERT(obj_rpc_is_fetch(rpc));
D_ASSERT(orwo != NULL);
D_ASSERT(orw != NULL);
if (orw->orw_flags & ORF_CHECK_EXISTENCE)
goto out;
if (orw_iod_nr <= 0) {
D_ERROR("rpc %p contains invalid sizes count %d for "
DF_UOID" with epc "DF_X64".\n",
rpc, orw_iod_nr, DP_UOID(orw->orw_oid), orw->orw_epoch);
return -DER_INVAL;
}
/* Re-entry case.*/
if (orwo->orw_iod_sizes.ca_count != 0) {
D_ASSERT(orwo->orw_iod_sizes.ca_count == orw_iod_nr);
D_ASSERT(orwo->orw_iod_sizes.ca_arrays != NULL);
sizes = orwo->orw_iod_sizes.ca_arrays;
} else {
D_ALLOC_ARRAY(sizes, orw_iod_nr);
if (sizes == NULL)
return -DER_NOMEM;
}
for (i = 0, idx = 0; i < orw_iod_nr; i++) {
if (skips != NULL && isset(skips, i)) {
sizes[i] = 0;
continue;
}
sizes[i] = iods[idx].iod_size;
D_DEBUG(DB_IO, DF_UOID" %d:"DF_U64"\n", DP_UOID(orw->orw_oid),
i, iods[idx].iod_size);
if ((orw->orw_flags & ORF_FOR_MIGRATION) && sizes[i] == 0) {
D_DEBUG(DB_REBUILD,
DF_CONT " obj " DF_UOID "rebuild fetch zero iod_size, "
"i:%d/idx:%d, iod_nr %d, orw_epoch " DF_X64
", orw_epoch_first " DF_X64 " may cause DER_DATA_LOSS",
DP_CONT(orw->orw_pool_uuid, orw->orw_co_uuid),
DP_UOID(orw->orw_oid), i, idx, iods[idx].iod_nr, orw->orw_epoch,
orw->orw_epoch_first);
if (iods[idx].iod_type == DAOS_IOD_ARRAY) {
int j;
for (j = 0; j < min(8, iods[idx].iod_nr); j++)
D_DEBUG(DB_REBUILD, "recx[%d] - " DF_RECX, j,
DP_RECX(iods[idx].iod_recxs[j]));
}
}
idx++;
}
D_ASSERTF(idx == iod_nr, "idx %d, iod_nr %d\n", idx, iod_nr);
out:
if (sizes == NULL)
orw_iod_nr = 0;
orwo->orw_iod_sizes.ca_count = orw_iod_nr;
orwo->orw_iod_sizes.ca_arrays = sizes;
D_DEBUG(DB_TRACE, "rpc %p set sizes count as %d for "
DF_UOID" with epc "DF_X64".\n",
rpc, orw_iod_nr, DP_UOID(orw->orw_oid), orw->orw_epoch);
return 0;
}
/**
* Pack nrs in sgls inside the reply, so the client can update
* sgls before it returns to application.
* Pack sgl's data size in the reply, client fetch can based on
* it to update sgl's iov_len.
*
* @echo_sgl is set only for echo_rw()
*
* Note: this is only needed for bulk transfer, for inline transfer,
* it will pack the complete sgls inside the req/reply, see obj_shard_rw().
*/
static int
obj_set_reply_nrs(crt_rpc_t *rpc, daos_handle_t ioh, d_sg_list_t *echo_sgl, uint8_t *skips)
{
struct obj_rw_in *orw = crt_req_get(rpc);
struct obj_rw_out *orwo = crt_reply_get(rpc);
uint32_t *nrs;
daos_size_t *data_sizes;
uint32_t nrs_count = orw->orw_nr;
int i, j, idx;
if (nrs_count == 0 || (orw->orw_flags & ORF_CHECK_EXISTENCE))
return 0;
/* Re-entry case. */
if (orwo->orw_nrs.ca_count != 0) {
D_ASSERT(orwo->orw_nrs.ca_count == nrs_count);
D_ASSERT(orwo->orw_data_sizes.ca_count == nrs_count);
D_ASSERT(orwo->orw_nrs.ca_arrays != NULL);
D_ASSERT(orwo->orw_data_sizes.ca_arrays != NULL);
} else {
/* return sg_nr_out and data size for sgl */
D_ALLOC(orwo->orw_nrs.ca_arrays,
nrs_count * (sizeof(uint32_t) + sizeof(daos_size_t)));
if (orwo->orw_nrs.ca_arrays == NULL)
return -DER_NOMEM;
orwo->orw_nrs.ca_count = nrs_count;
orwo->orw_data_sizes.ca_count = nrs_count;
orwo->orw_data_sizes.ca_arrays = (void *)((char *)orwo->orw_nrs.ca_arrays +
nrs_count * (sizeof(uint32_t)));
}
nrs = orwo->orw_nrs.ca_arrays;
data_sizes = orwo->orw_data_sizes.ca_arrays;
for (i = 0, idx = 0; i < nrs_count; i++) {
if (skips != NULL && isset(skips, i)) {
nrs[i] = 0;
data_sizes[i] = 0;
continue;
}
if (echo_sgl != NULL) {
nrs[i] = echo_sgl->sg_nr_out;
} else {
struct bio_sglist *bsgl;
bsgl = vos_iod_sgl_at(ioh, idx);
D_ASSERT(bsgl != NULL);
nrs[i] = bsgl->bs_nr_out;
/* tail holes trimmed by ioc_trim_tail_holes() */
for (j = 0; j < bsgl->bs_nr_out; j++)
data_sizes[i] += bio_iov2req_len(
&bsgl->bs_iovs[j]);
}
idx++;
}
return 0;
}
static void
obj_echo_rw(crt_rpc_t *rpc, daos_iod_t *iod, uint64_t *off)
{
struct obj_rw_in *orw = crt_req_get(rpc);
struct obj_rw_out *orwo = crt_reply_get(rpc);
struct obj_tls *tls;
d_sg_list_t *p_sgl;
crt_bulk_op_t bulk_op;
bool bulk_bind;
int i;
int rc = 0;
D_DEBUG(DB_TRACE, "opc %d oid "DF_UOID" dkey "DF_KEY
" tgt/xs %d/%d epc "DF_X64".\n",
opc_get(rpc->cr_opc), DP_UOID(orw->orw_oid),
DP_KEY(&orw->orw_dkey),
dss_get_module_info()->dmi_tgt_id,
dss_get_module_info()->dmi_xs_id,
orw->orw_epoch);
if (obj_rpc_is_fetch(rpc)) {
rc = obj_set_reply_sizes(rpc, orw->orw_iod_array.oia_iods,
orw->orw_iod_array.oia_iod_nr, NULL);
if (rc)
D_GOTO(out, rc);
}
/* Inline fetch/update */
if (orw->orw_bulks.ca_arrays == NULL && orw->orw_bulks.ca_count == 0) {
if (obj_rpc_is_fetch(rpc)) {
orwo->orw_sgls.ca_count = orw->orw_sgls.ca_count;
orwo->orw_sgls.ca_arrays = orw->orw_sgls.ca_arrays;
}
D_GOTO(out, rc);
}
/* Only support 1 iod now */
D_ASSERT(orw->orw_iod_array.oia_iod_nr == 1);
tls = obj_tls_get();
p_sgl = &tls->ot_echo_sgl;
/* Let's check if tls already have enough buffer */
if (p_sgl->sg_nr < iod->iod_nr) {
d_sgl_fini(p_sgl, true);
rc = d_sgl_init(p_sgl, iod->iod_nr);
if (rc)
D_GOTO(out, rc);
p_sgl->sg_nr_out = p_sgl->sg_nr;
}
for (i = 0; i < iod->iod_nr; i++) {
daos_size_t size = iod->iod_size;
if (size == DAOS_REC_ANY)
size = sizeof(uint64_t);
if (iod->iod_type == DAOS_IOD_ARRAY) {
D_ASSERT(iod->iod_recxs);
size *= iod->iod_recxs[i].rx_nr;
}
/* Check each vector */
if (p_sgl->sg_iovs[i].iov_buf_len < size) {
D_FREE(p_sgl->sg_iovs[i].iov_buf);
D_ALLOC(p_sgl->sg_iovs[i].iov_buf, size);
/* obj_tls_fini() will free these buffer */
if (p_sgl->sg_iovs[i].iov_buf == NULL)
D_GOTO(out, rc = -DER_NOMEM);
p_sgl->sg_iovs[i].iov_buf_len = size;
p_sgl->sg_iovs[i].iov_len = size;
}
}
orwo->orw_sgls.ca_count = 0;
orwo->orw_sgls.ca_arrays = NULL;
if (obj_rpc_is_fetch(rpc)) {
rc = obj_set_reply_nrs(rpc, DAOS_HDL_INVAL, p_sgl, NULL);
if (rc != 0)
D_GOTO(out, rc);
bulk_op = CRT_BULK_PUT;
} else {
bulk_op = CRT_BULK_GET;
}
/* Only support 1 iod now */
bulk_bind = orw->orw_flags & ORF_BULK_BIND;
rc = obj_bulk_transfer(rpc, bulk_op, bulk_bind, orw->orw_bulks.ca_arrays, off, NULL,
DAOS_HDL_INVAL, &p_sgl, 1, 1, NULL);
out:
orwo->orw_ret = rc;
orwo->orw_map_version = orw->orw_map_ver;
}
/** if checksums are enabled, fetch needs to allocate the memory that will be
* used for the csum structures.
*/
static int
obj_fetch_csum_init(struct ds_cont_child *cont, struct obj_rw_in *orw, struct obj_rw_out *orwo)
{
int rc;
/**
* Allocate memory for the csum structures.
* This memory and information will be used by VOS to put the checksums
* in as it fetches the data's metadata from the btree/evtree.
*
* The memory will be freed in obj_rw_reply
*/
/* Re-entry case. */
if (orwo->orw_iod_csums.ca_count != 0) {
D_ASSERT(orwo->orw_iod_csums.ca_arrays != NULL);
rc = 0;
} else {
rc = daos_csummer_alloc_iods_csums(cont->sc_csummer, orw->orw_iod_array.oia_iods,
orw->orw_iod_array.oia_iod_nr, false, NULL,
&orwo->orw_iod_csums.ca_arrays);
if (rc >= 0) {
orwo->orw_iod_csums.ca_count = rc;
rc = 0;
}
}
return rc;
}
static inline struct dcs_iod_csums *
get_iod_csum(struct dcs_iod_csums *iod_csums, int i)
{
if (iod_csums == NULL)
return NULL;
return &iod_csums[i];
}
static int
csum_add2iods(daos_handle_t ioh, daos_iod_t *iods, uint32_t iods_nr,
uint8_t *skips, struct daos_csummer *csummer,
struct dcs_iod_csums *iod_csums, daos_unit_oid_t oid,
daos_key_t *dkey)
{
int rc = 0;
uint32_t biov_csums_idx = 0;
size_t biov_csums_used = 0;
int i, idx;
struct bio_desc *biod = vos_ioh2desc(ioh);
struct dcs_ci_list *csum_infos = vos_ioh2ci(ioh);
uint32_t csum_info_nr = vos_ioh2ci_nr(ioh);
for (i = 0, idx = 0; i < iods_nr; i++) {
if (skips != NULL && isset(skips, i))
continue;
if (biov_csums_idx >= csum_info_nr)
break; /** no more csums to add */
csum_infos->dcl_csum_offset += biov_csums_used;
rc = ds_csum_add2iod(
&iods[i], csummer,
bio_iod_sgl(biod, idx), csum_infos,
&biov_csums_used, get_iod_csum(iod_csums, i));
idx++;
if (rc != 0) {
D_ERROR("Failed to add csum for iod\n");
return rc;
}
biov_csums_idx += biov_csums_used;
}
return rc;
}
static int
csum_verify_keys(struct daos_csummer *csummer, daos_key_t *dkey,
struct dcs_csum_info *dkey_csum,
struct obj_iod_array *oia, daos_unit_oid_t *uoid)
{
return ds_csum_verify_keys(csummer, dkey, dkey_csum, oia->oia_iods, oia->oia_iod_csums,
oia->oia_iod_nr, uoid);
}
/** Add a recov record to the recov_lists (for singv degraded fetch) */
static int
obj_singv_ec_add_recov(uint32_t iod_nr, uint32_t iod_idx, uint64_t rec_size,
daos_epoch_t epoch,
struct daos_recx_ep_list **recov_lists_ptr)
{
struct daos_recx_ep_list *recov_lists = *recov_lists_ptr;
struct daos_recx_ep_list *recov_list;
struct daos_recx_ep recx_ep;