X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmdt%2Fmdt_io.c;h=5924aa197194374175376129eb59f6edd1c1cd54;hb=a54ecd2c2d964e2ae226fca5b043b5462a34eb7b;hp=4dc67be231852ff8d698139e3f8d7acc3cc4fc57;hpb=067dc642521487b2d53f46da1dec4b9d5f570c67;p=fs%2Flustre-release.git diff --git a/lustre/mdt/mdt_io.c b/lustre/mdt/mdt_io.c index 4dc67be..5924aa1 100644 --- a/lustre/mdt/mdt_io.c +++ b/lustre/mdt/mdt_io.c @@ -35,12 +35,6 @@ /* functions below are stubs for now, they will be implemented with * grant support on MDT */ -static inline void mdt_io_counter_incr(struct obd_export *exp, int opcode, - char *jobid, long amount) -{ - return; -} - static inline void mdt_dom_read_lock(struct mdt_object *mo) { down_read(&mo->mot_dom_sem); @@ -69,7 +63,7 @@ static void mdt_dom_resource_prolong(struct ldlm_prolong_args *arg) ENTRY; res = ldlm_resource_get(arg->lpa_export->exp_obd->obd_namespace, NULL, - &arg->lpa_resid, LDLM_EXTENT, 0); + &arg->lpa_resid, LDLM_IBITS, 0); if (IS_ERR(res)) { CDEBUG(D_DLMTRACE, "Failed to get resource for resid %llu/%llu\n", @@ -82,7 +76,11 @@ static void mdt_dom_resource_prolong(struct ldlm_prolong_args *arg) if (ldlm_has_dom(lock)) { LDLM_DEBUG(lock, "DOM lock to prolong "); ldlm_lock_prolong_one(lock, arg); - break; + /* only one PW or EX lock can be granted, + * no need to continue search + */ + if (lock->l_granted_mode & (LCK_PW | LCK_EX)) + break; } } unlock_res(res); @@ -143,7 +141,7 @@ static int mdt_rw_hpreq_lock_match(struct ptlrpc_request *req, RETURN(0); /* a bulk write can only hold a reference on a PW extent lock. */ - mode = LCK_PW; + mode = LCK_PW | LCK_GROUP; if (opc == OST_READ) /* whereas a bulk read can be protected by either a PR or PW * extent lock */ @@ -183,7 +181,7 @@ static int mdt_rw_hpreq_check(struct ptlrpc_request *req) LASSERT(rnb != NULL); LASSERT(!(rnb->rnb_flags & OBD_BRW_SRVLOCK)); - pa.lpa_mode = LCK_PW; + pa.lpa_mode = LCK_PW | LCK_GROUP; if (opc == OST_READ) pa.lpa_mode |= LCK_PR; @@ -271,7 +269,7 @@ static int mdt_punch_hpreq_lock_match(struct ptlrpc_request *req, if (!fid_res_name_eq(&oa->o_oi.oi_fid, &lock->l_resource->lr_name)) RETURN(0); - if (!(lock->l_granted_mode & LCK_PW)) + if (!(lock->l_granted_mode & (LCK_PW | LCK_GROUP))) RETURN(0); RETURN(1); @@ -309,14 +307,13 @@ static int mdt_punch_hpreq_check(struct ptlrpc_request *req) LASSERT(!(oa->o_valid & OBD_MD_FLFLAGS && oa->o_flags & OBD_FL_SRVLOCK)); - pa.lpa_mode = LCK_PW; + pa.lpa_mode = LCK_PW | LCK_GROUP; CDEBUG(D_DLMTRACE, "%s: refresh DOM lock for "DFID"\n", tgt_name(tsi->tsi_tgt), PFID(&tsi->tsi_fid)); mdt_prolong_dom_lock(tsi, &pa); - if (pa.lpa_blocks_cnt > 0) { CDEBUG(D_DLMTRACE, "%s: refreshed %u locks timeout for req %p.\n", @@ -364,6 +361,8 @@ static int mdt_preprw_read(const struct lu_env *env, struct obd_export *exp, struct niobuf_remote *rnb, int *nr_local, struct niobuf_local *lnb, char *jobid) { + struct tgt_session_info *tsi = tgt_ses_info(env); + struct ptlrpc_request *req = tgt_ses_req(tsi); struct dt_object *dob; int i, j, rc, tot_bytes = 0; int maxlnb = *nr_local; @@ -422,7 +421,7 @@ static int mdt_preprw_read(const struct lu_env *env, struct obd_export *exp, if (unlikely(rc)) GOTO(buf_put, rc); - mdt_io_counter_incr(exp, LPROC_MDT_IO_READ, jobid, tot_bytes); + mdt_counter_incr(req, LPROC_MDT_IO_READ, tot_bytes); RETURN(0); buf_put: dt_bufs_put(env, dob, lnb, *nr_local); @@ -437,6 +436,8 @@ static int mdt_preprw_write(const struct lu_env *env, struct obd_export *exp, struct niobuf_remote *rnb, int *nr_local, struct niobuf_local *lnb, char *jobid) { + struct tgt_session_info *tsi = tgt_ses_info(env); + struct ptlrpc_request *req = tgt_ses_req(tsi); struct dt_object *dob; int i, j, k, rc = 0, tot_bytes = 0; int maxlnb = *nr_local; @@ -496,7 +497,7 @@ static int mdt_preprw_write(const struct lu_env *env, struct obd_export *exp, if (likely(rc)) GOTO(err, rc); - mdt_io_counter_incr(exp, LPROC_MDT_IO_WRITE, jobid, tot_bytes); + mdt_counter_incr(req, LPROC_MDT_IO_WRITE, tot_bytes); RETURN(0); err: dt_bufs_put(env, dob, lnb, *nr_local); @@ -588,16 +589,16 @@ static int mdt_commitrw_read(const struct lu_env *env, struct mdt_device *mdt, static int mdt_commitrw_write(const struct lu_env *env, struct obd_export *exp, struct mdt_device *mdt, struct mdt_object *mo, - struct lu_attr *la, int objcount, int niocount, - struct niobuf_local *lnb, unsigned long granted, - int old_rc) + struct lu_attr *la, struct obdo *oa, int objcount, + int niocount, struct niobuf_local *lnb, + unsigned long granted, int old_rc) { struct dt_device *dt = mdt->mdt_bottom; struct dt_object *dob; struct thandle *th; int rc = 0; int retries = 0; - int i; + int i, restart = 0; ENTRY; @@ -656,9 +657,11 @@ retry: GOTO(out_stop, rc); dt_write_lock(env, dob, 0); - rc = dt_write_commit(env, dob, lnb, niocount, th); - if (rc) + rc = dt_write_commit(env, dob, lnb, niocount, th, oa->o_size); + if (rc) { + restart = th->th_restart_tran; GOTO(unlock, rc); + } if (la->la_valid) { rc = dt_attr_set(env, dob, la, th); @@ -682,13 +685,23 @@ out_stop: granted = 0; } - th->th_result = rc; + th->th_result = restart ? 0 : rc; dt_trans_stop(env, dt, th); if (rc == -ENOSPC && retries++ < 3) { CDEBUG(D_INODE, "retry after force commit, retries:%d\n", retries); goto retry; } + if (restart) { + retries++; + restart = 0; + if (retries % 10000 == 0) + CERROR("%s: restart IO write too many times: %d\n", + exp->exp_obd->obd_name, retries); + CDEBUG(D_INODE, "retry transaction, retries:%d\n", + retries); + goto retry; + } out: dt_bufs_put(env, dob, lnb, niocount); @@ -747,7 +760,7 @@ int mdt_obd_commitrw(const struct lu_env *env, int cmd, struct obd_export *exp, la_from_obdo(la, oa, valid); - rc = mdt_commitrw_write(env, exp, mdt, mo, la, objcount, + rc = mdt_commitrw_write(env, exp, mdt, mo, la, oa, objcount, npages, lnb, oa->o_grant_used, old_rc); if (rc == 0) obdo_from_la(oa, la, VALID_FLAGS | LA_GID | LA_UID); @@ -849,6 +862,7 @@ stop: int mdt_punch_hdl(struct tgt_session_info *tsi) { const struct obdo *oa = &tsi->tsi_ost_body->oa; + struct ptlrpc_request *req = tgt_ses_req(tsi); struct ost_body *repbody; struct mdt_thread_info *info; struct lu_attr *la; @@ -859,6 +873,7 @@ int mdt_punch_hdl(struct tgt_session_info *tsi) struct dt_object *dob; __u64 flags = 0; struct lustre_handle lh = { 0, }; + ktime_t kstart = ktime_get(); __u64 start, end; int rc; bool srvlock; @@ -942,14 +957,14 @@ int mdt_punch_hdl(struct tgt_session_info *tsi) GOTO(out_put, rc); mdt_dom_obj_lvb_update(tsi->tsi_env, mo, false); - mdt_io_counter_incr(tsi->tsi_exp, LPROC_MDT_IO_PUNCH, - tsi->tsi_jobid, 1); + mdt_counter_incr(req, LPROC_MDT_IO_PUNCH, + ktime_us_delta(ktime_get(), kstart)); EXIT; out_put: lu_object_put(tsi->tsi_env, &mo->mot_obj); out_unlock: if (srvlock) - tgt_extent_unlock(&lh, LCK_PW); + tgt_data_unlock(&lh, LCK_PW); out: mdt_thread_info_fini(info); return rc; @@ -979,7 +994,7 @@ int mdt_do_glimpse(const struct lu_env *env, struct ldlm_namespace *ns, policy.l_inodebits.bits = MDS_INODELOCK_DOM; mode = ldlm_lock_match(ns, LDLM_FL_TEST_LOCK, &res->lr_name, LDLM_IBITS, &policy, - LCK_PW, &lockh, 0); + LCK_PW, &lockh); /* There is no PW lock on this object; finished. */ if (mode == 0) @@ -1033,22 +1048,26 @@ out: return rc; } -static void mdt_lvb2body(struct ldlm_resource *res, struct mdt_body *mb) +static void mdt_lvb2reply(struct ldlm_resource *res, struct mdt_body *mb, + struct ost_lvb *lvb) { struct ost_lvb *res_lvb; lock_res(res); res_lvb = res->lr_lvb_data; - mb->mbo_dom_size = res_lvb->lvb_size; - mb->mbo_dom_blocks = res_lvb->lvb_blocks; - mb->mbo_mtime = res_lvb->lvb_mtime; - mb->mbo_ctime = res_lvb->lvb_ctime; - mb->mbo_atime = res_lvb->lvb_atime; - + if (lvb) + *lvb = *res_lvb; + + if (mb) { + mb->mbo_dom_size = res_lvb->lvb_size; + mb->mbo_dom_blocks = res_lvb->lvb_blocks; + mb->mbo_mtime = res_lvb->lvb_mtime; + mb->mbo_ctime = res_lvb->lvb_ctime; + mb->mbo_atime = res_lvb->lvb_atime; + mb->mbo_valid |= OBD_MD_FLATIME | OBD_MD_FLCTIME | + OBD_MD_FLMTIME | OBD_MD_DOM_SIZE; + } CDEBUG(D_DLMTRACE, "size %llu\n", res_lvb->lvb_size); - - mb->mbo_valid |= OBD_MD_FLATIME | OBD_MD_FLCTIME | OBD_MD_FLMTIME | - OBD_MD_DOM_SIZE; unlock_res(res); } @@ -1079,7 +1098,7 @@ int mdt_dom_object_size(const struct lu_env *env, struct mdt_device *mdt, if (dom_lock || !mdt_dom_lvb_is_valid(res)) mdt_dom_lvbo_update(res, NULL, NULL, false); - mdt_lvb2body(res, mb); + mdt_lvb2reply(res, mb, NULL); ldlm_resource_putref(res); RETURN(rc); } @@ -1110,6 +1129,8 @@ int mdt_glimpse_enqueue(struct mdt_thread_info *mti, struct ldlm_namespace *ns, ldlm_processing_policy policy; struct ldlm_reply *rep; struct mdt_body *mbo; + struct ost_lvb *lvb; + bool old_client = !exp_connect_dom_lvb(mti->mti_exp); int rc; ENTRY; @@ -1117,19 +1138,28 @@ int mdt_glimpse_enqueue(struct mdt_thread_info *mti, struct ldlm_namespace *ns, policy = ldlm_get_processing_policy(res); LASSERT(policy != NULL); - req_capsule_set_size(mti->mti_pill, &RMF_MDT_MD, RCL_SERVER, 0); - req_capsule_set_size(mti->mti_pill, &RMF_ACL, RCL_SERVER, 0); + if (unlikely(old_client)) { + req_capsule_set_size(mti->mti_pill, &RMF_MDT_MD, RCL_SERVER, 0); + req_capsule_set_size(mti->mti_pill, &RMF_ACL, RCL_SERVER, 0); + } else { + req_capsule_set_size(mti->mti_pill, &RMF_DLM_LVB, RCL_SERVER, + sizeof(*lvb)); + } rc = req_capsule_server_pack(mti->mti_pill); if (rc) RETURN(err_serious(rc)); rep = req_capsule_server_get(mti->mti_pill, &RMF_DLM_REP); - if (rep == NULL) - RETURN(-EPROTO); - mbo = req_capsule_server_get(mti->mti_pill, &RMF_MDT_BODY); - if (mbo == NULL) - RETURN(-EPROTO); + if (unlikely(old_client)) { + mbo = req_capsule_server_get(mti->mti_pill, &RMF_MDT_BODY); + LASSERT(mbo); + lvb = NULL; + } else { + lvb = req_capsule_server_get(mti->mti_pill, &RMF_DLM_LVB); + LASSERT(lvb); + mbo = NULL; + } lock_res(res); /* Check if this is a resend case (MSG_RESENT is set on RPC) and a @@ -1160,14 +1190,12 @@ int mdt_glimpse_enqueue(struct mdt_thread_info *mti, struct ldlm_namespace *ns, if (rc == -ENOENT) { /* We are racing with unlink(); just return -ENOENT */ rep->lock_policy_res2 = ptlrpc_status_hton(-ENOENT); - rc = 0; } else if (rc == -EINVAL) { /* this is possible is client lock has been cancelled but * still exists on server. If that lock was found on server * as only conflicting lock then the client has already * size authority and glimpse is not needed. */ CDEBUG(D_DLMTRACE, "Glimpse from the client owning lock\n"); - rc = 0; } else if (rc < 0) { RETURN(rc); } @@ -1176,7 +1204,8 @@ fill_mbo: /* LVB can be without valid data in case of DOM */ if (!mdt_dom_lvb_is_valid(res)) mdt_dom_lvbo_update(res, lock, NULL, false); - mdt_lvb2body(res, mbo); + mdt_lvb2reply(res, mbo, lvb); + RETURN(rc); } @@ -1195,8 +1224,6 @@ int mdt_brw_enqueue(struct mdt_thread_info *mti, struct ldlm_namespace *ns, ENTRY; - /* Get lock from request for possible resent case. */ - mdt_intent_fixup_resent(mti, *lockp, lhc, flags); req_capsule_set_size(mti->mti_pill, &RMF_MDT_MD, RCL_SERVER, 0); req_capsule_set_size(mti->mti_pill, &RMF_ACL, RCL_SERVER, 0); rc = req_capsule_server_pack(mti->mti_pill); @@ -1222,10 +1249,13 @@ int mdt_brw_enqueue(struct mdt_thread_info *mti, struct ldlm_namespace *ns, if (mdt_object_remote(mo)) GOTO(out, rc = -EPROTO); + /* Get lock from request for possible resent case. */ + mdt_intent_fixup_resent(mti, *lockp, lhc, flags); /* resent case */ if (!lustre_handle_is_used(&lhc->mlh_reg_lh)) { mdt_lock_handle_init(lhc); - mdt_lock_reg_init(lhc, (*lockp)->l_req_mode); + mdt_lh_reg_init(lhc, *lockp); + /* This will block MDT thread but it should be fine until * client caches small amount of data for DoM, which should be * smaller than one BRW RPC and should be able to be @@ -1246,7 +1276,7 @@ int mdt_brw_enqueue(struct mdt_thread_info *mti, struct ldlm_namespace *ns, GOTO(out_fail, rc); mdt_dom_disk_lvbo_update(mti->mti_env, mo, res, false); } - mdt_lvb2body(res, mbo); + mdt_lvb2reply(res, mbo, NULL); out_fail: rep->lock_policy_res2 = clear_serious(rc); if (rep->lock_policy_res2) { @@ -1256,6 +1286,8 @@ out_fail: rc = mdt_intent_lock_replace(mti, lockp, lhc, flags, rc); out: + if (rc < 0) + lhc->mlh_reg_lh.cookie = 0ull; mdt_object_put(mti->mti_env, mo); RETURN(rc); } @@ -1267,17 +1299,21 @@ bool mdt_dom_client_has_lock(struct mdt_thread_info *info, struct mdt_device *mdt = info->mti_mdt; union ldlm_policy_data *policy = &info->mti_policy; struct ldlm_res_id *res_id = &info->mti_res_id; + __u64 open_flags = info->mti_spec.sp_cr_flags; struct lustre_handle lockh; enum ldlm_mode mode; struct ldlm_lock *lock; + enum ldlm_mode lm; bool rc; policy->l_inodebits.bits = MDS_INODELOCK_DOM; fid_build_reg_res_name(fid, res_id); + + lm = (open_flags & MDS_FMODE_WRITE) ? LCK_PW : LCK_PR | LCK_PW; mode = ldlm_lock_match(mdt->mdt_namespace, LDLM_FL_BLOCK_GRANTED | LDLM_FL_TEST_LOCK, res_id, LDLM_IBITS, policy, - LCK_PW, &lockh, 0); + lm, &lockh); /* There is no other PW lock on this object; finished. */ if (mode == 0) @@ -1383,7 +1419,7 @@ int mdt_data_version_get(struct tgt_session_info *tsi) rc = 0; out: if (srvlock) - tgt_mdt_data_unlock(&lh, lock_mode); + tgt_data_unlock(&lh, lock_mode); repbody->mbo_valid |= OBD_MD_FLFLAGS; repbody->mbo_flags = OBD_FL_FLUSH; @@ -1408,6 +1444,7 @@ int mdt_dom_read_on_open(struct mdt_thread_info *mti, struct mdt_device *mdt, int rc; loff_t offset; unsigned int len, copied = 0; + __u64 real_dom_size; int lnbs, nr_local, i; bool dom_lock = false; @@ -1441,8 +1478,18 @@ int mdt_dom_read_on_open(struct mdt_thread_info *mti, struct mdt_device *mdt, if (!dom_lock || !mdt->mdt_opts.mo_dom_read_open) RETURN(0); + /* if DoM object holds encrypted content, we need to make sure we + * send whole encryption units, or client will read corrupted content + */ + if (mbo->mbo_valid & LA_FLAGS && mbo->mbo_flags & LUSTRE_ENCRYPT_FL && + mbo->mbo_dom_size & ~LUSTRE_ENCRYPTION_MASK) + real_dom_size = (mbo->mbo_dom_size & LUSTRE_ENCRYPTION_MASK) + + LUSTRE_ENCRYPTION_UNIT_SIZE; + else + real_dom_size = mbo->mbo_dom_size; + CDEBUG(D_INFO, "File size %llu, reply sizes %d/%d\n", - mbo->mbo_dom_size, req->rq_reqmsg->lm_repsize, req->rq_replen); + real_dom_size, req->rq_reqmsg->lm_repsize, req->rq_replen); len = req->rq_reqmsg->lm_repsize - req->rq_replen; /* NB: at this moment we have the following sizes: @@ -1461,11 +1508,11 @@ int mdt_dom_read_on_open(struct mdt_thread_info *mti, struct mdt_device *mdt, * 1) try to fit into the buffer we have * 2) return just file tail otherwise. */ - if (mbo->mbo_dom_size <= len) { + if (real_dom_size <= len) { /* can fit whole data */ - len = mbo->mbo_dom_size; + len = real_dom_size; offset = 0; - } else if (mbo->mbo_dom_size < + } else if (real_dom_size < mdt_lmm_dom_stripesize(mti->mti_attr.ma_lmm)) { int tail, pgbits; @@ -1484,14 +1531,14 @@ int mdt_dom_read_on_open(struct mdt_thread_info *mti, struct mdt_device *mdt, } pgbits = max_t(int, PAGE_SHIFT, req->rq_export->exp_target_data.ted_pagebits); - tail = mbo->mbo_dom_size % (1 << pgbits); + tail = real_dom_size % (1 << pgbits); /* no partial tail or tail can't fit in reply */ if (tail == 0 || len < tail) RETURN(0); len = tail; - offset = mbo->mbo_dom_size - len; + offset = real_dom_size - len; } else { /* DOM stripe is fully written, so don't expect its tail * will be used by append. @@ -1532,7 +1579,7 @@ int mdt_dom_read_on_open(struct mdt_thread_info *mti, struct mdt_device *mdt, /* parse remote buffers to local buffers and prepare the latter */ lnbs = (len >> PAGE_SHIFT) + 1; - OBD_ALLOC(lnb, sizeof(*lnb) * lnbs); + OBD_ALLOC_PTR_ARRAY(lnb, lnbs); if (lnb == NULL) GOTO(unlock, rc = -ENOMEM); @@ -1573,7 +1620,7 @@ int mdt_dom_read_on_open(struct mdt_thread_info *mti, struct mdt_device *mdt, buf_put: dt_bufs_put(env, mo, lnb, nr_local); free: - OBD_FREE(lnb, sizeof(*lnb) * lnbs); + OBD_FREE_PTR_ARRAY(lnb, lnbs); unlock: dt_read_unlock(env, mo); lu_object_put(env, &mo->do_lu);