Motr  M0
client.c File Reference
#include "lib/vec.h"
#include "lib/types.h"
#include "lib/memory.h"
#include "lib/errno.h"
#include "sm/sm.h"
#include "layout/layout.h"
#include "ioservice/fid_convert.h"
#include "motr/addb.h"
#include "motr/client.h"
#include "motr/client_internal.h"
#include "motr/layout.h"
#include "motr/sync.h"
#include "lib/trace.h"
#include "lib/finject.h"
Include dependency graph for client.c:

Go to the source code of this file.

Macros

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_CLIENT
 

Enumerations

enum  { MAX_OPCODE = 256 }
 

Functions

 M0_BOB_DEFINE (M0_INTERNAL, &oc_bobtype, m0_op_common)
 
 M0_BOB_DEFINE (M0_INTERNAL, &oo_bobtype, m0_op_obj)
 
 M0_BOB_DEFINE (M0_INTERNAL, &op_bobtype, m0_op)
 
 M0_BOB_DEFINE (M0_INTERNAL, &ar_bobtype, m0_ast_rc)
 
M0_INTERNAL struct m0_clientm0__entity_instance (const struct m0_entity *entity)
 
M0_INTERNAL struct m0_clientm0__op_instance (const struct m0_op *op)
 
M0_INTERNAL struct m0_opm0__ioo_to_op (struct m0_op_io *ioo)
 
M0_INTERNAL bool m0__is_oostore (struct m0_client *instance)
 
M0_INTERNAL struct m0_clientm0__obj_instance (const struct m0_obj *obj)
 
M0_INTERNAL struct m0_clientm0__idx_instance (const struct m0_idx *idx)
 
M0_INTERNAL struct m0_localitym0__locality_pick (struct m0_client *cinst)
 
M0_INTERNAL bool m0_entity_type_is_valid (enum m0_entity_type type)
 
M0_INTERNAL bool entity_invariant_full (struct m0_entity *ent)
 
M0_INTERNAL bool entity_invariant_locked (const struct m0_entity *ent)
 
M0_INTERNAL bool m0_op_invariant (const struct m0_op *op)
 
M0_INTERNAL bool m0_op_entity_invariant (const struct m0_op *op)
 
M0_INTERNAL bool entity_id_is_valid (const struct m0_uint128 *id)
 
M0_INTERNAL void m0_entity_init (struct m0_entity *entity, struct m0_realm *parent, const struct m0_uint128 *id, const enum m0_entity_type type)
 
void m0_obj_init (struct m0_obj *obj, struct m0_realm *parent, const struct m0_uint128 *id, uint64_t layout_id)
 
void m0_entity_fini (struct m0_entity *entity)
 
void m0_obj_fini (struct m0_obj *obj)
 
M0_INTERNAL int m0_op_executed (struct m0_op *op)
 
M0_INTERNAL int m0_op_stable (struct m0_op *op)
 
M0_INTERNAL int m0_op_failed (struct m0_op *op)
 
M0_INTERNAL int m0_op_get (struct m0_op **op, size_t size)
 
M0_INTERNAL void m0_op_cancel_one (struct m0_op *op)
 
void m0_op_cancel (struct m0_op **op, uint32_t nr)
 
static void addb2_add_op_attrs (const struct m0_op *op)
 
M0_INTERNAL void m0_op_launch_one (struct m0_op *op)
 
void m0_op_launch (struct m0_op **op, uint32_t nr)
 
int32_t m0_op_wait (struct m0_op *op, uint64_t bits, m0_time_t to)
 
M0_INTERNAL int m0_op_alloc (struct m0_op **op, size_t op_size)
 
M0_INTERNAL int m0_op_init (struct m0_op *op, const struct m0_sm_conf *conf, struct m0_entity *entity)
 
void m0_op_fini (struct m0_op *op)
 
void m0_op_free (struct m0_op *op)
 
void m0_op_setup (struct m0_op *op, const struct m0_op_ops *cbs, m0_time_t linger)
 
void m0_op_kick (struct m0_op *op)
 
int32_t m0_rc (const struct m0_op *op)
 

Variables

const struct m0_bob_type oc_bobtype
 
const struct m0_bob_type oo_bobtype
 
const struct m0_bob_type op_bobtype
 
const struct m0_bob_type ar_bobtype
 
const struct m0_uint128 M0_UBER_REALM = {0UL, 1ULL}
 
const struct m0_uint128 M0_ID_APP = { 0ULL, 0x100000ULL }
 
static uint64_t opcount [MAX_OPCODE]
 
