Motr  M0
Module

Data Structures

struct  m0
 
struct  m0_modlev
 
struct  m0_moddep
 
struct  m0_module
 
struct  m0_module_type
 
struct  m0_param_source
 

Macros

#define M0_MODDEP_INIT(other, src, dst)   { .md_other = (other), .md_src = (src), .md_dst = (dst) }
 

Enumerations

enum  m0_module_id {
  M0_MODULE_NET, M0_MODULE_UT, M0_MODULE_ADDB2, M0_MODULE_LOCALITY,
  M0_MODULE_HA, M0_MODULE_PROCESSOR, M0_MODULE_POOL, M0_MODULE_ISC,
  M0_MODULE_NR
}
 
enum  {
  M0_LEVEL_INST_PREPARE, M0_LEVEL_INST_QUIESCE_SYSTEM, M0_LEVEL_INST_ONCE, M0_LEVEL_INST_SUBSYSTEMS,
  M0_LEVEL_INST_READY
}
 
enum  { M0_MODLEV_NONE = -1, M0_MODLEV_MAX = 64, M0_MODDEP_MAX = 128 }
 

Functions

M0_INTERNAL int m0_init_once (struct m0 *instance)
 
M0_INTERNAL void m0_fini_once (void)
 
M0_INTERNAL int m0_subsystems_init (void)
 
M0_INTERNAL void m0_subsystems_fini (void)
 
M0_INTERNAL int m0_quiesce_init (void)
 
M0_INTERNAL void m0_quiesce_fini (void)
 
 M0_LOCKERS__DEFINE (M0_INTERNAL, m0_inst, m0, i_lockers)
 
M0_INTERNAL struct m0m0_get (void)
 
M0_INTERNAL void m0_set (struct m0 *instance)
 
static int level_inst_enter (struct m0_module *module)
 
static void level_inst_leave (struct m0_module *module)
 
M0_INTERNAL void m0_instance_setup (struct m0 *instance)
 
 M0_LOCKERS__DECLARE (M0_INTERNAL, m0_inst, m0, 16)
 
static bool moddeps_are_unique (const struct m0_moddep *arr, unsigned n)
 
static bool module_invariant (const struct m0_module *mod)
 
static int module_up (struct m0_module *module, int level)
 
M0_INTERNAL int m0_module_init (struct m0_module *module, int level)
 
M0_INTERNAL void m0_module_fini (struct m0_module *module, int level)
 
M0_INTERNAL void m0_module_dep_add (struct m0_module *m0, int l0, struct m0_module *m1, int l1)
 
M0_INTERNAL void m0_module_setup (struct m0_module *module, const char *name, const struct m0_modlev *level, int level_nr, struct m0 *instance)
 
 M0_TL_DESCR_DEFINE (m0_param_sources, "m0_param_sources", static, struct m0_param_source, ps_link, ps_magic, M0_PARAM_SOURCE_MAGIC, M0_PARAM_SOURCES_MAGIC)
 
 M0_TL_DEFINE (m0_param_sources, M0_INTERNAL, struct m0_param_source)
 
static struct m0_tlparam_sources (void)
 
M0_INTERNAL void * m0_param_get (const char *key)
 
M0_INTERNAL void m0_param_source_add (struct m0_param_source *src)
 
M0_INTERNAL void m0_param_source_del (struct m0_param_source *src)
 
 M0_TL_DECLARE (m0_param_sources, M0_INTERNAL, struct m0_param_source)
 

Variables

static const struct m0_modlev levels_inst []
 

Detailed Description

A module is part of Motr, which can be initialised or finalised. A module can correspond to a software module (e.g., lib/thread, reqh) or to a run-time entity (reqh instance, service, stob domain, etc.).

A module defines an ordered list of levels, corresponding to the states of module initialisation. E.g., a reqh instance module might have following levels:

0. m0_reqh structure initialised

  1. locality handler threads started
  2. BE started
  3. layout domain initialised
  4. ready to start services

With a level are associated entry and exit functions, executed when the level is entered and left.

There are dependencies between (module, level) pairs. A dependency

*         (m0, l0) -> (m1, l1)
* 

means that the module m1 must be at least at the level l1 before the module m0 can enter the level l0. For example there can be a dependency

*         (reqh_instance, locality_handler_threads_started) -> \
*                 (lib_thread, initialised)
* 

specifying that threading subsystem should be initialised before reqh can start threads.

It's important to understand that dependencies exist between (module, level) pairs rather than between modules. Because of this, a potential dependency cycle can be broken by introducing an additional level, instead of a more expensive operation of introducing an additional module.

