Motr  M0
sync.c File Reference
#include "motr/addb.h"
#include "motr/client.h"
#include "motr/client_internal.h"
#include "motr/sync.h"
#include "lib/trace.h"
#include "lib/finject.h"
#include "mdservice/fsync_fops.h"
#include "fop/fom_generic.h"
#include "lib/memory.h"
#include "lib/tlist.h"
#include "lib/hash.h"
#include "file/file.h"
#include "motr/magic.h"
#include "pool/pool.h"
Include dependency graph for sync.c:

Go to the source code of this file.

Macros

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_CLIENT
 

Functions

 M0_BOB_DEFINE (static, &os_bobtype, m0_op_sync)
 
 M0_TL_DESCR_DEFINE (sync_target, "Targets to synced for a client SYNC request", static, struct sync_target, srt_tlink, srt_tlink_magic, M0_SYNC_TGT_TL_MAGIC, M0_SYNC_TGT_TL_MAGIC)
 
 M0_TL_DEFINE (sync_target, static, struct sync_target)
 
 M0_TL_DESCR_DEFINE (spf, "sync_fop_wrappers pending fsync-fops", static, struct sync_fop_wrapper, sfw_tlink, sfw_tlink_magic, M0_T1FS_FFW_TLIST_MAGIC1, M0_T1FS_FFW_TLIST_MAGIC2)
 
 M0_TL_DEFINE (spf, static, struct sync_fop_wrapper)
 
 M0_TL_DESCR_DEFINE (spti, "m0_reqh_service_txid pending list", M0_INTERNAL, struct m0_reqh_service_txid, stx_tlink, stx_link_magic, M0_INSTANCE_PTI_MAGIC, M0_INSTANCE_PTI_MAGIC)
 
 M0_TL_DEFINE (spti, M0_INTERNAL, struct m0_reqh_service_txid)
 
static void sync_fop_cleanup (struct m0_ref *ref)
 
static void sync_request_done_locked (struct sync_request *sreq)
 
static void sync_request_done (struct sync_request *sreq)
 
static void sync_request_ast (struct m0_sm_group *grp, struct m0_sm_ast *ast)
 
static void sync_fop_done (struct sync_fop_wrapper *sfw, int rc)
 
static void sync_fop_stx_update (struct m0_reqh_service_txid *stx, uint64_t txid)
 
static int sync_reply_process (struct sync_fop_wrapper *sfw)
 
static void sync_fop_ast (struct m0_sm_group *grp, struct m0_sm_ast *ast)
 
static void sync_rio_replied (struct m0_rpc_item *item)
 
static int sync_request_fop_send (struct sync_request *sreq, struct m0_reqh_service_txid *stx, enum m0_fsync_mode mode, bool set_ri_ops, struct sync_fop_wrapper **sfw_out)
 
static int sync_request_launch (struct sync_request *sreq, enum m0_fsync_mode mode, bool wait_after_launch)
 
static int sync_reply_wait (struct sync_fop_wrapper *sfw)
 
static int sync_request_launch_and_wait (struct sync_request *sreq, enum m0_fsync_mode mode)
 
static int sync_request_target_add (struct sync_request *sreq, int type, void *target)
 
static int sync_request_stx_add (struct sync_request *sreq, struct m0_tl *pending_tx_tl, struct m0_mutex *pending_tx_lock)
 
static void sync_pending_stx_update (struct m0_reqh_service_ctx *service, struct m0_mutex *pending_tx_lock, struct m0_tl *pending_tx, struct m0_be_tx_remid *btr)
 
void sync_record_update (struct m0_reqh_service_ctx *service, struct m0_entity *ent, struct m0_op *op, struct m0_be_tx_remid *btr)
 
static bool sync_op_invariant (struct m0_op_sync *os)
 
static void sync_op_cb_fini (struct m0_op_common *oc)
 
static void sync_op_cb_free (struct m0_op_common *oc)
 
static void sync_op_cb_launch (struct m0_op_common *oc)
 
static void sync_request_init (struct sync_request *sreq)
 
static int sync_op_init (struct m0_op *op)
 