struct m0_sm_state_descr m0_op_phases []
 
struct m0_sm_trans_descr m0_op_trans []
 
struct m0_sm_conf m0_op_conf
 
struct m0_sm_state_descr entity_phases []
 
struct m0_sm_trans_descr entity_trans []
 
struct m0_sm_conf entity_conf
 

Macro Definition Documentation

◆ M0_TRACE_SUBSYSTEM

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_CLIENT

Definition at line 37 of file client.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MAX_OPCODE 

Definition at line 95 of file client.c.

Function Documentation

◆ addb2_add_op_attrs()

static void addb2_add_op_attrs ( const struct m0_op op)
static

Definition at line 658 of file client.c.

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

◆ entity_id_is_valid()

M0_INTERNAL bool entity_id_is_valid ( const struct m0_uint128 id)

Check if entity's id is valid.

Definition at line 354 of file client.c.

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

◆ entity_invariant_full()

M0_INTERNAL bool entity_invariant_full ( struct m0_entity ent)

Definition at line 300 of file client.c.

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

◆ entity_invariant_locked()

M0_INTERNAL bool entity_invariant_locked ( const struct m0_entity ent)

Entity invariant. Checks type and state machine.

Parameters
entAn entity.
Returns
Whether the entities type is valid.

Definition at line 320 of file client.c.

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

◆ m0__entity_instance()

M0_INTERNAL struct m0_client* m0__entity_instance ( const struct m0_entity entity)

-------------------------------------------------------------------------—*

Helper functions *

Definition at line 226 of file client.c.

Here is the caller graph for this function:

◆ m0__idx_instance()

M0_INTERNAL struct m0_client* m0__idx_instance ( const struct m0_idx idx)

Returns the m0_client instance, found from the provided index.

Parameters
idxThe index to find the instance for.
Returns
A pointer to the m0_client instance.

Definition at line 269 of file client.c.

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

◆ m0__ioo_to_op()

M0_INTERNAL struct m0_op* m0__ioo_to_op ( struct m0_op_io ioo)

Returns generic client op from io op.

Definition at line 249 of file client.c.

Here is the caller graph for this function:

◆ m0__is_oostore()

M0_INTERNAL bool m0__is_oostore ( struct m0_client instance)

Returns if client instance is operating under oostore mode.

Definition at line 255 of file client.c.

Here is the caller graph for this function:

◆ m0__locality_pick()

M0_INTERNAL struct m0_locality* m0__locality_pick ( struct m0_client cinst)

Pick a locality: Motr and the new locality interface(chore) now uses TLS to store data and these data are set when a "motr" thread is created. An application thread (not the main thread calling m0_init, considering ST multi-threading framework), it doesn't have the same TLS by nature, which causes a problem when it calls motr functions like m0_locality_here/get directly as below.

Ensure to use m0_thread_adopt/shun to make a thread (non-)motrism when a thread starts/ends.

TODO: more intelligent locality selection policy based on fid and workload.

Definition at line 290 of file client.c.

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

◆ m0__obj_instance()

M0_INTERNAL struct m0_client* m0__obj_instance ( const struct m0_obj obj)

Returns the m0_ client instance, found from the provided object.

Parameters
objThe object to find the instance for.
Returns
A pointer to the m0_ instance.

Definition at line 261 of file client.c.

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

◆ m0__op_instance()

M0_INTERNAL struct m0_client* m0__op_instance ( const struct m0_op op)

Returns the m0_ client instance, found from the provided operation.

Parameters
opThe Operation to find the instance for.
Returns
A pointer to the m0_ instance.

Definition at line 236 of file client.c.

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

◆ M0_BOB_DEFINE() [1/4]

M0_BOB_DEFINE ( M0_INTERNAL  ,
oc_bobtype,
m0_op_common   
)

◆ M0_BOB_DEFINE() [2/4]

M0_BOB_DEFINE ( M0_INTERNAL  ,
oo_bobtype,
m0_op_obj   
)

◆ M0_BOB_DEFINE() [3/4]

M0_BOB_DEFINE ( M0_INTERNAL  ,
op_bobtype,
m0_op   
)

◆ M0_BOB_DEFINE() [4/4]

M0_BOB_DEFINE ( M0_INTERNAL  ,
ar_bobtype,
m0_ast_rc   
)

◆ m0_entity_init()

M0_INTERNAL void m0_entity_init ( struct m0_entity entity,
struct m0_realm parent,
const struct m0_uint128 id,
const enum m0_entity_type  type 
)

