Motr  M0
iter_ut.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2016-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_UT
24 
25 #include <endian.h> /* htobe64, betoh64 */
26 #include <unistd.h>
27 #include "ut/ut.h"
28 #include "be/ut/helper.h"
29 #include "be/tx.h"
30 #include "pool/pool.h"
31 #include "reqh/reqh.h"
32 #include "reqh/reqh_service.h"
33 #include "dix/cm/cm.h"
34 #include "rpc/rpc_opcodes.h"
35 #include "cas/cas.h"
36 #include "cas/ctg_store.h"
37 #include "dix/cm/iter.h"
38 #include "dix/fid_convert.h"
39 #include "lib/finject.h"
40 #include "lib/trace.h"
41 
42 #define POOL_WIDTH 10
43 #define NODES 10
44 #define DATA_NR 1
45 #define FAILURES_NR 3
46 #define SPARE_NR 3
47 #define DEVS_ID_SHIFT 100
48 
49 static struct m0_reqh reqh;
50 static struct m0_be_ut_backend be;
51 static struct m0_be_seg *seg0;
52 static struct m0_reqh_service *repair_svc;
54 static struct m0_fom_type ut_fom_type;
57 
58 static struct m0_pool pool;
59 static struct m0_pools_common pc;
60 static struct m0_pool_version pv;
61 
62 static struct m0_fid pv_fid = M0_FID_TINIT('v', 1, 1);
63 static int spare_usage_pos = 0;
64 
65 enum {
66  RPC_CUTOFF = 4096
67 };
68 
77 };
78 
88 };
89 
90 struct iter_ut_fom {
92  struct m0_fom iu_fom;
95  struct m0_buf iu_key;
96  struct m0_buf iu_val;
98  struct m0_cas_ctg *iu_ctg;
99  struct m0_cas_id iu_cid;
103 };
104 
106  [ITER_UT_FOM_INIT] = {
108  .sd_name = "init",
109  .sd_allowed = M0_BITS(ITER_UT_FOM_INIT_WAIT)
110  },
112  .sd_name = "init_wait",
113  .sd_allowed = M0_BITS(ITER_UT_FOM_CTIDX_LOCK,
116  },
118  .sd_name = "ctidx-lock",
119  .sd_allowed = M0_BITS(ITER_UT_FOM_EXEC)
120 
121  },
123  .sd_name = "meta-lock",
124  .sd_allowed = M0_BITS(ITER_UT_FOM_EXEC)
125 
126  },
127  [ITER_UT_FOM_EXEC] = {
128  .sd_name = "exec",
129  .sd_allowed = M0_BITS(ITER_UT_FOM_DONE)
130  },
131  [ITER_UT_FOM_DONE] = {
132  .sd_name = "in-progress",
133  .sd_allowed = M0_BITS(ITER_UT_FOM_FINAL,
135  },
137  .sd_name = "tx-commit-wait",
138  .sd_allowed = M0_BITS(ITER_UT_FOM_FINAL)
139  },
140  [ITER_UT_FOM_FINAL] = {
141  .sd_name = "final",
142  .sd_flags = M0_SDF_TERMINAL,
143  },
144 };
145 
146 static const struct m0_sm_conf iter_ut_fom_conf = {
147  .scf_name = "iter_ut_fom",
148  .scf_nr_states = ARRAY_SIZE(iter_ut_fom_phases),
149  .scf_state = iter_ut_fom_phases,
150 };
151 
153 {
154  struct m0_cm *cm = container_of(svc, struct m0_cm,
155  cm_service);
156  struct m0_dix_cm *dix_cm = container_of(cm, struct m0_dix_cm, dcm_base);
157 
158  return &dix_cm->dcm_it;
159 }
160 
161 static void iter_ut_fom_fini(struct m0_fom *fom0)
162 {
163  struct iter_ut_fom *fom = M0_AMB(fom, fom0, iu_fom);
164 
165  m0_long_lock_link_fini(&fom->iu_lock_link);
166  m0_long_lock_link_fini(&fom->iu_del_lock_link);
167 
168  if (fom->iu_op == ITER_UT_OP_CTIDX_INSERT)
169  m0_cas_id_fini(&fom->iu_cid);
170  m0_fom_fini(fom0);
171  m0_semaphore_up(fom->iu_sem);
172 }
173 
174 static uint64_t iter_ut_fom_locality(const struct m0_fom *fom)
175 {
176  return fom->fo_type->ft_id;
177 }
178 
179 static void iter_ut_fom_init(struct iter_ut_fom *fom)
180 {
181  struct m0_be_tx_credit *accum = &fom->iu_fom.fo_tx.tx_betx_cred;
182 
183  m0_long_lock_link_init(&fom->iu_lock_link, &fom->iu_fom, NULL);
184  m0_long_lock_link_init(&fom->iu_del_lock_link, &fom->iu_fom, NULL);
185 
186  if (fom->iu_op == ITER_UT_OP_CTIDX_INSERT ||
187  fom->iu_op == ITER_UT_OP_CTIDX_DELETE) {
188  struct m0_cas_id *cid = &fom->iu_cid;
189  struct m0_dix_ldesc *ldesc = &cid->ci_layout.u.dl_desc;
190 
191  cid->ci_fid = fom->iu_cctg_fid;
194  }
195 
196  if (fom->iu_op != ITER_UT_OP_META_LOOKUP)
197  m0_dtx_init(&fom->iu_fom.fo_tx,
198  m0_fom_reqh(&fom->iu_fom)->rh_beseg->bs_domain,
199  &fom->iu_fom.fo_loc->fl_group);
200 
201  switch (fom->iu_op) {
203  m0_ctg_create_credit(accum);
204  break;
207  break;
209  m0_ctg_ctidx_insert_credits(&fom->iu_cid, accum);
210  break;
212  m0_ctg_ctidx_delete_credits(&fom->iu_cid, accum);
213  break;
215  m0_ctg_insert_credit(fom->iu_ctg, fom->iu_key.b_nob,
216  fom->iu_val.b_nob, accum);
217  break;
219  m0_ctg_delete_credit(fom->iu_ctg, fom->iu_key.b_nob,
220  fom->iu_val.b_nob, accum);
221  break;
223  /* Nothing to do. */
224  break;
225  }
226 }
227 
228 static int iter_ut_fom_exec(struct iter_ut_fom *fom)
229 {
230  struct m0_ctg_op *ctg_op = &fom->iu_ctg_op;
231  struct m0_be_tx *be_tx = &fom->iu_fom.fo_tx.tx_betx;
232  int result;
233 
234  switch (fom->iu_op) {
236  result = m0_ctg_meta_insert(ctg_op, &fom->iu_cctg_fid,
238  M0_UT_ASSERT(result >= 0);
239  break;
241  result = m0_ctg_meta_delete(ctg_op, &fom->iu_cctg_fid,
243  M0_UT_ASSERT(result >= 0);
244  break;
246  result = m0_ctg_meta_lookup(ctg_op, &fom->iu_cctg_fid,
248  break;
250  result = m0_ctg_ctidx_insert_sync(&fom->iu_cid, be_tx);
251  M0_PRE(result == 0);
253  result = M0_FSO_AGAIN;
254  break;
256  result = m0_ctg_ctidx_delete_sync(&fom->iu_cid, be_tx);
257  M0_PRE(result == 0);
259  result = M0_FSO_AGAIN;
260  break;
262  result = m0_ctg_insert(ctg_op, fom->iu_ctg, &fom->iu_key,
263  &fom->iu_val, ITER_UT_FOM_DONE);
264  break;
266  result = m0_ctg_delete(ctg_op, fom->iu_ctg, &fom->iu_key,
268  break;
269  default:
270  M0_IMPOSSIBLE("Incorrect op %d", fom->iu_op);
271  }
272  return result;
273 }
274 
275 static void iter_ut_fom_result(struct iter_ut_fom *fom)
276 {
277  struct m0_ctg_op *ctg_op = &fom->iu_ctg_op;
278  int rc;
279 
280  rc = m0_ctg_op_rc(ctg_op);
281  M0_UT_ASSERT(rc == 0);
282  switch (fom->iu_op) {
289  break;
291  fom->iu_ctg = m0_ctg_meta_lookup_result(ctg_op);
292  }
293 }
294 
295 static int iter_ut_fom_tick(struct m0_fom *fom0)
296 {
297  struct iter_ut_fom *fom = M0_AMB(fom, fom0, iu_fom);
298  int result = M0_FSO_AGAIN;
299 
300  switch (m0_fom_phase(fom0)) {
301  case ITER_UT_FOM_INIT:
303  if (fom->iu_op != ITER_UT_OP_META_LOOKUP)
304  m0_dtx_open(&fom0->fo_tx);
306  break;
308  if (fom->iu_op != ITER_UT_OP_META_LOOKUP) {
309  /* XXX simplified version of fom_tx_wait() */
311  M0_BTS_FAILED);
312  if (M0_IN(m0_be_tx_state(m0_fom_tx(fom0)),
314  m0_fom_wait_on(fom0,
315  &m0_fom_tx(fom0)->t_sm.sm_chan,
316  &fom0->fo_cb);
317  result = M0_FSO_WAIT;
318  break;
319  } else {
320  m0_dtx_opened(&fom0->fo_tx);
321  }
322  }
323  m0_ctg_op_init(&fom->iu_ctg_op, fom0, 0);
324  if (fom->iu_op == ITER_UT_OP_CTIDX_DELETE)
326  m0_ctg_del_lock(),
327  &fom->iu_del_lock_link,
329  else if (fom->iu_op == ITER_UT_OP_META_DELETE)
331  m0_ctg_del_lock(),
332  &fom->iu_del_lock_link,
334  else
336 
337  break;
341  &fom->iu_lock_link,
343  break;
347  &fom->iu_lock_link,
349  break;
350  case ITER_UT_FOM_EXEC:
351  result = iter_ut_fom_exec(fom);
352  break;
353  case ITER_UT_FOM_DONE:
355  m0_ctg_op_fini(&fom->iu_ctg_op);
356  if (fom->iu_op == ITER_UT_OP_CTIDX_DELETE) {
358  &fom->iu_del_lock_link);
360  &fom->iu_lock_link);
361  } else if (fom->iu_op == ITER_UT_OP_META_DELETE) {
363  &fom->iu_del_lock_link);
365  &fom->iu_lock_link);
366  }
367 
368  if (fom->iu_op != ITER_UT_OP_META_LOOKUP) {
369  m0_dtx_done(&fom0->fo_tx);
370  m0_fom_wait_on(fom0, &m0_fom_tx(fom0)->t_sm.sm_chan,
371  &fom0->fo_cb);
373  } else {
375  }
376  result = M0_FSO_WAIT;
377  break;
379  if (m0_be_tx_state(m0_fom_tx(fom0)) == M0_BTS_DONE) {
380  m0_dtx_fini(&fom0->fo_tx);
382  } else {
383  m0_fom_wait_on(fom0, &m0_fom_tx(fom0)->t_sm.sm_chan,
384  &fom0->fo_cb);
385  }
386  result = M0_FSO_WAIT;
387  break;
388  }
389  return result;
390 }
391 
392 static const struct m0_fom_ops iter_ut_fom_ops = {
394  .fo_tick = iter_ut_fom_tick,
395  .fo_home_locality = iter_ut_fom_locality
396 };
397 
398 static const struct m0_fom_type_ops iter_ut_fom_type_ops = {
399  .fto_create = NULL
400 };
401 
402 static void iter_ut_fom_op_sync(struct iter_ut_fom *fom)
403 {
404  struct m0_semaphore sem;
405 
406  m0_semaphore_init(&sem, 0);
408  &reqh);
409  fom->iu_sem = &sem;
410  m0_fom_queue(&fom->iu_fom);
413 }
414 
415 static void iter_ut_fom_op(struct iter_ut_fom *fom, struct m0_semaphore *sem)
416 {
418  NULL, &reqh);
419  fom->iu_sem = sem;
420  m0_fom_queue(&fom->iu_fom);
421 }
422 
423 static void iter_ut_meta_insert(struct m0_fid *cctg_fid)
424 {
425  struct iter_ut_fom fom;
426 
427  M0_SET0(&fom);
428  fom.iu_cctg_fid = *cctg_fid;
429  fom.iu_op = ITER_UT_OP_META_INSERT;
431 }
432 
433 static struct m0_cas_ctg *iter_ut_meta_lookup(struct m0_fid *cctg_fid)
434 {
435  struct iter_ut_fom fom;
436 
437  M0_SET0(&fom);
438  fom.iu_cctg_fid = *cctg_fid;
439  fom.iu_op = ITER_UT_OP_META_LOOKUP;
441  return fom.iu_ctg;
442 }
443 
444 static void iter_ut_ctidx_insert(struct m0_fid *cctg_fid)
445 {
446  struct iter_ut_fom fom;
447 
448  M0_SET0(&fom);
449  fom.iu_cctg_fid = *cctg_fid;
452 }
453 
455  struct m0_fid *cctg_fid,
456  struct m0_semaphore *sem)
457 {
458  M0_SET0(fom);
459  fom->iu_cctg_fid = *cctg_fid;
460  fom->iu_op = ITER_UT_OP_META_DELETE;
462 }
463 
465  struct m0_fid *cctg_fid,
466  struct m0_semaphore *sem)
467 {
468  M0_SET0(fom);
469  fom->iu_cctg_fid = *cctg_fid;
470  fom->iu_op = ITER_UT_OP_CTIDX_DELETE;
472 }
473 
474 static void iter_ut_insert(struct m0_cas_ctg *cctg, uint64_t key, uint64_t val)
475 {
476  struct iter_ut_fom fom;
477  struct m0_buf kbuf = {};
478  struct m0_buf vbuf = {};
479  int rc;
480 
481  M0_SET0(&fom);
482  rc = m0_buf_alloc(&kbuf, sizeof(key));
483  m0_buf_alloc(&vbuf, sizeof(val));
484  M0_UT_ASSERT(rc == 0);
485  *(uint64_t *)kbuf.b_addr = htobe64(key);
486  *(uint64_t *)vbuf.b_addr = htobe64(val);
487  fom.iu_ctg = cctg;
488  fom.iu_key = kbuf;
489  fom.iu_val = vbuf;
490  fom.iu_op = ITER_UT_OP_KV_INSERT;
492  m0_buf_free(&kbuf);
493  m0_buf_free(&vbuf);
494 }
495 
496 static void iter_ut_delete(struct m0_cas_ctg *cctg, uint64_t key, uint64_t val)
497 {
498  struct iter_ut_fom fom;
499  struct m0_buf kbuf = {};
500  struct m0_buf vbuf = {};
501  int rc;
502 
503  M0_SET0(&fom);
504  rc = m0_buf_alloc(&kbuf, sizeof(key));
505  m0_buf_alloc(&vbuf, sizeof(val));
506  M0_UT_ASSERT(rc == 0);
507  *(uint64_t *)kbuf.b_addr = htobe64(key);
508  *(uint64_t *)vbuf.b_addr = htobe64(val);
509  fom.iu_ctg = cctg;
510  fom.iu_key = kbuf;
511  fom.iu_val = vbuf;
512  fom.iu_op = ITER_UT_OP_KV_DELETE;
514  m0_buf_free(&kbuf);
515  m0_buf_free(&vbuf);
516 }
517 
518 static void device_state_set(uint64_t pool_device_id,
519  int dev_state)
520 {
521  struct m0_pooldev *pdev;
522  struct m0_poolmach_state *state;
523 
524  state = pv.pv_mach.pm_state;
525  pdev = &state->pst_devices_array[pool_device_id];
526  pdev->pd_state = dev_state;
527 }
528 
529 static void device_repaired_set(uint64_t pool_device_id)
530 {
531  struct m0_pool_spare_usage *spare_usage_array;
532  struct m0_pool_spare_usage *spare_usage_item;
533 
534  device_state_set(pool_device_id, M0_PNDS_SNS_REPAIRED);
535 
536  spare_usage_array = pv.pv_mach.pm_state->pst_spare_usage_array;
537  spare_usage_item = &spare_usage_array[spare_usage_pos];
538  spare_usage_item->psu_device_index = (uint32_t)pool_device_id;
539  spare_usage_item->psu_device_state = M0_PNDS_SNS_REPAIRED;
540  spare_usage_pos++;
541 }
542 
543 static void device_repairing_set(uint64_t pool_device_id)
544 {
545  struct m0_pool_spare_usage *spare_usage_array;
546  struct m0_pool_spare_usage *spare_usage_item;
547 
548  device_state_set(pool_device_id, M0_PNDS_SNS_REPAIRING);
549 
550  spare_usage_array = pv.pv_mach.pm_state->pst_spare_usage_array;
551  spare_usage_item = &spare_usage_array[spare_usage_pos];
552  spare_usage_item->psu_device_index = (uint32_t)pool_device_id;
553  spare_usage_item->psu_device_state = M0_PNDS_SNS_REPAIRING;
554  spare_usage_pos++;
555 }
556 
557 static void device_rebalancing_set(uint64_t pool_device_id)
558 {
559  struct m0_pool_spare_usage *spare_usage_array;
560  struct m0_pool_spare_usage *spare_usage_item;
561 
562  device_state_set(pool_device_id, M0_PNDS_SNS_REBALANCING);
563 
564  spare_usage_array = pv.pv_mach.pm_state->pst_spare_usage_array;
565  spare_usage_item = &spare_usage_array[spare_usage_pos];
566  spare_usage_item->psu_device_index = (uint32_t)pool_device_id;
567  spare_usage_item->psu_device_state = M0_PNDS_SNS_REBALANCING;
568  spare_usage_pos++;
569 }
570 
572 {
573  struct m0_pool_spare_usage *spare_usage_array;
574  struct m0_pool_spare_usage *spare_usage_item;
575 
576  spare_usage_array = pv.pv_mach.pm_state->pst_spare_usage_array;
577  spare_usage_item = &spare_usage_array[spare_usage_pos];
578  spare_usage_item->psu_device_index = POOL_PM_SPARE_SLOT_UNUSED;
579  spare_usage_item->psu_device_state = 0;
580  spare_usage_pos++;
581 }
582 
583 static void iter_ut_devs_setup()
584 {
585  uint32_t i;
586  struct m0_pooldev *pdev;
587  struct m0_poolmach_state *state;
588 
589  state = pv.pv_mach.pm_state;
590  for (i = 0; i < state->pst_nr_devices; i++) {
591  pdev = &state->pst_devices_array[i];
592  pdev->pd_state = M0_PNDS_ONLINE;
593  pdev->pd_id = M0_FID_TINIT('d', 1, i);
594  pdev->pd_sdev_idx = i + DEVS_ID_SHIFT;
595  pdev->pd_index = i;
596  }
597 }
598 
599 static void iter_ut_pool_init()
600 {
601  int result;
602  struct m0_fid p_fid = { .f_key = 1 };
603 
604  result = m0_pool_init(&pool, &p_fid, 0);
605  M0_UT_ASSERT(result == 0);
606  result = m0_pool_version_init(&pv,
607  &pv_fid,
608  &pool,
609  POOL_WIDTH,
610  NODES,
611  DATA_NR,
612  FAILURES_NR,
613  SPARE_NR);
614  M0_UT_ASSERT(result == 0);
619  pool_version_tlist_add(&pool.po_vers, &pv);
620  pools_tlist_init(&pc.pc_pools);
621  pools_tlink_init_at_tail(&pool, &pc.pc_pools);
622 }
623 
624 static void iter_ut_reqh_init(void)
625 {
626  int result;
627 
628  M0_SET0(&reqh);
629  M0_SET0(&be);
632  result = M0_REQH_INIT(&reqh,
633  .rhia_db = seg0,
634  .rhia_mdstore = (void *)1,
635  .rhia_fid = &g_process_fid,
636  .rhia_pc = &pc
637  );
638  M0_UT_ASSERT(result == 0);
639  result = m0_layout_init_by_pver(&reqh.rh_ldom, &pv, NULL);
640  M0_UT_ASSERT(result == 0);
643 }
644 
645 
646 static void iter_ut_init(struct m0_reqh_service **svc,
647  struct m0_reqh_service_type *stype)
648 {
649  int result;
650 
651  spare_usage_pos = 0;
652 
653  m0_fi_enable("cas_in_ut", "ut");
654 
657  NULL);
658  M0_UT_ASSERT(result == 0);
663 
664  if (stype == &dix_repair_cmt.ct_stype) {
665  /* If a fom type called m0_fom_type_init() once,
666  * it has already registered. And another call
667  * won't change its type. So we have to use another
668  * variable to switch between different fom types.
669  */
675  } else {
681  }
682 }
683 
684 static void iter_ut_pool_fini()
685 {
686  pools_tlink_del_fini(&pool);
687  pools_tlist_fini(&pc.pc_pools);
688  pool_version_tlist_del(&pv);
690  m0_pool_fini(&pool);
691 }
692 
693 static void iter_ut_reqh_fini()
694 {
698 }
699 
700 static void iter_ut_fini(struct m0_reqh_service *svc)
701 {
709  m0_fi_disable("cas_in_ut", "ut");
710 }
711 
712 static void start_stop(void)
713 {
714  struct m0_dix_cm_iter *iter;
715  int rc;
716 
718  iter = iter_ut_iter(repair_svc);
719  M0_SET0(iter);
721  M0_ASSERT(rc == 0);
722  m0_dix_cm_iter_stop(iter);
724 }
725 
726 static int iter_ut_next_sync(struct m0_dix_cm_iter *iter,
727  struct m0_buf *key,
728  struct m0_buf *val,
729  uint32_t *sdev_id)
730 {
731  struct m0_clink clink;
732 
733  M0_SET0(key);
734  M0_SET0(val);
735 
738  m0_dix_cm_iter_next(iter);
742  return m0_dix_cm_iter_get(iter, key, val, sdev_id);
743 }
744 
745 static void empty_store(void)
746 {
747  struct m0_dix_cm_iter *iter;
748  struct m0_buf key;
749  struct m0_buf val;
750  uint32_t sdev_id;
751  int rc;
752 
754  iter = iter_ut_iter(repair_svc);
755  M0_SET0(iter);
757  M0_ASSERT(rc == 0);
758  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
759  M0_ASSERT(rc == -ENODATA);
760  m0_dix_cm_iter_stop(iter);
762 }
763 
764 static void empty_cctg(void)
765 {
766  struct m0_dix_cm_iter *iter;
767  struct m0_fid cctg_fid0 = M0_FID_TINIT('T', 1, 0);
768  struct m0_fid cctg_fid1 = M0_FID_TINIT('T', 1, 1);
769  struct m0_buf key;
770  struct m0_buf val;
771  uint32_t sdev_id;
772  int rc;
773 
775  iter_ut_meta_insert(&cctg_fid0);
776  iter_ut_ctidx_insert(&cctg_fid0);
777  iter_ut_meta_insert(&cctg_fid1);
778  iter_ut_ctidx_insert(&cctg_fid1);
779  iter = iter_ut_iter(repair_svc);
780  M0_SET0(iter);
782  M0_ASSERT(rc == 0);
783  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
784  M0_ASSERT(rc == -ENODATA);
785  m0_dix_cm_iter_stop(iter);
787 }
788 
789 static void cctg_not_found(void)
790 {
791  struct m0_dix_cm_iter *iter;
792  struct m0_fid cctg_fid = M0_FID_TINIT('T', 1, 0);
793  struct m0_buf key;
794  struct m0_buf val;
795  uint32_t sdev_id;
796  int rc;
797 
799  iter = iter_ut_iter(repair_svc);
800  /*
801  * Don't insert component catalogue into meta.
802  * Iterator should return error.
803  */
804  iter_ut_ctidx_insert(&cctg_fid);
805  M0_SET0(iter);
807  M0_ASSERT(rc == 0);
808  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
809  M0_ASSERT(rc == -ENOENT);
810  m0_dix_cm_iter_stop(iter);
812 }
813 
814 static uint64_t buf_value(const struct m0_buf *buf)
815 {
816  return be64toh(*(uint64_t *)buf->b_addr);
817 }
818 
819 
820 static void one_rec(void)
821 {
822  struct m0_dix_cm_iter *iter;
823  struct m0_fid cctg_fid = M0_FID_TINIT('T', 1, 0);
824  struct m0_cas_ctg *cctg;
825  struct m0_buf key;
826  struct m0_buf val;
827  uint32_t sdev_id;
828  int rc;
829 
831  iter = iter_ut_iter(repair_svc);
832  iter_ut_ctidx_insert(&cctg_fid);
833  iter_ut_meta_insert(&cctg_fid);
834  cctg = iter_ut_meta_lookup(&cctg_fid);
835  iter_ut_insert(cctg, 10, 20);
836  M0_SET0(iter);
838  M0_ASSERT(rc == 0);
839  m0_fi_enable_once("dix_cm_is_repair_coordinator", "always_coordinator");
840  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
841  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
842  M0_ASSERT(rc == 0);
843  M0_UT_ASSERT(buf_value(&key) == 10);
844  M0_UT_ASSERT(buf_value(&val) == 20);
845  m0_buf_free(&key);
846  m0_buf_free(&val);
847  m0_fi_enable_once("dix_cm_is_repair_coordinator", "always_coordinator");
848  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
849  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
850  M0_ASSERT(rc == -ENODATA);
851  m0_dix_cm_iter_stop(iter);
853  m0_fi_disable("dix_cm_is_repair_coordinator", "always_coordinator");
854  m0_fi_disable("dix_cm_repair_tgts_get", "single_target");
855 }
856 
857 static void multi_rec(void)
858 {
859  enum {
860  CCTG_COUNT = 10,
861  REC_COUNT = 20,
862  };
863 
864  struct m0_dix_cm_iter *iter;
865  struct m0_fid cctg_fid;
866  struct m0_cas_ctg *cctg;
867  struct m0_buf key;
868  struct m0_buf val;
869  uint32_t sdev_id;
870  int i;
871  int j;
872  int rc;
873 
875  iter = iter_ut_iter(repair_svc);
876  for (i = 0; i < CCTG_COUNT; i++) {
877  cctg_fid = M0_FID_TINIT('T', 1, i);
878  iter_ut_ctidx_insert(&cctg_fid);
879  iter_ut_meta_insert(&cctg_fid);
880  cctg = iter_ut_meta_lookup(&cctg_fid);
881  for (j = 0; j < REC_COUNT; j++)
882  iter_ut_insert(cctg, 100 * i + j, j * j);
883  }
884  M0_SET0(iter);
886  M0_ASSERT(rc == 0);
887  for (i = 0; i < CCTG_COUNT; i++) {
888  for (j = 0; j < REC_COUNT; j++) {
889  m0_fi_enable_once("dix_cm_is_repair_coordinator",
890  "always_coordinator");
891  m0_fi_enable_once("dix_cm_repair_tgts_get",
892  "single_target");
893  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
894  M0_ASSERT(rc == 0);
895  M0_UT_ASSERT(buf_value(&key) == 100 * i + j);
896  M0_UT_ASSERT(buf_value(&val) == j * j);
897  m0_buf_free(&key);
898  m0_buf_free(&val);
899  }
900  }
901  m0_fi_enable_once("dix_cm_is_repair_coordinator", "always_coordinator");
902  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
903  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
904  M0_ASSERT(rc == -ENODATA);
905  m0_dix_cm_iter_stop(iter);
907  m0_fi_disable("dix_cm_is_repair_coordinator", "always_coordinator");
908  m0_fi_disable("dix_cm_repair_tgts_get", "single_target");
909 }
910 
911 static void rep_coordinator(void)
912 {
913  struct m0_dix_cm_iter *iter;
914  struct m0_fid dix_fid;
915  struct m0_fid cctg_fid;
916  struct m0_cas_ctg *cctg;
917  struct m0_buf key;
918  struct m0_buf val;
919  uint32_t sdev_id;
920  int rc;
921 
922  m0_fi_enable("m0_dix_target", "pdcluster-map");
923 /*
924  * Parity group info for key 10 (pool dev_id/global dev_id):
925  * =============================================
926  * 0: dev_id: 4/104, data, online, (local)
927  * 1: dev_id: 9/109, parity, online
928  * 2: dev_id: 6/106, parity, online
929  * 3: dev_id: 5/105, parity, online
930  * 4: dev_id: 1/101, spare, online
931  * 5: dev_id: 0/100, spare, online
932  * 6: dev_id: 7/107, spare, online
933  * =============================================
934  */
935  /* A coordinator, the first in the parity group. */
937  iter = iter_ut_iter(repair_svc);
938  m0_dix_fid_dix_make(&dix_fid, 1, 0);
940  &cctg_fid,
941  104);
942  iter_ut_ctidx_insert(&cctg_fid);
943  iter_ut_meta_insert(&cctg_fid);
944  cctg = iter_ut_meta_lookup(&cctg_fid);
945  iter_ut_insert(cctg, 10, 20);
946  M0_SET0(iter);
948  M0_ASSERT(rc == 0);
949  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
950  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
951  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
952  M0_ASSERT(rc == 0);
953  M0_UT_ASSERT(buf_value(&key) == 10);
954  M0_UT_ASSERT(buf_value(&val) == 20);
955  m0_buf_free(&key);
956  m0_buf_free(&val);
957  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
958  M0_ASSERT(rc == -ENODATA);
959  m0_dix_cm_iter_stop(iter);
961 
962 /*
963  * Parity group info for key 10 (pool dev_id/global dev_id):
964  * =============================================
965  * 0: dev_id: 4/104, data, failed
966  * 1: dev_id: 9/109, parity, failed
967  * 2: dev_id: 6/106, parity, online, (local)
968  * 3: dev_id: 5/105, parity, online
969  * 4: dev_id: 1/101, spare, online
970  * 5: dev_id: 0/100, spare, online
971  * 6: dev_id: 7/107, spare, online
972  * =============================================
973  */
974  /* A coordinator, not the first in the parity group. */
976  iter = iter_ut_iter(repair_svc);
977  m0_dix_fid_dix_make(&dix_fid, 1, 0);
979  &cctg_fid,
980  106);
981  iter_ut_ctidx_insert(&cctg_fid);
982  iter_ut_meta_insert(&cctg_fid);
983  cctg = iter_ut_meta_lookup(&cctg_fid);
984  iter_ut_insert(cctg, 10, 20);
987  M0_SET0(iter);
989  M0_ASSERT(rc == 0);
990  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
991  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
992  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
993  M0_ASSERT(rc == 0);
994  M0_UT_ASSERT(buf_value(&key) == 10);
995  M0_UT_ASSERT(buf_value(&val) == 20);
996  m0_buf_free(&key);
997  m0_buf_free(&val);
998  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
999  M0_ASSERT(rc == -ENODATA);
1000  m0_dix_cm_iter_stop(iter);
1002 
1003 /*
1004  * Parity group info for key 10 (pool dev_id/global dev_id):
1005  * =============================================
1006  * 0: dev_id: 4/104, data, online
1007  * 1: dev_id: 9/109, parity, online, (local)
1008  * 2: dev_id: 6/106, parity, online
1009  * 3: dev_id: 5/105, parity, online
1010  * 4: dev_id: 1/101, spare, online
1011  * 5: dev_id: 0/100, spare, online
1012  * 6: dev_id: 7/107, spare, online
1013  * =============================================
1014  */
1015  /* Not a coordinator, not the first in the parity group. */
1017  iter = iter_ut_iter(repair_svc);
1018  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1019  m0_dix_fid_convert_dix2cctg(&dix_fid,
1020  &cctg_fid,
1021  109);
1022  iter_ut_ctidx_insert(&cctg_fid);
1023  iter_ut_meta_insert(&cctg_fid);
1024  cctg = iter_ut_meta_lookup(&cctg_fid);
1025  iter_ut_insert(cctg, 10, 20);
1026  M0_SET0(iter);
1028  M0_ASSERT(rc == 0);
1029  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1030  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
1031  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1032  M0_ASSERT(rc == -ENODATA);
1033  m0_dix_cm_iter_stop(iter);
1035  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
1036  m0_fi_disable("dix_cm_repair_tgts_get", "single_target");
1037 
1038 /*
1039  * Parity group info for key 10 (pool dev_id/global dev_id):
1040  * =============================================
1041  * 0: dev_id: 4/104, data, failed
1042  * 1: dev_id: 9/109, parity, failed
1043  * 2: dev_id: 6/106, parity, failed
1044  * 3: dev_id: 5/105, parity, failed
1045  * 4: dev_id: 1/101, spare, online, (local)
1046  * 5: dev_id: 0/100, spare, online
1047  * 6: dev_id: 7/107, spare, online
1048  * =============================================
1049  */
1050  /* Not a coordinator, serves spare unit. */
1052  iter = iter_ut_iter(repair_svc);
1053  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1054  m0_dix_fid_convert_dix2cctg(&dix_fid,
1055  &cctg_fid,
1056  101);
1057  iter_ut_ctidx_insert(&cctg_fid);
1058  iter_ut_meta_insert(&cctg_fid);
1059  cctg = iter_ut_meta_lookup(&cctg_fid);
1060  iter_ut_insert(cctg, 10, 20);
1065  M0_SET0(iter);
1067  M0_ASSERT(rc == 0);
1068  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1069  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
1070  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1071  M0_ASSERT(rc == -ENODATA);
1072  m0_dix_cm_iter_stop(iter);
1074  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
1075  m0_fi_disable("dix_cm_repair_tgts_get", "single_target");
1076 }
1077 
1078 static void one_dev_fail(void)
1079 {
1080  struct m0_dix_cm_iter *iter;
1081  struct m0_fid dix_fid;
1082  struct m0_fid cctg_fid;
1083  struct m0_cas_ctg *cctg;
1084  struct m0_buf key;
1085  struct m0_buf val;
1086  uint32_t sdev_id;
1087  int rc;
1088 
1089 /*
1090  * Parity group info for key 10 (pool dev_id/global dev_id):
1091  * =============================================
1092  * 0: dev_id: 4/104, data, repairing
1093  * 1: dev_id: 9/109, parity, online, (local)
1094  * 2: dev_id: 6/106, parity, online
1095  * 3: dev_id: 5/105, parity, online
1096  * 4: dev_id: 1/101, spare, online
1097  * 5: dev_id: 0/100, spare, online
1098  * 6: dev_id: 7/107, spare, online
1099  * =============================================
1100  *
1101  * Spare usage array info (pool dev_id/global dev_id):
1102  * =============================================
1103  * 0: dev_id: 4/104, repairing, served by:
1104  * dev_id: 1/101, online
1105  * 1: slot unused, served by:
1106  * dev_id: 0/100, online
1107  * 2: slot unused, served by:
1108  * dev_id: 7/107, online
1109  * =============================================
1110  *
1111  * Targets for key 10 (pool dev_id/global dev_id):
1112  * =============================================
1113  * 1: dev_id: 1/101
1114  * =============================================
1115  */
1116 
1118  iter = iter_ut_iter(repair_svc);
1119  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1120  m0_dix_fid_convert_dix2cctg(&dix_fid,
1121  &cctg_fid,
1122  109);
1123  iter_ut_ctidx_insert(&cctg_fid);
1124  iter_ut_meta_insert(&cctg_fid);
1125  cctg = iter_ut_meta_lookup(&cctg_fid);
1126  iter_ut_insert(cctg, 10, 20);
1128  M0_SET0(iter);
1130  M0_ASSERT(rc == 0);
1131  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1132  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1133  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1134  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1135  M0_ASSERT(rc == 0);
1136  M0_UT_ASSERT(buf_value(&key) == 10);
1137  M0_UT_ASSERT(buf_value(&val) == 20);
1138  M0_UT_ASSERT(sdev_id == 101);
1139  m0_buf_free(&key);
1140  m0_buf_free(&val);
1141  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1142  M0_ASSERT(rc == -ENODATA);
1143  m0_dix_cm_iter_stop(iter);
1145  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
1146  m0_fi_disable("dix_cm_iter_next_key", "print_spare_usage");
1147  m0_fi_disable("dix_cm_iter_next_key", "print_targets");
1148 }
1149 
1150 static void two_devs_fail(void)
1151 {
1152  struct m0_dix_cm_iter *iter;
1153  struct m0_fid dix_fid;
1154  struct m0_fid cctg_fid;
1155  struct m0_cas_ctg *cctg;
1156  struct m0_buf key;
1157  struct m0_buf val;
1158  uint32_t sdev_id;
1159  int rc;
1160 
1161 /*
1162  * Parity group info for key 10 (pool dev_id/global dev_id):
1163  * =============================================
1164  * 0: dev_id: 4/104, data, repairing
1165  * 1: dev_id: 9/109, parity, online, (local)
1166  * 2: dev_id: 6/106, parity, online
1167  * 3: dev_id: 5/105, parity, repairing
1168  * 4: dev_id: 1/101, spare, online
1169  * 5: dev_id: 0/100, spare, online
1170  * 6: dev_id: 7/107, spare, online
1171  * =============================================
1172  *
1173  * Spare usage array info (pool dev_id/global dev_id):
1174  * =============================================
1175  * 0: dev_id: 4/104, repairing, served by:
1176  * dev_id: 1/101, online
1177  * 1: dev_id: 5/105, repairing, served by:
1178  * dev_id: 0/100, online
1179  * 2: slot unused, served by:
1180  * dev_id: 7/107, online
1181  * =============================================
1182  *
1183  * Targets for key 10 (pool dev_id/global dev_id):
1184  * =============================================
1185  * 1: dev_id: 1/101
1186  * 2: dev_id: 0/100
1187  * =============================================
1188  */
1189 
1191  iter = iter_ut_iter(repair_svc);
1192  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1193  m0_dix_fid_convert_dix2cctg(&dix_fid,
1194  &cctg_fid,
1195  109);
1196  iter_ut_ctidx_insert(&cctg_fid);
1197  iter_ut_meta_insert(&cctg_fid);
1198  cctg = iter_ut_meta_lookup(&cctg_fid);
1199  iter_ut_insert(cctg, 10, 20);
1202  M0_SET0(iter);
1204  M0_ASSERT(rc == 0);
1205  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1206  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1207  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1208  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1209  M0_ASSERT(rc == 0);
1210  M0_UT_ASSERT(buf_value(&key) == 10);
1211  M0_UT_ASSERT(buf_value(&val) == 20);
1212  M0_UT_ASSERT(sdev_id == 101);
1213  m0_buf_free(&key);
1214  m0_buf_free(&val);
1215  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1216  M0_ASSERT(rc == 0);
1217  M0_UT_ASSERT(buf_value(&key) == 10);
1218  M0_UT_ASSERT(buf_value(&val) == 20);
1219  M0_UT_ASSERT(sdev_id == 100);
1220  m0_buf_free(&key);
1221  m0_buf_free(&val);
1222  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1223  M0_ASSERT(rc == -ENODATA);
1224  m0_dix_cm_iter_stop(iter);
1226  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
1227  m0_fi_disable("dix_cm_iter_next_key", "print_spare_usage");
1228  m0_fi_disable("dix_cm_iter_next_key", "print_targets");
1229 }
1230 
1231 static void outside_dev_fail(void)
1232 {
1233  struct m0_dix_cm_iter *iter;
1234  struct m0_fid dix_fid;
1235  struct m0_fid cctg_fid;
1236  struct m0_cas_ctg *cctg;
1237  struct m0_buf key;
1238  struct m0_buf val;
1239  uint32_t sdev_id;
1240  int rc;
1241 
1242 /*
1243  * Parity group info for key 10 (pool dev_id/global dev_id):
1244  * =============================================
1245  * 0: dev_id: 4/104, data, online, (local)
1246  * 1: dev_id: 9/109, parity, online
1247  * 2: dev_id: 6/106, parity, online
1248  * 3: dev_id: 5/105, parity, online
1249  * 4: dev_id: 1/101, spare, online
1250  * 5: dev_id: 0/100, spare, online
1251  * 6: dev_id: 7/107, spare, online
1252  * =============================================
1253  *
1254  * Spare usage array info (pool dev_id/global dev_id):
1255  * =============================================
1256  * 0: dev_id: 3/103, repairing, served by:
1257  * dev_id: 1/101, online
1258  * 1: slot unused, served by:
1259  * dev_id: 0/100, online
1260  * 2: slot unused, served by:
1261  * dev_id: 7/107, online
1262  * =============================================
1263  */
1265  iter = iter_ut_iter(repair_svc);
1266  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1267  m0_dix_fid_convert_dix2cctg(&dix_fid,
1268  &cctg_fid,
1269  104);
1270  iter_ut_ctidx_insert(&cctg_fid);
1271  iter_ut_meta_insert(&cctg_fid);
1272  cctg = iter_ut_meta_lookup(&cctg_fid);
1273  iter_ut_insert(cctg, 10, 20);
1275  M0_SET0(iter);
1277  M0_ASSERT(rc == 0);
1278  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1279  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1280  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1281  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1282  M0_ASSERT(rc == -ENODATA);
1283  m0_dix_cm_iter_stop(iter);
1285 
1286 /*
1287  * Parity group info for key 10 (pool dev_id/global dev_id):
1288  * =============================================
1289  * 0: dev_id: 4/104, data, online, (local)
1290  * 1: dev_id: 9/109, parity, repairing
1291  * 2: dev_id: 6/106, parity, online
1292  * 3: dev_id: 5/105, parity, online
1293  * 4: dev_id: 1/101, spare, online
1294  * 5: dev_id: 0/100, spare, online
1295  * 6: dev_id: 7/107, spare, online
1296  * =============================================
1297  *
1298  * Spare usage array info (pool dev_id/global dev_id):
1299  * =============================================
1300  * 0: dev_id: 3/103, repairing, served by:
1301  * dev_id: 1/101, online
1302  * 1: dev_id: 9/109, repairing, served by:
1303  * dev_id: 0/100, online
1304  * 2: slot unused, served by:
1305  * dev_id: 7/107, online
1306  * =============================================
1307  *
1308  * Targets for key 10 (pool dev_id/global dev_id):
1309  * =============================================
1310  * 1: dev_id: 0/100
1311  * =============================================
1312  */
1314  iter = iter_ut_iter(repair_svc);
1315  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1316  m0_dix_fid_convert_dix2cctg(&dix_fid,
1317  &cctg_fid,
1318  104);
1319  iter_ut_ctidx_insert(&cctg_fid);
1320  iter_ut_meta_insert(&cctg_fid);
1321  cctg = iter_ut_meta_lookup(&cctg_fid);
1322  iter_ut_insert(cctg, 10, 20);
1325  M0_SET0(iter);
1327  M0_ASSERT(rc == 0);
1328  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1329  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1330  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1331  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1332  M0_ASSERT(rc == 0);
1333  M0_UT_ASSERT(buf_value(&key) == 10);
1334  M0_UT_ASSERT(buf_value(&val) == 20);
1335  M0_UT_ASSERT(sdev_id == 100);
1336  m0_buf_free(&key);
1337  m0_buf_free(&val);
1338  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1339  M0_ASSERT(rc == -ENODATA);
1340  m0_dix_cm_iter_stop(iter);
1342 
1343 /*
1344  * Parity group info for key 10 (pool dev_id/global dev_id):
1345  * =============================================
1346  * 0: dev_id: 4/104, data, online, (local)
1347  * 1: dev_id: 9/109, parity, repairing
1348  * 2: dev_id: 6/106, parity, online
1349  * 3: dev_id: 5/105, parity, online
1350  * 4: dev_id: 1/101, spare, repairing
1351  * 5: dev_id: 0/100, spare, online
1352  * 6: dev_id: 7/107, spare, online
1353  * =============================================
1354  *
1355  * Spare usage array info (pool dev_id/global dev_id):
1356  * =============================================
1357  * 0: dev_id: 3/103, repaired, served by:
1358  * dev_id: 1/101, repairing
1359  * 1: dev_id: 1/101, repairing, served by:
1360  * dev_id: 0/100, online
1361  * 2: dev_id: 9/109, repairing, served by:
1362  * dev_id: 7/107, online
1363  * =============================================
1364  *
1365  * Targets for key 10 (pool dev_id/global dev_id):
1366  * =============================================
1367  * 1: dev_id: 7/107
1368  * =============================================
1369  */
1371  iter = iter_ut_iter(repair_svc);
1372  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1373  m0_dix_fid_convert_dix2cctg(&dix_fid,
1374  &cctg_fid,
1375  104);
1376  iter_ut_ctidx_insert(&cctg_fid);
1377  iter_ut_meta_insert(&cctg_fid);
1378  cctg = iter_ut_meta_lookup(&cctg_fid);
1379  iter_ut_insert(cctg, 10, 20);
1383  M0_SET0(iter);
1385  M0_ASSERT(rc == 0);
1386  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1387  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1388  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1389  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1390  M0_ASSERT(rc == 0);
1391  M0_UT_ASSERT(buf_value(&key) == 10);
1392  M0_UT_ASSERT(buf_value(&val) == 20);
1393  M0_UT_ASSERT(sdev_id == 107);
1394  m0_buf_free(&key);
1395  m0_buf_free(&val);
1396  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1397  M0_ASSERT(rc == -ENODATA);
1398  m0_dix_cm_iter_stop(iter);
1400  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
1401  m0_fi_disable("dix_cm_iter_next_key", "print_spare_usage");
1402  m0_fi_disable("dix_cm_iter_next_key", "print_targets");
1403 }
1404 
1405 static void empty_spare_fail(void)
1406 {
1407  struct m0_dix_cm_iter *iter;
1408  struct m0_fid dix_fid;
1409  struct m0_fid cctg_fid;
1410  struct m0_cas_ctg *cctg;
1411  struct m0_buf key;
1412  struct m0_buf val;
1413  uint32_t sdev_id;
1414  int rc;
1415 
1416 /*
1417  * Parity group info for key 10 (pool dev_id/global dev_id):
1418  * =============================================
1419  * 0: dev_id: 4/104, data, online, (local)
1420  * 1: dev_id: 9/109, parity, online
1421  * 2: dev_id: 6/106, parity, online
1422  * 3: dev_id: 5/105, parity, online
1423  * 4: dev_id: 1/101, spare, online
1424  * 5: dev_id: 0/100, spare, repairing
1425  * 6: dev_id: 7/107, spare, online
1426  * =============================================
1427  *
1428  * Spare usage array info (pool dev_id/global dev_id):
1429  * =============================================
1430  * 0: dev_id: 0/100, repairing, served by:
1431  * dev_id: 1/101, online
1432  * 1: slot unused, served by:
1433  * dev_id: 0/100, repairing
1434  * 2: slot unused, served by:
1435  * dev_id: 7/107, online
1436  * =============================================
1437  */
1439  iter = iter_ut_iter(repair_svc);
1440  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1441  m0_dix_fid_convert_dix2cctg(&dix_fid,
1442  &cctg_fid,
1443  104);
1444  iter_ut_ctidx_insert(&cctg_fid);
1445  iter_ut_meta_insert(&cctg_fid);
1446  cctg = iter_ut_meta_lookup(&cctg_fid);
1447  iter_ut_insert(cctg, 10, 20);
1449  M0_SET0(iter);
1451  M0_ASSERT(rc == 0);
1452  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1453  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1454  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1455  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1456  M0_ASSERT(rc == -ENODATA);
1457  m0_dix_cm_iter_stop(iter);
1459 
1460 /*
1461  * Parity group info for key 10 (pool dev_id/global dev_id):
1462  * =============================================
1463  * 0: dev_id: 4/104, data, online, (local)
1464  * 1: dev_id: 9/109, parity, online
1465  * 2: dev_id: 6/106, parity, online
1466  * 3: dev_id: 5/105, parity, online
1467  * 4: dev_id: 1/101, spare, repaired
1468  * 5: dev_id: 0/100, spare, repairing
1469  * 6: dev_id: 7/107, spare, online
1470  * =============================================
1471  *
1472  * Spare usage array info (pool dev_id/global dev_id):
1473  * =============================================
1474  * 0: dev_id: 1/101, repaired, served by:
1475  * dev_id: 1/101, repaired
1476  * 1: dev_id: 0/100, repairing, served by:
1477  * dev_id: 0/100, repairing
1478  * 2: slot unused, served by:
1479  * dev_id: 7/107, online
1480  * =============================================
1481  */
1483  iter = iter_ut_iter(repair_svc);
1484  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1485  m0_dix_fid_convert_dix2cctg(&dix_fid,
1486  &cctg_fid,
1487  104);
1488  iter_ut_ctidx_insert(&cctg_fid);
1489  iter_ut_meta_insert(&cctg_fid);
1490  cctg = iter_ut_meta_lookup(&cctg_fid);
1491  iter_ut_insert(cctg, 10, 20);
1494  M0_SET0(iter);
1496  M0_ASSERT(rc == 0);
1497  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1498  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1499  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1500  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1501  M0_ASSERT(rc == -ENODATA);
1502  m0_dix_cm_iter_stop(iter);
1504 
1505 /*
1506  * Parity group info for key 10 (pool dev_id/global dev_id):
1507  * =============================================
1508  * 0: dev_id: 4/104, data, online, (local)
1509  * 1: dev_id: 9/109, parity, online
1510  * 2: dev_id: 6/106, parity, online
1511  * 3: dev_id: 5/105, parity, online
1512  * 4: dev_id: 1/101, spare, repairing
1513  * 5: dev_id: 0/100, spare, repaired
1514  * 6: dev_id: 7/107, spare, online
1515  * =============================================
1516  *
1517  * Spare usage array info (pool dev_id/global dev_id):
1518  * =============================================
1519  * 0: dev_id: 0/100, repaired, served by:
1520  * dev_id: 1/101, repairing
1521  * 1: dev_id: 1/101, repairing, served by:
1522  * dev_id: 0/100, repaired
1523  * 2: slot unused, served by:
1524  * dev_id: 7/107, online
1525  * =============================================
1526  */
1528  iter = iter_ut_iter(repair_svc);
1529  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1530  m0_dix_fid_convert_dix2cctg(&dix_fid,
1531  &cctg_fid,
1532  104);
1533  iter_ut_ctidx_insert(&cctg_fid);
1534  iter_ut_meta_insert(&cctg_fid);
1535  cctg = iter_ut_meta_lookup(&cctg_fid);
1536  iter_ut_insert(cctg, 10, 20);
1539  M0_SET0(iter);
1541  M0_ASSERT(rc == 0);
1542  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1543  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1544  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1545  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1546  M0_ASSERT(rc == -ENODATA);
1547  m0_dix_cm_iter_stop(iter);
1549 
1550 /*
1551  * Parity group info for key 10 (pool dev_id/global dev_id):
1552  * =============================================
1553  * 0: dev_id: 4/104, data, online, (local)
1554  * 1: dev_id: 9/109, parity, online
1555  * 2: dev_id: 6/106, parity, online
1556  * 3: dev_id: 5/105, parity, online
1557  * 4: dev_id: 1/101, spare, repaired
1558  * 5: dev_id: 0/100, spare, repairing
1559  * 6: dev_id: 7/107, spare, repaired
1560  * =============================================
1561  *
1562  * Spare usage array info (pool dev_id/global dev_id):
1563  * =============================================
1564  * 0: dev_id: 7/107, repaired, served by:
1565  * dev_id: 1/101, repaired
1566  * 1: dev_id: 1/101, repaired, served by:
1567  * dev_id: 0/100, repairing
1568  * 2: dev_id: 0/100, repairing, served by:
1569  * dev_id: 7/107, repaired
1570  * =============================================
1571  */
1573  iter = iter_ut_iter(repair_svc);
1574  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1575  m0_dix_fid_convert_dix2cctg(&dix_fid,
1576  &cctg_fid,
1577  104);
1578  iter_ut_ctidx_insert(&cctg_fid);
1579  iter_ut_meta_insert(&cctg_fid);
1580  cctg = iter_ut_meta_lookup(&cctg_fid);
1581  iter_ut_insert(cctg, 10, 20);
1585  M0_SET0(iter);
1587  M0_ASSERT(rc == 0);
1588  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1589  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1590  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1591  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1592  M0_ASSERT(rc == -ENODATA);
1593  m0_dix_cm_iter_stop(iter);
1595  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
1596  m0_fi_disable("dix_cm_iter_next_key", "print_spare_usage");
1597  m0_fi_disable("dix_cm_iter_next_key", "print_targets");
1598 }
1599 
1600 static void filled_spare_fail(void)
1601 {
1602  struct m0_dix_cm_iter *iter;
1603  struct m0_fid dix_fid;
1604  struct m0_fid cctg_fid;
1605  struct m0_cas_ctg *cctg;
1606  struct m0_buf key;
1607  struct m0_buf val;
1608  uint32_t sdev_id;
1609  int rc;
1610 
1611 /*
1612  * Parity group info for key 10 (pool dev_id/global dev_id):
1613  * =============================================
1614  * 0: dev_id: 4/104, data, online, (local)
1615  * 1: dev_id: 9/109, parity, online
1616  * 2: dev_id: 6/106, parity, repaired
1617  * 3: dev_id: 5/105, parity, online
1618  * 4: dev_id: 1/101, spare, repairing
1619  * 5: dev_id: 0/100, spare, online
1620  * 6: dev_id: 7/107, spare, online
1621  * =============================================
1622  *
1623  * Spare usage array info (pool dev_id/global dev_id):
1624  * =============================================
1625  * 0: dev_id: 6/106, repaired, served by:
1626  * dev_id: 1/101, repairing
1627  * 1: dev_id: 1/101, repairing, served by:
1628  * dev_id: 0/100, online
1629  * 2: slot unused, served by:
1630  * dev_id: 7/107, online
1631  * =============================================
1632  *
1633  * Targets for key 10 (pool dev_id/global dev_id):
1634  * =============================================
1635  * 1: dev_id: 0/100
1636  * =============================================
1637  */
1639  iter = iter_ut_iter(repair_svc);
1640  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1641  m0_dix_fid_convert_dix2cctg(&dix_fid,
1642  &cctg_fid,
1643  104);
1644  iter_ut_ctidx_insert(&cctg_fid);
1645  iter_ut_meta_insert(&cctg_fid);
1646  cctg = iter_ut_meta_lookup(&cctg_fid);
1647  iter_ut_insert(cctg, 10, 20);
1650  M0_SET0(iter);
1652  M0_ASSERT(rc == 0);
1653  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1654  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1655  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1656  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1657  M0_ASSERT(rc == 0);
1658  M0_UT_ASSERT(buf_value(&key) == 10);
1659  M0_UT_ASSERT(buf_value(&val) == 20);
1660  M0_UT_ASSERT(sdev_id == 100);
1661  m0_buf_free(&key);
1662  m0_buf_free(&val);
1663  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1664  M0_ASSERT(rc == -ENODATA);
1665  m0_dix_cm_iter_stop(iter);
1667 
1668 /*
1669  * Parity group info for key 10 (pool dev_id/global dev_id):
1670  * =============================================
1671  * 0: dev_id: 4/104, data, online, (local)
1672  * 1: dev_id: 9/109, parity, online
1673  * 2: dev_id: 6/106, parity, repaired
1674  * 3: dev_id: 5/105, parity, online
1675  * 4: dev_id: 1/101, spare, repaired
1676  * 5: dev_id: 0/100, spare, repairing
1677  * 6: dev_id: 7/107, spare, online
1678  * =============================================
1679  *
1680  * Spare usage array info (pool dev_id/global dev_id):
1681  * =============================================
1682  * 0: dev_id: 6/106, repaired, served by:
1683  * dev_id: 1/101, repaired
1684  * 1: dev_id: 1/101, repaired, served by:
1685  * dev_id: 0/100, repairing
1686  * 2: dev_id: 0/100, repairing, served by:
1687  * dev_id: 7/107, online
1688  * =============================================
1689  *
1690  * Targets for key 10 (pool dev_id/global dev_id):
1691  * =============================================
1692  * 1: dev_id: 7/107
1693  * =============================================
1694  */
1696  iter = iter_ut_iter(repair_svc);
1697  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1698  m0_dix_fid_convert_dix2cctg(&dix_fid,
1699  &cctg_fid,
1700  104);
1701  iter_ut_ctidx_insert(&cctg_fid);
1702  iter_ut_meta_insert(&cctg_fid);
1703  cctg = iter_ut_meta_lookup(&cctg_fid);
1704  iter_ut_insert(cctg, 10, 20);
1708  M0_SET0(iter);
1710  M0_ASSERT(rc == 0);
1711  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1712  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1713  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1714  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1715  M0_ASSERT(rc == 0);
1716  M0_UT_ASSERT(buf_value(&key) == 10);
1717  M0_UT_ASSERT(buf_value(&val) == 20);
1718  M0_UT_ASSERT(sdev_id == 107);
1719  m0_buf_free(&key);
1720  m0_buf_free(&val);
1721  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1722  M0_ASSERT(rc == -ENODATA);
1723  m0_dix_cm_iter_stop(iter);
1725 
1726 /*
1727  * Parity group info for key 10 (pool dev_id/global dev_id):
1728  * =============================================
1729  * 0: dev_id: 4/104, data, repaired
1730  * 1: dev_id: 9/109, parity, online, (local)
1731  * 2: dev_id: 6/106, parity, repaired
1732  * 3: dev_id: 5/105, parity, online
1733  * 4: dev_id: 1/101, spare, repairing
1734  * 5: dev_id: 0/100, spare, online
1735  * 6: dev_id: 7/107, spare, online
1736  * =============================================
1737  *
1738  * Spare usage array info (pool dev_id/global dev_id):
1739  * =============================================
1740  * 0: dev_id: 4/104, repaired, served by:
1741  * dev_id: 1/101, repairing
1742  * 1: dev_id: 6/106, repaired, served by:
1743  * dev_id: 0/100, online
1744  * 2: dev_id: 1/101, repairing, served by:
1745  * dev_id: 7/107, online
1746  * =============================================
1747  *
1748  * Targets for key 10 (pool dev_id/global dev_id):
1749  * =============================================
1750  * 1: dev_id: 7/107
1751  * =============================================
1752  */
1754  iter = iter_ut_iter(repair_svc);
1755  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1756  m0_dix_fid_convert_dix2cctg(&dix_fid,
1757  &cctg_fid,
1758  109);
1759  iter_ut_ctidx_insert(&cctg_fid);
1760  iter_ut_meta_insert(&cctg_fid);
1761  cctg = iter_ut_meta_lookup(&cctg_fid);
1762  iter_ut_insert(cctg, 10, 20);
1766  M0_SET0(iter);
1768  M0_ASSERT(rc == 0);
1769  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1770  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1771  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1772  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1773  M0_ASSERT(rc == 0);
1774  M0_UT_ASSERT(buf_value(&key) == 10);
1775  M0_UT_ASSERT(buf_value(&val) == 20);
1776  M0_UT_ASSERT(sdev_id == 107);
1777  m0_buf_free(&key);
1778  m0_buf_free(&val);
1779  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1780  M0_ASSERT(rc == -ENODATA);
1781  m0_dix_cm_iter_stop(iter);
1783 
1784 /*
1785  * Parity group info for key 10 (pool dev_id/global dev_id):
1786  * =============================================
1787  * 0: dev_id: 4/104, data, repaired
1788  * 1: dev_id: 9/109, parity, online, (local)
1789  * 2: dev_id: 6/106, parity, online
1790  * 3: dev_id: 5/105, parity, online
1791  * 4: dev_id: 1/101, spare, repairing
1792  * 5: dev_id: 0/100, spare, repairing
1793  * 6: dev_id: 7/107, spare, online
1794  * =============================================
1795  *
1796  * Spare usage array info (pool dev_id/global dev_id):
1797  * =============================================
1798  * 0: dev_id: 4/104, repaired, served by:
1799  * dev_id: 1/101, repairing
1800  * 1: dev_id: 1/101, repairing, served by:
1801  * dev_id: 0/100, repairing
1802  * 2: dev_id: 0/100, repairing, served by:
1803  * dev_id: 7/107, online
1804  * =============================================
1805  *
1806  * Targets for key 10 (pool dev_id/global dev_id):
1807  * =============================================
1808  * 1: dev_id: 7/107
1809  * =============================================
1810  */
1812  iter = iter_ut_iter(repair_svc);
1813  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1814  m0_dix_fid_convert_dix2cctg(&dix_fid,
1815  &cctg_fid,
1816  109);
1817  iter_ut_ctidx_insert(&cctg_fid);
1818  iter_ut_meta_insert(&cctg_fid);
1819  cctg = iter_ut_meta_lookup(&cctg_fid);
1820  iter_ut_insert(cctg, 10, 20);
1824  M0_SET0(iter);
1826  M0_ASSERT(rc == 0);
1827  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1828  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1829  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1830  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1831  M0_ASSERT(rc == 0);
1832  M0_UT_ASSERT(buf_value(&key) == 10);
1833  M0_UT_ASSERT(buf_value(&val) == 20);
1834  M0_UT_ASSERT(sdev_id == 107);
1835  m0_buf_free(&key);
1836  m0_buf_free(&val);
1837  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1838  M0_ASSERT(rc == -ENODATA);
1839  m0_dix_cm_iter_stop(iter);
1841 
1842 /*
1843  * Parity group info for key 10 (pool dev_id/global dev_id):
1844  * =============================================
1845  * 0: dev_id: 4/104, data, repaired
1846  * 1: dev_id: 9/109, parity, online, (local)
1847  * 2: dev_id: 6/106, parity, online
1848  * 3: dev_id: 5/105, parity, online
1849  * 4: dev_id: 1/101, spare, repairing
1850  * 5: dev_id: 0/100, spare, repairing
1851  * 6: dev_id: 7/107, spare, online
1852  * =============================================
1853  *
1854  * Spare usage array info (pool dev_id/global dev_id):
1855  * =============================================
1856  * 0: dev_id: 4/104, repaired, served by:
1857  * dev_id: 1/101, repairing
1858  * 1: dev_id: 0/100, repairing, served by:
1859  * dev_id: 0/100, repairing
1860  * 2: dev_id: 1/101, repairing, served by:
1861  * dev_id: 7/107, online
1862  * =============================================
1863  *
1864  * Targets for key 10 (pool dev_id/global dev_id):
1865  * =============================================
1866  * 1: dev_id: 7/107
1867  * =============================================
1868  */
1870  iter = iter_ut_iter(repair_svc);
1871  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1872  m0_dix_fid_convert_dix2cctg(&dix_fid,
1873  &cctg_fid,
1874  109);
1875  iter_ut_ctidx_insert(&cctg_fid);
1876  iter_ut_meta_insert(&cctg_fid);
1877  cctg = iter_ut_meta_lookup(&cctg_fid);
1878  iter_ut_insert(cctg, 10, 20);
1882  M0_SET0(iter);
1884  M0_ASSERT(rc == 0);
1885  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1886  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1887  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1888  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1889  M0_ASSERT(rc == 0);
1890  M0_UT_ASSERT(buf_value(&key) == 10);
1891  M0_UT_ASSERT(buf_value(&val) == 20);
1892  M0_UT_ASSERT(sdev_id == 107);
1893  m0_buf_free(&key);
1894  m0_buf_free(&val);
1895  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1896  M0_ASSERT(rc == -ENODATA);
1897  m0_dix_cm_iter_stop(iter);
1899 
1900 /*
1901  * Parity group info for key 10 (pool dev_id/global dev_id):
1902  * =============================================
1903  * 0: dev_id: 4/104, data, repaired
1904  * 1: dev_id: 9/109, parity, online, (local)
1905  * 2: dev_id: 6/106, parity, online
1906  * 3: dev_id: 5/105, parity, repairing
1907  * 4: dev_id: 1/101, spare, repairing
1908  * 5: dev_id: 0/100, spare, online
1909  * 6: dev_id: 7/107, spare, online
1910  * =============================================
1911  *
1912  * Spare usage array info (pool dev_id/global dev_id):
1913  * =============================================
1914  * 0: dev_id: 4/104, repaired, served by:
1915  * dev_id: 1/101, repairing
1916  * 1: dev_id: 1/101, repairing, served by:
1917  * dev_id: 0/100, online
1918  * 2: dev_id: 5/105, repairing, served by:
1919  * dev_id: 7/107, online
1920  * =============================================
1921  *
1922  * Targets for key 10 (pool dev_id/global dev_id):
1923  * =============================================
1924  * 1: dev_id: 0/100
1925  * 2: dev_id: 7/107
1926  * =============================================
1927  */
1929  iter = iter_ut_iter(repair_svc);
1930  m0_dix_fid_dix_make(&dix_fid, 1, 0);
1931  m0_dix_fid_convert_dix2cctg(&dix_fid,
1932  &cctg_fid,
1933  109);
1934  iter_ut_ctidx_insert(&cctg_fid);
1935  iter_ut_meta_insert(&cctg_fid);
1936  cctg = iter_ut_meta_lookup(&cctg_fid);
1937  iter_ut_insert(cctg, 10, 20);
1941  M0_SET0(iter);
1943  M0_ASSERT(rc == 0);
1944  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
1945  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
1946  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
1947  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1948  M0_ASSERT(rc == 0);
1949  M0_UT_ASSERT(buf_value(&key) == 10);
1950  M0_UT_ASSERT(buf_value(&val) == 20);
1951  M0_UT_ASSERT(sdev_id == 100);
1952  m0_buf_free(&key);
1953  m0_buf_free(&val);
1954  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1955  M0_ASSERT(rc == 0);
1956  M0_UT_ASSERT(buf_value(&key) == 10);
1957  M0_UT_ASSERT(buf_value(&val) == 20);
1958  M0_UT_ASSERT(sdev_id == 107);
1959  m0_buf_free(&key);
1960  m0_buf_free(&val);
1961  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
1962  M0_ASSERT(rc == -ENODATA);
1963  m0_dix_cm_iter_stop(iter);
1965  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
1966  m0_fi_disable("dix_cm_iter_next_key", "print_spare_usage");
1967  m0_fi_disable("dix_cm_iter_next_key", "print_targets");
1968 }
1969 
1970 static void many_keys_rep(void)
1971 {
1972  struct m0_dix_cm_iter *iter;
1973  struct m0_fid dix_fid;
1974  struct m0_fid cctg_fid;
1975  struct m0_cas_ctg *cctg;
1976  struct m0_buf key;
1977  struct m0_buf val;
1978  uint32_t sdev_id;
1979  int rc;
1980 
1981 /*
1982  * Parity group info for keys 10/11/12 (pool dev_id/global dev_id):
1983  * =============================================
1984  * 0: dev_id: 4/104, data, repairing
1985  * 1: dev_id: 9/109, parity, online, (local)
1986  * 2: dev_id: 6/106, parity, online
1987  * 3: dev_id: 5/105, parity, online
1988  * 4: dev_id: 1/101, spare, online
1989  * 5: dev_id: 0/100, spare, online
1990  * 6: dev_id: 7/107, spare, online
1991  * =============================================
1992  *
1993  * Spare usage array info (pool dev_id/global dev_id):
1994  * =============================================
1995  * 0: dev_id: 4/104, repairing, served by:
1996  * dev_id: 1/101, online
1997  * 1: slot unused, served by:
1998  * dev_id: 0/100, online
1999  * 2: slot unused, served by:
2000  * dev_id: 7/107, online
2001  * =============================================
2002  *
2003  * Targets for keys 10/11/12 (pool dev_id/global dev_id):
2004  * =============================================
2005  * 1: dev_id: 1/101
2006  * =============================================
2007  */
2008 
2010  iter = iter_ut_iter(repair_svc);
2011  m0_dix_fid_dix_make(&dix_fid, 1, 0);
2012  m0_dix_fid_convert_dix2cctg(&dix_fid,
2013  &cctg_fid,
2014  109);
2015  iter_ut_ctidx_insert(&cctg_fid);
2016  iter_ut_meta_insert(&cctg_fid);
2017  cctg = iter_ut_meta_lookup(&cctg_fid);
2018  iter_ut_insert(cctg, 10, 20);
2019  iter_ut_insert(cctg, 11, 30);
2020  iter_ut_insert(cctg, 12, 40);
2022  M0_SET0(iter);
2024  M0_ASSERT(rc == 0);
2025  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2026  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2027  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2028  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2029  M0_ASSERT(rc == 0);
2030  M0_UT_ASSERT(buf_value(&key) == 10);
2031  M0_UT_ASSERT(buf_value(&val) == 20);
2032  M0_UT_ASSERT(sdev_id == 101);
2033  m0_buf_free(&key);
2034  m0_buf_free(&val);
2035  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2036  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2037  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2038  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2039  M0_ASSERT(rc == 0);
2040  M0_UT_ASSERT(buf_value(&key) == 11);
2041  M0_UT_ASSERT(buf_value(&val) == 30);
2042  M0_UT_ASSERT(sdev_id == 101);
2043  m0_buf_free(&key);
2044  m0_buf_free(&val);
2045  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2046  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2047  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2048  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2049  M0_ASSERT(rc == 0);
2050  M0_UT_ASSERT(buf_value(&key) == 12);
2051  M0_UT_ASSERT(buf_value(&val) == 40);
2052  M0_UT_ASSERT(sdev_id == 101);
2053  m0_buf_free(&key);
2054  m0_buf_free(&val);
2055  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2056  M0_ASSERT(rc == -ENODATA);
2057  m0_dix_cm_iter_stop(iter);
2059  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
2060  m0_fi_disable("dix_cm_iter_next_key", "print_spare_usage");
2061  m0_fi_disable("dix_cm_iter_next_key", "print_targets");
2062 }
2063 
2064 static void user_concur_rep(void)
2065 {
2066  struct m0_dix_cm_iter *iter;
2067  struct m0_fid dix_fid;
2068  struct m0_fid cctg_fid;
2069  struct m0_cas_ctg *cctg;
2070  struct m0_buf key;
2071  struct m0_buf val;
2072  uint32_t sdev_id;
2073  int rc;
2074 
2075 /*
2076  * Parity group info for keys 10/11/12 (pool dev_id/global dev_id):
2077  * =============================================
2078  * 0: dev_id: 4/104, data, repairing
2079  * 1: dev_id: 9/109, parity, online, (local)
2080  * 2: dev_id: 6/106, parity, online
2081  * 3: dev_id: 5/105, parity, online
2082  * 4: dev_id: 1/101, spare, online
2083  * 5: dev_id: 0/100, spare, online
2084  * 6: dev_id: 7/107, spare, online
2085  * =============================================
2086  *
2087  * Spare usage array info (pool dev_id/global dev_id):
2088  * =============================================
2089  * 0: dev_id: 4/104, repairing, served by:
2090  * dev_id: 1/101, online
2091  * 1: slot unused, served by:
2092  * dev_id: 0/100, online
2093  * 2: slot unused, served by:
2094  * dev_id: 7/107, online
2095  * =============================================
2096  *
2097  * Targets for keys 10/11/12 (pool dev_id/global dev_id):
2098  * =============================================
2099  * 1: dev_id: 1/101
2100  * =============================================
2101  */
2102 
2104  iter = iter_ut_iter(repair_svc);
2105  m0_dix_fid_dix_make(&dix_fid, 1, 0);
2106  m0_dix_fid_convert_dix2cctg(&dix_fid,
2107  &cctg_fid,
2108  109);
2109  iter_ut_ctidx_insert(&cctg_fid);
2110  iter_ut_meta_insert(&cctg_fid);
2111  cctg = iter_ut_meta_lookup(&cctg_fid);
2112  iter_ut_insert(cctg, 10, 20);
2113  iter_ut_insert(cctg, 11, 30);
2114  iter_ut_insert(cctg, 12, 40);
2116  M0_SET0(iter);
2118  M0_ASSERT(rc == 0);
2119 
2120  /* Delete the first record. */
2121  iter_ut_delete(cctg, 10, 20);
2122 
2123  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2124  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2125  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2126  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2127  M0_ASSERT(rc == 0);
2128  M0_UT_ASSERT(buf_value(&key) == 11);
2129  M0_UT_ASSERT(buf_value(&val) == 30);
2130  M0_UT_ASSERT(sdev_id == 101);
2131  m0_buf_free(&key);
2132  m0_buf_free(&val);
2133 
2134  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2135  M0_ASSERT(rc == 0);
2136  M0_UT_ASSERT(buf_value(&key) == 12);
2137  M0_UT_ASSERT(buf_value(&val) == 40);
2138  M0_UT_ASSERT(sdev_id == 101);
2139  m0_buf_free(&key);
2140  m0_buf_free(&val);
2141 
2142  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2143  M0_ASSERT(rc == -ENODATA);
2144  m0_dix_cm_iter_stop(iter);
2146 
2147 
2148  /* NEXT TEST */
2150  iter = iter_ut_iter(repair_svc);
2151  m0_dix_fid_dix_make(&dix_fid, 1, 0);
2152  m0_dix_fid_convert_dix2cctg(&dix_fid,
2153  &cctg_fid,
2154  109);
2155  iter_ut_ctidx_insert(&cctg_fid);
2156  iter_ut_meta_insert(&cctg_fid);
2157  cctg = iter_ut_meta_lookup(&cctg_fid);
2158  iter_ut_insert(cctg, 10, 20);
2159  iter_ut_insert(cctg, 11, 30);
2160  iter_ut_insert(cctg, 12, 40);
2162  M0_SET0(iter);
2164  M0_ASSERT(rc == 0);
2165  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2166  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2167  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2168  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2169  M0_ASSERT(rc == 0);
2170  M0_UT_ASSERT(buf_value(&key) == 10);
2171  M0_UT_ASSERT(buf_value(&val) == 20);
2172  M0_UT_ASSERT(sdev_id == 101);
2173  m0_buf_free(&key);
2174  m0_buf_free(&val);
2175 
2176  /* Delete current record. */
2177  iter_ut_delete(cctg, 10, 20);
2178 
2179  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2180  M0_ASSERT(rc == 0);
2181  M0_UT_ASSERT(buf_value(&key) == 11);
2182  M0_UT_ASSERT(buf_value(&val) == 30);
2183  M0_UT_ASSERT(sdev_id == 101);
2184  m0_buf_free(&key);
2185  m0_buf_free(&val);
2186 
2187  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2188  M0_ASSERT(rc == 0);
2189  M0_UT_ASSERT(buf_value(&key) == 12);
2190  M0_UT_ASSERT(buf_value(&val) == 40);
2191  M0_UT_ASSERT(sdev_id == 101);
2192  m0_buf_free(&key);
2193  m0_buf_free(&val);
2194 
2195  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2196  M0_ASSERT(rc == -ENODATA);
2197  m0_dix_cm_iter_stop(iter);
2199 
2200 
2201  /* NEXT TEST */
2203  iter = iter_ut_iter(repair_svc);
2204  m0_dix_fid_dix_make(&dix_fid, 1, 0);
2205  m0_dix_fid_convert_dix2cctg(&dix_fid,
2206  &cctg_fid,
2207  109);
2208  iter_ut_ctidx_insert(&cctg_fid);
2209  iter_ut_meta_insert(&cctg_fid);
2210  cctg = iter_ut_meta_lookup(&cctg_fid);
2211  iter_ut_insert(cctg, 10, 20);
2212  iter_ut_insert(cctg, 11, 30);
2213  iter_ut_insert(cctg, 12, 40);
2215  M0_SET0(iter);
2217  M0_ASSERT(rc == 0);
2218  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2219  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2220  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2221  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2222  M0_ASSERT(rc == 0);
2223  M0_UT_ASSERT(buf_value(&key) == 10);
2224  M0_UT_ASSERT(buf_value(&val) == 20);
2225  M0_UT_ASSERT(sdev_id == 101);
2226  m0_buf_free(&key);
2227  m0_buf_free(&val);
2228 
2229  /* Delete next record. */
2230  iter_ut_delete(cctg, 11, 30);
2231 
2232  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2233  M0_ASSERT(rc == 0);
2234  M0_UT_ASSERT(buf_value(&key) == 12);
2235  M0_UT_ASSERT(buf_value(&val) == 40);
2236  M0_UT_ASSERT(sdev_id == 101);
2237  m0_buf_free(&key);
2238  m0_buf_free(&val);
2239 
2240  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2241  M0_ASSERT(rc == -ENODATA);
2242  m0_dix_cm_iter_stop(iter);
2244 
2245 
2246  /* NEXT TEST */
2248  iter = iter_ut_iter(repair_svc);
2249  m0_dix_fid_dix_make(&dix_fid, 1, 0);
2250  m0_dix_fid_convert_dix2cctg(&dix_fid,
2251  &cctg_fid,
2252  109);
2253  iter_ut_ctidx_insert(&cctg_fid);
2254  iter_ut_meta_insert(&cctg_fid);
2255  cctg = iter_ut_meta_lookup(&cctg_fid);
2256  iter_ut_insert(cctg, 10, 20);
2257  iter_ut_insert(cctg, 11, 30);
2258  iter_ut_insert(cctg, 12, 40);
2260  M0_SET0(iter);
2262  M0_ASSERT(rc == 0);
2263  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2264  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2265  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2266  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2267  M0_ASSERT(rc == 0);
2268  M0_UT_ASSERT(buf_value(&key) == 10);
2269  M0_UT_ASSERT(buf_value(&val) == 20);
2270  M0_UT_ASSERT(sdev_id == 101);
2271  m0_buf_free(&key);
2272  m0_buf_free(&val);
2273 
2274  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2275  M0_ASSERT(rc == 0);
2276  M0_UT_ASSERT(buf_value(&key) == 11);
2277  M0_UT_ASSERT(buf_value(&val) == 30);
2278  M0_UT_ASSERT(sdev_id == 101);
2279  m0_buf_free(&key);
2280  m0_buf_free(&val);
2281 
2282  /* Delete the last record. */
2283  iter_ut_delete(cctg, 12, 40);
2284 
2285  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2286  M0_ASSERT(rc == -ENODATA);
2287  m0_dix_cm_iter_stop(iter);
2289  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
2290  m0_fi_disable("dix_cm_iter_next_key", "print_spare_usage");
2291  m0_fi_disable("dix_cm_iter_next_key", "print_targets");
2292 }
2293 
2294 /*
2295  * Deletes concurrently current catalogue of repair iterator.
2296  * Iterator should skip current catalogue and continues with the next one.
2297  */
2298 static void ctg_del_concur_rep1(void)
2299 {
2300  struct m0_dix_cm_iter *iter;
2301  struct m0_fid dix_fid;
2302  struct m0_fid cctg_fid1;
2303  struct m0_fid cctg_fid2;
2304  struct m0_cas_ctg *cctg;
2305  struct m0_buf key;
2306  struct m0_buf val;
2307  struct m0_semaphore sem;
2308  uint32_t sdev_id;
2309  struct iter_ut_fom ctidx_fom;
2310  struct iter_ut_fom meta_fom;
2311  int rc;
2312 
2314  iter = iter_ut_iter(repair_svc);
2315 
2316  m0_dix_fid_dix_make(&dix_fid, 1, 1);
2317  m0_dix_fid_convert_dix2cctg(&dix_fid, &cctg_fid1, 104);
2318  iter_ut_ctidx_insert(&cctg_fid1);
2319  iter_ut_meta_insert(&cctg_fid1);
2320 
2321  m0_dix_fid_dix_make(&dix_fid, 2, 2);
2322  m0_dix_fid_convert_dix2cctg(&dix_fid, &cctg_fid2, 104);
2323  iter_ut_ctidx_insert(&cctg_fid2);
2324  iter_ut_meta_insert(&cctg_fid2);
2325 
2326  cctg = iter_ut_meta_lookup(&cctg_fid1);
2327  iter_ut_insert(cctg, 10, 20);
2328  iter_ut_insert(cctg, 11, 30);
2329  iter_ut_insert(cctg, 12, 40);
2330 
2331  cctg = iter_ut_meta_lookup(&cctg_fid2);
2332  iter_ut_insert(cctg, 100, 200);
2333  iter_ut_insert(cctg, 110, 300);
2334 
2336  M0_SET0(iter);
2338  M0_ASSERT(rc == 0);
2339 
2340  m0_fi_enable_once("dix_cm_is_repair_coordinator", "always_coordinator");
2341  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
2342  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2343  M0_ASSERT(rc == 0);
2344  M0_UT_ASSERT(buf_value(&key) == 10);
2345  M0_UT_ASSERT(buf_value(&val) == 20);
2346  m0_buf_free(&key);
2347  m0_buf_free(&val);
2348 
2349  m0_semaphore_init(&sem, 0);
2350  iter_ut_meta_delete_async(&meta_fom, &cctg_fid1, &sem);
2351  iter_ut_ctidx_delete_async(&ctidx_fom, &cctg_fid1, &sem);
2353  M0_TIME_NEVER);
2355  M0_TIME_NEVER);
2356 
2357  m0_fi_enable_once("dix_cm_is_repair_coordinator", "always_coordinator");
2358  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
2359  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2360  M0_ASSERT(rc == 0);
2361  M0_UT_ASSERT(buf_value(&key) == 100);
2362  M0_UT_ASSERT(buf_value(&val) == 200);
2363  m0_buf_free(&key);
2364  m0_buf_free(&val);
2365 
2366  m0_fi_enable_once("dix_cm_is_repair_coordinator", "always_coordinator");
2367  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
2368  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2369  M0_ASSERT(rc == 0);
2370  M0_UT_ASSERT(buf_value(&key) == 110);
2371  M0_UT_ASSERT(buf_value(&val) == 300);
2372  m0_buf_free(&key);
2373  m0_buf_free(&val);
2374 
2375  m0_fi_enable_once("dix_cm_is_repair_coordinator", "always_coordinator");
2376  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
2377  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2378  M0_ASSERT(rc == -ENODATA);
2379 
2383 
2384  m0_dix_cm_iter_stop(iter);
2386  m0_fi_disable("dix_cm_is_repair_coordinator", "always_coordinator");
2387  m0_fi_disable("dix_cm_repair_tgts_get", "single_target");
2388 }
2389 
2390 /*
2391  * Deletes concurrently a catalogue, that is not processed by iterator at the
2392  * moment. Iterator should continue processing his current catalogue.
2393  */
2394 static void ctg_del_concur_rep2(void)
2395 {
2396  struct m0_dix_cm_iter *iter;
2397  struct m0_fid dix_fid;
2398  struct m0_fid cctg_fid1;
2399  struct m0_fid cctg_fid2;
2400  struct m0_cas_ctg *cctg;
2401  struct m0_buf key;
2402  struct m0_buf val;
2403  struct m0_semaphore sem;
2404  uint32_t sdev_id;
2405  struct iter_ut_fom ctidx_fom;
2406  struct iter_ut_fom meta_fom;
2407  int rc;
2408 
2410  iter = iter_ut_iter(repair_svc);
2411 
2412  m0_dix_fid_dix_make(&dix_fid, 1, 1);
2413  m0_dix_fid_convert_dix2cctg(&dix_fid, &cctg_fid1, 104);
2414  iter_ut_ctidx_insert(&cctg_fid1);
2415  iter_ut_meta_insert(&cctg_fid1);
2416 
2417  m0_dix_fid_dix_make(&dix_fid, 2, 2);
2418  m0_dix_fid_convert_dix2cctg(&dix_fid, &cctg_fid2, 104);
2419  iter_ut_ctidx_insert(&cctg_fid2);
2420  iter_ut_meta_insert(&cctg_fid2);
2421 
2422  cctg = iter_ut_meta_lookup(&cctg_fid1);
2423  iter_ut_insert(cctg, 10, 20);
2424  iter_ut_insert(cctg, 11, 30);
2425  iter_ut_insert(cctg, 12, 40);
2426 
2427  cctg = iter_ut_meta_lookup(&cctg_fid2);
2428  iter_ut_insert(cctg, 100, 200);
2429  iter_ut_insert(cctg, 110, 300);
2430 
2432  M0_SET0(iter);
2434  M0_ASSERT(rc == 0);
2435 
2436  m0_fi_enable_once("dix_cm_is_repair_coordinator", "always_coordinator");
2437  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
2438  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2439  M0_ASSERT(rc == 0);
2440  M0_UT_ASSERT(buf_value(&key) == 10);
2441  M0_UT_ASSERT(buf_value(&val) == 20);
2442  m0_buf_free(&key);
2443  m0_buf_free(&val);
2444 
2445  m0_semaphore_init(&sem, 0);
2446  iter_ut_meta_delete_async(&meta_fom, &cctg_fid2, &sem);
2447  iter_ut_ctidx_delete_async(&ctidx_fom, &cctg_fid2, &sem);
2449  M0_TIME_NEVER);
2451  M0_TIME_NEVER);
2452 
2453  m0_fi_enable_once("dix_cm_is_repair_coordinator", "always_coordinator");
2454  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
2455  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2456  M0_ASSERT(rc == 0);
2457  M0_UT_ASSERT(buf_value(&key) == 11);
2458  M0_UT_ASSERT(buf_value(&val) == 30);
2459  m0_buf_free(&key);
2460  m0_buf_free(&val);
2461 
2462  m0_fi_enable_once("dix_cm_is_repair_coordinator", "always_coordinator");
2463  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
2464  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2465  M0_ASSERT(rc == 0);
2466  M0_UT_ASSERT(buf_value(&key) == 12);
2467  M0_UT_ASSERT(buf_value(&val) == 40);
2468  m0_buf_free(&key);
2469  m0_buf_free(&val);
2470 
2471  m0_fi_enable_once("dix_cm_is_repair_coordinator", "always_coordinator");
2472  m0_fi_enable_once("dix_cm_repair_tgts_get", "single_target");
2473  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2474  M0_ASSERT(rc == -ENODATA);
2475 
2479 
2480  m0_dix_cm_iter_stop(iter);
2482  m0_fi_disable("dix_cm_is_repair_coordinator", "always_coordinator");
2483  m0_fi_disable("dix_cm_repair_tgts_get", "single_target");
2484 }
2485 
2486 static void one_dev_reb(void)
2487 {
2488  struct m0_dix_cm_iter *iter;
2489  struct m0_fid dix_fid;
2490  struct m0_fid cctg_fid;
2491  struct m0_cas_ctg *cctg;
2492  struct m0_buf key;
2493  struct m0_buf val;
2494  uint32_t sdev_id;
2495  int rc;
2496 
2497 /*
2498  * Parity group info for key 10 (pool dev_id/global dev_id):
2499  * =============================================
2500  * 0: dev_id: 4/104, data, online
2501  * 1: dev_id: 9/109, parity, rebalancing
2502  * 2: dev_id: 6/106, parity, online
2503  * 3: dev_id: 5/105, parity, online
2504  * 4: dev_id: 1/101, spare, online, (local)
2505  * 5: dev_id: 0/100, spare, online
2506  * 6: dev_id: 7/107, spare, online
2507  * =============================================
2508  *
2509  * Spare usage array info (pool dev_id/global dev_id):
2510  * =============================================
2511  * 0: dev_id: 9/109, rebalancing, served by:
2512  * dev_id: 1/101, online
2513  * 1: slot unused, served by:
2514  * dev_id: 0/100, online
2515  * 2: slot unused, served by:
2516  * dev_id: 7/107, online
2517  * =============================================
2518  *
2519  * Targets for key 10 (pool dev_id/global dev_id):
2520  * =============================================
2521  * 1: dev_id: 9/109
2522  * =============================================
2523  */
2525  iter = iter_ut_iter(rebalance_svc);
2526  m0_dix_fid_dix_make(&dix_fid, 1, 0);
2527  m0_dix_fid_convert_dix2cctg(&dix_fid,
2528  &cctg_fid,
2529  101);
2530  iter_ut_ctidx_insert(&cctg_fid);
2531  iter_ut_meta_insert(&cctg_fid);
2532  cctg = iter_ut_meta_lookup(&cctg_fid);
2533  iter_ut_insert(cctg, 10, 20);
2535  M0_SET0(iter);
2537  M0_ASSERT(rc == 0);
2538  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2539  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2540  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2541  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2542  M0_ASSERT(rc == 0);
2543  M0_UT_ASSERT(buf_value(&key) == 10);
2544  M0_UT_ASSERT(buf_value(&val) == 20);
2545  M0_UT_ASSERT(sdev_id == 109);
2546  m0_buf_free(&key);
2547  m0_buf_free(&val);
2548  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2549  M0_ASSERT(rc == -ENODATA);
2550  m0_dix_cm_iter_stop(iter);
2552  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
2553  m0_fi_disable("dix_cm_iter_next_key", "print_spare_usage");
2554  m0_fi_disable("dix_cm_iter_next_key", "print_targets");
2555 }
2556 
2557 static void reb_coordinator(void)
2558 {
2559  struct m0_dix_cm_iter *iter;
2560  struct m0_fid dix_fid;
2561  struct m0_fid cctg_fid;
2562  struct m0_cas_ctg *cctg;
2563  struct m0_buf key;
2564  struct m0_buf val;
2565  uint32_t sdev_id;
2566  int rc;
2567 
2568 /*
2569  * Parity group info for key 10 (pool dev_id/global dev_id):
2570  * =============================================
2571  * 0: dev_id: 4/104, data, repaired
2572  * 1: dev_id: 9/109, parity, rebalancing
2573  * 2: dev_id: 6/106, parity, online
2574  * 3: dev_id: 5/105, parity, online
2575  * 4: dev_id: 1/101, spare, online, (local)
2576  * 5: dev_id: 0/100, spare, online
2577  * 6: dev_id: 7/107, spare, online
2578  * =============================================
2579  *
2580  * Spare usage array info (pool dev_id/global dev_id):
2581  * =============================================
2582  * 0: dev_id: 4/104, repaired, served by:
2583  * dev_id: 1/101, online
2584  * 1: dev_id: 9/109, rebalancing, served by:
2585  * dev_id: 0/100, online
2586  * 2: slot unused, served by:
2587  * dev_id: 7/107, online
2588  * =============================================
2589  */
2591  iter = iter_ut_iter(rebalance_svc);
2592  m0_dix_fid_dix_make(&dix_fid, 1, 0);
2593  m0_dix_fid_convert_dix2cctg(&dix_fid,
2594  &cctg_fid,
2595  101);
2596  iter_ut_ctidx_insert(&cctg_fid);
2597  iter_ut_meta_insert(&cctg_fid);
2598  cctg = iter_ut_meta_lookup(&cctg_fid);
2599  iter_ut_insert(cctg, 10, 20);
2602  M0_SET0(iter);
2604  M0_ASSERT(rc == 0);
2605  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2606  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2607  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2608  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2609  M0_ASSERT(rc == -ENODATA);
2610  m0_dix_cm_iter_stop(iter);
2612 
2613 /*
2614  * Parity group info for key 10 (pool dev_id/global dev_id):
2615  * =============================================
2616  * 0: dev_id: 4/104, data, repaired
2617  * 1: dev_id: 9/109, parity, rebalancing
2618  * 2: dev_id: 6/106, parity, online
2619  * 3: dev_id: 5/105, parity, online
2620  * 4: dev_id: 1/101, spare, online, (local)
2621  * 5: dev_id: 0/100, spare, online
2622  * 6: dev_id: 7/107, spare, online
2623  * =============================================
2624  *
2625  * Spare usage array info (pool dev_id/global dev_id):
2626  * =============================================
2627  * 0: dev_id: 4/104, repaired, served by:
2628  * dev_id: 1/101, online
2629  * 1: dev_id: 9/109, rebalancing, served by:
2630  * dev_id: 0/100, online
2631  * 2: slot unused, served by:
2632  * dev_id: 7/107, online
2633  * =============================================
2634  */
2636  iter = iter_ut_iter(rebalance_svc);
2637  m0_dix_fid_dix_make(&dix_fid, 1, 0);
2638  m0_dix_fid_convert_dix2cctg(&dix_fid,
2639  &cctg_fid,
2640  100);
2641  iter_ut_ctidx_insert(&cctg_fid);
2642  iter_ut_meta_insert(&cctg_fid);
2643  cctg = iter_ut_meta_lookup(&cctg_fid);
2644  iter_ut_insert(cctg, 10, 20);
2647  M0_SET0(iter);
2649  M0_ASSERT(rc == 0);
2650  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2651  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2652  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2653  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2654  M0_ASSERT(rc == 0);
2655  M0_UT_ASSERT(buf_value(&key) == 10);
2656  M0_UT_ASSERT(buf_value(&val) == 20);
2657  M0_UT_ASSERT(sdev_id == 109);
2658  m0_buf_free(&key);
2659  m0_buf_free(&val);
2660  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2661  M0_ASSERT(rc == -ENODATA);
2662  m0_dix_cm_iter_stop(iter);
2664 
2665 /*
2666  * Parity group info for key 10 (pool dev_id/global dev_id):
2667  * =============================================
2668  * 0: dev_id: 4/104, data, repaired
2669  * 1: dev_id: 9/109, parity, rebalancing
2670  * 2: dev_id: 6/106, parity, online
2671  * 3: dev_id: 5/105, parity, online
2672  * 4: dev_id: 1/101, spare, rebalancing
2673  * 5: dev_id: 0/100, spare, online
2674  * 6: dev_id: 7/107, spare, online, (local)
2675  * =============================================
2676  *
2677  * Spare usage array info (pool dev_id/global dev_id):
2678  * =============================================
2679  * 0: dev_id: 9/109, rebalancing, served by:
2680  * dev_id: 1/101, rebalancing
2681  * 1: dev_id: 4/104, repaired, served by:
2682  * dev_id: 0/100, online
2683  * 2: dev_id: 1/101, rebalancing, served by:
2684  * dev_id: 7/107, online
2685  * =============================================
2686  *
2687  * Targets for key 10 (pool dev_id/global dev_id):
2688  * =============================================
2689  * 1: dev_id: 9/109
2690  * =============================================
2691  */
2693  iter = iter_ut_iter(rebalance_svc);
2694  m0_dix_fid_dix_make(&dix_fid, 1, 0);
2695  m0_dix_fid_convert_dix2cctg(&dix_fid,
2696  &cctg_fid,
2697  107);
2698  iter_ut_ctidx_insert(&cctg_fid);
2699  iter_ut_meta_insert(&cctg_fid);
2700  cctg = iter_ut_meta_lookup(&cctg_fid);
2701  iter_ut_insert(cctg, 10, 20);
2705  M0_SET0(iter);
2707  M0_ASSERT(rc == 0);
2708  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2709  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2710  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2711  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2712  M0_ASSERT(rc == 0);
2713  M0_UT_ASSERT(buf_value(&key) == 10);
2714  M0_UT_ASSERT(buf_value(&val) == 20);
2715  M0_UT_ASSERT(sdev_id == 109);
2716  m0_buf_free(&key);
2717  m0_buf_free(&val);
2718  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2719  M0_ASSERT(rc == -ENODATA);
2720  m0_dix_cm_iter_stop(iter);
2722  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
2723  m0_fi_disable("dix_cm_iter_next_key", "print_spare_usage");
2724  m0_fi_disable("dix_cm_iter_next_key", "print_targets");
2725 }
2726 
2727 static void outside_dev_reb(void)
2728 {
2729  struct m0_dix_cm_iter *iter;
2730  struct m0_fid dix_fid;
2731  struct m0_fid cctg_fid;
2732  struct m0_cas_ctg *cctg;
2733  struct m0_buf key;
2734  struct m0_buf val;
2735  uint32_t sdev_id;
2736  int rc;
2737 
2738 /*
2739  * Parity group info for key 10 (pool dev_id/global dev_id):
2740  * =============================================
2741  * 0: dev_id: 4/104, data, online
2742  * 1: dev_id: 9/109, parity, online
2743  * 2: dev_id: 6/106, parity, online
2744  * 3: dev_id: 5/105, parity, online
2745  * 4: dev_id: 1/101, spare, online, (local)
2746  * 5: dev_id: 0/100, spare, online
2747  * 6: dev_id: 7/107, spare, online
2748  * =============================================
2749  *
2750  * Spare usage array info (pool dev_id/global dev_id):
2751  * =============================================
2752  * 0: dev_id: 3/103, rebalancing, served by:
2753  * dev_id: 1/101, online
2754  * 1: slot unused, served by:
2755  * dev_id: 0/100, online
2756  * 2: slot unused, served by:
2757  * dev_id: 7/107, online
2758  * =============================================
2759  */
2761  iter = iter_ut_iter(rebalance_svc);
2762  m0_dix_fid_dix_make(&dix_fid, 1, 0);
2763  m0_dix_fid_convert_dix2cctg(&dix_fid,
2764  &cctg_fid,
2765  101);
2766  iter_ut_ctidx_insert(&cctg_fid);
2767  iter_ut_meta_insert(&cctg_fid);
2768  cctg = iter_ut_meta_lookup(&cctg_fid);
2769  iter_ut_insert(cctg, 10, 20);
2771  M0_SET0(iter);
2773  M0_ASSERT(rc == 0);
2774  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2775  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2776  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2777  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2778  M0_ASSERT(rc == -ENODATA);
2779  m0_dix_cm_iter_stop(iter);
2781 
2782 /*
2783  * Parity group info for key 10 (pool dev_id/global dev_id):
2784  * =============================================
2785  * 0: dev_id: 4/104, data, online
2786  * 1: dev_id: 9/109, parity, rebalancing
2787  * 2: dev_id: 6/106, parity, online
2788  * 3: dev_id: 5/105, parity, online
2789  * 4: dev_id: 1/101, spare, online
2790  * 5: dev_id: 0/100, spare, online, (local)
2791  * 6: dev_id: 7/107, spare, online
2792  * =============================================
2793  *
2794  * Spare usage array info (pool dev_id/global dev_id):
2795  * =============================================
2796  * 0: dev_id: 3/103, rebalancing, served by:
2797  * dev_id: 1/101, online
2798  * 1: dev_id: 9/109, rebalancing, served by:
2799  * dev_id: 0/100, online
2800  * 2: slot unused, served by:
2801  * dev_id: 7/107, online
2802  * =============================================
2803  *
2804  * Targets for key 10 (pool dev_id/global dev_id):
2805  * =============================================
2806  * 1: dev_id: 9/109
2807  * =============================================
2808  */
2810  iter = iter_ut_iter(rebalance_svc);
2811  m0_dix_fid_dix_make(&dix_fid, 1, 0);
2812  m0_dix_fid_convert_dix2cctg(&dix_fid,
2813  &cctg_fid,
2814  100);
2815  iter_ut_ctidx_insert(&cctg_fid);
2816  iter_ut_meta_insert(&cctg_fid);
2817  cctg = iter_ut_meta_lookup(&cctg_fid);
2818  iter_ut_insert(cctg, 10, 20);
2821  M0_SET0(iter);
2823  M0_ASSERT(rc == 0);
2824  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2825  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2826  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2827  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2828  M0_ASSERT(rc == 0);
2829  M0_UT_ASSERT(buf_value(&key) == 10);
2830  M0_UT_ASSERT(buf_value(&val) == 20);
2831  M0_UT_ASSERT(sdev_id == 109);
2832  m0_buf_free(&key);
2833  m0_buf_free(&val);
2834  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2835  M0_ASSERT(rc == -ENODATA);
2836  m0_dix_cm_iter_stop(iter);
2838 
2839 /*
2840  * Parity group info for key 10 (pool dev_id/global dev_id):
2841  * =============================================
2842  * 0: dev_id: 4/104, data, online
2843  * 1: dev_id: 9/109, parity, rebalancing
2844  * 2: dev_id: 6/106, parity, online
2845  * 3: dev_id: 5/105, parity, online
2846  * 4: dev_id: 1/101, spare, online
2847  * 5: dev_id: 0/100, spare, rebalancing
2848  * 6: dev_id: 7/107, spare, online, (local)
2849  * =============================================
2850  *
2851  * Spare usage array info (pool dev_id/global dev_id):
2852  * =============================================
2853  * 0: dev_id: 3/103, rebalancing, served by:
2854  * dev_id: 1/101, online
2855  * 1: dev_id: 9/109, rebalancing, served by:
2856  * dev_id: 0/100, rebalancing
2857  * 2: dev_id: 0/100, rebalancing, served by:
2858  * dev_id: 7/107, online
2859  * =============================================
2860  *
2861  * Targets for key 10 (pool dev_id/global dev_id):
2862  * =============================================
2863  * 1: dev_id: 9/109
2864  * =============================================
2865  */
2867  iter = iter_ut_iter(rebalance_svc);
2868  m0_dix_fid_dix_make(&dix_fid, 1, 0);
2869  m0_dix_fid_convert_dix2cctg(&dix_fid,
2870  &cctg_fid,
2871  107);
2872  iter_ut_ctidx_insert(&cctg_fid);
2873  iter_ut_meta_insert(&cctg_fid);
2874  cctg = iter_ut_meta_lookup(&cctg_fid);
2875  iter_ut_insert(cctg, 10, 20);
2879  M0_SET0(iter);
2881  M0_ASSERT(rc == 0);
2882  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2883  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2884  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2885  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2886  M0_ASSERT(rc == 0);
2887  M0_UT_ASSERT(buf_value(&key) == 10);
2888  M0_UT_ASSERT(buf_value(&val) == 20);
2889  M0_UT_ASSERT(sdev_id == 109);
2890  m0_buf_free(&key);
2891  m0_buf_free(&val);
2892  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2893  M0_ASSERT(rc == -ENODATA);
2894  m0_dix_cm_iter_stop(iter);
2896  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
2897  m0_fi_disable("dix_cm_iter_next_key", "print_spare_usage");
2898  m0_fi_disable("dix_cm_iter_next_key", "print_targets");
2899 }
2900 
2901 static void reb_unused(void)
2902 {
2903  struct m0_dix_cm_iter *iter;
2904  struct m0_fid dix_fid;
2905  struct m0_fid cctg_fid;
2906  struct m0_cas_ctg *cctg;
2907  struct m0_buf key;
2908  struct m0_buf val;
2909  uint32_t sdev_id;
2910  int rc;
2911 
2912 /*
2913  * Parity group info for key 10 (pool dev_id/global dev_id):
2914  * =============================================
2915  * 0: dev_id: 4/104, data, online
2916  * 1: dev_id: 9/109, parity, rebalancing
2917  * 2: dev_id: 6/106, parity, online
2918  * 3: dev_id: 5/105, parity, online
2919  * 4: dev_id: 1/101, spare, online, (local)
2920  * 5: dev_id: 0/100, spare, online
2921  * 6: dev_id: 7/107, spare, online
2922  * =============================================
2923  *
2924  * Spare usage array info (pool dev_id/global dev_id):
2925  * =============================================
2926  * 0: slot unused, served by:
2927  * dev_id: 1/101, online
2928  * 1: dev_id: 9/109, rebalancing, served by:
2929  * dev_id: 0/100, online
2930  * 2: slot unused, served by:
2931  * dev_id: 7/107, online
2932  * =============================================
2933  */
2935  iter = iter_ut_iter(rebalance_svc);
2936  m0_dix_fid_dix_make(&dix_fid, 1, 0);
2937  m0_dix_fid_convert_dix2cctg(&dix_fid,
2938  &cctg_fid,
2939  101);
2940  iter_ut_ctidx_insert(&cctg_fid);
2941  iter_ut_meta_insert(&cctg_fid);
2942  cctg = iter_ut_meta_lookup(&cctg_fid);
2943  iter_ut_insert(cctg, 10, 20);
2946  M0_SET0(iter);
2948  M0_ASSERT(rc == 0);
2949  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2950  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2951  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2952  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2953  M0_ASSERT(rc == -ENODATA);
2954  m0_dix_cm_iter_stop(iter);
2956 
2957 /*
2958  * Parity group info for key 10 (pool dev_id/global dev_id):
2959  * =============================================
2960  * 0: dev_id: 4/104, data, online
2961  * 1: dev_id: 9/109, parity, rebalancing
2962  * 2: dev_id: 6/106, parity, online
2963  * 3: dev_id: 5/105, parity, online
2964  * 4: dev_id: 1/101, spare, online
2965  * 5: dev_id: 0/100, spare, online
2966  * 6: dev_id: 7/107, spare, online, (local)
2967  * =============================================
2968  *
2969  * Spare usage array info (pool dev_id/global dev_id):
2970  * =============================================
2971  * 0: dev_id: 9/109, rebalancing, served by:
2972  * dev_id: 1/101, online
2973  * 1: slot unused, served by:
2974  * dev_id: 0/100, online
2975  * 2: slot unused, served by:
2976  * dev_id: 7/107, online
2977  * =============================================
2978  */
2980  iter = iter_ut_iter(rebalance_svc);
2981  m0_dix_fid_dix_make(&dix_fid, 1, 0);
2982  m0_dix_fid_convert_dix2cctg(&dix_fid,
2983  &cctg_fid,
2984  107);
2985  iter_ut_ctidx_insert(&cctg_fid);
2986  iter_ut_meta_insert(&cctg_fid);
2987  cctg = iter_ut_meta_lookup(&cctg_fid);
2988  iter_ut_insert(cctg, 10, 20);
2990  M0_SET0(iter);
2992  M0_ASSERT(rc == 0);
2993  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
2994  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
2995  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
2996  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
2997  M0_ASSERT(rc == -ENODATA);
2998  m0_dix_cm_iter_stop(iter);
3000 
3001 /*
3002  * Parity group info for key 10 (pool dev_id/global dev_id):
3003  * =============================================
3004  * 0: dev_id: 4/104, data, online
3005  * 1: dev_id: 9/109, parity, rebalancing
3006  * 2: dev_id: 6/106, parity, online
3007  * 3: dev_id: 5/105, parity, online
3008  * 4: dev_id: 1/101, spare, rebalancing
3009  * 5: dev_id: 0/100, spare, online
3010  * 6: dev_id: 7/107, spare, online, (local)
3011  * =============================================
3012  *
3013  * Spare usage array info (pool dev_id/global dev_id):
3014  * =============================================
3015  * 0: dev_id: 9/109, rebalancing, served by:
3016  * dev_id: 1/101, rebalancing
3017  * 1: slot unused, served by:
3018  * dev_id: 0/100, online
3019  * 2: dev_id: 1/101, rebalancing, served by:
3020  * dev_id: 7/107, online
3021  * =============================================
3022  *
3023  * Targets for key 10 (pool dev_id/global dev_id):
3024  * =============================================
3025  * 1: dev_id: 9/109
3026  * =============================================
3027  */
3029  iter = iter_ut_iter(rebalance_svc);
3030  m0_dix_fid_dix_make(&dix_fid, 1, 0);
3031  m0_dix_fid_convert_dix2cctg(&dix_fid,
3032  &cctg_fid,
3033  107);
3034  iter_ut_ctidx_insert(&cctg_fid);
3035  iter_ut_meta_insert(&cctg_fid);
3036  cctg = iter_ut_meta_lookup(&cctg_fid);
3037  iter_ut_insert(cctg, 10, 20);
3041  M0_SET0(iter);
3043  M0_ASSERT(rc == 0);
3044  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
3045  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
3046  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
3047  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3048  M0_ASSERT(rc == 0);
3049  M0_UT_ASSERT(buf_value(&key) == 10);
3050  M0_UT_ASSERT(buf_value(&val) == 20);
3051  M0_UT_ASSERT(sdev_id == 109);
3052  m0_buf_free(&key);
3053  m0_buf_free(&val);
3054  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3055  M0_ASSERT(rc == -ENODATA);
3056  m0_dix_cm_iter_stop(iter);
3058 
3059 /*
3060  * Test case: firstly the data from the device 4/104 was repaired, then the data
3061  * from the device 9/109 (for example) was repaired on the device 0/100, which
3062  * in turn failed and its data was repaired on the device 7/107 (local device).
3063  * After that the device 9/109 was turned on and its data was rebalanced (unused
3064  * slot appeared in spare usage array), and then the device 0/100 has been
3065  * turned on and now rebalance is in progress. No targets should be determined
3066  * as original device that serves the data was turned on.
3067  *
3068  * Parity group info for key 10 (pool dev_id/global dev_id):
3069  * =============================================
3070  * 0: dev_id: 4/104, data, repaired
3071  * 1: dev_id: 9/109, parity, online
3072  * 2: dev_id: 6/106, parity, online
3073  * 3: dev_id: 5/105, parity, online
3074  * 4: dev_id: 1/101, spare, online
3075  * 5: dev_id: 0/100, spare, rebalancing
3076  * 6: dev_id: 7/107, spare, online, (local)
3077  * =============================================
3078  *
3079  * Spare usage array info (pool dev_id/global dev_id):
3080  * =============================================
3081  * 0: dev_id: 4/104, repaired, served by:
3082  * dev_id: 1/101, online
3083  * 1: slot unused, served by:
3084  * dev_id: 0/100, rebalancing
3085  * 2: dev_id: 0/100, rebalancing, served by:
3086  * dev_id: 7/107, online
3087  * =============================================
3088  */
3090  iter = iter_ut_iter(rebalance_svc);
3091  m0_dix_fid_dix_make(&dix_fid, 1, 0);
3092  m0_dix_fid_convert_dix2cctg(&dix_fid,
3093  &cctg_fid,
3094  107);
3095  iter_ut_ctidx_insert(&cctg_fid);
3096  iter_ut_meta_insert(&cctg_fid);
3097  cctg = iter_ut_meta_lookup(&cctg_fid);
3098  iter_ut_insert(cctg, 10, 20);
3102  M0_SET0(iter);
3104  M0_ASSERT(rc == 0);
3105  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
3106  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
3107  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
3108  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3109  M0_ASSERT(rc == -ENODATA);
3110  m0_dix_cm_iter_stop(iter);
3112  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
3113  m0_fi_disable("dix_cm_iter_next_key", "print_spare_usage");
3114  m0_fi_disable("dix_cm_iter_next_key", "print_targets");
3115 }
3116 
3117 static void many_keys_reb(void)
3118 {
3119  struct m0_dix_cm_iter *iter;
3120  struct m0_fid dix_fid;
3121  struct m0_fid cctg_fid;
3122  struct m0_cas_ctg *cctg;
3123  struct m0_buf key;
3124  struct m0_buf val;
3125  uint32_t sdev_id;
3126  int rc;
3127 
3128 /*
3129  * Parity group info for key 10/11/12 (pool dev_id/global dev_id):
3130  * =============================================
3131  * 0: dev_id: 4/104, data, online
3132  * 1: dev_id: 9/109, parity, rebalancing
3133  * 2: dev_id: 6/106, parity, online
3134  * 3: dev_id: 5/105, parity, online
3135  * 4: dev_id: 1/101, spare, online, (local)
3136  * 5: dev_id: 0/100, spare, online
3137  * 6: dev_id: 7/107, spare, online
3138  * =============================================
3139  *
3140  * Spare usage array info (pool dev_id/global dev_id):
3141  * =============================================
3142  * 0: dev_id: 9/109, rebalancing, served by:
3143  * dev_id: 1/101, online
3144  * 1: slot unused, served by:
3145  * dev_id: 0/100, online
3146  * 2: slot unused, served by:
3147  * dev_id: 7/107, online
3148  * =============================================
3149  *
3150  * Targets for key 10/11/12 (pool dev_id/global dev_id):
3151  * =============================================
3152  * 1: dev_id: 9/109
3153  * =============================================
3154  */
3156  iter = iter_ut_iter(rebalance_svc);
3157  m0_dix_fid_dix_make(&dix_fid, 1, 0);
3158  m0_dix_fid_convert_dix2cctg(&dix_fid,
3159  &cctg_fid,
3160  101);
3161  iter_ut_ctidx_insert(&cctg_fid);
3162  iter_ut_meta_insert(&cctg_fid);
3163  cctg = iter_ut_meta_lookup(&cctg_fid);
3164  iter_ut_insert(cctg, 10, 20);
3165  iter_ut_insert(cctg, 11, 30);
3166  iter_ut_insert(cctg, 12, 40);
3168  M0_SET0(iter);
3170  M0_ASSERT(rc == 0);
3171  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
3172  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
3173  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
3174  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3175  M0_ASSERT(rc == 0);
3176  M0_UT_ASSERT(buf_value(&key) == 10);
3177  M0_UT_ASSERT(buf_value(&val) == 20);
3178  M0_UT_ASSERT(sdev_id == 109);
3179  m0_buf_free(&key);
3180  m0_buf_free(&val);
3181  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
3182  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
3183  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
3184  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3185  M0_ASSERT(rc == 0);
3186  M0_UT_ASSERT(buf_value(&key) == 11);
3187  M0_UT_ASSERT(buf_value(&val) == 30);
3188  M0_UT_ASSERT(sdev_id == 109);
3189  m0_buf_free(&key);
3190  m0_buf_free(&val);
3191  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
3192  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
3193  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
3194  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3195  M0_ASSERT(rc == 0);
3196  M0_UT_ASSERT(buf_value(&key) == 12);
3197  M0_UT_ASSERT(buf_value(&val) == 40);
3198  M0_UT_ASSERT(sdev_id == 109);
3199  m0_buf_free(&key);
3200  m0_buf_free(&val);
3201  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3202  M0_ASSERT(rc == -ENODATA);
3203  m0_dix_cm_iter_stop(iter);
3205  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
3206  m0_fi_disable("dix_cm_iter_next_key", "print_spare_usage");
3207  m0_fi_disable("dix_cm_iter_next_key", "print_targets");
3208 }
3209 
3210 static void user_concur_reb(void)
3211 {
3212  struct m0_dix_cm_iter *iter;
3213  struct m0_fid dix_fid;
3214  struct m0_fid cctg_fid;
3215  struct m0_cas_ctg *cctg;
3216  struct m0_buf key;
3217  struct m0_buf val;
3218  uint32_t sdev_id;
3219  int rc;
3220 
3221 /*
3222  * Parity group info for key 10/11/12 (pool dev_id/global dev_id):
3223  * =============================================
3224  * 0: dev_id: 4/104, data, online
3225  * 1: dev_id: 9/109, parity, rebalancing
3226  * 2: dev_id: 6/106, parity, online
3227  * 3: dev_id: 5/105, parity, online
3228  * 4: dev_id: 1/101, spare, online, (local)
3229  * 5: dev_id: 0/100, spare, online
3230  * 6: dev_id: 7/107, spare, online
3231  * =============================================
3232  *
3233  * Spare usage array info (pool dev_id/global dev_id):
3234  * =============================================
3235  * 0: dev_id: 9/109, rebalancing, served by:
3236  * dev_id: 1/101, online
3237  * 1: slot unused, served by:
3238  * dev_id: 0/100, online
3239  * 2: slot unused, served by:
3240  * dev_id: 7/107, online
3241  * =============================================
3242  *
3243  * Targets for key 10/11/12 (pool dev_id/global dev_id):
3244  * =============================================
3245  * 1: dev_id: 9/109
3246  * =============================================
3247  */
3249  iter = iter_ut_iter(rebalance_svc);
3250  m0_dix_fid_dix_make(&dix_fid, 1, 0);
3251  m0_dix_fid_convert_dix2cctg(&dix_fid,
3252  &cctg_fid,
3253  101);
3254  iter_ut_ctidx_insert(&cctg_fid);
3255  iter_ut_meta_insert(&cctg_fid);
3256  cctg = iter_ut_meta_lookup(&cctg_fid);
3257  iter_ut_insert(cctg, 10, 20);
3258  iter_ut_insert(cctg, 11, 30);
3259  iter_ut_insert(cctg, 12, 40);
3261  M0_SET0(iter);
3263  M0_ASSERT(rc == 0);
3264  /* Delete the first record. */
3265  iter_ut_delete(cctg, 10, 20);
3266 
3267  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
3268  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
3269  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
3270  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3271  M0_ASSERT(rc == 0);
3272  M0_UT_ASSERT(buf_value(&key) == 11);
3273  M0_UT_ASSERT(buf_value(&val) == 30);
3274  M0_UT_ASSERT(sdev_id == 109);
3275  m0_buf_free(&key);
3276  m0_buf_free(&val);
3277 
3278  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3279  M0_ASSERT(rc == 0);
3280  M0_UT_ASSERT(buf_value(&key) == 12);
3281  M0_UT_ASSERT(buf_value(&val) == 40);
3282  M0_UT_ASSERT(sdev_id == 109);
3283  m0_buf_free(&key);
3284  m0_buf_free(&val);
3285 
3286  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3287  M0_ASSERT(rc == -ENODATA);
3288  m0_dix_cm_iter_stop(iter);
3290 
3291  /* NEXT TEST */
3293  iter = iter_ut_iter(rebalance_svc);
3294  m0_dix_fid_dix_make(&dix_fid, 1, 0);
3295  m0_dix_fid_convert_dix2cctg(&dix_fid,
3296  &cctg_fid,
3297  101);
3298  iter_ut_ctidx_insert(&cctg_fid);
3299  iter_ut_meta_insert(&cctg_fid);
3300  cctg = iter_ut_meta_lookup(&cctg_fid);
3301  iter_ut_insert(cctg, 10, 20);
3302  iter_ut_insert(cctg, 11, 30);
3303  iter_ut_insert(cctg, 12, 40);
3305  M0_SET0(iter);
3307  M0_ASSERT(rc == 0);
3308  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
3309  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
3310  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
3311  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3312  M0_ASSERT(rc == 0);
3313  M0_UT_ASSERT(buf_value(&key) == 10);
3314  M0_UT_ASSERT(buf_value(&val) == 20);
3315  M0_UT_ASSERT(sdev_id == 109);
3316  m0_buf_free(&key);
3317  m0_buf_free(&val);
3318 
3319  /* Delete next record. */
3320  iter_ut_delete(cctg, 11, 30);
3321 
3322  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3323  M0_ASSERT(rc == 0);
3324  M0_UT_ASSERT(buf_value(&key) == 12);
3325  M0_UT_ASSERT(buf_value(&val) == 40);
3326  M0_UT_ASSERT(sdev_id == 109);
3327  m0_buf_free(&key);
3328  m0_buf_free(&val);
3329 
3330  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3331  M0_ASSERT(rc == -ENODATA);
3332  m0_dix_cm_iter_stop(iter);
3334 
3335 
3336  /* NEXT TEST */
3338  iter = iter_ut_iter(rebalance_svc);
3339  m0_dix_fid_dix_make(&dix_fid, 1, 0);
3340  m0_dix_fid_convert_dix2cctg(&dix_fid,
3341  &cctg_fid,
3342  101);
3343  iter_ut_ctidx_insert(&cctg_fid);
3344  iter_ut_meta_insert(&cctg_fid);
3345  cctg = iter_ut_meta_lookup(&cctg_fid);
3346  iter_ut_insert(cctg, 10, 20);
3347  iter_ut_insert(cctg, 11, 30);
3348  iter_ut_insert(cctg, 12, 40);
3350  M0_SET0(iter);
3352  M0_ASSERT(rc == 0);
3353  m0_fi_enable_once("dix_cm_iter_next_key", "print_parity_group");
3354  m0_fi_enable_once("dix_cm_iter_next_key", "print_spare_usage");
3355  m0_fi_enable_once("dix_cm_iter_next_key", "print_targets");
3356  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3357  M0_ASSERT(rc == 0);
3358  M0_UT_ASSERT(buf_value(&key) == 10);
3359  M0_UT_ASSERT(buf_value(&val) == 20);
3360  M0_UT_ASSERT(sdev_id == 109);
3361  m0_buf_free(&key);
3362  m0_buf_free(&val);
3363 
3364  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3365  M0_ASSERT(rc == 0);
3366  M0_UT_ASSERT(buf_value(&key) == 11);
3367  M0_UT_ASSERT(buf_value(&val) == 30);
3368  M0_UT_ASSERT(sdev_id == 109);
3369  m0_buf_free(&key);
3370  m0_buf_free(&val);
3371 
3372  /* Delete the last record. */
3373  iter_ut_delete(cctg, 12, 40);
3374 
3375  rc = iter_ut_next_sync(iter, &key, &val, &sdev_id);
3376  M0_ASSERT(rc == -ENODATA);
3377  m0_dix_cm_iter_stop(iter);
3379  m0_fi_disable("dix_cm_iter_next_key", "print_parity_group");
3380  m0_fi_disable("dix_cm_iter_next_key", "print_spare_usage");
3381  m0_fi_disable("dix_cm_iter_next_key", "print_targets");
3382  m0_fi_disable("m0_dix_target", "pdcluster-map");
3383 }
3384 
3386  .ts_name = "dix-cm-iter",
3387  .ts_owners = "Egor",
3388  .ts_init = NULL,
3389  .ts_fini = NULL,
3390  .ts_tests = {
3391  { "start-stop", start_stop, "Egor" },
3392  { "empty-store", empty_store, "Egor" },
3393  { "empty-cctg", empty_cctg, "Egor" },
3394  { "cctg-not-found", cctg_not_found, "Egor" },
3395  { "one-rec", one_rec, "Egor" },
3396  { "multi-rec", multi_rec, "Egor" },
3397  { "rep-coordinator", rep_coordinator, "Sergey" },
3398  { "one-dev-fail", one_dev_fail, "Sergey" },
3399  { "two-devs-fail", two_devs_fail, "Sergey" },
3400  { "outside-dev-fail", outside_dev_fail, "Sergey" },
3401  { "empty-spare-fail", empty_spare_fail, "Sergey" },
3402  { "filled-spare-fail", filled_spare_fail, "Sergey" },
3403  { "many-keys-rep", many_keys_rep, "Sergey" },
3404  { "user-concur-rep", user_concur_rep, "Sergey" },
3405  { "ctg-del-concur-rep1", ctg_del_concur_rep1, "Sergey" },
3406  { "ctg-del-concur-rep2", ctg_del_concur_rep2, "Sergey" },
3407  { "reb-coordinator", reb_coordinator, "Sergey" },
3408  { "one-dev-reb", one_dev_reb, "Sergey" },
3409  { "outside-dev-reb", outside_dev_reb, "Sergey" },
3410  { "reb-unused", reb_unused, "Sergey" },
3411  { "many-keys-reb", many_keys_reb, "Sergey" },
3412  { "user-concur-reb", user_concur_reb, "Sergey" },
3413  { NULL, NULL }
3414  }
3415 };
3416 
3417 #undef M0_TRACE_SUBSYSTEM
3418 
3419 /*
3420  * Local variables:
3421  * c-indentation-style: "K&R"
3422  * c-basic-offset: 8
3423  * tab-width: 8
3424  * fill-column: 80
3425  * scroll-step: 1
3426  * End:
3427  */
3428 /*
3429  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
3430  */
struct m0_semaphore * iu_sem
Definition: iter_ut.c:100
struct m0_poolmach_state * pm_state
Definition: pool_machine.h:169
M0_INTERNAL void m0_long_lock_link_init(struct m0_long_lock_link *link, struct m0_fom *fom, struct m0_long_lock_addb2 *addb2)
Definition: fom_long_lock.c:66
static const struct m0_fom_type_ops iter_ut_fom_type_ops
Definition: iter_ut.c:398
M0_INTERNAL void m0_chan_wait(struct m0_clink *link)
Definition: chan.c:336
M0_INTERNAL void m0_ctg_ctidx_insert_credits(struct m0_cas_id *cid, struct m0_be_tx_credit *accum)
Definition: ctg_store.c:1962
M0_INTERNAL void m0_ctg_delete_credit(struct m0_cas_ctg *ctg, m0_bcount_t knob, m0_bcount_t vnob, struct m0_be_tx_credit *accum)
Definition: ctg_store.c:1913
struct m0_be_domain * bs_domain
Definition: seg.h:82
#define M0_PRE(cond)
M0_INTERNAL int m0_reqh_service_start(struct m0_reqh_service *service)
Definition: reqh_service.c:343
M0_EXTERN struct m0_cm_type dix_rebalance_cmt
Definition: cm.h:174
M0_INTERNAL int m0_ctg_meta_insert(struct m0_ctg_op *ctg_op, const struct m0_fid *fid, int next_phase)
Definition: ctg_store.c:1336
static void iter_ut_reqh_init(void)
Definition: iter_ut.c:624
static void iter_ut_fom_op_sync(struct iter_ut_fom *fom)
Definition: iter_ut.c:402
M0_INTERNAL void m0_pool_fini(struct m0_pool *pool)
Definition: pool.c:322
static void iter_ut_ctidx_delete_async(struct iter_ut_fom *fom, struct m0_fid *cctg_fid, struct m0_semaphore *sem)
Definition: iter_ut.c:464
struct m0_tl po_vers
Definition: pool.h:84
static int iter_ut_fom_exec(struct iter_ut_fom *fom)
Definition: iter_ut.c:228
M0_INTERNAL void m0_reqh_service_stop(struct m0_reqh_service *service)
Definition: reqh_service.c:402
#define M0_FOM_LONG_LOCK_RETURN(rc)
uint64_t ft_id
Definition: fom.h:613
#define NULL
Definition: misc.h:38
uint32_t pst_nr_devices
Definition: pool_machine.h:108
M0_INTERNAL void m0_clink_init(struct m0_clink *link, m0_chan_cb_t cb)
Definition: chan.c:201
static void multi_rec(void)
Definition: iter_ut.c:857
M0_INTERNAL int m0_ctg_delete(struct m0_ctg_op *ctg_op, struct m0_cas_ctg *ctg, const struct m0_buf *key, int next_phase)
Definition: ctg_store.c:1540
static void iter_ut_ctidx_insert(struct m0_fid *cctg_fid)
Definition: iter_ut.c:444
M0_INTERNAL void m0_clink_del_lock(struct m0_clink *link)
Definition: chan.c:293
Definition: idx_mock.c:52
static struct m0_be_ut_backend be
Definition: iter_ut.c:50
static struct m0_semaphore sem
Definition: cp.c:32
struct m0_be_clink pst_conf_ready
Definition: pool_machine.h:154
m0_be_tx_state
Definition: tx.h:214
#define M0_REQH_INIT(reqh,...)
Definition: reqh.h:262
Definition: sm.h:350
const m0_time_t M0_TIME_NEVER
Definition: time.c:108
void * b_addr
Definition: buf.h:39
M0_INTERNAL void m0_dix_cm_iter_next(struct m0_dix_cm_iter *iter)
Definition: iter.c:1458
M0_INTERNAL struct m0_long_lock * m0_ctg_lock(struct m0_cas_ctg *ctg)
Definition: ctg_store.c:2162
M0_INTERNAL void m0_ctg_store_fini(void)
Definition: ctg_store.c:870
struct m0_poolmach pv_mach
Definition: pool.h:133
static void reb_coordinator(void)
Definition: iter_ut.c:2557
#define FAILURES_NR
Definition: iter_ut.c:45
M0_INTERNAL void m0_reqh_layouts_cleanup(struct m0_reqh *reqh)
Definition: reqh.c:169
M0_INTERNAL void m0_reqh_service_prepare_to_stop(struct m0_reqh_service *service)
Definition: reqh_service.c:375
static void iter_ut_fini(struct m0_reqh_service *svc)
Definition: iter_ut.c:700
M0_INTERNAL void m0_dtx_init(struct m0_dtx *tx, struct m0_be_domain *be_domain, struct m0_sm_group *sm_group)
Definition: dtm.c:67
int(* fto_create)(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: fom.h:650
M0_INTERNAL void m0_dtx_opened(struct m0_dtx *tx)
Definition: dtm.c:94
M0_INTERNAL void m0_cas_id_fini(struct m0_cas_id *cid)
Definition: cas.c:198
static void ctg_del_concur_rep1(void)
Definition: iter_ut.c:2298
struct m0_dix_layout ci_layout
Definition: cas.h:120
static struct m0_fom_type ut_fom_type_reb
Definition: iter_ut.c:56
static void device_repaired_set(uint64_t pool_device_id)
Definition: iter_ut.c:529
M0_INTERNAL struct m0_be_seg * m0_be_domain_seg0_get(struct m0_be_domain *dom)
Definition: domain.c:466
struct m0_be_tx_credit iu_tx_cred
Definition: iter_ut.c:97
static void iter_ut_meta_delete_async(struct iter_ut_fom *fom, struct m0_fid *cctg_fid, struct m0_semaphore *sem)
Definition: iter_ut.c:454
struct m0_dtx fo_tx
Definition: fom.h:498
M0_INTERNAL void m0_fom_wait_on(struct m0_fom *fom, struct m0_chan *chan, struct m0_fom_callback *cb)
Definition: fom.c:1490
#define M0_BITS(...)
Definition: misc.h:236
M0_INTERNAL void m0_long_write_unlock(struct m0_long_lock *lock, struct m0_long_lock_link *link)
M0_INTERNAL int m0_dix_cm_iter_start(struct m0_dix_cm_iter *iter, struct m0_dix_cm_type *dcmt, struct m0_reqh *reqh, m0_bcount_t rpc_cutoff)
Definition: iter.c:1429
static void cctg_not_found(void)
Definition: iter_ut.c:789
#define container_of(ptr, type, member)
Definition: misc.h:33
static void outside_dev_reb(void)
Definition: iter_ut.c:2727
#define M0_SET0(obj)
Definition: misc.h:64
static struct m0_be_seg * seg0
Definition: iter_ut.c:51
Definition: ut.h:77
static void many_keys_reb(void)
Definition: iter_ut.c:3117
struct m0_cas_ctg * iu_ctg
Definition: iter_ut.c:98
struct m0_ut_suite dix_cm_iter_ut
Definition: iter_ut.c:3385
M0_INTERNAL void m0_ctg_insert_credit(struct m0_cas_ctg *ctg, m0_bcount_t knob, m0_bcount_t vnob, struct m0_be_tx_credit *accum)
Definition: ctg_store.c:1905
static void device_rebalancing_set(uint64_t pool_device_id)
Definition: iter_ut.c:557
m0_fom_phase
Definition: fom.h:372
#define DATA_NR
Definition: iter_ut.c:44
static struct m0_be_tx * m0_fom_tx(struct m0_fom *fom)
Definition: fom.h:537
Definition: sock.c:887
static struct m0_pools_common pc
Definition: iter_ut.c:59
static struct m0_pool_version pv
Definition: iter_ut.c:60
const struct m0_fom_type * fo_type
Definition: dump.c:107
M0_INTERNAL int m0_pool_init(struct m0_pool *pool, const struct m0_fid *id, enum m0_pver_policy_code pver_policy)
Definition: pool.c:307
enum iter_ut_fom_op iu_op
Definition: iter_ut.c:91
struct m0_pooldev * pst_devices_array
Definition: pool_machine.h:111
static void spare_slot_unused_set()
Definition: iter_ut.c:571
static struct m0_cm * cm
Definition: cm.c:63
Definition: buf.h:37
struct m0_reqh * bec_reqh
Definition: engine.h:84
M0_INTERNAL int m0_ctg_insert(struct m0_ctg_op *ctg_op, struct m0_cas_ctg *ctg, const struct m0_buf *key, const struct m0_buf *val, int next_phase)
Definition: ctg_store.c:1448
static int iter_ut_next_sync(struct m0_dix_cm_iter *iter, struct m0_buf *key, struct m0_buf *val, uint32_t *sdev_id)
Definition: iter_ut.c:726
M0_INTERNAL int m0_ctg_meta_lookup(struct m0_ctg_op *ctg_op, const struct m0_fid *fid, int next_phase)
Definition: ctg_store.c:1362
void m0_fom_init(struct m0_fom *fom, const struct m0_fom_type *fom_type, const struct m0_fom_ops *ops, struct m0_fop *fop, struct m0_fop *reply, struct m0_reqh *reqh)
Definition: fom.c:1372
M0_INTERNAL bool m0_long_write_lock(struct m0_long_lock *lk, struct m0_long_lock_link *link, int next_phase)
int i
Definition: dir.c:1033
static struct m0_fom_type ut_fom_type
Definition: iter_ut.c:54
static void filled_spare_fail(void)
Definition: iter_ut.c:1600
static void iter_ut_init(struct m0_reqh_service **svc, struct m0_reqh_service_type *stype)
Definition: iter_ut.c:646
#define M0_FID_TINIT(type, container, key)
Definition: fid.h:90
#define M0_AMB(obj, ptr, field)
Definition: misc.h:320
static const struct socktype stype[]
Definition: sock.c:1156
struct m0_be_clink pst_conf_exp
Definition: pool_machine.h:153
M0_INTERNAL void m0_dtx_open(struct m0_dtx *tx)
Definition: dtm.c:86
M0_INTERNAL struct m0_cas_ctg * m0_ctg_meta(void)
Definition: ctg_store.c:2130
iter_ut_fom_op
Definition: iter_ut.c:69
M0_INTERNAL void m0_fi_disable(const char *fp_func, const char *fp_tag)
Definition: finject.c:485
static void m0_fi_enable(const char *func, const char *tag)
Definition: finject.h:276
void m0_fom_fini(struct m0_fom *fom)
Definition: fom.c:1324
M0_EXTERN struct m0_dix_cm_type dix_rebalance_dcmt
Definition: cm.h:176
#define M0_ASSERT(cond)
const char * scf_name
Definition: sm.h:352
struct m0_long_lock_link iu_lock_link
Definition: iter_ut.c:101
M0_INTERNAL void m0_dix_cm_iter_stop(struct m0_dix_cm_iter *iter)
Definition: iter.c:1525
M0_INTERNAL void m0_reqh_service_fini(struct m0_reqh_service *service)
Definition: reqh_service.c:457
M0_INTERNAL void m0_long_lock_link_fini(struct m0_long_lock_link *link)
Definition: fom_long_lock.c:76
iter_ut_fom_phase
Definition: iter_ut.c:79
M0_INTERNAL int m0_ctg_store_init(struct m0_be_domain *dom)
Definition: ctg_store.c:814
M0_INTERNAL int m0_pool_version_init(struct m0_pool_version *pv, const struct m0_fid *id, struct m0_pool *pool, uint32_t pool_width, uint32_t nr_nodes, uint32_t nr_data, uint32_t nr_failures, uint32_t nr_spare)
Definition: pool.c:522
static void iter_ut_insert(struct m0_cas_ctg *cctg, uint64_t key, uint64_t val)
Definition: iter_ut.c:474
M0_INTERNAL void m0_fom_type_init(struct m0_fom_type *type, uint64_t id, const struct m0_fom_type_ops *ops, const struct m0_reqh_service_type *svc_type, const struct m0_sm_conf *sm)
Definition: fom.c:1596
M0_INTERNAL void m0_ctg_mark_deleted_credit(struct m0_be_tx_credit *accum)
Definition: ctg_store.c:1805
M0_INTERNAL int m0_dix_ldesc_init(struct m0_dix_ldesc *ld, struct m0_ext *range, m0_bcount_t range_nr, enum m0_dix_hash_fnc_type htype, struct m0_fid *pver)
Definition: layout.c:171
static void iter_ut_fom_init(struct iter_ut_fom *fom)
Definition: iter_ut.c:179
static struct m0_fom_type ut_fom_type_rep
Definition: iter_ut.c:55
void m0_be_ut_backend_init(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:238
struct m0_fom iu_fom
Definition: iter_ut.c:92
struct m0_cm dcm_base
Definition: cm.h:119
static void user_concur_reb(void)
Definition: iter_ut.c:3210
M0_INTERNAL int m0_buf_alloc(struct m0_buf *buf, size_t size)
Definition: buf.c:43
M0_INTERNAL int m0_semaphore_init(struct m0_semaphore *semaphore, unsigned value)
Definition: semaphore.c:38
static void iter_ut_fom_result(struct iter_ut_fom *fom)
Definition: iter_ut.c:275
struct m0_cas_id iu_cid
Definition: iter_ut.c:99
uint32_t pd_sdev_idx
Definition: pool.h:437
M0_INTERNAL int m0_layout_init_by_pver(struct m0_layout_domain *dom, struct m0_pool_version *pv, int *count)
Definition: layout_pver.c:118
static uint64_t buf_value(const struct m0_buf *buf)
Definition: iter_ut.c:814
static void iter_ut_devs_setup()
Definition: iter_ut.c:583
M0_INTERNAL void m0_ctg_create_credit(struct m0_be_tx_credit *accum)
Definition: ctg_store.c:1823
static void one_dev_fail(void)
Definition: iter_ut.c:1078
M0_INTERNAL void m0_dtx_fini(struct m0_dtx *tx)
Definition: dtm.c:134
static void iter_ut_reqh_fini()
Definition: iter_ut.c:693
M0_INTERNAL int m0_reqh_service_allocate(struct m0_reqh_service **out, const struct m0_reqh_service_type *stype, struct m0_reqh_context *rctx)
Definition: reqh_service.c:185
M0_EXTERN struct m0_dix_cm_type dix_repair_dcmt
Definition: cm.h:175
Definition: reqh.h:94
struct m0_layout_domain rh_ldom
Definition: reqh.h:153
uint32_t dl_type
Definition: layout.h:100
struct m0_fid pd_id
Definition: pool.h:428
static void empty_cctg(void)
Definition: iter_ut.c:764
Definition: dump.c:103
struct m0_fid ci_fid
Definition: cas.h:113
M0_INTERNAL void m0_buf_free(struct m0_buf *buf)
Definition: buf.c:55
M0_INTERNAL void m0_reqh_service_init(struct m0_reqh_service *service, struct m0_reqh *reqh, const struct m0_fid *fid)
Definition: reqh_service.c:428
static struct m0_clink clink[RDWR_REQUEST_MAX]
M0_INTERNAL void m0_dtx_done(struct m0_dtx *tx)
Definition: dtm.c:115
#define SPARE_NR
Definition: iter_ut.c:46
union m0_dix_layout::@145 u
Definition: seg.h:66
M0_INTERNAL int m0_dix_cm_iter_get(struct m0_dix_cm_iter *iter, struct m0_buf *key, struct m0_buf *val, uint32_t *sdev_id)
Definition: iter.c:1465
Definition: cm.h:117
struct m0_be_domain but_dom
Definition: helper.h:47
M0_INTERNAL void m0_ctg_op_init(struct m0_ctg_op *ctg_op, struct m0_fom *fom, uint32_t flags)
Definition: ctg_store.c:1759
M0_INTERNAL void m0_pool_version_fini(struct m0_pool_version *pv)
Definition: pool.c:786
static struct m0_pool pool
Definition: iter_ut.c:58
#define NODES
Definition: iter_ut.c:43
M0_INTERNAL int m0_fom_timedwait(struct m0_fom *fom, uint64_t phases, m0_time_t deadline)
Definition: fom.c:724
void m0_clink_add_lock(struct m0_chan *chan, struct m0_clink *link)
Definition: chan.c:255
static void iter_ut_pool_fini()
Definition: iter_ut.c:684
uint32_t sd_flags
Definition: sm.h:378
Definition: fom.h:481
static void start_stop(void)
Definition: iter_ut.c:712
struct m0_be_domain_cfg but_dom_cfg
Definition: helper.h:53
#define POOL_WIDTH
Definition: iter_ut.c:42
M0_INTERNAL int m0_ctg_ctidx_delete_sync(const struct m0_cas_id *cid, struct m0_be_tx *tx)
Definition: ctg_store.c:2060
const char * ts_name
Definition: ut.h:99
static struct m0_fid pv_fid
Definition: iter_ut.c:62
#define DEVS_ID_SHIFT
Definition: iter_ut.c:47
struct m0_buf iu_val
Definition: iter_ut.c:96
M0_INTERNAL void m0_reqh_start(struct m0_reqh *reqh)
Definition: reqh.c:711
static void reb_unused(void)
Definition: iter_ut.c:2901
static void iter_ut_pool_init()
Definition: iter_ut.c:599
static void iter_ut_fom_fini(struct m0_fom *fom0)
Definition: iter_ut.c:161
M0_INTERNAL void m0_dix_fid_dix_make(struct m0_fid *dix_fid, uint32_t container, uint64_t key)
Definition: fid_convert.c:45
static const struct m0_sm_conf iter_ut_fom_conf
Definition: iter_ut.c:146
M0_INTERNAL void m0_layout_domain_cleanup(struct m0_layout_domain *dom)
Definition: layout.c:653
Definition: fid.h:38
uint64_t f_key
Definition: fid.h:40
M0_EXTERN struct m0_cm_type dix_repair_cmt
Definition: cm.h:173
M0_INTERNAL void m0_semaphore_fini(struct m0_semaphore *semaphore)
Definition: semaphore.c:45
static uint64_t iter_ut_fom_locality(const struct m0_fom *fom)
Definition: iter_ut.c:174
struct m0_buf iu_key
Definition: iter_ut.c:95
static struct m0_dix_cm_iter * iter_ut_iter(struct m0_reqh_service *svc)
Definition: iter_ut.c:152
static void one_rec(void)
Definition: iter_ut.c:820
static int iter_ut_fom_tick(struct m0_fom *fom0)
Definition: iter_ut.c:295
static void many_keys_rep(void)
Definition: iter_ut.c:1970
struct m0_reqh_service cm_service
Definition: cm.h:191
static void rep_coordinator(void)
Definition: iter_ut.c:911
static void outside_dev_fail(void)
Definition: iter_ut.c:1231
struct m0_long_lock_link iu_del_lock_link
Definition: iter_ut.c:102
Definition: cm.h:166
static struct m0_net_test_service svc
Definition: service.c:34
M0_INTERNAL int m0_ctg_ctidx_insert_sync(const struct m0_cas_id *cid, struct m0_be_tx *tx)
Definition: ctg_store.c:2010
M0_INTERNAL void m0_ctg_ctidx_delete_credits(struct m0_cas_id *cid, struct m0_be_tx_credit *accum)
Definition: ctg_store.c:1971
struct m0_tl pc_pools
Definition: pool.h:162
M0_INTERNAL int m0_ctg_meta_delete(struct m0_ctg_op *ctg_op, const struct m0_fid *fid, int next_phase)
Definition: ctg_store.c:1392
M0_INTERNAL void m0_clink_fini(struct m0_clink *link)
Definition: chan.c:208
uint32_t psu_device_index
Definition: pool.h:480
void m0_be_ut_backend_fini(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:242
static void empty_store(void)
Definition: iter_ut.c:745
M0_INTERNAL void m0_reqh_idle_wait_for(struct m0_reqh *reqh, struct m0_reqh_service *service)
Definition: reqh.c:591
struct m0_be_seg * rh_beseg
Definition: reqh.h:112
static int spare_usage_pos
Definition: iter_ut.c:63
static void m0_fi_enable_once(const char *func, const char *tag)
Definition: finject.h:301
struct m0_reqh_service_type ct_stype
Definition: cm.h:145
struct m0_fid p_fid
Definition: tx_desc.h:164
M0_INTERNAL void m0_fom_queue(struct m0_fom *fom)
Definition: fom.c:624
M0_INTERNAL struct m0_cas_ctg * m0_ctg_ctidx(void)
Definition: ctg_store.c:2135
static void user_concur_rep(void)
Definition: iter_ut.c:2064
void(* fo_fini)(struct m0_fom *fom)
Definition: fom.h:657
static void device_state_set(uint64_t pool_device_id, int dev_state)
Definition: iter_ut.c:518
static struct m0_cas_ctg * iter_ut_meta_lookup(struct m0_fid *cctg_fid)
Definition: iter_ut.c:433
M0_INTERNAL void m0_ctg_op_fini(struct m0_ctg_op *ctg_op)
Definition: ctg_store.c:1788
static void two_devs_fail(void)
Definition: iter_ut.c:1150
Definition: pool.h:80
static void iter_ut_meta_insert(struct m0_fid *cctg_fid)
Definition: iter_ut.c:423
M0_INTERNAL void m0_semaphore_down(struct m0_semaphore *semaphore)
Definition: semaphore.c:49
void m0_fom_phase_set(struct m0_fom *fom, int phase)
Definition: fom.c:1688
static void device_repairing_set(uint64_t pool_device_id)
Definition: iter_ut.c:543
M0_INTERNAL void m0_semaphore_up(struct m0_semaphore *semaphore)
Definition: semaphore.c:65
struct m0_ctg_op iu_ctg_op
Definition: iter_ut.c:93
static void iter_ut_delete(struct m0_cas_ctg *cctg, uint64_t key, uint64_t val)
Definition: iter_ut.c:496
static const struct m0_fom_ops iter_ut_fom_ops
Definition: iter_ut.c:392
static void ctg_del_concur_rep2(void)
Definition: iter_ut.c:2394
struct m0_fid iu_cctg_fid
Definition: iter_ut.c:94
Definition: cas.h:107
static struct m0_reqh reqh
Definition: iter_ut.c:49
struct m0_be_engine_cfg bc_engine
Definition: domain.h:79
M0_INTERNAL void m0_dix_fid_convert_dix2cctg(const struct m0_fid *dix_fid, struct m0_fid *cctg_fid, uint32_t device_id)
Definition: fid_convert.c:54
int32_t rc
Definition: trigger_fop.h:47
struct m0_pool_spare_usage * pst_spare_usage_array
Definition: pool_machine.h:137
struct m0_chan di_completed
Definition: iter.h:156
#define ARRAY_SIZE(a)
Definition: misc.h:45
uint32_t pd_index
Definition: pool.h:432
struct m0_fid g_process_fid
Definition: ut.c:689
struct m0_fom_callback fo_cb
Definition: fom.h:488
#define M0_UT_ASSERT(a)
Definition: ut.h:46
static struct m0_reqh_service * repair_svc
Definition: iter_ut.c:52
static void empty_spare_fail(void)
Definition: iter_ut.c:1405
static void one_dev_reb(void)
Definition: iter_ut.c:2486
M0_INTERNAL int m0_ctg_op_rc(struct m0_ctg_op *ctg_op)
Definition: ctg_store.c:1779
struct m0_dix_cm_iter dcm_it
Definition: cm.h:128
M0_INTERNAL struct m0_long_lock * m0_ctg_del_lock(void)
Definition: ctg_store.c:2157
M0_INTERNAL struct m0_reqh * m0_fom_reqh(const struct m0_fom *fom)
Definition: fom.c:283
Definition: tx.h:280
Definition: idx_mock.c:47
static struct m0_sm_state_descr iter_ut_fom_phases[]
Definition: iter_ut.c:105
static struct m0_reqh_service * rebalance_svc
Definition: iter_ut.c:53
M0_INTERNAL struct m0_cas_ctg * m0_ctg_meta_lookup_result(struct m0_ctg_op *ctg_op)
Definition: ctg_store.c:1377
#define M0_IMPOSSIBLE(fmt,...)