The collection of modules is not fixed. An entry function of a module can add more modules and dependencies to the system. For example, one of m0d levels fetches configuration information from confc. The list of services to be run on this m0d is obtained from confc, and modules, corresponding to the services are added, with appropriate dependencies. After this m0d initialisation continues, taking new modules and dependencies into account.

Dependencies organize modules in an acyclic graph, which is not necessarily a tree. Flexible initialisation is achieved by adding special nodes in this graph. E.g., a unit test can introduce a module, depending on subsystems that the test needs. To prepare for the test, this module is initialised, starting subsystems. Another well-known nodes in this graph are m0t1fs_instance and m0d_instance: first is a module representing a m0t1fs mount point, depending on all subsystems that m0t1fs needs. The latter represents an m0d process.

As an example of a long(ish) chain of dependencies consider:

0. network starts

  1. rpc starts
  2. reqh starts
  3. confc starts
  4. reqh connects to confd
  5. confc is populated from confd
  6. stob identifier of seg0 is obtained from confc
  7. BE starts
  8. dtm starts
  9. reqh starts (other) services

m0_param API is used to configure initialisation: Motr modules use m0_param_get() to obtain external information.

Macro Definition Documentation

◆ M0_MODDEP_INIT

#define M0_MODDEP_INIT (   other,
  src,
  dst 
)    { .md_other = (other), .md_src = (src), .md_dst = (dst) }

Definition at line 137 of file module.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Levels of m0 instance.

Enumerator
M0_LEVEL_INST_PREPARE 

m0_param_source_add(), m0_param_source_del(), m0_param_get() may not be used before m0::i_self enters M0_LEVEL_INST_PREPARE or after it leaves it.

M0_LEVEL_INST_QUIESCE_SYSTEM 

Layer subsystem non-reloaded for reconfigure Motr.

M0_LEVEL_INST_ONCE 
M0_LEVEL_INST_SUBSYSTEMS 
M0_LEVEL_INST_READY 

The "fully initialised" level, which the users of m0 instance should m0_module_init() it to.

M0_LEVEL_INST_READY depends on a particular set of modules, according to the use case (UT, m0t1fs, m0d, etc.).

Definition at line 171 of file instance.h.

◆ anonymous enum

anonymous enum
Enumerator
M0_MODLEV_NONE 
M0_MODLEV_MAX 
M0_MODDEP_MAX 

Definition at line 106 of file module.h.

◆ m0_module_id

Identifiers of standard modules.

Enumerator
M0_MODULE_NET 
M0_MODULE_UT 
M0_MODULE_ADDB2 
M0_MODULE_LOCALITY 
M0_MODULE_HA 
M0_MODULE_PROCESSOR 
M0_MODULE_POOL 
M0_MODULE_ISC 
M0_MODULE_NR 

Definition at line 43 of file instance.h.

Function Documentation

◆ level_inst_enter()

static int level_inst_enter ( struct m0_module module)
static

Definition at line 54 of file instance.c.

Here is the call graph for this function:

◆ level_inst_leave()

static void level_inst_leave ( struct m0_module module)
static

Definition at line 74 of file instance.c.

◆ m0_fini_once()

M0_INTERNAL void m0_fini_once ( void  )

Definition at line 302 of file init.c.

Here is the call graph for this function:

◆ m0_get()

M0_INTERNAL struct m0 * m0_get ( void  )

Returns current m0 instance.

In the kernel, there is only one instance. It is returned.

In user space, the instance is created by m0d early startup code and stored in thread-local storage. This instance is inherited by threads (i.e., when a thread is created it gets the instance of the creator and stores it in its TLS).

Theoretically, user space Motr can support multiple instances in the same address space.

Postcondition
retval != NULL

Definition at line 41 of file instance.c.

Here is the call graph for this function:

◆ m0_init_once()

M0_INTERNAL int m0_init_once ( struct m0 instance)

Definition at line 279 of file init.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_instance_setup()

M0_INTERNAL void m0_instance_setup ( struct m0 instance)

Definition at line 110 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ M0_LOCKERS__DECLARE()

M0_LOCKERS__DECLARE ( M0_INTERNAL  ,
m0_inst  ,
m0  ,
16   
)

◆ M0_LOCKERS__DEFINE()

M0_LOCKERS__DEFINE ( M0_INTERNAL  ,
m0_inst  ,
m0  ,
i_lockers   
)

◆ m0_module_dep_add()

M0_INTERNAL void m0_module_dep_add ( struct m0_module m0,
int  l0,
struct m0_module m1,
int  l1 
)

Creates (m0, l0) -> (m1, l1) dependency.

