-static int osp_prep_update_req(const struct lu_env *env,
- struct osp_device *osp,
- struct update_buf *ubuf, int ubuf_len,
- struct ptlrpc_request **reqp)
-{
- struct obd_import *imp;
- struct ptlrpc_request *req;
- struct update_buf *tmp;
- int rc;
- ENTRY;
-
- imp = osp->opd_obd->u.cli.cl_import;
- LASSERT(imp);
-
- req = ptlrpc_request_alloc(imp, &RQF_UPDATE_OBJ);
- if (req == NULL)
- RETURN(-ENOMEM);
-
- req_capsule_set_size(&req->rq_pill, &RMF_UPDATE, RCL_CLIENT,
- UPDATE_BUFFER_SIZE);
-
- rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, UPDATE_OBJ);
- if (rc != 0) {
- ptlrpc_req_finished(req);
- RETURN(rc);
- }
-
- req_capsule_set_size(&req->rq_pill, &RMF_UPDATE_REPLY, RCL_SERVER,
- UPDATE_BUFFER_SIZE);
-
- tmp = req_capsule_client_get(&req->rq_pill, &RMF_UPDATE);
- memcpy(tmp, ubuf, ubuf_len);
-
- ptlrpc_request_set_replen(req);
-
- *reqp = req;
-
- RETURN(rc);
-}
-
-static int osp_remote_sync(const struct lu_env *env, struct dt_device *dt,
- struct update_request *update,
- struct ptlrpc_request **reqp)
-{
- struct osp_device *osp = dt2osp_dev(dt);
- struct ptlrpc_request *req = NULL;
- int rc;
- ENTRY;
-
- rc = osp_prep_update_req(env, osp, update->ur_buf, UPDATE_BUFFER_SIZE,
- &req);
- if (rc)
- RETURN(rc);
-
- /* Note: some dt index api might return non-zero result here, like
- * osd_index_ea_lookup, so we should only check rc < 0 here */
- rc = ptlrpc_queue_wait(req);
- if (rc < 0) {
- ptlrpc_req_finished(req);
- update->ur_rc = rc;
- RETURN(rc);
- }
-
- if (reqp != NULL) {
- *reqp = req;
- RETURN(rc);
- }
-
- update->ur_rc = rc;
-
- ptlrpc_req_finished(req);
-
- RETURN(rc);
-}
-
-/**
- * Create a new update request for the device.
- */
-static struct update_request
-*osp_create_update_req(struct dt_device *dt)
-{
- struct update_request *update;
-
- OBD_ALLOC_PTR(update);
- if (!update)
- return ERR_PTR(-ENOMEM);
-
- OBD_ALLOC_LARGE(update->ur_buf, UPDATE_BUFFER_SIZE);
- if (update->ur_buf == NULL) {
- OBD_FREE_PTR(update);
- return ERR_PTR(-ENOMEM);
- }
-
- CFS_INIT_LIST_HEAD(&update->ur_list);
- update->ur_dt = dt;
- update->ur_batchid = 0;
- update->ur_buf->ub_magic = UPDATE_BUFFER_MAGIC;
- update->ur_buf->ub_count = 0;
-
- return update;
-}
-
-static void osp_destroy_update_req(struct update_request *update)
-{
- if (update == NULL)
- return;
-
- cfs_list_del(&update->ur_list);
- if (update->ur_buf != NULL)
- OBD_FREE_LARGE(update->ur_buf, UPDATE_BUFFER_SIZE);
-
- OBD_FREE_PTR(update);
- return;
-}
-
-int osp_trans_stop(const struct lu_env *env, struct thandle *th)
-{
- int rc = 0;
-
- rc = th->th_current_request->ur_rc;
- osp_destroy_update_req(th->th_current_request);
- th->th_current_request = NULL;
-
- return rc;
-}
-
-/**
- * In DNE phase I, all remote updates will be packed into RPC (the format
- * description is in lustre_idl.h) during declare phase, all of updates
- * are attached to the transaction, one entry per OSP. Then in trans start,
- * LOD will walk through these entries and send these UPDATEs to the remote
- * MDT to be executed synchronously.
- */
-int osp_trans_start(const struct lu_env *env, struct dt_device *dt,
- struct thandle *th)
-{
- struct update_request *update;
- int rc = 0;
-
- /* In phase I, if the transaction includes remote updates, the local
- * update should be synchronized, so it will set th_sync = 1 */
- update = th->th_current_request;
- LASSERT(update != NULL && update->ur_dt == dt);
- if (update->ur_buf->ub_count > 0) {
- rc = osp_remote_sync(env, dt, update, NULL);
- th->th_sync = 1;
- }
-
- RETURN(rc);
-}
-