Motr  M0
cmd.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2015-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_SPIEL
24 #include "lib/trace.h"
25 #include "lib/finject.h" /* M0_FI_ENABLED */
26 
27 #include "conf/obj_ops.h" /* M0_CONF_DIRNEXT, m0_conf_obj_get */
28 #include "conf/preload.h" /* m0_confx_string_free */
29 #include "conf/helpers.h" /* m0_conf_service_name_dup */
30 #include "fid/fid_list.h" /* m0_fid_item */
31 #include "rpc/rpclib.h" /* m0_rpc_post_with_timeout_sync */
32 #include "cm/repreb/trigger_fom.h" /* m0_cm_op */
33 #include "cm/repreb/trigger_fop.h" /* trigger_fop */
34 #include "sns/cm/trigger_fop.h" /* m0_sns_cm_trigger_fop_alloc */
35 #include "dix/cm/trigger_fop.h" /* m0_dix_cm_trigger_fop_alloc */
36 #include "sss/device_fops.h" /* m0_sss_device_fop_create */
37 #include "sss/ss_fops.h"
38 #include "sss/process_fops.h" /* m0_ss_fop_process_rep */
39 #include "spiel/spiel.h"
40 #include "spiel/spiel_internal.h"
41 #include "spiel/cmd_internal.h"
42 
48 M0_TL_DESCR_DEFINE(spiel_string, "list of endpoints",
49  static, struct spiel_string_entry, sse_link, sse_magic,
51 M0_TL_DEFINE(spiel_string, static, struct spiel_string_entry);
52 
53 static void spiel_fop_destroy(struct m0_fop *fop)
54 {
58  m0_free(fop);
59 }
60 
61 static void spiel_rpc_link_destroy(struct m0_rpc_link *rlink)
62 {
63  M0_LOG(M0_DEBUG, "destroying rpc link %p", rlink);
64  if (rlink != NULL) {
65  if (rlink->rlk_connected) {
66  m0_time_t conn_timeout;
67  conn_timeout = m0_time_from_now(SPIEL_CONN_TIMEOUT, 0);
68  m0_rpc_link_disconnect_sync(rlink, conn_timeout);
69  }
70  m0_rpc_link_fini(rlink);
71  m0_free(rlink);
72  }
73 }
74 
75 static bool _filter_svc(const struct m0_conf_obj *obj)
76 {
78 }
79 
80 static bool _filter_controller(const struct m0_conf_obj *obj)
81 {
83 }
84 
85 static int spiel_node_process_endpoint_add(struct m0_spiel_core *spc,
86  struct m0_conf_obj *node,
87  struct m0_tl *list)
88 {
89  struct spiel_string_entry *entry;
90  struct m0_conf_diter it;
91  struct m0_conf_process *p;
92  struct m0_conf_service *svc;
93  int rc;
94 
95  M0_ENTRY("conf_node: %p", &node);
97 
98  rc = m0_conf_diter_init(&it, spc->spc_confc, node,
99  M0_CONF_NODE_PROCESSES_FID,
100  M0_CONF_PROCESS_SERVICES_FID);
101  if (rc != 0)
102  return M0_ERR(rc);
103 
104  while ((rc = m0_conf_diter_next_sync(&it, _filter_svc)) ==
105  M0_CONF_DIRNEXT) {
107  if (svc->cs_type == M0_CST_IOS) {
110  M0_ALLOC_PTR(entry);
111  if (entry == NULL) {
112  rc = M0_ERR(-ENOMEM);
113  break;
114  }
115  entry->sse_string = m0_strdup(p->pc_endpoint);
116  spiel_string_tlink_init_at(entry, list);
117  break;
118  }
119  }
120 
122  return M0_RC(rc);
123 }
124 
129 static int spiel_endpoints_for_device_generic(struct m0_spiel_core *spc,
130  const struct m0_fid *drive,
131  struct m0_tl *out)
132 {
133  struct m0_confc *confc = spc->spc_confc;
134  struct m0_conf_diter it;
135  struct m0_conf_obj *root;
136  struct m0_conf_obj *drive_obj;
137  struct m0_conf_obj *ctrl_obj;
138  struct m0_conf_obj *encl_obj;
139  struct m0_conf_enclosure *encl;
140  struct m0_conf_obj *node_obj;
141  int rc;
142 
143  M0_ENTRY();
144  M0_PRE(drive != NULL);
145  M0_PRE(out != NULL);
146 
147  if (m0_conf_fid_type(drive) != &M0_CONF_DRIVE_TYPE)
148  return M0_ERR(-EINVAL);
149 
151  if (rc != 0)
152  return M0_ERR(rc);
153 
155  M0_CONF_ROOT_SITES_FID,
156  M0_CONF_SITE_RACKS_FID,
157  M0_CONF_RACK_ENCLS_FID,
158  M0_CONF_ENCLOSURE_CTRLS_FID);
159  if (rc != 0) {
161  return M0_ERR(rc);
162  }
163 
165  M0_CONF_DIRNEXT) {
166  ctrl_obj = m0_conf_diter_result(&it);
167  rc = m0_confc_open_sync(&drive_obj, ctrl_obj,
168  M0_CONF_CONTROLLER_DRIVES_FID, *drive);
169 
170  if (rc == 0) {
171  encl_obj = m0_conf_obj_grandparent(ctrl_obj);
172  encl = M0_CONF_CAST(encl_obj, m0_conf_enclosure);
174  &encl->ce_node->cn_obj.co_id,
175  &node_obj);
176  if (rc == 0) {
177  spiel_node_process_endpoint_add(spc, node_obj,
178  out);
179  m0_confc_close(node_obj);
180  }
181  m0_confc_close(drive_obj);
182  }
183  }
184 
187 
188  return M0_RC(rc);
189 }
190 
192  const char *remote_ep,
193  struct m0_fop *cmd_fop,
195  struct m0_rpc_link **rlink)
196 {
197  struct m0_rpc_link *rpc_link;
198  m0_time_t conn_timeout;
199  int rc;
200 
201  M0_ENTRY("lep=%s ep=%s", m0_rpc_machine_ep(rmachine), remote_ep);
202 
203  M0_PRE(rmachine != NULL);
204  M0_PRE(remote_ep != NULL);
205  M0_PRE(cmd_fop != NULL);
206 
207  /* RPC link structure is too big to allocate it on stack */
208  M0_ALLOC_PTR(rpc_link);
209  if (rpc_link == NULL)
210  return M0_ERR(-ENOMEM);
211 
212  M0_LOG(M0_DEBUG, "initializing rpc link %p", rlink);
213  rc = m0_rpc_link_init(rpc_link, rmachine, NULL, remote_ep,
215  if (rc == 0) {
216  conn_timeout = m0_time_from_now(SPIEL_CONN_TIMEOUT, 0);
217  if (M0_FI_ENABLED("timeout"))
219  rc = m0_rpc_link_connect_sync(rpc_link, conn_timeout);
220 
221  if (rc == 0) {
222  *rlink = rpc_link;
224  &rpc_link->rlk_sess,
225  NULL,
227  timeout);
228  } else {
229  m0_rpc_link_fini(rpc_link);
230  m0_free(rpc_link);
231  }
232  }
233 
234  return M0_RC(rc);
235 }
236 
259  const struct m0_fid *obj_fid,
260  bool (*filter)(const struct m0_conf_obj *obj),
261  uint32_t nr_lvls,
262  const struct m0_fid *path,
263  struct m0_conf_obj **conf_obj)
264 {
265  int rc;
266  struct m0_conf_obj *root_obj = NULL;
267  struct m0_conf_obj *tmp;
268  struct m0_conf_diter it;
269 
270  M0_ENTRY("obj_fid="FID_F, FID_P(obj_fid));
271 
272  M0_PRE(confc != NULL);
273  M0_PRE(obj_fid != NULL);
274  M0_PRE(path != NULL);
275  M0_PRE(nr_lvls > 0);
276  M0_PRE(m0_fid_eq(&path[0], &M0_CONF_ROOT_NODES_FID) ||
277  m0_fid_eq(&path[0], &M0_CONF_ROOT_POOLS_FID));
278  M0_PRE(conf_obj != NULL);
279 
280  *conf_obj = NULL;
281 
282  rc = m0_confc_open_sync(&root_obj, confc->cc_root, M0_FID0);
283  if (rc != 0)
284  return M0_ERR(rc);
285 
286  rc = m0_conf__diter_init(&it, confc, root_obj, nr_lvls, path);
287 
288  if (rc != 0) {
289  m0_confc_close(root_obj);
290  return M0_ERR(rc);
291  }
292 
294  tmp = m0_conf_diter_result(&it);
295 
296  if (m0_fid_eq(&tmp->co_id, obj_fid)) {
297  *conf_obj = tmp;
298  /* Pin object to protect it from removal */
299  m0_conf_obj_get_lock(*conf_obj);
300  rc = 0;
301  break;
302  }
303  }
304 
306  m0_confc_close(root_obj);
307 
308  if (*conf_obj == NULL && rc == 0)
309  rc = M0_ERR(-ENOENT);
310 
311  M0_POST(ergo(rc == 0, (*conf_obj)->co_nrefs > 0));
312  return M0_RC(rc);
313 }
314 
321  void *ctx,
322  bool (*iter_cb)(const struct m0_conf_obj
323  *item, void *ctx),
324  uint32_t nr_lvls,
325  const struct m0_fid *path)
326 {
327  int rc;
328  bool loop;
329  struct m0_conf_obj *root_obj = NULL;
330  struct m0_conf_obj *obj;
331  struct m0_conf_diter it;
332 
333  M0_ENTRY();
334 
335  M0_PRE(confc != NULL);
336  M0_PRE(path != NULL);
337  M0_PRE(nr_lvls > 0);
338  M0_PRE(m0_fid_eq(&path[0], &M0_CONF_ROOT_NODES_FID));
339 
340  rc = m0_confc_open_sync(&root_obj, confc->cc_root, M0_FID0);
341  if (rc != 0)
342  return M0_ERR(rc);
343 
344  rc = m0_conf__diter_init(&it, confc, root_obj, nr_lvls, path);
345 
346  if (rc != 0) {
347  m0_confc_close(root_obj);
348  return M0_ERR(rc);
349  }
350 
351  loop = true;
352  while (loop &&
355  /* Pin obj to protect it from removal while being in use */
357  loop = iter_cb(obj, ctx);
361  }
362 
364  m0_confc_close(root_obj);
365 
366  return M0_RC(rc);
367 }
368 
369 /****************************************************/
370 /* Services */
371 /****************************************************/
372 
376 static int spiel_ss_ep_for_svc(const struct m0_conf_service *s,
377  char **ss_ep)
378 {
379  struct m0_conf_process *p;
380 
381  M0_PRE(s != NULL);
382  M0_PRE(ss_ep != NULL);
383 
384  M0_ENTRY();
385 
386  /* m0_conf_process::pc_services dir is the parent for the service */
388  M0_ASSERT(!m0_conf_obj_is_stub(&p->pc_obj));
389  /* All services within a process share the same endpoint. */
390  *ss_ep = m0_strdup(p->pc_endpoint);
391  return M0_RC(*ss_ep == NULL ? -ENOENT : 0);
392 }
393 
394 static int spiel_svc_conf_obj_find(struct m0_spiel_core *spc,
395  const struct m0_fid *svc,
396  struct m0_conf_service **out)
397 {
398  struct m0_conf_obj *obj;
399  int rc;
400 
401  rc = SPIEL_CONF_OBJ_FIND(spc->spc_confc, svc, &obj, _filter_svc,
402  M0_CONF_ROOT_NODES_FID,
403  M0_CONF_NODE_PROCESSES_FID,
404  M0_CONF_PROCESS_SERVICES_FID);
405  if (rc == 0)
407  return M0_RC(rc);
408 }
409 
410 static int spiel_svc_fop_fill(struct m0_fop *fop,
411  struct m0_conf_service *svc,
412  uint32_t cmd)
413 {
414  struct m0_sss_req *ss_fop = m0_fop_data(fop);
415  char *name;
416 
417  ss_fop->ss_cmd = cmd;
418  ss_fop->ss_id = svc->cs_obj.co_id;
419 
421  if (name == NULL)
422  return M0_ERR(-ENOMEM);
423  m0_buf_init(&ss_fop->ss_name, name, strlen(name));
424 
425  /* TODO: Check what parameters are used by which service types
426  * and fill ss_fop->ss_param appropriately */
427 
428  return 0;
429 }
430 
431 static int spiel_svc_fop_fill_and_send(struct m0_spiel_core *spc,
432  struct m0_fop *fop,
433  const struct m0_fid *svc_fid,
434  uint32_t cmd,
435  struct m0_rpc_link **rlink)
436 {
437  int rc;
438  struct m0_conf_service *svc;
439  char *ss_ep = NULL;
440 
441  M0_ENTRY();
446  M0_PRE(spc != NULL);
447  rc = spiel_svc_conf_obj_find(spc, svc_fid, &svc);
448  if (rc != 0)
449  return M0_ERR(rc);
450 
451  rc = spiel_svc_fop_fill(fop, svc, cmd) ?:
452  spiel_ss_ep_for_svc(svc, &ss_ep);
453  if (rc == 0) {
454  rc = spiel_cmd_send(spc->spc_rmachine, ss_ep, fop,
455  M0_TIME_NEVER, rlink);
456  m0_free(ss_ep);
457  }
458 
459  m0_confc_close(&svc->cs_obj);
460  return M0_RC(rc);
461 }
462 
464 {
466 }
467 
468 static struct m0_sss_rep *spiel_sss_reply_data(struct m0_fop *fop)
469 {
470  struct m0_rpc_item *item = fop->f_item.ri_reply;
472 
473  return (struct m0_sss_rep *)m0_fop_data(rep_fop);
474 }
475 
476 static int spiel_svc_generic_handler(struct m0_spiel_core *spc,
477  const struct m0_fid *svc_fid,
478  enum m0_sss_req_cmd cmd,
479  int *status)
480 {
481  int rc;
482  struct m0_fop *fop;
483  struct m0_rpc_link *rlink = NULL;
484 
485  M0_ENTRY();
486 
487  if (m0_conf_fid_type(svc_fid) != &M0_CONF_SERVICE_TYPE)
488  return M0_ERR(-EINVAL);
489 
490  fop = spiel_svc_fop_alloc(spc->spc_rmachine);
491 
492  if (fop == NULL)
493  return M0_ERR(-ENOMEM);
494 
495  rc = spiel_svc_fop_fill_and_send(spc, fop, svc_fid, cmd, &rlink) ?:
497 
498  if (rc == 0 && status != NULL)
499  *status = spiel_sss_reply_data(fop)->ssr_state;
500 
502  spiel_rpc_link_destroy(rlink);
503 
504  return M0_RC(rc);
505 }
506 
507 int m0_spiel_service_init(struct m0_spiel *spl, const struct m0_fid *svc_fid)
508 {
509  M0_ENTRY("spl %p svc_fid "FID_F, spl, FID_P(svc_fid));
510 
511  return M0_RC(spiel_svc_generic_handler(&spl->spl_core, svc_fid,
513 }
514 M0_EXPORTED(m0_spiel_service_init);
515 
516 int m0_spiel_service_start(struct m0_spiel *spl, const struct m0_fid *svc_fid)
517 {
518  M0_ENTRY("spl %p svc_fid "FID_F, spl, FID_P(svc_fid));
519 
520  return M0_RC(spiel_svc_generic_handler(&spl->spl_core, svc_fid,
522 }
523 M0_EXPORTED(m0_spiel_service_start);
524 
525 int m0_spiel_service_stop(struct m0_spiel *spl, const struct m0_fid *svc_fid)
526 {
527  M0_ENTRY("spl %p svc_fid "FID_F, spl, FID_P(svc_fid));
529  svc_fid))
530  return M0_ERR(-EPERM);
531 
532  return M0_RC(spiel_svc_generic_handler(&spl->spl_core, svc_fid,
534 }
535 M0_EXPORTED(m0_spiel_service_stop);
536 
537 int m0_spiel_service_health(struct m0_spiel *spl, const struct m0_fid *svc_fid)
538 {
539  M0_ENTRY("spl %p svc_fid "FID_F, spl, FID_P(svc_fid));
540 
541  return M0_RC(spiel_svc_generic_handler(&spl->spl_core, svc_fid,
543 }
544 M0_EXPORTED(m0_spiel_service_health);
545 
547  const struct m0_fid *svc_fid)
548 {
549  M0_ENTRY("spl %p svc_fid "FID_F, spl, FID_P(svc_fid));
550 
551  return M0_RC(spiel_svc_generic_handler(&spl->spl_core, svc_fid,
553 }
554 M0_EXPORTED(m0_spiel_service_quiesce);
555 
556 int m0_spiel_service_status(struct m0_spiel *spl, const struct m0_fid *svc_fid,
557  int *status)
558 {
559  M0_ENTRY("spl %p svc_fid "FID_F, spl, FID_P(svc_fid));
560 
561  return M0_RC(spiel_svc_generic_handler(&spl->spl_core, svc_fid,
562  M0_SERVICE_STATUS, status));
563 }
564 M0_EXPORTED(m0_spiel_service_status);
565 
566 
567 /****************************************************/
568 /* Devices */
569 /****************************************************/
570 
571 static int spiel_device_command_fop_send(struct m0_spiel_core *spc,
572  const char *endpoint,
573  const struct m0_fid *dev_fid,
574  int cmd,
575  uint32_t *ha_state)
576 {
577  struct m0_fop *fop;
578  struct m0_sss_device_fop_rep *rep;
579  int rc;
580  struct m0_rpc_link *rlink = NULL;
581 
582  fop = m0_sss_device_fop_create(spc->spc_rmachine, cmd, dev_fid);
583  if (fop == NULL)
584  return M0_ERR(-ENOMEM);
585 
586  rc = spiel_cmd_send(spc->spc_rmachine, endpoint, fop,
587  cmd == M0_DEVICE_FORMAT ?
589  M0_TIME_NEVER, &rlink);
590  if (rc == 0) {
593  rc = rep->ssdp_rc;
594  if (ha_state != NULL)
595  *ha_state = rep->ssdp_ha_state;
596  }
598  spiel_rpc_link_destroy(rlink);
599 
600  return M0_RC(rc);
601 }
602 
606 static int spiel_device_command_send(struct m0_spiel_core *spc,
607  const struct m0_fid *drive,
608  enum m0_sss_device_req_cmd cmd,
609  uint32_t *ha_state)
610 {
611  struct m0_tl endpoints;
612  struct spiel_string_entry *ep;
613  int rc;
614 
615  M0_ENTRY();
616 
617  if (m0_conf_fid_type(drive) != &M0_CONF_DRIVE_TYPE)
618  return M0_ERR_INFO(-EINVAL, "drive="FID_F, FID_P(drive));
619 
620  spiel_string_tlist_init(&endpoints);
621 
622  rc = spiel_endpoints_for_device_generic(spc, drive, &endpoints);
623  if (rc == 0 && spiel_string_tlist_is_empty(&endpoints))
624  rc = M0_ERR_INFO(-ENOENT, "No IOS endpoints found for drive "
625  FID_F, FID_P(drive));
626 
627  if (rc == 0)
628  m0_tl_teardown(spiel_string, &endpoints, ep) {
629  rc = rc ?:
630  spiel_device_command_fop_send(spc, ep->sse_string,
631  drive, cmd, ha_state);
632  m0_free((char *)ep->sse_string);
633  m0_free(ep);
634  }
635 
636  spiel_string_tlist_fini(&endpoints);
637 
638  return M0_RC(rc);
639 }
640 
641 int m0_spiel_device_attach(struct m0_spiel *spl, const struct m0_fid *dev_fid)
642 {
643  return m0_spiel_device_attach_state(spl, dev_fid, NULL);
644 }
645 M0_EXPORTED(m0_spiel_device_attach);
646 
648  const struct m0_fid *dev_fid,
649  uint32_t *ha_state)
650 {
651  M0_ENTRY("spl %p svc_fid "FID_F, spl, FID_P(dev_fid));
652 
653  return M0_RC(spiel_device_command_send(&spl->spl_core, dev_fid,
654  M0_DEVICE_ATTACH, ha_state));
655 }
656 M0_EXPORTED(m0_spiel_device_attach_state);
657 
658 int m0_spiel_device_detach(struct m0_spiel *spl, const struct m0_fid *dev_fid)
659 {
660  M0_ENTRY("spl %p svc_fid "FID_F, spl, FID_P(dev_fid));
661 
662  return M0_RC(spiel_device_command_send(&spl->spl_core, dev_fid,
664 }
665 M0_EXPORTED(m0_spiel_device_detach);
666 
667 int m0_spiel_device_format(struct m0_spiel *spl, const struct m0_fid *dev_fid)
668 {
669  M0_ENTRY("spl %p svc_fid "FID_F, spl, FID_P(dev_fid));
670 
671  return M0_RC(spiel_device_command_send(&spl->spl_core, dev_fid,
673 }
674 M0_EXPORTED(m0_spiel_device_format);
675 
676 /****************************************************/
677 /* Processes */
678 /****************************************************/
679 static bool _filter_proc(const struct m0_conf_obj *obj)
680 {
682 }
683 
684 static int spiel_proc_conf_obj_find(struct m0_spiel_core *spc,
685  const struct m0_fid *proc,
686  struct m0_conf_process **out)
687 {
688  struct m0_conf_obj *obj;
689  int rc;
690 
691  rc = SPIEL_CONF_OBJ_FIND(spc->spc_confc, proc, &obj, _filter_proc,
692  M0_CONF_ROOT_NODES_FID,
693  M0_CONF_NODE_PROCESSES_FID);
694  if (rc == 0)
696  return M0_RC(rc);
697 }
698 
699 static int spiel_process_command_send(struct m0_spiel_core *spc,
700  const struct m0_fid *proc_fid,
701  struct m0_fop *fop,
702  struct m0_rpc_link **rlink)
703 {
704  struct m0_conf_process *process;
705  int rc;
706 
707  M0_ENTRY();
708 
709  M0_PRE(spc != NULL);
710  M0_PRE(proc_fid != NULL);
711  M0_PRE(fop != NULL);
713  M0_PRE(spc != NULL);
714 
715  rc = spiel_proc_conf_obj_find(spc, proc_fid, &process);
716  if (rc != 0)
717  return M0_ERR(rc);
718 
719  m0_confc_close(&process->pc_obj);
720 
721  rc = spiel_cmd_send(spc->spc_rmachine, process->pc_endpoint, fop,
722  M0_TIME_NEVER, rlink);
723  if (rc != 0)
725  return M0_RC(rc);
726 }
727 
729 {
731 }
732 
736 static int spiel_process_command_execute(struct m0_spiel_core *spc,
737  const struct m0_fid *proc_fid,
738  int cmd,
739  const struct m0_buf *param,
740  struct m0_ss_process_rep *ssp_rep)
741 {
742  struct m0_fop *fop;
743  struct m0_ss_process_req *req;
744  int rc;
745  struct m0_rpc_link *rlink = NULL;
746 
747  M0_ENTRY();
748 
749  M0_PRE(spc != NULL);
750  M0_PRE(proc_fid != NULL);
751 
753  return M0_ERR(-EINVAL);
754  fop = m0_ss_process_fop_create(spc->spc_rmachine, cmd, proc_fid);
755  if (fop == NULL)
756  return M0_ERR(-ENOMEM);
758  if (param != NULL)
759  req->ssp_param = *param;
760  rc = spiel_process_command_send(spc, proc_fid, fop, &rlink);
761  req->ssp_param = M0_BUF_INIT0; /* Clean param before destruction. */
762  if (rc == 0) {
764  if (ssp_rep != NULL)
765  *ssp_rep = *spiel_process_reply_data(fop);
766  }
768  spiel_rpc_link_destroy(rlink);
769 
770  return M0_RC(rc);
771 }
772 
773 static int spiel_process_command(struct m0_spiel *spl,
774  const struct m0_fid *proc_fid,
775  int cmd)
776 {
778  cmd, NULL, NULL);
779 }
780 
781 int m0_spiel_process_stop(struct m0_spiel *spl, const struct m0_fid *proc_fid)
782 {
783  M0_ENTRY();
785 }
786 M0_EXPORTED(m0_spiel_process_stop);
787 
789  const struct m0_fid *proc_fid)
790 {
791  M0_ENTRY();
793 }
794 M0_EXPORTED(m0_spiel_process_reconfig);
795 
796 static int spiel_process__health(struct m0_spiel_core *spc,
797  const struct m0_fid *proc_fid)
798 {
799  struct m0_ss_process_rep ssp_rep = { 0 };
800  int rc;
801  int health;
802 
803  M0_ENTRY();
804 
805  health = M0_HEALTH_UNKNOWN;
807  NULL, &ssp_rep);
808  if (rc == 0) {
809  health = ssp_rep.sspr_health;
810  }
811  return rc < 0 ? M0_ERR(rc) : M0_RC(health);
812 }
813 
815  const struct m0_fid *proc_fid)
816 {
818 }
819 M0_EXPORTED(m0_spiel_process_health);
820 
822  const struct m0_fid *proc_fid)
823 {
824  M0_ENTRY();
826 }
827 M0_EXPORTED(m0_spiel_process_quiesce);
828 
829 static int spiel_running_svcs_list_fill(struct m0_bufs *bufs,
830  struct m0_spiel_running_svc **svcs)
831 {
832  struct m0_ss_process_svc_item *src;
833  struct m0_spiel_running_svc *services;
834  int i;
835 
836  M0_ENTRY();
837 
838  M0_ALLOC_ARR(services, bufs->ab_count);
839  if (services == NULL)
840  return M0_ERR(-ENOMEM);
841  for(i = 0; i < bufs->ab_count; ++i) {
842  src = (struct m0_ss_process_svc_item *)bufs->ab_elems[i].b_addr;
843  services[i].spls_fid = src->ssps_fid;
844  services[i].spls_name = m0_strdup(src->ssps_name);
845  if (services[i].spls_name == NULL)
846  goto err;
847  }
848  *svcs = services;
849 
850  return M0_RC(bufs->ab_count);
851 err:
852  for(i = 0; i < bufs->ab_count; ++i)
853  m0_free(services[i].spls_name);
854  m0_free(services);
855  return M0_ERR(-ENOMEM);
856 }
857 
859  const struct m0_fid *proc_fid,
860  struct m0_spiel_running_svc **services)
861 {
862  struct m0_fop *fop;
864  int rc;
865  struct m0_rpc_link *rlink = NULL;
866 
867  M0_ENTRY();
868 
870  return M0_ERR(-EINVAL);
871 
874  if (fop == NULL)
875  return M0_ERR(-ENOMEM);
877  if (rc == 0) {
880  rc = rep->sspr_rc;
881  if (rc == 0)
882  rc = spiel_running_svcs_list_fill(&rep->sspr_services,
883  services);
884  }
886  spiel_rpc_link_destroy(rlink);
887 
888  return M0_RC(rc);
889 }
890 M0_EXPORTED(m0_spiel_process_list_services);
891 
893  const struct m0_fid *proc_fid,
894  const char *libname)
895 {
896  const struct m0_buf param = M0_BUF_INIT_CONST(strlen(libname) + 1,
897  libname);
898  M0_ENTRY(); /* The terminating NUL is part of param. */
901  &param, NULL));
902 }
903 M0_EXPORTED(m0_spiel_process_lib_load);
904 
905 /****************************************************/
906 /* Pools */
907 /****************************************************/
908 
909 static int spiel_stats_item_add(struct m0_tl *tl, const struct m0_fid *fid)
910 {
911  struct m0_fid_item *si;
912 
913  M0_ALLOC_PTR(si);
914  if (si == NULL)
915  return M0_ERR(-ENOMEM);
916  si->i_fid = *fid;
917  m0_fids_tlink_init_at(si, tl);
918  return M0_RC(0);
919 }
920 
921 
922 static bool _filter_pool(const struct m0_conf_obj *obj)
923 {
924  M0_LOG(M0_DEBUG, FID_F, FID_P(&obj->co_id));
926 }
927 
928 /* Spiel SNS/DIX repair/re-balance context per service. */
929 struct spiel_repreb {
931  /* RPC link for the corresponding service. */
934  struct m0_fop *sr_fop;
935  int sr_rc;
937 };
938 
940  const char *remote_ep,
941  struct spiel_repreb *repreb)
942 {
943  struct m0_rpc_link *rlink = &repreb->sr_rlink;
944  m0_time_t conn_timeout;
945  int rc;
946  struct m0_fop *fop;
947  struct m0_rpc_item *item;
948 
949  M0_ENTRY("lep=%s ep=%s", m0_rpc_machine_ep(rmachine), remote_ep);
950 
951  M0_PRE(rmachine != NULL);
952  M0_PRE(remote_ep != NULL);
953  M0_PRE(repreb != NULL);
954 
955  fop = repreb->sr_fop;
956  rc = m0_rpc_link_init(rlink, rmachine, NULL, remote_ep,
958  if (rc == 0) {
959  conn_timeout = m0_time_from_now(SPIEL_CONN_TIMEOUT, 0);
960  rc = m0_rpc_link_connect_sync(rlink, conn_timeout);
961  if (rc != 0) {
962  m0_rpc_link_fini(rlink);
963  return M0_RC(rc);
964  }
965  item = &fop->f_item;
966  item->ri_ops = NULL;
967  item->ri_session = &rlink->rlk_sess;
970  m0_fop_get(fop);
971  rc = m0_rpc_post(item);
973  }
974  repreb->sr_is_connected = true;
975  return M0_RC(rc);
976 }
977 
978 static int spiel_repreb_fop_fill_and_send(struct m0_spiel_core *spc,
979  struct m0_fop *fop,
980  enum m0_cm_op op,
981  struct spiel_repreb *repreb)
982 {
983  struct trigger_fop *treq = m0_fop_data(fop);
984  struct m0_conf_service *svc = repreb->sr_service;
985  struct m0_conf_process *p = M0_CONF_CAST(
986  m0_conf_obj_grandparent(&svc->cs_obj),
988 
989  M0_ENTRY("fop %p conf_service %p", fop, svc);
990  treq->op = op;
991  repreb->sr_fop = fop;
992  repreb->sr_is_connected = false;
993  return M0_RC(spiel_repreb_cmd_send(spc->spc_rmachine, p->pc_endpoint,
994  repreb));
995 }
996 
999  int pl_rc;
1000  struct m0_spiel_core *pl_spc;
1004 };
1005 
1007  struct m0_conf_obj *obj_diskv)
1008 {
1009  struct m0_conf_objv *diskv;
1010  struct m0_conf_obj *obj_disk;
1011  struct m0_conf_drive *disk;
1012  int rc;
1013 
1014  diskv = M0_CONF_CAST(obj_diskv, m0_conf_objv);
1015  if (diskv == NULL)
1016  return M0_ERR(-ENOENT);
1018  return -EINVAL; /* rackv, ctrlv objectv's are ignored. */
1019 
1020  rc = m0_confc_open_by_fid_sync(ctx->pl_spc->spc_confc,
1021  &diskv->cv_real->co_id, &obj_disk);
1022  if (rc != 0)
1023  return M0_RC(rc);
1024 
1025  disk = M0_CONF_CAST(obj_disk, m0_conf_drive);
1026  if (disk->ck_sdev != NULL)
1027  rc = spiel_stats_item_add(&ctx->pl_sdevs_fid,
1028  &disk->ck_sdev->sd_obj.co_id);
1029 
1030  m0_confc_close(obj_disk);
1031  return M0_RC(rc);
1032 }
1033 
1034 static bool _filter_sdev(const struct m0_conf_obj *obj)
1035 {
1037 }
1038 
1040  const struct m0_conf_obj *service)
1041 {
1042  struct m0_conf_diter it;
1043  struct m0_conf_obj *obj;
1044  int rc;
1045  bool found = false;
1046 
1047  rc = m0_conf_diter_init(&it, ctx->pl_spc->spc_confc,
1048  (struct m0_conf_obj*)service,
1049  M0_CONF_SERVICE_SDEVS_FID);
1050 
1051  if (rc != 0)
1052  return false;
1053 
1055  == M0_CONF_DIRNEXT && !found) {
1057  if (m0_tl_find(m0_fids, si, &ctx->pl_sdevs_fid,
1058  m0_fid_eq(&si->i_fid, &obj->co_id)) != NULL)
1059  found = true;
1060  }
1062  return found;
1063 }
1064 
1066  struct m0_spiel_core *spc,
1067  enum m0_repreb_type type)
1068 {
1069  M0_SET0(ctx);
1070  ctx->pl_spc = spc;
1071  ctx->pl_service_type = type;
1072  m0_fids_tlist_init(&ctx->pl_sdevs_fid);
1073  m0_fids_tlist_init(&ctx->pl_services_fid);
1074  M0_POST(m0_fids_tlist_invariant(&ctx->pl_sdevs_fid));
1075  M0_POST(m0_fids_tlist_invariant(&ctx->pl_services_fid));
1076 }
1077 
1079 {
1080  struct m0_fid_item *si;
1081 
1082  if (!m0_fids_tlist_is_empty(&ctx->pl_sdevs_fid))
1083  m0_tl_teardown(m0_fids, &ctx->pl_sdevs_fid, si) {
1084  m0_free(si);
1085  }
1086  m0_fids_tlist_fini(&ctx->pl_sdevs_fid);
1087 
1088  if (!m0_fids_tlist_is_empty(&ctx->pl_services_fid))
1089  m0_tl_teardown(m0_fids, &ctx->pl_services_fid, si) {
1090  m0_free(si);
1091  }
1092  m0_fids_tlist_fini(&ctx->pl_services_fid);
1093 }
1094 
1095 static void spiel__add_item(struct _pool_cmd_ctx *pool_ctx,
1096  const struct m0_conf_obj *item,
1097  struct m0_conf_service *service,
1099 {
1100  if (service->cs_type == type &&
1102  pool_ctx->pl_rc = spiel_stats_item_add(
1103  &pool_ctx->pl_services_fid,
1104  &item->co_id);
1105 }
1106 static bool spiel__pool_service_select(const struct m0_conf_obj *item,
1107  void *ctx)
1108 {
1109  struct _pool_cmd_ctx *pool_ctx = ctx;
1110  struct m0_conf_service *service;
1111 
1112  /* continue iterating only when no issue occurred previously */
1113  if (pool_ctx->pl_rc != 0)
1114  return false;
1115  /* skip all but service objects */
1117  return true;
1118 
1120  if (pool_ctx->pl_service_type == M0_REPREB_TYPE_SNS)
1121  spiel__add_item(pool_ctx, item, service, M0_CST_IOS);
1122  else if (pool_ctx->pl_service_type == M0_REPREB_TYPE_DIX)
1123  spiel__add_item(pool_ctx, item, service, M0_CST_CAS);
1124  return true;
1125 }
1126 
1128  const enum m0_cm_op cmd,
1129  struct spiel_repreb *repreb)
1130 {
1131  struct m0_fop *fop;
1132  int rc;
1133 
1134  M0_PRE(repreb != NULL);
1135  if (ctx->pl_service_type == M0_REPREB_TYPE_SNS)
1136  rc = m0_sns_cm_trigger_fop_alloc(ctx->pl_spc->spc_rmachine,
1137  cmd, &fop);
1138  else
1139  rc = m0_dix_cm_trigger_fop_alloc(ctx->pl_spc->spc_rmachine,
1140  cmd, &fop);
1141  if (rc != 0)
1142  return M0_ERR(rc);
1143  return M0_RC(spiel_repreb_fop_fill_and_send(ctx->pl_spc, fop, cmd,
1144  repreb));
1145 }
1146 
1148  const enum m0_cm_op cmd,
1149  struct spiel_repreb *repreb)
1150 {
1151  int rc;
1152  struct m0_fop *fop;
1153  struct m0_rpc_item *item;
1154  struct m0_spiel_repreb_status *status;
1155  struct m0_status_rep_fop *reply;
1156  m0_time_t conn_timeout;
1157 
1158  M0_PRE(repreb != NULL);
1159 
1160  status = &repreb->sr_status;
1161  fop = repreb->sr_fop;
1162  M0_ASSERT(ergo(repreb->sr_is_connected, fop != NULL));
1163  item = &fop->f_item;
1166 
1167  if (M0_IN(cmd, (CM_OP_REPAIR_STATUS, CM_OP_REBALANCE_STATUS))) {
1168  status->srs_fid = repreb->sr_service->cs_obj.co_id;
1169  if (rc == 0) {
1171  status->srs_progress = reply->ssr_progress;
1172  status->srs_state = reply->ssr_state;
1173  } else {
1174  status->srs_state = rc;
1175  }
1176  }
1178  if (repreb->sr_is_connected) {
1179  M0_ASSERT(repreb->sr_rlink.rlk_connected);
1180  conn_timeout = m0_time_from_now(SPIEL_CONN_TIMEOUT, 0);
1181  m0_rpc_link_disconnect_sync(&repreb->sr_rlink, conn_timeout);
1182  m0_rpc_link_fini(&repreb->sr_rlink);
1183  }
1184 
1185  return M0_RC(rc);
1186 }
1187 
1188 static bool _filter_objv(const struct m0_conf_obj *obj)
1189 {
1190  M0_LOG(M0_DEBUG, FID_F, FID_P(&obj->co_id));
1192 }
1193 
1195  const struct m0_fid *pool_fid)
1196 {
1197  struct m0_confc *confc = ctx->pl_spc->spc_confc;
1198  struct m0_conf_obj *pool_obj = NULL;
1199  struct m0_conf_obj *obj;
1200  struct m0_conf_diter it;
1201  int rc;
1202 
1203  M0_ENTRY(FID_F, FID_P(pool_fid));
1204 
1205  rc = SPIEL_CONF_OBJ_FIND(confc, pool_fid, &pool_obj, _filter_pool,
1206  M0_CONF_ROOT_POOLS_FID) ?:
1207  m0_conf_diter_init(&it, confc, pool_obj,
1208  M0_CONF_POOL_PVERS_FID,
1209  M0_CONF_PVER_SITEVS_FID,
1210  M0_CONF_SITEV_RACKVS_FID,
1211  M0_CONF_RACKV_ENCLVS_FID,
1212  M0_CONF_ENCLV_CTRLVS_FID,
1213  M0_CONF_CTRLV_DRIVEVS_FID);
1214  if (rc != 0)
1215  goto leave;
1216 
1218  == M0_CONF_DIRNEXT) {
1220  /* Pin obj to protect it from removal while being in use */
1226  }
1228 
1229 leave:
1230  m0_confc_close(pool_obj);
1231  return M0_RC(rc);
1232 }
1233 
1234 static int spiel_pool_generic_handler(struct m0_spiel_core *spc,
1235  const struct m0_fid *pool_fid,
1236  const enum m0_cm_op cmd,
1237  struct m0_spiel_repreb_status **statuses,
1238  enum m0_repreb_type type)
1239 {
1240  int rc;
1241  int service_count;
1242  int i;
1243  struct _pool_cmd_ctx ctx;
1244  struct m0_fid_item *si;
1245  bool cmd_status;
1246  struct m0_spiel_repreb_status *repreb_statuses = NULL;
1247  struct spiel_repreb *repreb;
1248  struct m0_conf_obj *svc_obj;
1249 
1250  M0_ENTRY();
1251  M0_PRE(pool_fid != NULL);
1252  M0_PRE(spc != NULL);
1253  M0_PRE(spc->spc_rmachine != NULL);
1254 
1255  if (m0_conf_fid_type(pool_fid) != &M0_CONF_POOL_TYPE)
1256  return M0_ERR(-EINVAL);
1257 
1258  spiel__pool_ctx_init(&ctx, spc, type);
1259 
1260  rc = spiel_pool__device_collection_fill(&ctx, pool_fid) ?:
1261  SPIEL_CONF_DIR_ITERATE(spc->spc_confc, &ctx,
1263  M0_CONF_ROOT_NODES_FID,
1264  M0_CONF_NODE_PROCESSES_FID,
1265  M0_CONF_PROCESS_SERVICES_FID) ?:
1266  ctx.pl_rc;
1267  if (rc != 0)
1268  goto leave;
1269 
1270  cmd_status = M0_IN(cmd, (CM_OP_REPAIR_STATUS, CM_OP_REBALANCE_STATUS));
1271  service_count = m0_fids_tlist_length(&ctx.pl_services_fid);
1272 
1273  M0_ALLOC_ARR(repreb, service_count);
1274  if (repreb == NULL) {
1275  rc = M0_ERR(-ENOMEM);
1276  goto leave;
1277  }
1278  if (cmd_status) {
1279  M0_ALLOC_ARR(repreb_statuses, service_count);
1280  if (repreb_statuses == NULL) {
1281  rc = M0_ERR(-ENOMEM);
1282  m0_free(repreb);
1283  goto leave;
1284  }
1285  }
1286 
1287  /* Synchronously send `cmd' to each service associated with the pool. */
1288  i = 0;
1289  m0_tl_for(m0_fids, &ctx.pl_services_fid, si) {
1290  /* Open m0_conf_service object. */
1291  rc = m0_confc_open_by_fid_sync(spc->spc_confc, &si->i_fid,
1292  &svc_obj);
1293  if (rc != 0) {
1294  M0_LOG(M0_ERROR, "confc_open failed; rc=%d service="
1295  FID_F" i=%d", rc, FID_P(&si->i_fid), i);
1296  repreb[i++].sr_rc = rc;
1297  continue;
1298  }
1299  /* Is the service M0_NC_ONLINE? */
1300  if (svc_obj->co_ha_state != M0_NC_ONLINE) {
1301  rc = M0_ERR(-EINVAL);
1302  M0_LOG(M0_ERROR, "service "FID_F" is not online; i=%d"
1303  " ha_state=%d", FID_P(&si->i_fid), i,
1304  svc_obj->co_ha_state);
1305  m0_confc_close(svc_obj);
1306  repreb[i++].sr_rc = rc;
1307  continue;
1308  }
1309  repreb[i].sr_service = M0_CONF_CAST(svc_obj, m0_conf_service);
1310  M0_ASSERT(i < service_count);
1311 
1312  /* Send pool command to the service. */
1313  rc = spiel__pool_cmd_send(&ctx, cmd, &repreb[i]);
1314 
1315  m0_confc_close(svc_obj);
1316  if (rc != 0) {
1317  M0_LOG(M0_ERROR, "pool command sending failed;"
1318  " rc=%d service="FID_F" i=%d", rc,
1319  FID_P(&si->i_fid), i);
1320  repreb[i++].sr_rc = rc;
1321  continue;
1322  }
1323  ++i;
1324  } m0_tl_endfor;
1325 
1326  /*
1327  * Sequentially wait for services to process pool command and return
1328  * result.
1329  */
1330  i = 0;
1331  m0_tl_for (m0_fids, &ctx.pl_services_fid, si) {
1332  rc = spiel__pool_cmd_status_get(&ctx, cmd, &repreb[i]);
1333  if (cmd_status) {
1334  repreb_statuses[i] = repreb[i].sr_status;
1335  M0_LOG(M0_DEBUG, "service"FID_F" status=%d",
1336  FID_P(&si->i_fid),
1337  repreb_statuses[i].srs_state);
1338  }
1339  ++i;
1340  if (rc != 0)
1341  continue;
1342  } m0_tl_endfor;
1343 
1344  if (rc == 0 && cmd_status) {
1345  rc = i;
1346  *statuses = repreb_statuses;
1347  M0_LOG(M0_DEBUG, "array addr=%p size=%d", repreb_statuses, i);
1348  } else
1349  m0_free(repreb_statuses);
1350 
1351  m0_free(repreb);
1352 leave:
1354  return M0_RC(rc);
1355 }
1356 
1358  const struct m0_fid *pool_fid)
1359 {
1360  M0_ENTRY();
1361  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1362  CM_OP_REPAIR, NULL,
1364 }
1365 M0_EXPORTED(m0_spiel_sns_repair_start);
1366 
1368  const struct m0_fid *pool_fid)
1369 {
1370  M0_ENTRY();
1371  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1372  CM_OP_REPAIR, NULL,
1374 }
1375 M0_EXPORTED(m0_spiel_dix_repair_start);
1376 
1379  const struct m0_fid *pool_fid)
1380 {
1381  return m0_spiel_sns_repair_start(spl, pool_fid);
1382 }
1383 
1385  const struct m0_fid *pool_fid)
1386 {
1387  M0_ENTRY();
1388  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1391 }
1392 M0_EXPORTED(m0_spiel_sns_repair_continue);
1393 
1395  const struct m0_fid *pool_fid)
1396 {
1397  M0_ENTRY();
1398  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1401 }
1402 M0_EXPORTED(m0_spiel_dix_repair_continue);
1403 
1406  const struct m0_fid *pool_fid)
1407 {
1408  return m0_spiel_sns_repair_continue(spl, pool_fid);
1409 }
1410 
1412  const struct m0_fid *pool_fid)
1413 {
1414  M0_ENTRY();
1415  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1418 }
1419 M0_EXPORTED(m0_spiel_sns_repair_quiesce);
1420 
1422  const struct m0_fid *pool_fid)
1423 {
1424  M0_ENTRY();
1425  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1428 }
1429 M0_EXPORTED(m0_spiel_dix_repair_quiesce);
1430 
1433  const struct m0_fid *pool_fid)
1434 {
1435  return m0_spiel_sns_repair_quiesce(spl, pool_fid);
1436 }
1437 
1439  const struct m0_fid *pool_fid)
1440 {
1441  M0_ENTRY();
1442  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1445 }
1446 M0_EXPORTED(m0_spiel_sns_repair_abort);
1447 
1449  const struct m0_fid *pool_fid)
1450 {
1451  M0_ENTRY();
1452  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1455 }
1456 M0_EXPORTED(m0_spiel_dix_repair_abort);
1457 
1460  const struct m0_fid *pool_fid)
1461 {
1462  return m0_spiel_sns_repair_abort(spl, pool_fid);
1463 }
1464 
1466  const struct m0_fid *pool_fid,
1467  struct m0_spiel_repreb_status **statuses)
1468 {
1469  int rc;
1470 
1471  M0_ENTRY();
1472  M0_PRE(statuses != NULL);
1473  rc = spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1474  CM_OP_REPAIR_STATUS, statuses,
1476  return rc >= 0 ? M0_RC(rc) : M0_ERR(rc);
1477 }
1478 M0_EXPORTED(m0_spiel_sns_repair_status);
1479 
1481  const struct m0_fid *pool_fid,
1482  struct m0_spiel_repreb_status **statuses)
1483 {
1484  int rc;
1485 
1486  M0_ENTRY();
1487  M0_PRE(statuses != NULL);
1488  rc = spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1489  CM_OP_REPAIR_STATUS, statuses,
1491  return rc >= 0 ? M0_RC(rc) : M0_ERR(rc);
1492 }
1493 M0_EXPORTED(m0_spiel_dix_repair_status);
1494 
1497  const struct m0_fid *pool_fid,
1498  struct m0_spiel_sns_status **statuses)
1499 {
1500  return m0_spiel_sns_repair_status(spl, pool_fid,
1501  (struct m0_spiel_repreb_status **)statuses);
1502 }
1503 
1505  const struct m0_fid *pool_fid)
1506 {
1507  M0_ENTRY();
1508  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1511 }
1512 M0_EXPORTED(m0_spiel_sns_rebalance_start);
1513 
1515  const struct m0_fid *pool_fid)
1516 {
1517  M0_ENTRY();
1518  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1521 }
1522 M0_EXPORTED(m0_spiel_dix_rebalance_start);
1523 
1526  const struct m0_fid *pool_fid)
1527 {
1528  return m0_spiel_sns_rebalance_start(spl, pool_fid);
1529 }
1530 
1532  const struct m0_fid *pool_fid)
1533 {
1534  M0_ENTRY();
1535  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1538 }
1539 M0_EXPORTED(m0_spiel_sns_rebalance_continue);
1540 
1542  const struct m0_fid *node_fid)
1543 {
1544  return M0_ERR_INFO(-EPERM, "Cannot start direct rebalance for "FID_F
1545  " operation not implemented", FID_P(node_fid));
1546 }
1548 
1550  const struct m0_fid *pool_fid)
1551 {
1552  M0_ENTRY();
1553  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1556 }
1557 M0_EXPORTED(m0_spiel_dix_rebalance_continue);
1558 
1561  const struct m0_fid *pool_fid)
1562 {
1563  return m0_spiel_sns_rebalance_continue(spl, pool_fid);
1564 }
1565 
1567  const struct m0_fid *pool_fid)
1568 {
1569  M0_ENTRY();
1570  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1573 }
1574 M0_EXPORTED(m0_spiel_sns_rebalance_quiesce);
1575 
1577  const struct m0_fid *pool_fid)
1578 {
1579  M0_ENTRY();
1580  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1583 }
1584 M0_EXPORTED(m0_spiel_dix_rebalance_quiesce);
1585 
1588  const struct m0_fid *pool_fid)
1589 {
1590  return m0_spiel_sns_rebalance_quiesce(spl, pool_fid);
1591 }
1592 
1594  const struct m0_fid *pool_fid,
1595  struct m0_spiel_repreb_status **statuses)
1596 {
1597  int rc;
1598 
1599  M0_ENTRY();
1600  M0_PRE(statuses != NULL);
1601  rc = spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1602  CM_OP_REBALANCE_STATUS, statuses,
1604  return rc >= 0 ? M0_RC(rc) : M0_ERR(rc);
1605 }
1606 M0_EXPORTED(m0_spiel_sns_rebalance_status);
1607 
1609  const struct m0_fid *pool_fid,
1610  struct m0_spiel_repreb_status **statuses)
1611 {
1612  int rc;
1613 
1614  M0_ENTRY();
1615  M0_PRE(statuses != NULL);
1616  rc = spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1617  CM_OP_REBALANCE_STATUS, statuses,
1619  return rc >= 0 ? M0_RC(rc) : M0_ERR(rc);
1620 }
1621 M0_EXPORTED(m0_spiel_dix_rebalance_status);
1622 
1624  const struct m0_fid *pool_fid,
1625  struct m0_spiel_sns_status **statuses)
1626 {
1627  return m0_spiel_sns_rebalance_status(spl, pool_fid,
1628  (struct m0_spiel_repreb_status **)statuses);
1629 }
1630 
1632  const struct m0_fid *pool_fid)
1633 {
1634  M0_ENTRY();
1635  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1638 }
1639 M0_EXPORTED(m0_spiel_sns_rebalance_abort);
1640 
1642  const struct m0_fid *pool_fid)
1643 {
1644  M0_ENTRY();
1645  return M0_RC(spiel_pool_generic_handler(&spl->spl_core, pool_fid,
1648 }
1649 M0_EXPORTED(m0_spiel_dix_rebalance_abort);
1650 
1653  const struct m0_fid *pool_fid)
1654 {
1655  return m0_spiel_sns_rebalance_abort(spl, pool_fid);
1656 }
1657 
1658 /***********************************************/
1659 /* Byte count */
1660 /***********************************************/
1661 
1666  struct m0_buf pd_key;
1667  struct m0_buf pd_rec;
1668  uint32_t pd_kv_count;
1671  /* uint64_t pd_magic; */
1672 };
1673 
1679  struct m0_fid sci_fid;
1683  struct m0_fop sci_fop;
1697  struct m0_spiel_core *sci_spc;
1701  uint64_t sci_magic;
1702  int sci_rc;
1703 };
1704 
1705 /****************************************************/
1706 /* Filesystem */
1707 /****************************************************/
1708 
1715  struct m0_fid spi_fid;
1724  struct m0_fop spi_fop;
1729  uint32_t spi_svc_count;
1730  uint64_t spi_magic;
1731 };
1732 
1733 M0_TL_DESCR_DEFINE(spiel_proc_items, "spiel_proc_items", static,
1734  struct spiel_proc_item, spi_link, spi_magic,
1736 
1737 M0_TL_DEFINE(spiel_proc_items, static, struct spiel_proc_item);
1738 
1739 static inline void _fs_stats_ctx_lock(struct _fs_stats_ctx *fsx)
1740 {
1741  m0_mutex_lock(&fsx->fx_guard);
1742 }
1743 
1744 static inline void _fs_stats_ctx_unlock(struct _fs_stats_ctx *fsx)
1745 {
1746  m0_mutex_unlock(&fsx->fx_guard);
1747 }
1748 
1750 {
1751  struct _fs_stats_ctx *fsx = proc->spi_ctx;
1752 
1753  _fs_stats_ctx_lock(fsx);
1754  fsx->fx_svc_processed += proc->spi_svc_count;
1755  if (fsx->fx_svc_processed == fsx->fx_svc_total)
1756  m0_semaphore_up(&fsx->fx_barrier);
1757  _fs_stats_ctx_unlock(fsx);
1758 }
1759 
1761 {
1762  struct spiel_proc_item *proc = M0_AMB(proc, clink, spi_rlink_wait);
1763 
1764  M0_ENTRY(FID_F, FID_P(&proc->spi_fid));
1766  M0_LEAVE();
1767  return true;
1768 }
1769 
1771 {
1772  m0_time_t conn_timeout;
1773 
1774  M0_ENTRY(FID_F, FID_P(&proc->spi_fid));
1775  conn_timeout = m0_time_from_now(SPIEL_CONN_TIMEOUT, 0);
1777  proc->spi_rlink_wait.cl_is_oneshot = true;
1778  m0_rpc_link_disconnect_async(&proc->spi_rlink, conn_timeout,
1779  &proc->spi_rlink_wait);
1780  M0_LEAVE();
1781 }
1782 
1784  struct m0_sm_ast *ast)
1785 {
1786  struct spiel_proc_item *proc = M0_AMB(proc, ast, spi_ast);
1787  struct _fs_stats_ctx *ctx = proc->spi_ctx;
1788  struct m0_rpc_item *item = &proc->spi_fop.f_item;
1789  struct m0_ss_process_rep *rep;
1790  int rc;
1791 
1792  M0_ENTRY(FID_F, FID_P(&proc->spi_fid));
1793  rc = M0_FI_ENABLED("item_error") ? -EINVAL : m0_rpc_item_error(item);
1798  if (rc != 0)
1799  goto leave;
1801  if (rep->sspr_health >= M0_HEALTH_GOOD) {
1803  if (M0_FI_ENABLED("overflow") ||
1804  m0_addu64_will_overflow(rep->sspr_free_seg,
1805  ctx->fx_free_seg) ||
1806  m0_addu64_will_overflow(rep->sspr_total_seg,
1807  ctx->fx_total_seg) ||
1808  m0_addu64_will_overflow(rep->sspr_free_disk,
1809  ctx->fx_free_disk) ||
1810  m0_addu64_will_overflow(rep->sspr_total_disk,
1811  ctx->fx_total_disk)) {
1812  ctx->fx_rc = M0_ERR(-EOVERFLOW);
1813  } else {
1814  ctx->fx_free_seg += rep->sspr_free_seg;
1815  ctx->fx_total_seg += rep->sspr_total_seg;
1816  ctx->fx_free_disk += rep->sspr_free_disk;
1817  ctx->fx_avail_disk += rep->sspr_avail_disk;
1818  ctx->fx_total_disk += rep->sspr_total_disk;
1819  ctx->fx_svc_replied += proc->spi_svc_count;
1820  }
1822  }
1823 leave:
1824  m0_rpc_machine_lock(ctx->fx_spc->spc_rmachine);
1825  m0_fop_put(&proc->spi_fop);
1826  m0_fop_fini(&proc->spi_fop);
1827  m0_rpc_machine_unlock(ctx->fx_spc->spc_rmachine);
1829  M0_LEAVE();
1830 }
1831 
1833  struct m0_sm_ast *ast)
1834 {
1836  spi_ast));
1837 }
1838 
1839 static struct m0_sm_group* spiel_proc_sm_group(const struct spiel_proc_item *p)
1840 {
1841  return p->spi_ctx->fx_spc->spc_confc->cc_group;
1842 }
1843 
1845 {
1846  struct m0_fop *fop = m0_rpc_item_to_fop(item);
1847  struct spiel_proc_item *proc = M0_AMB(proc, fop, spi_fop);
1848 
1849  M0_ENTRY(FID_F, FID_P(&proc->spi_fid));
1852  M0_LEAVE();
1853 }
1854 
1857 };
1858 
1860 {
1861  struct spiel_proc_item *proc = M0_AMB(proc, clink, spi_rlink_wait);
1862  struct m0_ss_process_req *req;
1863  struct _fs_stats_ctx *ctx = proc->spi_ctx;
1864  struct m0_fop *fop = &proc->spi_fop;
1865  struct m0_rpc_item *item;
1866  int rc;
1867 
1868  M0_ENTRY(FID_F, FID_P(&proc->spi_fid));
1870  if (proc->spi_rlink.rlk_rc != 0) {
1871  M0_LOG(M0_ERROR, "connect failed");
1872  goto proc_handled;
1873  }
1875  rc = M0_FI_ENABLED("alloc_fail") ? -ENOMEM : m0_fop_data_alloc(fop);
1876  if (rc != 0) {
1877  M0_LOG(M0_ERROR, "fop data alloc failed");
1878  goto fop_fini;
1879  }
1880  fop->f_item.ri_rmachine = ctx->fx_spc->spc_rmachine;
1882  req->ssp_cmd = M0_PROCESS_HEALTH;
1883  req->ssp_id = proc->spi_fid;
1884  item = &fop->f_item;
1886  item->ri_session = &proc->spi_rlink.rlk_sess;
1888  item->ri_nr_sent_max = 5;
1889  m0_fop_get(fop);
1890  rc = M0_FI_ENABLED("rpc_post") ? -ENOTCONN : m0_rpc_post(item);
1891  if (rc != 0) {
1892  M0_LOG(M0_ERROR, "rpc post failed");
1893  goto fop_put;
1894  }
1895  M0_LEAVE();
1896  return true;
1897 fop_put:
1899 fop_fini:
1900  m0_fop_fini(fop);
1903  return true;
1904 proc_handled:
1906  M0_LEAVE();
1907  return true;
1908 }
1909 
1911  struct spiel_proc_item *proc)
1912 {
1913  struct m0_conf_process *process;
1914  m0_time_t conn_timeout;
1915  int rc;
1916 
1917  M0_ENTRY("proc fid "FID_F, FID_P(&proc->spi_fid));
1918  rc = M0_FI_ENABLED("obj_find") ? -ENOENT :
1919  spiel_proc_conf_obj_find(fsx->fx_spc, &proc->spi_fid, &process);
1920  if (rc != 0)
1921  goto err;
1922  m0_confc_close(&process->pc_obj);
1923  conn_timeout = m0_time_from_now(SPIEL_CONN_TIMEOUT, 0);
1924  rc = m0_rpc_link_init(&proc->spi_rlink, fsx->fx_spc->spc_rmachine, NULL,
1926  if (rc != 0)
1927  goto err;
1929  proc->spi_rlink_wait.cl_is_oneshot = true;
1930  m0_rpc_link_connect_async(&proc->spi_rlink, conn_timeout,
1931  &proc->spi_rlink_wait);
1932  M0_LEAVE();
1933  return;
1934 err:
1936  M0_ERR(rc);
1937 }
1938 
1939 
1940 static void spiel__fs_stats_ctx_init(struct _fs_stats_ctx *fsx,
1941  struct m0_spiel_core *spc,
1942  const struct m0_conf_obj_type *item_type)
1943 {
1944  M0_SET0(fsx);
1945  fsx->fx_spc = spc;
1946  fsx->fx_type = item_type;
1947  m0_semaphore_init(&fsx->fx_barrier, 0);
1948  m0_mutex_init(&fsx->fx_guard);
1949  spiel_proc_items_tlist_init(&fsx->fx_items);
1950  M0_POST(spiel_proc_items_tlist_invariant(&fsx->fx_items));
1951 }
1952 
1953 static void spiel__fs_stats_ctx_fini(struct _fs_stats_ctx *fsx)
1954 {
1955  struct spiel_proc_item *si;
1956 
1957  m0_tl_teardown(spiel_proc_items, &fsx->fx_items, si) {
1958  if (!M0_IS0(&si->spi_rlink))
1959  m0_rpc_link_fini(&si->spi_rlink);
1960  m0_free(si);
1961  }
1962  spiel_proc_items_tlist_fini(&fsx->fx_items);
1963  m0_mutex_fini(&fsx->fx_guard);
1965 }
1966 
1973 static bool spiel__item_enlist(const struct m0_conf_obj *item, void *ctx)
1974 {
1975  struct _fs_stats_ctx *fsx = ctx;
1976  struct spiel_proc_item *si = NULL;
1977 
1978  M0_LOG(SPIEL_LOGLVL, "arrived: " FID_F " (%s)", FID_P(&item->co_id),
1979  m0_fid_type_getfid(&item->co_id)->ft_name);
1980  /* skip all but requested object types */
1981  if (m0_conf_obj_type(item) != fsx->fx_type)
1982  return true;
1983  if (!M0_FI_ENABLED("alloc fail"))
1984  M0_ALLOC_PTR(si);
1985  if (si == NULL) {
1986  fsx->fx_rc = M0_ERR(-ENOMEM);
1987  return false;
1988  }
1989  si->spi_fid = item->co_id;
1990  si->spi_ctx = fsx;
1991  spiel_proc_items_tlink_init_at(si, &fsx->fx_items);
1992  M0_LOG(SPIEL_LOGLVL, "* booked: " FID_F " (%s)", FID_P(&item->co_id),
1993  m0_fid_type_getfid(&item->co_id)->ft_name);
1994  return true;
1995 }
1996 
2004  struct m0_confc *confc)
2005 {
2006  struct m0_conf_diter it;
2007  struct m0_fid *proc_fid = &proc->spi_fid;
2008  struct m0_conf_obj *proc_obj;
2009  struct m0_conf_service *svc;
2010  int rc;
2011 
2012  M0_ENTRY("proc_fid = "FID_F, FID_P(proc_fid));
2014 
2015  rc = M0_FI_ENABLED("open_by_fid") ? -EINVAL :
2017  if (rc != 0)
2018  return M0_ERR(rc);
2019  if (proc_obj->co_ha_state != M0_NC_ONLINE) {
2020  rc = M0_ERR(-EINVAL);
2021  goto obj_close;
2022  }
2023  rc = M0_FI_ENABLED("diter_init") ? -EINVAL :
2024  m0_conf_diter_init(&it, confc, proc_obj,
2025  M0_CONF_PROCESS_SERVICES_FID);
2026  if (rc != 0)
2027  goto obj_close;
2028  while (m0_conf_diter_next_sync(&it, NULL) > 0) {
2030  if (M0_IN(svc->cs_type, (M0_CST_IOS, M0_CST_MDS, M0_CST_CAS)))
2031  M0_CNT_INC(proc->spi_svc_count);
2032  }
2033  if (proc->spi_svc_count != 0) {
2034  /*
2035  * There is no point to update process' HA state unless
2036  * the one is expected to host the required services.
2037  */
2038  rc = M0_FI_ENABLED("ha_update") ? -EINVAL :
2040  }
2041  else {
2042  rc = -ENOENT; /* this case is normal, don't use M0_ERR() */
2043  }
2045 obj_close:
2046  m0_confc_close(proc_obj);
2047  return M0_RC(rc);
2048 }
2049 
2051  struct m0_sm_ast *ast)
2052 {
2053  struct spiel_proc_counter_item *proc = M0_AMB(proc, ast, sci_ast);
2054  struct m0_rpc_item *item = &proc->sci_fop.f_item;
2055  struct m0_ss_process_rep *rep;
2056  m0_time_t conn_timeout;
2057  int rc;
2058 
2059  M0_ENTRY(FID_F, FID_P(&proc->sci_fid));
2061  if (rc != 0)
2062  goto leave;
2064 
2065  rc = m0_buf_alloc(&proc->sci_data.pd_key, rep->sspr_bckey.b_nob);
2066  if (rc != 0)
2067  goto leave;
2068  rc = m0_buf_alloc(&proc->sci_data.pd_rec, rep->sspr_bcrec.b_nob);
2069  if (rc != 0) {
2070  m0_buf_free(&proc->sci_data.pd_key);
2071  goto leave;
2072  }
2073 
2074  memcpy(proc->sci_data.pd_key.b_addr, rep->sspr_bckey.b_addr,
2075  rep->sspr_bckey.b_nob);
2076  memcpy(proc->sci_data.pd_rec.b_addr, rep->sspr_bcrec.b_addr,
2077  rep->sspr_bcrec.b_nob);
2078  proc->sci_data.pd_kv_count = rep->sspr_kv_count;
2079 
2080 leave:
2081  m0_rpc_machine_lock(proc->sci_spc->spc_rmachine);
2082  m0_fop_put(&proc->sci_fop);
2083  m0_fop_fini(&proc->sci_fop);
2084  m0_rpc_machine_unlock(proc->sci_spc->spc_rmachine);
2085 
2086  conn_timeout = m0_time_from_now(SPIEL_CONN_TIMEOUT, 0);
2087  m0_rpc_link_disconnect_sync(&proc->sci_rlink, conn_timeout);
2088  m0_rpc_link_fini(&proc->sci_rlink);
2089  proc->sci_rc = rc;
2090  m0_semaphore_up(&proc->sci_barrier);
2091  M0_LEAVE();
2092 }
2093 
2095 {
2096  return i->sci_spc->spc_confc->cc_group;
2097 }
2098 
2100 {
2101  struct m0_fop *fop = m0_rpc_item_to_fop(item);
2102  struct spiel_proc_counter_item *proc = M0_AMB(proc, fop, sci_fop);
2103 
2104  M0_ENTRY(FID_F, FID_P(&proc->sci_fid));
2107  M0_LEAVE();
2108 }
2109 
2112 };
2113 
2115 {
2116  struct spiel_proc_counter_item *proc = M0_AMB(proc, clink, sci_rlink_wait);
2117  struct m0_ss_process_req *req;
2118  struct m0_fop *fop = &proc->sci_fop;
2119  struct m0_rpc_item *item;
2120  m0_time_t conn_timeout;
2121  int rc;
2122 
2123  M0_ENTRY(FID_F, FID_P(&proc->sci_fid));
2125  if (proc->sci_rlink.rlk_rc != 0) {
2126  M0_LOG(M0_ERROR, "connect failed");
2127  proc->sci_rc = proc->sci_rlink.rlk_rc;
2128  m0_semaphore_up(&proc->sci_barrier);
2129  goto ret;
2130  }
2133  if (rc != 0) {
2134  M0_LOG(M0_ERROR, "fop data alloc failed");
2135  goto fop_fini;
2136  }
2137 
2138  fop->f_item.ri_rmachine = proc->sci_spc->spc_rmachine;
2140  req->ssp_cmd = M0_PROCESS_COUNTER;
2141  req->ssp_id = proc->sci_fid;
2142  item = &fop->f_item;
2144  item->ri_session = &proc->sci_rlink.rlk_sess;
2146  item->ri_nr_sent_max = 5;
2147  m0_fop_get(fop);
2148  rc = m0_rpc_post(item);
2149  if (rc != 0) {
2150  M0_LOG(M0_ERROR, "rpc post failed");
2152  goto fop_fini;
2153  }
2154 
2155  proc->sci_rc = rc;
2156  goto ret;
2157 
2158 fop_fini:
2159  m0_fop_fini(fop);
2160  conn_timeout = m0_time_from_now(SPIEL_CONN_TIMEOUT, 0);
2161  m0_rpc_link_disconnect_sync(&proc->sci_rlink, conn_timeout);
2162  m0_rpc_link_fini(&proc->sci_rlink);
2163  proc->sci_rc = rc;
2164  m0_semaphore_up(&proc->sci_barrier);
2165  M0_LEAVE();
2166  return true;
2167 
2168 ret:
2169  M0_LEAVE();
2170  return true;
2171 }
2172 
2174 {
2175  struct m0_conf_process *process;
2176  struct m0_spiel_core *spc = proc->sci_spc;
2177  m0_time_t conn_timeout;
2178  int rc;
2179 
2180  M0_ENTRY("proc fid "FID_F, FID_P(&proc->sci_fid));
2181  rc = spiel_proc_conf_obj_find(spc, &proc->sci_fid, &process);
2182  if (rc != 0)
2183  return M0_ERR(rc);
2184  m0_confc_close(&process->pc_obj);
2185  conn_timeout = m0_time_from_now(SPIEL_CONN_TIMEOUT, 0);
2186  rc = m0_rpc_link_init(&proc->sci_rlink, spc->spc_rmachine, NULL,
2188  if (rc != 0)
2189  return M0_ERR(rc);
2190 
2192  proc->sci_rlink_wait.cl_is_oneshot = true;
2193  m0_rpc_link_connect_async(&proc->sci_rlink, conn_timeout,
2194  &proc->sci_rlink_wait);
2195  return M0_RC(rc);
2196 }
2197 
2198 static void count_stats_failed_free(struct m0_proc_counter *count_stats,
2199  int failed_index)
2200 {
2201  int i;
2202 
2203  for (i = 0; i <= failed_index; i++) {
2204  if (count_stats->pc_bckey[i] != NULL)
2205  m0_free(count_stats->pc_bckey[i]);
2206  if (count_stats->pc_bcrec[i] != NULL)
2207  m0_free(count_stats->pc_bcrec[i]);
2208  }
2209 }
2210 
2212  struct m0_fid *proc_fid,
2213  struct m0_proc_counter *count_stats)
2214 {
2215  struct spiel_proc_counter_item *proc = NULL;
2216  struct m0_spiel_core *spc = &spl->spl_core;
2217  struct m0_conf_obj *proc_obj;
2218  struct m0_spiel_bckey *key_cur;
2219  struct m0_spiel_bcrec *rec_cur;
2220  int rc = 0;
2221  int i;
2222 
2223  M0_ENTRY();
2224  M0_PRE(spl != NULL);
2225  M0_PRE(spc->spc_confc != NULL);
2226  M0_PRE(count_stats != NULL);
2227 
2228  if (!m0_confc_is_inited(spc->spc_confc))
2229  return M0_ERR_INFO(-EAGAIN, "confc is finalised");
2230 
2231  rc = m0_confc_open_by_fid_sync(spc->spc_confc, proc_fid, &proc_obj);
2232  if (rc != 0)
2233  return M0_ERR(rc);
2234  if (proc_obj->co_ha_state != M0_NC_ONLINE) {
2235  rc = M0_ERR(-EPERM);
2236  goto obj_close;
2237  }
2238 
2239  M0_ALLOC_PTR(proc);
2240  if (proc == NULL) {
2241  rc = M0_ERR(-ENOMEM);
2242  goto obj_close;
2243  }
2244 
2245  m0_semaphore_init(&proc->sci_barrier, 0);
2246  proc->sci_fid = *proc_fid;
2247  proc->sci_spc = spc;
2248 
2249  /* List will be implemented when adding retry mechanism CORTX-28389. */
2250  /*
2251  M0_TL_DESCR_DEFINE(proc_counter, "proc-counter", M0_INTERNAL,
2252  struct m0_proc_data, pd_link, pd_magic,
2253  M0_NET_BUFFER_LINK_MAGIC, M0_NET_BUFFER_HEAD_MAGIC);
2254  M0_TL_DEFINE(proc_counter, M0_INTERNAL, struct m0_proc_data);
2255  */
2257  if (rc != 0)
2258  goto sem_fini;
2260 
2261  count_stats->pc_proc_fid = *proc_fid;
2262  count_stats->pc_rc = proc->sci_rc;
2263 
2264  if (proc->sci_rc != 0) {
2265  rc = proc->sci_rc;
2266  goto sem_fini;
2267  }
2268 
2269  count_stats->pc_cnt = proc->sci_data.pd_kv_count;
2270  M0_ALLOC_ARR(count_stats->pc_bckey, proc->sci_data.pd_kv_count);
2271  if (count_stats->pc_bckey == NULL) {
2272  rc = M0_ERR(-ENOMEM);
2273  goto buf_free;
2274  }
2275  M0_ALLOC_ARR(count_stats->pc_bcrec, proc->sci_data.pd_kv_count);
2276  if (count_stats->pc_bcrec == NULL) {
2277  m0_free(count_stats->pc_bckey);
2278  rc = M0_ERR(-ENOMEM);
2279  goto buf_free;
2280  }
2281 
2282  key_cur = (struct m0_spiel_bckey *)proc->sci_data.pd_key.b_addr;
2283  rec_cur = (struct m0_spiel_bcrec *)proc->sci_data.pd_rec.b_addr;
2284 
2285  for (i = 0; i < proc->sci_data.pd_kv_count; i++) {
2286  M0_ALLOC_PTR(count_stats->pc_bckey[i]);
2287  M0_ALLOC_PTR(count_stats->pc_bcrec[i]);
2288  if (count_stats->pc_bckey[i] == NULL ||
2289  count_stats->pc_bcrec[i] == NULL) {
2290  count_stats_failed_free(count_stats, i);
2291  rc = M0_ERR(-ENOMEM);
2292  goto buf_free;
2293  }
2294 
2295  memcpy(count_stats->pc_bckey[i], key_cur,
2296  sizeof(struct m0_spiel_bckey));
2297  memcpy(count_stats->pc_bcrec[i], rec_cur,
2298  sizeof(struct m0_spiel_bcrec));
2299 
2300  key_cur++;
2301  rec_cur++;
2302  }
2303 
2304 buf_free:
2305  m0_buf_free(&proc->sci_data.pd_key);
2306  m0_buf_free(&proc->sci_data.pd_rec);
2307 sem_fini:
2309 obj_close:
2310  m0_confc_close(proc_obj);
2311  return M0_RC(rc);
2312 }
2313 M0_EXPORTED(m0_spiel_proc_counters_fetch);
2314 
2315 M0_INTERNAL int m0_spiel__fs_stats_fetch(struct m0_spiel_core *spc,
2316  struct m0_fs_stats *stats)
2317 {
2318  struct _fs_stats_ctx fsx;
2319  struct spiel_proc_item *proc;
2320  int rc;
2321 
2322  M0_ENTRY();
2323  M0_PRE(spc != NULL);
2324  M0_PRE(spc->spc_confc != NULL);
2325  M0_PRE(stats != NULL);
2326 
2327  if (!m0_confc_is_inited(spc->spc_confc))
2328  return M0_ERR_INFO(-EAGAIN, "confc is finalised");
2329 
2331  /* walk along the filesystem nodes and get to process level */
2332  rc = SPIEL_CONF_DIR_ITERATE(spc->spc_confc, &fsx,
2334  M0_CONF_ROOT_NODES_FID,
2335  M0_CONF_NODE_PROCESSES_FID) ?:
2336  fsx.fx_rc;
2337  if (rc != 0)
2338  goto end;
2339  /* update stats by the list of found processes */
2340  m0_tl_for(spiel_proc_items, &fsx.fx_items, proc) {
2341  rc = spiel__proc_is_to_update_stats(proc, spc->spc_confc);
2342  if (rc != 0) {
2343  rc = 0;
2344  spiel_proc_items_tlist_del(proc);
2345  m0_free(proc);
2346  continue;
2347  }
2348  fsx.fx_svc_total += proc->spi_svc_count;
2349  } m0_tl_endfor;
2350  m0_tl_for(spiel_proc_items, &fsx.fx_items, proc) {
2351  spiel_process__health_async(&fsx, proc);
2352  } m0_tl_endfor;
2354  _fs_stats_ctx_lock(&fsx);
2356  fsx.fx_svc_replied <= fsx.fx_svc_total);
2357  /* report stats to consumer */
2358  *stats = (struct m0_fs_stats) {
2359  .fs_free_seg = fsx.fx_free_seg,
2360  .fs_total_seg = fsx.fx_total_seg,
2361  .fs_free_disk = fsx.fx_free_disk,
2362  .fs_avail_disk = fsx.fx_avail_disk,
2363  .fs_total_disk = fsx.fx_total_disk,
2364  .fs_svc_total = fsx.fx_svc_total,
2365  .fs_svc_replied = fsx.fx_svc_replied,
2366  };
2367  _fs_stats_ctx_unlock(&fsx);
2368 end:
2370  return M0_RC(rc ? rc : fsx.fx_rc);
2371 }
2372 M0_EXPORTED(m0_spiel_filesystem_stats_fetch);
2373 
2375  struct m0_fs_stats *stats)
2376 {
2377  return m0_spiel__fs_stats_fetch(&spl->spl_core, stats);
2378 }
2379 
2380 int m0_spiel_confstr(struct m0_spiel *spl, char **out)
2381 {
2382  char *confstr;
2383  int rc;
2384 
2385  rc = m0_conf_cache_to_string(&spiel_confc(spl)->cc_cache, &confstr,
2386  false);
2387  if (rc != 0)
2388  return M0_ERR(rc);
2389  *out = m0_strdup(confstr);
2390  if (*out == NULL)
2391  rc = M0_ERR(-ENOMEM);
2392  m0_confx_string_free(confstr);
2393  return M0_RC(rc);
2394 }
2395 M0_EXPORTED(m0_spiel_confstr);
2396 
2398  struct m0_fid *fid,
2399  struct m0_conf_pver_info *out_info)
2400 {
2401  struct m0_confc *confc;
2402 
2403  M0_ENTRY();
2404  M0_PRE(spl != NULL);
2405 
2406  confc = spl->spl_core.spc_confc;
2407  if (!m0_confc_is_inited(confc))
2408  return M0_ERR_INFO(-EAGAIN, "confc is finalised");
2409 
2410  return M0_RC(m0_conf_pver_status(fid, confc, out_info));
2411 }
2412 M0_EXPORTED(m0_spiel_conf_pver_status);
2414 #undef M0_TRACE_SUBSYSTEM
2415 
2416 /*
2417  * Local variables:
2418  * c-indentation-style: "K&R"
2419  * c-basic-offset: 8
2420  * tab-width: 8
2421  * fill-column: 80
2422  * scroll-step: 1
2423  * End:
2424  */
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
int m0_spiel_pool_rebalance_start(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1525
M0_INTERNAL int m0_spiel__fs_stats_fetch(struct m0_spiel_core *spc, struct m0_fs_stats *stats)
Definition: cmd.c:2315
static int spiel_process_command_execute(struct m0_spiel_core *spc, const struct m0_fid *proc_fid, int cmd, const struct m0_buf *param, struct m0_ss_process_rep *ssp_rep)
Definition: cmd.c:736
M0_INTERNAL int m0_rpc_post(struct m0_rpc_item *item)
Definition: rpc.c:63
struct m0_fid hae_active_rm_fid
static void spiel_fop_destroy(struct m0_fop *fop)
Definition: cmd.c:53
static int spiel_pool_generic_handler(struct m0_spiel_core *spc, const struct m0_fid *pool_fid, const enum m0_cm_op cmd, struct m0_spiel_repreb_status **statuses, enum m0_repreb_type type)
Definition: cmd.c:1234
int m0_spiel_sns_rebalance_quiesce(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1566
static struct m0_addb2_philter p
Definition: consumer.c:40
struct m0_conf_obj * cc_root
Definition: confc.h:404
const char * pc_endpoint
Definition: obj.h:590
#define M0_PRE(cond)
struct m0_buf * ab_elems
Definition: buf.h:45
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
const struct m0_conf_obj_type M0_CONF_OBJV_TYPE
Definition: objv.c:151
M0_INTERNAL struct m0_fop * m0_sss_device_fop_create(struct m0_rpc_machine *mach, uint32_t cmd, const struct m0_fid *fid)
Definition: device_fops.c:86
int m0_spiel_sns_rebalance_continue(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1531
struct m0_fop sci_fop
Definition: cmd.c:1683
int m0_spiel_pool_rebalance_quiesce(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1587
struct m0_spiel_bckey ** pc_bckey
Definition: spiel.h:1281
M0_INTERNAL void m0_mutex_unlock(struct m0_mutex *mutex)
Definition: mutex.c:66
static void _fs_stats_ctx_unlock(struct _fs_stats_ctx *fsx)
Definition: cmd.c:1744
static struct m0_list list
Definition: list.c:144
m0_bcount_t fx_total_disk
Definition: cmd_internal.h:79
#define m0_strdup(s)
Definition: string.h:43
static void spiel_proc_item_postprocess(struct spiel_proc_item *proc)
Definition: cmd.c:1749
enum m0_rpc_item_priority ri_prio
Definition: item.h:133
uint32_t pc_cnt
Definition: spiel.h:1279
int m0_spiel_sns_rebalance_status(struct m0_spiel *spl, const struct m0_fid *pool_fid, struct m0_spiel_repreb_status **statuses)
Definition: cmd.c:1593
struct _fs_stats_ctx * spi_ctx
Definition: cmd.c:1727
#define NULL
Definition: misc.h:38
M0_INTERNAL void m0_clink_init(struct m0_clink *link, m0_chan_cb_t cb)
Definition: chan.c:201
Definition: cmd_internal.h:53
m0_conf_service_type
Definition: schema.h:194
struct m0_ha_entrypoint_rep rc_ha_entrypoint_rep
Definition: rconfc.h:420
struct m0_sm_ast spi_ast
Definition: cmd.c:1725
static int spiel_pool_device_collect(struct _pool_cmd_ctx *ctx, struct m0_conf_obj *obj_diskv)
Definition: cmd.c:1006
int m0_rpc_post_with_timeout_sync(struct m0_fop *fop, struct m0_rpc_session *session, const struct m0_rpc_item_ops *ri_ops, m0_time_t deadline, m0_time_t timeout)
Definition: rpclib.c:249
struct m0_tlink spi_link
Definition: cmd.c:1726
#define ergo(a, b)
Definition: misc.h:293
struct m0_spiel_core * sci_spc
Definition: cmd.c:1697
void(* sa_cb)(struct m0_sm_group *grp, struct m0_sm_ast *)
Definition: sm.h:506
M0_INTERNAL int m0_sns_cm_trigger_fop_alloc(struct m0_rpc_machine *mach, uint32_t op, struct m0_fop **fop)
bool sr_is_connected
Definition: cmd.c:936
const m0_time_t M0_TIME_NEVER
Definition: time.c:108
void * b_addr
Definition: buf.h:39
uint32_t ssr_state
Definition: ss_fops.h:86
static struct io_request req
Definition: file.c:100
static struct m0_sm_group * grp
Definition: bytecount.c:38
struct m0_fop * sr_fop
Definition: cmd.c:934
M0_INTERNAL void m0_fop_init(struct m0_fop *fop, struct m0_fop_type *fopt, void *data, void(*fop_release)(struct m0_ref *))
Definition: fop.c:79
static bool _filter_pool(const struct m0_conf_obj *obj)
Definition: cmd.c:922
uint64_t m0_time_t
Definition: time.h:37
#define M0_LOG(level,...)
Definition: trace.h:167
int m0_spiel_dix_repair_abort(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1448
M0_LEAVE()
const struct m0_conf_obj_type * m0_conf_fid_type(const struct m0_fid *fid)
Definition: obj.c:368
const struct m0_conf_obj_type M0_CONF_SERVICE_TYPE
Definition: service.c:156
M0_INTERNAL void m0_sm_ast_post(struct m0_sm_group *grp, struct m0_sm_ast *ast)
Definition: sm.c:135
M0_INTERNAL void m0_confx_string_free(char *str)
Definition: preload.c:86
int m0_spiel_dix_rebalance_abort(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1641
struct m0_semaphore sci_barrier
Definition: cmd.c:1700
static struct net_test_cmd_node * node
Definition: commands.c:72
unsigned int srs_progress
Definition: spiel.h:170
int m0_spiel_sns_repair_status(struct m0_spiel *spl, const struct m0_fid *pool_fid, struct m0_spiel_repreb_status **statuses)
Definition: cmd.c:1465
static bool spiel_proc_item_rlink_cb(struct m0_clink *clink)
Definition: cmd.c:1859
static int spiel__pool_cmd_status_get(struct _pool_cmd_ctx *ctx, const enum m0_cm_op cmd, struct spiel_repreb *repreb)
Definition: cmd.c:1147
static void leave(struct m0_locality_chore *chore, struct m0_locality *loc, void *place)
Definition: locality.c:315
int m0_spiel_service_start(struct m0_spiel *spl, const struct m0_fid *svc_fid)
Definition: cmd.c:516
uint32_t ab_count
Definition: buf.h:44
static struct m0_sm_group * spiel_counter_sm_group(struct spiel_proc_counter_item *i)
Definition: cmd.c:2094
M0_INTERNAL void m0_buf_init(struct m0_buf *buf, void *data, uint32_t nob)
Definition: buf.c:37
const struct m0_conf_obj_type M0_CONF_SDEV_TYPE
Definition: sdev.c:122
int m0_spiel_dix_repair_quiesce(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1421
M0_INTERNAL int m0_conf_diter_next_sync(struct m0_conf_diter *it, bool(*filter)(const struct m0_conf_obj *obj))
Definition: diter.c:555
char * sse_string
Definition: cmd_internal.h:54
M0_INTERNAL void m0_conf_obj_put(struct m0_conf_obj *obj)
Definition: obj_ops.c:205
struct m0_buf pd_rec
Definition: cmd.c:1667
static void spiel__add_item(struct _pool_cmd_ctx *pool_ctx, const struct m0_conf_obj *item, struct m0_conf_service *service, enum m0_conf_service_type type)
Definition: cmd.c:1095
int m0_spiel_sns_repair_abort(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1438
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
static struct m0_be_emap_cursor it
Definition: extmap.c:46
uint32_t fx_svc_processed
Definition: cmd_internal.h:73
static bool m0_addu64_will_overflow(uint64_t a, uint64_t b)
Definition: arith.h:235
int pl_rc
Definition: cmd.c:999
const struct m0_conf_obj_type M0_CONF_POOL_TYPE
Definition: pool.c:249
static struct m0_addb2_mach * mach
Definition: storage.c:42
int m0_spiel_device_attach_state(struct m0_spiel *spl, const struct m0_fid *dev_fid, uint32_t *ha_state)
Definition: cmd.c:647
m0_cm_op
Definition: cm.h:37
int m0_spiel_dix_rebalance_continue(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1549
Definition: sm.h:504
M0_TL_DEFINE(spiel_string, static, struct spiel_string_entry)
struct m0_fop_type m0_fop_ss_fopt
Definition: ss_fops.c:39
static bool _filter_controller(const struct m0_conf_obj *obj)
Definition: cmd.c:80
uint32_t ss_cmd
Definition: ss_fops.h:61
M0_INTERNAL struct m0_ss_process_rep * m0_ss_fop_process_rep(struct m0_fop *fop)
Definition: process_fops.c:191
static bool spiel_proc_counter_item_rlink_cb(struct m0_clink *clink)
Definition: cmd.c:2114
#define container_of(ptr, type, member)
Definition: misc.h:33
#define M0_SET0(obj)
Definition: misc.h:64
M0_INTERNAL void m0_mutex_lock(struct m0_mutex *mutex)
Definition: mutex.c:49
struct m0_spiel_bcrec ** pc_bcrec
Definition: spiel.h:1282
struct m0_tl fx_items
Definition: cmd_internal.h:80
#define SPIEL_CONF_OBJ_FIND(confc, fid, conf_obj, filter,...)
Definition: cmd_internal.h:33
M0_INTERNAL const char * m0_rpc_machine_ep(const struct m0_rpc_machine *rmach)
Definition: rpc_machine.c:603
int m0_spiel_dix_repair_start(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1367
static void spiel__fs_stats_ctx_init(struct _fs_stats_ctx *fsx, struct m0_spiel_core *spc, const struct m0_conf_obj_type *item_type)
Definition: cmd.c:1940
int m0_spiel_pool_repair_status(struct m0_spiel *spl, const struct m0_fid *pool_fid, struct m0_spiel_sns_status **statuses)
Definition: cmd.c:1496
M0_INTERNAL struct m0_fop * m0_ss_process_fop_create(struct m0_rpc_machine *mach, uint32_t cmd, const struct m0_fid *fid)
Definition: process_fops.c:156
static struct m0_rpc_item * item
Definition: item.c:56
M0_INTERNAL bool m0_conf_obj_is_stub(const struct m0_conf_obj *obj)
Definition: obj.c:302
struct m0_fop_getxattr_rep * rep
Definition: dir.c:455
int m0_rpc_item_wait_for_reply(struct m0_rpc_item *item, m0_time_t timeout)
Definition: item.c:824
static bool _filter_objv(const struct m0_conf_obj *obj)
Definition: cmd.c:1188
int m0_spiel_pool_rebalance_continue(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1560
uint32_t op
Definition: trigger_fop.h:52
static void spiel_process_health_replied_ast(struct m0_sm_group *grp, struct m0_sm_ast *ast)
Definition: cmd.c:1783
static struct foo * obj
Definition: tlist.c:302
const struct m0_conf_obj_type M0_CONF_CONTROLLER_TYPE
Definition: controller.c:131
struct m0_clink sci_rlink_wait
Definition: cmd.c:1688
struct m0_fop_type m0_fop_process_fopt
Definition: process_fops.c:42
static int spiel_process__counters_async(struct spiel_proc_counter_item *proc)
Definition: cmd.c:2173
#define m0_tl_endfor
Definition: tlist.h:700
struct m0_fid fid
Definition: di.c:46
int m0_spiel_sns_rebalance_start(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1504
static int spiel_running_svcs_list_fill(struct m0_bufs *bufs, struct m0_spiel_running_svc **svcs)
Definition: cmd.c:829
struct m0_clink spi_rlink_wait
Definition: cmd.c:1722
int m0_spiel_sns_repair_start(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1357
int m0_spiel_device_format(struct m0_spiel *spl, const struct m0_fid *dev_fid)
Definition: cmd.c:667
int m0_spiel_conf_pver_status(struct m0_spiel *spl, struct m0_fid *fid, struct m0_conf_pver_info *out_info)
Definition: cmd.c:2397
return M0_RC(rc)
op
Definition: libdemo.c:64
struct m0_fid srs_fid
Definition: spiel.h:166
static int spiel_ss_ep_for_svc(const struct m0_conf_service *s, char **ss_ep)
Definition: cmd.c:376
int m0_spiel_device_detach(struct m0_spiel *spl, const struct m0_fid *dev_fid)
Definition: cmd.c:658
Definition: sock.c:754
int sr_rc
Definition: cmd.c:935
m0_repreb_type
Definition: spiel.h:183
#define M0_ENTRY(...)
Definition: trace.h:170
Definition: buf.h:37
static struct m0_sm_ast ast[NR]
Definition: locality.c:44
M0_TL_DESCR_DEFINE(spiel_string, "list of endpoints", static, struct spiel_string_entry, sse_link, sse_magic, M0_STATS_MAGIC, M0_STATS_HEAD_MAGIC)
Definition: filter.py:1
int m0_spiel_sns_repair_continue(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1384
void m0_fop_put0_lock(struct m0_fop *fop)
Definition: fop.c:213
int i
Definition: dir.c:1033
int m0_spiel_process_reconfig(struct m0_spiel *spl, const struct m0_fid *proc_fid)
Definition: cmd.c:788
int m0_spiel_service_status(struct m0_spiel *spl, const struct m0_fid *svc_fid, int *status)
Definition: cmd.c:556
struct m0_sm_ast sci_ast
Definition: cmd.c:1698
struct m0_spiel_core * pl_spc
Definition: cmd.c:1000
struct m0_spiel::m0_spiel_core spl_core
struct m0_rpc_machine * m0_fop_rpc_machine(const struct m0_fop *fop)
Definition: fop.c:360
#define M0_ERR_INFO(rc, fmt,...)
Definition: trace.h:215
struct m0_conf_root * root
Definition: note.c:50
struct m0_fid ss_id
Definition: ss_fops.h:71
return M0_ERR(-EOPNOTSUPP)
struct m0_mutex fx_guard
Definition: cmd_internal.h:83
M0_INTERNAL void m0_rpc_machine_unlock(struct m0_rpc_machine *machine)
Definition: rpc_machine.c:558
int m0_spiel_pool_rebalance_status(struct m0_spiel *spl, const struct m0_fid *pool_fid, struct m0_spiel_sns_status **statuses)
Definition: cmd.c:1623
static void spiel_process__health_async(struct _fs_stats_ctx *fsx, struct spiel_proc_item *proc)
Definition: cmd.c:1910
const char * name
Definition: trace.c:110
#define M0_AMB(obj, ptr, field)
Definition: misc.h:320
struct m0_rpc_link spi_rlink
Definition: cmd.c:1717
struct m0_buf ss_name
Definition: ss_fops.h:66
#define m0_tl_teardown(name, head, obj)
Definition: tlist.h:708
static int spiel_process_command_send(struct m0_spiel_core *spc, const struct m0_fid *proc_fid, struct m0_fop *fop, struct m0_rpc_link **rlink)
Definition: cmd.c:699
static struct m0_confc * spiel_confc(struct m0_spiel *spl)
int m0_spiel_process_stop(struct m0_spiel *spl, const struct m0_fid *proc_fid)
Definition: cmd.c:781
#define M0_ASSERT(cond)
struct m0_rpc_link sr_rlink
Definition: cmd.c:932
m0_bcount_t fx_free_seg
Definition: cmd_internal.h:75
static bool spiel__item_enlist(const struct m0_conf_obj *item, void *ctx)
Definition: cmd.c:1973
M0_INTERNAL int m0_conf_cache_to_string(struct m0_conf_cache *cache, char **str, bool debug)
Definition: cache.c:257
M0_INTERNAL const char * m0_conf_service_type2str(enum m0_conf_service_type type)
Definition: service.c:169
static struct m0_confc * confc
Definition: file.c:94
char * spls_name
Definition: spiel.h:927
static int spiel_repreb_fop_fill_and_send(struct m0_spiel_core *spc, struct m0_fop *fop, enum m0_cm_op op, struct spiel_repreb *repreb)
Definition: cmd.c:978
static bool spiel_proc_item_disconnect_cb(struct m0_clink *clink)
Definition: cmd.c:1760
static int spiel_svc_conf_obj_find(struct m0_spiel_core *spc, const struct m0_fid *svc, struct m0_conf_service **out)
Definition: cmd.c:394
m0_bcount_t fx_avail_disk
Definition: cmd_internal.h:78
static int _spiel_conf_dir_iterate(struct m0_confc *confc, void *ctx, bool(*iter_cb)(const struct m0_conf_obj *item, void *ctx), uint32_t nr_lvls, const struct m0_fid *path)
Definition: cmd.c:320
static struct m0_ss_process_rep * spiel_process_reply_data(struct m0_fop *fop)
Definition: cmd.c:728
static struct m0_rpc_machine rmachine
Definition: formation2.c:36
uint32_t fx_svc_replied
Definition: cmd_internal.h:74
static int spiel_node_process_endpoint_add(struct m0_spiel_core *spc, struct m0_conf_obj *node, struct m0_tl *list)
Definition: cmd.c:85
struct m0_conf_obj * m0_conf_obj_grandparent(const struct m0_conf_obj *obj)
Definition: obj.c:384
enum m0_ha_obj_state co_ha_state
Definition: obj.h:241
int m0_spiel_process_quiesce(struct m0_spiel *spl, const struct m0_fid *proc_fid)
Definition: cmd.c:821
Definition: tlist.h:251
int m0_spiel_dix_rebalance_status(struct m0_spiel *spl, const struct m0_fid *pool_fid, struct m0_spiel_repreb_status **statuses)
Definition: cmd.c:1608
M0_INTERNAL int m0_conf_obj_ha_update(const struct m0_fid *obj_fid)
Definition: helpers.c:587
static bool spiel__pool_service_select(const struct m0_conf_obj *item, void *ctx)
Definition: cmd.c:1106
static bool spiel__pool_service_has_sdev(struct _pool_cmd_ctx *ctx, const struct m0_conf_obj *service)
Definition: cmd.c:1039
int m0_spiel_service_quiesce(struct m0_spiel *spl, const struct m0_fid *svc_fid)
Definition: cmd.c:546
int m0_spiel_service_init(struct m0_spiel *spl, const struct m0_fid *svc_fid)
Definition: cmd.c:507
#define M0_BUF_INIT0
Definition: buf.h:71
static void spiel__pool_ctx_init(struct _pool_cmd_ctx *ctx, struct m0_spiel_core *spc, enum m0_repreb_type type)
Definition: cmd.c:1065
M0_INTERNAL struct m0_ss_process_req * m0_ss_fop_process_req(struct m0_fop *fop)
Definition: process_fops.c:183
int m0_spiel_dix_repair_status(struct m0_spiel *spl, const struct m0_fid *pool_fid, struct m0_spiel_repreb_status **statuses)
Definition: cmd.c:1480
int m0_spiel_pool_repair_abort(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1459
static int spiel_svc_generic_handler(struct m0_spiel_core *spc, const struct m0_fid *svc_fid, enum m0_sss_req_cmd cmd, int *status)
Definition: cmd.c:476
struct m0_confc * spc_confc
Definition: spiel.h:210
int m0_spiel_dix_rebalance_quiesce(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1576
struct m0_semaphore fx_barrier
Definition: cmd_internal.h:85
int m0_spiel_confstr(struct m0_spiel *spl, char **out)
Definition: cmd.c:2380
struct m0_fop * m0_fop_get(struct m0_fop *fop)
Definition: fop.c:162
uint64_t sci_magic
Definition: cmd.c:1701
static void spiel_proc_item_disconnect_ast(struct m0_sm_group *grp, struct m0_sm_ast *ast)
Definition: cmd.c:1832
struct m0_rpc_item * ri_reply
Definition: item.h:163
M0_INTERNAL int m0_buf_alloc(struct m0_buf *buf, size_t size)
Definition: buf.c:43
M0_INTERNAL const struct m0_fid_type * m0_fid_type_getfid(const struct m0_fid *fid)
Definition: fid.c:76
M0_INTERNAL int m0_semaphore_init(struct m0_semaphore *semaphore, unsigned value)
Definition: semaphore.c:38
static char * proc_fid
Definition: m0hsm.c:45
M0_INTERNAL void m0_mutex_init(struct m0_mutex *mutex)
Definition: mutex.c:35
struct m0_fid sci_fid
Definition: cmd.c:1679
uint64_t ri_nr_sent_max
Definition: item.h:146
#define M0_POST(cond)
static void fop_fini(void)
Definition: iterator_test.c:41
const struct m0_conf_obj_type M0_CONF_DRIVE_TYPE
Definition: drive.c:108
uint32_t fx_svc_total
Definition: cmd_internal.h:72
struct m0_rpc_item_ops spiel_process_counter_ops
Definition: cmd.c:2110
static struct m0_sss_rep * spiel_sss_reply_data(struct m0_fop *fop)
Definition: cmd.c:468
static struct m0_rpc_machine * spiel_rmachine(struct m0_spiel *spl)
enum m0_cm_status srs_state
Definition: spiel.h:168
static int spiel_svc_fop_fill_and_send(struct m0_spiel_core *spc, struct m0_fop *fop, const struct m0_fid *svc_fid, uint32_t cmd, struct m0_rpc_link **rlink)
Definition: cmd.c:431
M0_INTERNAL int m0_fop_data_alloc(struct m0_fop *fop)
Definition: fop.c:71
m0_sss_device_req_cmd
Definition: device_fops.h:128
M0_INTERNAL void m0_buf_free(struct m0_buf *buf)
Definition: buf.c:55
M0_INTERNAL void m0_fop_fini(struct m0_fop *fop)
Definition: fop.c:136
#define M0_CONF_CAST(ptr, type)
Definition: obj.h:780
struct m0_conf_sdev * ck_sdev
Definition: obj.h:710
M0_INTERNAL bool m0_confc_is_inited(const struct m0_confc *confc)
Definition: confc.c:448
static struct m0_clink clink[RDWR_REQUEST_MAX]
struct m0_conf_service * sr_service
Definition: cmd.c:933
struct m0_tl pl_sdevs_fid
Definition: cmd.c:1001
int m0_spiel_pool_repair_start(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1378
#define m0_confc_open_sync(result, origin,...)
Definition: confc.h:707
int m0_spiel_device_attach(struct m0_spiel *spl, const struct m0_fid *dev_fid)
Definition: cmd.c:641
static struct fdmi_ctx ctx
Definition: main.c:80
#define FID_P(f)
Definition: fid.h:77
int m0_spiel_dix_repair_continue(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1394
m0_bcount_t fx_free_disk
Definition: cmd_internal.h:77
struct m0_buf pd_key
Definition: cmd.c:1666
static struct m0_sm_group * spiel_proc_sm_group(const struct spiel_proc_item *p)
Definition: cmd.c:1839
struct m0_mutex cc_lock
Definition: confc.h:391
M0_INTERNAL void m0_conf_obj_get_lock(struct m0_conf_obj *obj)
Definition: obj_ops.c:198
int m0_conf_pver_status(struct m0_fid *fid, struct m0_confc *confc, struct m0_conf_pver_info *out_info)
Definition: pvers.c:837
struct m0_spiel_core * fx_spc
Definition: cmd_internal.h:71
int m0_spiel_service_stop(struct m0_spiel *spl, const struct m0_fid *svc_fid)
Definition: cmd.c:525
static uint32_t timeout
Definition: console.c:52
struct m0_conf_node * ce_node
Definition: obj.h:682
int m0_spiel_service_health(struct m0_spiel *spl, const struct m0_fid *svc_fid)
Definition: cmd.c:537
static void spiel_process_disconnect_async(struct spiel_proc_item *proc)
Definition: cmd.c:1770
void(* rio_replied)(struct m0_rpc_item *item)
Definition: item.h:300
M0_INTERNAL bool m0_fid_eq(const struct m0_fid *fid0, const struct m0_fid *fid1)
Definition: fid.c:164
const char * ft_name
Definition: fid.h:102
M0_INTERNAL struct m0_conf_obj * m0_conf_diter_result(const struct m0_conf_diter *it)
Definition: diter.c:576
static void _fs_stats_ctx_lock(struct _fs_stats_ctx *fsx)
Definition: cmd.c:1739
static int spiel_endpoints_for_device_generic(struct m0_spiel_core *spc, const struct m0_fid *drive, struct m0_tl *out)
Definition: cmd.c:129
struct m0_conf_obj pc_obj
Definition: obj.h:581
#define m0_conf_diter_init(iter, confc, origin,...)
Definition: diter.h:235
m0_sss_req_cmd
Definition: ss_fops.h:46
int32_t m0_rpc_item_error(const struct m0_rpc_item *item)
Definition: item.c:973
static int spiel_repreb_cmd_send(struct m0_rpc_machine *rmachine, const char *remote_ep, struct spiel_repreb *repreb)
Definition: cmd.c:939
static int spiel_pool__device_collection_fill(struct _pool_cmd_ctx *ctx, const struct m0_fid *pool_fid)
Definition: cmd.c:1194
static void spiel_process_counter_replied(struct m0_rpc_item *item)
Definition: cmd.c:2099
static int spiel__proc_is_to_update_stats(struct spiel_proc_item *proc, struct m0_confc *confc)
Definition: cmd.c:2003
static int spiel_device_command_fop_send(struct m0_spiel_core *spc, const char *endpoint, const struct m0_fid *dev_fid, int cmd, uint32_t *ha_state)
Definition: cmd.c:571
#define SPIEL_CONF_DIR_ITERATE(confc, ctx, iter_cb,...)
Definition: cmd_internal.h:40
M0_INTERNAL struct m0_sss_device_fop_rep * m0_sss_fop_to_dev_rep(struct m0_fop *fop)
Definition: device_fops.c:129
struct m0_tl pl_services_fid
Definition: cmd.c:1002
char * ep
Definition: sw.h:132
struct m0_fid spi_fid
Definition: cmd.c:1715
static bool _filter_proc(const struct m0_conf_obj *obj)
Definition: cmd.c:679
int m0_spiel_dix_rebalance_start(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1514
#define M0_CNT_INC(cnt)
Definition: arith.h:226
int m0_spiel_node_direct_rebalance_start(struct m0_spiel *spl, const struct m0_fid *node_fid)
Definition: cmd.c:1541
#define M0_FI_ENABLED(tag)
Definition: finject.h:231
Definition: fid.h:38
const struct m0_conf_obj_type M0_CONF_NODE_TYPE
Definition: node.c:128
#define M0_IS0(obj)
Definition: misc.h:70
M0_INTERNAL void m0_rpc_machine_lock(struct m0_rpc_machine *machine)
Definition: rpc_machine.c:551
int m0_spiel_pool_rebalance_abort(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1652
int m0_spiel_process_list_services(struct m0_spiel *spl, const struct m0_fid *proc_fid, struct m0_spiel_running_svc **services)
Definition: cmd.c:858
static void spiel_process_counter_replied_ast(struct m0_sm_group *grp, struct m0_sm_ast *ast)
Definition: cmd.c:2050
static int spiel_cmd_send(struct m0_rpc_machine *rmachine, const char *remote_ep, struct m0_fop *cmd_fop, m0_time_t timeout, struct m0_rpc_link **rlink)
Definition: cmd.c:191
static bool _filter_sdev(const struct m0_conf_obj *obj)
Definition: cmd.c:1034
static void spiel__pool_ctx_fini(struct _pool_cmd_ctx *ctx)
Definition: cmd.c:1078
M0_INTERNAL void m0_fop_release(struct m0_ref *ref)
Definition: fop.c:148
int m0_spiel_sns_repair_quiesce(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1411
struct m0_tl * sci_counters
Definition: cmd.c:1694
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
int m0_spiel_filesystem_stats_fetch(struct m0_spiel *spl, struct m0_fs_stats *stats)
Definition: cmd.c:2374
M0_INTERNAL void m0_semaphore_fini(struct m0_semaphore *semaphore)
Definition: semaphore.c:45
Definition: beck.c:130
struct m0_conf_obj cn_obj
Definition: obj.h:562
const struct m0_rpc_item_ops * ri_ops
Definition: item.h:149
struct m0_conf_obj cs_obj
Definition: obj.h:595
m0_time_t m0_time_from_now(uint64_t secs, long ns)
Definition: time.c:96
M0_INTERNAL void m0_conf_diter_fini(struct m0_conf_diter *it)
Definition: diter.c:313
uint32_t pd_kv_count
Definition: cmd.c:1668
int m0_spiel_process_health(struct m0_spiel *spl, const struct m0_fid *proc_fid)
Definition: cmd.c:814
struct m0_rpc_session * ri_session
Definition: item.h:147
static struct m0_net_test_service svc
Definition: service.c:34
struct m0_conf_obj sd_obj
Definition: obj.h:616
int m0_spiel_process_lib_load(struct m0_spiel *spl, const struct m0_fid *proc_fid, const char *libname)
Definition: cmd.c:892
static struct m0_fop * spiel_svc_fop_alloc(struct m0_rpc_machine *mach)
Definition: cmd.c:463
uint32_t spi_svc_count
Definition: cmd.c:1729
M0_INTERNAL void m0_mutex_fini(struct m0_mutex *mutex)
Definition: mutex.c:42
M0_INTERNAL void m0_clink_fini(struct m0_clink *link)
Definition: chan.c:208
struct m0_tlink pd_link
Definition: cmd.c:1669
void m0_fop_put_lock(struct m0_fop *fop)
Definition: fop.c:199
static void buf_free(struct m0_buf *bufs, uint32_t count)
Definition: xform.c:453
static struct m0_fop * fop
Definition: item.c:57
static int spiel_stats_item_add(struct m0_tl *tl, const struct m0_fid *fid)
Definition: cmd.c:909
int m0_spiel_sns_rebalance_abort(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1631
int m0_spiel_pool_repair_continue(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1405
static int _spiel_conf_obj_find(struct m0_confc *confc, const struct m0_fid *obj_fid, bool(*filter)(const struct m0_conf_obj *obj), uint32_t nr_lvls, const struct m0_fid *path, struct m0_conf_obj **conf_obj)
Find object with given obj_fid in provided confc.
Definition: cmd.c:258
struct m0_fop * m0_rpc_item_to_fop(const struct m0_rpc_item *item)
Definition: fop.c:346
struct m0_fid spls_fid
Definition: spiel.h:925
uint64_t spi_magic
Definition: cmd.c:1730
static int spiel_device_command_send(struct m0_spiel_core *spc, const struct m0_fid *drive, enum m0_sss_device_req_cmd cmd, uint32_t *ha_state)
Definition: cmd.c:606
Definition: buf.h:43
M0_INTERNAL void m0_confc_close(struct m0_conf_obj *obj)
Definition: confc.c:921
struct m0_rconfc spl_rconfc
Definition: spiel.h:213
enum m0_repreb_type pl_service_type
Definition: cmd.c:1003
static uint64_t found
Definition: base.c:376
struct m0_proc_data sci_data
Definition: cmd.c:1696
#define SPIEL_DEVICE_FORMAT_TIMEOUT
Definition: cmd_internal.h:51
struct m0_spiel_repreb_status sr_status
Definition: cmd.c:930
static void spiel_rpc_link_destroy(struct m0_rpc_link *rlink)
Definition: cmd.c:61
int32_t ssr_rc
Definition: ss_fops.h:81
M0_INTERNAL void m0_semaphore_down(struct m0_semaphore *semaphore)
Definition: semaphore.c:49
static bool _filter_svc(const struct m0_conf_obj *obj)
Definition: cmd.c:75
const struct m0_conf_obj_type * fx_type
Definition: cmd_internal.h:82
struct m0_fop spi_fop
Definition: cmd.c:1724
const struct m0_conf_obj_type M0_CONF_PROCESS_TYPE
Definition: process.c:161
Definition: nucleus.c:42
static int spiel_proc_conf_obj_find(struct m0_spiel_core *spc, const struct m0_fid *proc, struct m0_conf_process **out)
Definition: cmd.c:684
struct m0_fid pc_proc_fid
Definition: spiel.h:1280
#define SPIEL_LOGLVL
Definition: cmd_internal.h:88
#define out(...)
Definition: gen.c:41
M0_INTERNAL int m0_dix_cm_trigger_fop_alloc(struct m0_rpc_machine *mach, uint32_t op, struct m0_fop **fop)
struct m0_rpc_item_ops spiel_process_health_ops
Definition: cmd.c:1855
int type
Definition: dir.c:1031
M0_INTERNAL void m0_semaphore_up(struct m0_semaphore *semaphore)
Definition: semaphore.c:65
#define M0_FID0
Definition: fid.h:93
int m0_spiel_proc_counters_fetch(struct m0_spiel *spl, struct m0_fid *proc_fid, struct m0_proc_counter *count_stats)
Definition: cmd.c:2211
static int spiel_process_command(struct m0_spiel *spl, const struct m0_fid *proc_fid, int cmd)
Definition: cmd.c:773
static void spiel__fs_stats_ctx_fini(struct _fs_stats_ctx *fsx)
Definition: cmd.c:1953
struct m0_rpc_machine * ri_rmachine
Definition: item.h:160
static struct m0_dtm_oper_descr reply
Definition: transmit.c:94
struct m0_rpc_link sci_rlink
Definition: cmd.c:1681
#define m0_tl_find(name, var, head,...)
Definition: tlist.h:757
#define m0_tl_for(name, head, obj)
Definition: tlist.h:695
void m0_free(void *data)
Definition: memory.c:146
static struct m0_addb2_source * s
Definition: consumer.c:39
void m0_fop_put(struct m0_fop *fop)
Definition: fop.c:177
M0_INTERNAL struct m0_ss_process_svc_list_rep * m0_ss_fop_process_svc_list_rep(struct m0_fop *fop)
Definition: process_fops.c:200
struct m0_rpc_item f_item
Definition: fop.h:83
M0_INTERNAL int m0_conf__diter_init(struct m0_conf_diter *it, struct m0_confc *confc, struct m0_conf_obj *origin, uint32_t nr_lvls, const struct m0_fid *path)
Definition: diter.c:282
#define M0_BUF_INIT_CONST(size, data)
Definition: buf.h:66
M0_INTERNAL int m0_confc_open_by_fid_sync(struct m0_confc *confc, const struct m0_fid *fid, struct m0_conf_obj **result)
Definition: confc.c:943
static struct m0_reqh_service * service[REQH_IN_UT_MAX]
Definition: long_lock_ut.c:46
struct m0_pdclust_src_addr src
Definition: fd.c:108
static int spiel_process__health(struct m0_spiel_core *spc, const struct m0_fid *proc_fid)
Definition: cmd.c:796
static void count_stats_failed_free(struct m0_proc_counter *count_stats, int failed_index)
Definition: cmd.c:2198
int32_t rc
Definition: trigger_fop.h:47
static struct sync_interactions si
Definition: sync.c:121
int m0_spiel_pool_repair_quiesce(struct m0_spiel *spl, const struct m0_fid *pool_fid)
Definition: cmd.c:1432
const m0_time_t M0_TIME_IMMEDIATELY
Definition: time.c:107
Definition: fop.h:79
struct m0_conf_obj * cv_real
Definition: obj.h:558
#define FID_F
Definition: fid.h:75
static void spiel_process_health_replied(struct m0_rpc_item *item)
Definition: cmd.c:1844
m0_bcount_t fx_total_seg
Definition: cmd_internal.h:76
struct m0_fop * rep_fop
Definition: dir.c:334
static int spiel_svc_fop_fill(struct m0_fop *fop, struct m0_conf_service *svc, uint32_t cmd)
Definition: cmd.c:410
m0_time_t ri_deadline
Definition: item.h:141
struct m0_fop * m0_fop_alloc(struct m0_fop_type *fopt, void *data, struct m0_rpc_machine *mach)
Definition: fop.c:96
static int spiel__pool_cmd_send(struct _pool_cmd_ctx *ctx, const enum m0_cm_op cmd, struct spiel_repreb *repreb)
Definition: cmd.c:1127