-
Notifications
You must be signed in to change notification settings - Fork 311
/
Copy pathsrv_pool.c
8936 lines (7856 loc) · 249 KB
/
srv_pool.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.
* (C) Copyright 2025 Hewlett Packard Enterprise Development LP
* (C) Copyright 2025 Google LLC
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
/**
* \file
*
* ds_pool: Pool Service
*
* This file contains the server API methods and the RPC handlers that are both
* related pool metadata.
*/
#define D_LOGFAC DD_FAC(pool)
#include <daos_srv/pool.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <gurt/telemetry_common.h>
#include <gurt/telemetry_producer.h>
#include <daos_api.h> /* for daos_prop_alloc/_free() */
#include <daos/pool_map.h>
#include <daos/rpc.h>
#include <daos/pool.h>
#include <daos/rsvc.h>
#include <daos_srv/container.h>
#include <daos_srv/daos_mgmt_srv.h>
#include <daos_srv/daos_engine.h>
#include <daos_srv/rdb.h>
#include <daos_srv/rebuild.h>
#include <daos_srv/security.h>
#include <cart/api.h>
#include <cart/iv.h>
#include "rpc.h"
#include "srv_internal.h"
#include "srv_layout.h"
#include "srv_pool_map.h"
#define DAOS_POOL_GLOBAL_VERSION_WITH_HDL_CRED 1
#define DAOS_POOL_GLOBAL_VERSION_WITH_SVC_OPS_KVS 3
#define DAOS_POOL_GLOBAL_VERSION_WITH_DATA_THRESH 3
#define PS_OPS_PER_SEC 4096
/*
* Return the corresponding VOS DF version or 0 if pool_global_version is not
* supported.
*/
uint32_t
ds_pool_get_vos_df_version(uint32_t pool_global_version)
{
if (pool_global_version == 4)
return VOS_POOL_DF_2_8;
if (pool_global_version == 3)
return VOS_POOL_DF_2_6;
else if (pool_global_version == 2)
return VOS_POOL_DF_2_4;
return 0;
}
/** Return the VOS DF version for the default pool global version. */
uint32_t
ds_pool_get_vos_df_version_default(void)
{
uint32_t v = ds_pool_get_vos_df_version(DAOS_POOL_GLOBAL_VERSION);
D_ASSERT(v != 0);
return v;
}
#define DUP_OP_MIN_RDB_SIZE (1 << 30)
/* Pool service crt event */
struct pool_svc_event {
d_rank_t psv_rank;
uint64_t psv_incarnation;
enum crt_event_source psv_src;
enum crt_event_type psv_type;
};
#define DF_PS_EVENT "rank=%u inc="DF_U64" src=%d type=%d"
#define DP_PS_EVENT(e) e->psv_rank, e->psv_incarnation, e->psv_src, e->psv_type
/*
* Pool service crt event set
*
* This stores an unordered array of pool_svc_event objects. For all different
* i and j, we have pss_buf[i].psv_rank != pss_buf[j].psv_rank.
*
* An event set facilitates the merging of a sequence of events. For instance,
* sequence (in the format <rank, type>)
* <3, D>, <5, D>, <1, D>, <5, A>, <1, A>, <1, D>
* will merge into set
* <3, D>, <5, A>, <1, D>
* (that is, during the merge, an event overrides a previuos event of the same
* rank in the set).
*/
struct pool_svc_event_set {
struct pool_svc_event *pss_buf;
uint32_t pss_len;
uint32_t pss_cap;
};
#define DF_PS_EVENT_SET "len=%u"
#define DP_PS_EVENT_SET(s) s->pss_len
/* Pool service crt-event-handling state */
struct pool_svc_events {
ABT_mutex pse_mutex;
ABT_cond pse_cv;
struct pool_svc_event_set *pse_pending;
uint64_t pse_timeout; /* s */
uint64_t pse_time; /* s */
struct sched_request *pse_timer;
ABT_thread pse_handler;
bool pse_stop;
bool pse_paused;
};
/* Pool service schedule state */
struct pool_svc_sched {
ABT_mutex psc_mutex; /* only for psc_cv */
ABT_cond psc_cv;
bool psc_in_progress;
bool psc_canceled;
void *psc_arg;
int psc_rc;
};
static int
sched_init(struct pool_svc_sched *sched)
{
int rc;
rc = ABT_mutex_create(&sched->psc_mutex);
if (rc != ABT_SUCCESS) {
return dss_abterr2der(rc);
}
rc = ABT_cond_create(&sched->psc_cv);
if (rc != ABT_SUCCESS) {
ABT_mutex_free(&sched->psc_mutex);
return dss_abterr2der(rc);
}
sched->psc_in_progress = false;
sched->psc_canceled = false;
sched->psc_arg = NULL;
sched->psc_rc = 0;
return 0;
}
static void
sched_fini(struct pool_svc_sched *sched)
{
ABT_cond_free(&sched->psc_cv);
ABT_mutex_free(&sched->psc_mutex);
}
static void
sched_begin(struct pool_svc_sched *sched, void *arg)
{
sched->psc_in_progress = true;
sched->psc_canceled = false;
sched->psc_arg = arg;
sched->psc_rc = 0;
}
static void
sched_end(struct pool_svc_sched *sched)
{
sched->psc_in_progress = false;
sched->psc_canceled = false;
}
static void
sched_cancel(struct pool_svc_sched *sched)
{
if (sched->psc_in_progress)
sched->psc_canceled = true;
}
static void
sched_wait(struct pool_svc_sched *sched)
{
/*
* The CV requires a mutex. We don't otherwise need it for ULTs within
* the same xstream.
*/
ABT_mutex_lock(sched->psc_mutex);
while (sched->psc_in_progress)
ABT_cond_wait(sched->psc_cv, sched->psc_mutex);
ABT_mutex_unlock(sched->psc_mutex);
}
static void
sched_cancel_and_wait(struct pool_svc_sched *sched)
{
sched_cancel(sched);
sched_wait(sched);
}
struct pool_space_cache {
struct daos_pool_space psc_space;
uint64_t psc_memfile_bytes;
uint64_t psc_timestamp;
ABT_mutex psc_lock;
};
/* Pool service */
struct pool_svc {
struct ds_rsvc ps_rsvc;
uuid_t ps_uuid; /* pool UUID */
struct ds_pool *ps_pool;
struct cont_svc *ps_cont_svc; /* one combined svc for now */
ABT_rwlock ps_lock; /* for DB data */
rdb_path_t ps_root; /* root KVS */
rdb_path_t ps_handles; /* pool handle KVS */
rdb_path_t ps_user; /* pool user attributes KVS */
rdb_path_t ps_ops; /* metadata ops KVS */
int ps_error; /* in DB data (see pool_svc_lookup_leader) */
struct pool_svc_events ps_events;
struct pool_space_cache ps_space_cache;
uint32_t ps_global_version;
int ps_svc_rf;
bool ps_force_notify; /* MS of PS membership */
struct pool_svc_sched ps_reconf_sched;
struct pool_svc_sched ps_rfcheck_sched; /* Check all containers RF for the pool */
uint32_t ps_ops_enabled; /* cached ds_pool_prop_svc_ops_enabled */
uint32_t ps_ops_max; /* cached ds_pool_prop_svc_ops_max */
uint32_t ps_ops_age; /* cached ds_pool_prop_svc_ops_age */
};
/* Pool service failed to start */
struct pool_svc_failed {
uuid_t psf_uuid; /* pool UUID */
int psf_error; /* error number */
d_list_t psf_link; /* link to global list */
};
/** serialize operations on pool_svc_failed_list */
static pthread_rwlock_t psfl_rwlock = PTHREAD_RWLOCK_INITIALIZER;
/* tracking failed pool service */
D_LIST_HEAD(pool_svc_failed_list);
static bool pool_disable_exclude;
static int pool_prop_read(struct rdb_tx *tx, const struct pool_svc *svc,
uint64_t bits, daos_prop_t **prop_out);
static int
pool_space_query_bcast(crt_context_t ctx, struct pool_svc *svc, uuid_t pool_hdl,
struct daos_pool_space *ps, uint64_t *mem_file_bytes);
static int ds_pool_upgrade_if_needed(uuid_t pool_uuid, struct rsvc_hint *po_hint,
struct pool_svc *svc, crt_rpc_t *rpc);
static int
find_hdls_to_evict(struct rdb_tx *tx, struct pool_svc *svc, uuid_t **hdl_uuids,
size_t *hdl_uuids_size, int *n_hdl_uuids, char *machine);
static inline struct pool_svc *
pool_ds2svc(struct ds_pool_svc *ds_svc)
{
return (struct pool_svc *)ds_svc;
}
static inline struct ds_pool_svc *
pool_svc2ds(struct pool_svc *svc)
{
return (struct ds_pool_svc *)svc;
}
static struct pool_svc *
pool_svc_obj(struct ds_rsvc *rsvc)
{
return container_of(rsvc, struct pool_svc, ps_rsvc);
}
static int
write_map_buf(struct rdb_tx *tx, const rdb_path_t *kvs, struct pool_buf *buf,
uint32_t version)
{
d_iov_t value;
int rc;
D_DEBUG(DB_MD, "version=%u ntargets=%u ndomains=%u\n", version,
buf->pb_target_nr, buf->pb_domain_nr);
/* Write the version. */
d_iov_set(&value, &version, sizeof(version));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_map_version, &value);
if (rc != 0)
return rc;
/* Write the buffer. */
d_iov_set(&value, buf, pool_buf_size(buf->pb_nr));
return rdb_tx_update(tx, kvs, &ds_pool_prop_map_buffer, &value);
}
/*
* Retrieve the pool map buffer address in persistent memory and the pool map
* version into "map_buf" and "map_version", respectively.
*/
static int
locate_map_buf(struct rdb_tx *tx, const rdb_path_t *kvs, struct pool_buf **buf,
uint32_t *version)
{
uint32_t ver;
d_iov_t value;
int rc;
/* Read the version. */
d_iov_set(&value, &ver, sizeof(ver));
rc = rdb_tx_lookup(tx, kvs, &ds_pool_prop_map_version, &value);
if (rc != 0)
return rc;
/* Look up the buffer address. */
d_iov_set(&value, NULL /* buf */, 0 /* size */);
rc = rdb_tx_lookup(tx, kvs, &ds_pool_prop_map_buffer, &value);
if (rc != 0)
return rc;
*buf = value.iov_buf;
*version = ver;
D_DEBUG(DB_MD, "version=%u ntargets=%u ndomains=%u\n", *version,
(*buf)->pb_target_nr, (*buf)->pb_domain_nr);
return 0;
}
/* Callers are responsible for freeing buf with D_FREE. */
static int
read_map_buf(struct rdb_tx *tx, const rdb_path_t *kvs, struct pool_buf **buf,
uint32_t *version)
{
struct pool_buf *b;
size_t size;
int rc;
rc = locate_map_buf(tx, kvs, &b, version);
if (rc != 0)
return rc;
size = pool_buf_size(b->pb_nr);
D_ALLOC(*buf, size);
if (*buf == NULL)
return -DER_NOMEM;
memcpy(*buf, b, size);
return 0;
}
/* Callers are responsible for destroying the object via pool_map_decref(). */
static int
read_map(struct rdb_tx *tx, const rdb_path_t *kvs, struct pool_map **map)
{
struct pool_buf *buf;
uint32_t version;
int rc;
rc = locate_map_buf(tx, kvs, &buf, &version);
if (rc != 0)
return rc;
return pool_map_create(buf, version, map);
}
static char *
pool_svc_rdb_path_common(const uuid_t pool_uuid, const char *suffix)
{
char *name;
char *path;
int rc;
D_ASPRINTF(name, RDB_FILE"pool%s", suffix);
if (name == NULL)
return NULL;
rc = ds_mgmt_tgt_file(pool_uuid, name, NULL /* idx */, &path);
D_FREE(name);
if (rc != 0)
return NULL;
return path;
}
/* Return a pool service RDB path. */
char *
ds_pool_svc_rdb_path(const uuid_t pool_uuid)
{
return pool_svc_rdb_path_common(pool_uuid, "");
}
/* copy \a prop to \a prop_def (duplicated default prop) */
static int
pool_prop_default_copy(daos_prop_t *prop_def, daos_prop_t *prop)
{
struct daos_prop_entry *entry;
struct daos_prop_entry *entry_def;
int i;
int rc;
if (prop == NULL || prop->dpp_nr == 0 || prop->dpp_entries == NULL)
return 0;
for (i = 0; i < prop->dpp_nr; i++) {
entry = &prop->dpp_entries[i];
entry_def = daos_prop_entry_get(prop_def, entry->dpe_type);
D_ASSERTF(entry_def != NULL, "type %d not found in "
"default prop.\n", entry->dpe_type);
switch (entry->dpe_type) {
case DAOS_PROP_PO_LABEL:
D_FREE(entry_def->dpe_str);
D_STRNDUP(entry_def->dpe_str, entry->dpe_str,
DAOS_PROP_LABEL_MAX_LEN);
if (entry_def->dpe_str == NULL)
return -DER_NOMEM;
break;
case DAOS_PROP_PO_OWNER:
case DAOS_PROP_PO_OWNER_GROUP:
D_FREE(entry_def->dpe_str);
D_STRNDUP(entry_def->dpe_str, entry->dpe_str,
DAOS_ACL_MAX_PRINCIPAL_LEN);
if (entry_def->dpe_str == NULL)
return -DER_NOMEM;
break;
case DAOS_PROP_PO_SPACE_RB:
case DAOS_PROP_PO_SELF_HEAL:
case DAOS_PROP_PO_RECLAIM:
case DAOS_PROP_PO_EC_CELL_SZ:
case DAOS_PROP_PO_REDUN_FAC:
case DAOS_PROP_PO_EC_PDA:
case DAOS_PROP_PO_RP_PDA:
case DAOS_PROP_PO_SVC_REDUN_FAC:
case DAOS_PROP_PO_PERF_DOMAIN:
case DAOS_PROP_PO_SVC_OPS_ENABLED:
case DAOS_PROP_PO_SVC_OPS_ENTRY_AGE:
case DAOS_PROP_PO_DATA_THRESH:
case DAOS_PROP_PO_CHECKPOINT_MODE:
case DAOS_PROP_PO_CHECKPOINT_THRESH:
case DAOS_PROP_PO_CHECKPOINT_FREQ:
case DAOS_PROP_PO_REINT_MODE:
entry_def->dpe_val = entry->dpe_val;
break;
case DAOS_PROP_PO_ACL:
if (entry->dpe_val_ptr != NULL) {
struct daos_acl *acl = entry->dpe_val_ptr;
D_FREE(entry_def->dpe_val_ptr);
rc = daos_prop_entry_dup_ptr(entry_def, entry,
daos_acl_get_size(acl));
if (rc)
return rc;
}
break;
case DAOS_PROP_PO_SCRUB_MODE:
entry_def->dpe_val = entry->dpe_val;
break;
case DAOS_PROP_PO_SCRUB_FREQ:
entry_def->dpe_val = entry->dpe_val;
break;
case DAOS_PROP_PO_SCRUB_THRESH:
entry_def->dpe_val = entry->dpe_val;
break;
case DAOS_PROP_PO_GLOBAL_VERSION:
case DAOS_PROP_PO_UPGRADE_STATUS:
case DAOS_PROP_PO_OBJ_VERSION:
D_ERROR("pool property %u could be not set\n", entry->dpe_type);
return -DER_INVAL;
default:
D_ERROR("ignore bad dpt_type %d.\n", entry->dpe_type);
break;
}
}
/* Validate the result */
if (!daos_prop_valid(prop_def, true /* pool */, true /* input */)) {
D_ERROR("properties validation check failed\n");
return -DER_INVAL;
}
return 0;
}
static int
pool_prop_write(struct rdb_tx *tx, const rdb_path_t *kvs, daos_prop_t *prop)
{
struct daos_prop_entry *entry;
d_iov_t value;
int i;
int rc = 0;
uint32_t val32;
uint32_t global_ver;
if (prop == NULL || prop->dpp_nr == 0 || prop->dpp_entries == NULL)
return 0;
/*
* Determine the global version. In some cases, such as
* init_pool_metadata, the global version shall be found in prop, not
* in the RDB.
*/
entry = daos_prop_entry_get(prop, DAOS_PROP_PO_GLOBAL_VERSION);
if (entry == NULL || !daos_prop_is_set(entry)) {
d_iov_set(&value, &val32, sizeof(val32));
rc = rdb_tx_lookup(tx, kvs, &ds_pool_prop_global_version, &value);
if (rc && rc != -DER_NONEXIST)
return rc;
else if (rc == -DER_NONEXIST)
global_ver = 0;
else
global_ver = val32;
} else {
global_ver = entry->dpe_val;
}
D_DEBUG(DB_MD, "global version: %u\n", global_ver);
for (i = 0; i < prop->dpp_nr; i++) {
entry = &prop->dpp_entries[i];
switch (entry->dpe_type) {
case DAOS_PROP_PO_LABEL:
if (entry->dpe_str == NULL ||
strlen(entry->dpe_str) == 0) {
entry = daos_prop_entry_get(&pool_prop_default,
entry->dpe_type);
D_ASSERT(entry != NULL);
}
d_iov_set(&value, entry->dpe_str,
strlen(entry->dpe_str));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_label,
&value);
break;
case DAOS_PROP_PO_OWNER:
d_iov_set(&value, entry->dpe_str,
strlen(entry->dpe_str));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_owner,
&value);
break;
case DAOS_PROP_PO_OWNER_GROUP:
d_iov_set(&value, entry->dpe_str,
strlen(entry->dpe_str));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_owner_group,
&value);
break;
case DAOS_PROP_PO_ACL:
if (entry->dpe_val_ptr != NULL) {
struct daos_acl *acl;
acl = entry->dpe_val_ptr;
d_iov_set(&value, acl, daos_acl_get_size(acl));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_acl,
&value);
}
break;
case DAOS_PROP_PO_SPACE_RB:
d_iov_set(&value, &entry->dpe_val,
sizeof(entry->dpe_val));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_space_rb,
&value);
break;
case DAOS_PROP_PO_SELF_HEAL:
d_iov_set(&value, &entry->dpe_val,
sizeof(entry->dpe_val));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_self_heal,
&value);
break;
case DAOS_PROP_PO_RECLAIM:
d_iov_set(&value, &entry->dpe_val,
sizeof(entry->dpe_val));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_reclaim,
&value);
break;
case DAOS_PROP_PO_EC_CELL_SZ:
if (!daos_ec_cs_valid(entry->dpe_val)) {
D_ERROR("DAOS_PROP_PO_EC_CELL_SZ property value"
" "DF_U64" should within rage of "
"["DF_U64", "DF_U64"] and multiplier of "DF_U64"\n",
entry->dpe_val,
DAOS_PROP_PO_EC_CELL_SZ_MIN,
DAOS_PROP_PO_EC_CELL_SZ_MAX,
DAOS_PROP_PO_EC_CELL_SZ_MIN);
rc = -DER_INVAL;
break;
}
d_iov_set(&value, &entry->dpe_val,
sizeof(entry->dpe_val));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_ec_cell_sz,
&value);
break;
case DAOS_PROP_PO_REDUN_FAC:
d_iov_set(&value, &entry->dpe_val,
sizeof(entry->dpe_val));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_redun_fac,
&value);
break;
case DAOS_PROP_PO_DATA_THRESH:
if (!daos_data_thresh_valid(entry->dpe_val)) {
rc = -DER_INVAL;
break;
}
d_iov_set(&value, &entry->dpe_val, sizeof(entry->dpe_val));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_data_thresh, &value);
break;
case DAOS_PROP_PO_SVC_LIST:
break;
case DAOS_PROP_PO_EC_PDA:
if (!daos_ec_pda_valid(entry->dpe_val)) {
rc = -DER_INVAL;
break;
}
d_iov_set(&value, &entry->dpe_val,
sizeof(entry->dpe_val));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_ec_pda,
&value);
break;
case DAOS_PROP_PO_RP_PDA:
if (!daos_rp_pda_valid(entry->dpe_val)) {
rc = -DER_INVAL;
break;
}
d_iov_set(&value, &entry->dpe_val,
sizeof(entry->dpe_val));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_rp_pda,
&value);
break;
case DAOS_PROP_PO_SCRUB_MODE:
d_iov_set(&value, &entry->dpe_val,
sizeof(entry->dpe_val));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_scrub_mode,
&value);
if (rc)
return rc;
break;
case DAOS_PROP_PO_SCRUB_FREQ:
d_iov_set(&value, &entry->dpe_val,
sizeof(entry->dpe_val));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_scrub_freq,
&value);
if (rc)
return rc;
break;
case DAOS_PROP_PO_SCRUB_THRESH:
d_iov_set(&value, &entry->dpe_val,
sizeof(entry->dpe_val));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_scrub_thresh,
&value);
if (rc)
return rc;
break;
case DAOS_PROP_PO_GLOBAL_VERSION:
if (entry->dpe_val > DAOS_POOL_GLOBAL_VERSION) {
rc = -DER_INVAL;
break;
}
val32 = entry->dpe_val;
d_iov_set(&value, &val32, sizeof(val32));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_global_version,
&value);
break;
case DAOS_PROP_PO_UPGRADE_STATUS:
if (entry->dpe_val > DAOS_UPGRADE_STATUS_COMPLETED) {
rc = -DER_INVAL;
break;
}
val32 = entry->dpe_val;
d_iov_set(&value, &val32, sizeof(val32));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_upgrade_status,
&value);
break;
case DAOS_PROP_PO_PERF_DOMAIN:
val32 = entry->dpe_val;
d_iov_set(&value, &val32, sizeof(val32));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_perf_domain,
&value);
break;
case DAOS_PROP_PO_SVC_REDUN_FAC:
if (global_ver < 2) {
D_DEBUG(DB_MD, "skip writing svc_redun_fac for global version %u\n",
global_ver);
rc = 0;
break;
}
d_iov_set(&value, &entry->dpe_val, sizeof(entry->dpe_val));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_svc_redun_fac, &value);
break;
case DAOS_PROP_PO_OBJ_VERSION:
if (entry->dpe_val > DS_POOL_OBJ_VERSION) {
rc = -DER_INVAL;
break;
}
val32 = entry->dpe_val;
d_iov_set(&value, &val32, sizeof(val32));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_obj_version, &value);
break;
case DAOS_PROP_PO_CHECKPOINT_MODE:
val32 = entry->dpe_val;
d_iov_set(&value, &val32, sizeof(val32));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_checkpoint_mode, &value);
if (rc)
return rc;
break;
case DAOS_PROP_PO_CHECKPOINT_FREQ:
val32 = entry->dpe_val;
if (val32 > DAOS_PROP_PO_CHECKPOINT_FREQ_MAX)
val32 = DAOS_PROP_PO_CHECKPOINT_FREQ_MAX;
else if (val32 < DAOS_PROP_PO_CHECKPOINT_FREQ_MIN)
val32 = DAOS_PROP_PO_CHECKPOINT_FREQ_MIN;
d_iov_set(&value, &val32, sizeof(val32));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_checkpoint_freq, &value);
if (rc)
return rc;
break;
case DAOS_PROP_PO_CHECKPOINT_THRESH:
val32 = entry->dpe_val;
if (val32 > DAOS_PROP_PO_CHECKPOINT_THRESH_MAX)
val32 = DAOS_PROP_PO_CHECKPOINT_THRESH_MAX;
else if (val32 < DAOS_PROP_PO_CHECKPOINT_THRESH_MIN)
val32 = DAOS_PROP_PO_CHECKPOINT_THRESH_MIN;
d_iov_set(&value, &val32, sizeof(val32));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_checkpoint_thresh, &value);
if (rc)
return rc;
break;
case DAOS_PROP_PO_REINT_MODE:
val32 = entry->dpe_val;
d_iov_set(&value, &val32, sizeof(val32));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_reint_mode,
&value);
if (rc)
return rc;
break;
case DAOS_PROP_PO_SVC_OPS_ENABLED:
val32 = entry->dpe_val;
d_iov_set(&value, &val32, sizeof(val32));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_svc_ops_enabled, &value);
if (rc)
return rc;
break;
case DAOS_PROP_PO_SVC_OPS_ENTRY_AGE:
val32 = entry->dpe_val;
d_iov_set(&value, &val32, sizeof(val32));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_svc_ops_age, &value);
if (rc)
return rc;
break;
default:
D_ERROR("bad dpe_type %d.\n", entry->dpe_type);
return -DER_INVAL;
}
if (rc) {
D_ERROR("Failed to update entry type=%d, rc="DF_RC"\n",
entry->dpe_type, DP_RC(rc));
break;
}
}
return rc;
}
static int
init_pool_metadata(struct rdb_tx *tx, const rdb_path_t *kvs, uint32_t nnodes, const char *group,
const d_rank_list_t *ranks, daos_prop_t *prop, uint32_t ndomains,
const uint32_t *domains)
{
struct pool_buf *map_buf;
uint32_t map_version = 1;
uint32_t connectable;
uint32_t nhandles = 0;
d_iov_t value;
struct rdb_kvs_attr attr;
int ntargets = nnodes * dss_tgt_nr;
uint32_t upgrade_global_version = DAOS_POOL_GLOBAL_VERSION;
uint32_t svc_ops_enabled = 1;
/* max number of entries in svc_ops KVS: equivalent of max age (sec) x PS_OPS_PER_SEC */
uint32_t svc_ops_age = DAOS_PROP_PO_SVC_OPS_ENTRY_AGE_DEFAULT;
uint32_t svc_ops_max;
uint32_t svc_ops_num;
uint64_t rdb_size;
int rc;
struct daos_prop_entry *entry;
rc = gen_pool_buf(NULL /* map */, &map_buf, map_version, ndomains, nnodes, ntargets,
domains, dss_tgt_nr);
if (rc != 0) {
D_ERROR("failed to generate pool buf, "DF_RC"\n", DP_RC(rc));
goto out;
}
entry = daos_prop_entry_get(prop, DAOS_PROP_PO_REDUN_FAC);
if (entry) {
if (entry->dpe_val + 1 > map_buf->pb_domain_nr) {
D_ERROR("ndomains(%u) could not meet redunc factor(%lu)\n",
map_buf->pb_domain_nr, entry->dpe_val);
D_GOTO(out_map_buf, rc = -DER_INVAL);
}
}
/* Initialize the pool map properties. */
rc = write_map_buf(tx, kvs, map_buf, map_version);
if (rc != 0) {
D_ERROR("failed to write map properties, "DF_RC"\n", DP_RC(rc));
goto out_map_buf;
}
rc = pool_prop_write(tx, kvs, prop);
if (rc != 0) {
D_ERROR("failed to write props, "DF_RC"\n", DP_RC(rc));
goto out_map_buf;
}
/* Write connectable property */
connectable = 1;
d_iov_set(&value, &connectable, sizeof(connectable));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_connectable, &value);
if (rc != 0) {
D_ERROR("failed to write connectable prop, "DF_RC"\n",
DP_RC(rc));
goto out_map_buf;
}
/**
* Firstly write upgrading global version, so resuming could figure
* out what is target global version of upgrading, use this to reject
* resuming pool upgrading if DAOS software upgraded again.
*/
d_iov_set(&value, &upgrade_global_version, sizeof(upgrade_global_version));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_upgrade_global_version, &value);
if (rc != 0) {
D_ERROR("failed to write upgrade global version prop, "DF_RC"\n",
DP_RC(rc));
goto out_map_buf;
}
/* Write the handle properties. */
d_iov_set(&value, &nhandles, sizeof(nhandles));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_nhandles, &value);
if (rc != 0) {
D_ERROR("failed to update handle props, "DF_RC"\n", DP_RC(rc));
goto out_map_buf;
}
attr.dsa_class = RDB_KVS_GENERIC;
attr.dsa_order = 16;
rc = rdb_tx_create_kvs(tx, kvs, &ds_pool_prop_handles, &attr);
if (rc != 0) {
D_ERROR("failed to create handle prop KVS, "DF_RC"\n",
DP_RC(rc));
goto out_map_buf;
}
/* Create pool user attributes KVS */
rc = rdb_tx_create_kvs(tx, kvs, &ds_pool_attr_user, &attr);
if (rc != 0) {
D_ERROR("failed to create user attr KVS, "DF_RC"\n", DP_RC(rc));
goto out_map_buf;
}
/* Create pool service operations KVS */
attr.dsa_class = RDB_KVS_LEXICAL;
attr.dsa_order = 16;
rc = rdb_tx_create_kvs(tx, kvs, &ds_pool_prop_svc_ops, &attr);
if (rc != 0) {
D_ERROR("failed to create service ops KVS, " DF_RC "\n", DP_RC(rc));
goto out_map_buf;
}
/* Determine if duplicate service operations detection will be enabled */
entry = daos_prop_entry_get(prop, DAOS_PROP_PO_SVC_OPS_ENABLED);
if (entry)
svc_ops_enabled = entry->dpe_val;
if (svc_ops_enabled) {
rc = rdb_get_size(tx->dt_db, &rdb_size);
if (rc != 0)
goto out_map_buf;
if (rdb_size < DUP_OP_MIN_RDB_SIZE) {
svc_ops_enabled = 0;
D_WARN("pool duplicate ops detection disabled due to rdb size %zu < %u\n",
rdb_size, DUP_OP_MIN_RDB_SIZE);
}
}
d_iov_set(&value, &svc_ops_enabled, sizeof(svc_ops_enabled));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_svc_ops_enabled, &value);
if (rc != 0) {
DL_ERROR(rc, "failed to set svc_ops_enabled");
goto out_map_buf;
}
/* Maximum number of RPCs that may be kept in svc_ops, from SVC_OPS_ENTRY_AGE property.
* Default: PS_OPS_PER_SEC x DEFAULT_SVC_OPS_ENTRY_AGE_SEC.
*/
entry = daos_prop_entry_get(prop, DAOS_PROP_PO_SVC_OPS_ENTRY_AGE);
if (entry)
svc_ops_age = entry->dpe_val;
svc_ops_max = PS_OPS_PER_SEC * svc_ops_age;
svc_ops_num = 0;
d_iov_set(&value, &svc_ops_age, sizeof(svc_ops_age));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_svc_ops_age, &value);
if (rc != 0) {
DL_ERROR(rc, "failed to set svc_ops_age");
goto out_map_buf;
}
d_iov_set(&value, &svc_ops_max, sizeof(svc_ops_max));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_svc_ops_max, &value);
if (rc != 0) {
DL_ERROR(rc, "failed to set svc_ops_max");
goto out_map_buf;
}
d_iov_set(&value, &svc_ops_num, sizeof(svc_ops_num));
rc = rdb_tx_update(tx, kvs, &ds_pool_prop_svc_ops_num, &value);
if (rc != 0)
DL_ERROR(rc, "failed to set svc_ops_num");
out_map_buf:
pool_buf_free(map_buf);
out:
return rc;
}
/*
* The svc_rf parameter inputs the pool service redundancy factor, while
* ranks->rl_nr outputs how many replicas are actually selected, which may be
* less than the number of replicas required to achieve the pool service
* redundancy factor. If the return value is 0, callers are responsible for
* calling d_rank_list_free(*ranksp).
*/
static int
select_svc_ranks(int svc_rf, struct pool_buf *map_buf, uint32_t map_version,
d_rank_list_t **ranksp)
{
struct pool_map *map;
d_rank_list_t replicas = {0};
d_rank_list_t *to_add;
d_rank_list_t *to_remove;
int rc;
rc = pool_map_create(map_buf, map_version, &map);
if (rc != 0)
return rc;
rc = ds_pool_plan_svc_reconfs(svc_rf, map, &replicas, CRT_NO_RANK /* self */,
false /* filter_only */, &to_add, &to_remove);
pool_map_decref(map);
if (rc != 0)
return rc;
D_ASSERTF(to_remove->rl_nr == 0, "to_remove=%u\n", to_remove->rl_nr);
d_rank_list_free(to_remove);
d_rank_list_sort(to_add);
*ranksp = to_add;
return 0;
}
/* TODO: replace all rsvc_complete_rpc() calls in this file with pool_rsvc_complete_rpc() */
/*
* Returns:
*
* RSVC_CLIENT_RECHOOSE Instructs caller to retry RPC starting from rsvc_client_choose()
* RSVC_CLIENT_PROCEED OK; proceed to process the reply
*/
static int
pool_rsvc_client_complete_rpc(struct rsvc_client *client, const crt_endpoint_t *ep,
int rc_crt, struct pool_op_out *out)
{
int rc;
rc = rsvc_client_complete_rpc(client, ep, rc_crt, out->po_rc, &out->po_hint);
if (rc == RSVC_CLIENT_RECHOOSE ||
(rc == RSVC_CLIENT_PROCEED && daos_rpc_retryable_rc(out->po_rc))) {
return RSVC_CLIENT_RECHOOSE;
}
return RSVC_CLIENT_PROCEED;
}
/**
* Create a (combined) pool(/container) service. This method shall be called on
* a single storage node in the pool. If the return value is 0, the caller is
* responsible for freeing \a svc_addrs with d_rank_list_free.
*
* Note that if the return value is nonzero, the caller is responsible for
* stopping and destroying any PS replicas that may have been created. This
* behavior is tailored for ds_mgmt_create_pool, who will clean up all pool
* resources upon errors.
*
* \param[in] pool_uuid pool UUID
* \param[in] ntargets number of targets in the pool
* \param[in] group crt group ID (unused now)
* \param[in] target_addrs list of \a ntargets target ranks
* \param[in] ndomains number of domains the pool spans over
* \param[in] domains serialized domain tree
* \param[in] prop pool properties (must include a valid
* pool service redundancy factor)
* \param[out] svc_addrs returns the list of pool service
* replica ranks
*/
int
ds_pool_svc_dist_create(const uuid_t pool_uuid, int ntargets, const char *group,
d_rank_list_t *target_addrs, int ndomains, uint32_t *domains,
daos_prop_t *prop, d_rank_list_t **svc_addrs)
{
struct daos_prop_entry *svc_rf_entry;
struct pool_buf *map_buf;
uint32_t map_version = 1;