Motr  M0
client_init.c File Reference
#include "lib/memory.h"
#include "lib/errno.h"
#include "lib/uuid.h"
#include "lib/finject.h"
#include "lib/arith.h"
#include "lib/mutex.h"
#include "lib/time.h"
#include "addb2/global.h"
#include "addb2/sys.h"
#include "fid/fid.h"
#include "conf/ha.h"
#include "conf/helpers.h"
#include "conf/confc.h"
#include "rpc/rpclib.h"
#include "pool/pool.h"
#include "rm/rm_service.h"
#include "net/lnet/lnet_core_types.h"
#include "dtm0/service.h"
#include "dtm0/helper.h"
#include "motr/io.h"
#include "motr/client.h"
#include "motr/addb.h"
#include "motr/client_internal.h"
#include "motr/layout.h"
#include "lib/trace.h"
#include <unistd.h>
Include dependency graph for client_init.c:

Go to the source code of this file.

Macros

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_CLIENT
 
#define NOT_EMPTY(x)   (x != NULL && *x != '\0')
 

Enumerations

enum  initlift_states {
  IL_UNINITIALISED = 0, IL_NET, IL_RPC, IL_AST_THREAD,
  IL_HA, IL_CONFC, IL_POOLS, IL_POOL_VERSION,
  IL_RESOURCE_MANAGER, IL_LAYOUT_DB, IL_IDX_SERVICE, IL_ROOT_FID,
  IL_ADDB2, IL_DTM0, IL_INITIALISED, IL_FAILED
}
 

Functions

 M0_BOB_DEFINE (static, &m0c_bobtype, m0_client)
 
static int initlift_uninitialised (struct m0_sm *mach)
 
static int initlift_net (struct m0_sm *mach)
 
static int initlift_rpc (struct m0_sm *mach)
 
static int initlift_ast_thread (struct m0_sm *mach)
 
static int initlift_ha (struct m0_sm *mach)
 
static int initlift_confc (struct m0_sm *mach)
 
static int initlift_pools (struct m0_sm *mach)
 
static int initlift_pool_version (struct m0_sm *mach)
 
static int initlift_resource_manager (struct m0_sm *mach)
 
static int initlift_layouts (struct m0_sm *mach)
 
static int initlift_idx_service (struct m0_sm *mach)
 
static int initlift_rootfid (struct m0_sm *mach)
 
static int initlift_addb2 (struct m0_sm *mach)
 
static int initlift_dtm0 (struct m0_sm *mach)
 
static bool m0c_invariant (struct m0_client *m0c)
 
static struct m0_rconfcrconfc (struct m0_client *m0c)
 
M0_INTERNAL struct m0_confcm0_confc (struct m0_client *m0c)
 
static int client_fid_sscanf (const char *s, struct m0_fid *fid, const char *descr)
 
static int initlift_get_next_floor (struct m0_client *m0c)
 
static void initlift_move_next_floor (struct m0_client *m0c)
 
static void initlift_fail (int rc, struct m0_client *m0c)
 
static void client_net_fini (struct m0_client *m0c)
 
static int client_net_init (struct m0_client *m0c)
 
static void rpc_fini (struct m0_client *m0c)
 
static int rpc_init (struct m0_client *m0c)
 
static void ast_thread (struct m0_client *m0c)
 
static void ha_process_event (struct m0_client *m0c, enum m0_conf_ha_process_event event)
 
static int ha_init (struct m0_client *m0c)
 
static void ha_fini (struct m0_client *m0c)
 
static bool rconfc_expired_cb (struct m0_clink *clink)
 
static bool rconfc_ready_cb (struct m0_clink *clink)
 
static void rconfc_fatal_cb (struct m0_rconfc *rconfc)
 
static void io_ref_cb (struct m0_ref *ref)
 
static bool confc_ready_async_cb (struct m0_clink *clink)
 
M0_INTERNAL int m0__io_ref_get (struct m0_client *m0c)
 
M0_INTERNAL void m0__io_ref_put (struct m0_client *m0c)
 
static int confc_init (struct m0_client *m0c)
 
static void confc_fini (struct m0_client *m0c)
 
static int pools_init (struct m0_client *m0c)
 
static void pools_fini (struct m0_client *m0c)
 
static int service_start (struct m0_reqh *reqh, struct m0_fid *sfid, struct m0_reqh_service_type *stype, struct m0_reqh_service **service)
 
static int rootfid_lookup (struct m0_client *m0c)
 
M0_INTERNAL void m0_client_global_fini (void)
 
