Motr  M0
File operation packet

Data Structures

struct  m0_fop_data
 
struct  m0_fop
 
struct  m0_fop_type
 
struct  m0_fop_type_ops
 
struct  __m0_fop_type_init_args
 
struct  m0_fop_type_batch
 
struct  m0_fop_fol_frag
 

Macros

#define M0_FOP_DEFAULT_ITEM_TYPE_OPS
 
#define M0_FOP_TYPE_INIT(ft, ...)
 
#define M0_FOP_TYPE_INIT2_DECL   struct __m0_fop_type_init_args __args
 
#define M0_FOP_TYPE_INIT2(ft, ...)
 
#define M0_FOP_XCODE_OBJ(f)
 

Typedefs

typedef uint32_t m0_fop_type_code_t
 

Enumerations

enum  m0_addb2_fop_counter { M0_AFC_PHASE, M0_AFC_STATE, M0_AFC_RPC_OUT, M0_AFC_RPC_IN }
 

Functions

 M0_TL_DESCR_DEFINE (ft, "fop types", static, struct m0_fop_type, ft_linkage, ft_magix, M0_FOP_TYPE_MAGIC, M0_FOP_TYPE_HEAD_MAGIC)
 
 M0_TL_DEFINE (ft, static, struct m0_fop_type)
 
M0_INTERNAL const char * m0_fop_name (const struct m0_fop *fop)
 
static size_t fop_data_size (const struct m0_fop *fop)
 
M0_INTERNAL bool m0_fop_rpc_is_locked (struct m0_fop *fop)
 
M0_INTERNAL int m0_fop_data_alloc (struct m0_fop *fop)
 
M0_INTERNAL void m0_fop_init (struct m0_fop *fop, struct m0_fop_type *fopt, void *data, void(*fop_release)(struct m0_ref *))
 
struct m0_fopm0_fop_alloc (struct m0_fop_type *fopt, void *data, struct m0_rpc_machine *mach)
 
struct m0_fopm0_fop_alloc_at (struct m0_rpc_session *sess, struct m0_fop_type *fopt)
 
struct m0_fopm0_fop_reply_alloc (struct m0_fop *req, struct m0_fop_type *rept)
 
M0_INTERNAL void m0_fop_fini (struct m0_fop *fop)
 
M0_INTERNAL void m0_fop_release (struct m0_ref *ref)
 
struct m0_fopm0_fop_get (struct m0_fop *fop)
 
void m0_fop_put (struct m0_fop *fop)
 
void m0_fop_put0 (struct m0_fop *fop)
 
void m0_fop_put_lock (struct m0_fop *fop)
 
void m0_fop_put0_lock (struct m0_fop *fop)
 
void * m0_fop_data (const struct m0_fop *fop)
 
uint32_t m0_fop_opcode (const struct m0_fop *fop)
 
void m0_fop_type_fini (struct m0_fop_type *fopt)
 
void m0_fop_type_init (struct m0_fop_type *ft, const struct __m0_fop_type_init_args *args)
 
M0_INTERNAL void m0_fop_type_init_nr (const struct m0_fop_type_batch *batch)
 
M0_INTERNAL void m0_fop_type_fini_nr (const struct m0_fop_type_batch *batch)
 
M0_INTERNAL struct m0_fop_typem0_fop_type_next (struct m0_fop_type *ftype)
 
 M0_FOL_FRAG_TYPE_DECLARE (m0_fop_fol_frag,, NULL, NULL, NULL, NULL)
 
M0_INTERNAL int m0_fops_init (void)
 
M0_INTERNAL void m0_fops_fini (void)
 
struct m0_rpc_itemm0_fop_to_rpc_item (const struct m0_fop *fop)
 
struct m0_fopm0_rpc_item_to_fop (const struct m0_rpc_item *item)
 
void m0_fop_rpc_machine_set (struct m0_fop *fop, struct m0_rpc_machine *mach)
 
struct m0_rpc_machinem0_fop_rpc_machine (const struct m0_fop *fop)
 
