Motr  M0
setup.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-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 #include <stdio.h> /* fprintf */
24 #include <sys/stat.h> /* mkdir */
25 #include <unistd.h> /* daemon */
26 #include <err.h>
27 
28 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_M0D
29 #include "lib/trace.h"
30 
31 #include "lib/assert.h"
32 #include "lib/errno.h"
33 #include "lib/finject.h" /* M0_FI_ENABLED */
34 #include "lib/string.h" /* m0_strdup, m0_streq */
35 #include "lib/getopts.h"
36 #include "lib/memory.h"
37 #include "lib/misc.h"
38 #include "lib/locality.h"
39 #include "lib/uuid.h" /* m0_uuid_generate */
40 #include "lib/fs.h" /* m0_file_read */
41 #include "lib/thread.h" /* m0_process */
42 #include "fid/fid.h"
43 #include "stob/ad.h"
44 #include "net/net.h"
45 #include "net/lnet/lnet.h"
46 #include "rpc/rpc.h"
47 #include "reqh/reqh.h"
48 #include "cob/cob.h"
49 #include "mdstore/mdstore.h"
50 #include "motr/setup.h"
51 #include "motr/setup_dix.h" /* m0_cs_dix_setup */
52 #include "motr/setup_internal.h"
53 #include "motr/magic.h"
54 #include "motr/version.h"
55 #include "rpc/rpclib.h"
56 #include "rpc/rpc_internal.h"
57 #include "addb2/storage.h"
58 #include "addb2/net.h"
59 #include "module/instance.h" /* m0_get */
60 #include "conf/obj.h" /* M0_CONF_PROCESS_TYPE */
61 #include "conf/helpers.h" /* m0_confc_args */
62 #include "conf/obj_ops.h" /* M0_CONF_DIRNEXT */
63 #include "be/ut/helper.h"
64 #include "ioservice/fid_convert.h" /* M0_AD_STOB_LINUX_DOM_KEY */
65 #include "ioservice/storage_dev.h"
66 #include "ioservice/io_service.h" /* m0_ios_net_buffer_pool_size_set */
67 #include "stob/linux.h"
68 #include "conf/ha.h" /* m0_conf_ha_process_event_post */
69 #include "dtm0/helper.h" /* m0_dtm0_log_create */
70 
77 
91 enum {
98 };
99 
100 M0_TL_DESCR_DEFINE(cs_buffer_pools, "buffer pools in the motr context",
101  static, struct cs_buffer_pool, cs_bp_linkage, cs_bp_magic,
103 M0_TL_DEFINE(cs_buffer_pools, static, struct cs_buffer_pool);
104 
105 M0_TL_DESCR_DEFINE(cs_eps, "cs endpoints", , struct cs_endpoint_and_xprt,
106  ex_linkage, ex_magix, M0_CS_ENDPOINT_AND_XPRT_MAGIC,
108 
109 M0_TL_DEFINE(cs_eps, M0_INTERNAL, struct cs_endpoint_and_xprt);
110 
111 static struct m0_bob_type cs_eps_bob;
113 
114 M0_INTERNAL const char *m0_cs_stypes[M0_STOB_TYPE_NR] = {
115  [M0_LINUX_STOB] = "Linux",
116  [M0_AD_STOB] = "AD"
117 };
118 
119 static bool reqh_context_check(const void *bob);
120 
121 static struct m0_bob_type rhctx_bob = {
122  .bt_name = "m0_reqh_context",
123  .bt_magix_offset = M0_MAGIX_OFFSET(struct m0_reqh_context, rc_magix),
124  .bt_magix = M0_CS_REQH_CTX_MAGIC,
125  .bt_check = reqh_context_check
126 };
128 
129 M0_TL_DESCR_DEFINE(ndom, "network domains", static, struct m0_net_domain,
130  nd_app_linkage, nd_magix, M0_NET_DOMAIN_MAGIC,
132 
133 M0_TL_DEFINE(ndom, static, struct m0_net_domain);
134 
135 static struct m0_bob_type ndom_bob;
137 
138 static const struct m0_bob_type cs_bob_type = {
139  .bt_name = "m0_motr",
140  .bt_magix_offset = M0_MAGIX_OFFSET(struct m0_motr, cc_magic),
141  .bt_magix = M0_CS_MOTR_MAGIC,
142 };
143 /* "inline" to silence the warning about unused m0_motr_bob_check() */
144 M0_BOB_DEFINE(static inline, &cs_bob_type, m0_motr);
145 
147 {
148  struct m0_motr *cctx = container_of(rctx, struct m0_motr, cc_reqh_ctx);
149 
150  return _0C(ergo(rctx->rc_services[M0_CST_CONFD] != NULL &&
151  m0_streq(rctx->rc_services[M0_CST_CONFD],
152  "M0_CST_CONFD"),
153  rctx->rc_confdb != NULL && *rctx->rc_confdb != '\0')) &&
154  _0C(cctx->cc_no_conf ||
155  ergo(rctx->rc_services[M0_CST_CONFD] == NULL,
156  cctx->cc_ha_addr != NULL &&
157  *cctx->cc_ha_addr != '\0')) &&
159  !cs_eps_tlist_is_empty(&rctx->rc_eps)));
160 }
161 
162 static bool reqh_context_check(const void *bob)
163 {
164  const struct m0_reqh_context *rctx = bob;
165  return
168  RC_INITIALISED))) &&
170  &rctx->rc_eps))) &&
171  _0C(rctx->rc_motr != NULL) &&
174 }
175 
176 static bool reqh_context_invariant(const struct m0_reqh_context *rctx)
177 {
178  return m0_reqh_context_bob_check(rctx); /* calls reqh_context_check() */
179 }
180 
181 static struct m0_reqh *motr2reqh(struct m0_motr *motr)
182 {
183  return &motr->cc_reqh_ctx.rc_reqh;
184 }
185 
186 static struct m0_rconfc *motr2rconfc(struct m0_motr *motr)
187 {
188  return &motr2reqh(motr)->rh_rconfc;
189 }
190 
191 M0_INTERNAL struct m0_confc *m0_motr2confc(struct m0_motr *motr)
192 {
193  return &motr2rconfc(motr)->rc_confc;
194 }
195 
196 M0_INTERNAL struct m0_rpc_machine *m0_motr_to_rmach(struct m0_motr *motr)
197 {
198  return m0_reqh_rpc_mach_tlist_head(&motr2reqh(motr)->rh_rpc_machines);
199 }
200 
211 static struct m0_net_xprt *cs_xprt_lookup(const char *xprt_name,
212  struct m0_net_xprt **xprts,
213  size_t xprts_nr)
214 {
215  size_t i;
216 
217  M0_PRE(xprt_name != NULL && xprts != NULL && xprts_nr > 0);
218 
219  for (i = 0; i < xprts_nr; ++i)
220  if (m0_streq(xprt_name, xprts[i]->nx_name))
221  return xprts[i];
222  return NULL;
223 }
224 
226 static void cs_xprts_list(FILE *out, struct m0_net_xprt **xprts,
227  size_t xprts_nr)
228 {
229  int i;
230 
231  M0_PRE(out != NULL && xprts != NULL);
232 
233  fprintf(out, "\nSupported transports:\n");
234  for (i = 0; i < xprts_nr; ++i)
235  fprintf(out, " %s\n", xprts[i]->nx_name);
236 }
237 
239 static void cs_stob_types_list(FILE *out)
240 {
241  int i;
242 
243  M0_PRE(out != NULL);
244 
245  fprintf(out, "\nSupported stob types:\n");
246  for (i = 0; i < ARRAY_SIZE(m0_cs_stypes); ++i)
247  fprintf(out, " %s\n", m0_cs_stypes[i]);
248 }
249 
251 static bool stype_is_valid(const char *stype)
252 {
253  M0_PRE(stype != NULL);
254 
257 }
258 
264  const struct m0_net_xprt *xprt,
265  const char *ep)
266 {
267  static int (*cmp[])(const char *s1, const char *s2) = {
268  strcmp,
270  };
271  struct cs_endpoint_and_xprt *ex;
272  bool seen = false;
273 
275 
276  m0_tl_for(cs_eps, &rctx->rc_eps, ex) {
277  M0_ASSERT(cs_endpoint_and_xprt_bob_check(ex));
278  if (cmp[!!m0_streq(xprt->nx_name, "lnet")](ex->ex_endpoint,
279  ep) == 0 &&
280  m0_streq(ex->ex_xprt, xprt->nx_name)) {
281  if (seen)
282  return true;
283  else
284  seen = true;
285  }
286  } m0_tl_endfor;
287 
288  return false;
289 }
290 
305 static int cs_endpoint_validate(struct m0_motr *cctx, const char *ep,
306  const char *xprt_name)
307 {
308  struct m0_net_xprt *xprt = NULL;
309 
310  M0_ENTRY();
311  M0_PRE(cctx != NULL);
312 
313  if (ep == NULL || xprt_name == NULL)
314  return M0_RC(-EINVAL);
315 
316  xprt = cs_xprt_lookup(xprt_name, cctx->cc_xprts, cctx->cc_xprts_nr);
317  if (xprt == NULL)
318  return M0_RC(-EINVAL);
319  if (m0_net_xprt_default_get() == NULL)
321 
322  return M0_RC(cs_endpoint_is_duplicate(&cctx->cc_reqh_ctx, xprt, ep) ?
323  -EADDRINUSE : 0);
324 }
325 
326 M0_INTERNAL int m0_ep_and_xprt_extract(struct cs_endpoint_and_xprt *epx,
327  const char *ep)
328 {
329  char *sptr;
330  char *endpoint;
331  int ep_len;
332 
333  M0_PRE(ep != NULL);
334 
335  epx->ex_cep = ep;
336  ep_len = min32u(strlen(ep) + 1, CS_MAX_EP_ADDR_LEN);
337  M0_ALLOC_ARR(epx->ex_scrbuf, ep_len);
338  if (epx->ex_scrbuf == NULL)
339  return M0_ERR(-ENOMEM);
340 
341  strncpy(epx->ex_scrbuf, ep, ep_len);
342  epx->ex_scrbuf[ep_len - 1] = '\0';
343  epx->ex_xprt = strtok_r(epx->ex_scrbuf, ":", &sptr);
344  if (epx->ex_xprt == NULL)
345  goto err;
346 
347  endpoint = strtok_r(NULL, "\0", &sptr);
348  if (endpoint == NULL)
349  goto err;
350 
351  epx->ex_endpoint = endpoint;
352  cs_endpoint_and_xprt_bob_init(epx);
353  cs_eps_tlink_init(epx);
354  return 0;
355 
356 err:
357  m0_free(epx->ex_scrbuf);
358  return M0_ERR(-EINVAL);
359 }
360 
361 M0_INTERNAL void m0_ep_and_xprt_fini(struct cs_endpoint_and_xprt *epx)
362 {
363  M0_PRE(cs_endpoint_and_xprt_bob_check(epx));
364  M0_PRE(epx->ex_scrbuf != NULL);
365  m0_free(epx->ex_scrbuf);
366  cs_eps_tlink_fini(epx);
367  cs_endpoint_and_xprt_bob_fini(epx);
368 }
369 
375 static int ep_and_xprt_append(struct m0_tl *head, const char *ep)
376 {
377  struct cs_endpoint_and_xprt *epx;
378  int rc;
379  M0_PRE(ep != NULL);
380 
381  M0_ALLOC_PTR(epx);
382  if (epx == NULL) {
383  M0_LOG(M0_ERROR, "malloc failed");
384  return M0_ERR(-ENOMEM);
385  }
386 
387  rc = m0_ep_and_xprt_extract(epx, ep);
388  if (rc != 0)
389  goto err;
390 
391  cs_eps_tlist_add_tail(head, epx);
392  return 0;
393 err:
394  m0_free(epx);
395  return M0_ERR(-EINVAL);
396 }
397 
402 static bool service_is_duplicate(const struct m0_reqh_context *rctx,
403  const char *sname)
404 {
405  int n;
406  int i;
407 
409 
410  for (i = 0, n = 0; i < rctx->rc_nr_services; ++i) {
411  if (m0_strcaseeq(rctx->rc_services[i], sname))
412  ++n;
413  if (n > 1)
414  return true;
415  }
416  return false;
417 }
418 
419 static int cs_reqh_ctx_init(struct m0_motr *cctx)
420 {
421  struct m0_reqh_context *rctx = &cctx->cc_reqh_ctx;
422 
423  M0_ENTRY();
424 
425  *rctx = (struct m0_reqh_context) {
426  .rc_motr = cctx
427  };
430  if (rctx->rc_services == NULL || rctx->rc_service_fids == NULL) {
433  return M0_ERR(-ENOMEM);
434  }
435 
436  cs_eps_tlist_init(&rctx->rc_eps);
437  m0_reqh_context_bob_init(rctx);
438 
440  rctx->rc_stob.s_ad_disks_init = false;
441  return M0_RC(0);
442 }
443 
445 {
446  struct cs_endpoint_and_xprt *ep;
447  int i;
448 
449  m0_reqh_context_bob_fini(rctx);
450 
451  m0_tl_teardown(cs_eps, &rctx->rc_eps, ep) {
453  m0_free(ep);
454  };
455  cs_eps_tlist_fini(&rctx->rc_eps);
456 
457  for (i = 0; i < M0_CST_NR; ++i)
462  rctx->rc_stob.s_ad_disks_init = false;
463 }
464 
465 M0_INTERNAL struct m0_net_domain *
466 m0_cs_net_domain_locate(struct m0_motr *cctx, const char *xprt_name)
467 {
468  struct m0_net_domain *ndom;
469 
470  M0_PRE(cctx != NULL && xprt_name != NULL);
471 
472  ndom = m0_tl_find(ndom, ndom, &cctx->cc_ndoms,
473  m0_streq(ndom->nd_xprt->nx_name, xprt_name));
474 
475  M0_ASSERT(ergo(ndom != NULL, m0_net_domain_bob_check(ndom)));
476 
477  return ndom;
478 }
479 
480 static struct m0_net_buffer_pool *
482 {
483  struct cs_buffer_pool *cs_bp;
484 
485  M0_PRE(cctx != NULL);
486  M0_PRE(ndom != NULL);
487 
488  cs_bp = m0_tl_find(cs_buffer_pools, cs_bp, &cctx->cc_buffer_pools,
489  cs_bp->cs_buffer_pool.nbp_ndom == ndom);
490  return cs_bp == NULL ? NULL : &cs_bp->cs_buffer_pool;
491 }
492 
510 static int cs_rpc_machine_init(struct m0_motr *cctx, const char *xprt_name,
511  const char *ep, const uint32_t tm_colour,
512  const uint32_t recv_queue_min_length,
513  const uint32_t max_rpc_msg_size,
514  struct m0_reqh *reqh)
515 {
516  struct m0_rpc_machine *rpcmach;
517  struct m0_net_domain *ndom;
518  struct m0_net_buffer_pool *buffer_pool;
519  int rc;
520 
521  M0_PRE(cctx != NULL && xprt_name != NULL && ep != NULL && reqh != NULL);
522 
523  ndom = m0_cs_net_domain_locate(cctx, xprt_name);
524  if (ndom == NULL)
525  return M0_ERR(-EINVAL);
527  return M0_ERR(-EINVAL);
528 
529  M0_ALLOC_PTR(rpcmach);
530  if (rpcmach == NULL)
531  return M0_ERR(-ENOMEM);
532 
533  buffer_pool = cs_buffer_pool_get(cctx, ndom);
534  rc = m0_rpc_machine_init(rpcmach, ndom, ep,
535  reqh, buffer_pool, tm_colour, max_rpc_msg_size,
536  recv_queue_min_length);
537  if (rc != 0)
538  m0_free(rpcmach);
539  return M0_RC(rc);
540 }
541 
542 static int cs_rpc_machines_init(struct m0_motr *cctx)
543 {
544  struct m0_reqh_context *rctx = &cctx->cc_reqh_ctx;
545  struct cs_endpoint_and_xprt *ep;
546 
547  M0_ENTRY();
549 
550  m0_tl_for(cs_eps, &rctx->rc_eps, ep) {
551  int rc;
552 
553  M0_ASSERT(cs_endpoint_and_xprt_bob_check(ep));
554  rc = cs_rpc_machine_init(cctx, ep->ex_xprt,
555  ep->ex_endpoint, ep->ex_tm_colour,
558  &rctx->rc_reqh);
559  if (rc != 0)
560  return M0_RC(rc);
561  } m0_tl_endfor;
562 
563  return M0_RC(0);
564 }
565 
566 static void cs_rpc_machines_fini(struct m0_reqh *reqh)
567 {
568  struct m0_rpc_machine *rpcmach;
569 
570  m0_tl_for(m0_reqh_rpc_mach, &reqh->rh_rpc_machines, rpcmach) {
571  M0_ASSERT(m0_rpc_machine_bob_check(rpcmach));
572  m0_rpc_machine_fini(rpcmach);
573  m0_free(rpcmach);
574  } m0_tl_endfor;
575 }
576 
581 static int cs_ha_init(struct m0_motr *cctx)
582 {
584  const char *ep;
585  int rc;
586 
587  M0_ENTRY();
588  if (cctx->cc_ha_addr == NULL && cctx->cc_reqh_ctx.rc_confdb != NULL) {
589  ep = cs_eps_tlist_head(&cctx->cc_reqh_ctx.rc_eps)->ex_endpoint;
590  cctx->cc_ha_addr = m0_strdup(ep);
591  cctx->cc_no_all2all_connections = true;
592  }
593 
594  motr_ha_cfg = (struct m0_motr_ha_cfg){
595  .mhc_dispatcher_cfg = {
596  .hdc_enable_note = true,
597  .hdc_enable_keepalive = true,
598  .hdc_enable_fvec = true,
599  },
600  .mhc_addr = cctx->cc_ha_addr,
601  .mhc_rpc_machine = m0_motr_to_rmach(cctx),
602  .mhc_reqh = &cctx->cc_reqh_ctx.rc_reqh,
603  .mhc_process_fid = cctx->cc_reqh_ctx.rc_fid,
604  };
605  rc = m0_motr_ha_init(&cctx->cc_motr_ha, &motr_ha_cfg);
606  M0_ASSERT(rc == 0);
607  rc = m0_motr_ha_start(&cctx->cc_motr_ha);
608  M0_ASSERT(rc == 0);
609  cctx->cc_ha_is_started = true;
610  return 0;
611 }
612 
613 static bool bad_address(char *addr)
614 {
615  return addr == NULL || *addr == '\0';
616 }
617 
618 static void cs_ha_process_event(struct m0_motr *cctx,
619  enum m0_conf_ha_process_event event)
620 {
622 
623  type = cctx->cc_mkfs ? M0_CONF_HA_PROCESS_M0MKFS :
625  if (cctx->cc_ha_is_started && !cctx->cc_no_conf &&
626  cctx->cc_motr_ha.mh_link != NULL) {
627  m0_conf_ha_process_event_post(&cctx->cc_motr_ha.mh_ha,
628  cctx->cc_motr_ha.mh_link,
629  &cctx->cc_reqh_ctx.rc_fid,
630  m0_process(), event, type);
631  }
632 }
633 
637 static void cs_ha_stop(struct m0_motr *cctx)
638 {
639  M0_ENTRY("client_ctx: %p", cctx);
640  if (!cctx->cc_ha_is_started)
641  return;
643  cctx->cc_ha_is_started = false;
644  if (bad_address(cctx->cc_ha_addr)) {
645  M0_LOG(M0_ERROR, "invalid HA address");
646  goto leave; /* session had no chance to be established */
647  }
648  if (!cctx->cc_no_conf)
649  m0_motr_ha_disconnect(&cctx->cc_motr_ha);
650  m0_motr_ha_stop(&cctx->cc_motr_ha);
651 leave:
652  M0_LEAVE();
653 }
654 
655 static void cs_ha_fini(struct m0_motr *cctx)
656 {
657  M0_ENTRY("client_ctx: %p", cctx);
658  m0_motr_ha_fini(&cctx->cc_motr_ha);
659  M0_LEAVE();
660 }
661 
662 static uint32_t
664 {
665  struct cs_endpoint_and_xprt *ep;
666  uint32_t n = 0;
667 
668  m0_tl_for(cs_eps, &rctx->rc_eps, ep) {
669  if (m0_streq(ep->ex_xprt, dom->nd_xprt->nx_name))
670  ep->ex_tm_colour = n++;
671  } m0_tl_endfor;
672 
673  M0_POST(n > 0);
674  return n;
675 }
676 
678  struct m0_net_domain *dom)
679 {
680  struct cs_endpoint_and_xprt *ep;
681  uint32_t result = 0;
682 
684 
685  m0_tl_for(cs_eps, &rctx->rc_eps, ep) {
686  if (m0_streq(ep->ex_xprt, dom->nd_xprt->nx_name))
687  result += rctx->rc_recv_queue_min_length;
688  } m0_tl_endfor;
689  return result;
690 }
691 
692 static void cs_buffer_pool_fini(struct m0_motr *cctx)
693 {
694  struct cs_buffer_pool *cs_bp;
695 
696  M0_PRE(cctx != NULL);
697 
698  m0_tl_for(cs_buffer_pools, &cctx->cc_buffer_pools, cs_bp) {
699  cs_buffer_pools_tlink_del_fini(cs_bp);
701  m0_free(cs_bp);
702  } m0_tl_endfor;
703 }
704 
705 static int cs_buffer_pool_setup(struct m0_motr *cctx)
706 {
707  struct m0_reqh_context *rctx = &cctx->cc_reqh_ctx;
708  struct m0_net_domain *dom;
709  struct cs_buffer_pool *bp;
710  uint32_t tms_nr;
711  uint32_t max_recv_queue_len;
712  int rc = 0;
713 
714  m0_tl_for(ndom, &cctx->cc_ndoms, dom) {
715  max_recv_queue_len = cs_dom_tm_min_recv_queue_total(rctx, dom);
716  tms_nr = cs_domain_tms_nr(rctx, dom);
717  M0_ASSERT(max_recv_queue_len >= tms_nr);
718 
719  M0_ALLOC_PTR(bp);
720  if (bp == NULL) {
721  rc = -ENOMEM;
722  break;
723  }
725  dom, &bp->cs_buffer_pool,
726  m0_rpc_bufs_nr(max_recv_queue_len, tms_nr),
727  tms_nr);
728  if (rc != 0) {
729  m0_free(bp);
730  break;
731  }
732  cs_buffer_pools_tlink_init_at_tail(bp, &cctx->cc_buffer_pools);
733  } m0_tl_endfor;
734 
735  if (rc != 0)
737  return M0_RC(rc);
738 }
739 
740 static int stob_file_id_get(yaml_document_t *doc, yaml_node_t *node,
741  uint64_t *id)
742 {
743  char *endptr;
744  const char *key_str;
745  yaml_node_pair_t *pair;
746 
747  for (pair = node->data.mapping.pairs.start;
748  pair < node->data.mapping.pairs.top; ++pair) {
749  key_str = (const char *)yaml_document_get_node(doc,
750  pair->key)->data.scalar.value;
751  if (m0_strcaseeq(key_str, "id")) {
752  *id = strtoll((const char *)yaml_document_get_node(doc,
753  pair->value)->data.scalar.value, &endptr,
754  10);
755  return *endptr == '\0' ? M0_RC(0) : M0_ERR(-EINVAL);
756  }
757  }
758  return M0_RC(-ENOENT);
759 }
760 
761 static const char *stob_file_path_get(yaml_document_t *doc, yaml_node_t *node)
762 {
763  const char *key_str;
764  yaml_node_pair_t *pair;
765 
766  for (pair = node->data.mapping.pairs.start;
767  pair < node->data.mapping.pairs.top; ++pair) {
768  key_str = (const char *)yaml_document_get_node(doc,
769  pair->key)->data.scalar.value;
770  if (m0_strcaseeq(key_str, "filename"))
771  return (const char *)yaml_document_get_node(doc,
772  pair->value)->data.scalar.value;
773  }
774 
775  return NULL;
776 }
777 
778 static int cs_stob_file_load(const char *dfile, struct cs_stobs *stob)
779 {
780  FILE *f;
781  yaml_parser_t parser;
782  yaml_document_t *document;
783  int rc = -EINVAL;
784 
785  f = fopen(dfile, "r");
786  if (f == NULL)
787  return M0_ERR(-EINVAL);
788 
789  document = &stob->s_sfile.sf_document;
790  rc = yaml_parser_initialize(&parser);
791  if (rc != 1)
792  goto end;
793 
794  yaml_parser_set_input_file(&parser, f);
795  rc = yaml_parser_load(&parser, document);
796  if (rc != 1)
797  goto end;
798 
799  stob->s_sfile.sf_is_initialised = true;
800  yaml_parser_delete(&parser);
801  rc = 0;
802 end:
803  fclose(f);
804  return M0_RC(rc);
805 }
806 
807 static void cs_storage_devs_fini(void)
808 {
809  struct m0_storage_devs *devs = &m0_get()->i_storage_devs;
810 
811  m0_storage_devs_lock(devs);
814  m0_storage_devs_fini(devs);
815 }
816 
820 static int cs_storage_devs_init(struct cs_stobs *stob,
822  struct m0_be_seg *seg,
823  const char *stob_path,
824  bool force,
825  bool disable_direct_io)
826 {
827  int rc;
828  int result;
829  uint64_t cid;
830  uint64_t stob_file_id;
831  const char *f_path;
832  struct m0_storage_devs *devs = &m0_get()->i_storage_devs;
833  struct m0_storage_dev *dev;
834  yaml_document_t *doc;
835  yaml_node_t *node;
836  yaml_node_t *s_node;
837  yaml_node_item_t *item;
838  m0_bcount_t size = 0; /* Uses BALLOC_DEF_CONTAINER_SIZE; */
839 
840  struct m0_motr *cctx;
841  struct m0_reqh_context *rctx;
842  struct m0_confc *confc;
843  struct m0_reqh *reqh;
844  struct m0_fid sdev_fid;
845  struct m0_conf_sdev *conf_sdev;
846 
847  M0_ENTRY();
848  M0_PRE(ergo(type == M0_STORAGE_DEV_TYPE_AD, stob->s_sdom != NULL));
849 
850  rctx = container_of(stob, struct m0_reqh_context, rc_stob);
851  reqh = &rctx->rc_reqh;
852  cctx = container_of(rctx, struct m0_motr, cc_reqh_ctx);
854  rc = m0_storage_devs_init(devs, type, seg, stob->s_sdom, reqh);
855  if (rc != 0)
856  return M0_ERR(rc);
857  m0_storage_devs_use_directio(devs, !disable_direct_io);
858 
859  if (stob->s_sfile.sf_is_initialised) {
860  M0_LOG(M0_DEBUG, "yaml config");
861  doc = &stob->s_sfile.sf_document;
862  for (node = doc->nodes.start; node < doc->nodes.top; ++node) {
863  for (item = (node)->data.sequence.items.start;
864  item < (node)->data.sequence.items.top; ++item) {
865  s_node = yaml_document_get_node(doc, *item);
866  result = stob_file_id_get(doc, s_node,
867  &stob_file_id);
868  if (result != 0)
869  continue;
870  M0_ASSERT(stob_file_id > 0);
871  cid = stob_file_id - 1;
872  f_path = stob_file_path_get(doc, s_node);
874  &sdev_fid);
875  if (rc == 0) {
876  rc = m0_conf_sdev_get(confc, &sdev_fid,
877  &conf_sdev);
878  if (rc != 0) {
880  "Cannot open sdev "FID_F,
881  FID_P(&sdev_fid));
882  break;
883  }
884  M0_LOG(M0_DEBUG, "cid:0x%"PRIx64
885  " -> sdev_fid:"FID_F" idx:0x%x",
886  cid, FID_P(&sdev_fid),
887  conf_sdev->sd_dev_idx);
888  } else
889  /* Every storage device need not have a
890  * counterpart in configuration. */
891  conf_sdev = NULL;
892  if (M0_FI_ENABLED("spare_reserve"))
893  /*
894  * We intend to fill disks faster, hence
895  * sizes reduced to 256 MB.
896  */
897  size = 1024ULL *1024 * 256;
898  rc = m0_storage_dev_new(devs, cid, f_path, size,
899  conf_sdev, force, &dev);
900  if (rc == 0) {
901  /*
902  * There is no concurrent access to the
903  * devs on this stage. But we lock the
904  * structure to meet the precondition
905  * of m0_storage_dev_attach().
906  */
907  m0_storage_devs_lock(devs);
908  m0_storage_dev_attach(dev, devs);
910  }
911  if (conf_sdev != NULL)
912  m0_confc_close(&conf_sdev->sd_obj);
913  if (rc != 0) {
914  M0_LOG(M0_ERROR, "Storage device failed"
915  " cid=%"PRIu64, cid);
916  break;
917  }
918  }
919  }
920  } else if (stob->s_ad_disks_init || M0_FI_ENABLED("init_via_conf")) {
921  M0_LOG(M0_DEBUG, "conf config");
922  rc = cs_conf_storage_init(stob, devs, force);
923  } else {
924  /*
925  * This is special case for tests. We don't have configured
926  * storages. Therefore, create a default one.
927  * Unit tests with m0_rpc_server_start() and sss/st don't
928  * configure storages properly via conf.xc or YAML file and
929  * rely on these storages with specific IDs. Such tests should
930  * provide valid conf.xc or YAML file instead of using default
931  * storages with hardcoded IDs.
932  */
933  M0_LOG(M0_DEBUG, "creating default storage");
935  rc = m0_storage_dev_new(devs,
937  NULL, size, NULL, force, &dev);
938  else
940  stob_path, size, NULL,
941  force, &dev);
942  if (rc == 0) {
943  /* see m0_storage_dev_attach() above */
944  m0_storage_devs_lock(devs);
945  m0_storage_dev_attach(dev, devs);
947  }
948  }
949  if (rc != 0)
951  return M0_RC(rc);
952 }
953 
955 static char *cs_storage_ldom_location_gen(const char *stob_path)
956 {
957  char *location;
958  static const char prefix[] = "linuxstob:";
959 
960  M0_ALLOC_ARR(location, strlen(stob_path) + ARRAY_SIZE(prefix));
961  if (location != NULL)
962  sprintf(location, "%s%s", prefix, stob_path);
963 
964  return location;
965 }
966 
971 static int cs_storage_ldom_destroy(const char *stob_path,
972  const char *str_cfg_init)
973 {
974  struct m0_stob_domain *dom;
975  char *location;
976  int rc;
977 
978  M0_ENTRY();
979  M0_PRE(stob_path != NULL);
980 
982  if (location == NULL)
983  return M0_ERR(-ENOMEM);
984 
985  rc = m0_stob_domain_init(location, str_cfg_init, &dom);
986  if (rc == 0)
988  else
990  /* Don't fail if domain doesn't exist. */
991  if (rc == -ENOENT)
992  rc = 0;
993  m0_free(location);
994  return M0_RC(rc);
995 }
996 
997 static int cs_storage_bstore_prepare(const char *stob_path,
998  const char *str_cfg_init,
999  uint64_t dom_key,
1000  bool mkfs,
1001  struct m0_stob_domain **out)
1002 {
1003  int rc;
1004  int rc1 = 0;
1005  char *location;
1006 
1007  M0_ENTRY();
1008  M0_PRE(stob_path != NULL);
1009 
1011  if (location == NULL)
1012  return M0_ERR(-ENOMEM);
1013 
1014  rc = m0_stob_domain_init(location, str_cfg_init, out);
1015  if (mkfs) {
1016  /* Found existing stob domain, kill it. */
1017  if (!M0_IN(rc, (0, -ENOENT))) {
1018  rc1 = rc == 0 ? m0_stob_domain_destroy(*out) :
1020  (location);
1021  if (rc1 != 0)
1022  goto out;
1023  }
1024  if (rc != 0) {
1025  rc = m0_stob_domain_create(location, str_cfg_init,
1026  dom_key, NULL, out);
1027  if (rc != 0)
1028  M0_LOG(M0_ERROR,
1029  "m0_stob_domain_create: rc=%d", rc);
1030  } else {
1031  M0_LOG(M0_INFO, "Found alive filesystem, do nothing.");
1032  }
1033  } else if (rc != 0)
1034  M0_LOG(M0_ERROR, "Cannot init stob domain rc=%d", rc);
1035 out:
1036  m0_free(location);
1037  return M0_RC(rc1 == 0 ? rc : rc1);
1038 }
1039 
1047 static int cs_storage_init(const char *stob_type,
1048  const char *stob_path,
1049  uint64_t dom_key,
1050  struct cs_stobs *stob,
1051  struct m0_be_seg *seg,
1052  bool mkfs, bool force,
1053  bool disable_direct_io)
1054 {
1055  const char *ldom_cfg_init;
1056  bool linux_stob;
1057  bool fake_storage;
1058  int rc = 0;
1059 
1060  M0_ENTRY();
1061  M0_PRE(stob_type != NULL);
1062  M0_PRE(stob != NULL);
1063  M0_PRE(stob->s_sdom == NULL);
1065 
1066  /* XXX `-F` (force) doesn't work for linuxstob storage devices. */
1067 
1068  ldom_cfg_init = disable_direct_io ? "directio=false" : "directio=true";
1069 
1071  m0_get()->i_reqh_uses_ad_stob = !linux_stob;
1072  m0_get()->i_storage_is_fake = fake_storage =
1073  linux_stob && stob_path != NULL && !stob->s_ad_disks_init &&
1074  !stob->s_sfile.sf_is_initialised;
1075 
1076 
1077  if (mkfs && force && (fake_storage || !linux_stob))
1078  rc = cs_storage_ldom_destroy(stob_path, NULL);
1079  if (linux_stob) {
1081  NULL, stob_path, force,
1082  disable_direct_io);
1083  } else {
1084  rc = rc ?: cs_storage_bstore_prepare(stob_path, ldom_cfg_init,
1085  dom_key, mkfs,
1086  &stob->s_sdom);
1087  if (rc != 0)
1088  stob->s_sdom = NULL;
1090  seg, stob_path, false,
1091  disable_direct_io);
1092  }
1093  if (rc != 0 && stob->s_sdom != NULL)
1094  m0_stob_domain_fini(stob->s_sdom);
1095 
1096  return M0_RC(rc);
1097 }
1098 
1102 static void cs_storage_fini(struct cs_stobs *stob)
1103 {
1105  if (stob->s_sdom != NULL)
1106  m0_stob_domain_fini(stob->s_sdom);
1107  if (stob->s_sfile.sf_is_initialised)
1108  yaml_document_delete(&stob->s_sfile.sf_document);
1109 }
1110 
1117 M0_INTERNAL int cs_service_init(const char *name, struct m0_reqh_context *rctx,
1118  struct m0_reqh *reqh, struct m0_fid *fid)
1119 {
1120  struct m0_reqh_service_type *stype;
1121  struct m0_reqh_service *service;
1122  int rc = 0;
1123 
1124  M0_ENTRY("name=`%s'", name);
1125  M0_PRE(name != NULL && *name != '\0' && reqh != NULL);
1126 
1128  if (stype == NULL) {
1129  M0_LOG(M0_ERROR, "Service name %s is not found.", name);
1130  return M0_ERR_INFO(-EINVAL, "Unknown reqh service type: %s",
1131  name);
1132  }
1133 
1135  if (service == NULL) {
1138  } else {
1139  M0_LOG(M0_WARN, "Service %s ("FID_F") is already registered "
1140  "for reqh %p", name, FID_P(fid), reqh);
1141  }
1142  return M0_RC(rc);
1143 }
1144 
1146  struct m0_motr *cctx)
1147 {
1148  uint32_t i;
1149  int rc = 0;
1150 
1151  M0_ENTRY();
1153 
1154  for (i = 0; i < M0_CST_NR && rc == 0; ++i) {
1155  if (rctx->rc_services[i] == NULL ||
1156  M0_IN(i, (M0_CST_HA, M0_CST_SSS)))
1157  continue;
1158  if (i == M0_CST_FIS) {
1159  if (!rctx->rc_fis_enabled)
1160  /*
1161  * Even in case FIS is present in conf, the
1162  * service must stay down being not enabled by
1163  * command line parameter '-j'.
1164  */
1165  continue;
1166  else
1167  M0_LOG(M0_DEBUG, "FIS enabled by command opt.");
1168  }
1170  &rctx->rc_service_fids[i]);
1171  M0_LOG(M0_DEBUG, "service: %s" FID_F " cs_service_init: %d",
1173  rc);
1174  }
1175  return M0_RC(rc);
1176 }
1177 
1178 M0_INTERNAL void cs_service_fini(struct m0_reqh_service *service)
1179 {
1180  struct m0_reqh *reqh = service->rs_reqh;
1181  /*
1182  * XXX: The following lines are going to be refactored. Currently it's
1183  * not so easy to extract proper interface from reqh/reqh.c.
1184  */
1191  }
1192  M0_LOG(M0_DEBUG, "service=%s", service->rs_type->rst_name);
1194 }
1195 
1197  struct m0_motr *cctx)
1198 {
1199  struct m0_reqh_service *service;
1200  const char *name;
1201  uint32_t i;
1202  int rc = 0;
1203 
1204  M0_ENTRY();
1205 
1206  for (i = 0; i < M0_CST_NR && rc == 0; ++i) {
1207  if (rctx->rc_services[i] == NULL ||
1208  M0_IN(i, (M0_CST_HA, M0_CST_SSS)))
1209  continue;
1210  name = rctx->rc_services[i];
1211  M0_LOG(M0_DEBUG, "service: %s" FID_F, name,
1212  FID_P(&rctx->rc_service_fids[i]));
1214  &rctx->rc_service_fids[i]);
1215  if (service != NULL)
1217  }
1218 
1219  M0_LEAVE();
1220 }
1221 
1223  struct m0_motr *cctx)
1224 {
1225  struct m0_reqh *reqh = &rctx->rc_reqh;
1226  struct m0_reqh_service *ss_service;
1227  int rc;
1228 
1229  M0_ENTRY();
1230 
1234  rc = m0_reqh_service_setup(&ss_service, &m0_ss_svc_type,
1235  reqh, NULL, NULL) ?:
1236  cs_service_init("simple-fom-service", NULL, reqh, NULL) ?:
1237  cs_service_init("M0_CST_FDMI", NULL, reqh, NULL) ?:
1239 
1240  if (rc == 0)
1242 
1243  return M0_RC(rc);
1244 }
1245 
1246 static int
1248 {
1249  struct m0_net_xprt *xprt;
1250  struct m0_net_domain *ndom = NULL;
1251  int rc;
1252 
1253  M0_PRE(cs_endpoint_and_xprt_bob_check(ep));
1254 
1255  xprt = cs_xprt_lookup(ep->ex_xprt, cctx->cc_xprts, cctx->cc_xprts_nr);
1256  if (xprt == NULL)
1257  return M0_ERR(-EINVAL);
1258 
1259  ndom = m0_cs_net_domain_locate(cctx, ep->ex_xprt);
1260  if (ndom != NULL)
1261  return 0; /* pass */
1262 
1263  M0_ALLOC_PTR(ndom);
1264  if (ndom == NULL) {
1265  rc = -ENOMEM;
1266  goto err;
1267  }
1268 
1269  rc = m0_net_domain_init(ndom, xprt);
1270  if (rc != 0)
1271  goto err;
1272 
1273  m0_net_domain_bob_init(ndom);
1274  ndom_tlink_init_at_tail(ndom, &cctx->cc_ndoms);
1275  return 0;
1276 err:
1277  m0_free(ndom); /* freeing NULL does not hurt */
1278  return M0_RC(rc);
1279 }
1280 
1285 static int cs_net_domains_init(struct m0_motr *cctx)
1286 {
1287  struct m0_reqh_context *rctx = &cctx->cc_reqh_ctx;
1288  struct cs_endpoint_and_xprt *ep;
1289 
1290  M0_ENTRY();
1292 
1293  m0_tl_for(cs_eps, &rctx->rc_eps, ep) {
1294  int rc = cs_net_domain_init(ep, cctx);
1295  if (rc != 0)
1296  return M0_RC(rc);
1297  } m0_tl_endfor;
1298  return M0_RC(0);
1299 }
1300 
1306 static void cs_net_domains_fini(struct m0_motr *cctx)
1307 {
1308  struct m0_net_domain *ndom;
1309 
1310  m0_tl_for(ndom, &cctx->cc_ndoms, ndom) {
1311  M0_ASSERT(m0_net_domain_bob_check(ndom));
1312  m0_net_domain_fini(ndom);
1313  ndom_tlink_del_fini(ndom);
1314  m0_net_domain_bob_fini(ndom);
1315  m0_free(ndom);
1316  } m0_tl_endfor;
1317 }
1318 
1319 static int cs_storage_prepare(struct m0_reqh_context *rctx, bool erase)
1320 {
1321  struct m0_sm_group *grp = m0_locality0_get()->lo_grp;
1322  struct m0_be_domain *bedom = rctx->rc_beseg->bs_domain;
1323  struct m0_cob_domain *dom;
1324  struct m0_dtx tx = {};
1325  int rc = 0;
1326  int rc2;
1327 
1329 
1330  if (erase)
1331  rc = m0_mdstore_destroy(&rctx->rc_mdstore, grp, bedom);
1332 
1334  bedom, rctx->rc_beseg)
1335  ?: m0_dtm0_log_create(grp, bedom, rctx->rc_beseg);
1336  if (rc != 0)
1337  goto end;
1339 
1340  m0_dtx_init(&tx, bedom, grp);
1342 
1343  rc = m0_dtx_open_sync(&tx);
1344  if (rc == 0) {
1346  m0_dtx_done_sync(&tx);
1347  }
1348  m0_dtx_fini(&tx);
1349 
1350  if (rc != 0) {
1351  /* Note, m0_mdstore_destroy() creates exclusive tx. */
1352  rc2 = m0_mdstore_destroy(&rctx->rc_mdstore, grp, bedom);
1353  if (rc2 != 0)
1354  M0_LOG(M0_ERROR, "Ignoring rc2=%d from "
1355  "m0_mdstore_destroy()", rc2);
1356  }
1357 end:
1359  return M0_RC(rc);
1360 }
1361 
1362 static void be_seg_init(struct m0_be_ut_backend *be,
1363  m0_bcount_t size,
1364  bool preallocate,
1365  bool format,
1366  const char *stob_create_cfg,
1367  struct m0_be_seg **out)
1368 {
1369  struct m0_be_seg *seg;
1370 
1372  if (seg != NULL && format) {
1374  seg = NULL;
1375  }
1376  if (seg == NULL) {
1377  if (size == 0)
1379  m0_be_ut_backend_seg_add2(be, size, preallocate,
1380  stob_create_cfg, &seg);
1381  }
1382  *out = seg;
1383 }
1384 
1385 static bool pver_is_actual(const struct m0_conf_obj *obj)
1386 {
1391  return m0_conf_obj_type(obj) == &M0_CONF_PVER_TYPE &&
1393 }
1394 
1399  uint32_t *repair_zone_pcnt)
1400 {
1401  struct m0_confc *confc;
1402  struct m0_conf_root *croot = NULL;
1403  struct m0_conf_diter it;
1404  struct m0_conf_pver *pver_obj;
1405  int rc;
1406 
1407  *repair_zone_pcnt = 0;
1409  M0_LOG(M0_DEBUG, "m0_confc_root_open: rc=%d", rc);
1410  if (rc == 0) {
1411  confc = m0_confc_from_obj(&croot->rt_obj);
1412  rc = m0_conf_diter_init(&it, confc, &croot->rt_obj,
1413  M0_CONF_ROOT_POOLS_FID,
1414  M0_CONF_POOL_PVERS_FID);
1415  M0_LOG(M0_DEBUG, "m0_conf_diter_init rc %d", rc);
1416  }
1417  while (rc == 0 &&
1419  M0_CONF_DIRNEXT) {
1420  pver_obj = M0_CONF_CAST(m0_conf_diter_result(&it),
1421  m0_conf_pver);
1422  if (!m0_fid_eq(&pver_obj->pv_obj.co_id,
1423  &croot->rt_imeta_pver)) {
1424  continue;
1425  }
1426 
1427  *repair_zone_pcnt = pver_obj->pv_u.subtree.pvs_attr.pa_S *
1428  100 /
1429  pver_obj->pv_u.subtree.pvs_attr.pa_P *
1432 
1433  M0_LOG(M0_DEBUG, "pver_obj %p N %d K %d S %d P %d percent %d",
1434  pver_obj,
1435  pver_obj->pv_u.subtree.pvs_attr.pa_N,
1436  pver_obj->pv_u.subtree.pvs_attr.pa_K,
1437  pver_obj->pv_u.subtree.pvs_attr.pa_S,
1438  pver_obj->pv_u.subtree.pvs_attr.pa_P,
1439  *repair_zone_pcnt);
1440 
1441  M0_ASSERT(*repair_zone_pcnt <= M0_BC_REPAIR_ZONE_MAX_ALLOWED);
1442  }
1443  if (rc == 0)
1445  if (croot != NULL)
1446  m0_confc_close(&croot->rt_obj);
1447  M0_LOG(M0_DEBUG, "spare percent %d", *repair_zone_pcnt);
1448  return rc;
1449 }
1450 
1452  struct m0_be_domain_cfg *dom_cfg)
1453 {
1454  uint32_t *zone_pcnt = dom_cfg->bc_zone_pcnt;
1455  uint32_t repair_zone_pcnt;
1456  int rc;
1457 
1458  rc = be_repair_zone_pcnt_get(reqh, &repair_zone_pcnt);
1459 
1460  if (rc == 0) {
1461  zone_pcnt[M0_BAP_REPAIR] = repair_zone_pcnt;
1462  zone_pcnt[M0_BAP_NORMAL] = 100 - zone_pcnt[M0_BAP_REPAIR];
1463  }
1464 
1465  return rc;
1466 }
1467 
1468 static int cs_be_init(struct m0_reqh_context *rctx,
1469  struct m0_be_ut_backend *be,
1470  const char *name,
1471  bool preallocate,
1472  bool format,
1473  struct m0_be_seg **out)
1474 {
1475  enum { len = 1024 };
1476  char **loc = &be->but_stob_domain_location;
1477  int rc;
1478 
1479  *loc = m0_alloc(len);
1480  if (*loc == NULL)
1481  return M0_ERR(-ENOMEM);
1482  snprintf(*loc, len, "linuxstob:%s%s", name[0] == '/' ? "" : "./", name);
1483 
1489  if (!m0_is_po2(rctx->rc_be_log_size))
1490  return M0_ERR(-EINVAL);
1491  if (rctx->rc_be_log_size > 0) {
1494  }
1495  if (rctx->rc_be_tx_group_tx_nr_max > 0) {
1498  }
1499  if (rctx->rc_be_tx_group_tx_nr_max > 0) {
1502  }
1505  return M0_ERR(-EINVAL);
1506  if (rctx->rc_be_tx_group_reg_nr_max > 0 &&
1511  }
1515  }
1516  if (rctx->rc_be_tx_reg_nr_max > 0 &&
1517  rctx->rc_be_tx_reg_size_max > 0) {
1521  }
1522  if (rctx->rc_be_tx_payload_size_max > 0) {
1525  }
1532  }
1534  if (rc != 0)
1535  goto err;
1537  if (rc != 0)
1538  goto err;
1539 
1540  be_seg_init(be, rctx->rc_be_seg_size, preallocate, format,
1541  rctx->rc_be_seg_path, out);
1542  if (*out != NULL)
1543  return 0;
1544  M0_LOG(M0_ERROR, "cs_be_init: failed to init segment");
1545  rc = M0_ERR(-ENOMEM);
1546 err:
1547  m0_free0(loc);
1548  return M0_ERR(rc);
1549 }
1550 
1551 M0_INTERNAL void cs_be_fini(struct m0_be_ut_backend *be)
1552 {
1555 }
1556 
1568 {
1569  int rc;
1570 
1571  M0_ENTRY();
1573 
1575  .rhia_mdstore = &rctx->rc_mdstore,
1576  .rhia_pc = &rctx->rc_motr->cc_pools_common,
1577  .rhia_fid = &rctx->rc_fid);
1579  return M0_RC(rc);
1580 }
1581 
1582 static int cs_storage_setup(struct m0_motr *cctx)
1583 {
1588  static int cdom_id = M0_MDS_COB_ID_START;
1589  struct m0_reqh_context *rctx = &cctx->cc_reqh_ctx;
1590  bool mkfs = cctx->cc_mkfs;
1591  bool force = cctx->cc_force;
1592  int rc;
1593 
1594  M0_ENTRY();
1596 
1597  if (cctx->cc_no_storage)
1598  return M0_RC(0);
1599 
1601 
1604  (mkfs && force), &rctx->rc_beseg);
1605  if (rc != 0)
1606  return M0_ERR_INFO(rc, "cs_be_init");
1607 
1609  if (rc != 0) {
1610  M0_LOG(M0_ERROR, "m0_reqh_be_init: rc=%d", rc);
1611  goto be_fini;
1612  }
1613 
1616  if (rc != 0) {
1617  M0_LOG(M0_ERROR,
1618  "Failed to load device configuration file");
1619  goto reqh_be_fini;
1620  }
1621  }
1622 
1625  &rctx->rc_stob, rctx->rc_beseg,
1626  mkfs, force, rctx->rc_disable_direct_io);
1627  if (rc != 0) {
1628  M0_LOG(M0_ERROR, "cs_storage_init: rc=%d", rc);
1629  /* XXX who should call yaml_document_delete()? */
1630  goto reqh_be_fini;
1631  }
1632 
1634  M0_ADDB2_STOB_DOM_KEY, true, force,
1636  if (rc != 0)
1637  goto cleanup_stob;
1638 
1639  rctx->rc_cdom_id.id = ++cdom_id;
1640 
1641  /*
1642  This MUST be initialized before m0_mdstore_init() is called.
1643  Otherwise it returns -ENOENT, which is used for detecting if
1644  fs is alive and should be preserved.
1645  */
1646  rctx->rc_mdstore.md_dom = m0_reqh_lockers_get(&rctx->rc_reqh,
1647  m0_get()->i_mds_cdom_key);
1648 
1649  if (mkfs) {
1650  /*
1651  * Init mdstore without root cob first. Now we can use it
1652  * for mkfs.
1653  */
1655  if (rc != 0 && rc != -ENOENT) {
1656  M0_LOG(M0_ERROR, "m0_mdstore_init: rc=%d", rc);
1657  goto cleanup_addb2;
1658  }
1659 
1660  /* Prepare new metadata structure, erase old one if exists. */
1661  if ((rc == 0 && force) || rc == -ENOENT)
1662  rc = cs_storage_prepare(rctx, (rc == 0 && force));
1664  if (rc != 0) {
1665  M0_LOG(M0_ERROR, "cs_storage_prepare: rc=%d", rc);
1666  goto cleanup_addb2;
1667  }
1668  }
1669 
1671  /* Init mdstore and root cob as it should be created by mkfs. */
1673  if (rc != 0) {
1674  M0_LOG(M0_ERROR, "Failed to initialize mdstore. %s",
1675  !mkfs ? "Did you run mkfs?" : "Mkfs failed?");
1676  goto cleanup_addb2;
1677  }
1678 
1680  return M0_RC(rc);
1681 
1682 cleanup_addb2:
1684 cleanup_stob:
1686 reqh_be_fini:
1688 be_fini:
1689  cs_be_fini(&rctx->rc_be);
1690  return M0_ERR(rc);
1691 }
1692 
1693 static int cs_dtm0_init(struct m0_reqh_context *rctx)
1694 {
1696 }
1697 
1698 static void cs_dtm0_fini(struct m0_reqh_context *rctx)
1699 {
1701 }
1702 
1704 {
1705  struct m0_reqh *reqh = &rctx->rc_reqh;
1706 
1707  M0_ENTRY();
1709 
1711  /*
1712  * In case incomplete contexts exist, those need to be offlined
1713  * early to unblock fom domains and let reqh shut down smooth.
1714  */
1715  if (!rctx->rc_motr->cc_no_conf)
1718  }
1719 
1720  M0_LEAVE();
1721 }
1722 
1734 static void cs_reqh_stop(struct m0_reqh_context *rctx)
1735 {
1736  struct m0_reqh *reqh = &rctx->rc_reqh;
1737 
1738  M0_ENTRY();
1740 
1743 
1745  M0_LEAVE();
1746 }
1747 
1749 {
1750  struct m0_reqh *reqh = &rctx->rc_reqh;
1751 
1755  cs_be_fini(&rctx->rc_be);
1757  m0_reqh_fini(reqh);
1759  M0_LEAVE();
1760 }
1761 
1763 {
1764  struct m0_reqh_context *rctx = &cctx->cc_reqh_ctx;
1765 
1766  m0_rwlock_read_lock(&cctx->cc_rwlock);
1768  m0_rwlock_read_unlock(&cctx->cc_rwlock);
1769 
1770  return &rctx->rc_reqh;
1771 }
1772 
1773 M0_INTERNAL struct m0_reqh_context *m0_cs_reqh_context(struct m0_reqh *reqh)
1774 {
1775  return bob_of(reqh, struct m0_reqh_context, rc_reqh, &rhctx_bob);
1776 }
1777 
1778 M0_INTERNAL struct m0_motr *m0_cs_ctx_get(struct m0_reqh *reqh)
1779 {
1780  return m0_cs_reqh_context(reqh)->rc_motr;
1781 }
1782 
1783 M0_INTERNAL struct m0_storage_devs *m0_cs_storage_devs_get(void)
1784 {
1785  return &m0_get()->i_storage_devs;
1786 }
1787 
1788 static void cs_motr_init(struct m0_motr *cctx)
1789 {
1790  ndom_tlist_init(&cctx->cc_ndoms);
1791  m0_bob_type_tlist_init(&ndom_bob, &ndom_tl);
1792  cs_buffer_pools_tlist_init(&cctx->cc_buffer_pools);
1793 
1794  m0_bob_type_tlist_init(&cs_eps_bob, &cs_eps_tl);
1795 
1796  m0_rwlock_init(&cctx->cc_rwlock);
1797 
1798  cs_eps_tlist_init(&cctx->cc_ios_eps);
1799  cs_eps_tlist_init(&cctx->cc_mds_eps);
1800  M0_SET0(&cctx->cc_stats_svc_epx);
1801  cctx->cc_args.ca_argc = 0;
1802  cctx->cc_args.ca_argc_max = 0;
1803  cctx->cc_args.ca_argv = NULL;
1804  cctx->cc_ha_addr = NULL;
1805 }
1806 
1807 static void cs_motr_fini(struct m0_motr *cctx)
1808 {
1809  struct cs_endpoint_and_xprt *ep;
1810 
1811  m0_free(cctx->cc_ha_addr);
1812 
1813  m0_tl_teardown(cs_eps, &cctx->cc_ios_eps, ep) {
1815  m0_free(ep);
1816  };
1817  cs_eps_tlist_fini(&cctx->cc_ios_eps);
1818 
1819  m0_tl_teardown(cs_eps, &cctx->cc_mds_eps, ep) {
1821  m0_free(ep);
1822  };
1823  cs_eps_tlist_fini(&cctx->cc_mds_eps);
1824 
1825  if (cctx->cc_stats_svc_epx.ex_endpoint != NULL)
1826  m0_ep_and_xprt_fini(&cctx->cc_stats_svc_epx);
1827  cs_buffer_pools_tlist_fini(&cctx->cc_buffer_pools);
1828  ndom_tlist_fini(&cctx->cc_ndoms);
1829  m0_rwlock_fini(&cctx->cc_rwlock);
1830  if (cctx->cc_enable_finj)
1831  m0_fi_fini();
1832  while (cctx->cc_args.ca_argc > 0)
1833  m0_free(cctx->cc_args.ca_argv[--cctx->cc_args.ca_argc]);
1834  m0_free(cctx->cc_args.ca_argv);
1835 }
1836 
1837 static void cs_usage(FILE *out, const char *progname)
1838 {
1839  M0_PRE(out != NULL);
1840  M0_PRE(progname != NULL);
1841 
1842  fprintf(out,
1843 "Usage: %s [-h] [-x] [-l]\n"
1844 " or %s <global options> <reqh>+\n"
1845 "\n"
1846 "Type `%s -h' for help.\n", progname, progname, progname);
1847 }
1848 
1849 static void cs_help(FILE *out, const char *progname)
1850 {
1851  M0_PRE(out != NULL);
1852 
1853  cs_usage(out, progname);
1854  fprintf(out, "\n"
1855 "Queries:\n"
1856 " -h Display this help.\n"
1857 " -v Show version information and exit.\n"
1858 " -x List supported network transports.\n"
1859 " -l List supported services.\n"
1860 "\n"
1861 "Global options:\n"
1862 " -F Force mkfs to override found filesystem.\n"
1863 " -Q num Minimum length of TM receive queue.\n"
1864 " -M num Maximum RPC message size.\n"
1865 " -H addr Endpoint address of HA service.\n"
1866 " -G addr Endpoint address of MD service.\n"
1867 " -R addr Endpoint address of stats service.\n"
1868 " -i addr Add new entry to the list of IOS endpoint addresses.\n"
1869 " -w num Pool width.\n"
1870 " -Z Run as daemon.\n"
1871 " -E num Number of net buffers used by IOS.\n"
1872 " -J num Number of net buffers used by SNS.\n"
1873 " -o str Enable fault injection point with given name.\n"
1874 " -g Disable ADDB storage.\n"
1875 "\n"
1876 "Request handler options:\n"
1877 " -D str BE stob domain file path (used by UT only).\n"
1878 " -L str BE log file path.\n"
1879 " -b str BE seg0 file path.\n"
1880 " -B str BE primary segment file path.\n"
1881 " -z num BE primary segment size in bytes (used by m0mkfs only).\n"
1882 " -V num BE log size.\n"
1883 " -n num BE tx group tx nr max.\n"
1884 " -k num BE tx group reg nr max.\n"
1885 " -K num BE tx group reg size max.\n"
1886 " -p num BE tx group payload size max.\n"
1887 " -C num BE tx reg nr max.\n"
1888 " -N num BE tx reg size max.\n"
1889 " -s num BE tx payload size max.\n"
1890 " -y num BE tx group freeze timeout min, ms.\n"
1891 " -Y num BE tx group freeze timeout max, ms.\n"
1892 " -a Preallocate BE segment.\n"
1893 " -c str [optional] Path to the configuration database."
1894 " Mandatory for confd service.\n"
1895 " -T str Type of storage. Supported types: linux, ad.\n"
1896 " -S str Stob file path.\n"
1897 " -A str ADDB stob file path.\n"
1898 " -d str [optional] Path to device configuration file.\n"
1899 " Device configuration file should contain device id and the\n"
1900 " corresponding device path.\n"
1901 " if -U option is specified, disks.conf file is not used.\n"
1902 " E.g. id: 0,\n"
1903 " filename: /dev/sda\n"
1904 " Note that only AD type stob domain can be configured over device.\n"
1905 " -U Use confc API instead of `-d` to obtain device configuration.\n"
1906 " -q num [optional] Minimum length of TM receive queue.\n"
1907 " Defaults to the value set with '-Q' option.\n"
1908 " -m num [optional] Maximum RPC message size.\n"
1909 " Defaults to the value set with '-M' option.\n"
1910 " -e addr Network layer endpoint of a service.\n"
1911 " Format: <transport>:<address>.\n"
1912 " Currently supported transport is lnet.\n"
1913 " .\n"
1914 " lnet takes 4-tuple endpoint address in the form\n"
1915 " NID : PID : PortalNumber : TransferMachineIdentifier\n"
1916 " e.g. lnet:172.18.50.40@o2ib1:12345:34:1\n"
1917 " .\n"
1918 " If multiple '-e' options are provided, network transport\n"
1919 " will have several endpoints, distinguished by transfer machine id\n"
1920 " (the 4th component of 4-tuple endpoint address in lnet).\n"
1921 " -f fid Process fid (mandatory for m0d).\n"
1922 " -I Disable direct I/O for data.\n"
1923 " -j Enable fault injection service (FIS).\n"
1924 "\n"
1925 "Example:\n"
1926 " %s -Q 4 -M 4096 -T linux -D bepath -S stobfile \\\n"
1927 " -e lnet:172.18.50.40@o2ib1:12345:34:1 \\\n"
1928 " -q 8 -m 65536 \\\n"
1929 " -f '<0x7200000000000001:1>'\n",
1930  progname);
1931 }
1932 
1933 static int cs_reqh_ctx_validate(struct m0_motr *cctx)
1934 {
1935  struct m0_reqh_context *rctx = &cctx->cc_reqh_ctx;
1936  struct cs_endpoint_and_xprt *ep;
1937  M0_ENTRY();
1938 
1939  if (!cctx->cc_no_storage) {
1940  if (rctx->rc_stype == NULL)
1941  return M0_ERR_INFO(-EINVAL, "rc_stype is not set");
1942  if (rctx->rc_stpath == NULL)
1943  return M0_ERR_INFO(-EINVAL, "rc_stpath is not set");
1944  if (rctx->rc_bepath == NULL)
1945  return M0_ERR_INFO(-EINVAL, "rc_bepath is not set");
1946  }
1947  cctx->cc_recv_queue_min_length = max64(cctx->cc_recv_queue_min_length,
1951 
1952  if (rctx->rc_max_rpc_msg_size == 0)
1953  rctx->rc_max_rpc_msg_size = cctx->cc_max_rpc_msg_size;
1954 
1955  if (cctx->cc_no_storage)
1956  return M0_RC(0);
1957 
1958  if (!stype_is_valid(rctx->rc_stype)) {
1959  cs_stob_types_list(cctx->cc_outfile);
1960  return M0_ERR_INFO(-EINVAL, "Invalid service type");
1961  }
1962 
1963  if (cs_eps_tlist_is_empty(&rctx->rc_eps) && rctx->rc_nr_services == 0)
1964  return M0_RC(0);
1965 
1966  if (cs_eps_tlist_is_empty(&rctx->rc_eps))
1967  return M0_ERR_INFO(-EINVAL, "Endpoint is missing");
1968 
1969  m0_tl_for(cs_eps, &rctx->rc_eps, ep) {
1970  int rc;
1971 
1972  M0_ASSERT(cs_endpoint_and_xprt_bob_check(ep));
1973  rc = cs_endpoint_validate(cctx, ep->ex_endpoint, ep->ex_xprt);
1974  if (rc != 0)
1975  return M0_ERR_INFO(rc, "Invalid endpoint: %s",
1976  ep->ex_endpoint);
1977  } m0_tl_endfor;
1978 
1979  return M0_RC(0);
1980 }
1981 
1983 {
1984  struct m0_reqh_context *rctx = &cctx->cc_reqh_ctx;
1985  int i;
1986 
1987  M0_ENTRY();
1988 
1990 
1991  for (i = 0; i < M0_CST_NR && rctx->rc_services[i] != NULL;
1992  ++i) {
1993  const char *sname = rctx->rc_services[i];
1994 
1995  if (!m0_reqh_service_is_registered(sname))
1996  return M0_ERR_INFO(-ENOENT,
1997  "Service is not registered: %s",
1998  sname);
1999 
2000  if (service_is_duplicate(rctx, sname))
2001  return M0_ERR_INFO(-EEXIST, "Service is not unique: %s",
2002  sname);
2003  }
2004 
2005  return M0_RC(0);
2006 }
2007 
2019 static int cs_daemonize(struct m0_motr *cctx)
2020 {
2021  if (cctx->cc_daemon) {
2022  struct sigaction hup_act = { .sa_handler = SIG_IGN };
2023  return daemon(1, 0) ?: sigaction(SIGHUP, &hup_act, NULL);
2024  }
2025  return 0;
2026 }
2027 
2028 static int process_fid_parse(const char *str, struct m0_fid *fid)
2029 {
2030  M0_PRE(str != NULL);
2031  M0_PRE(fid != NULL);
2032  return m0_fid_sscanf(str, fid) ?:
2034  m0_fid_is_valid(fid) ?
2035  0 : M0_ERR(-EINVAL);
2036 }
2037 
2038 /* With this, utilities like m0mkfs will generate process FID on the fly */
2040 {
2041  if (!m0_fid_is_set(&rctx->rc_fid)) {
2042  m0_uuid_generate((struct m0_uint128*)&rctx->rc_fid);
2044  }
2045 }
2046 
2048 static int _args_parse(struct m0_motr *cctx, int argc, char **argv)
2049 {
2050  struct m0_reqh_context *rctx = &cctx->cc_reqh_ctx;
2051  int rc_getops;
2052  int rc = 0;
2053 
2054  M0_ENTRY();
2055 
2056  if (argc <= 1) {
2057  cs_usage(cctx->cc_outfile, argv[0]);
2058  return M0_RC(-EINVAL);
2059  }
2060 
2061  rc_getops = M0_GETOPTS(argv[0], argc, argv,
2062  /* -------------------------------------------
2063  * Queries
2064  */
2065  M0_VOIDARG('h', "Usage help",
2066  LAMBDA(void, (void)
2067  {
2068  cs_help(cctx->cc_outfile, argv[0]);
2069  rc = 1;
2070  })),
2071  M0_VOIDARG('v', "Show version information and exit",
2072  LAMBDA(void, (void)
2073  {
2075  rc = 1;
2076  })),
2077  M0_VOIDARG('x', "List supported network transports",
2078  LAMBDA(void, (void)
2079  {
2080  cs_xprts_list(cctx->cc_outfile,
2081  cctx->cc_xprts,
2082  cctx->cc_xprts_nr);
2083  rc = 1;
2084  })),
2085  M0_VOIDARG('l', "List supported services",
2086  LAMBDA(void, (void)
2087  {
2088  printf("Supported services:\n");
2090  rc = 1;
2091  })),
2092  /* -------------------------------------------
2093  * Global options
2094  */
2095  M0_VOIDARG('F',
2096  "Force mkfs to override found filesystem",
2097  LAMBDA(void, (void)
2098  {
2099  cctx->cc_force = true;
2100  })),
2101  M0_FORMATARG('Q', "Minimum length of TM receive queue",
2102  "%i", &cctx->cc_recv_queue_min_length),
2103  M0_FORMATARG('M', "Maximum RPC message size", "%i",
2104  &cctx->cc_max_rpc_msg_size),
2105  M0_STRINGARG('H', "Endpoint address of HA service",
2106  LAMBDA(void, (const char *s)
2107  {
2108  cctx->cc_ha_addr = m0_strdup(s);
2109  M0_ASSERT(cctx->cc_ha_addr != NULL);
2110  })),
2111  M0_STRINGARG('G', "Endpoint address of MD service",
2112  LAMBDA(void, (const char *s)
2113  {
2115  &cctx->cc_mds_eps, s);
2116  M0_LOG(M0_DEBUG, "adding %s to md ep "
2117  "list %d", s, rc);
2118  })),
2119  M0_STRINGARG('R', "Endpoint address of stats service",
2120  LAMBDA(void, (const char *s)
2121  {
2123  &cctx->cc_stats_svc_epx, s);
2124  })),
2125  M0_STRINGARG('i', "Add new entry to the list of IOS"
2126  " endpoint addresses",
2127  LAMBDA(void, (const char *s)
2128  {
2130  &cctx->cc_ios_eps, s);
2131  M0_LOG(M0_DEBUG, "adding %s to ios ep "
2132  "list %d", s, rc);
2133  })),
2134  M0_FORMATARG('w', "Pool width", "%i",
2135  &cctx->cc_pool_width),
2136  M0_VOIDARG('Z', "Run as daemon",
2137  LAMBDA(void, (void)
2138  {
2139  cctx->cc_daemon = true;
2140  })),
2141  M0_NUMBERARG('E', "Number of net buffers used by IOS",
2142  LAMBDA(void, (int64_t n)
2143  {
2145  })),
2146  M0_NUMBERARG('J', "Number of net buffers used by SNS",
2147  LAMBDA(void, (int64_t n)
2148  {
2149  cctx->cc_sns_buf_nr = n;
2150  })),
2151  M0_STRINGARG('o', "Enable fault injection point"
2152  " with given name",
2153  LAMBDA(void, (const char *s)
2154  {
2155  cctx->cc_enable_finj = true;
2156  m0_fi_init();
2158  })),
2159  M0_VOIDARG('g', "Disable ADDB storage",
2160  LAMBDA(void, (void)
2161  {
2163  true;
2164  })),
2165  M0_STRINGARG('u', "Node UUID",
2166  LAMBDA(void, (const char *s)
2167  {
2168  /* not used here, it's a placeholder */
2169  })),
2170  /* -------------------------------------------
2171  * Request handler options
2172  */
2173  M0_STRINGARG('D', "BE stob domain file path",
2174  LAMBDA(void, (const char *s)
2175  {
2176  rctx->rc_bepath = s;
2177  })),
2178  M0_STRINGARG('L', "BE log file path",
2179  LAMBDA(void, (const char *s)
2180  {
2181  rctx->rc_be_log_path = s;
2182  })),
2183  M0_STRINGARG('b', "BE seg0 file path",
2184  LAMBDA(void, (const char *s)
2185  {
2186  rctx->rc_be_seg0_path = s;
2187  })),
2188  M0_STRINGARG('B', "BE primary segment file path",
2189  LAMBDA(void, (const char *s)
2190  {
2191  rctx->rc_be_seg_path = s;
2192  })),
2193  M0_NUMBERARG('z', "BE primary segment size",
2194  LAMBDA(void, (int64_t size)
2195  {
2197  })),
2198  M0_NUMBERARG('V', "BE log size",
2199  LAMBDA(void, (int64_t size)
2200  {
2202  })),
2203  M0_NUMBERARG('n', "BE tx group tx nr max",
2204  LAMBDA(void, (int64_t nr)
2205  {
2207  })),
2208  M0_NUMBERARG('k', "BE tx group reg nr max",
2209  LAMBDA(void, (int64_t nr)
2210  {
2212  })),
2213  M0_NUMBERARG('K', "BE tx group reg size max",
2214  LAMBDA(void, (int64_t size)
2215  {
2217  size;
2218  })),
2219  M0_NUMBERARG('p', "BE tx group payload size max",
2220  LAMBDA(void, (int64_t size)
2221  {
2223  size;
2224  })),
2225  M0_NUMBERARG('C', "BE tx reg nr max",
2226  LAMBDA(void, (int64_t nr)
2227  {
2229  })),
2230  M0_NUMBERARG('N', "BE tx reg size max",
2231  LAMBDA(void, (int64_t size)
2232  {
2234  })),
2235  M0_NUMBERARG('s', "BE tx payload size max",
2236  LAMBDA(void, (int64_t size)
2237  {
2239  })),
2240  M0_NUMBERARG('y', "BE tx group freeze timeout min, ms",
2241  LAMBDA(void, (int64_t t)
2242  {
2244  t * M0_TIME_ONE_MSEC;
2245  })),
2246  M0_NUMBERARG('Y', "BE tx group freeze timeout max, ms",
2247  LAMBDA(void, (int64_t t)
2248  {
2250  t * M0_TIME_ONE_MSEC;
2251  })),
2252  M0_VOIDARG('a', "Preallocate BE segment",
2253  LAMBDA(void, (void)
2254  {
2255  rctx->rc_be_seg_preallocate = true;
2256  })),
2257  M0_STRINGARG('c', "Path to the configuration database",
2258  LAMBDA(void, (const char *s)
2259  {
2260  rctx->rc_confdb = s;
2261  })),
2262  M0_STRINGARG('T', "Storage domain type",
2263  LAMBDA(void, (const char *s)
2264  {
2265  rctx->rc_stype = s;
2266  })),
2267  M0_STRINGARG('S', "Data storage filename",
2268  LAMBDA(void, (const char *s)
2269  {
2270  rctx->rc_stpath = s;
2271  })),
2272  M0_STRINGARG('A', "ADDB storage domain location",
2273  LAMBDA(void, (const char *s)
2274  {
2275  char tmp_buf[512];
2276  sprintf(tmp_buf, "%s-%d", s, (int)m0_pid());
2277  rctx->rc_addb_stlocation = strdup(tmp_buf);
2278  })),
2279  M0_STRINGARG('d', "Device configuration file",
2280  LAMBDA(void, (const char *s)
2281  {
2282  rctx->rc_dfilepath = s;
2283  })),
2284  M0_VOIDARG('U', "Use confc API instead of `-d`"
2285  " to obtain device configuration",
2286  LAMBDA(void, (void)
2287  {
2288  rctx->rc_stob.s_ad_disks_init = true;
2289  })),
2290  M0_NUMBERARG('q', "Minimum TM recv queue length",
2291  LAMBDA(void, (int64_t length)
2292  {
2293  rctx->rc_recv_queue_min_length = length;
2294  })),
2295  M0_NUMBERARG('m', "Maximum RPC message size",
2296  LAMBDA(void, (int64_t size)
2297  {
2299  })),
2300  /*
2301  * XXX TODO Test the following use case: endpoints are
2302  * specified both via `-e' CLI option and via
2303  * configuration.
2304  */
2305  M0_STRINGARG('e', "Network endpoint,"
2306  " e.g. transport:address",
2307  LAMBDA(void, (const char *s)
2308  {
2310  })),
2311  M0_STRINGARG('f', "Process fid (mandatory for m0d)",
2312  LAMBDA(void, (const char *s)
2313  {
2315  })),
2316  M0_VOIDARG('I', "Disable direct I/O for data",
2317  LAMBDA(void, (void)
2318  {
2319  rctx->rc_disable_direct_io = true;
2320  })),
2321  M0_VOIDARG('j', "Enable fault injection service (FIS)",
2322  LAMBDA(void, (void)
2323  {
2324  rctx->rc_fis_enabled = true;
2325  })),
2326  M0_NUMBERARG('r', "ADDB Record storage size",
2327  LAMBDA(void, (int64_t size)
2328  {
2330  M0_LOG(M0_WARN, "ADDB size is more than recommended");
2331  M0_LOG(M0_DEBUG, "ADDB size = %" PRIu64 "", size);
2333  })),
2334  );
2335  /* generate reqh fid in case it is all-zero */
2337 
2338  return M0_RC(rc_getops ?: rc);
2339 }
2340 
2341 static int cs_args_parse(struct m0_motr *cctx, int argc, char **argv)
2342 {
2343  M0_ENTRY();
2344  return _args_parse(cctx, argc, argv);
2345 }
2346 
2347 static void cs_ha_connect(struct m0_motr *cctx)
2348 {
2349  m0_motr_ha_connect(&cctx->cc_motr_ha);
2351 }
2352 
2353 static int cs_conf_setup(struct m0_motr *cctx)
2354 {
2355  struct m0_reqh *reqh = motr2reqh(cctx);
2356  struct m0_confc_args conf_args = {
2357  .ca_profile = "0:0",
2358  .ca_rmach = m0_motr_to_rmach(cctx),
2359  .ca_group = m0_locality0_get()->lo_grp
2360  };
2361  int rc;
2362 
2363  if (cctx->cc_reqh_ctx.rc_confdb != NULL) {
2364  rc = m0_file_read(cctx->cc_reqh_ctx.rc_confdb,
2365  &conf_args.ca_confstr);
2366  if (rc != 0)
2367  return M0_ERR(rc);
2368  }
2369 
2370  rc = m0_reqh_conf_setup(reqh, &conf_args);
2371  /* confstr is not needed after m0_reqh_conf_setup() */
2372  m0_free0(&conf_args.ca_confstr);
2373  if (rc != 0)
2374  return M0_ERR(rc);
2375 
2377  if (rc != 0) {
2380  }
2381  return M0_RC(rc);
2382 }
2383 
2384 static void cs_conf_fini(struct m0_motr *cctx)
2385 {
2386  if (cctx->cc_pools_common.pc_confc != NULL)
2387  m0_pools_common_fini(&cctx->cc_pools_common);
2388 
2391 }
2392 
2394 {
2395  return M0_RC(m0_reqh_mdpool_layout_build(&cctx->cc_reqh_ctx.rc_reqh));
2396 }
2397 
2406 {
2407  int signum = M0_FI_ENABLED("ut_signal") ? SIGUSR2 : SIGINT;
2408 
2409  M0_ENTRY("signum=%d", signum);
2410  if (kill(getpid(), signum) != 0)
2411  M0_LOG(M0_ERROR, "kill() failed with errno=%d", errno);
2412  M0_LEAVE();
2413 }
2414 
2415 volatile sig_atomic_t gotsignal;
2416 
2421 M0_INTERNAL void m0_cs_gotsignal_reset(void)
2422 {
2423  /* get rid of remnants of cs_rconfc_fatal_cb() if called */
2424  gotsignal = 0;
2425 }
2426 
2455 enum cs_level {
2457  /*
2458  * XXX Added as a workaround to match original implementation.
2459  * I don't know why it works now.
2460  *
2461  * The proper way would be to wait in m0_net_buffer_pool_fini()
2462  * until all buffers are not in use, then run the finalisation code.
2463  */
2507 };
2508 
2509 static const struct m0_modlev cs_module_levels[];
2510 
2511 static struct m0_motr *cs_module2motr(struct m0_module *module)
2512 {
2513  return bob_of(module, struct m0_motr, cc_module, &cs_bob_type);
2514 }
2515 
2516 static int cs_level_enter(struct m0_module *module)
2517 {
2518  struct m0_motr *cctx = cs_module2motr(module);
2519  struct m0_reqh_context *rctx = &cctx->cc_reqh_ctx;
2520  struct m0_reqh *reqh = motr2reqh(cctx);
2521  int level = module->m_cur + 1;
2522  const char *level_name = cs_module_levels[level].ml_name;
2523  int rc;
2524 
2525  M0_ENTRY("cctx=%p level=%d level_name=%s", cctx, level, level_name);
2538  return M0_ERR(-EINTR);
2539  switch (level) {
2540  case CS_LEVEL_MOTR_INIT:
2541  cs_motr_init(cctx);
2542  return M0_RC(0);
2544  return M0_RC(0);
2546  return M0_RC(cs_reqh_ctx_init(cctx));
2547  case CS_LEVEL_CS_INIT:
2548  return M0_RC(0);
2549  case CS_LEVEL_RWLOCK_LOCK:
2550  m0_rwlock_write_lock(&cctx->cc_rwlock);
2551  return M0_RC(0);
2552  case CS_LEVEL_ARGS_PARSE:
2553  return M0_RC(cs_args_parse(cctx,
2554  cctx->cc_setup_env_argc,
2555  cctx->cc_setup_env_argv));
2557  return M0_RC(cs_reqh_ctx_validate(cctx));
2558  case CS_LEVEL_DAEMONIZE:
2559  return M0_RC(cs_daemonize(cctx));
2561  return M0_RC(cs_net_domains_init(cctx));
2563  return M0_RC(cs_buffer_pool_setup(cctx));
2564  case CS_LEVEL_REQH_START:
2565  return M0_RC(cs_reqh_start(&cctx->cc_reqh_ctx));
2567  return M0_RC(cs_rpc_machines_init(cctx));
2568  case CS_LEVEL_HA_INIT:
2569  return M0_RC(cs_ha_init(cctx));
2571  if (cctx->cc_no_conf)
2572  return M0_RC(0);
2573  if (cctx->cc_reqh_ctx.rc_confdb == NULL)
2575  return M0_RC(0);
2581  return M0_RC(0);
2583  if (cctx->cc_no_conf)
2584  return M0_RC(0);
2585  return M0_RC(cs_conf_setup(cctx));
2586  case CS_LEVEL_CONF_GET:
2587  if (cctx->cc_no_conf)
2588  return M0_RC(0);
2590  &cctx->cc_conf_root);
2591  if (rc != 0)
2592  cctx->cc_conf_root = NULL;
2593  return M0_RC(rc);
2595  if (cctx->cc_no_conf)
2596  return M0_RC(0);
2597  return M0_RC(m0_conf_full_load(cctx->cc_conf_root));
2599  if (cctx->cc_no_conf)
2600  return M0_RC(0);
2601  return M0_RC(cs_conf_services_init(cctx));
2602  case CS_LEVEL_CONF_TO_ARGS:
2603  if (cctx->cc_no_conf)
2604  return M0_RC(0);
2605  return M0_RC(cs_conf_to_args(&cctx->cc_args,
2606  cctx->cc_conf_root));
2608  if (cctx->cc_no_conf)
2609  return M0_RC(0);
2610  return M0_RC(_args_parse(cctx, cctx->cc_args.ca_argc,
2611  cctx->cc_args.ca_argv));
2613  if (cctx->cc_no_conf)
2614  return M0_RC(0);
2615  if (cctx->cc_reqh_ctx.rc_confdb != NULL)
2617  return M0_RC(0);
2619  if (cctx->cc_no_conf)
2620  return M0_RC(0);
2621  return M0_RC(m0_pools_common_init(&cctx->cc_pools_common,
2623  case CS_LEVEL_POOLS_SETUP:
2624  if (cctx->cc_no_conf)
2625  return M0_RC(0);
2626  return M0_RC(m0_pools_setup(&cctx->cc_pools_common,
2627  NULL, NULL, NULL));
2628  case CS_LEVEL_SET_OOSTORE:
2629  if (cctx->cc_no_conf)
2630  return M0_RC(0);
2631  if (cctx->cc_pools_common.pc_md_redundancy > 0)
2632  motr2reqh(cctx)->rh_oostore = true;
2633  return M0_RC(0);
2635  if (cctx->cc_no_conf)
2636  return M0_RC(0);
2637  if (!cctx->cc_mkfs)
2639  return M0_RC(0);
2641  if (cctx->cc_no_conf)
2642  return M0_RC(0);
2643  m0_confc_close(&cctx->cc_conf_root->rt_obj);
2644  cctx->cc_conf_root = NULL;
2645  return M0_RC(0);
2647  return M0_RC(cs_storage_setup(cctx));
2648  case CS_LEVEL_DTM0_INIT:
2649  return M0_RC(cs_dtm0_init(rctx));
2651  m0_rwlock_write_unlock(&cctx->cc_rwlock);
2652  return M0_RC(0);
2654  /*
2655  * m0_cs_start() is not called in mkfs mode.
2656  *
2657  * Halon expects STARTED to be able to continue the bootstrap,
2658  * even in mkfs case.
2659  *
2660  * XXX STARTED expected even in the error case.
2661  * It should be fixed either here or in Halon.
2662  */
2663  if (cctx->cc_mkfs) {
2665  /*
2666  For mkfs, M0_NC_DTM_RECOVERING state is transient,
2667  sending M0_CONF_HA_PROCESS_DTM_RECOVERED just after
2668  M0_CONF_HA_PROCESS_STARTED.
2669 
2670  cs_ha_process_event(cctx,
2671  M0_CONF_HA_PROCESS_DTM_RECOVERED);
2672  */
2673  }
2674  return M0_RC(0);
2676  if (!cctx->cc_no_conf) { /* otherwise rconfc did not start */
2677  /*
2678  * So far rconfc has no fatal callback installed
2679  * to distinguish rconfc failure occurred during
2680  * m0_rconfc_start_wait() from failure state reached
2681  * after successful rconfc start. To catch the
2682  * after-start failure, fatal callback is installed
2683  * here.
2684  */
2689  }
2690  return M0_RC(0);
2691  case CS_LEVEL_DIX_SETUP:
2692  if (cctx->cc_mkfs)
2693  return M0_RC(m0_cs_dix_setup(cctx));
2694  else
2695  return M0_RC(0);
2696  case CS_LEVEL_SETUP_ENV:
2697  return M0_RC(0);
2698  case CS_LEVEL_CHECK_CONFIG:
2699  cctx->cc_skip_pools_and_ha_update = cctx->cc_no_conf ||
2700  bad_address(cctx->cc_ha_addr) ||
2701  cctx->cc_no_all2all_connections;
2702  return M0_RC(0);
2703  case CS_LEVEL_CONF_GET2:
2704  if (cctx->cc_skip_pools_and_ha_update)
2705  return M0_RC(0);
2707  &cctx->cc_conf_root);
2708  if (rc != 0)
2709  cctx->cc_conf_root = NULL;
2710  return M0_RC(rc);
2712  if (cctx->cc_skip_pools_and_ha_update)
2713  return M0_RC(0);
2714  return M0_RC(m0_pools_service_ctx_create(&cctx->cc_pools_common));
2716  if (cctx->cc_skip_pools_and_ha_update)
2717  return M0_RC(0);
2718  return M0_RC(m0_pool_versions_setup(&cctx->cc_pools_common));
2720  return M0_RC(reqh_services_start(rctx, cctx));
2722  if (cctx->cc_skip_pools_and_ha_update)
2723  return M0_RC(0);
2724  if (M0_FI_ENABLED("pools_cleanup"))
2725  return M0_RC(-EINVAL);
2728  if (cctx->cc_skip_pools_and_ha_update)
2729  return M0_RC(0);
2732  m0_confc_close(&cctx->cc_conf_root->rt_obj);
2733  cctx->cc_conf_root = NULL;
2734  return M0_RC(0);
2737  /*
2738  For m0d, M0_NC_DTM_RECOVERING state is being sent here just for
2739  test purposes. The real notification shall be sent inside
2740  dtm0_rmsg_fom_tick().
2741 
2742  cs_ha_process_event(cctx,
2743  M0_CONF_HA_PROCESS_DTM_RECOVERED);
2744  */
2745  return M0_RC(0);
2746  case CS_LEVEL_START:
2747  return M0_RC(0);
2748  default:
2749  return M0_ERR_INFO(-ENOSYS, "cctx=%p level=%d", cctx, level);
2750  }
2751 }
2752 
2753 static void cs_level_leave(struct m0_module *module)
2754 {
2755  struct m0_motr *cctx = cs_module2motr(module);
2756  struct m0_reqh_context *rctx = &cctx->cc_reqh_ctx;
2757  int level = module->m_cur;
2758  const char *level_name = cs_module_levels[level].ml_name;
2759 
2760  M0_ENTRY("cctx=%p level=%d level_name=%s", cctx, level, level_name);
2761  switch (level) {
2762  case CS_LEVEL_MOTR_INIT:
2763  cs_motr_fini(cctx);
2764  break;
2768  break;
2771  break;
2772  case CS_LEVEL_CS_INIT:
2773  case CS_LEVEL_RWLOCK_LOCK:
2774  case CS_LEVEL_ARGS_PARSE:
2776  case CS_LEVEL_DAEMONIZE:
2778  /* see CS_LEVEL_BUFFER_FINI_WORKAROUND */
2780  /* see CS_LEVEL_BUFFER_FINI_WORKAROUND */
2781  break;
2782  case CS_LEVEL_REQH_START:
2783  if (rctx->rc_state == RC_INITIALISED)
2785  break;
2788  break;
2789  case CS_LEVEL_HA_INIT:
2791  break;
2793  if (cctx->cc_ha_is_started)
2794  cctx->cc_ha_was_started = true;
2795  /*
2796  * XXX There is a race during HA finalisation. Addb2 is still
2797  * up at this point and may cause I/O to storage. If the I/O
2798  * fails ioq_io_error() uses i_ha and i_ha_link to send an HA
2799  * message. This can be done along with the HA finalisation.
2800  */
2801  if (cctx->cc_ha_was_started &&
2803  cs_ha_fini(cctx);
2805  cs_reqh_stop(rctx);
2806  break;
2808  if (cctx->cc_no_conf)
2809  break;
2810  if (cctx->cc_conf_root != NULL) {
2811  m0_confc_close(&cctx->cc_conf_root->rt_obj);
2812  cctx->cc_conf_root = NULL;
2813  }
2814  /*
2815  * Need to shut rconfc down prior to stopping REQH
2816  * services, as rconfc needs RPC be up and running
2817  * to safely stop and fini.
2818  */
2819  cs_conf_fini(cctx);
2820  break;
2821  case CS_LEVEL_CONF_GET:
2822  break;
2824  break;
2826  reqh_context_services_fini(&cctx->cc_reqh_ctx, cctx);
2827  break;
2828  case CS_LEVEL_CONF_TO_ARGS:
2829  break;
2831  break;
2833  if (cctx->cc_mkfs)
2835  if (cctx->cc_ha_was_started)
2836  cs_ha_stop(cctx);
2837  break;
2839  if (cctx->cc_pools_common.pc_confc != NULL)
2840  m0_pools_common_fini(&cctx->cc_pools_common);
2841  break;
2842  case CS_LEVEL_POOLS_SETUP:
2843  if (cctx->cc_pools_common.pc_confc != NULL)
2844  m0_pools_destroy(&cctx->cc_pools_common);
2845  break;
2846  case CS_LEVEL_SET_OOSTORE:
2847  break;
2849  break;
2851  break;
2853  if (rctx->rc_state == RC_INITIALISED) {
2856  }
2857  break;
2858  case CS_LEVEL_DTM0_INIT:
2859  cs_dtm0_fini(rctx);
2860  break;
2862  break;
2864  if (cctx->cc_mkfs)
2866  break;
2868  break;
2869  case CS_LEVEL_DIX_SETUP:
2870  break;
2871  case CS_LEVEL_SETUP_ENV:
2872  break;
2873  case CS_LEVEL_CHECK_CONFIG:
2874  break;
2875  case CS_LEVEL_CONF_GET2:
2876  if (cctx->cc_conf_root != NULL) {
2877  m0_confc_close(&cctx->cc_conf_root->rt_obj);
2878  cctx->cc_conf_root = NULL;
2879  }
2880  break;
2882  if (cctx->cc_pools_common.pc_confc != NULL)
2883  m0_pools_service_ctx_destroy(&cctx->cc_pools_common);
2884  break;
2886  if (rctx->rc_state == RC_INITIALISED)
2888  if (cctx->cc_pools_common.pc_confc != NULL)
2889  m0_pool_versions_destroy(&cctx->cc_pools_common);
2890  break;
2892  if (rctx->rc_state >= RC_REQH_INITIALISED) {
2894  /*
2895  * cctx->cc_ha_is_started is being changed,
2896  * we need the old one
2897  */
2898  cctx->cc_ha_was_started = cctx->cc_ha_is_started;
2899  }
2900  break;
2902  break;
2904  break;
2906  break;
2909  break;
2910  case CS_LEVEL_START:
2911  break;
2912  default:
2913  M0_IMPOSSIBLE("Can't be here: level=%d", level);
2914  }
2915  M0_LEAVE();
2916 }
2917 
2918 #define CS_MODULE_LEVEL(level) [level] = { \
2919  .ml_name = #level, \
2920  .ml_enter = cs_level_enter, \
2921  .ml_leave = cs_level_leave, \
2922  }
2923 
2924 static const struct m0_modlev cs_module_levels[] = {
2969 };
2970 #undef CS_MODULE_LEVEL
2971 
2972 int m0_cs_setup_env(struct m0_motr *cctx, int argc, char **argv)
2973 {
2974  int rc;
2975 
2976  if (M0_FI_ENABLED("fake_error"))
2977  return M0_ERR(-EINVAL);
2978 
2979  cctx->cc_setup_env_argc = argc;
2980  cctx->cc_setup_env_argv = argv;
2981  rc = m0_module_init(&cctx->cc_module, CS_LEVEL_SETUP_ENV);
2982  if (rc != 0)
2983  m0_module_fini(&cctx->cc_module, CS_LEVEL_CS_INIT);
2984  return M0_RC(rc);
2985 }
2986 
2988 {
2989  int rc;
2990 
2991  M0_ENTRY();
2992 
2993  rc = m0_module_init(&cctx->cc_module, CS_LEVEL_START);
2994  if (rc != 0)
2995  m0_module_fini(&cctx->cc_module, CS_LEVEL_SETUP_ENV);
2996  return rc == 0 ? M0_RC(0) : M0_ERR(rc);
2997 }
2998 
2999 int m0_cs_init(struct m0_motr *cctx, struct m0_net_xprt **xprts,
3000  size_t xprts_nr, FILE *out, bool mkfs)
3001 {
3002  int rc;
3003 
3004  M0_ENTRY();
3005  M0_PRE(xprts != NULL && xprts_nr > 0 && out != NULL);
3006 
3007  if (M0_FI_ENABLED("fake_error"))
3008  return M0_ERR(-EINVAL);
3009 
3010  cctx->cc_xprts = xprts;
3011  cctx->cc_xprts_nr = xprts_nr;
3012  cctx->cc_outfile = out;
3013  cctx->cc_mkfs = mkfs;
3014  cctx->cc_force = false;
3015  cctx->cc_no_all2all_connections = false;
3016  cctx->cc_sns_buf_nr = 1 << 6;
3017 
3018  m0_module_setup(&cctx->cc_module, "motr/setup", cs_module_levels,
3020  m0_motr_bob_init(cctx);
3021  rc = m0_module_init(&cctx->cc_module, CS_LEVEL_REQH_CTX_INIT);
3022  if (rc != 0) {
3023  m0_module_fini(&cctx->cc_module, M0_MODLEV_NONE);
3024  m0_motr_bob_fini(cctx);
3025  }
3026  return M0_RC(rc);
3027 }
3028 
3029 void m0_cs_fini(struct m0_motr *cctx)
3030 {
3031  M0_ENTRY();
3032 
3033  m0_module_fini(&cctx->cc_module, M0_MODLEV_NONE);
3034  m0_motr_bob_fini(cctx);
3035 
3036  M0_LEAVE();
3037 }
3038 
3043 M0_INTERNAL int m0_motr_stob_reopen(struct m0_reqh *reqh,
3044  struct m0_poolmach *pm,
3045  uint32_t dev_id)
3046 {
3047  struct m0_stob_id stob_id;
3048  struct m0_reqh_context *rctx;
3049  struct cs_stobs *stob;
3050  yaml_document_t *doc;
3051  yaml_node_t *node;
3052  yaml_node_t *s_node;
3053  yaml_node_item_t *item;
3054  const char *f_path;
3055  uint64_t cid;
3056  int rc = 0;
3057  int result;
3058 
3060  stob = &rctx->rc_stob;
3061  doc = &stob->s_sfile.sf_document;
3063  return M0_RC(cs_conf_device_reopen(pm, stob, dev_id));
3064  if (!stob->s_sfile.sf_is_initialised)
3065  return M0_ERR(-EINVAL);
3066  for (node = doc->nodes.start; node < doc->nodes.top; ++node) {
3067  for (item = (node)->data.sequence.items.start;
3068  item < (node)->data.sequence.items.top; ++item) {
3069  s_node = yaml_document_get_node(doc, *item);
3070  result = stob_file_id_get(doc, s_node, &cid);
3071  if (result != 0)
3072  continue;
3073  if (cid == dev_id) {
3074  f_path = stob_file_path_get(doc, s_node);
3075  m0_stob_id_make(0, cid, &stob->s_sdom->sd_id,
3076  &stob_id);
3077  rc = m0_stob_linux_reopen(&stob_id, f_path);
3078  if (rc != 0)
3079  return M0_ERR(rc);
3080  }
3081  }
3082  }
3083  return M0_RC(rc);
3084 }
3085 
3087 #undef M0_TRACE_SUBSYSTEM
3088 
3089 /*
3090  * Local variables:
3091  * c-indentation-style: "K&R"
3092  * c-basic-offset: 8
3093  * tab-width: 8
3094  * fill-column: 80
3095  * scroll-step: 1
3096  * End:
3097  */
m0_bcount_t tgc_payload_max
Definition: tx_group.h:66
const struct m0_conf_obj_type * m0_conf_obj_type(const struct m0_conf_obj *obj)
Definition: obj.c:363
struct m0_fid co_id
Definition: obj.h:208
M0_INTERNAL int m0_reqh_service_state_get(const struct m0_reqh_service *s)
Definition: reqh_service.c:560
#define M0_GETOPTS(progname, argc, argv,...)
Definition: getopts.h:169
static void cs_buffer_pool_fini(struct m0_motr *cctx)
Definition: setup.c:692
M0_INTERNAL uint64_t m0_process(void)
Definition: kthread.c:295
M0_INTERNAL void m0_net_buffer_pool_fini(struct m0_net_buffer_pool *pool)
Definition: buffer_pool.c:154
uint64_t id
Definition: cob.h:240
M0_INTERNAL void m0_mdstore_fini(struct m0_mdstore *md)
Definition: mdstore.c:130
M0_INTERNAL void m0_reqh_be_fini(struct m0_reqh *reqh)
Definition: reqh.c:289
const char * ex_endpoint
Definition: setup.h:174
static size_t nr
Definition: dump.c:1505
static void cs_ha_process_event(struct m0_motr *cctx, enum m0_conf_ha_process_event event)
Definition: setup.c:618
M0_INTERNAL void m0_pools_common_fini(struct m0_pools_common *pc)
Definition: pool.c:1549
struct m0_be_domain * bs_domain
Definition: seg.h:82
M0_INTERNAL int cs_conf_storage_init(struct cs_stobs *stob, struct m0_storage_devs *devs, bool force)
Definition: conf.c:398
#define M0_PRE(cond)
void m0_rpc_machine_fini(struct m0_rpc_machine *machine)
Definition: rpc_machine.c:233
m0_time_t bec_group_freeze_timeout_max
Definition: engine.h:81
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
Definition: dtm.h:554
M0_INTERNAL struct m0_reqh_service * m0_reqh_service_lookup(const struct m0_reqh *reqh, const struct m0_fid *fid)
Definition: reqh_service.c:551
static int reqh_services_start(struct m0_reqh_context *rctx, struct m0_motr *cctx)
Definition: setup.c:1222
m0_bcount_t rc_addb_record_file_size
Definition: setup.h:347
void m0_net_domain_fini(struct m0_net_domain *dom)
Definition: domain.c:71
M0_INTERNAL int m0_be_ut_backend_init_cfg(struct m0_be_ut_backend *ut_be, const struct m0_be_domain_cfg *cfg, bool mkfs)
Definition: stubs.c:231
struct m0_cob_domain * md_dom
Definition: mdstore.h:58
#define m0_strdup(s)
Definition: string.h:43
struct m0_reqh * m0_cs_reqh_get(struct m0_motr *cctx)
Definition: setup.c:1762
M0_INTERNAL int m0_motr_ha_start(struct m0_motr_ha *mha)
Definition: ha.c:549
m0_bcount_t rc_be_tx_group_reg_size_max
Definition: setup.h:284
M0_INTERNAL int m0_cob_domain_mkfs(struct m0_cob_domain *dom, const struct m0_fid *rootfid, struct m0_be_tx *tx)
Definition: cob.c:980
m0_conf_ha_process_event
Definition: ha.h:49
M0_INTERNAL void m0_reqh_service_stop(struct m0_reqh_service *service)
Definition: reqh_service.c:402
static void cs_rpc_machines_fini(struct m0_reqh *reqh)
Definition: setup.c:566
struct m0_pdclust_attr pvs_attr
Definition: obj.h:481
#define NULL
Definition: misc.h:38
const char * rc_stpath
Definition: setup.h:231
static void cs_rconfc_fatal_cb(struct m0_rconfc *rconfc)
Definition: setup.c:2405
static int cs_level_enter(struct m0_module *module)
Definition: setup.c:2516
static int cs_reqh_ctx_init(struct m0_motr *cctx)
Definition: setup.c:419
m0_bcount_t rc_be_tx_group_reg_nr_max
Definition: setup.h:283
static int reqh_context_services_init(struct m0_reqh_context *rctx, struct m0_motr *cctx)
Definition: setup.c:1145
static int ep_and_xprt_append(struct m0_tl *head, const char *ep)
Definition: setup.c:375
#define ergo(a, b)
Definition: misc.h:293
M0_INTERNAL int m0_conf_full_load(struct m0_conf_root *r)
Definition: helpers.c:165
struct m0_cob_domain_id rc_cdom_id
Definition: setup.h:306
m0_bcount_t rc_be_tx_group_tx_nr_max
Definition: setup.h:282
M0_INTERNAL int m0_mdstore_init(struct m0_mdstore *md, struct m0_be_seg *db, bool init_root)
Definition: mdstore.c:78
#define M0_REQH_INIT(reqh,...)
Definition: reqh.h:262
M0_INTERNAL void m0_uuid_generate(struct m0_uint128 *u)
Definition: uuid.c:44
struct m0_net_buffer_pool cs_buffer_pool
M0_INTERNAL int m0_motr_stob_reopen(struct m0_reqh *reqh, struct m0_poolmach *pm, uint32_t dev_id)
Definition: setup.c:3043
M0_INTERNAL void m0_storage_dev_attach(struct m0_storage_dev *dev, struct m0_storage_devs *devs)
Definition: storage_dev.c:633
static FILE * f
Definition: adieu.c:79
static void cs_conf_fini(struct m0_motr *cctx)
Definition: setup.c:2384
static int cs_args_parse(struct m0_motr *cctx, int argc, char **argv)
Definition: setup.c:2341
static uint32_t max_rpc_msg_size
Definition: m0dixinit.c:72
cs_level
Definition: setup.c:2455
uint32_t pa_N
Definition: pdclust.h:104
struct m0_be_0type_seg_cfg bc_seg0_cfg
Definition: domain.h:120
static struct m0_net_xprt * cs_xprt_lookup(const char *xprt_name, struct m0_net_xprt **xprts, size_t xprts_nr)
Definition: setup.c:211
static struct m0_sm_group * grp
Definition: bytecount.c:38
struct m0_conf_obj rt_obj
Definition: obj.h:372
static struct m0_motr_ha_cfg motr_ha_cfg
Definition: client_init.c:714
#define M0_LOG(level,...)
Definition: trace.h:167
M0_LEAVE()
M0_INTERNAL void m0_reqh_layouts_cleanup(struct m0_reqh *reqh)
Definition: reqh.c:169
static int cs_reqh_start(struct m0_reqh_context *rctx)
Definition: setup.c:1567
M0_INTERNAL void m0_reqh_service_prepare_to_stop(struct m0_reqh_service *service)
Definition: reqh_service.c:375
enum m0_trace_level level
Definition: trace.c:111
static void be_seg_init(struct m0_be_ut_backend *be, m0_bcount_t size, bool preallocate, bool format, const char *stob_create_cfg, struct m0_be_seg **out)
Definition: setup.c:1362
M0_INTERNAL int m0_file_read(const char *path, char **out)
Definition: fs.c:61
const struct m0_conf_obj_type M0_CONF_PVER_TYPE
Definition: pver.c:260
uint8_t ft_id
Definition: fid.h:101
M0_INTERNAL int m0_stob_domain_destroy(struct m0_stob_domain *dom)
Definition: domain.c:227
static void cs_storage_devs_fini(void)
Definition: setup.c:807
const char * rc_confdb
Definition: setup.h:301
char * ca_confstr
Definition: helpers.h:36
static void cs_dtm0_fini(struct m0_reqh_context *rctx)
Definition: setup.c:1698
M0_INTERNAL const char * m0_cs_stypes[M0_STOB_TYPE_NR]
Definition: setup.c:114
int m0_cs_setup_env(struct m0_motr *cctx, int argc, char **argv)
Definition: setup.c:2972
static struct net_test_cmd_node * node
Definition: commands.c:72
static void cs_ha_stop(struct m0_motr *cctx)
Definition: setup.c:637
static uint32_t cs_domain_tms_nr(struct m0_reqh_context *rctx, struct m0_net_domain *dom)
Definition: setup.c:663
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
uint32_t pa_K
Definition: pdclust.h:107
static struct m0_uint128 prefix
Definition: extmap.c:45
static bool m0_is_po2(uint64_t val)
Definition: arith.h:153
void m0_cs_fini(struct m0_motr *cctx)
Definition: setup.c:3029
char * ex_scrbuf
Definition: setup.h:180
#define m0_strcaseeq(a, b)
Definition: string.h:35
M0_INTERNAL void cs_service_fini(struct m0_reqh_service *service)
Definition: setup.c:1178
static void leave(struct m0_locality_chore *chore, struct m0_locality *loc, void *place)
Definition: locality.c:315
M0_INTERNAL void m0_rwlock_write_lock(struct m0_rwlock *lock)
Definition: rwlock.c:42
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
char * but_stob_domain_location
Definition: helper.h:58
struct m0_bufvec data
Definition: di.c:40
m0_time_t rc_be_tx_group_freeze_timeout_max
Definition: setup.h:290
bool rc_be_seg_preallocate
Definition: setup.h:335
const char * rc_stype
Definition: setup.h:240
static void cs_help(FILE *out, const char *progname)
Definition: setup.c:1849
M0_INTERNAL void m0_rconfc_stop_sync(struct m0_rconfc *rconfc)
Definition: rconfc.c:2995
uint32_t bc_zone_pcnt[M0_BAP_NR]
Definition: domain.h:103
M0_INTERNAL int m0_dtm0_domain_init(struct m0_dtm0_domain *dod, struct m0_dtm0_domain_cfg *dod_cfg)
Definition: domain.c:183
M0_INTERNAL void m0_net_xprt_default_set(const struct m0_net_xprt *xprt)
Definition: net.c:143
M0_INTERNAL uint8_t m0_fid_tget(const struct m0_fid *fid)
Definition: fid.c:133
static struct m0_rpc_client_ctx cctx
Definition: rconfc.c:69
static struct m0_be_emap_cursor it
Definition: extmap.c:46
struct m0_conf_obj pv_obj
Definition: obj.h:533
static int cs_be_init(struct m0_reqh_context *rctx, struct m0_be_ut_backend *be, const char *name, bool preallocate, bool format, struct m0_be_seg **out)
Definition: setup.c:1468
M0_INTERNAL void m0_rconfc_fatal_cb_set(struct m0_rconfc *rconfc, m0_rconfc_cb_t cb)
Definition: rconfc.c:3067
const char * ml_name
Definition: module.h:114
static void cs_usage(FILE *out, const char *progname)
Definition: setup.c:1837
static int cs_rpc_machines_init(struct m0_motr *cctx)
Definition: setup.c:542
M0_INTERNAL int m0_stob_linux_reopen(struct m0_stob_id *stob_id, const char *f_path)
Definition: linux.c:554
uint32_t pa_S
Definition: pdclust.h:110
volatile sig_atomic_t gotsignal
Definition: setup.c:2415
uint64_t m0_bcount_t
Definition: types.h:77
const char * rc_bepath
Definition: setup.h:243
static char * cs_storage_ldom_location_gen(const char *stob_path)
Definition: setup.c:955
M0_INTERNAL void m0_be_ut_backend_seg_add2(struct m0_be_ut_backend *ut_be, m0_bcount_t size, bool preallocate, const char *stob_create_cfg, struct m0_be_seg **out)
Definition: helper.c:466
M0_INTERNAL struct m0 * m0_get(void)
Definition: instance.c:41
bool cc_no_conf
Definition: setup.h:428
static int process_fid_parse(const char *str, struct m0_fid *fid)
Definition: setup.c:2028
static void cs_reqh_storage_fini(struct m0_reqh_context *rctx)
Definition: setup.c:1748
#define container_of(ptr, type, member)
Definition: misc.h:33
#define M0_SET0(obj)
Definition: misc.h:64
static const struct m0_modlev cs_module_levels[]
Definition: setup.c:2509
M0_INTERNAL int cs_service_init(const char *name, struct m0_reqh_context *rctx, struct m0_reqh *reqh, struct m0_fid *fid)
Definition: setup.c:1117
const char * ex_xprt
Definition: setup.h:176
M0_INTERNAL int m0_pools_setup(struct m0_pools_common *pc, const struct m0_fid *profile, struct m0_sm_group *sm_grp, struct m0_dtm *dtm)
Definition: pool.c:1810
struct m0_motr * rc_motr
Definition: setup.h:318
static int cs_storage_ldom_destroy(const char *stob_path, const char *str_cfg_init)
Definition: setup.c:971
struct m0_be_tx_credit bec_tx_size_max
Definition: engine.h:73
m0_conf_ha_process_type
Definition: ha.h:86
M0_INTERNAL void m0_reqh_fini(struct m0_reqh *reqh)
Definition: reqh.c:320
M0_INTERNAL int m0_motr_ha_init(struct m0_motr_ha *mha, struct m0_motr_ha_cfg *mha_cfg)
Definition: ha.c:509
static void cs_motr_fini(struct m0_motr *cctx)
Definition: setup.c:1807
M0_INTERNAL struct m0_rpc_machine * m0_motr_to_rmach(struct m0_motr *motr)
Definition: setup.c:196
M0_INTERNAL bool m0_fid_is_set(const struct m0_fid *fid)
Definition: fid.c:106
static void cs_xprts_list(FILE *out, struct m0_net_xprt **xprts, size_t xprts_nr)
Definition: setup.c:226
static struct m0_rpc_item * item
Definition: item.c:56
M0_INTERNAL int m0_reqh_addb2_init(struct m0_reqh *reqh, const char *location, uint64_t key, bool mkfs, bool force, m0_bcount_t size)
Definition: reqh.c:341
static int cs_ha_init(struct m0_motr *cctx)
Definition: setup.c:581
const char * rc_dfilepath
Definition: setup.h:237
static struct foo * obj
Definition: tlist.c:302
#define PRIx64
Definition: types.h:61
struct m0_be_ut_backend rc_be
Definition: setup.h:267
M0_INTERNAL int m0_dtx_done_sync(struct m0_dtx *tx)
Definition: dtm.c:122
const char * bt_name
Definition: bob.h:73
#define M0_VOIDARG(ch, desc, func)
Definition: getopts.h:177
const char * location
Definition: storage.c:50
M0_INTERNAL void m0_storage_devs_use_directio(struct m0_storage_devs *devs, bool directio)
Definition: storage_dev.c:134
static int cs_be_dom_cfg_zone_pcnt_fill(struct m0_reqh *reqh, struct m0_be_domain_cfg *dom_cfg)
Definition: setup.c:1451
m0_bcount_t rc_be_tx_reg_size_max
Definition: setup.h:287
M0_INTERNAL int m0_net_lnet_ep_addr_net_cmp(const char *addr1, const char *addr2)
Definition: lnet_main.c:941
M0_INTERNAL struct m0_reqh_service_type * m0_reqh_service_type_find(const char *sname)
Definition: reqh_service.c:168
M0_TL_DESCR_DEFINE(cs_buffer_pools, "buffer pools in the motr context", static, struct cs_buffer_pool, cs_bp_linkage, cs_bp_magic, M0_CS_BUFFER_POOL_MAGIC, M0_CS_BUFFER_POOL_HEAD_MAGIC)
M0_INTERNAL void m0_rwlock_init(struct m0_rwlock *lock)
Definition: rwlock.c:32
#define m0_tl_endfor
Definition: tlist.h:700
M0_INTERNAL void m0_reqh_shutdown_wait(struct m0_reqh *reqh)
Definition: reqh.c:647
struct m0_fid fid
Definition: di.c:46
M0_INTERNAL int m0_fi_init(void)
Definition: finject_init.c:40
M0_INTERNAL void m0_motr_ha_disconnect(struct m0_motr_ha *mha)
Definition: ha.c:578
#define M0_NUMBERARG(ch, desc, func)
Definition: getopts.h:187
#define M0_CHECK_EX(cond)
M0_INTERNAL int m0_confc_root_open(struct m0_confc *confc, struct m0_conf_root **root)
Definition: helpers.c:219
return M0_RC(rc)
M0_INTERNAL void m0_cob_tx_credit(struct m0_cob_domain *dom, enum m0_cob_op optype, struct m0_be_tx_credit *accum)
Definition: cob.c:2281
m0_time_t rc_be_tx_group_freeze_timeout_min
Definition: setup.h:289
#define equi(a, b)
Definition: misc.h:297
static int head(struct m0_sm *mach)
Definition: sm.c:468
Definition: sock.c:754
#define M0_BE_TX_CREDIT(nr, size)
Definition: tx_credit.h:94
static void cs_ha_connect(struct m0_motr *cctx)
Definition: setup.c:2347
#define M0_ENTRY(...)
Definition: trace.h:170
struct m0_reqh_context rctx
M0_INTERNAL void m0_be_ut_backend_seg_del(struct m0_be_ut_backend *ut_be, struct m0_be_seg *seg)
Definition: helper.c:483
struct m0_reqh * bec_reqh
Definition: engine.h:84
static void cs_storage_fini(struct cs_stobs *stob)
Definition: setup.c:1102
M0_INTERNAL void m0_sm_group_unlock(struct m0_sm_group *grp)
Definition: sm.c:96
#define CS_MODULE_LEVEL(level)
Definition: setup.c:2918
struct m0_storage_devs i_storage_devs
Definition: instance.h:123
M0_INTERNAL bool m0_reqh_service_is_registered(const char *sname)
Definition: reqh_service.c:514
uint32_t sd_dev_idx
Definition: obj.h:635
#define M0_STRINGARG(ch, desc, func)
Definition: getopts.h:207
int i
Definition: dir.c:1033
void m0_build_info_print(void)
Definition: version.c:66
uint32_t rc_nr_services
Definition: setup.h:252
M0_BOB_DEFINE(extern, &cs_eps_bob, cs_endpoint_and_xprt)
struct m0_be_log_store_cfg lc_store_cfg
Definition: log.h:250
M0_INTERNAL int m0_stob_domain_create(const char *location, const char *str_cfg_init, uint64_t dom_key, const char *str_cfg_create, struct m0_stob_domain **out)
Definition: domain.c:217
#define PRIu64
Definition: types.h:58
static void cs_net_domains_fini(struct m0_motr *cctx)
Definition: setup.c:1306
static int cs_storage_setup(struct m0_motr *cctx)
Definition: setup.c:1582
bool i_storage_is_fake
Definition: instance.h:131
M0_INTERNAL int m0_storage_dev_new(struct m0_storage_devs *devs, uint64_t cid, const char *path, uint64_t size, struct m0_conf_sdev *conf_sdev, bool force, struct m0_storage_dev **dev)
Definition: storage_dev.c:576
void m0_be_ut_backend_cfg_default(struct m0_be_domain_cfg *cfg)
Definition: stubs.c:227
M0_INTERNAL bool m0_reqh_invariant(const struct m0_reqh *reqh)
Definition: reqh.c:136
static int64_t max64(int64_t a, int64_t b)
Definition: arith.h:51
uint32_t rc_recv_queue_min_length
Definition: setup.h:324
static int _args_parse(struct m0_motr *cctx, int argc, char **argv)
Definition: setup.c:2048
#define M0_ERR_INFO(rc, fmt,...)
Definition: trace.h:215
static struct m0_bob_type ndom_bob
Definition: setup.c:135
return M0_ERR(-EOPNOTSUPP)
#define LAMBDA(T,...)
Definition: thread.h:153
m0_bcount_t rc_be_tx_payload_size_max
Definition: setup.h:288
M0_INTERNAL const struct m0_fid M0_MDSERVICE_SLASH_FID
Definition: md_fid.c:63
static const char * stob_file_path_get(yaml_document_t *doc, yaml_node_t *node)
Definition: setup.c:761
Definition: trace.h:482
const char * name
Definition: trace.c:110
static int cs_dtm0_init(struct m0_reqh_context *rctx)
Definition: setup.c:1693
M0_INTERNAL struct m0_confc * m0_reqh2confc(struct m0_reqh *reqh)
Definition: reqh.c:753
static const struct socktype stype[]
Definition: sock.c:1156
static uint32_t cs_dom_tm_min_recv_queue_total(struct m0_reqh_context *rctx, struct m0_net_domain *dom)
Definition: setup.c:677
#define m0_tl_teardown(name, head, obj)
Definition: tlist.h:708
const char * bsc_stob_create_cfg
Definition: domain.h:74
struct m0_fid rt_imeta_pver
Definition: obj.h:403
#define M0_FORMATARG(ch, desc, fmt, ptr)
Definition: getopts.h:218
stob_type
Definition: setup.h:144
M0_INTERNAL void m0_storage_devs_lock(struct m0_storage_devs *devs)
Definition: storage_dev.c:71
m0_bcount_t rc_be_tx_group_payload_size_max
Definition: setup.h:285
static bool stype_is_valid(const char *stype)
Definition: setup.c:251
static int cs_buffer_pool_setup(struct m0_motr *cctx)
Definition: setup.c:705
const struct m0_fid_type cot_ftype
Definition: obj.h:314
M0_INTERNAL int m0_reqh_conf_setup(struct m0_reqh *reqh, struct m0_confc_args *args)
Definition: reqh.c:729
static struct m0_stob * stob
Definition: storage.c:39
#define m0_free0(pptr)
Definition: memory.h:77
struct m0_be_seg * rc_beseg
Definition: setup.h:268
bool i_disable_addb2_storage
Definition: instance.h:133
struct m0_be_tx_credit tgc_size_max
Definition: tx_group.h:61
#define M0_ASSERT(cond)
static struct m0_confc * confc
Definition: file.c:94
const struct m0_net_xprt * nd_xprt
Definition: net.h:396
m0_bcount_t rc_be_seg_size
Definition: setup.h:280
static int cs_stob_file_load(const char *dfile, struct cs_stobs *stob)
Definition: setup.c:778
struct m0_tl rc_eps
Definition: setup.h:255
static int cs_reqh_ctx_validate(struct m0_motr *cctx)
Definition: setup.c:1933
static bool reqh_context_invariant(const struct m0_reqh_context *rctx)
Definition: setup.c:176
bool i_reqh_uses_ad_stob
Definition: instance.h:132
M0_INTERNAL int m0_rpc_net_buffer_pool_setup(struct m0_net_domain *ndom, struct m0_net_buffer_pool *app_pool, uint32_t bufs_nr, uint32_t tm_nr)
Definition: rpc.c:229
union m0_conf_pver::@122 pv_u
static bool reqh_ctx_services_are_valid(const struct m0_reqh_context *rctx)
Definition: setup.c:146
const char * rst_name
Definition: reqh_service.h:447
static struct net_test_cmd_node nodes[NTC_MULTIPLE_NODES]
Definition: commands.c:74
M0_INTERNAL void m0_reqh_service_fini(struct m0_reqh_service *service)
Definition: reqh_service.c:457
bool sf_is_initialised
Definition: setup.h:198
static struct m0_thread t[8]
Definition: service_ut.c:1230
Definition: tlist.h:251
#define bob_of(ptr, type, field, bt)
Definition: bob.h:140
static int cs_conf_setup(struct m0_motr *cctx)
Definition: setup.c:2353
#define m0_streq(a, b)
Definition: string.h:34
M0_INTERNAL struct m0_reqh_context * m0_cs_reqh_context(struct m0_reqh *reqh)
Definition: setup.c:1773
M0_INTERNAL uint32_t m0_rpc_bufs_nr(uint32_t len, uint32_t tms_nr)
Definition: rpc.c:271
struct m0_tl rh_rpc_machines
Definition: reqh.h:135
struct m0_reqh rc_reqh
Definition: setup.h:312
static struct m0_stob_domain * dom
Definition: storage.c:38
M0_INTERNAL bool m0_reqh_service_invariant(const struct m0_reqh_service *svc)
Definition: reqh_service.c:143
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
M0_INTERNAL void m0_module_setup(struct m0_module *module, const char *name, const struct m0_modlev *level, int level_nr, struct m0 *instance)
Definition: module.c:193
m0_bcount_t lsc_size
Definition: log_store.h:171
parser
Definition: queues.py:206
M0_INTERNAL int cs_conf_device_reopen(struct m0_poolmach *pm, struct cs_stobs *stob, uint32_t dev_id)
Definition: conf.c:520
M0_INTERNAL int m0_rpc_machine_init(struct m0_rpc_machine *machine, struct m0_net_domain *net_dom, const char *ep_addr, struct m0_reqh *reqh, struct m0_net_buffer_pool *receive_pool, uint32_t colour, m0_bcount_t msg_size, uint32_t queue_len)
Definition: rpc_machine.c:123
struct m0_be_tx_credit tx_betx_cred
Definition: dtm.h:560
struct m0_net_xprt * m0_net_xprt_default_get(void)
Definition: net.c:151
unsigned long tgc_tx_nr_max
Definition: tx_group.h:57
M0_INTERNAL void m0_pools_service_ctx_destroy(struct m0_pools_common *pc)
Definition: pool.c:1617
static void process_fid_generate_conditional(struct m0_reqh_context *rctx)
Definition: setup.c:2039
static int cmp(const struct m0_ut_suite **s0, const struct m0_ut_suite **s1)
Definition: ut.c:654
M0_INTERNAL int m0_reqh_mdpool_layout_build(struct m0_reqh *reqh)
Definition: reqh.c:145
void * m0_alloc(size_t size)
Definition: memory.c:126
bool rh_oostore
Definition: reqh.h:171
static int cs_endpoint_validate(struct m0_motr *cctx, const char *ep, const char *xprt_name)
Definition: setup.c:305
static const char * progname
Definition: traced.c:65
static int cs_storage_prepare(struct m0_reqh_context *rctx, bool erase)
Definition: setup.c:1319
struct m0_reqh_service_type m0_ss_svc_type
Definition: ss_svc.c:159
M0_INTERNAL void cs_be_fini(struct m0_be_ut_backend *be)
Definition: setup.c:1551
static int m0_rconfc_start_sync(struct m0_rconfc *rconfc)
Definition: rconfc.h:502
M0_INTERNAL int m0_conf_confc_ha_update(struct m0_confc *confc)
Definition: helpers.c:658
#define M0_POST(cond)
static void cs_reqh_stop(struct m0_reqh_context *rctx)
Definition: setup.c:1734
Definition: xcode.h:73
M0_INTERNAL struct m0_confc * m0_motr2confc(struct m0_motr *motr)
Definition: setup.c:191
M0_INTERNAL void m0_dtx_fini(struct m0_dtx *tx)
Definition: dtm.c:134
M0_INTERNAL void m0_rconfc_lock(struct m0_rconfc *rconfc)
Definition: rconfc.c:2841
Definition: reqh.h:94
M0_INTERNAL void m0_ios_net_buffer_pool_size_set(uint32_t buffer_pool_size)
Definition: io_service.c:994
M0_INTERNAL int cs_conf_to_args(struct cs_args *dest, struct m0_conf_root *root)
Definition: conf.c:159
struct m0_sm_group * lo_grp
Definition: locality.h:67
M0_INTERNAL m0_bcount_t m0_net_domain_get_max_buffer_size(struct m0_net_domain *dom)
M0_INTERNAL struct m0_net_domain * m0_cs_net_domain_locate(struct m0_motr *cctx, const char *xprt_name)
Definition: setup.c:466
M0_INTERNAL void m0_reqh_post_storage_fini_svcs_stop(struct m0_reqh *reqh)
Definition: reqh.c:704
const char * rc_be_seg_path
Definition: setup.h:278
M0_INTERNAL void m0_rwlock_write_unlock(struct m0_rwlock *lock)
Definition: rwlock.c:47
M0_INTERNAL void m0_motr_ha_connect(struct m0_motr_ha *mha)
Definition: ha.c:567
struct ping_xprt xprts[1]
Definition: main.c:71
const char * ex_cep
Definition: setup.h:169
M0_INTERNAL void m0_storage_devs_fini(struct m0_storage_devs *devs)
Definition: storage_dev.c:107
const char * lsc_stob_create_cfg
Definition: log_store.h:173
#define M0_CONF_CAST(ptr, type)
Definition: obj.h:780
static bool pver_is_actual(const struct m0_conf_obj *obj)
Definition: setup.c:1385
M0_INTERNAL int m0_reqh_service_setup(struct m0_reqh_service **out, struct m0_reqh_service_type *stype, struct m0_reqh *reqh, struct m0_reqh_context *rctx, const struct m0_fid *fid)
Definition: reqh_service.c:565
M0_INTERNAL int m0_fid_sscanf(const char *s, struct m0_fid *fid)
Definition: fid.c:227
static struct m0_net_buffer_pool * cs_buffer_pool_get(struct m0_motr *cctx, struct m0_net_domain *ndom)
Definition: setup.c:481
Definition: seg.h:66
uint32_t rc_max_rpc_msg_size
Definition: setup.h:332
#define FID_P(f)
Definition: fid.h:77
struct m0_be_domain but_dom
Definition: helper.h:47
static struct m0_bob_type rhctx_bob
Definition: setup.c:121
M0_INTERNAL struct m0_storage_devs * m0_cs_storage_devs_get(void)
Definition: setup.c:1783
M0_INTERNAL void m0_storage_devs_detach_all(struct m0_storage_devs *devs)
Definition: storage_dev.c:743
static int cs_storage_bstore_prepare(const char *stob_path, const char *str_cfg_init, uint64_t dom_key, bool mkfs, struct m0_stob_domain **out)
Definition: setup.c:997
static bool cs_endpoint_is_duplicate(const struct m0_reqh_context *rctx, const struct m0_net_xprt *xprt, const char *ep)
Definition: setup.c:263
bool rc_fis_enabled
Definition: setup.h:344
M0_INTERNAL void m0_rconfc_fini(struct m0_rconfc *rconfc)
Definition: rconfc.c:3009
M0_INTERNAL int m0_storage_devs_init(struct m0_storage_devs *devs, enum m0_storage_dev_type type, struct m0_be_seg *be_seg, struct m0_stob_domain *bstore_dom, struct m0_reqh *reqh)
Definition: storage_dev.c:83
M0_INTERNAL int m0_reqh_state_get(struct m0_reqh *reqh)
Definition: reqh.c:398
M0_INTERNAL void m0_stob_domain_fini(struct m0_stob_domain *dom)
Definition: domain.c:204
struct m0_conf_pver_subtree subtree
Definition: obj.h:537
M0_INTERNAL int m0_conf_device_cid_to_fid(struct m0_confc *confc, uint64_t cid, struct m0_fid *fid)
Definition: helpers.c:100
m0_bcount_t rc_be_tx_reg_nr_max
Definition: setup.h:286
struct m0_dtm0_domain rc_dtm0_domain
Definition: setup.h:270
M0_INTERNAL bool m0_fid_eq(const struct m0_fid *fid0, const struct m0_fid *fid1)
Definition: fid.c:164
struct m0_net_domain * nbp_ndom
Definition: buffer_pool.h:261
static bool service_is_duplicate(const struct m0_reqh_context *rctx, const char *sname)
Definition: setup.c:402
M0_INTERNAL struct m0_conf_obj * m0_conf_diter_result(const struct m0_conf_diter *it)
Definition: diter.c:576
M0_INTERNAL int m0_stob_domain_destroy_location(const char *location)
Definition: domain.c:242
struct m0_be_domain_cfg but_dom_cfg
Definition: helper.h:53
#define m0_conf_diter_init(iter, confc, origin,...)
Definition: diter.h:235
format
Definition: hist.py:128
struct m0_fid rc_fid
Definition: setup.h:338
M0_INTERNAL void m0_reqh_start(struct m0_reqh *reqh)
Definition: reqh.c:711
int m0_cs_init(struct m0_motr *cctx, struct m0_net_xprt **xprts, size_t xprts_nr, FILE *out, bool mkfs)
Definition: setup.c:2999
M0_INTERNAL void m0_rconfc_unlock(struct m0_rconfc *rconfc)
Definition: rconfc.c:2855
M0_INTERNAL int m0_fi_enable_fault_point(const char *str)
Definition: finject_init.c:103
M0_INTERNAL struct m0_reqh_service * m0_reqh_service_find(const struct m0_reqh_service_type *st, const struct m0_reqh *reqh)
Definition: reqh_service.c:538
static bool reqh_context_check(const void *bob)
Definition: setup.c:162
Definition: setup.h:354
uint64_t n
Definition: fops.h:107
struct m0_reqh reqh
Definition: rm_foms.c:48
#define M0_MAGIX_OFFSET(type, field)
Definition: misc.h:356
static uint32_t min32u(uint32_t a, uint32_t b)
Definition: arith.h:56
int m0_net_domain_init(struct m0_net_domain *dom, const struct m0_net_xprt *xprt)
Definition: domain.c:36
char * ep
Definition: sw.h:132
M0_INTERNAL int m0_pools_common_init(struct m0_pools_common *pc, struct m0_rpc_machine *rmach)
Definition: pool.c:1425
M0_INTERNAL struct m0_locality * m0_locality0_get(void)
Definition: locality.c:169
M0_INTERNAL int m0_stob_domain_init(const char *location, const char *str_cfg_init, struct m0_stob_domain **out)
Definition: domain.c:195
struct m0_reqh_context cc_reqh_ctx
Definition: setup.h:361
#define M0_FI_ENABLED(tag)
Definition: finject.h:231
M0_INTERNAL bool m0_tlist_invariant(const struct m0_tl_descr *d, const struct m0_tl *list)
Definition: tlist.c:236
Definition: fid.h:38
struct m0_ha_dispatcher_cfg mhc_dispatcher_cfg
Definition: ha.h:47
M0_INTERNAL int m0_mdstore_create(struct m0_mdstore *md, struct m0_sm_group *grp, struct m0_cob_domain_id *id, struct m0_be_domain *bedom, struct m0_be_seg *db)
Definition: mdstore.c:135
struct m0_confc rc_confc
Definition: rconfc.h:235
const struct m0_reqh_service_type * rs_type
Definition: reqh_service.h:227
struct m0_be_tx tx_betx
Definition: dtm.h:559
static int cs_net_domains_init(struct m0_motr *cctx)
Definition: setup.c:1285
static void cs_stob_types_list(FILE *out)
Definition: setup.c:239
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
static int stob_file_id_get(yaml_document_t *doc, yaml_node_t *node, uint64_t *id)
Definition: setup.c:740
struct m0_motr motr
m0_time_t bec_group_freeze_timeout_min
Definition: engine.h:80
static void cs_reqh_shutdown(struct m0_reqh_context *rctx)
Definition: setup.c:1703
M0_INTERNAL void m0_conf_ha_process_event_post(struct m0_ha *ha, struct m0_ha_link *hl, const struct m0_fid *process_fid, uint64_t pid, enum m0_conf_ha_process_event event, enum m0_conf_ha_process_type type)
Definition: ha.c:45
M0_INTERNAL int m0_pools_service_ctx_create(struct m0_pools_common *pc)
Definition: pool.c:1535
M0_INTERNAL void m0_conf_diter_fini(struct m0_conf_diter *it)
Definition: diter.c:313
M0_INTERNAL void m0_reqh_service_list_print(void)
Definition: reqh_service.c:504
static struct m0_bob_type cs_eps_bob
Definition: setup.c:111
const char * rc_be_log_path
Definition: setup.h:276
uint32_t pa_P
Definition: pdclust.h:115
struct cs_stob_file s_sfile
Definition: setup.h:210
int m_cur
Definition: module.h:160
struct m0_conf_obj sd_obj
Definition: obj.h:616
struct m0_fid * rc_service_fids
Definition: setup.h:249
const char * rc_be_seg0_path
Definition: setup.h:277
m0_bcount_t size
Definition: di.c:39
#define _0C(exp)
Definition: assert.h:311
static struct m0_motr * cs_module2motr(struct m0_module *module)
Definition: setup.c:2511
struct m0_pools_common * rh_pools
Definition: reqh.h:118
M0_INTERNAL void m0_reqh_pre_storage_fini_svcs_stop(struct m0_reqh *reqh)
Definition: reqh.c:681
M0_TL_DEFINE(cs_buffer_pools, static, struct cs_buffer_pool)
Definition: xcode.c:1194
static int cs_reqh_mdpool_layouts_setup(struct m0_motr *cctx)
Definition: setup.c:2393
M0_INTERNAL void m0_rwlock_read_lock(struct m0_rwlock *lock)
Definition: rwlock.c:52
const char * nx_name
Definition: net.h:125
void m0_be_ut_backend_fini(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:242
M0_INTERNAL void m0_rwlock_fini(struct m0_rwlock *lock)
Definition: rwlock.c:37
M0_INTERNAL void m0_reqh_idle_wait_for(struct m0_reqh *reqh, struct m0_reqh_service *service)
Definition: reqh.c:591
M0_INTERNAL void m0_sm_group_lock(struct m0_sm_group *grp)
Definition: sm.c:83
static int cs_storage_init(const char *stob_type, const char *stob_path, uint64_t dom_key, struct cs_stobs *stob, struct m0_be_seg *seg, bool mkfs, bool force, bool disable_direct_io)
Definition: setup.c:1047
struct m0_be_log_cfg bc_log
Definition: domain.h:118
static struct m0_rconfc * motr2rconfc(struct m0_motr *motr)
Definition: setup.c:186
static int cs_daemonize(struct m0_motr *cctx)
Definition: setup.c:2019
M0_INTERNAL void m0_storage_devs_unlock(struct m0_storage_devs *devs)
Definition: storage_dev.c:77
M0_INTERNAL struct m0_confc * m0_confc_from_obj(const struct m0_conf_obj *obj)
Definition: confc.c:592
M0_INTERNAL int m0_dtx_open_sync(struct m0_dtx *tx)
Definition: dtm.c:101
static struct m0_be_seg * seg
Definition: btree.c:40
static struct m0_rconfc * rconfc(struct m0_client *m0c)
Definition: client_init.c:310
struct m0_fid_arr f_path
Definition: onwire.h:284
int m0_cs_start(struct m0_motr *cctx)
Definition: setup.c:2987
M0_INTERNAL void m0_confc_close(struct m0_conf_obj *obj)
Definition: confc.c:921
M0_INTERNAL int m0_ep_and_xprt_extract(struct cs_endpoint_and_xprt *epx, const char *ep)
Definition: setup.c:326
static int be_repair_zone_pcnt_get(struct m0_reqh *reqh, uint32_t *repair_zone_pcnt)
Definition: setup.c:1398
struct m0_rconfc rh_rconfc
Definition: reqh.h:166
M0_INTERNAL int m0_mdstore_destroy(struct m0_mdstore *md, struct m0_sm_group *grp, struct m0_be_domain *bedom)
Definition: mdstore.c:146
struct m0_be_tx_group_cfg bec_group_cfg
Definition: engine.h:71
enum cs_reqh_ctx_states rc_state
Definition: setup.h:261
static int cs_net_domain_init(struct cs_endpoint_and_xprt *ep, struct m0_motr *cctx)
Definition: setup.c:1247
M0_INTERNAL struct m0_be_seg * m0_be_domain_seg_first(const struct m0_be_domain *dom)
Definition: domain.c:486
bool s_ad_disks_init
Definition: setup.h:212
M0_INTERNAL void m0_motr_ha_stop(struct m0_motr_ha *mha)
Definition: ha.c:560
static void reqh_context_services_fini(struct m0_reqh_context *rctx, struct m0_motr *cctx)
Definition: setup.c:1196
M0_INTERNAL int m0_dtm0_log_create(struct m0_sm_group *grp, struct m0_be_domain *bedom, struct m0_be_seg *seg)
Definition: helper.c:60
static struct bulkio_params * bp
Definition: bulkio_ut.c:44
M0_INTERNAL void m0_dtm0_domain_fini(struct m0_dtm0_domain *dod)
Definition: domain.c:203
M0_INTERNAL void m0_rwlock_read_unlock(struct m0_rwlock *lock)
Definition: rwlock.c:57
const struct m0_conf_obj_type M0_CONF_PROCESS_TYPE
Definition: process.c:161
struct cs_stobs rc_stob
Definition: setup.h:264
M0_INTERNAL uint64_t m0_pid(void)
Definition: kthread.c:290
#define out(...)
Definition: gen.c:41
m0_storage_dev_type
Definition: storage_dev.h:65
int type
Definition: dir.c:1031
M0_INTERNAL int m0_pool_versions_setup(struct m0_pools_common *pc)
Definition: pool.c:1640
static const struct m0_bob_type cs_bob_type
Definition: setup.c:138
struct m0_net_xprt * xprt
Definition: module.c:61
bool rc_disable_direct_io
Definition: setup.h:341
struct m0_pools_common cc_pools_common
Definition: setup.h:356
struct m0_mdstore rc_mdstore
Definition: setup.h:304
static int cs_rpc_machine_init(struct m0_motr *cctx, const char *xprt_name, const char *ep, const uint32_t tm_colour, const uint32_t recv_queue_min_length, const uint32_t max_rpc_msg_size, struct m0_reqh *reqh)
Definition: setup.c:510
M0_INTERNAL void m0_pool_versions_destroy(struct m0_pools_common *pc)
Definition: pool.c:1876
M0_INTERNAL bool m0_fid_is_valid(const struct m0_fid *fid)
Definition: fid.c:96
const char * rc_addb_stlocation
Definition: setup.h:234
M0_INTERNAL void m0_motr_ha_fini(struct m0_motr_ha *mha)
Definition: ha.c:537
#define m0_tl_find(name, var, head,...)
Definition: tlist.h:757
M0_INTERNAL void m0_fi_fini(void)
Definition: finject_init.c:47
const char * ca_profile
Definition: helpers.h:34
struct m0_reqh * rs_reqh
Definition: reqh_service.h:259
static struct m0_reqh * motr2reqh(struct m0_motr *motr)
Definition: setup.c:181
M0_INTERNAL void m0_reqh_addb2_fini(struct m0_reqh *reqh)
Definition: reqh.c:383
#define m0_tl_for(name, head, obj)
Definition: tlist.h:695
M0_INTERNAL int m0_cs_dix_setup(struct m0_motr *cctx)
Definition: setup_dix.c:255
void m0_free(void *data)
Definition: memory.c:146
M0_INTERNAL int m0_reqh_be_init(struct m0_reqh *reqh, struct m0_be_seg *seg)
Definition: reqh.c:269
static struct m0_addb2_source * s
Definition: consumer.c:39
static void cs_reqh_ctx_fini(struct m0_reqh_context *rctx)
Definition: setup.c:444
struct m0_be_engine_cfg bc_engine
Definition: domain.h:79
static struct m0_reqh_service * service[REQH_IN_UT_MAX]
Definition: long_lock_ut.c:46
M0_INTERNAL struct m0_motr * m0_cs_ctx_get(struct m0_reqh *reqh)
Definition: setup.c:1778
M0_INTERNAL int cs_conf_services_init(struct m0_motr *cctx)
Definition: conf.c:464
M0_INTERNAL void m0_bob_type_tlist_init(struct m0_bob_type *bt, const struct m0_tl_descr *td)
Definition: bob.c:41
char ** rc_services
Definition: setup.h:246
M0_INTERNAL void m0_reqh_service_ctxs_shutdown_prepare(struct m0_reqh *reqh)
Definition: reqh_service.c:892
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
static void cs_ha_fini(struct m0_motr *cctx)
Definition: setup.c:655
m0_bcount_t rc_be_log_size
Definition: setup.h:281
M0_INTERNAL void m0_ep_and_xprt_fini(struct cs_endpoint_and_xprt *epx)
Definition: setup.c:361
static int cs_reqh_ctx_services_validate(struct m0_motr *cctx)
Definition: setup.c:1982
M0_INTERNAL void m0_module_fini(struct m0_module *module, int level)
Definition: module.c:142
static int cs_storage_devs_init(struct cs_stobs *stob, enum m0_storage_dev_type type, struct m0_be_seg *seg, const char *stob_path, bool force, bool disable_direct_io)
Definition: setup.c:820
static struct m0_be_ut_backend be
Definition: service_ut.c:59
static void cs_motr_init(struct m0_motr *cctx)
Definition: setup.c:1788
static void cs_level_leave(struct m0_module *module)
Definition: setup.c:2753
M0_INTERNAL void m0_cs_gotsignal_reset(void)
Definition: setup.c:2421
#define FID_F
Definition: fid.h:75
Definition: trace.h:478
static bool bad_address(char *addr)
Definition: setup.c:613
M0_INTERNAL int m0_module_init(struct m0_module *module, int level)
Definition: module.c:131
M0_INTERNAL void m0_fid_tassume(struct m0_fid *fid, const struct m0_fid_type *ft)
Definition: fid.c:146
#define M0_IMPOSSIBLE(fmt,...)
m0_bcount_t bec_tx_payload_max
Definition: engine.h:75
M0_INTERNAL void m0_pools_destroy(struct m0_pools_common *pc)
Definition: pool.c:1887
struct m0_module cc_module
Definition: setup.h:446