static int get_online_cpus (void)
 
M0_INTERNAL int m0_client_global_init (void)
 
int m0_client_init (struct m0_client **m0c_p, struct m0_config *conf, bool init_m0)
 
void m0_client_fini (struct m0_client *m0c, bool fini_m0)
 
void m0_process_fid (const struct m0_client *m0c, struct m0_fid *proc_fid)
 

Variables

static const struct m0_bob_type m0c_bobtype
 
struct m0_conf_rootconf_root
 
struct m0_sm_state_descr initlift_phases []
 
struct m0_sm_trans_descr initlift_trans []
 
struct m0_sm_conf initlift_conf
 
static struct m0_motr_ha_cfg motr_ha_cfg
 
static struct m0 m0_client_motr_instance
 

Macro Definition Documentation

◆ M0_TRACE_SUBSYSTEM

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_CLIENT

Definition at line 49 of file client_init.c.

◆ NOT_EMPTY

#define NOT_EMPTY (   x)    (x != NULL && *x != '\0')

Definition at line 1530 of file client_init.c.

Enumeration Type Documentation

◆ initlift_states

The Initialisation code in client is fiddly, lots of different parts of motr need to be initialised in the correct order, if something fails, all the parts that have been initialised need to be finalised and an error returned.

This typically means that all the initialisation code needs to know how to finalise client too, while not being the finalisation code. A rats nest of implicit states need to be tracked by *_init functions, pinned down by a rack of gotos, so that init can 'fini' what it has done so far.

This gives us difficult to read duplicated code, which in turns gives us really-difficult-to-test code paths when one component fails to initialise.

Why not use a state machine? Client initialises these components, in this order. If something fails it automatically reverses and moves back to IL_UNINITIALISED.

Rule of thumb: if you need a goto, you are probably tracking some kind of state that should be added here instead.

Enumerator
IL_UNINITIALISED 
IL_NET 
IL_RPC 
IL_AST_THREAD 
IL_HA 
IL_CONFC 
IL_POOLS 
IL_POOL_VERSION 
IL_RESOURCE_MANAGER 
IL_LAYOUT_DB 
IL_IDX_SERVICE 
IL_ROOT_FID 
IL_ADDB2 
IL_DTM0 
IL_INITIALISED 
IL_FAILED 

Definition at line 92 of file client_init.c.

Function Documentation

◆ ast_thread()

static void ast_thread ( struct m0_client m0c)
static

This is heavily based on m0t1fs/linux_kernel/super.cast_thread

Definition at line 618 of file client_init.c.

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

◆ client_fid_sscanf()

static int client_fid_sscanf ( const char *  s,
struct m0_fid fid,
const char *  descr 
)
static

Definition at line 320 of file client_init.c.

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

◆ client_net_fini()

static void client_net_fini ( struct m0_client m0c)
static

This is heavily based on m0t1fs/linux_kernel/super.cm0t1fs_net_fini

Parameters
m0cthe client instance we are working with.

Definition at line 423 of file client_init.c.

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

◆ client_net_init()

static int client_net_init ( struct m0_client m0c)
static

This is heavily based on m0t1fs/linux_kernel/super.cm0t1fs_net_init. m0t1fs is a kernel model and it sets the local addr and other arguments when installing the kernel model. For Motr client, as it supports both user and kernel modes, it is not feasible to pass arguments as m0t1fs does, instead Client asks an applition to input local endpoint and others explictly. (comments on commit d56b031c)

Parameters
m0cthe client instance we are working with.
Returns
0 for success, or an -errno code.

Definition at line 448 of file client_init.c.

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

◆ confc_fini()

static void confc_fini ( struct m0_client m0c)
static

Definition at line 985 of file client_init.c.

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

◆ confc_init()

static int confc_init ( struct m0_client m0c)
static

Definition at line 906 of file client_init.c.

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

◆ confc_ready_async_cb()

static bool confc_ready_async_cb ( struct m0_clink clink)
static

Definition at line 858 of file client_init.c.

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

◆ get_online_cpus()

static int get_online_cpus ( void  )
static

Retrieves the number of online CPUs

Definition at line 1482 of file client_init.c.

Here is the caller graph for this function:

◆ ha_fini()

static void ha_fini ( struct m0_client m0c)
static

Clears global HA session info and terminates rpc session to HA service.

Definition at line 751 of file client_init.c.

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

◆ ha_init()

static int ha_init ( struct m0_client m0c)
static

Definition at line 715 of file client_init.c.

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

