Motr  M0
spiel_ci_ut.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2015-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 #include "lib/trace.h"
25 
26 #include "spiel/spiel.h"
27 #include "spiel/spiel_internal.h"
29 #include "conf/obj_ops.h" /* M0_CONF_DIRNEXT */
30 #include "conf/confd.h" /* m0_confd_stype */
31 #include "module/instance.h" /* m0_get */
32 #include "stob/domain.h" /* m0_stob_domain */
33 #include "rpc/rpc_opcodes.h" /* M0_RPC_SESSION_ESTABLISH_REP_OPCODE */
34 #include "rm/rm_service.h" /* m0_rms_type */
35 #include "lib/finject.h"
36 #include "lib/fs.h" /* m0_file_read */
37 #include "conf/ut/common.h" /* m0_conf_ut_ast_thread_fini */
38 #include "ut/misc.h" /* M0_UT_PATH */
39 #include "ut/ut.h"
40 #include "motr/version.h" /* m0_build_info_get */
41 #include "ha/link.h" /* m0_ha_link_chan */
42 
43 
44 static struct m0_spiel spiel;
45 
46 static void spiel_ci_ut_init(void)
47 {
48  m0_spiel__ut_init(&spiel, M0_SRC_PATH("spiel/ut/conf.xc"), true);
51 }
52 
53 static void spiel_ci_ut_fini(void)
54 {
57  m0_spiel__ut_fini(&spiel, true);
58 }
59 
60 static void spiel_ci_ut_ha_state_set(const struct m0_fid *fid, uint32_t state)
61 {
62  struct m0_ha_note note = { .no_id = *fid, .no_state = state };
63  struct m0_ha_nvec nvec = { .nv_nr = 1, .nv_note = &note };
64  struct m0_ha_link *hl;
65  uint64_t tag;
66 
67  hl = m0_get()->i_ha_link;
68  tag = m0_ha_msg_nvec_send(&nvec, 0, false, M0_HA_NVEC_SET, hl);
70 }
71 
72 static void test_spiel_service_cmds(void)
73 {
74  const struct m0_fid svc_fid = M0_FID_TINIT(
76  const struct m0_fid svc_invalid_fid = M0_FID_TINIT(
78  const struct m0_fid top_level_rm_fid = M0_FID_TINIT(
80  int rc;
81  int status;
82 
84 
85  rc = m0_spiel_service_status(&spiel, &svc_fid, &status);
86  M0_UT_ASSERT(rc == 0);
87  M0_UT_ASSERT(status == M0_RST_STARTED);
88 
89  /* Doing `service stop` intialised during startup. */
90  rc = m0_spiel_service_quiesce(&spiel, &svc_fid);
91  M0_UT_ASSERT(rc == 0);
92 
93  rc = m0_spiel_service_stop(&spiel, &svc_fid);
94  M0_UT_ASSERT(rc == 0);
95  rc = m0_spiel_service_status(&spiel, &svc_fid, &status);
96  M0_UT_ASSERT(rc != 0);
97 
98  rc = m0_spiel_service_init(&spiel, &svc_fid);
99  M0_UT_ASSERT(rc == 0);
100  rc = m0_spiel_service_status(&spiel, &svc_fid, &status);
101  M0_UT_ASSERT(rc == 0);
102  M0_UT_ASSERT(status == M0_RST_INITIALISED);
103 
104  rc = m0_spiel_service_start(&spiel, &svc_fid);
105  M0_UT_ASSERT(rc == 0);
106  rc = m0_spiel_service_status(&spiel, &svc_fid, &status);
107  M0_UT_ASSERT(rc == 0);
108  M0_UT_ASSERT(status == M0_RST_STARTED);
109 
110  rc = m0_spiel_service_health(&spiel, &svc_fid);
111  /* This is true while the service doesn't implement rso_health */
113 
114  rc = m0_spiel_service_quiesce(&spiel, &svc_fid);
115  M0_UT_ASSERT(rc == 0);
116 
117  rc = m0_spiel_service_stop(&spiel, &svc_fid);
118  M0_UT_ASSERT(rc == 0);
119 
120  rc = m0_spiel_service_health(&spiel, &svc_invalid_fid);
121  M0_UT_ASSERT(rc == -ENOENT);
122 
123  /* Stopping of Top Level RM is disallowed */
124  rc = m0_spiel_service_stop(&spiel, &top_level_rm_fid);
125  M0_UT_ASSERT(rc == -EPERM);
127 }
128 
130 {
131  struct m0_spiel_running_svc *svcs;
132  int rc;
133  int i;
134  const struct m0_fid proc_fid = M0_FID_TINIT(
136 
139  M0_UT_ASSERT(rc > 0);
140  M0_UT_ASSERT(svcs != NULL);
141  for (i = 0; i < rc; ++i)
142  m0_free(svcs[i].spls_name);
143  m0_free(svcs);
144 
146 }
147 
148 static void test_spiel_process_cmds(void)
149 {
150  int rc;
151  const struct m0_fid process_fid = M0_FID_TINIT(
153  const struct m0_fid process_second_fid = M0_FID_TINIT(
155  const struct m0_fid process_invalid_fid = M0_FID_TINIT(
157  char *libpath;
158 
160  /* Reconfig */
161  rc = m0_spiel_process_reconfig(&spiel, &process_invalid_fid);
162  M0_UT_ASSERT(rc == -EINVAL);
163 
164  m0_fi_enable_once("m0_alloc", "fail_allocation");
166  M0_UT_ASSERT(rc == -ENOMEM);
167 
168  rc = m0_spiel_process_reconfig(&spiel, &process_second_fid);
169  M0_UT_ASSERT(rc == -ENOENT);
170 
171  m0_fi_enable_once("ss_process_reconfig", "unit_test");
173  M0_UT_ASSERT(rc == 0);
174 
175  /* Health */
176  rc = m0_spiel_process_health(&spiel, &process_invalid_fid);
177  M0_UT_ASSERT(rc == -EINVAL);
178 
181 
182  /* Load test library. */
183  rc = asprintf(&libpath, "%s/%s", m0_build_info_get()->bi_build_dir,
184  "ut/.libs/libtestlib.so.0.0.0");
185  M0_UT_ASSERT(rc >= 0);
187  M0_UT_ASSERT(rc == 0);
188  free(libpath);
189  /* Cleanup after the libtestlib.so. */
190  m0_fi_disable("sss_process_lib_load_testlib_test", "loaded");
191 
192  /* Load non-existent library. */
193  rc = m0_spiel_process_lib_load(&spiel, &process_fid, "/funnylib");
194  M0_UT_ASSERT(rc == -EINVAL);
195 
196  /* Stop */
197  rc = m0_spiel_process_stop(&spiel, &process_invalid_fid);
198  M0_UT_ASSERT(rc == -EINVAL);
199 
200  m0_fi_enable_once("m0_ss_process_stop_fop_release", "no_kill");
202  M0_UT_ASSERT(rc == 0);
203 
204  /* Quiesce */
205  rc = m0_spiel_process_quiesce(&spiel, &process_invalid_fid);
206  M0_UT_ASSERT(rc == -EINVAL);
207 
213  M0_UT_ASSERT(rc == 0);
215 }
216 
217 static bool spiel_stob_exists(uint64_t cid)
218 {
219  struct m0_storage_devs *devs = &m0_get()->i_storage_devs;
220  struct m0_stob_id id;
221  struct m0_stob *stob;
222  int rc;
223 
224  /* Current function is aware of internal logic of adstob storage */
226 
227  m0_stob_id_make(0, cid, &devs->sds_back_domain->sd_id, &id);
228  rc = m0_stob_lookup(&id, &stob);
229  if (rc == 0 && stob != NULL)
230  m0_stob_put(stob);
231  return rc == 0 && stob != NULL;
232 }
233 
234 static void test_spiel_device_cmds(void)
235 {
236  /*
237  * According to ut/conf.xc:
238  * - disk-78 is associated with sdev-74;
239  * - sdev-74 belongs to IO service-9 of process-5;
240  * - disk-55 is associated with sdev-51;
241  * - sdev-51 belongs to IO service-27 of process-49;
242  * - disk-23 does not exist.
243  */
244  uint64_t io_sdev = 5;
245  uint64_t foreign_sdev = 51;
246  const struct m0_fid io_disk = M0_FID_TINIT(
248  const struct m0_fid foreign_disk = M0_FID_TINIT(
250  const struct m0_fid nosuch_disk = M0_FID_TINIT(
252  int rc;
253  uint32_t ha_state;
254 
256  /*
257  * After motr startup devices are online by default,
258  * so detach them at first.
259  */
260  m0_fi_enable_once("m0_rpc_reply_post", "delay_reply");
261  m0_fi_enable_once("spiel_cmd_send", "timeout");
262  rc = m0_spiel_device_detach(&spiel, &io_disk);
263  M0_UT_ASSERT(rc == -ETIMEDOUT);
264 
265  rc = m0_spiel_device_detach(&spiel, &io_disk);
266  M0_UT_ASSERT(rc == 0);
267  M0_UT_ASSERT(!spiel_stob_exists(io_sdev));
268 
269  rc = m0_spiel_device_format(&spiel, &io_disk);
270  M0_UT_ASSERT(rc == 0);
271  M0_UT_ASSERT(!spiel_stob_exists(io_sdev));
272 
273  /*
274  * in the course of action test as well if device state is updated on
275  * remote side when attaching
276  */
278  m0_fi_enable_once("m0_storage_dev_new_by_conf", "no_real_dev");
279  rc = m0_spiel_device_attach_state(&spiel, &io_disk, &ha_state);
280  M0_UT_ASSERT(rc == 0);
282 
283  /*
284  * Server part processes foreign_disk as disk from another process.
285  */
286  rc = m0_spiel_device_format(&spiel, &foreign_disk);
287  M0_UT_ASSERT(rc == 0);
288 
289  m0_fi_enable_once("m0_storage_dev_new_by_conf", "no_real_dev");
290  rc = m0_spiel_device_attach(&spiel, &foreign_disk);
291  M0_UT_ASSERT(rc == 0);
292  /*
293  * Stob is not created for device that does not belong to IO service
294  * of current process, which is process-5.
295  */
296  M0_UT_ASSERT(!spiel_stob_exists(foreign_sdev));
297 
298  rc = m0_spiel_device_detach(&spiel, &foreign_disk);
299  M0_UT_ASSERT(rc == 0);
300  M0_UT_ASSERT(!spiel_stob_exists(foreign_sdev));
301 
302  rc = m0_spiel_device_attach(&spiel, &nosuch_disk);
303  M0_UT_ASSERT(rc == -ENOENT);
305 
306  /*
307  * XXX This "once" injection is not triggered. It may be redundant
308  * or the test expects call of the function and it doesn't happen.
309  */
310  m0_fi_disable("m0_storage_dev_new_by_conf", "no_real_dev");
311 }
312 
313 static void test_spiel_service_order(void)
314 {
315  int rc;
316  int i;
317  struct m0_spiel_running_svc *svcs;
318  const struct m0_fid process_fid = M0_FID_TINIT(
320  const struct m0_fid svc_fid = M0_FID_TINIT(
322  bool found = false;
323 
325  /* Doing process quiesce */
327  M0_UT_ASSERT(rc == 0);
328 
329  /* Doing `service stop` intialised during startup. */
330  rc = m0_spiel_service_stop(&spiel, &svc_fid);
331  M0_UT_ASSERT(rc == 0);
332 
333  /* Doing `service start` after process quiesce. */
334  rc = m0_spiel_service_init(&spiel, &svc_fid);
335  M0_UT_ASSERT(rc == 0);
336 
337  rc = m0_spiel_service_start(&spiel, &svc_fid);
338  M0_UT_ASSERT(rc == 0);
339 
340  /* Read Service list - rmservice must be started */
342  M0_UT_ASSERT(rc > 0);
343  M0_UT_ASSERT(svcs != NULL);
344  for (i = 0; i < rc; ++i) {
345  found |= m0_streq(svcs[i].spls_name, "M0_CST_RMS");
346  m0_free(svcs[i].spls_name);
347  }
348  m0_free(svcs);
351 }
352 
354  struct m0_conf_service *ios)
355 {
356  struct m0_conf_obj *sdevs_dir = &ios->cs_sdevs->cd_obj;
357  struct m0_conf_obj *obj;
358  struct m0_conf_sdev *sdev;
359  uint64_t total = 0;
360  int rc;
361 
362  rc = m0_confc_open_sync(&sdevs_dir, sdevs_dir, M0_FID0);
363  M0_UT_ASSERT(rc == 0);
364  obj = NULL;
365  while (m0_confc_readdir_sync(sdevs_dir, &obj) > 0) {
366  sdev = M0_CONF_CAST(obj, m0_conf_sdev);
368  total += sdev->sd_size;
369  }
370 
372  m0_confc_close(sdevs_dir);
373  return total;
374 }
375 
376 static bool test_spiel_filter_service(const struct m0_conf_obj *obj)
377 {
379 }
380 
381 static uint64_t test_spiel_fs_ios_total(void)
382 {
383  struct m0_confc confc;
384  struct m0_conf_diter it;
385  struct m0_conf_obj *root_obj;
386  struct m0_conf_service *svc;
387  char *confstr = NULL;
388  int rc;
389  uint64_t svc_total = 0;
390  uint64_t total = 0;
391 
392  rc = m0_file_read(M0_UT_PATH("conf.xc"), &confstr);
393  M0_UT_ASSERT(rc == 0);
395  confstr);
396  M0_UT_ASSERT(rc == 0);
397  m0_free0(&confstr);
398  rc = m0_confc_open_sync(&root_obj, confc.cc_root, M0_FID0);
399  M0_UT_ASSERT(rc == 0);
400  rc = m0_conf_diter_init(&it, &confc, root_obj,
401  M0_CONF_ROOT_NODES_FID,
402  M0_CONF_NODE_PROCESSES_FID,
403  M0_CONF_PROCESS_SERVICES_FID);
404  M0_UT_ASSERT(rc == 0);
406  M0_CONF_DIRNEXT) {
408  if(svc->cs_type == M0_CST_IOS) {
410  svc);
412  svc_total));
413  total += svc_total;
414  }
415  }
417  m0_confc_close(root_obj);
419  return total;
420 }
421 
422 static void spiel_fs_stats_check(const struct m0_fs_stats *stats)
423 {
424  M0_UT_ASSERT(stats->fs_free_disk <= stats->fs_total_disk);
425  M0_UT_ASSERT(stats->fs_svc_total >= stats->fs_svc_replied);
426 }
427 
428 extern uint32_t m0_rpc__filter_opcode[4];
429 
431 {
432  int rc;
433  uint64_t ios_total;
434  struct m0_fs_stats fs_stats = {0};
435  struct m0_ha_note note = {
436  .no_id = M0_FID_TINIT('r', 1, 5),
437  .no_state = M0_NC_FAILED
438  };
439  struct m0_ha_nvec nvec = {
440  .nv_nr = 1,
441  .nv_note = &note
442  };
443 
444  m0_fi_enable_once("cs_storage_devs_init", "init_via_conf");
445  m0_fi_enable("m0_storage_dev_new_by_conf", "no_real_dev");
446  m0_fi_enable("m0_storage_dev_new", "no_real_dev");
448  m0_fi_disable("m0_storage_dev_new_by_conf", "no_real_dev");
449  m0_fi_disable("m0_storage_dev_new", "no_real_dev");
450 
451  m0_fi_enable_once("spiel__item_enlist", "alloc fail");
453  M0_UT_ASSERT(rc == -ENOMEM);
454 
455  /* spiel__proc_is_to_update_stats */
456  m0_fi_enable_once("spiel__proc_is_to_update_stats", "open_by_fid");
458  M0_UT_ASSERT(rc == 0);
459  spiel_fs_stats_check(&fs_stats);
460  m0_fi_enable_once("spiel__proc_is_to_update_stats", "diter_init");
462  M0_UT_ASSERT(rc == 0);
463  spiel_fs_stats_check(&fs_stats);
464  m0_fi_enable_once("spiel__proc_is_to_update_stats", "ha_update");
466  M0_UT_ASSERT(rc == 0);
467  spiel_fs_stats_check(&fs_stats);
469  m0_ha_state_accept(&nvec, false);
471  M0_UT_ASSERT(rc == 0);
472  spiel_fs_stats_check(&fs_stats);
473  note.no_state = M0_NC_ONLINE;
474  m0_ha_state_accept(&nvec, false);
476 
477  /* spiel_process__health_async */
478  m0_fi_enable_once("m0_net_end_point_create", "fake_error");
480  M0_UT_ASSERT(rc == 0);
481  spiel_fs_stats_check(&fs_stats);
482  m0_fi_enable_once("spiel_process__health_async", "obj_find");
484  M0_UT_ASSERT(rc == 0);
485  spiel_fs_stats_check(&fs_stats);
486 
487  /* spiel_proc_item_rlink_cb */
488  m0_fi_enable("item_received_fi", "drop_opcode");
491  m0_fi_disable("item_received_fi", "drop_opcode");
492  M0_UT_ASSERT(rc == 0);
493  spiel_fs_stats_check(&fs_stats);
494  m0_fi_enable_once("spiel_proc_item_rlink_cb", "alloc_fail");
496  M0_UT_ASSERT(rc == 0);
497  spiel_fs_stats_check(&fs_stats);
498  m0_fi_enable_once("spiel_proc_item_rlink_cb", "rpc_post");
500  M0_UT_ASSERT(rc == 0);
501  spiel_fs_stats_check(&fs_stats);
502  /* spiel_process_health_replied_ast */
503  m0_fi_enable_once("spiel_process_health_replied_ast", "item_error");
505  M0_UT_ASSERT(rc == 0);
506  spiel_fs_stats_check(&fs_stats);
507  m0_fi_enable_once("spiel_process_health_replied_ast", "overflow");
509  M0_UT_ASSERT(rc == -EOVERFLOW);
510  /* test the existent one */
511  m0_fi_enable("ss_ios_stats_ingest", "take_dsx_in_effect");
513  M0_UT_ASSERT(rc == 0);
514  m0_fi_disable("ss_ios_stats_ingest", "take_dsx_in_effect");
515  spiel_fs_stats_check(&fs_stats);
516  ios_total = test_spiel_fs_ios_total();
517  M0_UT_ASSERT(fs_stats.fs_total_disk > ios_total);
519 }
520 
522 {
523  int rc;
524  struct m0_proc_counter count_stats;
525  struct m0_fid proc_fid = M0_FID_TINIT('r', 1, 6);
526  struct m0_fid temp_fid = M0_FID_TINIT('v', 1, 8);
527 
529 
530  M0_SET0(&count_stats);
531  m0_fi_enable_once("ss_bytecount_stats_ingest", "dummy_bytecount_data");
532  rc = m0_spiel_proc_counters_fetch(&spiel, &proc_fid, &count_stats);
533 
534  M0_UT_ASSERT(m0_fid_eq(&count_stats.pc_proc_fid, &proc_fid));
535  M0_UT_ASSERT(count_stats.pc_cnt = 1);
536  M0_UT_ASSERT(m0_fid_eq(&count_stats.pc_bckey[0]->sbk_fid, &temp_fid));
537  M0_UT_ASSERT(count_stats.pc_bckey[0]->sbk_user_id == 8881212);
538  M0_UT_ASSERT(count_stats.pc_bcrec[0]->sbr_byte_count == 10240000);
539  M0_UT_ASSERT(count_stats.pc_bcrec[0]->sbr_object_count == 10000);
540  M0_UT_ASSERT(rc == 0);
541 
543 }
544 
545 static void spiel_repair_start(const struct m0_fid *pool_fid,
546  const struct m0_fid *svc_fid,
547  enum m0_repreb_type type)
548 {
549  struct m0_spiel_repreb_status *status;
550  enum m0_cm_status state;
551  int rc;
552 
553  rc = (type == M0_REPREB_TYPE_SNS) ?
554  m0_spiel_sns_repair_start(&spiel, pool_fid) :
555  m0_spiel_dix_repair_start(&spiel, pool_fid);
556  M0_UT_ASSERT(rc == 0);
557  rc = (type == M0_REPREB_TYPE_SNS) ?
558  m0_spiel_sns_repair_status(&spiel, pool_fid, &status) :
559  m0_spiel_dix_repair_status(&spiel, pool_fid, &status);
560  M0_UT_ASSERT(rc == 1);
561  state = status[0].srs_state;
562  M0_UT_ASSERT(m0_fid_eq(&status[0].srs_fid, svc_fid));
564  M0_UT_ASSERT(status[0].srs_progress >= 0);
565  m0_free(status);
566 }
567 
569  enum m0_cm_op op,
570  struct m0_spiel_repreb_status **status,
571  const struct m0_fid *pool_fid,
572  const struct m0_fid *svc_fid)
573 {
574  enum m0_cm_status state;
575  int rc;
576 
577  while(1) {
578  if (type == M0_REPREB_TYPE_SNS)
579  rc = op == CM_OP_REPAIR ?
581  status) :
583  status);
584  else
585  rc = op == CM_OP_REPAIR ?
587  status) :
589  status);
590 
591  M0_UT_ASSERT(rc == 1);
592  state = (*status)[0].srs_state;
593  M0_UT_ASSERT(m0_fid_eq(&(*status)[0].srs_fid, svc_fid));
594  M0_UT_ASSERT(M0_IN(state, (CM_STATUS_IDLE,
597  CM_STATUS_FAILED)));
598  M0_UT_ASSERT((*status)[0].srs_progress >= 0);
599 
600  if (M0_IN(state, (CM_STATUS_IDLE, CM_STATUS_PAUSED,
602  break;
603  m0_free(*status);
604  }
605 }
606 
608 {
609  const struct m0_fid pool_fid = (type == M0_REPREB_TYPE_SNS) ?
612  struct m0_fid svc_fid = (type == M0_REPREB_TYPE_SNS) ?
615  struct m0_fid pool_invalid_fid = M0_FID_TINIT(
617  struct m0_fid invalid_fid = M0_FID_TINIT(
619  const struct m0_fid io_disk = M0_FID_TINIT(
621  struct m0_spiel_repreb_status *status = NULL;
622  enum m0_cm_status state;
623  int rc;
624 
627  m0_fi_enable("ready", "no_wait");
628  m0_fi_enable("m0_ha_local_state_set", "no_ha");
629  rc = (type == M0_REPREB_TYPE_SNS) ?
630  m0_spiel_sns_repair_start(&spiel, &invalid_fid) :
631  m0_spiel_dix_repair_start(&spiel, &invalid_fid);
632  M0_UT_ASSERT(rc == -EINVAL);
633 
634  rc = (type == M0_REPREB_TYPE_SNS) ?
635  m0_spiel_sns_repair_start(&spiel, &pool_invalid_fid) :
636  m0_spiel_dix_repair_start(&spiel, &pool_invalid_fid);
637  M0_UT_ASSERT(rc == -ENOENT);
638 
639  rc = (type == M0_REPREB_TYPE_SNS) ?
640  m0_spiel_sns_repair_quiesce(&spiel, &invalid_fid) :
641  m0_spiel_dix_repair_quiesce(&spiel, &invalid_fid);
642  M0_UT_ASSERT(rc == -EINVAL);
643  rc = (type == M0_REPREB_TYPE_SNS) ?
644  m0_spiel_sns_repair_abort(&spiel, &invalid_fid) :
645  m0_spiel_dix_repair_abort(&spiel, &invalid_fid);
646  M0_UT_ASSERT(rc == -EINVAL);
647  rc = (type == M0_REPREB_TYPE_SNS) ?
648  m0_spiel_sns_repair_continue(&spiel, &invalid_fid) :
649  m0_spiel_dix_repair_continue(&spiel, &invalid_fid);
650  M0_UT_ASSERT(rc == -EINVAL);
651  rc = (type == M0_REPREB_TYPE_SNS) ?
652  m0_spiel_sns_repair_status(&spiel, &invalid_fid, &status) :
653  m0_spiel_dix_repair_status(&spiel, &invalid_fid, &status);
654  M0_UT_ASSERT(rc == -EINVAL);
655  rc = (type == M0_REPREB_TYPE_SNS) ?
656  m0_spiel_sns_repair_status(&spiel, &pool_fid, &status) :
657  m0_spiel_dix_repair_status(&spiel, &pool_fid, &status);
658  M0_UT_ASSERT(rc == 1);
659  M0_UT_ASSERT(m0_fid_eq(&status[0].srs_fid, &svc_fid));
660  M0_UT_ASSERT(status[0].srs_state == CM_STATUS_IDLE);
661  M0_UT_ASSERT(status[0].srs_progress >= 0);
662  m0_free0(&status);
663 
666  spiel_repair_start(&pool_fid, &svc_fid, type);
667 
668  rc = (type == M0_REPREB_TYPE_SNS) ?
669  m0_spiel_sns_repair_abort(&spiel, &pool_fid) :
670  m0_spiel_dix_repair_abort(&spiel, &pool_fid);
671  M0_UT_ASSERT(rc == 0);
672  wait_for_repair_rebalance(type, CM_OP_REPAIR, &status, &pool_fid, &svc_fid);
673  state = status[0].srs_state;
674  M0_UT_ASSERT(m0_fid_eq(&status[0].srs_fid, &svc_fid));
675  M0_UT_ASSERT(state == CM_STATUS_IDLE);
676  M0_UT_ASSERT(status[0].srs_progress > 0);
677  m0_free0(&status);
678 
679  spiel_repair_start(&pool_fid, &svc_fid, type);
680 
681  rc = (type == M0_REPREB_TYPE_SNS) ?
682  m0_spiel_sns_repair_quiesce(&spiel, &pool_fid) :
683  m0_spiel_dix_repair_quiesce(&spiel, &pool_fid);
684  M0_UT_ASSERT(rc == 0);
685 
686  wait_for_repair_rebalance(type, CM_OP_REPAIR, &status, &pool_fid, &svc_fid);
687  M0_UT_ASSERT(m0_fid_eq(&status[0].srs_fid, &svc_fid));
689  M0_UT_ASSERT(status[0].srs_progress >= 0);
690  m0_free0(&status);
691 
692  rc = (type == M0_REPREB_TYPE_SNS) ?
693  m0_spiel_sns_repair_continue(&spiel, &pool_fid) :
694  m0_spiel_dix_repair_continue(&spiel, &pool_fid);
695  M0_UT_ASSERT(rc == 0);
696  wait_for_repair_rebalance(type, CM_OP_REPAIR, &status, &pool_fid, &svc_fid);
698  m0_free0(&status);
699  m0_fi_disable("ready", "no_wait");
700  m0_fi_disable("m0_ha_local_state_set", "no_ha");
702 }
703 
704 static void test_spiel_sns_repair(void)
705 {
707 }
708 
709 static void test_spiel_dix_repair(void)
710 {
712 }
713 
715 {
716  const struct m0_fid pool_fid = (type == M0_REPREB_TYPE_SNS) ?
719  struct m0_fid svc_fid = (type == M0_REPREB_TYPE_SNS) ?
722  struct m0_fid pool_invalid_fid = M0_FID_TINIT(
724  struct m0_fid invalid_fid = M0_FID_TINIT(
726  const struct m0_fid io_disk = M0_FID_TINIT(
728  struct m0_spiel_repreb_status *status;
729  enum m0_cm_status state;
730  int rc;
731 
734  m0_fi_enable("ready", "no_wait");
735  m0_fi_enable("m0_ha_local_state_set", "no_ha");
740  rc = (type == M0_REPREB_TYPE_SNS) ?
741  m0_spiel_sns_rebalance_start(&spiel, &invalid_fid) :
742  m0_spiel_dix_rebalance_start(&spiel, &invalid_fid);
743  M0_UT_ASSERT(rc == -EINVAL);
744 
745  rc = (type == M0_REPREB_TYPE_SNS) ?
746  m0_spiel_sns_rebalance_start(&spiel, &pool_invalid_fid) :
747  m0_spiel_dix_rebalance_start(&spiel, &pool_invalid_fid);
748  M0_UT_ASSERT(rc == -ENOENT);
749 
750  rc = (type == M0_REPREB_TYPE_SNS) ?
751  m0_spiel_sns_rebalance_quiesce(&spiel, &invalid_fid) :
752  m0_spiel_dix_rebalance_quiesce(&spiel, &invalid_fid);
753  M0_UT_ASSERT(rc == -EINVAL);
754  rc = (type == M0_REPREB_TYPE_SNS) ?
755  m0_spiel_sns_rebalance_continue(&spiel, &invalid_fid) :
756  m0_spiel_dix_rebalance_continue(&spiel, &invalid_fid);
757  M0_UT_ASSERT(rc == -EINVAL);
758  rc = (type == M0_REPREB_TYPE_SNS) ?
759  m0_spiel_sns_rebalance_status(&spiel, &invalid_fid, &status) :
760  m0_spiel_dix_rebalance_status(&spiel, &invalid_fid, &status);
761  M0_UT_ASSERT(rc == -EINVAL);
762 
763  rc = (type == M0_REPREB_TYPE_SNS) ?
764  m0_spiel_sns_rebalance_status(&spiel, &pool_fid, &status) :
765  m0_spiel_dix_rebalance_status(&spiel, &pool_fid, &status);
766  M0_UT_ASSERT(rc == 1);
767  M0_UT_ASSERT(m0_fid_eq(&status[0].srs_fid, &svc_fid));
768  M0_UT_ASSERT(status[0].srs_state == CM_STATUS_IDLE);
769  M0_UT_ASSERT(status[0].srs_progress >= 0);
770  m0_free(status);
771 
772  rc = (type == M0_REPREB_TYPE_SNS) ?
773  m0_spiel_sns_rebalance_start(&spiel, &pool_fid) :
774  m0_spiel_dix_rebalance_start(&spiel, &pool_fid);
775  M0_UT_ASSERT(rc == 0);
776 
777  rc = (type == M0_REPREB_TYPE_SNS) ?
778  m0_spiel_sns_rebalance_status(&spiel, &pool_fid, &status) :
779  m0_spiel_dix_rebalance_status(&spiel, &pool_fid, &status);
780  M0_UT_ASSERT(rc == 1);
781  state = status[0].srs_state;
782  M0_UT_ASSERT(m0_fid_eq(&status[0].srs_fid, &svc_fid));
784  CM_STATUS_FAILED)));
785  M0_UT_ASSERT(status[0].srs_progress >= 0);
786  m0_free(status);
787  if (M0_IN(state, (CM_STATUS_IDLE, CM_STATUS_FAILED)))
788  goto done;
789 
790  rc = (type == M0_REPREB_TYPE_SNS) ?
793  M0_UT_ASSERT(rc == 0);
794 
795  wait_for_repair_rebalance(type, CM_OP_REBALANCE, &status, &pool_fid, &svc_fid);
796  M0_UT_ASSERT(m0_fid_eq(&status[0].srs_fid, &svc_fid));
798  M0_UT_ASSERT(status[0].srs_progress >= 0);
799  m0_free(status);
800 
801  rc = (type == M0_REPREB_TYPE_SNS) ?
804  M0_UT_ASSERT(rc == 0);
805 
806  wait_for_repair_rebalance(type, CM_OP_REBALANCE, &status, &pool_fid, &svc_fid);
808  m0_free(status);
809 
810 done:
811  m0_fi_disable("ready", "no_wait");
812  m0_fi_disable("m0_ha_local_state_set", "no_ha");
814 }
815 
816 static void test_spiel_sns_rebalance(void)
817 {
819 }
820 
821 static void test_spiel_dix_rebalance(void)
822 {
824 }
825 
827 {
829 }
830 
832 {
833  return m0_conf_ut_ast_thread_fini() ?: system("rm -rf ut_spiel.db/");
834 }
835 
837  .ts_name = "spiel-ci-ut",
838  .ts_init = spiel_ci_tests_init,
839  .ts_fini = spiel_ci_tests_fini,
840  .ts_tests = {
841  { "service-cmds", test_spiel_service_cmds },
842  { "process-cmds", test_spiel_process_cmds },
843  { "service-order", test_spiel_service_order },
844  { "process-services-list", test_spiel_process_services_list },
845  { "device-cmds", test_spiel_device_cmds },
846  { "stats", test_spiel_fs_stats },
847  { "bytecount-stats", test_spiel_bc_stats },
848  { "pool-sns-repair", test_spiel_sns_repair },
849  { "pool-sns-rebalance", test_spiel_sns_rebalance },
850  { "pool-dix-repair", test_spiel_dix_repair },
851  { "pool-dix-rebalance", test_spiel_dix_rebalance },
852  { NULL, NULL }
853  }
854 };
855 
856 #undef M0_TRACE_SUBSYSTEM
const struct m0_conf_obj_type * m0_conf_obj_type(const struct m0_conf_obj *obj)
Definition: obj.c:363
static void test_spiel_service_cmds(void)
Definition: spiel_ci_ut.c:72
uint64_t id
Definition: cob.h:2380
m0_cm_status
Definition: cm.h:54
M0_INTERNAL uint64_t m0_ha_msg_nvec_send(const struct m0_ha_nvec *nvec, uint64_t id_of_get, bool ignore_same_state, int direction, struct m0_ha_link *hl)
Definition: note.c:279
int m0_spiel_sns_rebalance_quiesce(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1566
struct m0_conf_obj * cc_root
Definition: confc.h:404
static int spiel_ci_tests_fini()
Definition: spiel_ci_ut.c:831
#define M0_PRE(cond)
static void test_spiel_device_cmds(void)
Definition: spiel_ci_ut.c:234
int m0_spiel_sns_rebalance_continue(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1531
struct m0_spiel_bckey ** pc_bckey
Definition: spiel.h:1281
struct m0_conf_dir * cs_sdevs
Definition: obj.h:596
struct m0_ut_suite spiel_ci_ut
Definition: spiel_ci_ut.c:836
uint32_t pc_cnt
Definition: spiel.h:1279
int m0_spiel_sns_rebalance_status(struct m0_spiel *spl, const struct m0_fid *pool_fid, struct m0_spiel_repreb_status **statuses)
Definition: cmd.c:1593
#define NULL
Definition: misc.h:38
static bool test_spiel_filter_service(const struct m0_conf_obj *obj)
Definition: spiel_ci_ut.c:376
struct m0_conf_obj cd_obj
Definition: obj.h:358
static void test_spiel_process_services_list(void)
Definition: spiel_ci_ut.c:129
static uint64_t tag(uint8_t code, uint64_t id)
Definition: addb2.c:1047
int m0_spiel_dix_repair_abort(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1448
M0_INTERNAL int m0_file_read(const char *path, char **out)
Definition: fs.c:61
uint8_t ft_id
Definition: fid.h:101
const struct m0_conf_obj_type M0_CONF_SERVICE_TYPE
Definition: service.c:156
struct m0_fid sbk_fid
Definition: spiel.h:1261
unsigned int srs_progress
Definition: spiel.h:170
int m0_spiel_sns_repair_status(struct m0_spiel *spl, const struct m0_fid *pool_fid, struct m0_spiel_repreb_status **statuses)
Definition: cmd.c:1465
M0_INTERNAL int m0_ha_client_del(struct m0_confc *confc)
Definition: epoch.c:232
static void spiel_fs_stats_check(const struct m0_fs_stats *stats)
Definition: spiel_ci_ut.c:422
int m0_spiel_service_start(struct m0_spiel *spl, const struct m0_fid *svc_fid)
Definition: cmd.c:516
M0_INTERNAL int m0_confc_init(struct m0_confc *confc, struct m0_sm_group *sm_group, const char *confd_addr, struct m0_rpc_machine *rpc_mach, const char *local_conf)
Definition: confc.c:560
int m0_spiel_dix_repair_quiesce(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1421
M0_INTERNAL int m0_conf_diter_next_sync(struct m0_conf_diter *it, bool(*filter)(const struct m0_conf_obj *obj))
Definition: diter.c:555
static void test_spiel_pool_rebalance(enum m0_repreb_type type)
Definition: spiel_ci_ut.c:714
m0_bcount_t fs_total_disk
Definition: spiel.h:1326
int m0_spiel_sns_repair_abort(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1438
static struct m0_be_emap_cursor it
Definition: extmap.c:46
M0_INTERNAL void m0_confc_fini(struct m0_confc *confc)
Definition: confc.c:570
static bool m0_addu64_will_overflow(uint64_t a, uint64_t b)
Definition: arith.h:235
const struct m0_conf_obj_type M0_CONF_POOL_TYPE
Definition: pool.c:249
static void test_spiel_sns_repair(void)
Definition: spiel_ci_ut.c:704
int m0_spiel_device_attach_state(struct m0_spiel *spl, const struct m0_fid *dev_fid, uint32_t *ha_state)
Definition: cmd.c:647
m0_cm_op
Definition: cm.h:37
int m0_spiel_dix_rebalance_continue(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1549
M0_INTERNAL struct m0 * m0_get(void)
Definition: instance.c:41
#define M0_SRC_PATH(name)
Definition: misc.h:48
#define M0_SET0(obj)
Definition: misc.h:64
struct m0_spiel_bcrec ** pc_bcrec
Definition: spiel.h:1282
Definition: ut.h:77
static void test_spiel_service_order(void)
Definition: spiel_ci_ut.c:313
struct m0_stob_domain * sds_back_domain
Definition: storage_dev.h:134
int m0_spiel_dix_repair_start(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1367
static struct foo * obj
Definition: tlist.c:302
enum m0_storage_dev_type sds_type
Definition: storage_dev.h:128
static uint64_t test_spiel_fs_stats_sdevs_total(struct m0_confc *confc, struct m0_conf_service *ios)
Definition: spiel_ci_ut.c:353
struct m0_fid fid
Definition: di.c:46
int m0_spiel_sns_rebalance_start(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1504
struct m0_reqh_service_type m0_confd_stype
Definition: confd.c:453
int m0_spiel_sns_repair_start(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1357
int m0_spiel_device_format(struct m0_spiel *spl, const struct m0_fid *dev_fid)
Definition: cmd.c:667
op
Definition: libdemo.c:64
struct m0_fid srs_fid
Definition: spiel.h:166
int m0_spiel_device_detach(struct m0_spiel *spl, const struct m0_fid *dev_fid)
Definition: cmd.c:658
void test_spiel_bc_stats(void)
Definition: spiel_ci_ut.c:521
m0_repreb_type
Definition: spiel.h:183
static void test_spiel_dix_rebalance(void)
Definition: spiel_ci_ut.c:821
M0_INTERNAL int m0_stob_lookup(const struct m0_stob_id *id, struct m0_stob **out)
Definition: stob.c:119
M0_INTERNAL void m0_spiel__ut_fini(struct m0_spiel *spiel, bool cmd_iface)
static void spiel_ci_ut_init(void)
Definition: spiel_ci_ut.c:46
struct m0_storage_devs i_storage_devs
Definition: instance.h:123
int m0_spiel_sns_repair_continue(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1384
int i
Definition: dir.c:1033
int m0_spiel_process_reconfig(struct m0_spiel *spl, const struct m0_fid *proc_fid)
Definition: cmd.c:788
int m0_spiel_service_status(struct m0_spiel *spl, const struct m0_fid *svc_fid, int *status)
Definition: cmd.c:556
struct m0_spiel::m0_spiel_core spl_core
int32_t nv_nr
Definition: note.h:196
const struct m0_build_info * m0_build_info_get(void)
Definition: version.c:61
static void spiel_repair_start(const struct m0_fid *pool_fid, const struct m0_fid *svc_fid, enum m0_repreb_type type)
Definition: spiel_ci_ut.c:545
#define M0_FID_TINIT(type, container, key)
Definition: fid.h:90
M0_INTERNAL void m0_fi_disable(const char *fp_func, const char *fp_tag)
Definition: finject.c:485
Definition: stob.h:163
M0_INTERNAL int m0_conf_ut_ast_thread_fini(void)
Definition: common.c:96
const struct m0_fid_type cot_ftype
Definition: obj.h:314
static void m0_fi_enable(const char *func, const char *tag)
Definition: finject.h:276
static struct m0_stob * stob
Definition: storage.c:39
#define m0_free0(pptr)
Definition: memory.h:77
int m0_spiel_process_stop(struct m0_spiel *spl, const struct m0_fid *proc_fid)
Definition: cmd.c:781
#define M0_ASSERT(cond)
static struct m0_confc * confc
Definition: file.c:94
static void wait_for_repair_rebalance(enum m0_repreb_type type, enum m0_cm_op op, struct m0_spiel_repreb_status **status, const struct m0_fid *pool_fid, const struct m0_fid *svc_fid)
Definition: spiel_ci_ut.c:568
static void spiel_ci_ut_fini(void)
Definition: spiel_ci_ut.c:53
int m0_spiel_process_quiesce(struct m0_spiel *spl, const struct m0_fid *proc_fid)
Definition: cmd.c:821
uint64_t sbk_user_id
Definition: spiel.h:1262
int m0_spiel_dix_rebalance_status(struct m0_spiel *spl, const struct m0_fid *pool_fid, struct m0_spiel_repreb_status **statuses)
Definition: cmd.c:1608
#define m0_streq(a, b)
Definition: string.h:34
int m0_spiel_service_quiesce(struct m0_spiel *spl, const struct m0_fid *svc_fid)
Definition: cmd.c:546
static void test_spiel_pool_repair(enum m0_repreb_type type)
Definition: spiel_ci_ut.c:607
int m0_spiel_service_init(struct m0_spiel *spl, const struct m0_fid *svc_fid)
Definition: cmd.c:507
M0_INTERNAL void m0_stob_id_make(uint64_t container, uint64_t key, const struct m0_fid *dom_id, struct m0_stob_id *stob_id)
Definition: stob.c:343
int m0_spiel_dix_repair_status(struct m0_spiel *spl, const struct m0_fid *pool_fid, struct m0_spiel_repreb_status **statuses)
Definition: cmd.c:1480
struct m0_confc * spc_confc
Definition: spiel.h:210
int m0_spiel_dix_rebalance_quiesce(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1576
static char * proc_fid
Definition: m0hsm.c:45
static uint64_t test_spiel_fs_ios_total(void)
Definition: spiel_ci_ut.c:381
const struct m0_conf_obj_type M0_CONF_DRIVE_TYPE
Definition: drive.c:108
enum m0_cm_status srs_state
Definition: spiel.h:168
uint64_t sd_size
Definition: obj.h:643
#define M0_CONF_CAST(ptr, type)
Definition: obj.h:780
static struct m0_spiel spiel
Definition: spiel_ci_ut.c:44
#define m0_confc_open_sync(result, origin,...)
Definition: confc.h:707
int m0_spiel_device_attach(struct m0_spiel *spl, const struct m0_fid *dev_fid)
Definition: cmd.c:641
static void test_spiel_sns_rebalance(void)
Definition: spiel_ci_ut.c:816
struct m0_fid no_id
Definition: note.h:180
int m0_spiel_dix_repair_continue(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1394
static void spiel_ci_ut_ha_state_set(const struct m0_fid *fid, uint32_t state)
Definition: spiel_ci_ut.c:60
M0_INTERNAL void m0_spiel__ut_init(struct m0_spiel *spiel, const char *confd_path, bool cmd_iface)
M0_INTERNAL int m0_conf_ut_ast_thread_init(void)
Definition: common.c:86
int m0_spiel_service_stop(struct m0_spiel *spl, const struct m0_fid *svc_fid)
Definition: cmd.c:525
struct m0_ha_link * i_ha_link
Definition: instance.h:110
int m0_spiel_service_health(struct m0_spiel *spl, const struct m0_fid *svc_fid)
Definition: cmd.c:537
M0_INTERNAL bool m0_fid_eq(const struct m0_fid *fid0, const struct m0_fid *fid1)
Definition: fid.c:164
uint64_t sbr_byte_count
Definition: spiel.h:1266
M0_INTERNAL struct m0_conf_obj * m0_conf_diter_result(const struct m0_conf_diter *it)
Definition: diter.c:576
struct m0_reqh_service_type m0_rms_type
Definition: rm_service.c:69
struct m0_fid sd_id
Definition: domain.h:96
#define m0_conf_diter_init(iter, confc, origin,...)
Definition: diter.h:235
const char * ts_name
Definition: ut.h:99
void test_spiel_fs_stats(void)
Definition: spiel_ci_ut.c:430
static bool spiel_stob_exists(uint64_t cid)
Definition: spiel_ci_ut.c:217
uint32_t m0_rpc__filter_opcode[4]
Definition: rpc_machine.c:910
static void test_spiel_process_cmds(void)
Definition: spiel_ci_ut.c:148
M0_INTERNAL struct m0_locality * m0_locality0_get(void)
Definition: locality.c:169
int m0_spiel_dix_rebalance_start(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1514
Definition: fid.h:38
M0_INTERNAL void m0_ha_link_wait_delivery(struct m0_ha_link *hl, uint64_t tag)
Definition: link.c:669
static void test_spiel_dix_repair(void)
Definition: spiel_ci_ut.c:709
int m0_spiel_process_list_services(struct m0_spiel *spl, const struct m0_fid *proc_fid, struct m0_spiel_running_svc **services)
Definition: cmd.c:858
int m0_spiel_sns_repair_quiesce(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1411
int m0_spiel_filesystem_stats_fetch(struct m0_spiel *spl, struct m0_fs_stats *stats)
Definition: cmd.c:2374
Definition: beck.c:130
M0_INTERNAL void m0_conf_diter_fini(struct m0_conf_diter *it)
Definition: diter.c:313
int m0_spiel_process_health(struct m0_spiel *spl, const struct m0_fid *proc_fid)
Definition: cmd.c:814
static struct m0_net_test_service svc
Definition: service.c:34
int m0_spiel_process_lib_load(struct m0_spiel *spl, const struct m0_fid *proc_fid, const char *libname)
Definition: cmd.c:892
M0_INTERNAL int m0_ha_client_add(struct m0_confc *confc)
Definition: epoch.c:191
static void m0_fi_enable_once(const char *func, const char *tag)
Definition: finject.h:301
M0_INTERNAL void m0_confc_close(struct m0_conf_obj *obj)
Definition: confc.c:921
static int spiel_ci_tests_init()
Definition: spiel_ci_ut.c:826
static uint64_t found
Definition: base.c:376
static unsigned done
Definition: storage.c:91
const struct m0_conf_obj_type M0_CONF_PROCESS_TYPE
Definition: process.c:161
#define M0_UT_PATH(name)
Definition: misc.h:41
static int total
Definition: base.c:302
struct m0_fid pc_proc_fid
Definition: spiel.h:1280
int type
Definition: dir.c:1031
#define M0_FID0
Definition: fid.h:93
int m0_spiel_proc_counters_fetch(struct m0_spiel *spl, struct m0_fid *proc_fid, struct m0_proc_counter *count_stats)
Definition: cmd.c:2211
M0_INTERNAL void m0_ha_state_accept(const struct m0_ha_nvec *note, bool ignore_same_state)
Definition: note.c:189
void m0_free(void *data)
Definition: memory.c:146
uint64_t sbr_object_count
Definition: spiel.h:1267
M0_INTERNAL int m0_confc_readdir_sync(struct m0_conf_obj *dir, struct m0_conf_obj **pptr)
Definition: confc.c:1020
int32_t rc
Definition: trigger_fop.h:47
#define M0_UT_ASSERT(a)
Definition: ut.h:46
M0_INTERNAL void m0_stob_put(struct m0_stob *stob)
Definition: stob.c:291
static const char * process_fid
Definition: idx_dix.c:73
uint32_t no_state
Definition: note.h:182