Motr  M0
fom.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #pragma once
24 
25 #ifndef __MOTR_FOP_FOM_H__
26 #define __MOTR_FOP_FOM_H__
27 
199 /* import */
200 
201 #include "lib/queue.h"
202 #include "lib/thread.h"
203 #include "lib/bitmap.h"
204 #include "lib/mutex.h"
205 #include "lib/chan.h"
206 #include "lib/atomic.h"
207 #include "lib/tlist.h"
208 #include "lib/locality.h"
209 
210 #include "dtm/dtm.h" /* m0_dtx */
211 #include "fol/fol.h"
212 #include "stob/stob.h"
213 #include "addb2/counter.h"
214 #include "addb2/histogram.h"
215 #include "addb2/sys.h"
216 
217 struct m0_addb2_mach;
218 
219 /* import */
220 struct m0_reqh_service;
221 struct m0_reqh_service_type;
222 
223 /* export */
224 struct m0_fom_domain;
225 struct m0_fom_domain_ops;
226 struct m0_fom_locality;
227 struct m0_fom_type;
228 struct m0_fom_type_ops;
229 struct m0_fom;
230 struct m0_fom_ops;
231 struct m0_long_lock;
232 
233 /* defined in fom.c */
234 struct m0_loc_thread;
235 
236 #define FOM_PHASE_DEBUG (1)
237 
257 
259  struct m0_tl fl_runq;
260  size_t fl_runq_nr;
261 
263  struct m0_tl fl_wail;
264  size_t fl_wail_nr;
265 
271  unsigned fl_foms;
272 
275 
293  struct m0_chan fl_idle;
296  int fl_idx;
306 };
307 
314 M0_INTERNAL bool m0_locality_invariant(const struct m0_fom_locality *loc);
315 
319 M0_INTERNAL void m0_fom_locality_post_stats(struct m0_fom_locality *loc);
320 
335  const struct m0_fom_domain_ops *fd_ops;
339 };
340 
348  bool (*fdo_time_is_out)(const struct m0_fom_domain *dom,
349  const struct m0_fom *fom);
350 };
351 
367 };
368 
370 enum { M0_FOS_TRANS_NR = 8 };
371 
373  M0_FOM_PHASE_INIT, /*< 0 fom has been initialised. */
374  M0_FOM_PHASE_FINISH, /*< 1 terminal phase. */
376 };
377 
378 
387 M0_INTERNAL int m0_fom_domain_init(struct m0_fom_domain **dom);
388 
398 M0_INTERNAL void m0_fom_domain_fini(struct m0_fom_domain *dom);
399 
406 M0_INTERNAL bool m0_fom_domain_is_idle(const struct m0_fom_domain *dom);
407 M0_INTERNAL bool m0_fom_domain_is_idle_for(const struct m0_reqh_service *svc);
408 
413 M0_INTERNAL bool m0_fom_domain_invariant(const struct m0_fom_domain *dom);
414 
419 M0_INTERNAL void m0_fom_locality_inc(struct m0_fom *fom);
420 
427 M0_INTERNAL bool m0_fom_locality_dec(struct m0_fom *fom);
428 
435 };
436 
452  struct m0_fom *fc_fom;
458  bool (*fc_top)(struct m0_fom_callback *cb);
463  void (*fc_bottom)(struct m0_fom_callback *cb);
464 };
465 
481 struct m0_fom {
484  size_t fo_loc_idx;
485  const struct m0_fom_type *fo_type;
486  const struct m0_fom_ops *fo_ops;
490  struct m0_fop *fo_fop;
498  struct m0_dtx fo_tx;
503  bool fo_local;
514  unsigned fo_transitions;
518 
531 #if FOM_PHASE_DEBUG
532  int fo_log[32];
533 #endif
534  uint64_t fo_magic;
535 };
536 
537 static inline struct m0_be_tx *m0_fom_tx(struct m0_fom *fom)
538 {
539  return &fom->fo_tx.tx_betx;
540 }
541 
542 static inline struct m0_be_tx_credit *m0_fom_tx_credit(struct m0_fom *fom)
543 {
544  return &fom->fo_tx.tx_betx_cred;
545 }
546 
561 M0_INTERNAL void m0_fom_queue(struct m0_fom *fom);
562 
566 M0_INTERNAL struct m0_reqh *m0_fom_reqh(const struct m0_fom *fom);
567 
586 void m0_fom_init(struct m0_fom *fom, const struct m0_fom_type *fom_type,
587  const struct m0_fom_ops *ops, struct m0_fop *fop,
588  struct m0_fop *reply, struct m0_reqh *reqh);
600 void m0_fom_fini(struct m0_fom *fom);
601 
609 M0_INTERNAL bool m0_fom_invariant(const struct m0_fom *fom);
610 
612 struct m0_fom_type {
613  uint64_t ft_id;
614  const struct m0_fom_type_ops *ft_ops;
618 };
619 
645 };
646 
650  int (*fto_create)(struct m0_fop *fop, struct m0_fom **out,
651  struct m0_reqh *reqh);
652 };
653 
655 struct m0_fom_ops {
657  void (*fo_fini)(struct m0_fom *fom);
663  int (*fo_tick)(struct m0_fom *fom);
671  size_t (*fo_home_locality) (const struct m0_fom *fom);
675  void (*fo_addb2_descr)(struct m0_fom *fom);
676 
681  void (*fo_hung_notify)(const struct m0_fom *fom);
682 };
683 
690 M0_INTERNAL void m0_fom_block_enter(struct m0_fom *fom);
691 
697 M0_INTERNAL void m0_fom_block_leave(struct m0_fom *fom);
698 
707 M0_INTERNAL void m0_fom_ready(struct m0_fom *fom);
708 
714 M0_INTERNAL void m0_fom_wakeup(struct m0_fom *fom);
715 
719 M0_INTERNAL void m0_fom_callback_init(struct m0_fom_callback *cb);
720 
733 M0_INTERNAL void m0_fom_callback_arm(struct m0_fom *fom, struct m0_chan *chan,
734  struct m0_fom_callback *cb);
735 
739 M0_INTERNAL bool m0_fom_is_waiting_on(const struct m0_fom *fom);
740 
752 M0_INTERNAL void m0_fom_wait_on(struct m0_fom *fom, struct m0_chan *chan,
753  struct m0_fom_callback *cb);
754 
766 M0_INTERNAL void m0_fom_callback_fini(struct m0_fom_callback *cb);
767 
778 M0_INTERNAL void m0_fom_callback_cancel(struct m0_fom_callback *cb);
779 
796 };
797 
798 M0_INTERNAL void m0_fom_timeout_init(struct m0_fom_timeout *to);
799 M0_INTERNAL void m0_fom_timeout_fini(struct m0_fom_timeout *to);
800 
809 M0_INTERNAL int m0_fom_timeout_wait_on(struct m0_fom_timeout *to,
810  struct m0_fom *fom, m0_time_t deadline);
820 M0_INTERNAL int m0_fom_timeout_arm(struct m0_fom_timeout *to,
821  struct m0_fom *fom,
822  void (*cb)(struct m0_fom_callback *),
823  m0_time_t deadline);
831 M0_INTERNAL void m0_fom_timeout_cancel(struct m0_fom_timeout *to);
832 
837 M0_INTERNAL bool m0_fom_group_is_locked(const struct m0_fom *fom);
838 
846 M0_INTERNAL void m0_fom_sm_init(struct m0_fom *fom);
847 
848 void m0_fom_phase_set(struct m0_fom *fom, int phase);
849 
850 void m0_fom_phase_move(struct m0_fom *fom, int32_t rc, int phase);
851 
852 void m0_fom_phase_moveif(struct m0_fom *fom, int32_t rc, int phase0,
853  int phase1);
854 
855 int m0_fom_phase(const struct m0_fom *fom);
856 
857 M0_INTERNAL const char *m0_fom_phase_name(const struct m0_fom *fom, int phase);
858 
859 M0_INTERNAL int m0_fom_rc(const struct m0_fom *fom);
860 
861 M0_INTERNAL bool m0_fom_is_waiting(const struct m0_fom *fom);
862 
863 M0_INTERNAL void m0_fom_type_init(struct m0_fom_type *type, uint64_t id,
864  const struct m0_fom_type_ops *ops,
865  const struct m0_reqh_service_type *svc_type,
866  const struct m0_sm_conf *sm);
867 
868 M0_INTERNAL int m0_fom_addb2_init(struct m0_fom_type *type, uint64_t id);
869 
876 M0_INTERNAL int m0_fom_fol_rec_add(struct m0_fom *fom);
877 
881 M0_INTERNAL void m0_fom_fdmi_record_post(struct m0_fom *fom);
882 
883 M0_INTERNAL struct m0_reqh *m0_fom2reqh(const struct m0_fom *fom);
884 
902 M0_INTERNAL int m0_fom_timedwait(struct m0_fom *fom, uint64_t phases,
903  m0_time_t deadline);
904 
905 #endif /* __MOTR_FOP_FOM_H__ */
906 
908 /*
909  * Local variables:
910  * c-indentation-style: "K&R"
911  * c-basic-offset: 8
912  * tab-width: 8
913  * fill-column: 80
914  * scroll-step: 1
915  * End:
916  */
struct m0_addb2_sensor fl_clock
Definition: fom.h:301
M0_INTERNAL void m0_fom_domain_fini(struct m0_fom_domain *dom)
Definition: fom.c:1256
void m0_fom_phase_moveif(struct m0_fom *fom, int32_t rc, int phase0, int phase1)
Definition: fom.c:1710
M0_INTERNAL void m0_fom_wakeup(struct m0_fom *fom)
Definition: fom.c:532
Definition: dtm.h:554
static struct m0_sm_state_descr phases[]
Definition: stats_fom.c:31
size_t fo_loc_idx
Definition: fom.h:484
struct m0_tl fl_runq
Definition: fom.h:259
struct m0_fop * fo_fop
Definition: fom.h:490
struct m0_fom_domain * fl_dom
Definition: fom.h:256
M0_INTERNAL void m0_fom_block_enter(struct m0_fom *fom)
Definition: fom.c:538
uint64_t ft_id
Definition: fom.h:613
struct m0_loc_thread * fl_handler
Definition: fom.h:289
struct m0_addb2_hist fl_fom_active
Definition: fom.h:298
M0_INTERNAL bool m0_fom_locality_dec(struct m0_fom *fom)
Definition: fom.c:1309
struct m0_bitmap fl_processors
Definition: fom.h:295
Definition: sm.h:350
struct m0_fom_callback to_cb
Definition: fom.h:795
int(* fo_tick)(struct m0_fom *fom)
Definition: fom.h:663
uint64_t m0_time_t
Definition: time.h:37
struct m0_tlink fo_linkage
Definition: fom.h:511
static struct m0_be_tx_credit * m0_fom_tx_credit(struct m0_fom *fom)
Definition: fom.h:542
struct m0_sm_group fl_group
Definition: fom.h:274
unsigned fo_transitions_saved
Definition: fom.h:517
struct m0_chan fl_idle
Definition: fom.h:293
M0_INTERNAL int m0_fom_domain_init(struct m0_fom_domain **out)
Definition: fom.c:1173
int(* fto_create)(struct m0_fop *fop, struct m0_fom **out, struct m0_reqh *reqh)
Definition: fom.h:650
M0_INTERNAL void m0_fom_callback_init(struct m0_fom_callback *cb)
Definition: fom.c:1454
int fl_idx
Definition: fom.h:296
m0_fc_state
Definition: fom.h:432
struct m0_dtx fo_tx
Definition: fom.h:498
M0_INTERNAL void m0_fom_wait_on(struct m0_fom *fom, struct m0_chan *chan, struct m0_fom_callback *cb)
Definition: fom.c:1490
Definition: sm.h:504
m0_fom_phase
Definition: fom.h:372
static struct m0_be_tx * m0_fom_tx(struct m0_fom *fom)
Definition: fom.h:537
M0_INTERNAL int m0_fom_timeout_arm(struct m0_fom_timeout *to, struct m0_fom *fom, void(*cb)(struct m0_fom_callback *), m0_time_t deadline)
Definition: fom.c:1573
struct m0_locality_chore fd_hung_foms_chore
Definition: fom.h:337
struct m0_sm fo_sm_state
Definition: fom.h:524
M0_INTERNAL int m0_fom_timeout_wait_on(struct m0_fom_timeout *to, struct m0_fom *fom, m0_time_t deadline)
Definition: fom.c:1566
void m0_fom_init(struct m0_fom *fom, const struct m0_fom_type *fom_type, const struct m0_fom_ops *ops, struct m0_fop *fop, struct m0_fop *reply, struct m0_reqh *reqh)
Definition: fom.c:1372
struct m0_locality fl_locality
Definition: fom.h:302
M0_INTERNAL bool m0_fom_is_waiting(const struct m0_fom *fom)
Definition: fom.c:1732
bool fl_shutdown
Definition: fom.h:287
struct m0_chan_addb2 fl_chan_addb2
Definition: fom.h:304
struct m0_tl fl_wail
Definition: fom.h:263
struct m0_addb2_mach * fl_addb2_mach
Definition: fom.h:297
struct m0_chan fl_runrun
Definition: fom.h:282
const struct m0_fom_domain_ops * fd_ops
Definition: fom.h:335
M0_INTERNAL void m0_fom_ready(struct m0_fom *fom)
Definition: fom.c:429
Definition: fom.h:644
M0_INTERNAL void m0_fom_locality_post_stats(struct m0_fom_locality *loc)
struct m0_atomic64 fl_unblocking
Definition: fom.h:292
struct m0_fom_callback * fo_pending
Definition: fom.h:530
M0_INTERNAL bool m0_fom_domain_is_idle_for(const struct m0_reqh_service *svc)
Definition: fom.c:1281
M0_INTERNAL void m0_fom_callback_fini(struct m0_fom_callback *cb)
Definition: fom.c:1497
struct m0_clink fc_clink
Definition: fom.h:446
void m0_fom_fini(struct m0_fom *fom)
Definition: fom.c:1324
M0_INTERNAL bool m0_locality_invariant(const struct m0_fom_locality *loc)
Definition: fom.c:266
struct m0_sm_group_addb2 fl_grp_addb2
Definition: fom.h:303
bool fo_local
Definition: fom.h:503
M0_INTERNAL bool m0_fom_group_is_locked(const struct m0_fom *fom)
Definition: fom.c:229
void m0_fom_phase_move(struct m0_fom *fom, int32_t rc, int phase)
Definition: fom.c:1699
Definition: tlist.h:251
unsigned fl_foms
Definition: fom.h:271
M0_INTERNAL int m0_fom_addb2_init(struct m0_fom_type *type, uint64_t id)
M0_INTERNAL void m0_fom_fdmi_record_post(struct m0_fom *fom)
Definition: fom.c:1742
M0_INTERNAL bool m0_fom_domain_is_idle(const struct m0_fom_domain *dom)
Definition: fom.c:1289
M0_INTERNAL void m0_fom_type_init(struct m0_fom_type *type, uint64_t id, const struct m0_fom_type_ops *ops, const struct m0_reqh_service_type *svc_type, const struct m0_sm_conf *sm)
Definition: fom.c:1596
static struct m0_stob_domain * dom
Definition: storage.c:38
M0_INTERNAL void m0_fom_block_leave(struct m0_fom *fom)
Definition: fom.c:582
struct m0_sm_timer to_timer
Definition: fom.h:791
Definition: reqh.h:94
const struct m0_fom_type * fo_type
Definition: fom.h:485
struct m0_addb2_hist fl_runq_counter
Definition: fom.h:299
Definition: dump.c:103
Definition: chan.h:229
void(* fc_bottom)(struct m0_fom_callback *cb)
Definition: fom.h:463
m0_fom_state
Definition: fom.h:355
const struct m0_fom_ops * fo_ops
Definition: fom.h:486
struct m0_loc_thread * fo_thread
Definition: fom.h:526
uint64_t fo_magic
Definition: fom.h:534
M0_INTERNAL void m0_fom_sm_init(struct m0_fom *fom)
Definition: fom.c:1674
int fo_log[32]
Definition: fom.h:532
bool(* fc_top)(struct m0_fom_callback *cb)
Definition: fom.h:458
M0_INTERNAL void m0_fom_callback_arm(struct m0_fom *fom, struct m0_chan *chan, struct m0_fom_callback *cb)
Definition: fom.c:1460
M0_INTERNAL bool m0_fom_domain_invariant(const struct m0_fom_domain *dom)
Definition: fom.c:255
const struct m0_fom_type_ops * ft_ops
Definition: fom.h:614
struct m0_tl fl_threads
Definition: fom.h:291
M0_INTERNAL int m0_fom_timedwait(struct m0_fom *fom, uint64_t phases, m0_time_t deadline)
Definition: fom.c:724
Definition: fom.h:481
size_t(* fo_home_locality)(const struct m0_fom *fom)
Definition: fom.h:671
struct m0_reqh reqh
Definition: rm_foms.c:48
M0_INTERNAL void m0_fom_timeout_fini(struct m0_fom_timeout *to)
Definition: fom.c:1539
static struct m0_chan chan[RDWR_REQUEST_MAX]
m0_fom_phase_outcome
Definition: fom.h:625
struct m0_fom_locality * fo_loc
Definition: fom.h:483
void(* fo_hung_notify)(const struct m0_fom *fom)
Definition: fom.h:681
struct m0_reqh_service * fo_service
Definition: fom.h:505
bool(* fdo_time_is_out)(const struct m0_fom_domain *dom, const struct m0_fom *fom)
Definition: fom.h:348
unsigned fo_transitions
Definition: fom.h:514
void(* fo_addb2_descr)(struct m0_fom *fom)
Definition: fom.h:675
static struct m0_net_test_service svc
Definition: service.c:34
M0_INTERNAL bool m0_fom_is_waiting_on(const struct m0_fom *fom)
Definition: fom.c:1480
M0_INTERNAL int m0_fom_rc(const struct m0_fom *fom)
Definition: fom.c:1727
Definition: sm.h:301
struct m0_sm_conf ft_conf
Definition: fom.h:615
static struct m0_fop * fop
Definition: item.c:57
M0_INTERNAL void m0_fom_callback_cancel(struct m0_fom_callback *cb)
Definition: fom.c:1514
struct m0_fom * fc_fom
Definition: fom.h:452
struct m0_fom_locality ** fd_localities
Definition: fom.h:331
M0_INTERNAL void m0_fom_queue(struct m0_fom *fom)
Definition: fom.c:624
struct m0_addb2_sys * fd_addb2_sys
Definition: fom.h:338
struct m0_sm fo_sm_phase
Definition: fom.h:522
void(* fo_fini)(struct m0_fom *fom)
Definition: fom.h:657
struct m0_fop * fo_rep_fop
Definition: fom.h:492
M0_INTERNAL int m0_fom_fol_rec_add(struct m0_fom *fom)
Definition: fom.c:1737
static void fom_type(struct m0_addb2__context *ctx, const uint64_t *v, char *buf)
Definition: dump.c:516
M0_INTERNAL void m0_fom_locality_inc(struct m0_fom *fom)
Definition: fom.c:1295
struct m0_addb2_hist fl_wail_counter
Definition: fom.h:300
#define out(...)
Definition: gen.c:41
size_t fl_wail_nr
Definition: fom.h:264
void m0_fom_phase_set(struct m0_fom *fom, int phase)
Definition: fom.c:1688
int type
Definition: dir.c:1031
M0_INTERNAL void m0_fom_timeout_init(struct m0_fom_timeout *to)
Definition: fom.c:1532
struct m0_fom_ops ops
Definition: io_foms.c:623
static struct m0_dtm_oper_descr reply
Definition: transmit.c:94
size_t fd_localities_nr
Definition: fom.h:333
const struct m0_reqh_service_type * ft_rstype
Definition: fom.h:617
M0_INTERNAL struct m0_reqh * m0_fom2reqh(const struct m0_fom *fom)
Definition: fom.c:1749
int32_t rc
Definition: trigger_fop.h:47
size_t fl_runq_nr
Definition: fom.h:260
struct m0_fom_callback fo_cb
Definition: fom.h:488
struct m0_sm_ast fc_ast
Definition: fom.h:450
Definition: fop.h:79
struct m0_sm_conf ft_state_conf
Definition: fom.h:616
M0_INTERNAL struct m0_reqh * m0_fom_reqh(const struct m0_fom *fom)
Definition: fom.c:283
M0_INTERNAL void m0_fom_timeout_cancel(struct m0_fom_timeout *to)
Definition: fom.c:1581
M0_INTERNAL bool m0_fom_invariant(const struct m0_fom *fom)
Definition: fom.c:311
Definition: tx.h:280
enum m0_fc_state fc_state
Definition: fom.h:451
M0_INTERNAL const char * m0_fom_phase_name(const struct m0_fom *fom, int phase)
Definition: fom.c:1722