M0_INTERNAL struct m0_fop_typem0_item_type_to_fop_type (const struct m0_rpc_item_type *item_type)
 
M0_INTERNAL int m0_fop_encdec (struct m0_fop *fop, struct m0_bufvec_cursor *cur, enum m0_xcode_what what)
 
M0_INTERNAL struct m0_fop_typem0_fop_type_find (uint32_t opcode)
 
static int fop_xc_type (uint32_t opcode, const struct m0_xcode_type **out)
 
M0_INTERNAL int m0_fop_xc_type (const struct m0_xcode_obj *par, const struct m0_xcode_type **out)
 
M0_INTERNAL int m0_fop_rep_xc_type (const struct m0_xcode_obj *par, const struct m0_xcode_type **out)
 
M0_INTERNAL int m0_fop_fol_add (struct m0_fop *fop, struct m0_fop *rep, struct m0_dtx *dtx)
 
struct m0_rpc_machinem0_fop_session_machine (const struct m0_rpc_session *s)
 
int m0_fop_type_addb2_instrument (struct m0_fop_type *type)
 
struct m0_net_transfer_mcm0_fop_tm_get (const struct m0_fop *fop)
 
struct m0_net_domainm0_fop_domain_get (const struct m0_fop *fop)
 
void m0_fop_type_addb2_deinstrument (struct m0_fop_type *type)
 
M0_INTERNAL int m0_fop_item_type_default_encode (const struct m0_rpc_item_type *item_type, struct m0_rpc_item *item, struct m0_bufvec_cursor *cur)
 
M0_INTERNAL int m0_fop_item_type_default_decode (const struct m0_rpc_item_type *item_type, struct m0_rpc_item **item_out, struct m0_bufvec_cursor *cur)
 
M0_INTERNAL m0_bcount_t m0_fop_payload_size (const struct m0_rpc_item *item)
 
M0_INTERNAL int m0_fop_item_encdec (struct m0_rpc_item *item, struct m0_bufvec_cursor *cur, enum m0_xcode_what what)
 
void m0_fop_item_get (struct m0_rpc_item *item)
 
void m0_fop_item_put (struct m0_rpc_item *item)
 

Variables

static struct m0_mutex fop_types_lock
 
static struct m0_tl fop_types_list
 
M0_EXTERN struct m0_sm_conf fom_states_conf
 
const struct m0_rpc_item_type_ops m0_fop_default_item_type_ops
 
struct m0_fol_frag_type m0_fop_fol_frag_type
 

Detailed Description

File Operation Packet (fop, struct m0_fop) is a description of particular file system or storage operation. fop code knows how to serialise a fop to the network wire or storage buffer, and how to de-serialise it back, which makes it functionally similar to ONCRPC XDR.

A fop consists of fields. The structure and arrangement of a fop fields is described by a fop type (m0_fop_type), that also has a pointer to a set of operations that are used to manipulate the fop.

The execution of an operation described by fop is carried out by a "fop machine" (fom, struct m0_fom).

Note
"Had I been one of the tragic bums who lurked in the mist of that station platform where a brittle young FOP was pacing back and forth, I would not have withstood the temptation to destroy him."

This file contains definitions for encoding/decoding a fop type rpc item onto a bufvec.

See also
rpc/onwire.h

Macro Definition Documentation

◆ M0_FOP_DEFAULT_ITEM_TYPE_OPS

#define M0_FOP_DEFAULT_ITEM_TYPE_OPS
Value:
.rito_payload_size = m0_fop_payload_size, \
.rito_item_get = m0_fop_item_get, \
.rito_item_put = m0_fop_item_put
M0_INTERNAL m0_bcount_t m0_fop_payload_size(const struct m0_rpc_item *item)
Definition: fop_item_type.c:32
M0_INTERNAL int m0_fop_item_type_default_encode(const struct m0_rpc_item_type *item_type, struct m0_rpc_item *item, struct m0_bufvec_cursor *cur)
Definition: fop_item_type.c:47
M0_INTERNAL int m0_fop_item_type_default_decode(const struct m0_rpc_item_type *item_type, struct m0_rpc_item **item_out, struct m0_bufvec_cursor *cur)
Definition: fop_item_type.c:58
void m0_fop_item_put(struct m0_rpc_item *item)
void m0_fop_item_get(struct m0_rpc_item *item)