◆ ha_process_event()

static void ha_process_event ( struct m0_client m0c,
enum m0_conf_ha_process_event  event 
)
static

HA service connectivity.

Definition at line 684 of file client_init.c.

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

◆ initlift_addb2()

static int initlift_addb2 ( struct m0_sm mach)
static

Definition at line 1390 of file client_init.c.

Here is the call graph for this function:

◆ initlift_ast_thread()

static int initlift_ast_thread ( struct m0_sm mach)
static

Definition at line 639 of file client_init.c.

Here is the call graph for this function:

◆ initlift_confc()

static int initlift_confc ( struct m0_sm mach)
static

Definition at line 1009 of file client_init.c.

Here is the call graph for this function:

◆ initlift_dtm0()

static int initlift_dtm0 ( struct m0_sm mach)
static

Definition at line 1436 of file client_init.c.

Here is the call graph for this function:

◆ initlift_fail()

static void initlift_fail ( int  rc,
struct m0_client m0c 
)
static

Helper function to fail initialisation, move the lift into reverse and log the failing rc.

Parameters
rcthe failing rc.
m0cthe client instance we are working with.

Definition at line 388 of file client_init.c.

Here is the caller graph for this function:

◆ initlift_get_next_floor()

static int initlift_get_next_floor ( struct m0_client m0c)
static

Helper function to get the value of the next floor in the direction of travel.

Parameters
m0cthe client instance we are working with.
Returns
the next state/floor to transition to.

Definition at line 338 of file client_init.c.

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

◆ initlift_ha()

static int initlift_ha ( struct m0_sm mach)
static

Definition at line 769 of file client_init.c.

Here is the call graph for this function:

◆ initlift_idx_service()

static int initlift_idx_service ( struct m0_sm mach)
static

Definition at line 1223 of file client_init.c.

Here is the call graph for this function:

◆ initlift_layouts()

static int initlift_layouts ( struct m0_sm mach)
static

Definition at line 1199 of file client_init.c.

Here is the call graph for this function:

◆ initlift_move_next_floor()

static void initlift_move_next_floor ( struct m0_client m0c)
static

Helper function to move the initlift onto its next state in the direction of travel.

Parameters
m0cthe client instance we are working with.

Definition at line 363 of file client_init.c.

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

◆ initlift_net()

static int initlift_net ( struct m0_sm mach)
static

Definition at line 482 of file client_init.c.

Here is the call graph for this function:

◆ initlift_pool_version()

static int initlift_pool_version ( struct m0_sm mach)
static

Definition at line 1097 of file client_init.c.

Here is the call graph for this function:

◆ initlift_pools()

static int initlift_pools ( struct m0_sm mach)
static

Definition at line 1075 of file client_init.c.

Here is the call graph for this function:

◆ initlift_resource_manager()

static int initlift_resource_manager ( struct m0_sm mach)
static

Definition at line 1136 of file client_init.c.

Here is the call graph for this function:

◆ initlift_rootfid()

static int initlift_rootfid ( struct m0_sm mach)
static

Definition at line 1367 of file client_init.c.

Here is the call graph for this function:

◆ initlift_rpc()

static int initlift_rpc ( struct m0_sm mach)
static

Definition at line 596 of file client_init.c.

Here is the call graph for this function:

◆ initlift_uninitialised()

static int initlift_uninitialised ( struct m0_sm mach)
static

Forward declarations for state callbacks

Definition at line 398 of file client_init.c.

Here is the call graph for this function:

◆ io_ref_cb()

static void io_ref_cb ( struct m0_ref ref)
static

Definition at line 834 of file client_init.c.

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

◆ m0__io_ref_get()

M0_INTERNAL int m0__io_ref_get ( struct m0_client m0c)

Definition at line 868 of file client_init.c.

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

◆ m0__io_ref_put()

M0_INTERNAL void m0__io_ref_put ( struct m0_client m0c)

Definition at line 897 of file client_init.c.

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

◆ M0_BOB_DEFINE()

M0_BOB_DEFINE ( static  ,
m0c_bobtype,
m0_client   
)

◆ m0_client_global_fini()

M0_INTERNAL void m0_client_global_fini ( void  )

Definition at line 1460 of file client_init.c.

Here is the call graph for this function:

◆ m0_client_global_init()

M0_INTERNAL int m0_client_global_init ( void  )

global init/fini, used by motr/init.c

Definition at line 1495 of file client_init.c.

Here is the call graph for this function:

◆ m0_confc()

