X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmdt%2Fmdt_handler.c;h=6cc0c6c3d8214a1e05f65fe46135733b2ccd31e7;hb=c7a42267f5740d587f726e610695f1c72818a21e;hp=5547e6288da47565d24b4abb098850306ee46d2a;hpb=90d8e7fd28746a572c8de488222f5312fe927fc3;p=fs%2Flustre-release.git diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 5547e62..6cc0c6c 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -72,6 +72,7 @@ #endif #include #include +#include mdl_mode_t mdt_mdl_lock_modes[] = { [LCK_MINMODE] = MDL_MINMODE, @@ -164,6 +165,8 @@ static struct mdt_opc_slice mdt_fld_handlers[]; static struct mdt_device *mdt_dev(struct lu_device *d); static int mdt_regular_handle(struct ptlrpc_request *req); static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags); +static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt, + struct getinfo_fid2path *fp); static const struct lu_object_operations mdt_obj_ops; @@ -348,7 +351,7 @@ static int mdt_statfs(struct mdt_thread_info *info) /* This will trigger a watchdog timeout */ OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP, (MDT_SERVICE_WATCHDOG_FACTOR * - at_get(&svc->srv_at_estimate) / 1000) + 1); + at_get(&svc->srv_at_estimate)) + 1); rc = mdt_check_ucred(info); if (rc) @@ -520,6 +523,8 @@ static int mdt_getattr_internal(struct mdt_thread_info *info, CERROR("readlink failed: %d\n", rc); rc = -EFAULT; } else { + if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READLINK_EPROTO)) + rc -= 2; repbody->valid |= OBD_MD_LINKNAME; repbody->eadatasize = rc; /* NULL terminate */ @@ -952,6 +957,7 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, relock: ma = &info->mti_attr; + OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout*2); mdt_lock_handle_init(lhc); mdt_lock_reg_init(lhc, LCK_PR); @@ -997,7 +1003,7 @@ relock: /* Debugging code. */ res_id = &lock->l_resource->lr_name; - LDLM_DEBUG(lock, "Returning lock to client\n"); + LDLM_DEBUG(lock, "Returning lock to client"); LASSERTF(fid_res_name_eq(mdt_object_fid(child), &lock->l_resource->lr_name), "Lock res_id: %lu/%lu/%lu, Fid: "DFID".\n", @@ -1067,12 +1073,15 @@ static int lu_device_is_mdt(struct lu_device *d) return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdt_lu_ops); } +static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len, + void *karg, void *uarg); + static int mdt_set_info(struct mdt_thread_info *info) { struct ptlrpc_request *req = mdt_info_req(info); char *key; - __u32 *val; - int keylen, rc = 0; + void *val; + int keylen, vallen, rc = 0; ENTRY; rc = req_capsule_server_pack(info->mti_pill); @@ -1094,19 +1103,40 @@ static int mdt_set_info(struct mdt_thread_info *info) RETURN(-EFAULT); } - if (!KEY_IS(KEY_READ_ONLY)) - RETURN(-EINVAL); + vallen = req_capsule_get_size(info->mti_pill, &RMF_SETINFO_VAL, + RCL_CLIENT); - req->rq_status = 0; - lustre_msg_set_status(req->rq_repmsg, 0); + /* Swab any part of val you need to here */ + if (KEY_IS(KEY_READ_ONLY)) { + req->rq_status = 0; + lustre_msg_set_status(req->rq_repmsg, 0); - spin_lock(&req->rq_export->exp_lock); - if (*val) - req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY; - else - req->rq_export->exp_connect_flags &= ~OBD_CONNECT_RDONLY; - spin_unlock(&req->rq_export->exp_lock); + spin_lock(&req->rq_export->exp_lock); + if (*(__u32 *)val) + req->rq_export->exp_connect_flags |= OBD_CONNECT_RDONLY; + else + req->rq_export->exp_connect_flags &=~OBD_CONNECT_RDONLY; + spin_unlock(&req->rq_export->exp_lock); + + } else if (KEY_IS(KEY_CHANGELOG_CLEAR)) { + struct changelog_setinfo *cs = + (struct changelog_setinfo *)val; + if (vallen != sizeof(*cs)) { + CERROR("Bad changelog_clear setinfo size %d\n", vallen); + RETURN(-EINVAL); + } + if (ptlrpc_req_need_swab(req)) { + __swab64s(&cs->cs_recno); + __swab32s(&cs->cs_id); + } + + rc = mdt_iocontrol(OBD_IOC_CHANGELOG_CLEAR, info->mti_exp, + vallen, val, NULL); + lustre_msg_set_status(req->rq_repmsg, rc); + } else { + RETURN(-EINVAL); + } RETURN(0); } @@ -1167,6 +1197,10 @@ static int mdt_sendpage(struct mdt_thread_info *info, } LASSERT(desc->bd_nob == rdpg->rp_count); + rc = sptlrpc_svc_wrap_bulk(req, desc); + if (rc) + GOTO(free_desc, rc); + rc = ptlrpc_start_bulk_transfer(desc); if (rc) GOTO(free_desc, rc); @@ -1178,8 +1212,8 @@ static int mdt_sendpage(struct mdt_thread_info *info, if (timeout < 0) CERROR("Req deadline already passed %lu (now: %lu)\n", req->rq_deadline, cfs_time_current_sec()); - *lwi = LWI_TIMEOUT(max(timeout, 1) * HZ, NULL, NULL); - rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), lwi); + *lwi = LWI_TIMEOUT(cfs_time_seconds(max(timeout, 1)), NULL, NULL); + rc = l_wait_event(desc->bd_waitq, !ptlrpc_server_bulk_active(desc), lwi); LASSERT (rc == 0 || rc == -ETIMEDOUT); if (rc == 0) { @@ -1326,6 +1360,9 @@ static int mdt_writepage(struct mdt_thread_info *info) ptlrpc_prep_bulk_page(desc, page, (int)reqbody->size, (int)reqbody->nlink); + rc = sptlrpc_svc_prep_bulk(req, desc); + if (rc != 0) + GOTO(cleanup_page, rc); /* * Check if client was evicted while we were doing i/o before touching * network. @@ -1406,6 +1443,8 @@ static int mdt_readpage(struct mdt_thread_info *info) rdpg->rp_hash, reqbody->size); RETURN(-EFAULT); } + + rdpg->rp_attrs = reqbody->mode; rdpg->rp_count = reqbody->nlink; rdpg->rp_npages = (rdpg->rp_count + CFS_PAGE_SIZE - 1)>>CFS_PAGE_SHIFT; OBD_ALLOC(rdpg->rp_pages, rdpg->rp_npages * sizeof rdpg->rp_pages[0]); @@ -1480,6 +1519,18 @@ static int mdt_reint_internal(struct mdt_thread_info *info, GOTO(out_shrink, rc = err_serious(rc)); } + OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_REINT_DELAY, 10); + + /* for replay no cookkie / lmm need, because client have this already */ + if (info->mti_spec.no_create == 1) { + if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) + req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, 0); + + if (req_capsule_has_field(pill, &RMF_LOGCOOKIES, RCL_SERVER)) + req_capsule_set_size(pill, &RMF_LOGCOOKIES, RCL_SERVER, + 0); + } + rc = mdt_init_ucred_reint(info); if (rc) GOTO(out_shrink, rc); @@ -1645,9 +1696,6 @@ static int mdt_quotacheck_handle(struct mdt_thread_info *info) int rc; ENTRY; - if (OBD_FAIL_CHECK(OBD_FAIL_MDS_QUOTACHECK_NET)) - RETURN(0); - oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL); if (oqctl == NULL) RETURN(-EPROTO); @@ -1675,9 +1723,6 @@ static int mdt_quotactl_handle(struct mdt_thread_info *info) int id, rc; ENTRY; - if (OBD_FAIL_CHECK(OBD_FAIL_MDS_QUOTACTL_NET)) - RETURN(0); - oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL); if (oqctl == NULL) RETURN(-EPROTO); @@ -1718,10 +1763,10 @@ static int mdt_quotactl_handle(struct mdt_thread_info *info) switch (oqctl->qc_cmd) { case Q_QUOTAON: - rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type, id); + rc = mqo->mqo_on(info->mti_env, next, oqctl->qc_type); break; case Q_QUOTAOFF: - rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type, id); + rc = mqo->mqo_off(info->mti_env, next, oqctl->qc_type); break; case Q_SETINFO: rc = mqo->mqo_setinfo(info->mti_env, next, oqctl->qc_type, id, @@ -1764,6 +1809,7 @@ static int mdt_quotactl_handle(struct mdt_thread_info *info) } #endif + /* * OBD PING and other handlers. */ @@ -1792,6 +1838,101 @@ static int mdt_obd_qc_callback(struct mdt_thread_info *info) /* + * LLOG handlers. + */ + +/** clone llog ctxt from child (mdd) + * This allows remote llog (replicator) access. + * We can either pass all llog RPCs (eg mdt_llog_create) on to child where the + * context was originally set up, or we can handle them directly. + * I choose the latter, but that means I need any llog + * contexts set up by child to be accessable by the mdt. So we clone the + * context into our context list here. + */ +static int mdt_llog_ctxt_clone(const struct lu_env *env, struct mdt_device *mdt, + int idx) +{ + struct md_device *next = mdt->mdt_child; + struct llog_ctxt *ctxt; + int rc; + + if (!llog_ctxt_null(mdt2obd_dev(mdt), idx)) + return 0; + + rc = next->md_ops->mdo_llog_ctxt_get(env, next, idx, (void **)&ctxt); + if (rc || ctxt == NULL) { + CERROR("Can't get mdd ctxt %d\n", rc); + return rc; + } + + rc = llog_group_set_ctxt(&mdt2obd_dev(mdt)->obd_olg, ctxt, idx); + if (rc) + CERROR("Can't set mdt ctxt %d\n", rc); + + return rc; +} + +static int mdt_llog_ctxt_unclone(const struct lu_env *env, + struct mdt_device *mdt, int idx) +{ + struct llog_ctxt *ctxt; + + ctxt = llog_get_context(mdt2obd_dev(mdt), idx); + if (ctxt == NULL) + return 0; + /* Put once for the get we just did, and once for the clone */ + llog_ctxt_put(ctxt); + llog_ctxt_put(ctxt); + return 0; +} + +static int mdt_llog_create(struct mdt_thread_info *info) +{ + int rc; + + req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE); + rc = llog_origin_handle_create(mdt_info_req(info)); + return (rc < 0 ? err_serious(rc) : rc); +} + +static int mdt_llog_destroy(struct mdt_thread_info *info) +{ + int rc; + + req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_DESTROY); + rc = llog_origin_handle_destroy(mdt_info_req(info)); + return (rc < 0 ? err_serious(rc) : rc); +} + +static int mdt_llog_read_header(struct mdt_thread_info *info) +{ + int rc; + + req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER); + rc = llog_origin_handle_read_header(mdt_info_req(info)); + return (rc < 0 ? err_serious(rc) : rc); +} + +static int mdt_llog_next_block(struct mdt_thread_info *info) +{ + int rc; + + req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK); + rc = llog_origin_handle_next_block(mdt_info_req(info)); + return (rc < 0 ? err_serious(rc) : rc); +} + +static int mdt_llog_prev_block(struct mdt_thread_info *info) +{ + int rc; + + req_capsule_set(info->mti_pill, &RQF_LLOG_ORIGIN_HANDLE_PREV_BLOCK); + rc = llog_origin_handle_prev_block(mdt_info_req(info)); + return (rc < 0 ? err_serious(rc) : rc); +} + + +/* * DLM handlers. */ static struct ldlm_callback_suite cbs = { @@ -2156,7 +2297,7 @@ void mdt_save_lock(struct mdt_thread_info *info, struct lustre_handle *h, * * \param info thread info object * \param o mdt object - * \param h mdt lock handle referencing regular and PDO locks + * \param lh mdt lock handle referencing regular and PDO locks * \param decref force immediate lock releasing */ void mdt_object_unlock(struct mdt_thread_info *info, struct mdt_object *o, @@ -2211,7 +2352,9 @@ static struct mdt_handler *mdt_handler_find(__u32 opc, if (s->mos_opc_start <= opc && opc < s->mos_opc_end) { h = s->mos_hs + (opc - s->mos_opc_start); if (likely(h->mh_opc != 0)) - LASSERT(h->mh_opc == opc); + LASSERTF(h->mh_opc == opc, + "opcode mismatch %d != %d\n", + h->mh_opc, opc); else h = NULL; /* unsupported opc */ break; @@ -2315,6 +2458,7 @@ static int mdt_unpack_req_pack_rep(struct mdt_thread_info *info, __u32 flags) struct mdt_device *mdt = info->mti_mdt; /* Pack reply. */ + if (req_capsule_has_field(pill, &RMF_MDT_MD, RCL_SERVER)) req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, mdt->mdt_max_mdsize); @@ -2359,7 +2503,7 @@ static int mdt_req_handle(struct mdt_thread_info *info, * Checking for various OBD_FAIL_$PREF_$OPC_NET codes. _Do_ not try * to put same checks into handlers like mdt_close(), mdt_reint(), * etc., without talking to mdt authors first. Checking same thing - * there again is useless and returning 0 error wihtout packing reply + * there again is useless and returning 0 error without packing reply * is buggy! Handlers either pack reply or return error. * * We return 0 here and do not send any reply in order to emulate @@ -2447,7 +2591,7 @@ static int mdt_req_handle(struct mdt_thread_info *info, } /* If we're DISCONNECTing, the mdt_export_data is already freed */ - if (likely(rc == 0 && h->mh_opc != MDS_DISCONNECT)) + if (likely(rc == 0 && req->rq_export && h->mh_opc != MDS_DISCONNECT)) target_committed_to_req(req); if (unlikely((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) && @@ -2514,6 +2658,10 @@ static void mdt_thread_info_init(struct ptlrpc_request *req, info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET; info->mti_transno = lustre_msg_get_transno(req->rq_reqmsg); + info->mti_mos[0] = NULL; + info->mti_mos[1] = NULL; + info->mti_mos[2] = NULL; + info->mti_mos[3] = NULL; memset(&info->mti_attr, 0, sizeof(info->mti_attr)); info->mti_body = NULL; @@ -2526,6 +2674,7 @@ static void mdt_thread_info_init(struct ptlrpc_request *req, /* To not check for split by default. */ info->mti_spec.sp_ck_split = 0; + info->mti_spec.no_create = 0; } static void mdt_thread_info_fini(struct mdt_thread_info *info) @@ -2534,6 +2683,11 @@ static void mdt_thread_info_fini(struct mdt_thread_info *info) req_capsule_fini(info->mti_pill); if (info->mti_object != NULL) { + /* + * freeing an object may lead to OSD level transaction, do not + * let it mess with MDT. bz19385. + */ + info->mti_no_need_trans = 1; mdt_object_put(info->mti_env, info->mti_object); info->mti_object = NULL; } @@ -2667,6 +2821,7 @@ static int mdt_msg_check_version(struct lustre_msg *msg) switch (lustre_msg_get_opc(msg)) { case MDS_CONNECT: case MDS_DISCONNECT: + case MDS_SET_INFO: case OBD_PING: case SEC_CTX_INIT: case SEC_CTX_INIT_CONT: @@ -2692,7 +2847,7 @@ static int mdt_msg_check_version(struct lustre_msg *msg) case MDS_SYNC: case MDS_GETXATTR: case MDS_SETXATTR: - case MDS_SET_INFO: + case MDS_GET_INFO: case MDS_QUOTACHECK: case MDS_QUOTACTL: case QUOTA_DQACQ: @@ -2764,7 +2919,8 @@ static int mdt_handle0(struct ptlrpc_request *req, if (likely(h != NULL)) { rc = mdt_req_handle(info, h, req); } else { - CERROR("The unsupported opc: 0x%x\n", lustre_msg_get_opc(msg) ); + CERROR("The unsupported opc: 0x%x\n", + lustre_msg_get_opc(msg) ); req->rq_status = -ENOTSUPP; rc = ptlrpc_error(req); RETURN(rc); @@ -3013,7 +3169,7 @@ int mdt_intent_lock_replace(struct mdt_thread_info *info, new_lock->l_writers--; } - new_lock->l_export = class_export_get(req->rq_export); + new_lock->l_export = class_export_lock_get(req->rq_export); new_lock->l_blocking_ast = lock->l_blocking_ast; new_lock->l_completion_ast = lock->l_completion_ast; new_lock->l_remote_handle = lock->l_remote_handle; @@ -3205,14 +3361,15 @@ static int mdt_intent_reint(enum mdt_it_code opcode, } rep->lock_policy_res2 = clear_serious(rc); - lhc->mlh_reg_lh.cookie = 0ull; - if (rc == -ENOTCONN || rc == -ENODEV) { + if (rc == -ENOTCONN || rc == -ENODEV || + rc == -EOVERFLOW) { /**< if VBR failure then return error */ /* * If it is the disconnect error (ENODEV & ENOCONN), the error * will be returned by rq_status, and client at ptlrpc layer * will detect this, then disconnect, reconnect the import * immediately, instead of impacting the following the rpc. */ + lhc->mlh_reg_lh.cookie = 0ull; RETURN(rc); } else { /* @@ -3223,7 +3380,14 @@ static int mdt_intent_reint(enum mdt_it_code opcode, * FIXME: when open lock is finished, that should be * checked here. */ - RETURN(ELDLM_LOCK_ABORTED); + if (lustre_handle_is_used(&lhc->mlh_reg_lh)) { + rep->lock_policy_res2 = 0; + rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags); + RETURN(rc); + } else { + lhc->mlh_reg_lh.cookie = 0ull; + RETURN(ELDLM_LOCK_ABORTED); + } } } @@ -3362,7 +3526,7 @@ static void mdt_seq_adjust(const struct lu_env *env, struct mdt_device *m, int lost) { struct md_site *ms = mdt_md_site(m); - struct lu_range out; + struct lu_seq_range out; ENTRY; LASSERT(ms && ms->ms_server_seq); @@ -3428,6 +3592,7 @@ static int mdt_seq_init(const struct lu_env *env, rc = seq_server_init(ms->ms_control_seq, m->mdt_bottom, uuid, LUSTRE_SEQ_CONTROLLER, + ms, env); if (rc) @@ -3469,6 +3634,7 @@ static int mdt_seq_init(const struct lu_env *env, rc = seq_server_init(ms->ms_server_seq, m->mdt_bottom, uuid, LUSTRE_SEQ_SERVER, + ms, env); if (rc) GOTO(out_seq_fini, rc = -ENOMEM); @@ -3623,7 +3789,8 @@ static int mdt_fld_init(const struct lu_env *env, RETURN(rc = -ENOMEM); rc = fld_server_init(ms->ms_server_fld, - m->mdt_bottom, uuid, env); + m->mdt_bottom, uuid, + env, ms->ms_node_id); if (rc) { OBD_FREE_PTR(ms->ms_server_fld); ms->ms_server_fld = NULL; @@ -4087,72 +4254,118 @@ out: return rc; } +/** + * setup CONFIG_ORIG context, used to access local config log. + * this may need to be rewrite as part of llog rewrite for lu-api. + */ +static int mdt_obd_llog_setup(struct obd_device *obd, + struct lustre_sb_info *lsi) +{ + int rc; + + LASSERT(obd->obd_fsops == NULL); + + obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd)); + if (IS_ERR(obd->obd_fsops)) + return PTR_ERR(obd->obd_fsops); + + rc = fsfilt_setup(obd, lsi->lsi_srv_mnt->mnt_sb); + if (rc) { + fsfilt_put_ops(obd->obd_fsops); + return rc; + } + + OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt); + obd->obd_lvfs_ctxt.pwdmnt = lsi->lsi_srv_mnt; + obd->obd_lvfs_ctxt.pwd = lsi->lsi_srv_mnt->mnt_root; + obd->obd_lvfs_ctxt.fs = get_ds(); + + rc = llog_setup(obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, obd, + 0, NULL, &llog_lvfs_ops); + if (rc) { + CERROR("llog_setup() failed: %d\n", rc); + fsfilt_put_ops(obd->obd_fsops); + } + + return rc; +} + +static void mdt_obd_llog_cleanup(struct obd_device *obd) +{ + struct llog_ctxt *ctxt; + + ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT); + if (ctxt) + llog_cleanup(ctxt); + + if (obd->obd_fsops) { + fsfilt_put_ops(obd->obd_fsops); + obd->obd_fsops = NULL; + } +} + static void mdt_fini(const struct lu_env *env, struct mdt_device *m) { - struct md_device *next = m->mdt_child; - struct lu_device *d = &m->mdt_md_dev.md_lu_dev; - struct lu_site *ls = d->ld_site; + struct md_device *next = m->mdt_child; + struct lu_device *d = &m->mdt_md_dev.md_lu_dev; + struct lu_site *ls = d->ld_site; struct obd_device *obd = mdt2obd_dev(m); - int waited = 0; ENTRY; - /* At this point, obd exports might still be on the "obd_zombie_exports" - * list, and obd_zombie_impexp_thread() is trying to destroy them. - * We wait a little bit until all exports (except the self-export) - * have been destroyed, because the whole mdt stack might be accessed - * in mdt_destroy_export(). This will not be a long time, maybe one or - * two seconds are enough. This is not a problem while umounting. - * - * The three references that should be remaining are the - * obd_self_export and the attach and setup references. - */ - while (atomic_read(&obd->obd_refcount) > 3) { - cfs_schedule_timeout(CFS_TASK_UNINT, cfs_time_seconds(1)); - ++waited; - if (waited > 5 && IS_PO2(waited)) - LCONSOLE_WARN("Waiting for obd_zombie_impexp_thread " - "more than %d seconds to destroy all " - "the exports. The current obd refcount =" - " %d. Is it stuck there?\n", - waited, atomic_read(&obd->obd_refcount)); - } + target_recovery_fini(obd); ping_evictor_stop(); - target_recovery_fini(obd); mdt_stop_ptlrpc_service(m); + mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT); + mdt_obd_llog_cleanup(obd); + obd_exports_barrier(obd); obd_zombie_barrier(); #ifdef HAVE_QUOTA_SUPPORT next->md_ops->mdo_quota.mqo_cleanup(env, next); #endif + lut_fini(env, &m->mdt_lut); mdt_fs_cleanup(env, m); upcall_cache_cleanup(m->mdt_identity_cache); m->mdt_identity_cache = NULL; if (m->mdt_namespace != NULL) { - ldlm_namespace_free(m->mdt_namespace, NULL, d->ld_obd->obd_force); + ldlm_namespace_free(m->mdt_namespace, NULL, + d->ld_obd->obd_force); d->ld_obd->obd_namespace = m->mdt_namespace = NULL; } + cfs_free_nidlist(&m->mdt_nosquash_nids); + if (m->mdt_nosquash_str) { + OBD_FREE(m->mdt_nosquash_str, m->mdt_nosquash_strlen); + m->mdt_nosquash_str = NULL; + m->mdt_nosquash_strlen = 0; + } + mdt_seq_fini(env, m); mdt_seq_fini_cli(m); mdt_fld_fini(env, m); - mdt_procfs_fini(m); - lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry); - lprocfs_free_per_client_stats(obd); - lprocfs_free_obd_stats(obd); - ptlrpc_lprocfs_unregister_obd(d->ld_obd); - lprocfs_obd_cleanup(d->ld_obd); - sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset); next->md_ops->mdo_init_capa_ctxt(env, next, 0, 0, 0, NULL); cfs_timer_disarm(&m->mdt_ck_timer); mdt_ck_thread_stop(m); - /* finish the stack */ + /* + * Finish the stack + */ mdt_stack_fini(env, m, md2lu_dev(m->mdt_child)); + mdt_procfs_fini(m); + if (obd->obd_proc_exports_entry) { + lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry); + obd->obd_proc_exports_entry = NULL; + } + lprocfs_free_per_client_stats(obd); + lprocfs_free_obd_stats(obd); + ptlrpc_lprocfs_unregister_obd(obd); + lprocfs_obd_cleanup(obd); + if (ls) { struct md_site *mite; @@ -4166,6 +4379,30 @@ static void mdt_fini(const struct lu_env *env, struct mdt_device *m) EXIT; } +static int mdt_adapt_sptlrpc_conf(struct obd_device *obd, int initial) +{ + struct mdt_device *m = mdt_dev(obd->obd_lu_dev); + struct sptlrpc_rule_set tmp_rset; + int rc; + + sptlrpc_rule_set_init(&tmp_rset); + rc = sptlrpc_conf_target_get_rules(obd, &tmp_rset, initial); + if (rc) { + CERROR("mdt %s: failed get sptlrpc rules: %d\n", + obd->obd_name, rc); + return rc; + } + + sptlrpc_target_update_exp_flavor(obd, &tmp_rset); + + write_lock(&m->mdt_sptlrpc_lock); + sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset); + m->mdt_sptlrpc_rset = tmp_rset; + write_unlock(&m->mdt_sptlrpc_lock); + + return 0; +} + static void fsoptions_to_mdt_flags(struct mdt_device *m, char *options) { char *p = options; @@ -4255,6 +4492,7 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, m->mdt_max_mdsize = MAX_MD_SIZE; m->mdt_max_cookiesize = sizeof(struct llog_cookie); + m->mdt_som_conf = 0; m->mdt_opts.mo_user_xattr = 0; m->mdt_opts.mo_acl = 0; @@ -4266,14 +4504,13 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, } else { lsi = s2lsi(lmi->lmi_sb); fsoptions_to_mdt_flags(m, lsi->lsi_lmd->lmd_opts); - server_put_mount_2(dev, lmi->lmi_mnt); /* CMD is supported only in IAM mode */ ldd = lsi->lsi_ldd; LASSERT(num); node_id = simple_strtol(num, NULL, 10); if (!(ldd->ldd_flags & LDD_F_IAM_DIR) && node_id) { CERROR("CMD Operation not allowed in IOP mode\n"); - RETURN(-EINVAL); + GOTO(err_lmi, rc = -EINVAL); } } @@ -4285,6 +4522,12 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, m->mdt_capa_timeout = CAPA_TIMEOUT; m->mdt_capa_alg = CAPA_HMAC_ALG_SHA1; m->mdt_ck_timeout = CAPA_KEY_TIMEOUT; + m->mdt_squash_uid = 0; + m->mdt_squash_gid = 0; + CFS_INIT_LIST_HEAD(&m->mdt_nosquash_nids); + m->mdt_nosquash_str = NULL; + m->mdt_nosquash_strlen = 0; + init_rwsem(&m->mdt_squash_sem); spin_lock_init(&m->mdt_client_bitmap_lock); @@ -4352,10 +4595,14 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, GOTO(err_fini_proc, rc); } - rc = mdt_fld_init(env, obd->obd_name, m); + rc = lut_init(env, &m->mdt_lut, obd, m->mdt_bottom); if (rc) GOTO(err_fini_stack, rc); + rc = mdt_fld_init(env, obd->obd_name, m); + if (rc) + GOTO(err_lut, rc); + rc = mdt_seq_init(env, obd->obd_name, m); if (rc) GOTO(err_fini_fld, rc); @@ -4395,17 +4642,27 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, if (rc) GOTO(err_capa, rc); + rc = mdt_obd_llog_setup(obd, lsi); + if (rc) + GOTO(err_fs_cleanup, rc); + + rc = mdt_llog_ctxt_clone(env, m, LLOG_CHANGELOG_ORIG_CTXT); + if (rc) + GOTO(err_llog_cleanup, rc); + + mdt_adapt_sptlrpc_conf(obd, 1); + #ifdef HAVE_QUOTA_SUPPORT next = m->mdt_child; rc = next->md_ops->mdo_quota.mqo_setup(env, next, lmi->lmi_mnt); if (rc) - GOTO(err_fs_cleanup, rc); + GOTO(err_llog_cleanup, rc); #endif server_put_mount_2(dev, lmi->lmi_mnt); lmi = NULL; - target_recovery_init(obd, mdt_recovery_handle); + target_recovery_init(&m->mdt_lut, mdt_recovery_handle); rc = mdt_start_ptlrpc_service(m); if (rc) @@ -4437,8 +4694,11 @@ err_recovery: target_recovery_fini(obd); #ifdef HAVE_QUOTA_SUPPORT next->md_ops->mdo_quota.mqo_cleanup(env, next); -err_fs_cleanup: #endif +err_llog_cleanup: + mdt_llog_ctxt_unclone(env, m, LLOG_CHANGELOG_ORIG_CTXT); + mdt_obd_llog_cleanup(obd); +err_fs_cleanup: mdt_fs_cleanup(env, m); err_capa: cfs_timer_disarm(&m->mdt_ck_timer); @@ -4452,12 +4712,16 @@ err_fini_seq: mdt_seq_fini(env, m); err_fini_fld: mdt_fld_fini(env, m); +err_lut: + lut_fini(env, &m->mdt_lut); err_fini_stack: mdt_stack_fini(env, m, md2lu_dev(m->mdt_child)); err_fini_proc: mdt_procfs_fini(m); - if (obd->obd_proc_exports_entry) + if (obd->obd_proc_exports_entry) { lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry); + obd->obd_proc_exports_entry = NULL; + } ptlrpc_lprocfs_unregister_obd(obd); lprocfs_obd_cleanup(obd); err_fini_site: @@ -4465,7 +4729,7 @@ err_fini_site: err_free_site: OBD_FREE_PTR(mite); err_lmi: - if (lmi) + if (lmi) server_put_mount_2(dev, lmi->lmi_mnt); return (rc); } @@ -4481,34 +4745,6 @@ static int mdt_process_config(const struct lu_env *env, ENTRY; switch (cfg->lcfg_command) { - case LCFG_SPTLRPC_CONF: { - struct sptlrpc_conf_log *log; - struct sptlrpc_rule_set tmp_rset; - - log = sptlrpc_conf_log_extract(cfg); - if (IS_ERR(log)) { - rc = PTR_ERR(log); - break; - } - - sptlrpc_rule_set_init(&tmp_rset); - - rc = sptlrpc_rule_set_from_log(&tmp_rset, log); - if (rc) { - CERROR("mdt %p: failed get sptlrpc rules: %d\n", m, rc); - break; - } - - write_lock(&m->mdt_sptlrpc_lock); - sptlrpc_rule_set_free(&m->mdt_sptlrpc_rset); - m->mdt_sptlrpc_rset = tmp_rset; - write_unlock(&m->mdt_sptlrpc_lock); - - sptlrpc_target_update_exp_flavor( - md2lu_dev(&m->mdt_md_dev)->ld_obd, &tmp_rset); - - break; - } case LCFG_PARAM: { struct lprocfs_static_vars lvars; struct obd_device *obd = d->ld_obd; @@ -4578,7 +4814,7 @@ static struct lu_object *mdt_object_alloc(const struct lu_env *env, } static int mdt_object_init(const struct lu_env *env, struct lu_object *o, - const struct lu_object_conf *_) + const struct lu_object_conf *unused) { struct mdt_device *d = mdt_dev(o->lo_dev); struct lu_device *under; @@ -4615,6 +4851,16 @@ static void mdt_object_free(const struct lu_env *env, struct lu_object *o) EXIT; } +static int mdt_object_print(const struct lu_env *env, void *cookie, + lu_printer_t p, const struct lu_object *o) +{ + struct mdt_object *mdto = mdt_obj((struct lu_object *)o); + return (*p)(env, cookie, LUSTRE_MDT_NAME"-object@%p(ioepoch=%llu " + "flags=%llx, epochcount=%d, writecount=%d)", + mdto, mdto->mot_ioepoch, mdto->mot_flags, + mdto->mot_epochcount, mdto->mot_writecount); +} + static const struct lu_device_operations mdt_lu_ops = { .ldo_object_alloc = mdt_object_alloc, .ldo_process_config = mdt_process_config, @@ -4622,9 +4868,29 @@ static const struct lu_device_operations mdt_lu_ops = { static const struct lu_object_operations mdt_obj_ops = { .loo_object_init = mdt_object_init, - .loo_object_free = mdt_object_free + .loo_object_free = mdt_object_free, + .loo_object_print = mdt_object_print }; +static int mdt_obd_set_info_async(struct obd_export *exp, + __u32 keylen, void *key, + __u32 vallen, void *val, + struct ptlrpc_request_set *set) +{ + struct obd_device *obd = exp->exp_obd; + int rc; + ENTRY; + + LASSERT(obd); + + if (KEY_IS(KEY_SPTLRPC_CONF)) { + rc = mdt_adapt_sptlrpc_conf(obd, 0); + RETURN(rc); + } + + RETURN(0); +} + /* mds_connect_internal */ static int mdt_connect_internal(struct obd_export *exp, struct mdt_device *mdt, @@ -4647,6 +4913,9 @@ static int mdt_connect_internal(struct obd_export *exp, if (!mdt->mdt_opts.mo_user_xattr) data->ocd_connect_flags &= ~OBD_CONNECT_XATTR; + if (!mdt->mdt_som_conf) + data->ocd_connect_flags &= ~OBD_CONNECT_SOM; + spin_lock(&exp->exp_lock); exp->exp_connect_flags = data->ocd_connect_flags; spin_unlock(&exp->exp_lock); @@ -4669,60 +4938,97 @@ static int mdt_connect_internal(struct obd_export *exp, return -EBADE; } + if (mdt->mdt_som_conf && + !(exp->exp_connect_flags & OBD_CONNECT_MDS_MDS) && + !(exp->exp_connect_flags & OBD_CONNECT_SOM)) { + CWARN("%s: MDS has SOM enabled, but client does not support " + "it\n", mdt->mdt_md_dev.md_lu_dev.ld_obd->obd_name); + return -EBADE; + } + return 0; } +static int mdt_connect_check_sptlrpc(struct mdt_device *mdt, + struct obd_export *exp, + struct ptlrpc_request *req) +{ + struct sptlrpc_flavor flvr; + int rc = 0; + + if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) { + read_lock(&mdt->mdt_sptlrpc_lock); + sptlrpc_target_choose_flavor(&mdt->mdt_sptlrpc_rset, + req->rq_sp_from, + req->rq_peer.nid, + &flvr); + read_unlock(&mdt->mdt_sptlrpc_lock); + + spin_lock(&exp->exp_lock); + + exp->exp_sp_peer = req->rq_sp_from; + exp->exp_flvr = flvr; + + if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY && + exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) { + CERROR("unauthorized rpc flavor %x from %s, " + "expect %x\n", req->rq_flvr.sf_rpc, + libcfs_nid2str(req->rq_peer.nid), + exp->exp_flvr.sf_rpc); + rc = -EACCES; + } + + spin_unlock(&exp->exp_lock); + } else { + if (exp->exp_sp_peer != req->rq_sp_from) { + CERROR("RPC source %s doesn't match %s\n", + sptlrpc_part2name(req->rq_sp_from), + sptlrpc_part2name(exp->exp_sp_peer)); + rc = -EACCES; + } else { + rc = sptlrpc_target_export_check(exp, req); + } + } + + return rc; +} + /* mds_connect copy */ static int mdt_obd_connect(const struct lu_env *env, - struct lustre_handle *conn, struct obd_device *obd, + struct obd_export **exp, struct obd_device *obd, struct obd_uuid *cluuid, struct obd_connect_data *data, void *localdata) { struct mdt_thread_info *info; struct lsd_client_data *lcd; - struct obd_export *exp; + struct obd_export *lexp; + struct lustre_handle conn = { 0 }; struct mdt_device *mdt; struct ptlrpc_request *req; int rc; ENTRY; LASSERT(env != NULL); - if (!conn || !obd || !cluuid) + if (!exp || !obd || !cluuid) RETURN(-EINVAL); info = lu_context_key_get(&env->le_ctx, &mdt_thread_key); req = info->mti_pill->rc_req; mdt = mdt_dev(obd->obd_lu_dev); - rc = class_connect(conn, obd, cluuid); + rc = class_connect(&conn, obd, cluuid); if (rc) RETURN(rc); - exp = class_conn2export(conn); - LASSERT(exp != NULL); - - CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from)); + lexp = class_conn2export(&conn); + LASSERT(lexp != NULL); - spin_lock(&exp->exp_lock); - exp->exp_sp_peer = req->rq_sp_from; - - read_lock(&mdt->mdt_sptlrpc_lock); - sptlrpc_rule_set_choose(&mdt->mdt_sptlrpc_rset, exp->exp_sp_peer, - req->rq_peer.nid, &exp->exp_flvr); - read_unlock(&mdt->mdt_sptlrpc_lock); - - if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) { - CERROR("invalid rpc flavor %x, expect %x, from %s\n", - req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc, - libcfs_nid2str(req->rq_peer.nid)); - exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID; - spin_unlock(&exp->exp_lock); - RETURN(-EACCES); - } - spin_unlock(&exp->exp_lock); + rc = mdt_connect_check_sptlrpc(mdt, lexp, req); + if (rc) + GOTO(out, rc); - rc = mdt_connect_internal(exp, mdt, data); + rc = mdt_connect_internal(lexp, mdt, data); if (rc == 0) { OBD_ALLOC_PTR(lcd); if (lcd != NULL) { @@ -4730,24 +5036,25 @@ static int mdt_obd_connect(const struct lu_env *env, mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); LASSERT(mti != NULL); - mti->mti_exp = exp; + mti->mti_exp = lexp; memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid); - exp->exp_mdt_data.med_lcd = lcd; + lexp->exp_mdt_data.med_lcd = lcd; rc = mdt_client_new(env, mdt); if (rc != 0) { OBD_FREE_PTR(lcd); - exp->exp_mdt_data.med_lcd = NULL; + lexp->exp_mdt_data.med_lcd = NULL; } else { - mdt_export_stats_init(obd, exp, localdata); + mdt_export_stats_init(obd, lexp, localdata); } } else rc = -ENOMEM; } +out: if (rc != 0) - class_disconnect(exp); + class_disconnect(lexp); else - class_export_put(exp); + *exp = lexp; RETURN(rc); } @@ -4771,32 +5078,90 @@ static int mdt_obd_reconnect(const struct lu_env *env, req = info->mti_pill->rc_req; mdt = mdt_dev(obd->obd_lu_dev); - CDEBUG(D_SEC, "from %s\n", sptlrpc_part2name(req->rq_sp_from)); + rc = mdt_connect_check_sptlrpc(mdt, exp, req); + if (rc) + RETURN(rc); - spin_lock(&exp->exp_lock); - if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) { - exp->exp_sp_peer = req->rq_sp_from; + rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data); + if (rc == 0) + mdt_export_stats_init(obd, exp, localdata); - read_lock(&mdt->mdt_sptlrpc_lock); - sptlrpc_rule_set_choose(&mdt->mdt_sptlrpc_rset, - exp->exp_sp_peer, - req->rq_peer.nid, &exp->exp_flvr); - read_unlock(&mdt->mdt_sptlrpc_lock); + RETURN(rc); +} +static int mdt_mfd_cleanup(struct obd_export *exp) +{ + struct mdt_export_data *med = &exp->exp_mdt_data; + struct obd_device *obd = exp->exp_obd; + struct mdt_device *mdt; + struct mdt_thread_info *info; + struct lu_env env; + CFS_LIST_HEAD(closing_list); + struct mdt_file_data *mfd, *n; + int rc = 0; + ENTRY; - if (exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) { - CERROR("invalid rpc flavor %x, expect %x, from %s\n", - req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc, - libcfs_nid2str(req->rq_peer.nid)); - exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_INVALID; - spin_unlock(&exp->exp_lock); - RETURN(-EACCES); - } + spin_lock(&med->med_open_lock); + while (!list_empty(&med->med_open_head)) { + struct list_head *tmp = med->med_open_head.next; + mfd = list_entry(tmp, struct mdt_file_data, mfd_list); + + /* Remove mfd handle so it can't be found again. + * We are consuming the mfd_list reference here. */ + class_handle_unhash(&mfd->mfd_handle); + list_move_tail(&mfd->mfd_list, &closing_list); } - spin_unlock(&exp->exp_lock); + spin_unlock(&med->med_open_lock); + mdt = mdt_dev(obd->obd_lu_dev); + LASSERT(mdt != NULL); - rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data); - if (rc == 0) - mdt_export_stats_init(obd, exp, localdata); + rc = lu_env_init(&env, LCT_MD_THREAD); + if (rc) + RETURN(rc); + + info = lu_context_key_get(&env.le_ctx, &mdt_thread_key); + LASSERT(info != NULL); + memset(info, 0, sizeof *info); + info->mti_env = &env; + info->mti_mdt = mdt; + info->mti_exp = exp; + + if (!list_empty(&closing_list)) { + struct md_attr *ma = &info->mti_attr; + int lmm_size; + int cookie_size; + + lmm_size = mdt->mdt_max_mdsize; + OBD_ALLOC(ma->ma_lmm, lmm_size); + if (ma->ma_lmm == NULL) + GOTO(out_lmm, rc = -ENOMEM); + + cookie_size = mdt->mdt_max_cookiesize; + OBD_ALLOC(ma->ma_cookie, cookie_size); + if (ma->ma_cookie == NULL) + GOTO(out_cookie, rc = -ENOMEM); + + /* Close any open files (which may also cause orphan unlinking). */ + list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) { + list_del_init(&mfd->mfd_list); + memset(&ma->ma_attr, 0, sizeof(ma->ma_attr)); + ma->ma_lmm_size = lmm_size; + ma->ma_cookie_size = cookie_size; + ma->ma_need = 0; + /* It is not for setattr, just tell MDD to send + * DESTROY RPC to OSS if needed */ + ma->ma_attr_flags = MDS_CLOSE_CLEANUP; + ma->ma_valid = MA_FLAGS; + mdt_mfd_close(info, mfd); + } + info->mti_mdt = NULL; + OBD_FREE(ma->ma_cookie, cookie_size); + ma->ma_cookie = NULL; +out_cookie: + OBD_FREE(ma->ma_lmm, lmm_size); + ma->ma_lmm = NULL; + } +out_lmm: + lu_env_fini(&env); RETURN(rc); } @@ -4828,11 +5193,13 @@ static int mdt_obd_disconnect(struct obd_export *exp) spin_lock(&svc->srv_lock); list_del_init(&rs->rs_exp_list); + spin_lock(&rs->rs_lock); ptlrpc_schedule_difficult_reply(rs); + spin_unlock(&rs->rs_lock); spin_unlock(&svc->srv_lock); } spin_unlock(&exp->exp_lock); - + rc = mdt_mfd_cleanup(exp); class_export_put(exp); RETURN(rc); } @@ -4864,11 +5231,6 @@ static int mdt_destroy_export(struct obd_export *export) struct mdt_device *mdt; struct mdt_thread_info *info; struct lu_env env; - struct md_attr *ma; - int lmm_size; - int cookie_size; - CFS_LIST_HEAD(closing_list); - struct mdt_file_data *mfd, *n; int rc = 0; ENTRY; @@ -4879,6 +5241,8 @@ static int mdt_destroy_export(struct obd_export *export) target_destroy_export(export); ldlm_destroy_export(export); + LASSERT(list_empty(&export->exp_outstanding_replies)); + LASSERT(list_empty(&med->med_open_head)); if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid)) RETURN(0); @@ -4893,78 +5257,30 @@ static int mdt_destroy_export(struct obd_export *export) LASSERT(info != NULL); memset(info, 0, sizeof *info); info->mti_env = &env; - info->mti_mdt = mdt; info->mti_exp = export; - - ma = &info->mti_attr; - lmm_size = ma->ma_lmm_size = mdt->mdt_max_mdsize; - cookie_size = ma->ma_cookie_size = mdt->mdt_max_cookiesize; - OBD_ALLOC(ma->ma_lmm, lmm_size); - OBD_ALLOC(ma->ma_cookie, cookie_size); - - if (ma->ma_lmm == NULL || ma->ma_cookie == NULL) - GOTO(out, rc = -ENOMEM); - ma->ma_need = MA_LOV | MA_COOKIE; - ma->ma_valid = 0; - /* Close any open files (which may also cause orphan unlinking). */ - spin_lock(&med->med_open_lock); - while (!list_empty(&med->med_open_head)) { - struct list_head *tmp = med->med_open_head.next; - mfd = list_entry(tmp, struct mdt_file_data, mfd_list); - - /* Remove mfd handle so it can't be found again. - * We are consuming the mfd_list reference here. */ - class_handle_unhash(&mfd->mfd_handle); - list_move_tail(&mfd->mfd_list, &closing_list); - } - spin_unlock(&med->med_open_lock); - - list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) { - list_del_init(&mfd->mfd_list); - mdt_mfd_close(info, mfd); - /* TODO: if we close the unlinked file, - * we need to remove its objects from OST */ - memset(&ma->ma_attr, 0, sizeof(ma->ma_attr)); - spin_lock(&med->med_open_lock); - ma->ma_lmm_size = lmm_size; - ma->ma_cookie_size = cookie_size; - ma->ma_need = MA_LOV | MA_COOKIE; - ma->ma_valid = 0; - spin_unlock(&med->med_open_lock); - } - info->mti_mdt = NULL; mdt_client_del(&env, mdt); - EXIT; -out: - if (lmm_size) { - OBD_FREE(ma->ma_lmm, lmm_size); - ma->ma_lmm = NULL; - } - if (cookie_size) { - OBD_FREE(ma->ma_cookie, cookie_size); - ma->ma_cookie = NULL; - } lu_env_fini(&env); - - return rc; + RETURN(rc); } static void mdt_allow_cli(struct mdt_device *m, unsigned int flag) { if (flag & CONFIG_LOG) m->mdt_fl_cfglog = 1; + + /* also notify active event */ if (flag & CONFIG_SYNC) m->mdt_fl_synced = 1; - if (m->mdt_fl_cfglog /* bz11778: && m->mdt_fl_synced */) + if (m->mdt_fl_cfglog && m->mdt_fl_synced) /* Open for clients */ m->mdt_md_dev.md_lu_dev.ld_obd->obd_no_conn = 0; } static int mdt_upcall(const struct lu_env *env, struct md_device *md, - enum md_upcall_event ev) + enum md_upcall_event ev, void *data) { struct mdt_device *m = mdt_dev(&md->md_lu_dev); struct md_device *next = m->mdt_child; @@ -4980,10 +5296,8 @@ static int mdt_upcall(const struct lu_env *env, struct md_device *md, CDEBUG(D_INFO, "get max mdsize %d max cookiesize %d\n", m->mdt_max_mdsize, m->mdt_max_cookiesize); mdt_allow_cli(m, CONFIG_SYNC); -#ifdef HAVE_QUOTA_SUPPORT - if (md->md_lu_dev.ld_obd->obd_recovering == 0) - next->md_ops->mdo_quota.mqo_recovery(env, next); -#endif + if (data) + (*(__u64 *)data) = m->mdt_mount_count; break; case MD_NO_TRANS: mti = lu_context_key_get(&env->le_ctx, &mdt_thread_key); @@ -4994,6 +5308,13 @@ static int mdt_upcall(const struct lu_env *env, struct md_device *md, /* Check that MDT is not yet configured */ LASSERT(!m->mdt_fl_cfglog); break; +#ifdef HAVE_QUOTA_SUPPORT + case MD_LOV_QUOTA: + if (md->md_lu_dev.ld_obd->obd_recovering == 0 && + likely(md->md_lu_dev.ld_obd->obd_stopping == 0)) + next->md_ops->mdo_quota.mqo_recovery(env, next); + break; +#endif default: CERROR("invalid event\n"); rc = -EINVAL; @@ -5028,11 +5349,183 @@ static int mdt_obd_notify(struct obd_device *host, RETURN(0); } +static int mdt_rpc_fid2path(struct mdt_thread_info *info, void *key, + void *val, int vallen) +{ + struct mdt_device *mdt = mdt_dev(info->mti_exp->exp_obd->obd_lu_dev); + struct getinfo_fid2path *fpout, *fpin; + int rc = 0; + + fpin = key + size_round(sizeof(KEY_FID2PATH)); + fpout = val; + + if (ptlrpc_req_need_swab(info->mti_pill->rc_req)) + lustre_swab_fid2path(fpin); + + memcpy(fpout, fpin, sizeof(*fpin)); + if (fpout->gf_pathlen != vallen - sizeof(*fpin)) + RETURN(-EINVAL); + + rc = mdt_fid2path(info->mti_env, mdt, fpout); + RETURN(rc); +} + +static int mdt_fid2path(const struct lu_env *env, struct mdt_device *mdt, + struct getinfo_fid2path *fp) +{ + struct mdt_object *obj; + int rc; + ENTRY; + + CDEBUG(D_IOCTL, "path get "DFID" from "LPU64" #%d\n", + PFID(&fp->gf_fid), fp->gf_recno, fp->gf_linkno); + + if (!fid_is_sane(&fp->gf_fid)) + RETURN(-EINVAL); + + obj = mdt_object_find(env, mdt, &fp->gf_fid); + if (obj == NULL || IS_ERR(obj)) { + CDEBUG(D_IOCTL, "no object "DFID": %ld\n",PFID(&fp->gf_fid), + PTR_ERR(obj)); + RETURN(-EINVAL); + } + + rc = lu_object_exists(&obj->mot_obj.mo_lu); + if (rc <= 0) { + if (rc == -1) + rc = -EREMOTE; + else + rc = -ENOENT; + mdt_object_put(env, obj); + CDEBUG(D_IOCTL, "nonlocal object "DFID": %d\n", + PFID(&fp->gf_fid), rc); + RETURN(rc); + } + + rc = mo_path(env, md_object_next(&obj->mot_obj), fp->gf_path, + fp->gf_pathlen, &fp->gf_recno, &fp->gf_linkno); + mdt_object_put(env, obj); + + RETURN(rc); +} + +static int mdt_get_info(struct mdt_thread_info *info) +{ + struct ptlrpc_request *req = mdt_info_req(info); + char *key; + int keylen; + __u32 *vallen; + void *valout; + int rc; + ENTRY; + + key = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_KEY); + if (key == NULL) { + CDEBUG(D_IOCTL, "No GETINFO key"); + RETURN(-EFAULT); + } + keylen = req_capsule_get_size(info->mti_pill, &RMF_GETINFO_KEY, + RCL_CLIENT); + + vallen = req_capsule_client_get(info->mti_pill, &RMF_GETINFO_VALLEN); + if (vallen == NULL) { + CDEBUG(D_IOCTL, "Unable to get RMF_GETINFO_VALLEN buffer"); + RETURN(-EFAULT); + } + + req_capsule_set_size(info->mti_pill, &RMF_GETINFO_VAL, RCL_SERVER, + *vallen); + rc = req_capsule_server_pack(info->mti_pill); + valout = req_capsule_server_get(info->mti_pill, &RMF_GETINFO_VAL); + if (valout == NULL) { + CDEBUG(D_IOCTL, "Unable to get get-info RPC out buffer"); + RETURN(-EFAULT); + } + + if (KEY_IS(KEY_FID2PATH)) + rc = mdt_rpc_fid2path(info, key, valout, *vallen); + else + rc = -EINVAL; + + lustre_msg_set_status(req->rq_repmsg, rc); + + RETURN(rc); +} + +/* Pass the ioc down */ +static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt, + unsigned int cmd, int len, void *data) +{ + struct lu_context ioctl_session; + struct md_device *next = mdt->mdt_child; + int rc; + ENTRY; + + rc = lu_context_init(&ioctl_session, LCT_SESSION); + if (rc) + RETURN(rc); + ioctl_session.lc_thread = (struct ptlrpc_thread *)cfs_current(); + lu_context_enter(&ioctl_session); + env->le_ses = &ioctl_session; + + LASSERT(next->md_ops->mdo_iocontrol); + rc = next->md_ops->mdo_iocontrol(env, next, cmd, len, data); + + lu_context_exit(&ioctl_session); + lu_context_fini(&ioctl_session); + RETURN(rc); +} + +static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg) +{ + struct obd_ioctl_data *data = karg; + struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1; + __u64 version; + struct mdt_object *obj; + struct mdt_lock_handle *lh; + int rc; + ENTRY; + CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid)); + if (!fid_is_sane(fid)) + RETURN(-EINVAL); + + lh = &mti->mti_lh[MDT_LH_PARENT]; + mdt_lock_reg_init(lh, LCK_CR); + + obj = mdt_object_find_lock(mti, fid, lh, MDS_INODELOCK_UPDATE); + if (IS_ERR(obj)) + RETURN(PTR_ERR(obj)); + + rc = mdt_object_exists(obj); + if (rc < 0) { + rc = -EREMOTE; + /** + * before calling version get the correct MDS should be + * fid, this is error to find remote object here + */ + CERROR("nonlocal object "DFID"\n", PFID(fid)); + } else if (rc == 0) { + rc = -ENOENT; + CDEBUG(D_IOCTL, "no such object: "DFID"\n", PFID(fid)); + } else { + version = mo_version_get(mti->mti_env, mdt_object_child(obj)); + if (version < 0) { + rc = (int)version; + } else { + *(__u64 *)data->ioc_inlbuf2 = version; + rc = 0; + } + } + mdt_object_unlock_put(mti, obj, lh, 1); + RETURN(rc); +} + +/* ioctls on obd dev */ static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len, void *karg, void *uarg) { struct lu_env env; - struct obd_device *obd= exp->exp_obd; + struct obd_device *obd = exp->exp_obd; struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev); struct dt_device *dt = mdt->mdt_bottom; int rc; @@ -5055,6 +5548,22 @@ static int mdt_iocontrol(unsigned int cmd, struct obd_export *exp, int len, target_stop_recovery_thread(obd); rc = 0; break; + case OBD_IOC_CHANGELOG_REG: + case OBD_IOC_CHANGELOG_DEREG: + case OBD_IOC_CHANGELOG_CLEAR: + rc = mdt_ioc_child(&env, mdt, cmd, len, karg); + break; + case OBD_IOC_GET_OBJ_VERSION: { + struct mdt_thread_info *mti; + mti = lu_context_key_get(&env.le_ctx, &mdt_thread_key); + memset(mti, 0, sizeof *mti); + mti->mti_env = &env; + mti->mti_mdt = mdt; + mti->mti_exp = exp; + + rc = mdt_ioc_version_get(mti, karg); + break; + } default: CERROR("Not supported cmd = %d for device %s\n", cmd, obd->obd_name); @@ -5081,7 +5590,8 @@ int mdt_postrecov(const struct lu_env *env, struct mdt_device *mdt) rc = ld->ld_ops->ldo_recovery_complete(env, ld); #ifdef HAVE_QUOTA_SUPPORT - next->md_ops->mdo_quota.mqo_recovery(env, next); + if (likely(obd->obd_stopping == 0)) + next->md_ops->mdo_quota.mqo_recovery(env, next); #endif RETURN(rc); } @@ -5099,8 +5609,65 @@ int mdt_obd_postrecov(struct obd_device *obd) return rc; } +/** + * Send a copytool req to a client + * Note this sends a request RPC from a server (MDT) to a client (MDC), + * backwards of normal comms. + */ +int mdt_hsm_copytool_send(struct obd_export *exp) +{ + struct lnl_hdr *lh; + struct hsm_action_list *hal; + struct hsm_action_item *hai; + int rc, len; + ENTRY; + + CWARN("%s: writing to mdc at %s\n", exp->exp_obd->obd_name, + libcfs_nid2str(exp->exp_connection->c_peer.nid)); + + len = sizeof(*lh) + sizeof(*hal) + MTI_NAME_MAXLEN + + /* for mockup below */ 2 * size_round(sizeof(*hai)); + OBD_ALLOC(lh, len); + if (lh == NULL) + RETURN(-ENOMEM); + + lh->lnl_magic = LNL_MAGIC; + lh->lnl_transport = LNL_TRANSPORT_HSM; + lh->lnl_msgtype = HMT_ACTION_LIST; + lh->lnl_msglen = len; + + hal = (struct hsm_action_list *)(lh + 1); + hal->hal_version = HAL_VERSION; + hal->hal_archive_num = 1; + obd_uuid2fsname(hal->hal_fsname, exp->exp_obd->obd_name, + MTI_NAME_MAXLEN); + + /* mock up an action list */ + hal->hal_count = 2; + hai = hai_zero(hal); + hai->hai_action = HSMA_ARCHIVE; + hai->hai_fid.f_oid = 0xA00A; + hai->hai_len = sizeof(*hai); + hai = hai_next(hai); + hai->hai_action = HSMA_RESTORE; + hai->hai_fid.f_oid = 0xB00B; + hai->hai_len = sizeof(*hai); + + /* Uses the ldlm reverse import; this rpc will be seen by + the ldlm_callback_handler */ + rc = target_set_info_rpc(exp->exp_imp_reverse, LDLM_SET_INFO, + sizeof(KEY_HSM_COPYTOOL_SEND), + KEY_HSM_COPYTOOL_SEND, + len, lh, NULL); + + OBD_FREE(lh, len); + + RETURN(rc); +} + static struct obd_ops mdt_obd_device_ops = { .o_owner = THIS_MODULE, + .o_set_info_async = mdt_obd_set_info_async, .o_connect = mdt_obd_connect, .o_reconnect = mdt_obd_reconnect, .o_disconnect = mdt_obd_disconnect, @@ -5177,7 +5744,7 @@ struct md_ucred *mdt_ucred(const struct mdt_thread_info *info) } /** - * Enable/disable COS. + * Enable/disable COS (Commit On Sharing). * * Set/Clear the COS flag in mdt options. * @@ -5201,9 +5768,9 @@ void mdt_enable_cos(struct mdt_device *mdt, int val) } /** - * Check COS status. + * Check COS (Commit On Sharing) status. * - * Return COS flag status/ + * Return COS flag status. * * \param mdt mdt device */ @@ -5258,6 +5825,7 @@ static int __init mdt_mod_init(void) static void __exit mdt_mod_exit(void) { + llo_local_obj_unregister(&mdt_last_recv); class_unregister_type(LUSTRE_MDT_NAME); } @@ -5300,7 +5868,9 @@ static void __exit mdt_mod_exit(void) static struct mdt_handler mdt_mds_ops[] = { DEF_MDT_HNDL_F(0, CONNECT, mdt_connect), DEF_MDT_HNDL_F(0, DISCONNECT, mdt_disconnect), -DEF_MDT_HNDL_F(0, SET_INFO, mdt_set_info), +DEF_MDT_HNDL (0, SET_INFO, mdt_set_info, + &RQF_OBD_SET_INFO), +DEF_MDT_HNDL_F(0, GET_INFO, mdt_get_info), DEF_MDT_HNDL_F(0 |HABEO_REFERO, GETSTATUS, mdt_getstatus), DEF_MDT_HNDL_F(HABEO_CORPUS, GETATTR, mdt_getattr), DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, GETATTR_NAME, mdt_getattr_name), @@ -5340,7 +5910,19 @@ static struct mdt_handler mdt_dlm_ops[] = { DEF_DLM_HNDL_0(0, CP_CALLBACK, mdt_cp_callback) }; +#define DEF_LLOG_HNDL(flags, name, fn) \ + DEF_HNDL(LLOG, ORIGIN_HANDLE_CREATE, _NET, flags, name, fn, NULL) + static struct mdt_handler mdt_llog_ops[] = { + DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CREATE, mdt_llog_create), + DEF_LLOG_HNDL(0, ORIGIN_HANDLE_NEXT_BLOCK, mdt_llog_next_block), + DEF_LLOG_HNDL(0, ORIGIN_HANDLE_READ_HEADER, mdt_llog_read_header), + DEF_LLOG_HNDL(0, ORIGIN_HANDLE_WRITE_REC, NULL), + DEF_LLOG_HNDL(0, ORIGIN_HANDLE_CLOSE, NULL), + DEF_LLOG_HNDL(0, ORIGIN_CONNECT, NULL), + DEF_LLOG_HNDL(0, CATINFO, NULL), + DEF_LLOG_HNDL(0, ORIGIN_HANDLE_PREV_BLOCK, mdt_llog_prev_block), + DEF_LLOG_HNDL(0, ORIGIN_HANDLE_DESTROY, mdt_llog_destroy), }; #define DEF_SEC_CTX_HNDL(name, fn) \