Definition at line 184 of file fop.h.

◆ M0_FOP_TYPE_INIT

#define M0_FOP_TYPE_INIT (   ft,
  ... 
)
Value:
__VA_ARGS__ });
void m0_fop_type_init(struct m0_fop_type *ft, const struct __m0_fop_type_init_args *args)
Definition: fop.c:247
static struct m0_fop_type * ft[]
Definition: service_ut.c:856

Helper macro which can be used to submit fop type initialisation parameters partially and out of order.

See also
http://www.cofault.com/2005/08/named-formals.html

Definition at line 307 of file fop.h.

◆ M0_FOP_TYPE_INIT2

#define M0_FOP_TYPE_INIT2 (   ft,
  ... 
)
Value:
({ \
__args = (struct __m0_fop_type_init_args) {__VA_ARGS__}; \
m0_fop_type_init((ft), &__args); })
static struct m0_fop_type * ft[]
Definition: service_ut.c:856

Definition at line 317 of file fop.h.

◆ M0_FOP_TYPE_INIT2_DECL

#define M0_FOP_TYPE_INIT2_DECL   struct __m0_fop_type_init_args __args

This variant of M0_FOP_TYPE_INIT() re-uses the same __args object in each M0_FOP_TYPE_INIT2() call instead of creating the new one on stack bloating its size (which may not overstep the 1K limit in kernel).

Definition at line 316 of file fop.h.

◆ M0_FOP_XCODE_OBJ

#define M0_FOP_XCODE_OBJ (   f)
Value:
(struct m0_xcode_obj) { \
.xo_type = f->f_type->ft_xt, \
.xo_ptr = m0_fop_data(f), \
}
static FILE * f
Definition: adieu.c:79
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220

Definition at line 334 of file fop.h.

Typedef Documentation

◆ m0_fop_type_code_t

typedef uint32_t m0_fop_type_code_t

Definition at line 277 of file fop.h.

Enumeration Type Documentation

◆ m0_addb2_fop_counter

Enumerator
M0_AFC_PHASE 

Fom phase transitions.

M0_AFC_STATE 

Fom state transitions.

M0_AFC_RPC_OUT 

Outgoing rpc item transitions.

M0_AFC_RPC_IN 

Incoming rpc item transitions.

Definition at line 372 of file fop.h.

Function Documentation

◆ fop_data_size()

static size_t fop_data_size ( const struct m0_fop fop)
static

Definition at line 60 of file fop.c.

Here is the caller graph for this function:

◆ fop_xc_type()

static int fop_xc_type ( uint32_t  opcode,
const struct m0_xcode_type **  out 
)
static

Definition at line 399 of file fop.c.

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

◆ M0_FOL_FRAG_TYPE_DECLARE()

M0_FOL_FRAG_TYPE_DECLARE ( m0_fop_fol_frag  ,
NULL  ,
NULL  ,
NULL  ,
NULL   
)

◆ m0_fop_alloc()

struct m0_fop * m0_fop_alloc ( struct m0_fop_type fopt,
void *  data,
struct m0_rpc_machine mach 
)

Allocates and initialises fop object

Parameters
foptfop type to assign to this fop object
datatop level data object if data == NULL, data is allocated by this function
machrpc machine needed to release the fop
Postcondition
ergo(result != NULL, m0_ref_read(&result->f_ref) == 1)

Definition at line 96 of file fop.c.

Here is the call graph for this function:

◆ m0_fop_alloc_at()

struct m0_fop * m0_fop_alloc_at ( struct m0_rpc_session sess,
struct m0_fop_type fopt 
)

Definition at line 122 of file fop.c.

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

◆ m0_fop_data()

void * m0_fop_data ( const struct m0_fop fop)

Definition at line 220 of file fop.c.

◆ m0_fop_data_alloc()

M0_INTERNAL int m0_fop_data_alloc ( struct m0_fop fop)