-------------------------------------------------------------------------—*

Entity, Object and Index *

Definition at line 371 of file client.c.

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

◆ m0_entity_type_is_valid()

M0_INTERNAL bool m0_entity_type_is_valid ( enum m0_entity_type  type)

Definition at line 295 of file client.c.

Here is the caller graph for this function:

◆ m0_op_alloc()

M0_INTERNAL int m0_op_alloc ( struct m0_op **  op,
size_t  op_size 
)

Allocates memory for an operation.

Remarks
For each m0_op the implementation maintains some additional data. Therefore, the amount of memory allocated by this function is typically greater than sizeof(struct m0_op)
Parameters
[out]opPointer to the allocated operation.
op_sizeSize of the operation to be allocated. Must be greater than sizeof(struct m0_op_common).
Returns
0 if the operation was correctly allocated or -ENOMEM if it not enough memory was available.

Definition at line 779 of file client.c.

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

◆ m0_op_cancel_one()

M0_INTERNAL void m0_op_cancel_one ( struct m0_op op)

Cancel a launched single operation, called from m0_op_cancel.

Definition at line 599 of file client.c.

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

◆ m0_op_entity_invariant()

M0_INTERNAL bool m0_op_entity_invariant ( const struct m0_op op)

Checks if entiry is valid for NON-SYNC ops.

Definition at line 344 of file client.c.

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

◆ m0_op_executed()

M0_INTERNAL int m0_op_executed ( struct m0_op op)

----------------------------------------------------------------------——*

Operations *

This executes the optional user-provided callback. Called with the group lock held.

Parameters
machThe state machine which has changed to this state.
Returns
-1, stay in this state.

Definition at line 500 of file client.c.

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

◆ m0_op_failed()

M0_INTERNAL int m0_op_failed ( struct m0_op op)

Callback triggered by the state machine entering the 'FAILED' state. This in turn finds and executes the optional user-provided callback. Called with the group lock held.

Parameters
machThe state machine which has changed to this state.
Returns
-1, stay in this state.

Definition at line 548 of file client.c.

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

◆ m0_op_get()

M0_INTERNAL int m0_op_get ( struct m0_op **  op,
size_t  size 
)

Definition at line 568 of file client.c.

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

◆ m0_op_init()

M0_INTERNAL int m0_op_init ( struct m0_op op,
const struct m0_sm_conf conf,
struct m0_entity entity 
)

Initialises a client operation in its most generic form.

Parameters
opOperation being initialised.
confConfiguration for the operation state machine.
entityEntity the operation is targeted to.
Returns
0 if the operation succeeds. -EMGSIZE if the operation was pre-allocated with the wrong size. -ENOMEM if it was not possible to allocate memory for the operation.

Definition at line 806 of file client.c.

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

◆ m0_op_invariant()

M0_INTERNAL bool m0_op_invariant ( const struct m0_op op)

Op invariant. Checks op's bob.

Parameters
opAn op.
Returns
Whether the entities type is valid.

Definition at line 334 of file client.c.

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

◆ m0_op_launch_one()

M0_INTERNAL void m0_op_launch_one ( struct m0_op op)

