Motr  M0
cm.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-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 #pragma once
24 
25 #ifndef __MOTR_CM_CM_H__
26 #define __MOTR_CM_CM_H__
27 
28 #include "lib/tlist.h" /* struct m0_tlink */
29 #include "lib/types.h" /* uint8_t */
30 
31 #include "reqh/reqh_service.h" /* struct m0_reqh_service_type */
32 #include "sm/sm.h" /* struct m0_sm */
33 #include "fop/fom.h" /* struct m0_fom */
34 #include "fop/fom_simple.h"
35 
36 #include "cm/sw.h"
37 #include "cm/ag.h"
38 #include "cm/pump.h"
39 #include "cm/ag_store.h"
40 #include "ha/msg.h"
41 
116 /* Import */
117 struct m0_fop;
118 struct m0_net_buffer_pool;
119 struct m0_layout;
120 
135 };
136 
137 enum {
138  CM_RPC_TIMEOUT = 20, /* seconds */
140 };
141 
143 struct m0_cm_type {
148  uint64_t ct_fom_id;
157  uint64_t ct_magix;
158 };
159 
162  bool car_run;
163 };
164 
166 struct m0_cm {
167  struct m0_sm cm_mach;
168 
174  uint64_t cm_id;
175 
178 
186 
188  const struct m0_cm_ops *cm_ops;
189 
192 
194  const struct m0_cm_type *cm_type;
195 
204 
206 
221 
223 
225 
232 
234 
235  struct m0_chan cm_wait;
237 
239 
241 
247 
249 
250  uint64_t cm_proxy_nr;
251 
255 
258 
260 
262 
264 
265  bool cm_done;
266 
271  bool cm_reset;
272 
278 
282  bool cm_abort;
283 };
284 
286 struct m0_cm_ops {
292  int (*cmo_setup)(struct m0_cm *cm);
293 
294  int (*cmo_prepare)(struct m0_cm *cm);
295 
301  int (*cmo_start)(struct m0_cm *cm);
302 
304  void (*cmo_stop)(struct m0_cm *cm);
305 
306  int (*cmo_ag_alloc)(struct m0_cm *cm, const struct m0_cm_ag_id *id,
307  bool has_incoming, struct m0_cm_aggr_group **out);
308 
310  struct m0_cm_cp *(*cmo_cp_alloc)(struct m0_cm *cm);
311 
318  int (*cmo_data_next)(struct m0_cm *cm, struct m0_cm_cp *cp);
319 
324  int (*cmo_ag_next)(struct m0_cm *cm,
325  const struct m0_cm_ag_id *id_curr,
326  struct m0_cm_ag_id *id_next);
327 
335  int (*cmo_get_space_for)(struct m0_cm *cm, const struct m0_cm_ag_id *id,
336  size_t *count);
337 
343  void (*fop_release)(struct m0_ref *),
344  uint64_t proxy_id, const char *local_ep,
345  const struct m0_cm_sw *sw,
346  const struct m0_cm_sw *out_interval);
353  bool (*cmo_is_peer)(struct m0_cm *cm, struct m0_reqh_service_ctx *ctx);
354 
356  void (*cmo_ha_msg)(struct m0_cm *cm,
357  struct m0_ha_msg *msg, int rc);
358 
360  void (*cmo_fini)(struct m0_cm *cm);
361 };
362 
363 M0_INTERNAL int m0_cm_type_register(struct m0_cm_type *cmt);
364 M0_INTERNAL void m0_cm_type_deregister(struct m0_cm_type *cmt);
365 
370 M0_INTERNAL void m0_cm_lock(struct m0_cm *cm);
371 M0_INTERNAL int m0_cm_trylock(struct m0_cm *cm);
372 
374 M0_INTERNAL void m0_cm_unlock(struct m0_cm *cm);
375 
381 M0_INTERNAL bool m0_cm_is_locked(const struct m0_cm *cm);
382 
383 M0_INTERNAL int m0_cm_module_init(void);
384 M0_INTERNAL void m0_cm_module_fini(void);
385 
394 M0_INTERNAL int m0_cm_init(struct m0_cm *cm, struct m0_cm_type *cm_type,
395  const struct m0_cm_ops *cm_ops);
396 
403 M0_INTERNAL void m0_cm_fini(struct m0_cm *cm);
404 
413 M0_INTERNAL int m0_cm_setup(struct m0_cm *cm);
414 
415 M0_INTERNAL int m0_cm_prepare(struct m0_cm *cm);
416 M0_INTERNAL int m0_cm_ready(struct m0_cm *cm);
417 
418 M0_INTERNAL bool m0_cm_is_ready(struct m0_cm *cm);
419 M0_INTERNAL bool m0_cm_is_active(struct m0_cm *cm);
420 
428 M0_INTERNAL int m0_cm_start(struct m0_cm *cm);
429 
441 M0_INTERNAL int m0_cm_stop(struct m0_cm *cm);
442 
449 M0_INTERNAL int m0_cm_configure(struct m0_cm *cm, struct m0_fop *fop);
450 
454 M0_INTERNAL int m0_ha_cm_err_send(struct m0_cm *cm, int rc);
455 
465 M0_INTERNAL void m0_cm_fail(struct m0_cm *cm, int rc);
466 
467 #define M0_CM_TYPE_DECLARE(cmtype, id, ops, name, typecode) \
468 M0_INTERNAL struct m0_cm_type cmtype ## _cmt = { \
469  .ct_fom_id = (id), \
470  .ct_stype = { \
471  .rst_name = (name), \
472  .rst_ops = (ops), \
473  .rst_level = M0_RS_LEVEL_NORMAL, \
474  .rst_typecode = (typecode) \
475  } \
476 }
477 
479 M0_INTERNAL bool m0_cm_invariant(const struct m0_cm *cm);
480 
482 M0_INTERNAL void m0_cm_state_set(struct m0_cm *cm, enum m0_cm_state state);
483 M0_INTERNAL enum m0_cm_state m0_cm_state_get(const struct m0_cm *cm);
484 
489 M0_INTERNAL void m0_cm_continue(struct m0_cm *cm);
490 
500 M0_INTERNAL int m0_cm_data_next(struct m0_cm *cm, struct m0_cm_cp *cp);
501 
508 M0_INTERNAL bool m0_cm_has_more_data(const struct m0_cm *cm);
509 
510 M0_INTERNAL struct m0_net_buffer *m0_cm_buffer_get(struct m0_net_buffer_pool
511  *bp, uint64_t colour);
512 
513 M0_INTERNAL void m0_cm_buffer_put(struct m0_net_buffer_pool *bp,
514  struct m0_net_buffer *buf,
515  uint64_t colour);
516 
517 M0_INTERNAL struct m0_cm *m0_cmsvc2cm(struct m0_reqh_service *cmsvc);
518 
526 M0_INTERNAL int m0_cm_proxies_fini(struct m0_cm *cm);
527 
528 M0_INTERNAL struct m0_rpc_machine *m0_cm_rpc_machine_find(struct m0_reqh *reqh);
529 
530 M0_INTERNAL int m0_cm_ast_run_thread_init(struct m0_cm *cm);
531 M0_INTERNAL void m0_cm_ast_run_thread_fini(struct m0_cm *cm);
532 M0_INTERNAL void m0_cm_notify(struct m0_cm *cm);
533 M0_INTERNAL void m0_cm_wait(struct m0_cm *cm, struct m0_fom *fom);
534 M0_INTERNAL void m0_cm_wait_cancel(struct m0_cm *cm, struct m0_fom *fom);
535 M0_INTERNAL int m0_cm_complete(struct m0_cm *cm);
536 M0_INTERNAL void m0_cm_complete_notify(struct m0_cm *cm);
537 M0_INTERNAL void m0_cm_proxies_init_wait(struct m0_cm *cm, struct m0_fom *fom);
551 M0_INTERNAL void m0_cm_frozen_ag_cleanup(struct m0_cm *cm, struct m0_cm_proxy *proxy);
552 M0_INTERNAL void m0_cm_proxy_failed_cleanup(struct m0_cm *cm);
553 M0_INTERNAL void m0_cm_abort(struct m0_cm *cm, int rc);
554 M0_INTERNAL bool m0_cm_is_dirty(struct m0_cm *cm);
555 M0_INTERNAL bool m0_cm_proxies_updated(struct m0_cm *cm);
556 
559 /* __MOTR_CM_CM_H__ */
560 
561 #endif
562 
563 /*
564  * Local variables:
565  * c-indentation-style: "K&R"
566  * c-basic-offset: 8
567  * tab-width: 8
568  * fill-column: 80
569  * scroll-step: 1
570  * End:
571  */
uint64_t cm_aggr_grps_in_nr
Definition: cm.h:205
uint64_t id
Definition: cob.h:2380
M0_INTERNAL int m0_cm_ast_run_thread_init(struct m0_cm *cm)
Definition: cm.c:1215
int(* cmo_get_space_for)(struct m0_cm *cm, const struct m0_cm_ag_id *id, size_t *count)
Definition: cm.h:335
M0_INTERNAL void m0_cm_frozen_ag_cleanup(struct m0_cm *cm, struct m0_cm_proxy *proxy)
Definition: cm.c:1148
int(* cmo_ag_alloc)(struct m0_cm *cm, const struct m0_cm_ag_id *id, bool has_incoming, struct m0_cm_aggr_group **out)
Definition: cm.h:306
M0_INTERNAL void m0_cm_lock(struct m0_cm *cm)
Definition: cm.c:545
const struct m0_cm_type * cm_type
Definition: cm.h:194
M0_INTERNAL void m0_cm_fail(struct m0_cm *cm, int rc)
Definition: cm.c:527
M0_INTERNAL struct m0_rpc_machine * m0_cm_rpc_machine_find(struct m0_reqh *reqh)
Definition: cm.c:712
M0_INTERNAL bool m0_cm_is_dirty(struct m0_cm *cm)
Definition: cm.c:1193
Definition: sw.h:45
struct m0_bitmap cm_proxy_update_map
Definition: cm.h:252
M0_INTERNAL bool m0_cm_is_ready(struct m0_cm *cm)
Definition: cm.c:793
M0_INTERNAL bool m0_cm_is_active(struct m0_cm *cm)
Definition: cm.c:799
bool cm_quiesce
Definition: cm.h:277
const struct m0_cm_ops * cm_ops
Definition: cm.h:188
M0_INTERNAL void m0_cm_type_deregister(struct m0_cm_type *cmtype)
Definition: cm.c:1019
uint64_t m0_time_t
Definition: time.h:37
Definition: cp.h:160
struct m0_fom_type ct_ag_store_fomt
Definition: cm.h:156
M0_INTERNAL int m0_cm_stop(struct m0_cm *cm)
Definition: cm.c:866
void(* cmo_stop)(struct m0_cm *cm)
Definition: cm.h:304
uint64_t cm_id
Definition: cm.h:174
void fop_release(struct m0_ref *ref)
Definition: stats_ut_svc.c:148
M0_INTERNAL bool m0_cm_has_more_data(const struct m0_cm *cm)
Definition: cm.c:1052
M0_INTERNAL int m0_cm_trylock(struct m0_cm *cm)
Definition: cm.c:555
bool cm_done
Definition: cm.h:265
M0_INTERNAL void m0_cm_wait_cancel(struct m0_cm *cm, struct m0_fom *fom)
Definition: cm.c:1093
M0_INTERNAL int m0_ha_cm_err_send(struct m0_cm *cm, int rc)
Definition: cm.c:502
struct m0_fom_type ct_pump_fomt
Definition: cm.h:154
M0_INTERNAL void m0_cm_ast_run_thread_fini(struct m0_cm *cm)
Definition: cm.c:1223
int(* cmo_ag_next)(struct m0_cm *cm, const struct m0_cm_ag_id *id_curr, struct m0_cm_ag_id *id_next)
Definition: cm.h:324
M0_INTERNAL int m0_cm_start(struct m0_cm *cm)
Definition: cm.c:805
uint64_t cm_aggr_grps_out_nr
Definition: cm.h:233
M0_INTERNAL int m0_cm_module_init(void)
Definition: cm.c:895
M0_INTERNAL void m0_cm_fini(struct m0_cm *cm)
Definition: cm.c:964
int(* cmo_sw_onwire_fop_setup)(struct m0_cm *cm, struct m0_fop *fop, void(*fop_release)(struct m0_ref *), uint64_t proxy_id, const char *local_ep, const struct m0_cm_sw *sw, const struct m0_cm_sw *out_interval)
Definition: cm.h:342
M0_INTERNAL void m0_cm_state_set(struct m0_cm *cm, enum m0_cm_state state)
Definition: cm.c:570
Definition: sock.c:887
static m0_bcount_t count
Definition: xcode.c:167
int(* cmo_data_next)(struct m0_cm *cm, struct m0_cm_cp *cp)
Definition: cm.h:318
M0_INTERNAL int m0_cm_init(struct m0_cm *cm, struct m0_cm_type *cm_type, const struct m0_cm_ops *cm_ops)
Definition: cm.c:925
static struct m0_cm * cm
Definition: cm.c:63
M0_INTERNAL int m0_cm_data_next(struct m0_cm *cm, struct m0_cm_cp *cp)
Definition: cm.c:1034
M0_INTERNAL void m0_cm_unlock(struct m0_cm *cm)
Definition: cm.c:550
struct m0_tl cm_proxies
Definition: cm.h:246
uint64_t cm_nr_proxy_updated
Definition: cm.h:253
M0_INTERNAL void m0_cm_complete_notify(struct m0_cm *cm)
Definition: cm.c:1133
M0_INTERNAL bool m0_cm_proxies_updated(struct m0_cm *cm)
Definition: cm.c:1198
bool cm_reset
Definition: cm.h:271
struct m0_fom_type ct_fomt
Definition: cm.h:150
m0_cm_state
Definition: cm.h:125
struct m0_mutex cm_wait_mutex
Definition: cm.h:236
M0_INTERNAL struct m0_net_buffer * m0_cm_buffer_get(struct m0_net_buffer_pool *bp, uint64_t colour)
Definition: cm.c:1057
Definition: refs.h:34
int(* cmo_prepare)(struct m0_cm *cm)
Definition: cm.h:294
M0_INTERNAL int m0_cm_configure(struct m0_cm *cm, struct m0_fop *fop)
M0_INTERNAL void m0_cm_wait(struct m0_cm *cm, struct m0_fom *fom)
Definition: cm.c:1086
Definition: tlist.h:251
uint64_t ct_fom_id
Definition: cm.h:148
uint64_t ct_magix
Definition: cm.h:157
M0_INTERNAL void m0_cm_module_fini(void)
Definition: cm.c:907
struct m0_tlink ct_linkage
Definition: cm.h:147
Definition: msg.h:115
struct m0_cm_ag_id cm_last_out_hi
Definition: cm.h:222
struct m0_chan cm_wait
Definition: cm.h:235
Definition: reqh.h:94
Definition: dump.c:103
Definition: chan.h:229
Definition: cm.h:286
static struct fdmi_ctx ctx
Definition: main.c:80
struct m0_chan cm_complete
Definition: cm.h:238
M0_INTERNAL int m0_cm_setup(struct m0_cm *cm)
Definition: cm.c:595
M0_INTERNAL int m0_cm_ready(struct m0_cm *cm)
Definition: cm.c:759
void(* cmo_ha_msg)(struct m0_cm *cm, struct m0_ha_msg *msg, int rc)
Definition: cm.h:356
struct m0_chan cm_proxy_init_wait
Definition: cm.h:240
M0_INTERNAL void m0_cm_continue(struct m0_cm *cm)
struct m0_cm_ag_id cm_last_processed_out
Definition: cm.h:224
M0_INTERNAL void m0_cm_buffer_put(struct m0_net_buffer_pool *bp, struct m0_net_buffer *buf, uint64_t colour)
Definition: cm.c:1074
M0_INTERNAL struct m0_cm * m0_cmsvc2cm(struct m0_reqh_service *cmsvc)
Definition: cm.c:497
struct m0_fom_type ct_swu_fomt
Definition: cm.h:152
struct m0_sm_group cm_sm_group
Definition: cm.h:185
bool car_run
Definition: cm.h:162
Definition: fom.h:481
Definition: cm.h:143
void(* cmo_fini)(struct m0_cm *cm)
Definition: cm.h:360
struct m0_tl cm_aggr_grps_out
Definition: cm.h:231
uint64_t cm_proxy_nr
Definition: cm.h:250
M0_INTERNAL int m0_cm_prepare(struct m0_cm *cm)
Definition: cm.c:717
struct m0_reqh reqh
Definition: rm_foms.c:48
struct m0_cm_sw_update cm_sw_update
Definition: cm.h:259
M0_INTERNAL void m0_cm_notify(struct m0_cm *cm)
Definition: cm.c:1081
Definition: cm.h:134
static const char * local_ep(const struct m0_cm *cm)
Definition: cm_utils.c:397
struct m0_reqh_service cm_service
Definition: cm.h:191
uint64_t cm_proxy_active_nr
Definition: cm.h:254
M0_INTERNAL void m0_cm_proxies_init_wait(struct m0_cm *cm, struct m0_fom *fom)
Definition: cm.c:1142
Definition: cm.h:166
Definition: sm.h:301
M0_INTERNAL enum m0_cm_state m0_cm_state_get(const struct m0_cm *cm)
Definition: cm.c:565
int(* cmo_setup)(struct m0_cm *cm)
Definition: cm.h:292
static struct m0_fop * fop
Definition: item.c:57
struct m0_reqh_service_type ct_stype
Definition: cm.h:145
struct m0_thread car_th
Definition: cm.h:161
struct m0_cm_cp_pump cm_cp_pump
Definition: cm.h:257
bool(* cmo_is_peer)(struct m0_cm *cm, struct m0_reqh_service_ctx *ctx)
Definition: cm.h:353
static struct bulkio_params * bp
Definition: bulkio_ut.c:44
int(* cmo_start)(struct m0_cm *cm)
Definition: cm.h:301
#define out(...)
Definition: gen.c:41
struct m0_sm cm_mach
Definition: cm.h:167
M0_INTERNAL void m0_cm_abort(struct m0_cm *cm, int rc)
Definition: cm.c:1181
M0_INTERNAL bool m0_cm_invariant(const struct m0_cm *cm)
Definition: cm.c:585
struct m0_tl cm_aggr_grps_in
Definition: cm.h:203
M0_INTERNAL bool m0_cm_is_locked(const struct m0_cm *cm)
Definition: cm.c:560
struct m0_tl cm_failed_proxies
Definition: cm.h:248
Definition: mutex.h:47
M0_INTERNAL int m0_cm_complete(struct m0_cm *cm)
Definition: cm.c:1100
struct m0_cm_ast_run cm_asts_run
Definition: cm.h:263
int32_t rc
Definition: trigger_fop.h:47
bool cm_abort
Definition: cm.h:282
M0_INTERNAL int m0_cm_proxies_fini(struct m0_cm *cm)
Definition: cm.c:840
m0_time_t cm_epoch
Definition: cm.h:177
Definition: ag.h:49
M0_INTERNAL void m0_cm_proxy_failed_cleanup(struct m0_cm *cm)
Definition: cm.c:1172
Definition: fop.h:79
struct m0_cm_ag_store cm_ag_store
Definition: cm.h:261
struct m0_cm_ag_id cm_sw_last_updated_hi
Definition: cm.h:220
M0_INTERNAL int m0_cm_type_register(struct m0_cm_type *cmtype)
Definition: cm.c:995