Allocate top level fop data

Definition at line 71 of file fop.c.

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

◆ m0_fop_domain_get()

struct m0_net_domain * m0_fop_domain_get ( const struct m0_fop fop)

Definition at line 486 of file fop.c.

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

◆ m0_fop_encdec()

M0_INTERNAL int m0_fop_encdec ( struct m0_fop fop,
struct m0_bufvec_cursor cur,
enum m0_xcode_what  what 
)

Definition at line 375 of file fop.c.

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

◆ m0_fop_fini()

M0_INTERNAL void m0_fop_fini ( struct m0_fop fop)

Finalises fop.

Very likely you want to use m0_fop_put().

Use this only when you're sure that there are no other references on the fop other than the one you're holding. e.g. the fop is embedded in some other object and because of some error there is a need to finalise fop even before it is posted to RPC.

Precondition
M0_IN(m0_ref_read(&fop->f_ref), (0, 1))
See also
m0_fop_put

Definition at line 136 of file fop.c.

Here is the call graph for this function:

◆ m0_fop_fol_add()

M0_INTERNAL int m0_fop_fol_add ( struct m0_fop fop,
struct m0_fop rep,
struct m0_dtx dtx 
)

Adds fol record fragment for this fop (m0_fop_fol_frag) to the transaction.

Definition at line 427 of file fop.c.

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

◆ m0_fop_get()

struct m0_fop * m0_fop_get ( struct m0_fop fop)

Takes a reference on the fop.

Precondition
m0_ref_read(&fop->f_ref) > 0

Definition at line 162 of file fop.c.

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

◆ m0_fop_init()

M0_INTERNAL void m0_fop_init ( struct m0_fop fop,
struct m0_fop_type fopt,
void *  data,
void(*)(struct m0_ref *)  fop_release 
)

Initialises fop.

'data' argument if non-null specifies address of top level data object. 'fop_release' is a pointer to function that will be called when last reference on the fop is dropped. fop_release is expected to finalise and free the fop.

See also
m0_fop_release.

m0_fop_init sets fop reference count to 1. The caller is expected to drop the reference using m0_fop_put().

Precondition
fop != NULL && fopt != NULL && fop_release != NULL
Postcondition
m0_ref_read(&fop->f_ref) == 1
See also
m0_fop_data_alloc()

Definition at line 79 of file fop.c.

Here is the call graph for this function:

◆ m0_fop_item_encdec()

M0_INTERNAL int m0_fop_item_encdec ( struct m0_rpc_item item,
struct m0_bufvec_cursor cur,
enum m0_xcode_what  what 
)

Helper function used by encode/decode ops of each item type (rito_encode, rito_decode) for decoding an rpc item into/from a bufvec

Definition at line 95 of file fop_item_type.c.

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

◆ m0_fop_item_get()

void m0_fop_item_get ( struct m0_rpc_item item)

Definition at line 107 of file fop_item_type.c.

Here is the call graph for this function:

◆ m0_fop_item_put()

void m0_fop_item_put ( struct m0_rpc_item item)

Definition at line 112 of file fop_item_type.c.

Here is the call graph for this function:

◆ m0_fop_item_type_default_decode()

M0_INTERNAL int m0_fop_item_type_default_decode ( const struct m0_rpc_item_type item_type,
struct m0_rpc_item **  item_out,
struct m0_bufvec_cursor cur 
)

Generic deserialization routine for a fop rpc item type. Allocates a new rpc item and decodes the header and the payload into this item.

Parameters
item_typePointer to the item type struct for the item.
itemPointer to the item containing deserialized rpc onwire data and payload.
curcurrent position of the cursor in the bufvec.
Return values
0On success.
-errnoif failure.

Definition at line 58 of file fop_item_type.c.

Here is the call graph for this function:

◆ m0_fop_item_type_default_encode()

M0_INTERNAL int m0_fop_item_type_default_encode ( const struct m0_rpc_item_type item_type,
struct m0_rpc_item item,
struct m0_bufvec_cursor cur 
)