Launches a single operation, called from m0_op_launch.

 * PRE(op != NULL);  PRE(op->op_sm.sm_state == M0_OS_INITIALISED);  PRE(ergo(op->op_entity != NULL, entity_invariant_full(op->op_entity)); PRE((op->op_size >= sizeof(*oc)));

Parameters
opThe operation to be launch

Definition at line 686 of file client.c.

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

◆ m0_op_stable()

M0_INTERNAL int m0_op_stable ( struct m0_op op)

This in turn finds and executes the optional user-provided callback. Called with the group lock held.

Parameters
machThe state machine which has changed to this state.
Returns
-1, stay in this state.

Definition at line 520 of file client.c.

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

Variable Documentation

◆ ar_bobtype

const struct m0_bob_type ar_bobtype
Initial value:
= {
.bt_name = "ar_bobtype",
.bt_magix_offset = offsetof(struct m0_ast_rc, ar_magic),
.bt_magix = M0_M0_AST_RC_MAGIC,
.bt_check = NULL,
}
#define NULL
Definition: misc.h:38
#define offsetof(typ, memb)
Definition: misc.h:29

Definition at line 73 of file client.c.

◆ entity_conf

struct m0_sm_conf entity_conf
Initial value:
= {
.scf_name = "entity-conf",
.scf_nr_states = ARRAY_SIZE(entity_phases),
.scf_state = entity_phases,
.scf_trans = entity_trans,
.scf_trans_nr = ARRAY_SIZE(entity_trans),
}
struct m0_sm_trans_descr entity_trans[]
Definition: client.c:194
struct m0_sm_state_descr entity_phases[]
Definition: client.c:156
#define ARRAY_SIZE(a)
Definition: misc.h:45

Configuration structure for the client entity state machine.

Definition at line 213 of file client.c.

◆ entity_phases

struct m0_sm_state_descr entity_phases[]

State machine phases for client entities.

Definition at line 156 of file client.c.

◆ entity_trans

struct m0_sm_trans_descr entity_trans[]
Initial value:
= {
{"creating", M0_ES_INIT, M0_ES_CREATING},
{"deleting", M0_ES_OPEN, M0_ES_DELETING},
{"opening", M0_ES_INIT, M0_ES_OPENING},
{"finished-creating", M0_ES_CREATING, M0_ES_OPEN},
{"finished-deleting", M0_ES_DELETING, M0_ES_INIT},
{"failed-to-create", M0_ES_CREATING, M0_ES_FAILED},
{"failed-to-delete", M0_ES_DELETING, M0_ES_FAILED},
{"failed-to-open", M0_ES_OPENING, M0_ES_FAILED},
{"closing", M0_ES_OPEN, M0_ES_CLOSING},
{"failed-to-open", M0_ES_OPEN, M0_ES_FAILED},
{"finished-closing", M0_ES_CLOSING, M0_ES_INIT},
{"failed-to-close", M0_ES_CLOSING, M0_ES_FAILED},
}

Textual descriptions for the valid state machine transitions.

Definition at line 194 of file client.c.

◆ m0_op_phases

struct m0_sm_state_descr m0_op_phases[]
Initial value:
= {
.sd_name = "initialised",
.sd_allowed = M0_BITS(M0_OS_LAUNCHED,
},
.sd_name = "launched",
.sd_allowed = M0_BITS(M0_OS_EXECUTED,
},
.sd_name = "executed",
.sd_allowed = M0_BITS(M0_OS_STABLE,
},
.sd_name = "stable",
},
.sd_name = "failed",
},
}
#define M0_BITS(...)
Definition: misc.h:236

State machine phases for client operations. Note: sd_flags of OS_EXECUTED is set to M0_SDF_TERMINAL to allow an APP to wait on this state

Definition at line 103 of file client.c.

◆ m0_op_trans

struct m0_sm_trans_descr m0_op_trans[]
Initial value:
= {
{"failed-to-launch", M0_OS_INITIALISED, M0_OS_FAILED},
{"operation-executed", M0_OS_LAUNCHED, M0_OS_EXECUTED},
{"operation-failed", M0_OS_LAUNCHED, M0_OS_FAILED},
{"transaction-stable", M0_OS_EXECUTED, M0_OS_STABLE},
{"transaction-failed", M0_OS_EXECUTED, M0_OS_FAILED},
}

Textual descriptions for the valid state machine transitions.

Definition at line 133 of file client.c.

◆ oc_bobtype

const struct m0_bob_type oc_bobtype
Initial value:
= {
.bt_name = "op_common_bobtype",
.bt_magix_offset = offsetof(struct m0_op_common, oc_magic),
.bt_magix = M0_OC_MAGIC,
.bt_check = NULL,
}
#define NULL
Definition: misc.h:38
#define offsetof(typ, memb)
Definition: misc.h:29

Bob definitions

Definition at line 44 of file client.c.

◆ oo_bobtype

const struct m0_bob_type oo_bobtype
Initial value:
= {
.bt_name = "m0_op_obj_bobtype",
.bt_magix_offset = offsetof(struct m0_op_obj, oo_magic),
.bt_magix = M0_OO_MAGIC,
.bt_check = NULL,
}
#define NULL
Definition: misc.h:38
#define offsetof(typ, memb)
Definition: misc.h:29

Definition at line 45 of file client.c.

◆ op_bobtype

const struct m0_bob_type op_bobtype
Initial value:
= {
.bt_name = "m0_op_bobtype",
.bt_magix_offset = offsetof(struct m0_op, op_magic),
.bt_magix = M0_OP_MAGIC,
.bt_check = NULL,
}
#define NULL
Definition: misc.h:38
Definition: client.h:641
#define offsetof(typ, memb)
Definition: misc.h:29

Definition at line 46 of file client.c.

◆ opcount

uint64_t opcount[MAX_OPCODE]
static

Definition at line 96 of file client.c.