int m0_sync_op_init (struct m0_op **sop)
 
int m0_sync_entity_add (struct m0_op *sop, struct m0_entity *ent)
 
int m0_sync_op_add (struct m0_op *sop, struct m0_op *op)
 
int m0_entity_sync (struct m0_entity *ent)
 
int m0_sync (struct m0_client *m0c, bool wait)
 
M0_INTERNAL struct m0_entitym0__op_sync_entity (const struct m0_op *op)
 

Variables

static const struct m0_bob_type os_bobtype
 
static struct sync_interactions si
 
static const struct m0_rpc_item_ops sync_ri_ops
 

Macro Definition Documentation

◆ M0_TRACE_SUBSYSTEM

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_CLIENT

Definition at line 28 of file sync.c.

Function Documentation

◆ m0__op_sync_entity()

M0_INTERNAL struct m0_entity* m0__op_sync_entity ( const struct m0_op op)

Return first entity from sync operation. It is used as helper function to get client instance from entity for sync operation.

Definition at line 1172 of file sync.c.

Here is the caller graph for this function:

◆ M0_BOB_DEFINE()

M0_BOB_DEFINE ( static  ,
os_bobtype,
m0_op_sync   
)

◆ M0_TL_DEFINE() [1/3]

M0_TL_DEFINE ( sync_target  ,
static  ,
struct sync_target   
)

◆ M0_TL_DEFINE() [2/3]

M0_TL_DEFINE ( spf  ,
static  ,
struct sync_fop_wrapper   
)

◆ M0_TL_DEFINE() [3/3]

M0_TL_DEFINE ( spti  ,
M0_INTERNAL  ,
struct m0_reqh_service_txid   
)

◆ M0_TL_DESCR_DEFINE() [1/3]

M0_TL_DESCR_DEFINE ( sync_target  ,
"Targets to synced for a client SYNC request"  ,
static  ,
struct sync_target  ,
srt_tlink  ,
srt_tlink_magic  ,
M0_SYNC_TGT_TL_MAGIC  ,
M0_SYNC_TGT_TL_MAGIC   
)

◆ M0_TL_DESCR_DEFINE() [2/3]

M0_TL_DESCR_DEFINE ( spf  ,
"sync_fop_wrappers pending fsync-fops"  ,
static  ,
struct sync_fop_wrapper  ,
sfw_tlink  ,
sfw_tlink_magic  ,
M0_T1FS_FFW_TLIST_MAGIC1  ,
M0_T1FS_FFW_TLIST_MAGIC2   
)

◆ M0_TL_DESCR_DEFINE() [3/3]

M0_TL_DESCR_DEFINE ( spti  ,
"m0_reqh_service_txid pending list ,
M0_INTERNAL  ,
struct m0_reqh_service_txid  ,
stx_tlink  ,
stx_link_magic  ,
M0_INSTANCE_PTI_MAGIC  ,
M0_INSTANCE_PTI_MAGIC   
)

◆ sync_fop_ast()

static void sync_fop_ast ( struct m0_sm_group grp,
struct m0_sm_ast ast 
)
static

AST callback to a FSYNC fop.

Definition at line 356 of file sync.c.

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

◆ sync_fop_cleanup()

static void sync_fop_cleanup ( struct m0_ref ref)
static

Cleans-up a fop.

Definition at line 133 of file sync.c.

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

◆ sync_fop_done()

static void sync_fop_done ( struct sync_fop_wrapper sfw,
int  rc 
)
static

It's called after the FSYNC reply fop is received and processed. Posts SYNC request's AST if it is the last reply fop for the SYNC request.

Definition at line 213 of file sync.c.

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

◆ sync_fop_stx_update()

static void sync_fop_stx_update ( struct m0_reqh_service_txid stx,
uint64_t  txid 
)
static

Update stx (m0_reqh_service_txid) of an entity or op after receiving FSYNC FOP reply from service.

Definition at line 244 of file sync.c.

Here is the caller graph for this function:

◆ sync_op_cb_fini()

static void sync_op_cb_fini ( struct m0_op_common oc)
static

Callback for an SYNC operation being finalised.

Definition at line 840 of file sync.c.

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