Generic bufvec serialization routine for a fop rpc item type.

Parameters
item_typePointer to the item type struct for the item.
itempointer to the item which is to be serialized.
curcurrent position of the cursor in the bufvec.
Return values
0On success.
-errnoOn failure.

Definition at line 47 of file fop_item_type.c.

Here is the call graph for this function:

◆ m0_fop_name()

M0_INTERNAL const char * m0_fop_name ( const struct m0_fop fop)

Definition at line 55 of file fop.c.

Here is the caller graph for this function:

◆ m0_fop_opcode()

uint32_t m0_fop_opcode ( const struct m0_fop fop)

Definition at line 226 of file fop.c.

Here is the caller graph for this function:

◆ m0_fop_payload_size()

M0_INTERNAL m0_bcount_t m0_fop_payload_size ( const struct m0_rpc_item item)

Return the onwire size of the item type which is a fop in bytes. The onwire size of an item equals = size of (header + payload).

Parameters
itemThe rpc item for which the on wire size is to be calculated
Return values
Sizeof the item in bytes.

Definition at line 32 of file fop_item_type.c.

Here is the call graph for this function:

◆ m0_fop_put()

void m0_fop_put ( struct m0_fop fop)

Drops reference on the fop. If it was last reference the fop will be finalised and freed. Do not touch fop after call the this function.

Precondition
m0_ref_read(&fop->f_ref) > 0

Definition at line 177 of file fop.c.

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

◆ m0_fop_put0()

void m0_fop_put0 ( struct m0_fop fop)

Definition at line 192 of file fop.c.

Here is the call graph for this function:

◆ m0_fop_put0_lock()

void m0_fop_put0_lock ( struct m0_fop fop)

Definition at line 213 of file fop.c.

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

◆ m0_fop_put_lock()

void m0_fop_put_lock ( struct m0_fop fop)

Same as m0_fop_put() but also locks/unlocks rpc machine.

Definition at line 199 of file fop.c.

Here is the call graph for this function:

◆ m0_fop_release()

M0_INTERNAL void m0_fop_release ( struct m0_ref ref)

Default implementation of fop_release that can be passed to m0_fop_init() when fop is not embedded in any other object.

Definition at line 148 of file fop.c.

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

◆ m0_fop_rep_xc_type()

M0_INTERNAL int m0_fop_rep_xc_type ( const struct m0_xcode_obj par,
const struct m0_xcode_type **  out 
)

Definition at line 419 of file fop.c.

Here is the call graph for this function:

◆ m0_fop_reply_alloc()

struct m0_fop * m0_fop_reply_alloc ( struct m0_fop req,
struct m0_fop_type rept 
)

Definition at line 129 of file fop.c.

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

◆ m0_fop_rpc_is_locked()

M0_INTERNAL bool m0_fop_rpc_is_locked ( struct m0_fop fop)

Definition at line 66 of file fop.c.

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

◆ m0_fop_rpc_machine()

struct m0_rpc_machine * m0_fop_rpc_machine ( const struct m0_fop fop)

Definition at line 360 of file fop.c.

Here is the caller graph for this function:

◆ m0_fop_rpc_machine_set()

void m0_fop_rpc_machine_set ( struct m0_fop fop,
struct m0_rpc_machine mach 
)

Definition at line 352 of file fop.c.

Here is the caller graph for this function:

◆ m0_fop_session_machine()

struct m0_rpc_machine * m0_fop_session_machine ( const struct m0_rpc_session s)

Definition at line 453 of file fop.c.

Here is the caller graph for this function:

◆ m0_fop_tm_get()

struct m0_net_transfer_mc * m0_fop_tm_get ( const struct m0_fop fop)

Definition at line 479 of file fop.c.

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

◆ m0_fop_to_rpc_item()

struct m0_rpc_item * m0_fop_to_rpc_item ( const struct m0_fop fop)

Definition at line 338 of file fop.c.

Here is the caller graph for this function:

◆ m0_fop_type_addb2_deinstrument()

void m0_fop_type_addb2_deinstrument ( struct m0_fop_type type)

