23 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_SM 240 state <
conf->scf_nr_states &&
241 conf->scf_state[state].sd_name !=
NULL;
248 return &
mach->sm_conf->scf_state[state];
269 if (
mach->sm_invariant_chk_off)
279 if (
conf->scf_nr_states >=
sizeof(
conf->scf_state[0].sd_allowed) * 8) {
284 for (
i = 0, mask = 0;
i <
conf->scf_nr_states; ++
i) {
289 for (
i = 0;
i <
conf->scf_nr_states; ++
i) {
293 sd = &
conf->scf_state[
i];
319 mach->sm_state = state;
326 mach->sm_invariant_chk_off =
false;
354 for (
i = 0;
i <
conf->scf_nr_states; ++
i)
355 for (to = 0; to <
conf->scf_nr_states; ++to)
356 conf->scf_state[
i].sd_trans[to] = ~0;
358 for (
i = 0;
i <
conf->scf_trans_nr; ++
i) {
359 from =
conf->scf_trans[
i].td_src;
360 to =
conf->scf_trans[
i].td_tgt;
362 conf->scf_state[from].sd_trans[to] =
i;
365 for (
i = 0;
i <
conf->scf_nr_states; ++
i)
366 for (to = 0; to <
conf->scf_nr_states; ++to)
369 conf->scf_state[
i].sd_trans[to] != ~0));
449 if (
stats->as_id != 0) {
453 if (
stats->as_nr > 0)
456 mach->sm_state_epoch = now;
458 mach->sm_state = state;
463 }
while (state >= 0);
602 timer->tr_state =
ARMED;
603 timer->tr_grp =
group;
719 uint32_t
src, uint32_t
tgt)
734 for (
i = 0;
i <
base->scf_trans_nr;
i++) {
768 for (
i = 0;
i <
nr; ++
i) {
778 conf->scf_state[state].sd_name :
"invalid";
822 stats->as_id =
c->scf_addb2_id;
823 stats->as_nr =
c->scf_trans_nr;
824 for (
i = 0;
i <
stats->as_nr; ++
i) {
832 c->scf_addb2_counter +
i, 2);
864 conf->scf_addb2_key = result + 1;
872 if (
conf->scf_addb2_key > 0)
875 conf->scf_addb2_id = 0;
876 conf->scf_addb2_counter = 0;
877 conf->scf_addb2_key = 0;
895 if (
conf->scf_addb2_key > 0) {
899 return conf->scf_addb2_key > 0;
999 for (
i = 0;
i <
conf->scf_nr_states; ++
i) {
1010 for (
i = 0;
i <
conf->scf_trans_nr; ++
i) {
1027 #undef M0_TRACE_SUBSYSTEM
static void m0_atomic64_inc(struct m0_atomic64 *a)
static struct m0_sm_ast eoq
M0_INTERNAL void m0_chan_wait(struct m0_clink *link)
M0_INTERNAL void m0_sm_conf_init(struct m0_sm_conf *conf)
static bool conf_invariant(const struct m0_sm_conf *conf)
M0_INTERNAL void m0_sm_fail(struct m0_sm *mach, int fail_state, int32_t rc)
void(* sd_ex)(struct m0_sm *mach)
M0_INTERNAL void m0_mutex_unlock(struct m0_mutex *mutex)
M0_INTERNAL void(* m0_sm__conf_init)(const struct m0_sm_conf *conf)
static void timer_done(struct m0_sm_timer *timer)
M0_INTERNAL bool m0_chan_is_locked(const struct m0_chan *ch)
M0_INTERNAL int m0_sm_addb2_init(struct m0_sm_conf *conf, uint64_t id, uint64_t counter)
M0_INTERNAL void m0_clink_init(struct m0_clink *link, m0_chan_cb_t cb)
M0_INTERNAL void m0_clink_del(struct m0_clink *link)
M0_INTERNAL void m0_clink_del_lock(struct m0_clink *link)
int(* sd_in)(struct m0_sm *mach)
void * m0_locality_data(int key)
void(* sa_cb)(struct m0_sm_group *grp, struct m0_sm_ast *)
#define M0_MEMBER_SIZE(type, member)
struct m0_sm_group_addb2 * s_addb2
static struct m0_sm_group * grp
M0_INTERNAL void m0_sm_timeout_init(struct m0_sm_timeout *to)
static void timeout(void)
M0_INTERNAL void m0_sm_ast_wait(struct m0_sm_ast_wait *wait)
M0_INTERNAL void m0_sm_ast_post(struct m0_sm_group *grp, struct m0_sm_ast *ast)
void m0_console_printf(const char *fmt,...)
M0_INTERNAL void m0_sm_group_unlock_rec(struct m0_sm_group *grp, bool runast)
static int sm_addb2_ctor(struct m0_sm_addb2_stats *stats, const struct m0_sm_conf *c)
M0_INTERNAL bool sm_invariant0(const struct m0_sm *mach)
static struct m0_sm_ast ast
M0_INTERNAL const char * m0_failed_condition
struct m0_sm_ast * s_forkq
M0_INTERNAL void m0_sm_ast_wait_init(struct m0_sm_ast_wait *wait, struct m0_mutex *ch_guard)
bool(* sd_invariant)(const struct m0_sm *mach)
M0_INTERNAL const char * m0_sm_state_name(const struct m0_sm *mach, int state)
M0_INTERNAL void m0_sm_conf_trans_extend(const struct m0_sm_conf *base, struct m0_sm_conf *sub)
M0_INTERNAL void m0_sm_conf_extend(const struct m0_sm_state_descr *base, struct m0_sm_state_descr *sub, uint32_t nr)
M0_INTERNAL bool m0_clink_is_armed(const struct m0_clink *link)
static struct m0_addb2_mach * mach
#define m0_exists(var, nr,...)
static void _sm_group_unlock(struct m0_sm_group *grp)
M0_INTERNAL int m0_timer_init(struct m0_timer *timer, enum m0_timer_type type, struct m0_timer_locality *loc, m0_timer_callback_t callback, unsigned long data)
void m0_addb2_hist_mod(struct m0_addb2_hist *hist, int64_t val)
M0_INTERNAL void m0_chan_lock(struct m0_chan *ch)
#define container_of(ptr, type, member)
static const struct m0_sm_state_descr * state_get(const struct m0_sm *mach, uint32_t state)
M0_INTERNAL void m0_mutex_lock(struct m0_mutex *mutex)
static void sm_timer_bottom(struct m0_sm_group *grp, struct m0_sm_ast *ast)
M0_ADDB2_ADD(M0_AVI_FS_CREATE, new_fid.f_container, new_fid.f_key, mode, rc)
struct m0_addb2_hist as_hist[0]
M0_INTERNAL bool m0_sm_addb2_counter_init(struct m0_sm *sm)
M0_INTERNAL void m0_sm_group_fini(struct m0_sm_group *grp)
M0_INTERNAL int m0_sm_timedwait(struct m0_sm *mach, uint64_t states, m0_time_t deadline)
static void sm_unlock(struct m0_sm *mach)
static void sm_lock(struct m0_sm *mach)
M0_INTERNAL void m0_timer_fini(struct m0_timer *timer)
M0_INTERNAL void m0_sm_group_unlock(struct m0_sm_group *grp)
static const struct m0_sm_conf conf
M0_INTERNAL uint64_t m0_dummy_id_generate(void)
void m0_locality_data_free(int key)
M0_INTERNAL void m0_chan_signal(struct m0_chan *chan)
struct m0_sm_trans_descr * scf_trans
void m0_addb2_hist_del(struct m0_addb2_hist *hist)
M0_INTERNAL bool m0_sm_timer_is_armed(const struct m0_sm_timer *timer)
return M0_ERR(-EOPNOTSUPP)
struct m0_atomic64 aw_active
int m0_sm_group_call(struct m0_sm_group *group, int(*cb)(void *), void *data)
M0_INTERNAL void m0_timer_stop(struct m0_timer *timer)
M0_INTERNAL void m0_sm_ast_wait_loop(struct m0_sm_ast_wait *wait, struct m0_clink *clink)
M0_INTERNAL void m0_chan_init(struct m0_chan *chan, struct m0_mutex *ch_guard)
M0_INTERNAL bool m0_mutex_is_locked(const struct m0_mutex *mutex)
M0_INTERNAL void m0_sm_group_init(struct m0_sm_group *grp)
static void timeout_ast(struct m0_sm_timer *timer)
struct m0_sm_group * tr_grp
M0_INTERNAL void m0_timer_start(struct m0_timer *timer, m0_time_t expire)
m0_time_t m0_time_now(void)
static struct m0_addb2_callback c
void m0_sm_state_set(struct m0_sm *mach, int state)
static struct m0_sm_ast_wait wait
static void m0_atomic64_dec(struct m0_atomic64 *a)
static void sm_addb2_dtor(struct m0_sm_addb2_stats *stats, const struct m0_sm_conf *c)
int8_t sd_trans[M0_SM_MAX_STATES]
struct m0_sm_addb2_stats * sm_addb2_stats
M0_INTERNAL void m0_clink_signal(struct m0_clink *clink)
M0_INTERNAL int m0_semaphore_init(struct m0_semaphore *semaphore, unsigned value)
M0_INTERNAL void m0_mutex_init(struct m0_mutex *mutex)
M0_INTERNAL void m0_sm_addb2_fini(struct m0_sm_conf *conf)
static void _sm_group_lock(struct m0_sm_group *grp)
static bool grp_is_locked(const struct m0_sm_group *grp)
M0_INTERNAL bool m0_is_poisoned(const void *ptr)
struct m0_sm_ast * sa_next
static bool m0_atomic64_dec_and_test(struct m0_atomic64 *a)
M0_INTERNAL bool m0_timer_is_started(const struct m0_timer *timer)
static struct m0_clink clink[RDWR_REQUEST_MAX]
struct m0_addb2_hist ga_forq_hist
M0_INTERNAL void m0_chan_unlock(struct m0_chan *ch)
void m0_addb2_hist_add_auto(struct m0_addb2_hist *hist, int skip, uint64_t label, int idx)
static bool state_is_valid(const struct m0_sm_conf *conf, uint32_t state)
static void sm_addb2_counter_init_add(struct m0_sm *sm)
static int64_t m0_atomic64_get(const struct m0_atomic64 *a)
#define m0_forall(var, nr,...)
void m0_clink_add_lock(struct m0_chan *chan, struct m0_clink *link)
struct m0_pdclust_tgt_addr tgt
M0_INTERNAL int m0_sm_timeout_arm(struct m0_sm *mach, struct m0_sm_timeout *to, m0_time_t timeout, int state, uint64_t bitmask)
M0_INTERNAL void m0_sm_ast_wait_post(struct m0_sm_ast_wait *wait, struct m0_sm_group *grp, struct m0_sm_ast *ast)
M0_INTERNAL void m0_sm_timeout_fini(struct m0_sm_timeout *to)
static unsigned long sm_timer_top(unsigned long data)
#define M0_FI_ENABLED(tag)
M0_INTERNAL void m0_sm_timer_cancel(struct m0_sm_timer *timer)
M0_INTERNAL void m0_sm_init(struct m0_sm *mach, const struct m0_sm_conf *conf, uint32_t state, struct m0_sm_group *grp)
static struct m0_sm_trans_descr trans[]
static bool sm_timeout_cancel(struct m0_clink *link)
M0_INTERNAL void m0_clink_add(struct m0_chan *chan, struct m0_clink *link)
M0_INTERNAL bool m0_chan_timedwait(struct m0_clink *link, const m0_time_t abs_timeout)
M0_INTERNAL void m0_semaphore_fini(struct m0_semaphore *semaphore)
#define M0_ATOMIC64_CAS(loc, oldval, newval)
struct m0_sm_timer st_timer
M0_INTERNAL struct m0_thread * m0_thread_self(void)
static bool sm_is_locked(const struct m0_sm *mach)
m0_time_t m0_time_sub(const m0_time_t t1, const m0_time_t t2)
M0_INTERNAL void m0_sm_ast_wait_fini(struct m0_sm_ast_wait *wait)
M0_INTERNAL void m0_sm_conf_print(const struct m0_sm_conf *conf)
M0_INTERNAL void m0_sm_move(struct m0_sm *mach, int32_t rc, int state)
M0_INTERNAL void m0_mutex_fini(struct m0_mutex *mutex)
M0_INTERNAL void m0_clink_fini(struct m0_clink *link)
M0_INTERNAL void m0_sm_ast_wait_prepare(struct m0_sm_ast_wait *wait, struct m0_clink *clink)
M0_INTERNAL void m0_sm_group_lock(struct m0_sm_group *grp)
M0_INTERNAL uint64_t m0_ptr_wrap(const void *p)
M0_INTERNAL void m0_chan_fini(struct m0_chan *chan)
#define M0_ASSERT_INFO(cond, fmt,...)
int m0_locality_data_alloc(size_t nob, int(*ctor)(void *, void *), void(*dtor)(void *, void *), void *datum)
M0_INTERNAL void m0_sm_ast_cancel(struct m0_sm_group *grp, struct m0_sm_ast *ast)
M0_INTERNAL void m0_semaphore_down(struct m0_semaphore *semaphore)
M0_INTERNAL void m0_semaphore_up(struct m0_semaphore *semaphore)
M0_INTERNAL void m0_sm_conf_fini(struct m0_sm_conf *conf)
M0_INTERNAL bool m0_sm_conf_is_initialized(const struct m0_sm_conf *conf)
M0_INTERNAL void m0_sm_timer_fini(struct m0_sm_timer *timer)
M0_INTERNAL void m0_sm_asts_run(struct m0_sm_group *grp)
M0_INTERNAL bool m0_sm_timeout_is_armed(const struct m0_sm_timeout *to)
M0_INTERNAL void m0_sm_timer_init(struct m0_sm_timer *timer)
M0_INTERNAL uint64_t m0_sm_id_get(const struct m0_sm *sm)
#define M0_ADDB2_HIST(id, hist, datum,...)
static void sm_call_ast(struct m0_sm_group *grp, struct m0_sm_ast *ast)
M0_INTERNAL void m0_chan_fini_lock(struct m0_chan *chan)
void(* tr_cb)(struct m0_sm_timer *)
struct m0_semaphore sc_wait
static const struct m0_sm_state_descr * sm_state(const struct m0_sm *mach)
struct m0_pdclust_src_addr src
static bool trans_exists(const struct m0_sm_conf *conf, uint32_t src, uint32_t tgt)
M0_INTERNAL void m0_chan_broadcast(struct m0_chan *chan)
M0_INTERNAL void m0_sm_ast_wait_signal(struct m0_sm_ast_wait *wait)
struct m0_thread * m_owner
M0_INTERNAL bool m0_sm_group_is_locked(const struct m0_sm_group *grp)
M0_INTERNAL int m0_sm_timer_start(struct m0_sm_timer *timer, struct m0_sm_group *group, void(*cb)(struct m0_sm_timer *), m0_time_t deadline)
static struct m0_sm_state_descr states[C_NR]
const struct m0_sm_conf * sm_conf
M0_INTERNAL void m0_sm_ast_wait_complete(struct m0_sm_ast_wait *wait, struct m0_clink *clink)
static void state_set(struct m0_sm *mach, int state, int32_t rc)
static void m0_atomic64_set(struct m0_atomic64 *a, int64_t num)
M0_INTERNAL const char * m0_sm_conf_state_name(const struct m0_sm_conf *conf, int state)
M0_INTERNAL void m0_sm_fini(struct m0_sm *mach)
M0_INTERNAL bool m0_sm_invariant(const struct m0_sm *mach)
M0_INTERNAL void m0_sm_group_lock_rec(struct m0_sm_group *grp, bool runast)