-static struct update_request
-*osp_find_create_update_loc(struct thandle *th, struct dt_object *dt)
-{
- struct dt_device *dt_dev = lu2dt_dev(dt->do_lu.lo_dev);
- struct update_request *update;
- ENTRY;
-
- update = osp_find_update(th, dt_dev);
- if (update != NULL)
- RETURN(update);
-
- update = osp_create_update_req(dt_dev);
- if (IS_ERR(update))
- RETURN(update);
-
- cfs_list_add_tail(&update->ur_list, &th->th_remote_update_list);
-
- RETURN(update);
-}
-
-static int osp_get_attr_from_req(const struct lu_env *env,
- struct ptlrpc_request *req,
- struct lu_attr *attr, int index)
-{
- struct update_reply *reply;
- struct obdo *lobdo = &osp_env_info(env)->osi_obdo;
- struct obdo *wobdo;
- int size;
-
- LASSERT(attr != NULL);
-
- reply = req_capsule_server_sized_get(&req->rq_pill, &RMF_UPDATE_REPLY,
- UPDATE_BUFFER_SIZE);
- if (reply->ur_version != UPDATE_REPLY_V1)
- return -EPROTO;
-
- size = update_get_reply_buf(reply, (void **)&wobdo, index);
- if (size != sizeof(struct obdo))
- return -EPROTO;
-
- obdo_le_to_cpu(wobdo, wobdo);
- lustre_get_wire_obdo(NULL, lobdo, wobdo);
- la_from_obdo(attr, lobdo, lobdo->o_valid);
-
- return 0;
-}
-
-static int osp_md_declare_object_create(const struct lu_env *env,
- struct dt_object *dt,
- struct lu_attr *attr,
- struct dt_allocation_hint *hint,
- struct dt_object_format *dof,
- struct thandle *th)
-{
- struct osp_thread_info *osi = osp_env_info(env);
- struct update_request *update;
- struct lu_fid *fid1;
- int sizes[2] = {sizeof(struct obdo), 0};
- char *bufs[2] = {NULL, NULL};
- int buf_count;
- int rc;
-
-
- update = osp_find_create_update_loc(th, dt);
- if (IS_ERR(update)) {
- CERROR("%s: Get OSP update buf failed: rc = %d\n",
- dt->do_lu.lo_dev->ld_obd->obd_name,
- (int)PTR_ERR(update));
- return PTR_ERR(update);
- }
-
- osi->osi_obdo.o_valid = 0;
- LASSERT(S_ISDIR(attr->la_mode));
- obdo_from_la(&osi->osi_obdo, attr, attr->la_valid);
- lustre_set_wire_obdo(NULL, &osi->osi_obdo, &osi->osi_obdo);
- obdo_cpu_to_le(&osi->osi_obdo, &osi->osi_obdo);
-
- bufs[0] = (char *)&osi->osi_obdo;
- buf_count = 1;
- fid1 = (struct lu_fid *)lu_object_fid(&dt->do_lu);
- if (hint->dah_parent) {
- struct lu_fid *fid2;
- struct lu_fid *tmp_fid = &osi->osi_fid;
-
- fid2 = (struct lu_fid *)lu_object_fid(&hint->dah_parent->do_lu);
- fid_cpu_to_le(tmp_fid, fid2);
- sizes[1] = sizeof(*tmp_fid);
- bufs[1] = (char *)tmp_fid;
- buf_count++;
- }
-
- if (lu_object_exists(&dt->do_lu)) {
- /* If the object already exists, we needs to destroy
- * this orphan object first.
- *
- * The scenario might happen in this case
- *
- * 1. client send remote create to MDT0.
- * 2. MDT0 send create update to MDT1.
- * 3. MDT1 finished create synchronously.
- * 4. MDT0 failed and reboot.
- * 5. client resend remote create to MDT0.
- * 6. MDT0 tries to resend create update to MDT1,
- * but find the object already exists
- */
- CDEBUG(D_HA, "%s: object "DFID" exists, destroy this orphan\n",
- dt->do_lu.lo_dev->ld_obd->obd_name, PFID(fid1));
-
- rc = osp_insert_update(env, update, OBJ_REF_DEL, fid1, 0,
- NULL, NULL);
- if (rc != 0)
- GOTO(out, rc);
-
- if (S_ISDIR(lu_object_attr(&dt->do_lu))) {
- /* decrease for ".." */
- rc = osp_insert_update(env, update, OBJ_REF_DEL, fid1,
- 0, NULL, NULL);
- if (rc != 0)
- GOTO(out, rc);
- }
-
- rc = osp_insert_update(env, update, OBJ_DESTROY, fid1, 0, NULL,
- NULL);
- if (rc != 0)
- GOTO(out, rc);
-
- dt->do_lu.lo_header->loh_attr &= ~LOHA_EXISTS;
- /* Increase batchid to add this orphan object deletion
- * to separate transaction */
- osp_md_add_update_batchid(update);
- }
-
- rc = osp_insert_update(env, update, OBJ_CREATE, fid1, buf_count, sizes,
- bufs);
-out:
- if (rc)
- CERROR("%s: Insert update error: rc = %d\n",
- dt->do_lu.lo_dev->ld_obd->obd_name, rc);
-
- return rc;
-}
-
-static int osp_md_object_create(const struct lu_env *env, struct dt_object *dt,
- struct lu_attr *attr,
- struct dt_allocation_hint *hint,
- struct dt_object_format *dof,
- struct thandle *th)
-{
- struct osp_object *obj = dt2osp_obj(dt);
-
- CDEBUG(D_INFO, "create object "DFID"\n",
- PFID(&dt->do_lu.lo_header->loh_fid));
-
- /* Because the create update RPC will be sent during declare phase,
- * if creation reaches here, it means the object has been created
- * successfully */
- dt->do_lu.lo_header->loh_attr |= LOHA_EXISTS | (attr->la_mode & S_IFMT);
- obj->opo_empty = 1;
-
- return 0;
-}
-
-static int osp_md_declare_object_ref_del(const struct lu_env *env,
- struct dt_object *dt,
- struct thandle *th)
-{
- struct update_request *update;
- struct lu_fid *fid;
- int rc;
-
- update = osp_find_create_update_loc(th, dt);
- if (IS_ERR(update)) {
- CERROR("%s: Get OSP update buf failed: rc = %d\n",
- dt->do_lu.lo_dev->ld_obd->obd_name,
- (int)PTR_ERR(update));
- return PTR_ERR(update);
- }
-
- fid = (struct lu_fid *)lu_object_fid(&dt->do_lu);
-
- rc = osp_insert_update(env, update, OBJ_REF_DEL, fid, 0, NULL, NULL);
-
- return rc;
-}
-
-static int osp_md_object_ref_del(const struct lu_env *env,
- struct dt_object *dt,
- struct thandle *th)
-{
- CDEBUG(D_INFO, "ref del object "DFID"\n",
- PFID(&dt->do_lu.lo_header->loh_fid));
-
- return 0;
-}
-