Definition at line 493 of file fop.c.

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

◆ m0_fop_type_addb2_instrument()

int m0_fop_type_addb2_instrument ( struct m0_fop_type type)

Definition at line 461 of file fop.c.

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

◆ m0_fop_type_find()

M0_INTERNAL struct m0_fop_type * m0_fop_type_find ( uint32_t  opcode)

Finds the fop type corresponding to the opcode.

Parameters
opcodeFOP opcode.
Returns
m0_fop_type ref. or NULL

Definition at line 388 of file fop.c.

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

◆ m0_fop_type_fini()

void m0_fop_type_fini ( struct m0_fop_type fopt)

Definition at line 232 of file fop.c.

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

◆ m0_fop_type_fini_nr()

M0_INTERNAL void m0_fop_type_fini_nr ( const struct m0_fop_type_batch batch)

Definition at line 288 of file fop.c.

Here is the call graph for this function:

◆ m0_fop_type_init()

void m0_fop_type_init ( struct m0_fop_type ft,
const struct __m0_fop_type_init_args args 
)

Definition at line 247 of file fop.c.

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

◆ m0_fop_type_init_nr()

M0_INTERNAL void m0_fop_type_init_nr ( const struct m0_fop_type_batch batch)

Definition at line 282 of file fop.c.

Here is the call graph for this function:

◆ m0_fop_type_next()

M0_INTERNAL struct m0_fop_type * m0_fop_type_next ( struct m0_fop_type ftype)

Iterates through the registered fop types.

To iterate across all registered fop types, first call this function with NULL parameter. NULL is returned to indicate end of the iteration.

If a fop type is registered or unregistered while an iteration is in progress, behaviour is undefined.

ftype = NULL;
while ((ftype = m0_fop_type_next(ftype)) != NULL) {
do something with ftype
}

Definition at line 296 of file fop.c.

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

◆ m0_fop_xc_type()

M0_INTERNAL int m0_fop_xc_type ( const struct m0_xcode_obj par,
const struct m0_xcode_type **  out 
)

Definition at line 411 of file fop.c.

Here is the call graph for this function:

◆ m0_fops_fini()

M0_INTERNAL void m0_fops_fini ( void  )

Definition at line 329 of file fop.c.

Here is the call graph for this function:

◆ m0_fops_init()

M0_INTERNAL int m0_fops_init ( void  )

Definition at line 315 of file fop.c.

Here is the call graph for this function:

◆ m0_item_type_to_fop_type()

M0_INTERNAL struct m0_fop_type * m0_item_type_to_fop_type ( const struct m0_rpc_item_type rit)

Returns a fop type associated with an rpc item type

Definition at line 369 of file fop.c.

Here is the caller graph for this function:

◆ m0_rpc_item_to_fop()

struct m0_fop * m0_rpc_item_to_fop ( const struct m0_rpc_item item)

Definition at line 346 of file fop.c.

◆ M0_TL_DEFINE()

M0_TL_DEFINE ( ft  ,
static  ,
struct m0_fop_type   
)

◆ M0_TL_DESCR_DEFINE()

M0_TL_DESCR_DEFINE ( ft  ,
"fop types"  ,
static  ,
struct m0_fop_type  ,
ft_linkage  ,
ft_magix  ,
M0_FOP_TYPE_MAGIC  ,
M0_FOP_TYPE_HEAD_MAGIC   
)

Variable Documentation

◆ fom_states_conf

M0_EXTERN struct m0_sm_conf fom_states_conf

Definition at line 314 of file fop.c.

◆ fop_types_list

struct m0_tl fop_types_list
static

Definition at line 47 of file fop.c.

◆ fop_types_lock

struct m0_mutex fop_types_lock
static

Definition at line 46 of file fop.c.

◆ m0_fop_default_item_type_ops

const struct m0_rpc_item_type_ops m0_fop_default_item_type_ops

Default rpc item type ops for fop item types

Definition at line 118 of file fop_item_type.c.

◆ m0_fop_fol_frag_type

struct m0_fol_frag_type m0_fop_fol_frag_type