◆ sync_op_cb_free()

static void sync_op_cb_free ( struct m0_op_common oc)
static

'free entry' on the operations vector for SYNC operations.

Definition at line 861 of file sync.c.

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

◆ sync_op_cb_launch()

static void sync_op_cb_launch ( struct m0_op_common oc)
static

Callback for an SYNC operation being launched.

Definition at line 887 of file sync.c.

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

◆ sync_op_init()

static int sync_op_init ( struct m0_op op)
static

Definition at line 924 of file sync.c.

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

◆ sync_op_invariant()

static bool sync_op_invariant ( struct m0_op_sync os)
static

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

Client SYNC APIS *

Checks an SYNC operation is not malformed or corrupted.

Definition at line 828 of file sync.c.

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

◆ sync_pending_stx_update()

static void sync_pending_stx_update ( struct m0_reqh_service_ctx service,
struct m0_mutex pending_tx_lock,
struct m0_tl pending_tx,
struct m0_be_tx_remid btr 
)
static

Definition at line 748 of file sync.c.

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

◆ sync_record_update()

void sync_record_update ( struct m0_reqh_service_ctx service,
struct m0_entity ent,
struct m0_op op,
struct m0_be_tx_remid btr 
)

Updates a m0_reqh_service_txid with the specified be_tx_remid if the struct m0_be_tx_remid::tri_txid > the stored value obj may be NULL if the update has no associated inode.

Definition at line 788 of file sync.c.

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

◆ sync_reply_process()

static int sync_reply_process ( struct sync_fop_wrapper sfw)
static

Processes a reply to an fsync fop.

Definition at line 267 of file sync.c.

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

◆ sync_reply_wait()

static int sync_reply_wait ( struct sync_fop_wrapper sfw)
static

Waits for a reply to an fsync fop and process it. Cleans-up the fop allocated in sync_request_create.

Definition at line 567 of file sync.c.

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

◆ sync_request_ast()

static void sync_request_ast ( struct m0_sm_group grp,
struct m0_sm_ast ast 
)
static

Definition at line 192 of file sync.c.

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

◆ sync_request_done()

static void sync_request_done ( struct sync_request sreq)
static

Definition at line 178 of file sync.c.

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

◆ sync_request_done_locked()

static void sync_request_done_locked ( struct sync_request sreq)
static

Definition at line 150 of file sync.c.

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

◆ sync_request_fop_send()

static int sync_request_fop_send ( struct sync_request sreq,
struct m0_reqh_service_txid stx,
enum m0_fsync_mode  mode,
bool  set_ri_ops,
struct sync_fop_wrapper **  sfw_out 
)
static

Creates and sends an fsync fop from the provided m0_reqh_service_txid. Allocates and returns the fop wrapper at on success, which is freed on the last m0_fop_put().

Definition at line 411 of file sync.c.

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

◆ sync_request_init()

static void sync_request_init ( struct sync_request sreq)
static

Definition at line 915 of file sync.c.

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

◆ sync_request_launch()

static int sync_request_launch ( struct sync_request sreq,
enum m0_fsync_mode  mode,
bool  wait_after_launch 
)
static

Definition at line 488 of file sync.c.

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

◆ sync_request_launch_and_wait()

static int sync_request_launch_and_wait ( struct sync_request sreq,
enum m0_fsync_mode  mode 
)
static

Client sends an fsync-fop to a list of services, then blocks, waiting for replies. This is implemented as two loops. The 'fop sending loop', generates and posts fops, adding them to a list of pending fops. This is all done while holding the m0__entity::en_pending_tx_lock. The 'reply receiving loop' works over the list of pending fops, waiting for a reply for each one. It acquires the m0_obj::ob_pending_tx_map_lock only when necessary.

Definition at line 600 of file sync.c.

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

◆ sync_request_stx_add()

static int sync_request_stx_add ( struct sync_request sreq,
struct m0_tl pending_tx_tl,
struct m0_mutex pending_tx_lock 
)
static

Definition at line 673 of file sync.c.

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

◆ sync_request_target_add()

static int sync_request_target_add ( struct sync_request sreq,
int  type,
void *  target 
)
static