M0_INTERNAL struct m0_confc* m0_confc ( struct m0_client m0c)

Gets the confc from client instance.

Parameters
m0cclient instance.
Returns
the confc used by this client instance.

Definition at line 315 of file client_init.c.

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

◆ m0c_invariant()

static bool m0c_invariant ( struct m0_client m0c)
static

Checks a m0_client struct is correct.

Parameters
m0cThe client instance to check.
Returns
true or false.

Definition at line 305 of file client_init.c.

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

◆ pools_fini()

static void pools_fini ( struct m0_client m0c)
static

Definition at line 1066 of file client_init.c.

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

◆ pools_init()

static int pools_init ( struct m0_client m0c)
static

Definition at line 1031 of file client_init.c.

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

◆ rconfc()

static struct m0_rconfc* rconfc ( struct m0_client m0c)
static

Definition at line 310 of file client_init.c.

◆ rconfc_expired_cb()

static bool rconfc_expired_cb ( struct m0_clink clink)
static

Definition at line 790 of file client_init.c.

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

◆ rconfc_fatal_cb()

static void rconfc_fatal_cb ( struct m0_rconfc rconfc)
static

Definition at line 821 of file client_init.c.

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

◆ rconfc_ready_cb()

static bool rconfc_ready_cb ( struct m0_clink clink)
static

Definition at line 809 of file client_init.c.

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

◆ rootfid_lookup()

static int rootfid_lookup ( struct m0_client m0c)
static

Lookup the fid of the root filesystem. This is a m0t1fsism.

Parameters
m0cThe client instance we are working with.
Returns
0 for success, an error code otherwise.

Definition at line 1282 of file client_init.c.

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

◆ rpc_fini()

static void rpc_fini ( struct m0_client m0c)
static

This is heavily based on m0t1fs/linux_kernel/super.cm0t1fs_rpc_fini

Parameters
m0cthe client instance we are working with.

Definition at line 509 of file client_init.c.

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

◆ rpc_init()

static int rpc_init ( struct m0_client m0c)
static

This is heavily based on m0t1fs/linux_kernel/super.cm0t1fs_rpc_init

Parameters
m0cthe client instance we are working with.
Returns
0 for success, or an -errno code.

Definition at line 533 of file client_init.c.

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

◆ service_start()

static int service_start ( struct m0_reqh reqh,
struct m0_fid sfid,
struct m0_reqh_service_type stype,
struct m0_reqh_service **  service 
)
static

Definition at line 1129 of file client_init.c.

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

Variable Documentation

◆ conf_root

struct m0_conf_root* conf_root

Pointer to the root configuration object that a Client client attaches to. It is closed after Client initilisation is done as it may become invalid at some point of time.

Definition at line 68 of file client_init.c.

◆ initlift_conf

struct m0_sm_conf initlift_conf
Initial value:
= {
.scf_name = "initlift-conf",
.scf_nr_states = ARRAY_SIZE(initlift_phases),
.scf_state = initlift_phases,
.scf_trans = initlift_trans,
.scf_trans_nr = ARRAY_SIZE(initlift_trans),
}
struct m0_sm_trans_descr initlift_trans[]
Definition: client_init.c:225
struct m0_sm_state_descr initlift_phases[]
Definition: client_init.c:130
#define ARRAY_SIZE(a)
Definition: misc.h:45

Configuration structure for the client init state machine.

Definition at line 291 of file client_init.c.

◆ initlift_phases

struct m0_sm_state_descr initlift_phases[]

State machine phases for client operations.

Definition at line 130 of file client_init.c.

◆ initlift_trans

struct m0_sm_trans_descr initlift_trans[]

Textual descriptions for the valid state machine transitions.

Definition at line 225 of file client_init.c.

◆ m0_client_motr_instance

struct m0 m0_client_motr_instance
static

Definition at line 1532 of file client_init.c.

◆ m0c_bobtype

static const struct m0_bob_type m0c_bobtype
static
Initial value:
= {
.bt_name = "m0c_bobtype",
.bt_magix_offset = offsetof(struct m0_client, m0c_magic),
.bt_magix = M0_M0C_MAGIC,
.bt_check = NULL,
}
#define NULL
Definition: misc.h:38
#define offsetof(typ, memb)
Definition: misc.h:29

Definition at line 53 of file client_init.c.

◆ motr_ha_cfg

struct m0_motr_ha_cfg motr_ha_cfg
static

Establishes rpc session to HA service. The session is set up to be used globally.

Definition at line 714 of file client_init.c.