-
Notifications
You must be signed in to change notification settings - Fork 306
/
Copy pathdc_array.c
2626 lines (2224 loc) · 64.2 KB
/
dc_array.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-2024 Intel Corporation.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
/*
* This file is part of daos
*
* src/array/dc_array.c
*/
#define D_LOGFAC DD_FAC(array)
#include <daos/event.h>
#include <daos/object.h>
#include <daos/container.h>
#include <daos/array.h>
#include <daos_array.h>
#include <daos_task.h>
#include <daos.h>
#define AKEY_MAGIC_V 0xdaca55a9daca55a9
#define ARRAY_MD_KEY "daos_array_metadata"
#define CELL_SIZE "daos_array_cell_size"
#define CHUNK_SIZE "daos_array_chunk_size"
struct dc_array {
/** link chain in the global handle hash table */
struct d_hlink hlink;
/** DAOS object handle */
daos_handle_t daos_oh;
/** Array cell size of each element */
daos_size_t cell_size;
/** elems to store in 1 dkey before moving to the next one in the grp */
daos_size_t chunk_size;
/** DAOS container handle of array */
daos_handle_t coh;
/** DAOS object ID of array */
daos_obj_id_t oid;
/** object handle access mode */
unsigned int mode;
/** Is this a byte array (set short fetch & memset holes to 0 */
bool byte_array;
};
struct md_params {
daos_key_t dkey;
uint64_t dkey_val;
char akey_val;
daos_iod_t iod;
d_sg_list_t sgl;
d_iov_t sg_iov;
uint64_t md_vals[3];
};
struct io_params {
daos_key_t dkey;
uint64_t dkey_val;
daos_iod_t iod;
d_sg_list_t sgl;
d_iov_t sg_iov; /** for 1 record updates on set_size */
daos_iom_t iom; /** used on fetch only */
daos_size_t cell_size;
daos_size_t chunk_size;
daos_size_t num_records;
daos_size_t array_size;
tse_task_t *task;
struct io_params *next;
bool user_sgl_used;
char akey_val;
};
static void
array_free(struct d_hlink *hlink)
{
struct dc_array *array;
array = container_of(hlink, struct dc_array, hlink);
D_ASSERT(daos_hhash_link_empty(&array->hlink));
D_FREE(array);
}
static struct d_hlink_ops array_h_ops = {
.hop_free = array_free,
};
static struct dc_array *
array_alloc(void)
{
struct dc_array *array;
D_ALLOC_PTR(array);
if (array == NULL)
return NULL;
daos_hhash_hlink_init(&array->hlink, &array_h_ops);
return array;
}
static void
array_decref(struct dc_array *array)
{
daos_hhash_link_putref(&array->hlink);
}
static daos_handle_t
array_ptr2hdl(struct dc_array *array)
{
daos_handle_t oh;
daos_hhash_link_key(&array->hlink, &oh.cookie);
return oh;
}
static struct dc_array *
array_hdl2ptr(daos_handle_t oh)
{
struct d_hlink *hlink;
hlink = daos_hhash_link_lookup(oh.cookie);
if (hlink == NULL)
return NULL;
return container_of(hlink, struct dc_array, hlink);
}
static void
array_hdl_link(struct dc_array *array)
{
daos_hhash_link_insert(&array->hlink, DAOS_HTYPE_ARRAY);
}
static void
array_hdl_unlink(struct dc_array *array)
{
daos_hhash_link_delete(&array->hlink);
}
static int
free_md_params_cb(tse_task_t *task, void *data)
{
struct md_params *params = *((struct md_params **)data);
D_FREE(params);
return task->dt_result;
}
static int
free_val_cb(tse_task_t *task, void *data)
{
char *val = *((char **)data);
int rc = task->dt_result;
D_FREE(val);
return rc;
}
static void
free_io_params(struct io_params *io_list)
{
while (io_list) {
struct io_params *current = io_list;
if (current->iom.iom_recxs) {
daos_recx_free(current->iom.iom_recxs);
current->iom.iom_recxs = NULL;
}
D_FREE(current->iod.iod_recxs);
if (!current->user_sgl_used)
D_FREE(current->sgl.sg_iovs);
io_list = current->next;
D_FREE(current);
}
}
static int
free_io_params_cb(tse_task_t *task, void *data)
{
free_io_params(*((struct io_params **)data));
return task->dt_result;
}
static int
create_handle_cb(tse_task_t *task, void *data)
{
daos_array_create_t *args = *((daos_array_create_t **)data);
struct dc_array *array;
enum daos_otype_t type;
int rc = task->dt_result;
if (rc != 0) {
DL_CDEBUG(rc == -DER_EXIST, DLOG_DBG, DLOG_ERR, rc, "Failed to create array obj");
D_GOTO(err_obj, rc);
}
/** Create an array OH from the DAOS one */
array = array_alloc();
if (array == NULL)
D_GOTO(err_obj, rc = -DER_NOMEM);
array->coh = args->coh;
array->oid.hi = args->oid.hi;
array->oid.lo = args->oid.lo;
array->mode = DAOS_OO_RW;
array->cell_size = args->cell_size;
array->chunk_size = args->chunk_size;
array->daos_oh = *args->oh;
type = daos_obj_id2type(args->oid);
if (type == DAOS_OT_ARRAY_BYTE)
array->byte_array = true;
array_hdl_link(array);
*args->oh = array_ptr2hdl(array);
return 0;
err_obj:
if (daos_handle_is_valid(*args->oh)) {
daos_obj_close_t *close_args;
tse_task_t *close_task;
int rc2;
rc2 = daos_task_create(DAOS_OPC_OBJ_CLOSE, tse_task2sched(task),
0, NULL, &close_task);
if (rc2) {
D_ERROR("Failed to create task to cleanup obj hdl\n");
return rc;
}
close_args = daos_task_get_args(close_task);
close_args->oh = *args->oh;
tse_task_schedule(close_task, true);
}
return rc;
}
static int
free_handle_cb(tse_task_t *task, void *data)
{
struct dc_array *array = *((struct dc_array **)data);
int rc = task->dt_result;
if (rc != 0)
return rc;
array_hdl_unlink(array);
/* -1 for ref taken in dc_array_close */
array_decref(array);
/* -1 for array handle */
array_decref(array);
return 0;
}
#define DC_ARRAY_GLOB_MAGIC (0xdaca0387)
/* Structure of global buffer for dc_array */
struct dc_array_glob {
uint32_t magic;
uint32_t mode;
daos_obj_id_t oid;
daos_size_t cell_size;
daos_size_t chunk_size;
uuid_t cont_uuid;
uuid_t coh_uuid;
};
static inline daos_size_t
dc_array_glob_buf_size()
{
return sizeof(struct dc_array_glob);
}
static inline void
swap_array_glob(struct dc_array_glob *array_glob)
{
D_ASSERT(array_glob != NULL);
D_SWAP32S(&array_glob->magic);
D_SWAP32S(&array_glob->mode);
D_SWAP64S(&array_glob->cell_size);
D_SWAP64S(&array_glob->chunk_size);
D_SWAP64S(&array_glob->oid.hi);
D_SWAP64S(&array_glob->oid.lo);
/* skip cont_uuid */
/* skip coh_uuid */
}
static int
dc_array_l2g(daos_handle_t oh, d_iov_t *glob)
{
struct dc_array *array;
struct dc_array_glob *array_glob;
uuid_t coh_uuid;
uuid_t cont_uuid;
daos_size_t glob_buf_size;
int rc = 0;
D_ASSERT(glob != NULL);
array = array_hdl2ptr(oh);
if (array == NULL)
D_GOTO(out, rc = -DER_NO_HDL);
rc = dc_cont_hdl2uuid(array->coh, &coh_uuid, &cont_uuid);
if (rc != 0)
D_GOTO(out_array, rc);
glob_buf_size = dc_array_glob_buf_size();
if (glob->iov_buf == NULL) {
glob->iov_buf_len = glob_buf_size;
D_GOTO(out_array, rc = 0);
}
if (glob->iov_buf_len < glob_buf_size) {
D_DEBUG(DB_ANY, "Larger glob buffer needed ("DF_U64" bytes "
"provided, "DF_U64" required).\n", glob->iov_buf_len,
glob_buf_size);
glob->iov_buf_len = glob_buf_size;
D_GOTO(out_array, rc = -DER_TRUNC);
}
glob->iov_len = glob_buf_size;
/* init global handle */
array_glob = (struct dc_array_glob *)glob->iov_buf;
array_glob->magic = DC_ARRAY_GLOB_MAGIC;
array_glob->cell_size = array->cell_size;
array_glob->chunk_size = array->chunk_size;
array_glob->mode = array->mode;
array_glob->oid.hi = array->oid.hi;
array_glob->oid.lo = array->oid.lo;
uuid_copy(array_glob->coh_uuid, coh_uuid);
uuid_copy(array_glob->cont_uuid, cont_uuid);
out_array:
array_decref(array);
out:
if (rc)
D_ERROR("daos_array_l2g failed, rc: "DF_RC"\n", DP_RC(rc));
return rc;
}
int
dc_array_local2global(daos_handle_t oh, d_iov_t *glob)
{
int rc = 0;
if (glob == NULL) {
D_ERROR("Invalid parameter, NULL glob pointer.\n");
D_GOTO(out, rc = -DER_INVAL);
}
if (glob->iov_buf != NULL && (glob->iov_buf_len == 0 ||
glob->iov_buf_len < glob->iov_len)) {
D_ERROR("Invalid parameter of glob, iov_buf %p, iov_buf_len "
""DF_U64", iov_len "DF_U64".\n", glob->iov_buf,
glob->iov_buf_len, glob->iov_len);
D_GOTO(out, rc = -DER_INVAL);
}
rc = dc_array_l2g(oh, glob);
out:
return rc;
}
static int
dc_array_g2l(daos_handle_t coh, struct dc_array_glob *array_glob,
unsigned int mode, daos_handle_t *oh)
{
struct dc_array *array;
uuid_t coh_uuid;
uuid_t cont_uuid;
unsigned int array_mode;
int rc = 0;
D_ASSERT(array_glob != NULL);
D_ASSERT(oh != NULL);
/** Check container uuid mismatch */
rc = dc_cont_hdl2uuid(coh, &coh_uuid, &cont_uuid);
if (rc != 0)
D_GOTO(out, rc);
if (uuid_compare(cont_uuid, array_glob->cont_uuid) != 0) {
D_ERROR("Container uuid mismatch, in coh: "DF_UUID", "
"in array_glob:" DF_UUID"\n", DP_UUID(cont_uuid),
DP_UUID(array_glob->cont_uuid));
D_GOTO(out, rc = -DER_INVAL);
}
/** create an array open handle */
array = array_alloc();
if (array == NULL)
D_GOTO(out, rc = -DER_NOMEM);
array_mode = (mode == 0) ? array_glob->mode : mode;
rc = daos_obj_open(coh, array_glob->oid, array_mode, &array->daos_oh,
NULL);
if (rc) {
D_ERROR("daos_obj_open() failed "DF_RC"\n", DP_RC(rc));
D_GOTO(out_array, rc);
}
array->coh = coh;
array->cell_size = array_glob->cell_size;
array->chunk_size = array_glob->chunk_size;
array->oid.hi = array_glob->oid.hi;
array->oid.lo = array_glob->oid.lo;
array->mode = array_mode;
if (daos_obj_id2type(array->oid) == DAOS_OT_ARRAY_BYTE)
array->byte_array = true;
array_hdl_link(array);
*oh = array_ptr2hdl(array);
out_array:
if (rc)
array_decref(array);
out:
return rc;
}
int
dc_array_global2local(daos_handle_t coh, d_iov_t glob, unsigned int mode,
daos_handle_t *oh)
{
struct dc_array_glob *array_glob;
int rc = 0;
if (oh == NULL) {
D_ERROR("Invalid parameter, NULL coh.\n");
D_GOTO(out, rc = -DER_INVAL);
}
if (glob.iov_buf == NULL || glob.iov_buf_len < glob.iov_len ||
glob.iov_len != dc_array_glob_buf_size()) {
D_ERROR("Invalid parameter of glob, iov_buf %p, "
"iov_buf_len "DF_U64", iov_len "DF_U64".\n",
glob.iov_buf, glob.iov_buf_len, glob.iov_len);
D_GOTO(out, rc = -DER_INVAL);
}
array_glob = (struct dc_array_glob *)glob.iov_buf;
if (array_glob->magic == D_SWAP32(DC_ARRAY_GLOB_MAGIC)) {
swap_array_glob(array_glob);
D_ASSERT(array_glob->magic == DC_ARRAY_GLOB_MAGIC);
} else if (array_glob->magic != DC_ARRAY_GLOB_MAGIC) {
D_ERROR("Bad magic value: %#x.\n", array_glob->magic);
D_GOTO(out, rc = -DER_INVAL);
}
if (array_glob->cell_size == 0 ||
array_glob->chunk_size == 0) {
D_ERROR("Invalid parameter, cell/chunk size is 0.\n");
D_GOTO(out, rc = -DER_INVAL);
}
rc = dc_array_g2l(coh, array_glob, mode, oh);
if (rc != 0)
D_ERROR("dc_array_g2l failed "DF_RC"\n", DP_RC(rc));
out:
return rc;
}
static inline void
set_md_params(struct md_params *params)
{
/** write metadata to DKEY 0 */
params->dkey_val = 0;
d_iov_set(¶ms->dkey, ¶ms->dkey_val, sizeof(uint64_t));
/** set SGL */
d_iov_set(¶ms->sg_iov, params->md_vals, sizeof(params->md_vals));
params->sgl.sg_nr = 1;
params->sgl.sg_nr_out = 0;
params->sgl.sg_iovs = ¶ms->sg_iov;
/** set IOD */
params->akey_val = '0';
d_iov_set(¶ms->iod.iod_name, ¶ms->akey_val, 1);
params->iod.iod_nr = 1;
params->iod.iod_size = sizeof(params->md_vals);
params->iod.iod_recxs = NULL;
params->iod.iod_type = DAOS_IOD_SINGLE;
}
static int
write_md_cb(tse_task_t *task, void *data)
{
daos_array_create_t *args = *((daos_array_create_t **)data);
daos_obj_update_t *update_args;
struct md_params *params;
int rc = task->dt_result;
if (rc != 0) {
D_ERROR("Failed to open object "DF_RC"\n", DP_RC(rc));
return rc;
}
D_ALLOC_PTR(params);
if (params == NULL)
return -DER_NOMEM;
params->md_vals[0] = AKEY_MAGIC_V;
params->md_vals[1] = args->cell_size;
params->md_vals[2] = args->chunk_size;
set_md_params(params);
/** Set the args for the update task */
update_args = daos_task_get_args(task);
update_args->oh = *args->oh;
update_args->th = args->th;
update_args->dkey = ¶ms->dkey;
update_args->nr = 1;
update_args->iods = ¶ms->iod;
update_args->sgls = ¶ms->sgl;
update_args->flags = DAOS_COND_DKEY_INSERT | DAOS_COND_AKEY_INSERT;
rc = tse_task_register_comp_cb(task, free_md_params_cb, ¶ms,
sizeof(params));
if (rc != 0) {
D_FREE(params);
return rc;
}
return 0;
}
int
dc_array_create(tse_task_t *task)
{
daos_array_create_t *args = daos_task_get_args(task);
tse_task_t *open_task, *update_task;
daos_obj_open_t *open_args;
int rc;
if (!(daos_is_array(args->oid))) {
D_ERROR("Array must be of Array Type (OID type).\n");
D_GOTO(err_ptask, rc = -DER_INVAL);
}
/** Create task to open object */
rc = daos_task_create(DAOS_OPC_OBJ_OPEN, tse_task2sched(task),
0, NULL, &open_task);
if (rc != 0) {
D_ERROR("Failed to create object_open task\n");
D_GOTO(err_ptask, rc);
}
open_args = daos_task_get_args(open_task);
open_args->coh = args->coh;
open_args->oid = args->oid;
open_args->mode = DAOS_OO_RW;
open_args->oh = args->oh;
/** Create task to write object metadata */
rc = daos_task_create(DAOS_OPC_OBJ_UPDATE, tse_task2sched(task),
1, &open_task, &update_task);
if (rc != 0) {
D_ERROR("Failed to create object_update task\n");
D_GOTO(err_put1, rc);
}
/** The upper task completes when the update task completes */
rc = tse_task_register_deps(task, 1, &update_task);
if (rc != 0) {
D_ERROR("Failed to register dependency\n");
D_GOTO(err_put2, rc);
}
/** add a prepare CB to set the args for the metadata write */
rc = tse_task_register_cbs(update_task, write_md_cb, &args,
sizeof(args), NULL, NULL, 0);
if (rc != 0) {
D_ERROR("Failed to register prep CB\n");
D_GOTO(err_put2, rc);
}
/** CB to generate the array OH */
rc = tse_task_register_cbs(task, NULL, NULL, 0, create_handle_cb,
&args, sizeof(args));
if (rc != 0) {
D_ERROR("Failed to register completion cb\n");
D_GOTO(err_put2, rc);
}
tse_task_schedule(open_task, true);
tse_task_schedule(update_task, true);
return rc;
err_put2:
tse_task_complete(update_task, rc);
err_put1:
tse_task_complete(open_task, rc);
err_ptask:
tse_task_complete(task, rc);
return rc;
}
static int
open_handle_cb(tse_task_t *task, void *data)
{
daos_array_open_t *args = *((daos_array_open_t **)data);
struct dc_array *array;
struct md_params *params;
uint64_t *md_vals;
int rc = task->dt_result;
if (rc != 0) {
DL_CDEBUG(rc == -DER_NONEXIST, DLOG_DBG, DLOG_ERR, rc,
"Failed to open array object");
return rc;
}
/** check and set array metadata in case of array_open */
if (!args->open_with_attr) {
/** Check magic value */
params = daos_task_get_priv(task);
D_ASSERT(params != NULL);
md_vals = params->md_vals;
if (md_vals[0] != AKEY_MAGIC_V)
D_GOTO(err_obj, rc = -DER_NO_PERM);
/** If no cell and chunk size, this isn't an array obj. */
if (md_vals[1] == 0 || md_vals[2] == 0)
D_GOTO(err_obj, rc = -DER_NO_PERM);
/** Set array open OUT params */
*args->cell_size = md_vals[1];
*args->chunk_size = md_vals[2];
}
/** Create an array OH from the DAOS one */
array = array_alloc();
if (array == NULL)
D_GOTO(err_obj, rc = -DER_NOMEM);
array->coh = args->coh;
array->oid.hi = args->oid.hi;
array->oid.lo = args->oid.lo;
array->mode = args->mode;
array->cell_size = *args->cell_size;
array->chunk_size = *args->chunk_size;
array->daos_oh = *args->oh;
if (daos_obj_id2type(args->oid) == DAOS_OT_ARRAY_BYTE)
array->byte_array = true;
array_hdl_link(array);
*args->oh = array_ptr2hdl(array);
return 0;
err_obj:
if (daos_handle_is_valid(*args->oh)) {
daos_obj_close_t *close_args;
tse_task_t *close_task;
int rc2;
rc2 = daos_task_create(DAOS_OPC_OBJ_CLOSE, tse_task2sched(task),
0, NULL, &close_task);
if (rc2) {
D_ERROR("Failed to create task to cleanup obj hdl "DF_RC"\n", DP_RC(rc2));
return rc;
}
close_args = daos_task_get_args(close_task);
close_args->oh = *args->oh;
tse_task_schedule(close_task, true);
}
return rc;
}
static int
fetch_md_cb(tse_task_t *task, void *data)
{
daos_array_open_t *args = *((daos_array_open_t **)data);
daos_obj_fetch_t *fetch_args;
struct md_params *params;
int rc = task->dt_result;
if (rc != 0) {
D_ERROR("Failed to open object "DF_RC"\n", DP_RC(rc));
return rc;
}
params = daos_task_get_priv(task);
D_ASSERT(params != NULL);
set_md_params(params);
/** Set the args for the fetch task */
fetch_args = daos_task_get_args(task);
fetch_args->oh = *args->oh;
fetch_args->th = args->th;
fetch_args->dkey = ¶ms->dkey;
fetch_args->nr = 1;
fetch_args->iods = ¶ms->iod;
fetch_args->sgls = ¶ms->sgl;
fetch_args->flags = DAOS_COND_DKEY_FETCH | DAOS_COND_AKEY_FETCH;
return 0;
}
int
dc_array_open(tse_task_t *task)
{
daos_array_open_t *args = daos_task_get_args(task);
tse_task_t *open_task = NULL, *fetch_task = NULL;
daos_obj_open_t *open_args;
struct md_params *params;
enum daos_otype_t otype;
int rc;
if (args->open_with_attr)
if (*args->cell_size == 0 || *args->chunk_size == 0)
D_GOTO(err_ptask, rc = -DER_INVAL);
otype = daos_obj_id2type(args->oid);
if (!daos_is_array_type(otype)) {
D_ERROR("Array must be of type Array (OID type).\n");
D_GOTO(err_ptask, rc = -DER_INVAL);
}
if (!args->open_with_attr && otype != DAOS_OT_ARRAY) {
D_ERROR("Array open must be of DAOS_OT_ARRAY type (OID type).\n");
D_GOTO(err_ptask, rc = -DER_INVAL);
}
if (args->open_with_attr && otype == DAOS_OT_ARRAY) {
D_ERROR("Array open_with_attr must be of DAOS_OT_ARRAY_{BYTE,ATTR} "
"type (OID type).\n");
D_GOTO(err_ptask, rc = -DER_INVAL);
}
/** Create task to open object */
rc = daos_task_create(DAOS_OPC_OBJ_OPEN, tse_task2sched(task), 0, NULL, &open_task);
if (rc != 0) {
D_ERROR("Failed to create object_open task "DF_RC"\n", DP_RC(rc));
D_GOTO(err_ptask, rc);
}
open_args = daos_task_get_args(open_task);
open_args->coh = args->coh;
open_args->oid = args->oid;
open_args->mode = args->mode;
open_args->oh = args->oh;
/** if this is an open_with_attr call, just add the handle CB */
if (args->open_with_attr) {
/** The upper task completes when the open task completes */
rc = tse_task_register_deps(task, 1, &open_task);
if (rc != 0) {
D_ERROR("Failed to register dependency "DF_RC"\n", DP_RC(rc));
D_GOTO(err_put1, rc);
}
rc = tse_task_register_comp_cb(task, open_handle_cb, &args, sizeof(args));
if (rc != 0) {
D_ERROR("Failed to register completion cb "DF_RC"\n", DP_RC(rc));
D_GOTO(err_put1, rc);
}
tse_task_schedule(open_task, true);
return rc;
}
/** Create task to fetch object metadata depending on the open task to complete first. */
rc = daos_task_create(DAOS_OPC_OBJ_FETCH, tse_task2sched(task), 1, &open_task, &fetch_task);
if (rc != 0) {
D_ERROR("daos_task_create() failed: "DF_RC"\n", DP_RC(rc));
D_GOTO(err_put1, rc);
}
/** add a prepare CB to set the args for the metadata fetch */
rc = tse_task_register_cbs(fetch_task, fetch_md_cb, &args, sizeof(args), NULL, NULL, 0);
if (rc != 0) {
D_ERROR("tse_task_register_cbs() failed: "DF_RC"\n", DP_RC(rc));
D_GOTO(err_put2, rc);
}
/** The API task completes when the fetch task completes */
rc = tse_task_register_deps(task, 1, &fetch_task);
if (rc != 0) {
D_ERROR("tse_task_register_deps() failed: "DF_RC"\n", DP_RC(rc));
D_GOTO(err_put2, rc);
}
/*
* Allocate params for fetch task. need to do that here since we use that as priv value for
* upper task to verify metadata before creating the open handle.
*/
D_ALLOC_PTR(params);
if (params == NULL)
D_GOTO(err_put2, rc = -DER_NOMEM);
rc = tse_task_register_comp_cb(task, free_md_params_cb, ¶ms, sizeof(params));
if (rc != 0) {
D_ERROR("tse_task_register_cbs() failed: "DF_RC"\n", DP_RC(rc));
D_FREE(params);
D_GOTO(err_put2, rc);
}
/** set task private data for fetch and open handle creation */
daos_task_set_priv(fetch_task, params);
daos_task_set_priv(task, params);
/** Add a completion CB on the upper task to generate the array OH */
rc = tse_task_register_comp_cb(task, open_handle_cb, &args, sizeof(args));
if (rc != 0) {
D_ERROR("tse_task_register_comp_cb() failed: "DF_RC"\n", DP_RC(rc));
D_GOTO(err_put2, rc);
}
tse_task_schedule(open_task, true);
tse_task_schedule(fetch_task, true);
return rc;
err_put2:
tse_task_complete(fetch_task, rc);
err_put1:
tse_task_complete(open_task, rc);
err_ptask:
tse_task_complete(task, rc);
return rc;
}
int
dc_array_close_direct(daos_handle_t oh)
{
struct dc_array *array;
int rc;
array = array_hdl2ptr(oh);
if (array == NULL)
return -DER_NO_HDL;
rc = daos_obj_close(array->daos_oh, NULL);
if (rc) {
D_ERROR("daos_obj_close() failed: "DF_RC"\n", DP_RC(rc));
array_decref(array);
return rc;
}
array_hdl_unlink(array);
/* -1 for ref taken here */
array_decref(array);
/* -1 for array handle */
array_decref(array);
return 0;
}
int
dc_array_close(tse_task_t *task)
{
daos_array_close_t *args = daos_task_get_args(task);
struct dc_array *array;
tse_task_t *close_task;
daos_obj_close_t *close_args;
int rc;
/** decref for that in free_handle_cb */
array = array_hdl2ptr(args->oh);
if (array == NULL)
D_GOTO(err_ptask, rc = -DER_NO_HDL);
/** Create task to close object */
rc = daos_task_create(DAOS_OPC_OBJ_CLOSE, tse_task2sched(task),
0, NULL, &close_task);
if (rc) {
D_ERROR("Failed to create object_close task "DF_RC"\n", DP_RC(rc));
D_GOTO(err_put1, rc);
}
close_args = daos_task_get_args(close_task);
close_args->oh = array->daos_oh;
/** The upper task completes when the close task completes */
rc = tse_task_register_deps(task, 1, &close_task);
if (rc != 0) {
D_ERROR("Failed to register dependency "DF_RC"\n", DP_RC(rc));
D_GOTO(err_put2, rc);
}
/** Add a completion CB on the upper task to free the array */
rc = tse_task_register_cbs(task, NULL, NULL, 0, free_handle_cb,
&array, sizeof(array));
if (rc != 0) {
D_ERROR("Failed to register completion cb "DF_RC"\n", DP_RC(rc));
D_GOTO(err_put2, rc);
}
tse_task_schedule(close_task, true);
return rc;
err_put2:
tse_task_complete(close_task, rc);
err_put1:
array_decref(array);
err_ptask:
tse_task_complete(task, rc);
return rc;
}
int
dc_array_destroy(tse_task_t *task)
{
daos_array_destroy_t *args = daos_task_get_args(task);
struct dc_array *array;
tse_task_t *punch_task;
daos_obj_punch_t *punch_args;
int rc;
array = array_hdl2ptr(args->oh);
if (array == NULL)
D_GOTO(err_ptask, rc = -DER_NO_HDL);
/** Create task to punch object */
rc = daos_task_create(DAOS_OPC_OBJ_PUNCH, tse_task2sched(task),
0, NULL, &punch_task);
if (rc != 0) {
D_ERROR("Failed to create object_punch task\n");
D_GOTO(err_put1, rc);
}
punch_args = daos_task_get_args(punch_task);
punch_args->oh = array->daos_oh;
punch_args->th = args->th;
punch_args->dkey = NULL;
punch_args->akeys = NULL;
punch_args->akey_nr = 0;
/** The upper task completes when the punch task completes */
rc = tse_task_register_deps(task, 1, &punch_task);
if (rc != 0) {
D_ERROR("Failed to register dependency\n");
D_GOTO(err_put2, rc);
}
tse_task_schedule(punch_task, true);
array_decref(array);
return rc;
err_put2:
tse_task_complete(punch_task, rc);
err_put1:
array_decref(array);
err_ptask:
tse_task_complete(task, rc);
return rc;
}
int
dc_array_get_attr(daos_handle_t oh, daos_size_t *chunk_size,
daos_size_t *cell_size)
{
struct dc_array *array;
if (chunk_size == NULL || cell_size == NULL)
return -DER_INVAL;
array = array_hdl2ptr(oh);
if (array == NULL)
return -DER_NO_HDL;
*chunk_size = array->chunk_size;
*cell_size = array->cell_size;
array_decref(array);
return 0;
}
int
dc_array_update_chunk_size(daos_handle_t oh, daos_size_t chunk_size)
{
struct dc_array *array;
array = array_hdl2ptr(oh);
if (array == NULL)
return -DER_NO_HDL;
array->chunk_size = chunk_size;
array_decref(array);
return 0;
}
static bool
io_extent_same(daos_array_iod_t *iod, d_sg_list_t *sgl, daos_size_t cell_size,
daos_size_t *num_records)
{
daos_size_t rgs_len;
daos_size_t sgl_len;
daos_size_t u;
rgs_len = 0;
for (u = 0 ; u < iod->arr_nr ; u++)
rgs_len += iod->arr_rgs[u].rg_len;
*num_records = rgs_len;