/** * Lookup with version checking. * * This checks version of 'name'. Many reint functions uses 'name' for child not * FID, therefore we need to get object by name and check its version. */ int mdt_lookup_version_check(struct mdt_thread_info *info, struct mdt_object *p, struct lu_name *lname, struct lu_fid *fid, int idx) { int rc, vbrc; rc = mdo_lookup(info->mti_env, mdt_object_child(p), lname, fid, &info->mti_spec); /* Check version only during replay */ if (!req_is_replay(mdt_info_req(info))) return rc; info->mti_ver[idx] = ENOENT_VERSION; if (rc == 0) { struct mdt_object *child; child = mdt_object_find(info->mti_env, info->mti_mdt, fid); if (likely(!IS_ERR(child))) { mdt_obj_version_get(info, child, &info->mti_ver[idx]); mdt_object_put(info->mti_env, child); } } vbrc = mdt_version_check(mdt_info_req(info), info->mti_ver[idx], idx); return vbrc ? vbrc : rc; }
static int mdt_rename_unpack(struct mdt_thread_info *info) { struct lu_ucred *uc = mdt_ucred(info); struct mdt_rec_rename *rec; struct md_attr *ma = &info->mti_attr; struct lu_attr *attr = &info->mti_attr.ma_attr; struct mdt_reint_record *rr = &info->mti_rr; struct req_capsule *pill = info->mti_pill; int rc; ENTRY; CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint)); rec = req_capsule_client_get(pill, &RMF_REC_REINT); if (rec == NULL) RETURN(-EFAULT); /* This prior initialization is needed for old_init_ucred_reint() */ uc->uc_fsuid = rec->rn_fsuid; uc->uc_fsgid = rec->rn_fsgid; uc->uc_cap = rec->rn_cap; uc->uc_suppgids[0] = rec->rn_suppgid1; uc->uc_suppgids[1] = rec->rn_suppgid2; attr->la_uid = rec->rn_fsuid; attr->la_gid = rec->rn_fsgid; rr->rr_fid1 = &rec->rn_fid1; rr->rr_fid2 = &rec->rn_fid2; attr->la_ctime = rec->rn_time; attr->la_mtime = rec->rn_time; /* rename_tgt contains the mode already */ attr->la_mode = rec->rn_mode; attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE; if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT)) mdt_set_capainfo(info, 0, rr->rr_fid1, req_capsule_client_get(pill, &RMF_CAPA1)); if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT)) mdt_set_capainfo(info, 1, rr->rr_fid2, req_capsule_client_get(pill, &RMF_CAPA2)); rc = mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, 0); if (rc < 0) RETURN(rc); rc = mdt_name_unpack(pill, &RMF_SYMTGT, &rr->rr_tgt_name, 0); if (rc < 0) RETURN(rc); if (rec->rn_bias & MDS_VTX_BYPASS) ma->ma_attr_flags |= MDS_VTX_BYPASS; else ma->ma_attr_flags &= ~MDS_VTX_BYPASS; info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info)); rc = mdt_dlmreq_unpack(info); RETURN(rc); }
/** * Check version is correct. * * Should be called only during replay. */ static int mdt_version_check(struct ptlrpc_request *req, __u64 version, int idx) { __u64 *pre_ver = lustre_msg_get_versions(req->rq_reqmsg); ENTRY; if (!exp_connect_vbr(req->rq_export)) RETURN(0); LASSERT(req_is_replay(req)); /** VBR: version is checked always because costs nothing */ LASSERT(idx < PTLRPC_NUM_VERSIONS); /** Sanity check for malformed buffers */ if (pre_ver == NULL) { CERROR("No versions in request buffer\n"); spin_lock(&req->rq_export->exp_lock); req->rq_export->exp_vbr_failed = 1; spin_unlock(&req->rq_export->exp_lock); RETURN(-EOVERFLOW); } else if (pre_ver[idx] != version) { CDEBUG(D_INODE, "Version mismatch "LPX64" != "LPX64"\n", pre_ver[idx], version); spin_lock(&req->rq_export->exp_lock); req->rq_export->exp_vbr_failed = 1; spin_unlock(&req->rq_export->exp_lock); RETURN(-EOVERFLOW); } RETURN(0); }
static int mdt_rename_unpack(struct mdt_thread_info *info) { struct md_ucred *uc = mdt_ucred(info); struct mdt_rec_rename *rec; struct md_attr *ma = &info->mti_attr; struct lu_attr *attr = &info->mti_attr.ma_attr; struct mdt_reint_record *rr = &info->mti_rr; struct req_capsule *pill = info->mti_pill; int rc; ENTRY; CLASSERT(sizeof(struct mdt_rec_rename) == sizeof(struct mdt_rec_reint)); rec = req_capsule_client_get(pill, &RMF_REC_REINT); if (rec == NULL) RETURN(-EFAULT); uc->mu_fsuid = rec->rn_fsuid; uc->mu_fsgid = rec->rn_fsgid; uc->mu_cap = rec->rn_cap; uc->mu_suppgids[0] = rec->rn_suppgid1; uc->mu_suppgids[1] = rec->rn_suppgid2; attr->la_uid = rec->rn_fsuid; attr->la_gid = rec->rn_fsgid; rr->rr_fid1 = &rec->rn_fid1; rr->rr_fid2 = &rec->rn_fid2; attr->la_ctime = rec->rn_time; attr->la_mtime = rec->rn_time; /* rename_tgt contains the mode already */ attr->la_mode = rec->rn_mode; attr->la_valid = LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_MODE; if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT)) mdt_set_capainfo(info, 0, rr->rr_fid1, req_capsule_client_get(pill, &RMF_CAPA1)); if (req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT)) mdt_set_capainfo(info, 1, rr->rr_fid2, req_capsule_client_get(pill, &RMF_CAPA2)); info->mti_spec.sp_ck_split = !!(rec->rn_bias & MDS_CHECK_SPLIT); info->mti_cross_ref = !!(rec->rn_bias & MDS_CROSS_REF); rr->rr_name = req_capsule_client_get(pill, &RMF_NAME); rr->rr_tgt = req_capsule_client_get(pill, &RMF_SYMTGT); if (rr->rr_name == NULL || rr->rr_tgt == NULL) RETURN(-EFAULT); rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1; rr->rr_tgtlen = req_capsule_get_size(pill, &RMF_SYMTGT, RCL_CLIENT) - 1; if (!info->mti_cross_ref) LASSERT(rr->rr_namelen > 0 && rr->rr_tgtlen > 0); if (rec->rn_bias & MDS_VTX_BYPASS) ma->ma_attr_flags |= MDS_VTX_BYPASS; else ma->ma_attr_flags &= ~MDS_VTX_BYPASS; info->mti_spec.no_create = !!req_is_replay(mdt_info_req(info)); rc = mdt_dlmreq_unpack(info); RETURN(rc); }
/** * Save enoent version, it is needed when it is obvious that object doesn't * exist, e.g. child during create. */ static void mdt_enoent_version_save(struct mdt_thread_info *info, int idx) { /* save version of file name for replay, it must be ENOENT here */ if (!req_is_replay(mdt_info_req(info))) { info->mti_ver[idx] = ENOENT_VERSION; mdt_version_save(mdt_info_req(info), info->mti_ver[idx], idx); } }
/** * Get version from disk and save in reply buffer. * * Versions are saved in reply only during normal operations not replays. */ void mdt_version_get_save(struct mdt_thread_info *info, struct mdt_object *mto, int idx) { /* don't save versions during replay */ if (!req_is_replay(mdt_info_req(info))) { mdt_obj_version_get(info, mto, &info->mti_ver[idx]); mdt_version_save(mdt_info_req(info), info->mti_ver[idx], idx); } }
/** * Get version from disk and check it, no save in reply. */ int mdt_version_get_check(struct mdt_thread_info *info, struct mdt_object *mto, int idx) { /* only check versions during replay */ if (!req_is_replay(mdt_info_req(info))) return 0; mdt_obj_version_get(info, mto, &info->mti_ver[idx]); return mdt_version_check(mdt_info_req(info), info->mti_ver[idx], idx); }
/** * Get version from disk and check if recovery or just save. */ int mdt_version_get_check_save(struct mdt_thread_info *info, struct mdt_object *mto, int idx) { int rc = 0; mdt_obj_version_get(info, mto, &info->mti_ver[idx]); if (req_is_replay(mdt_info_req(info))) rc = mdt_version_check(mdt_info_req(info), info->mti_ver[idx], idx); else mdt_version_save(mdt_info_req(info), info->mti_ver[idx], idx); return rc; }
/** * Save pre-versions in reply. */ static void mdt_version_save(struct ptlrpc_request *req, __u64 version, int idx) { __u64 *reply_ver; if (!exp_connect_vbr(req->rq_export)) return; LASSERT(!req_is_replay(req)); LASSERT(req->rq_repmsg != NULL); reply_ver = lustre_msg_get_versions(req->rq_repmsg); if (reply_ver) reply_ver[idx] = version; }
/* * please see comment above LOV_MAGIC_V1_DEF */ static void mdt_fix_lov_magic(struct mdt_thread_info *info) { struct mdt_reint_record *rr = &info->mti_rr; struct lov_user_md_v1 *v1; v1 = (void *)rr->rr_eadata; LASSERT(v1); if (unlikely(req_is_replay(mdt_info_req(info)))) { if (v1->lmm_magic == LOV_USER_MAGIC_V1) { v1->lmm_magic = LOV_MAGIC_V1_DEF; } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V1)) { v1->lmm_magic = __swab32(LOV_MAGIC_V1_DEF); } else if (v1->lmm_magic == LOV_USER_MAGIC_V3) { v1->lmm_magic = LOV_MAGIC_V3_DEF; } else if (v1->lmm_magic == __swab32(LOV_USER_MAGIC_V3)) { v1->lmm_magic = __swab32(LOV_MAGIC_V3_DEF); } } }
static int mdt_open_unpack(struct mdt_thread_info *info) { struct md_ucred *uc = mdt_ucred(info); struct mdt_rec_create *rec; struct lu_attr *attr = &info->mti_attr.ma_attr; struct req_capsule *pill = info->mti_pill; struct mdt_reint_record *rr = &info->mti_rr; struct ptlrpc_request *req = mdt_info_req(info); struct md_op_spec *sp = &info->mti_spec; ENTRY; CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint)); rec = req_capsule_client_get(pill, &RMF_REC_REINT); if (rec == NULL) RETURN(-EFAULT); uc->mu_fsuid = rec->cr_fsuid; uc->mu_fsgid = rec->cr_fsgid; uc->mu_cap = rec->cr_cap; uc->mu_suppgids[0] = rec->cr_suppgid1; uc->mu_suppgids[1] = rec->cr_suppgid2; rr->rr_fid1 = &rec->cr_fid1; rr->rr_fid2 = &rec->cr_fid2; rr->rr_handle = &rec->cr_old_handle; attr->la_mode = rec->cr_mode; attr->la_rdev = rec->cr_rdev; attr->la_uid = rec->cr_fsuid; attr->la_gid = rec->cr_fsgid; attr->la_ctime = rec->cr_time; attr->la_mtime = rec->cr_time; attr->la_atime = rec->cr_time; attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_ATIME; memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u)); info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec); /* Do not trigger ASSERTION if client miss to set such flags. */ if (unlikely(info->mti_spec.sp_cr_flags == 0)) RETURN(-EPROTO); info->mti_replayepoch = rec->cr_ioepoch; info->mti_spec.sp_ck_split = !!(rec->cr_bias & MDS_CHECK_SPLIT); info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF); if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT)) mdt_set_capainfo(info, 0, rr->rr_fid1, req_capsule_client_get(pill, &RMF_CAPA1)); if (req_is_replay(req) && req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT)) { #if 0 mdt_set_capainfo(info, 1, rr->rr_fid2, req_capsule_client_get(pill, &RMF_CAPA2)); #else /* * FIXME: capa in replay open request might have expired, * bypass capa check. Security hole? */ mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA); mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA); #endif } rr->rr_name = req_capsule_client_get(pill, &RMF_NAME); if (rr->rr_name == NULL) RETURN(-EFAULT); rr->rr_namelen = req_capsule_get_size(pill, &RMF_NAME, RCL_CLIENT) - 1; sp->u.sp_ea.eadatalen = req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT); if (sp->u.sp_ea.eadatalen) { sp->u.sp_ea.eadata = req_capsule_client_get(pill, &RMF_EADATA); sp->no_create = !!req_is_replay(req); } RETURN(0); }
static int mdt_open_unpack(struct mdt_thread_info *info) { struct lu_ucred *uc = mdt_ucred(info); struct mdt_rec_create *rec; struct lu_attr *attr = &info->mti_attr.ma_attr; struct req_capsule *pill = info->mti_pill; struct mdt_reint_record *rr = &info->mti_rr; struct ptlrpc_request *req = mdt_info_req(info); struct md_op_spec *sp = &info->mti_spec; ENTRY; CLASSERT(sizeof(struct mdt_rec_create) == sizeof(struct mdt_rec_reint)); rec = req_capsule_client_get(pill, &RMF_REC_REINT); if (rec == NULL) RETURN(-EFAULT); /* This prior initialization is needed for old_init_ucred_reint() */ uc->uc_fsuid = rec->cr_fsuid; uc->uc_fsgid = rec->cr_fsgid; uc->uc_cap = rec->cr_cap; uc->uc_suppgids[0] = rec->cr_suppgid1; uc->uc_suppgids[1] = rec->cr_suppgid2; uc->uc_umask = rec->cr_umask; rr->rr_fid1 = &rec->cr_fid1; rr->rr_fid2 = &rec->cr_fid2; rr->rr_handle = &rec->cr_old_handle; attr->la_mode = rec->cr_mode; attr->la_rdev = rec->cr_rdev; attr->la_uid = rec->cr_fsuid; attr->la_gid = rec->cr_fsgid; attr->la_ctime = rec->cr_time; attr->la_mtime = rec->cr_time; attr->la_atime = rec->cr_time; attr->la_valid = LA_MODE | LA_RDEV | LA_UID | LA_GID | LA_CTIME | LA_MTIME | LA_ATIME; memset(&info->mti_spec.u, 0, sizeof(info->mti_spec.u)); info->mti_spec.sp_cr_flags = get_mrc_cr_flags(rec); /* Do not trigger ASSERTION if client miss to set such flags. */ if (unlikely(info->mti_spec.sp_cr_flags == 0)) RETURN(-EPROTO); info->mti_replayepoch = rec->cr_ioepoch; info->mti_cross_ref = !!(rec->cr_bias & MDS_CROSS_REF); if (req_capsule_get_size(pill, &RMF_CAPA1, RCL_CLIENT)) mdt_set_capainfo(info, 0, rr->rr_fid1, req_capsule_client_get(pill, &RMF_CAPA1)); if (req_is_replay(req) && req_capsule_get_size(pill, &RMF_CAPA2, RCL_CLIENT)) { #if 0 mdt_set_capainfo(info, 1, rr->rr_fid2, req_capsule_client_get(pill, &RMF_CAPA2)); #else /* * FIXME: capa in replay open request might have expired, * bypass capa check. Security hole? */ mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA); mdt_set_capainfo(info, 1, rr->rr_fid2, BYPASS_CAPA); #endif } mdt_name_unpack(pill, &RMF_NAME, &rr->rr_name, MNF_FIX_ANON); if (req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) { rr->rr_eadatalen = req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT); if (rr->rr_eadatalen > 0) { rr->rr_eadata = req_capsule_client_get(pill, &RMF_EADATA); sp->u.sp_ea.eadatalen = rr->rr_eadatalen; sp->u.sp_ea.eadata = rr->rr_eadata; sp->no_create = !!req_is_replay(req); mdt_fix_lov_magic(info); } /* * Client default md_size may be 0 right after client start, * until all osc are connected, set here just some reasonable * value to prevent misbehavior. */ if (rr->rr_eadatalen == 0 && !(info->mti_spec.sp_cr_flags & MDS_OPEN_DELAY_CREATE)) rr->rr_eadatalen = MIN_MD_SIZE; } RETURN(0); }
/** * Object updates between Targets. Because all the updates has been * dis-assemblied into object updates at sender side, so OUT will * call OSD API directly to execute these updates. * * In DNE phase I all of the updates in the request need to be executed * in one transaction, and the transaction has to be synchronously. * * Please refer to lustre/include/lustre/lustre_idl.h for req/reply * format. */ int out_handle(struct tgt_session_info *tsi) { const struct lu_env *env = tsi->tsi_env; struct tgt_thread_info *tti = tgt_th_info(env); struct thandle_exec_args *ta = &tti->tti_tea; struct req_capsule *pill = tsi->tsi_pill; struct dt_device *dt = tsi->tsi_tgt->lut_bottom; struct object_update_request *ureq; struct object_update *update; struct object_update_reply *reply; int bufsize; int count; int old_batchid = -1; int i; int rc = 0; int rc1 = 0; ENTRY; req_capsule_set(pill, &RQF_OUT_UPDATE); ureq = req_capsule_client_get(pill, &RMF_OUT_UPDATE); if (ureq == NULL) { CERROR("%s: No buf!: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } bufsize = req_capsule_get_size(pill, &RMF_OUT_UPDATE, RCL_CLIENT); if (bufsize != object_update_request_size(ureq)) { CERROR("%s: invalid bufsize %d: rc = %d\n", tgt_name(tsi->tsi_tgt), bufsize, -EPROTO); RETURN(err_serious(-EPROTO)); } if (ureq->ourq_magic != UPDATE_REQUEST_MAGIC) { CERROR("%s: invalid update buffer magic %x expect %x: " "rc = %d\n", tgt_name(tsi->tsi_tgt), ureq->ourq_magic, UPDATE_REQUEST_MAGIC, -EPROTO); RETURN(err_serious(-EPROTO)); } count = ureq->ourq_count; if (count <= 0) { CERROR("%s: empty update: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } req_capsule_set_size(pill, &RMF_OUT_UPDATE_REPLY, RCL_SERVER, OUT_UPDATE_REPLY_SIZE); rc = req_capsule_server_pack(pill); if (rc != 0) { CERROR("%s: Can't pack response: rc = %d\n", tgt_name(tsi->tsi_tgt), rc); RETURN(rc); } /* Prepare the update reply buffer */ reply = req_capsule_server_get(pill, &RMF_OUT_UPDATE_REPLY); if (reply == NULL) RETURN(err_serious(-EPROTO)); object_update_reply_init(reply, count); tti->tti_u.update.tti_update_reply = reply; rc = out_tx_start(env, dt, ta, tsi->tsi_exp); if (rc != 0) RETURN(rc); tti->tti_mult_trans = !req_is_replay(tgt_ses_req(tsi)); /* Walk through updates in the request to execute them synchronously */ for (i = 0; i < count; i++) { struct tgt_handler *h; struct dt_object *dt_obj; update = object_update_request_get(ureq, i, NULL); if (update == NULL) GOTO(out, rc = -EPROTO); if (ptlrpc_req_need_swab(pill->rc_req)) lustre_swab_object_update(update); if (old_batchid == -1) { old_batchid = update->ou_batchid; } else if (old_batchid != update->ou_batchid) { /* Stop the current update transaction, * create a new one */ rc = out_tx_end(env, ta); if (rc < 0) RETURN(rc); rc = out_tx_start(env, dt, ta, tsi->tsi_exp); if (rc != 0) RETURN(rc); old_batchid = update->ou_batchid; } if (!fid_is_sane(&update->ou_fid)) { CERROR("%s: invalid FID "DFID": rc = %d\n", tgt_name(tsi->tsi_tgt), PFID(&update->ou_fid), -EPROTO); GOTO(out, rc = err_serious(-EPROTO)); } dt_obj = dt_locate(env, dt, &update->ou_fid); if (IS_ERR(dt_obj)) GOTO(out, rc = PTR_ERR(dt_obj)); if (dt->dd_record_fid_accessed) { lfsck_pack_rfa(&tti->tti_lr, lu_object_fid(&dt_obj->do_lu)); tgt_lfsck_in_notify(env, dt, &tti->tti_lr); } tti->tti_u.update.tti_dt_object = dt_obj; tti->tti_u.update.tti_update = update; tti->tti_u.update.tti_update_reply_index = i; h = out_handler_find(update->ou_type); if (likely(h != NULL)) { /* For real modification RPC, check if the update * has been executed */ if (h->th_flags & MUTABOR) { struct ptlrpc_request *req = tgt_ses_req(tsi); if (out_check_resent(env, dt, dt_obj, req, out_reconstruct, reply, i)) GOTO(next, rc); } rc = h->th_act(tsi); } else { CERROR("%s: The unsupported opc: 0x%x\n", tgt_name(tsi->tsi_tgt), update->ou_type); lu_object_put(env, &dt_obj->do_lu); GOTO(out, rc = -ENOTSUPP); } next: lu_object_put(env, &dt_obj->do_lu); if (rc < 0) GOTO(out, rc); } out: rc1 = out_tx_end(env, ta); if (rc == 0) rc = rc1; RETURN(rc); }
/** * Object updates between Targets. Because all the updates has been * dis-assemblied into object updates at sender side, so OUT will * call OSD API directly to execute these updates. * * In DNE phase I all of the updates in the request need to be executed * in one transaction, and the transaction has to be synchronously. * * Please refer to lustre/include/lustre/lustre_idl.h for req/reply * format. */ int out_handle(struct tgt_session_info *tsi) { const struct lu_env *env = tsi->tsi_env; struct tgt_thread_info *tti = tgt_th_info(env); struct thandle_exec_args *ta = &tti->tti_tea; struct req_capsule *pill = tsi->tsi_pill; struct dt_device *dt = tsi->tsi_tgt->lut_bottom; struct out_update_header *ouh; struct out_update_buffer *oub = NULL; struct object_update *update; struct object_update_reply *reply; struct ptlrpc_bulk_desc *desc = NULL; struct l_wait_info lwi; void **update_bufs; int current_batchid = -1; __u32 update_buf_count; unsigned int i; unsigned int reply_index = 0; int rc = 0; int rc1 = 0; int ouh_size, reply_size; int updates; ENTRY; req_capsule_set(pill, &RQF_OUT_UPDATE); ouh_size = req_capsule_get_size(pill, &RMF_OUT_UPDATE_HEADER, RCL_CLIENT); if (ouh_size <= 0) RETURN(err_serious(-EPROTO)); ouh = req_capsule_client_get(pill, &RMF_OUT_UPDATE_HEADER); if (ouh == NULL) RETURN(err_serious(-EPROTO)); if (ouh->ouh_magic != OUT_UPDATE_HEADER_MAGIC) { CERROR("%s: invalid update buffer magic %x expect %x: " "rc = %d\n", tgt_name(tsi->tsi_tgt), ouh->ouh_magic, UPDATE_REQUEST_MAGIC, -EPROTO); RETURN(err_serious(-EPROTO)); } update_buf_count = ouh->ouh_count; if (update_buf_count == 0) RETURN(err_serious(-EPROTO)); OBD_ALLOC(update_bufs, sizeof(*update_bufs) * update_buf_count); if (update_bufs == NULL) RETURN(err_serious(-ENOMEM)); if (ouh->ouh_inline_length > 0) { update_bufs[0] = ouh->ouh_inline_data; } else { struct out_update_buffer *tmp; oub = req_capsule_client_get(pill, &RMF_OUT_UPDATE_BUF); if (oub == NULL) GOTO(out_free, rc = err_serious(-EPROTO)); desc = ptlrpc_prep_bulk_exp(pill->rc_req, update_buf_count, PTLRPC_BULK_OPS_COUNT, PTLRPC_BULK_GET_SINK | PTLRPC_BULK_BUF_KVEC, MDS_BULK_PORTAL, &ptlrpc_bulk_kvec_ops); if (desc == NULL) GOTO(out_free, rc = err_serious(-ENOMEM)); tmp = oub; for (i = 0; i < update_buf_count; i++, tmp++) { if (tmp->oub_size >= OUT_MAXREQSIZE) GOTO(out_free, rc = err_serious(-EPROTO)); OBD_ALLOC(update_bufs[i], tmp->oub_size); if (update_bufs[i] == NULL) GOTO(out_free, rc = err_serious(-ENOMEM)); desc->bd_frag_ops->add_iov_frag(desc, update_bufs[i], tmp->oub_size); } pill->rc_req->rq_bulk_write = 1; rc = sptlrpc_svc_prep_bulk(pill->rc_req, desc); if (rc != 0) GOTO(out_free, rc = err_serious(rc)); rc = target_bulk_io(pill->rc_req->rq_export, desc, &lwi); if (rc < 0) GOTO(out_free, rc = err_serious(rc)); } /* validate the request and calculate the total update count and * set it to reply */ reply_size = 0; updates = 0; for (i = 0; i < update_buf_count; i++) { struct object_update_request *our; int j; our = update_bufs[i]; if (ptlrpc_req_need_swab(pill->rc_req)) lustre_swab_object_update_request(our); if (our->ourq_magic != UPDATE_REQUEST_MAGIC) { CERROR("%s: invalid update buffer magic %x" " expect %x: rc = %d\n", tgt_name(tsi->tsi_tgt), our->ourq_magic, UPDATE_REQUEST_MAGIC, -EPROTO); GOTO(out_free, rc = err_serious(-EPROTO)); } updates += our->ourq_count; /* need to calculate reply size */ for (j = 0; j < our->ourq_count; j++) { update = object_update_request_get(our, j, NULL); if (update == NULL) GOTO(out, rc = err_serious(-EPROTO)); if (ptlrpc_req_need_swab(pill->rc_req)) lustre_swab_object_update(update); if (!fid_is_sane(&update->ou_fid)) { CERROR("%s: invalid FID "DFID": rc = %d\n", tgt_name(tsi->tsi_tgt), PFID(&update->ou_fid), -EPROTO); GOTO(out, rc = err_serious(-EPROTO)); } /* XXX: what ou_result_size can be considered safe? */ reply_size += sizeof(reply->ourp_lens[0]); reply_size += sizeof(struct object_update_result); reply_size += update->ou_result_size; } } reply_size += sizeof(*reply); if (unlikely(reply_size > ouh->ouh_reply_size)) { CERROR("%s: too small reply buf %u for %u, need %u at least\n", tgt_name(tsi->tsi_tgt), ouh->ouh_reply_size, updates, reply_size); GOTO(out_free, rc = err_serious(-EPROTO)); } req_capsule_set_size(pill, &RMF_OUT_UPDATE_REPLY, RCL_SERVER, ouh->ouh_reply_size); rc = req_capsule_server_pack(pill); if (rc != 0) { CERROR("%s: Can't pack response: rc = %d\n", tgt_name(tsi->tsi_tgt), rc); GOTO(out_free, rc = err_serious(-EPROTO)); } /* Prepare the update reply buffer */ reply = req_capsule_server_get(pill, &RMF_OUT_UPDATE_REPLY); if (reply == NULL) GOTO(out_free, rc = -EPROTO); reply->ourp_magic = UPDATE_REPLY_MAGIC; reply->ourp_count = updates; tti->tti_u.update.tti_update_reply = reply; tti->tti_mult_trans = !req_is_replay(tgt_ses_req(tsi)); /* Walk through updates in the request to execute them */ for (i = 0; i < update_buf_count; i++) { struct tgt_handler *h; struct dt_object *dt_obj; int update_count; struct object_update_request *our; int j; our = update_bufs[i]; update_count = our->ourq_count; for (j = 0; j < update_count; j++) { update = object_update_request_get(our, j, NULL); dt_obj = dt_locate(env, dt, &update->ou_fid); if (IS_ERR(dt_obj)) GOTO(out, rc = PTR_ERR(dt_obj)); if (dt->dd_record_fid_accessed) { lfsck_pack_rfa(&tti->tti_lr, lu_object_fid(&dt_obj->do_lu), LE_FID_ACCESSED, LFSCK_TYPE_LAYOUT); tgt_lfsck_in_notify(env, dt, &tti->tti_lr, NULL); } tti->tti_u.update.tti_dt_object = dt_obj; tti->tti_u.update.tti_update = update; tti->tti_u.update.tti_update_reply_index = reply_index; h = out_handler_find(update->ou_type); if (unlikely(h == NULL)) { CERROR("%s: unsupported opc: 0x%x\n", tgt_name(tsi->tsi_tgt), update->ou_type); GOTO(next, rc = -ENOTSUPP); } /* Check resend case only for modifying RPC */ if (h->th_flags & MUTABOR) { struct ptlrpc_request *req = tgt_ses_req(tsi); if (out_check_resent(env, dt, dt_obj, req, out_reconstruct, reply, reply_index)) GOTO(next, rc = 0); } /* start transaction for modification RPC only */ if (h->th_flags & MUTABOR && current_batchid == -1) { current_batchid = update->ou_batchid; rc = out_tx_start(env, dt, ta, tsi->tsi_exp); if (rc != 0) GOTO(next, rc); if (update->ou_flags & UPDATE_FL_SYNC) ta->ta_handle->th_sync = 1; } /* Stop the current update transaction, if the update * has different batchid, or read-only update */ if (((current_batchid != update->ou_batchid) || !(h->th_flags & MUTABOR)) && ta->ta_handle != NULL) { rc = out_tx_end(env, ta, rc); current_batchid = -1; if (rc != 0) GOTO(next, rc); /* start a new transaction if needed */ if (h->th_flags & MUTABOR) { rc = out_tx_start(env, dt, ta, tsi->tsi_exp); if (rc != 0) GOTO(next, rc); if (update->ou_flags & UPDATE_FL_SYNC) ta->ta_handle->th_sync = 1; current_batchid = update->ou_batchid; } } rc = h->th_act(tsi); next: reply_index++; lu_object_put(env, &dt_obj->do_lu); if (rc < 0) GOTO(out, rc); } } out: if (current_batchid != -1) { rc1 = out_tx_end(env, ta, rc); if (rc == 0) rc = rc1; } out_free: if (update_bufs != NULL) { if (oub != NULL) { for (i = 0; i < update_buf_count; i++, oub++) { if (update_bufs[i] != NULL) OBD_FREE(update_bufs[i], oub->oub_size); } } OBD_FREE(update_bufs, sizeof(*update_bufs) * update_buf_count); } if (desc != NULL) ptlrpc_free_bulk(desc); RETURN(rc); }
/* * VBR: save versions in reply: 0 - parent; 1 - child by fid; 2 - target by * name. */ static int mdt_reint_link(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) { struct mdt_reint_record *rr = &info->mti_rr; struct ptlrpc_request *req = mdt_info_req(info); struct md_attr *ma = &info->mti_attr; struct mdt_object *ms; struct mdt_object *mp; struct mdt_lock_handle *lhs; struct mdt_lock_handle *lhp; struct lu_name *lname; int rc; ENTRY; DEBUG_REQ(D_INODE, req, "link "DFID" to "DFID"/%s", PFID(rr->rr_fid1), PFID(rr->rr_fid2), rr->rr_name); if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_LINK)) RETURN(err_serious(-ENOENT)); if (info->mti_dlm_req) ldlm_request_cancel(req, info->mti_dlm_req, 0); /* Invalid case so return error immediately instead of * processing it */ if (lu_fid_eq(rr->rr_fid1, rr->rr_fid2)) RETURN(-EPERM); /* step 1: find & lock the target parent dir */ lhp = &info->mti_lh[MDT_LH_PARENT]; mdt_lock_pdo_init(lhp, LCK_PW, rr->rr_name, rr->rr_namelen); mp = mdt_object_find_lock(info, rr->rr_fid2, lhp, MDS_INODELOCK_UPDATE); if (IS_ERR(mp)) RETURN(PTR_ERR(mp)); if (mdt_object_obf(mp)) GOTO(out_unlock_parent, rc = -EPERM); rc = mdt_version_get_check_save(info, mp, 0); if (rc) GOTO(out_unlock_parent, rc); /* step 2: find & lock the source */ lhs = &info->mti_lh[MDT_LH_CHILD]; mdt_lock_reg_init(lhs, LCK_EX); ms = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1); if (IS_ERR(ms)) GOTO(out_unlock_parent, rc = PTR_ERR(ms)); if (mdt_object_remote(ms)) { mdt_object_put(info->mti_env, ms); CERROR("Target directory "DFID" is on another MDT\n", PFID(rr->rr_fid1)); GOTO(out_unlock_parent, rc = -EXDEV); } rc = mdt_object_lock(info, ms, lhs, MDS_INODELOCK_UPDATE, MDT_CROSS_LOCK); if (rc != 0) { mdt_object_put(info->mti_env, ms); GOTO(out_unlock_parent, rc); } /* step 3: link it */ mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom, OBD_FAIL_MDS_REINT_LINK_WRITE); info->mti_mos = ms; rc = mdt_version_get_check_save(info, ms, 1); if (rc) GOTO(out_unlock_child, rc); lname = mdt_name(info->mti_env, (char *)rr->rr_name, rr->rr_namelen); /** check target version by name during replay */ rc = mdt_lookup_version_check(info, mp, lname, &info->mti_tmp_fid1, 2); if (rc != 0 && rc != -ENOENT) GOTO(out_unlock_child, rc); /* save version of file name for replay, it must be ENOENT here */ if (!req_is_replay(mdt_info_req(info))) { info->mti_ver[2] = ENOENT_VERSION; mdt_version_save(mdt_info_req(info), info->mti_ver[2], 2); } rc = mdo_link(info->mti_env, mdt_object_child(mp), mdt_object_child(ms), lname, ma); if (rc == 0) mdt_counter_incr(req, LPROC_MDT_LINK); EXIT; out_unlock_child: mdt_object_unlock_put(info, ms, lhs, rc); out_unlock_parent: mdt_object_unlock_put(info, mp, lhp, rc); return rc; }
/** * Object updates between Targets. Because all the updates has been * dis-assemblied into object updates at sender side, so OUT will * call OSD API directly to execute these updates. * * In DNE phase I all of the updates in the request need to be executed * in one transaction, and the transaction has to be synchronously. * * Please refer to lustre/include/lustre/lustre_idl.h for req/reply * format. */ int out_handle(struct tgt_session_info *tsi) { const struct lu_env *env = tsi->tsi_env; struct tgt_thread_info *tti = tgt_th_info(env); struct thandle_exec_args *ta = &tti->tti_tea; struct req_capsule *pill = tsi->tsi_pill; struct dt_device *dt = tsi->tsi_tgt->lut_bottom; struct update_buf *ubuf; struct update *update; struct update_reply *update_reply; int bufsize; int count; int old_batchid = -1; unsigned off; int i; int rc = 0; int rc1 = 0; ENTRY; req_capsule_set(pill, &RQF_UPDATE_OBJ); bufsize = req_capsule_get_size(pill, &RMF_UPDATE, RCL_CLIENT); if (bufsize != UPDATE_BUFFER_SIZE) { CERROR("%s: invalid bufsize %d: rc = %d\n", tgt_name(tsi->tsi_tgt), bufsize, -EPROTO); RETURN(err_serious(-EPROTO)); } ubuf = req_capsule_client_get(pill, &RMF_UPDATE); if (ubuf == NULL) { CERROR("%s: No buf!: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } if (le32_to_cpu(ubuf->ub_magic) != UPDATE_BUFFER_MAGIC) { CERROR("%s: invalid magic %x expect %x: rc = %d\n", tgt_name(tsi->tsi_tgt), le32_to_cpu(ubuf->ub_magic), UPDATE_BUFFER_MAGIC, -EPROTO); RETURN(err_serious(-EPROTO)); } count = le32_to_cpu(ubuf->ub_count); if (count <= 0) { CERROR("%s: No update!: rc = %d\n", tgt_name(tsi->tsi_tgt), -EPROTO); RETURN(err_serious(-EPROTO)); } req_capsule_set_size(pill, &RMF_UPDATE_REPLY, RCL_SERVER, UPDATE_BUFFER_SIZE); rc = req_capsule_server_pack(pill); if (rc != 0) { CERROR("%s: Can't pack response: rc = %d\n", tgt_name(tsi->tsi_tgt), rc); RETURN(rc); } /* Prepare the update reply buffer */ update_reply = req_capsule_server_get(pill, &RMF_UPDATE_REPLY); if (update_reply == NULL) RETURN(err_serious(-EPROTO)); update_init_reply_buf(update_reply, count); tti->tti_u.update.tti_update_reply = update_reply; rc = out_tx_start(env, dt, ta); if (rc != 0) RETURN(rc); tti->tti_mult_trans = !req_is_replay(tgt_ses_req(tsi)); /* Walk through updates in the request to execute them synchronously */ off = cfs_size_round(offsetof(struct update_buf, ub_bufs[0])); for (i = 0; i < count; i++) { struct tgt_handler *h; struct dt_object *dt_obj; update = (struct update *)((char *)ubuf + off); if (old_batchid == -1) { old_batchid = update->u_batchid; } else if (old_batchid != update->u_batchid) { /* Stop the current update transaction, * create a new one */ rc = out_tx_end(env, ta); if (rc != 0) RETURN(rc); rc = out_tx_start(env, dt, ta); if (rc != 0) RETURN(rc); old_batchid = update->u_batchid; } fid_le_to_cpu(&update->u_fid, &update->u_fid); if (!fid_is_sane(&update->u_fid)) { CERROR("%s: invalid FID "DFID": rc = %d\n", tgt_name(tsi->tsi_tgt), PFID(&update->u_fid), -EPROTO); GOTO(out, rc = err_serious(-EPROTO)); } dt_obj = dt_locate(env, dt, &update->u_fid); if (IS_ERR(dt_obj)) GOTO(out, rc = PTR_ERR(dt_obj)); tti->tti_u.update.tti_dt_object = dt_obj; tti->tti_u.update.tti_update = update; tti->tti_u.update.tti_update_reply_index = i; h = out_handler_find(update->u_type); if (likely(h != NULL)) { /* For real modification RPC, check if the update * has been executed */ if (h->th_flags & MUTABOR) { struct ptlrpc_request *req = tgt_ses_req(tsi); if (out_check_resent(env, dt, dt_obj, req, out_reconstruct, update_reply, i)) GOTO(next, rc); } rc = h->th_act(tsi); } else { CERROR("%s: The unsupported opc: 0x%x\n", tgt_name(tsi->tsi_tgt), update->u_type); lu_object_put(env, &dt_obj->do_lu); GOTO(out, rc = -ENOTSUPP); } next: lu_object_put(env, &dt_obj->do_lu); if (rc < 0) GOTO(out, rc); off += cfs_size_round(update_size(update)); } out: rc1 = out_tx_end(env, ta); if (rc == 0) rc = rc1; RETURN(rc); }
static int mdt_reint_setattr(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) { struct md_attr *ma = &info->mti_attr; struct mdt_reint_record *rr = &info->mti_rr; struct ptlrpc_request *req = mdt_info_req(info); struct mdt_export_data *med = &req->rq_export->exp_mdt_data; struct mdt_file_data *mfd; struct mdt_object *mo; struct mdt_body *repbody; int som_au, rc, rc2; ENTRY; DEBUG_REQ(D_INODE, req, "setattr "DFID" %x", PFID(rr->rr_fid1), (unsigned int)ma->ma_attr.la_valid); if (info->mti_dlm_req) ldlm_request_cancel(req, info->mti_dlm_req, 0); repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY); mo = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1); if (IS_ERR(mo)) GOTO(out, rc = PTR_ERR(mo)); /* start a log jounal handle if needed */ if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM)) { if ((ma->ma_attr.la_valid & LA_SIZE) || (rr->rr_flags & MRF_OPEN_TRUNC)) { /* Check write access for the O_TRUNC case */ if (mdt_write_read(mo) < 0) GOTO(out_put, rc = -ETXTBSY); } } else if (info->mti_ioepoch && (info->mti_ioepoch->flags & MF_EPOCH_OPEN)) { /* Truncate case. IOEpoch is opened. */ rc = mdt_write_get(mo); if (rc) GOTO(out_put, rc); mfd = mdt_mfd_new(med); if (mfd == NULL) { mdt_write_put(mo); GOTO(out_put, rc = -ENOMEM); } mdt_ioepoch_open(info, mo, 0); repbody->ioepoch = mo->mot_ioepoch; mdt_object_get(info->mti_env, mo); mdt_mfd_set_mode(mfd, MDS_FMODE_TRUNC); mfd->mfd_object = mo; mfd->mfd_xid = req->rq_xid; spin_lock(&med->med_open_lock); cfs_list_add(&mfd->mfd_list, &med->med_open_head); spin_unlock(&med->med_open_lock); repbody->handle.cookie = mfd->mfd_handle.h_cookie; } som_au = info->mti_ioepoch && info->mti_ioepoch->flags & MF_SOM_CHANGE; if (som_au) { /* SOM Attribute update case. Find the proper mfd and update * SOM attributes on the proper object. */ LASSERT(mdt_conn_flags(info) & OBD_CONNECT_SOM); LASSERT(info->mti_ioepoch); spin_lock(&med->med_open_lock); mfd = mdt_handle2mfd(med, &info->mti_ioepoch->handle, req_is_replay(req)); if (mfd == NULL) { spin_unlock(&med->med_open_lock); CDEBUG(D_INODE, "no handle for file close: " "fid = "DFID": cookie = "LPX64"\n", PFID(info->mti_rr.rr_fid1), info->mti_ioepoch->handle.cookie); GOTO(out_put, rc = -ESTALE); } LASSERT(mfd->mfd_mode == MDS_FMODE_SOM); LASSERT(!(info->mti_ioepoch->flags & MF_EPOCH_CLOSE)); class_handle_unhash(&mfd->mfd_handle); cfs_list_del_init(&mfd->mfd_list); spin_unlock(&med->med_open_lock); mdt_mfd_close(info, mfd); } else if ((ma->ma_valid & MA_INODE) && ma->ma_attr.la_valid) { LASSERT((ma->ma_valid & MA_LOV) == 0); rc = mdt_attr_set(info, mo, ma, rr->rr_flags); if (rc) GOTO(out_put, rc); } else if ((ma->ma_valid & MA_LOV) && (ma->ma_valid & MA_INODE)) { struct lu_buf *buf = &info->mti_buf; LASSERT(ma->ma_attr.la_valid == 0); buf->lb_buf = ma->ma_lmm; buf->lb_len = ma->ma_lmm_size; rc = mo_xattr_set(info->mti_env, mdt_object_child(mo), buf, XATTR_NAME_LOV, 0); if (rc) GOTO(out_put, rc); } else LBUG(); /* If file data is modified, add the dirty flag */ if (ma->ma_attr_flags & MDS_DATA_MODIFIED) rc = mdt_add_dirty_flag(info, mo, ma); ma->ma_need = MA_INODE; ma->ma_valid = 0; rc = mdt_attr_get_complex(info, mo, ma); if (rc != 0) GOTO(out_put, rc); mdt_pack_attr2body(info, repbody, &ma->ma_attr, mdt_object_fid(mo)); if (info->mti_mdt->mdt_lut.lut_oss_capa && exp_connect_flags(info->mti_exp) & OBD_CONNECT_OSS_CAPA && S_ISREG(lu_object_attr(&mo->mot_obj)) && (ma->ma_attr.la_valid & LA_SIZE) && !som_au) { struct lustre_capa *capa; capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2); LASSERT(capa); capa->lc_opc = CAPA_OPC_OSS_DEFAULT | CAPA_OPC_OSS_TRUNC; rc = mo_capa_get(info->mti_env, mdt_object_child(mo), capa, 0); if (rc) GOTO(out_put, rc); repbody->valid |= OBD_MD_FLOSSCAPA; } EXIT; out_put: mdt_object_put(info->mti_env, mo); out: if (rc == 0) mdt_counter_incr(req, LPROC_MDT_SETATTR); mdt_client_compatibility(info); rc2 = mdt_fix_reply(info); if (rc == 0) rc = rc2; return rc; }