Definition at line 631 of file sync.c.

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

◆ sync_rio_replied()

static void sync_rio_replied ( struct m0_rpc_item item)
static

rio_replied RPC callback to be executed whenever a reply to FSYNC fop is received.

Definition at line 378 of file sync.c.

Here is the call graph for this function:

Variable Documentation

◆ os_bobtype

static const struct m0_bob_type os_bobtype
static
Initial value:
= {
.bt_name = "os_bobtype",
.bt_magix_offset = offsetof(struct m0_op_sync, os_magic),
.bt_magix = M0_OS_MAGIC,
.bt_check = NULL,
}
#define NULL
Definition: misc.h:38
#define offsetof(typ, memb)
Definition: misc.h:29

Client SYNC APIs follow the design described in m0t1fs/linux_kernel/fsync.h and are implemented with the following modifications/extensions.

(1) 3 APIs are added to create/initialise SYNC op and to add entities and operations to sync: m0_sync_op_init(): create a new SYNC op. m0_sync_entity_add(): Add an entity to SYNC op. m0_sync_op_add(): Add an op to SYNC op. The op can only added if its state is M0_OS_STABLE or M0_OS_EXECUTED.

m0t1fs_fsync() and m0t1fs_sync_fs() are changed to m0__entity_fsync() and m0_sync() respectively.

(2) Add support to sync index. A new fop type m0_fop_fsync_cas_fopt is added. See its definition in cas/cas.c. CAS handles FSYNC fops as IOS and MDS do by setting fom_ops to &m0_fsync_fom_ops and sm to &m0_fsync_fom_conf.

(3) For index UPDATE queries such as PUT and DEL, CAS piggy-backs the latest txid of an CAS servie in reply fop (via m0_cas_rep::cgr_mod_rep).

(4) Client maintains a list of {service, txid} pairs for each SYNC op. This list is constructed/updated when new elements are added to SYNC op. For a newly added pair {svc, t2}, if there exists a pair {svc, t1} in the list, these 2 pairs are merged into one {svc, max(t1, t2)}.

(5) An SYNC op (and request) may send multiple FSYNC fops to services. The process of reply fops is: (a) The rpc item callback, sync_ri_callback() is called to invoke the fop AST, sync_fop_ast, to process the reply fop. (b) Posts SYNC request's AST, sync_request_ast, if it is the last reply fop for the SYNC request. (c) SYNC op's state is moved to STABLE only if every FSYNC fop is executed successfully.

(6) Each entity and op has a list of pending service txid. The pending txid is updated when any UPDATE fop on entity is replied with latest txid of a service. The update process is added for dix/cas. Updating txid for cas is straightforward. For dix, an function pointer m0_dix_cli::dx_sync_rec_update is added and client related information (entity and op) is passed to dix via m0_dix_req::dr_sync_datum.

Definition at line 83 of file sync.c.

◆ si

struct sync_interactions si
static
Initial value:
= {
.si_post_rpc = &m0_rpc_post,
.si_wait_for_reply = &m0_rpc_item_wait_for_reply,
.si_fop_fini = &m0_fop_fini,
.si_fop_put = &m0_fop_put_lock,
}
M0_INTERNAL int m0_rpc_post(struct m0_rpc_item *item)
Definition: rpc.c:63
int m0_rpc_item_wait_for_reply(struct m0_rpc_item *item, m0_time_t timeout)
Definition: item.c:824
M0_INTERNAL void m0_fop_fini(struct m0_fop *fop)
Definition: fop.c:136
void m0_fop_put_lock(struct m0_fop *fop)
Definition: fop.c:199

Ugly abstraction of sync interactions with wider motr code

  • purely to facilitate unit testing.

Definition at line 121 of file sync.c.

◆ sync_ri_ops

const struct m0_rpc_item_ops sync_ri_ops
static
Initial value:
= {
.rio_replied = sync_rio_replied,
}
static void sync_rio_replied(struct m0_rpc_item *item)
Definition: sync.c:378

RPC callbacks for the posting of FSYNC fops to services.

Definition at line 401 of file sync.c.