Definition at line 168 of file module.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_module_fini()

M0_INTERNAL void m0_module_fini ( struct m0_module module,
int  level 
)

Downgrade the module to the given level.

Definition at line 142 of file module.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_module_init()

M0_INTERNAL int m0_module_init ( struct m0_module module,
int  level 
)

Bring module at least to the given level.

This function is not self-cleaning: even if it fails, m0_module_fini() should be called.

Definition at line 131 of file module.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_module_setup()

M0_INTERNAL void m0_module_setup ( struct m0_module module,
const char *  name,
const struct m0_modlev level,
int  level_nr,
struct m0 instance 
)

Performs initial configuration of m0_module fields.

Definition at line 193 of file module.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_param_get()

M0_INTERNAL void * m0_param_get ( const char *  key)

Obtains the value of parameter associated with given key. Returns NULL if no such value exists or an error occurs.

Definition at line 44 of file param.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_param_source_add()

M0_INTERNAL void m0_param_source_add ( struct m0_param_source src)

Appends new element to m0::i_param_sources.

Definition at line 56 of file param.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_param_source_del()

M0_INTERNAL void m0_param_source_del ( struct m0_param_source src)

Deletes ‘src’ from m0::i_param_sources.

Definition at line 62 of file param.c.

Here is the caller graph for this function:

◆ m0_quiesce_fini()

M0_INTERNAL void m0_quiesce_fini ( void  )

Definition at line 348 of file init.c.

Here is the call graph for this function:

◆ m0_quiesce_init()

M0_INTERNAL int m0_quiesce_init ( void  )

Definition at line 343 of file init.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_set()

M0_INTERNAL void m0_set ( struct m0 instance)

Stores given pointer in thread-local storage.

Precondition
instance != NULL

Definition at line 48 of file instance.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ m0_subsystems_fini()

M0_INTERNAL void m0_subsystems_fini ( void  )

Definition at line 338 of file init.c.

Here is the call graph for this function:

◆ m0_subsystems_init()

M0_INTERNAL int m0_subsystems_init ( void  )

Definition at line 333 of file init.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ M0_TL_DECLARE()

M0_TL_DECLARE ( m0_param_sources  ,
M0_INTERNAL  ,
struct m0_param_source   
)

◆ M0_TL_DEFINE()

M0_TL_DEFINE ( m0_param_sources  ,
M0_INTERNAL  ,
struct m0_param_source   
)

◆ M0_TL_DESCR_DEFINE()

M0_TL_DESCR_DEFINE ( m0_param_sources  ,
"m0_param_sources"  ,
static  ,
struct m0_param_source  ,
ps_link  ,
ps_magic  ,
M0_PARAM_SOURCE_MAGIC  ,
M0_PARAM_SOURCES_MAGIC   
)

◆ moddeps_are_unique()

static bool moddeps_are_unique ( const struct m0_moddep arr,
unsigned  n 
)
static

Returns true if the first ‘n’ entries of ‘arr’ are unique.

Definition at line 35 of file module.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ module_invariant()

static bool module_invariant ( const struct m0_module mod)
static

Definition at line 41 of file module.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ module_up()

static int module_up ( struct m0_module module,
int  level 
)
static

Definition at line 85 of file module.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ param_sources()

static struct m0_tl* param_sources ( void  )
static

Definition at line 37 of file param.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ levels_inst

const struct m0_modlev levels_inst[]
static
Initial value:
= {
.ml_name = "M0_LEVEL_INST_PREPARE",
.ml_enter = level_inst_enter,
.ml_leave = level_inst_leave
},
.ml_name = "M0_LEVEL_INST_QUIESCE_SYSTEM",
.ml_enter = level_inst_enter,
.ml_leave = (void *)m0_quiesce_fini
},
.ml_name = "M0_LEVEL_INST_ONCE",
.ml_enter = level_inst_enter,
.ml_leave = (void *)m0_fini_once
},
.ml_name = "M0_LEVEL_INST_SUBSYSTEMS",
.ml_enter = level_inst_enter,
.ml_leave = (void *)m0_subsystems_fini
},
.ml_name = "M0_LEVEL_INST_READY"
}
}
static void level_inst_leave(struct m0_module *module)
Definition: instance.c:74
M0_INTERNAL void m0_fini_once(void)
Definition: init.c:302
M0_INTERNAL void m0_subsystems_fini(void)
Definition: init.c:338
M0_INTERNAL void m0_quiesce_fini(void)
Definition: init.c:348
static int level_inst_enter(struct m0_module *module)
Definition: instance.c:54

Definition at line 84 of file instance.c.