X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fmdt%2Fmdt_handler.c;h=79ca02befe885b0fab6ce1f1d2f2a4ec90ef11dd;hp=66b0eb4f4fbab9bc06654a0803943215f308077c;hb=a0b959c53d10bf3f0fd6b22de46397d0c7e5f667;hpb=a1ef13bca025e09e10ce2d6e007013d0e187e6eb diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 66b0eb4..79ca02b 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -69,6 +69,7 @@ #include #include #include +#include mdl_mode_t mdt_mdl_lock_modes[] = { [LCK_MINMODE] = MDL_MINMODE, @@ -388,12 +389,70 @@ static void mdt_pack_size2body(struct mdt_thread_info *info, b->mbo_blocks = ma->ma_som->msd_blocks; } +#ifdef CONFIG_FS_POSIX_ACL +/* + * Pack ACL data into the reply. UIDs/GIDs are mapped and filtered by nodemap. + * + * \param info thread info object + * \param repbody reply to pack ACLs into + * \param o mdt object of file to examine + * \param nodemap nodemap of client to reply to + * \retval 0 success + * \retval -errno error getting or parsing ACL from disk + */ +int mdt_pack_acl2body(struct mdt_thread_info *info, struct mdt_body *repbody, + struct mdt_object *o, struct lu_nodemap *nodemap) +{ + const struct lu_env *env = info->mti_env; + struct md_object *next = mdt_object_child(o); + struct lu_buf *buf = &info->mti_buf; + int rc; + + buf->lb_buf = req_capsule_server_get(info->mti_pill, &RMF_ACL); + buf->lb_len = req_capsule_get_size(info->mti_pill, &RMF_ACL, + RCL_SERVER); + if (buf->lb_len == 0) + return 0; + + rc = mo_xattr_get(env, next, buf, XATTR_NAME_ACL_ACCESS); + if (rc < 0) { + if (rc == -ENODATA) { + repbody->mbo_aclsize = 0; + repbody->mbo_valid |= OBD_MD_FLACL; + rc = 0; + } else if (rc == -EOPNOTSUPP) { + rc = 0; + } else { + CERROR("%s: unable to read "DFID" ACL: rc = %d\n", + mdt_obd_name(info->mti_mdt), + PFID(mdt_object_fid(o)), rc); + } + } else { + rc = nodemap_map_acl(nodemap, buf->lb_buf, + rc, NODEMAP_FS_TO_CLIENT); + /* if all ACLs mapped out, rc is still >= 0 */ + if (rc < 0) { + CERROR("%s: nodemap_map_acl unable to parse "DFID + " ACL: rc = %d\n", mdt_obd_name(info->mti_mdt), + PFID(mdt_object_fid(o)), rc); + } else { + repbody->mbo_aclsize = rc; + repbody->mbo_valid |= OBD_MD_FLACL; + rc = 0; + } + } + return rc; +} +#endif + void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b, const struct lu_attr *attr, const struct lu_fid *fid) { - struct md_attr *ma = &info->mti_attr; + struct md_attr *ma = &info->mti_attr; + struct obd_export *exp = info->mti_exp; + struct lu_nodemap *nodemap = exp->exp_target_data.ted_nodemap; - LASSERT(ma->ma_valid & MA_INODE); + LASSERT(ma->ma_valid & MA_INODE); b->mbo_atime = attr->la_atime; b->mbo_mtime = attr->la_mtime; @@ -401,8 +460,12 @@ void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b, b->mbo_mode = attr->la_mode; b->mbo_size = attr->la_size; b->mbo_blocks = attr->la_blocks; - b->mbo_uid = attr->la_uid; - b->mbo_gid = attr->la_gid; + b->mbo_uid = nodemap_map_id(nodemap, NODEMAP_UID, + NODEMAP_FS_TO_CLIENT, + attr->la_uid); + b->mbo_gid = nodemap_map_id(nodemap, NODEMAP_GID, + NODEMAP_FS_TO_CLIENT, + attr->la_gid); b->mbo_flags = attr->la_flags; b->mbo_nlink = attr->la_nlink; b->mbo_rdev = attr->la_rdev; @@ -683,13 +746,17 @@ int mdt_attr_get_complex(struct mdt_thread_info *info, const struct lu_env *env = info->mti_env; struct md_object *next = mdt_object_child(o); struct lu_buf *buf = &info->mti_buf; - u32 mode = lu_object_attr(&next->mo_lu); int need = ma->ma_need; int rc = 0, rc2; + u32 mode; ENTRY; ma->ma_valid = 0; + if (mdt_object_exists(o) == 0) + GOTO(out, rc = -ENOENT); + mode = lu_object_attr(&next->mo_lu); + if (need & MA_INODE) { ma->ma_need = MA_INODE; rc = mo_attr_get(env, next, ma); @@ -775,25 +842,27 @@ out: static int mdt_getattr_internal(struct mdt_thread_info *info, struct mdt_object *o, int ma_need) { - struct md_object *next = mdt_object_child(o); - const struct mdt_body *reqbody = info->mti_body; - struct ptlrpc_request *req = mdt_info_req(info); - struct md_attr *ma = &info->mti_attr; - struct lu_attr *la = &ma->ma_attr; - struct req_capsule *pill = info->mti_pill; - const struct lu_env *env = info->mti_env; - struct mdt_body *repbody; - struct lu_buf *buffer = &info->mti_buf; - int rc; - int is_root; - ENTRY; + struct md_object *next = mdt_object_child(o); + const struct mdt_body *reqbody = info->mti_body; + struct ptlrpc_request *req = mdt_info_req(info); + struct md_attr *ma = &info->mti_attr; + struct lu_attr *la = &ma->ma_attr; + struct req_capsule *pill = info->mti_pill; + const struct lu_env *env = info->mti_env; + struct mdt_body *repbody; + struct lu_buf *buffer = &info->mti_buf; + struct obd_export *exp = info->mti_exp; + struct lu_nodemap *nodemap = exp->exp_target_data.ted_nodemap; + int rc; + int is_root; + ENTRY; - if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) - RETURN(err_serious(-ENOMEM)); + if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) + RETURN(err_serious(-ENOMEM)); - repbody = req_capsule_server_get(pill, &RMF_MDT_BODY); + repbody = req_capsule_server_get(pill, &RMF_MDT_BODY); - ma->ma_valid = 0; + ma->ma_valid = 0; if (mdt_object_remote(o)) { /* This object is located on remote node.*/ @@ -993,33 +1062,8 @@ static int mdt_getattr_internal(struct mdt_thread_info *info, } #ifdef CONFIG_FS_POSIX_ACL else if ((exp_connect_flags(req->rq_export) & OBD_CONNECT_ACL) && - (reqbody->mbo_valid & OBD_MD_FLACL)) { - buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL); - buffer->lb_len = req_capsule_get_size(pill, - &RMF_ACL, RCL_SERVER); - if (buffer->lb_len > 0) { - rc = mo_xattr_get(env, next, buffer, - XATTR_NAME_ACL_ACCESS); - if (rc < 0) { - if (rc == -ENODATA) { - repbody->mbo_aclsize = 0; - repbody->mbo_valid |= OBD_MD_FLACL; - rc = 0; - } else if (rc == -EOPNOTSUPP) { - rc = 0; - } else { - CERROR("%s: unable to read "DFID - " ACL: rc = %d\n", - mdt_obd_name(info->mti_mdt), - PFID(mdt_object_fid(o)), rc); - } - } else { - repbody->mbo_aclsize = rc; - repbody->mbo_valid |= OBD_MD_FLACL; - rc = 0; - } - } - } + (reqbody->mbo_valid & OBD_MD_FLACL)) + rc = mdt_pack_acl2body(info, repbody, o, nodemap); #endif if (reqbody->mbo_valid & OBD_MD_FLMDSCAPA && @@ -1126,7 +1170,7 @@ static int mdt_getattr(struct tgt_session_info *tsi) } if (rc < 0) - GOTO(out_shrink, rc); + GOTO(out, rc = err_serious(rc)); req_capsule_set_size(pill, &RMF_MDT_MD, RCL_SERVER, rc); @@ -1191,7 +1235,7 @@ static int mdt_swap_layouts(struct tgt_session_info *tsi) info = tsi2mdt_info(tsi); if (info->mti_dlm_req != NULL) - ldlm_request_cancel(req, info->mti_dlm_req, 0); + ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP); if (req_capsule_get_size(info->mti_pill, &RMF_CAPA1, RCL_CLIENT)) mdt_set_capainfo(info, 0, &info->mti_body->mbo_fid1, @@ -1265,43 +1309,32 @@ out: } static int mdt_raw_lookup(struct mdt_thread_info *info, - struct mdt_object *parent, - const struct lu_name *lname, - struct ldlm_reply *ldlm_rep) + struct mdt_object *parent, + const struct lu_name *lname, + struct ldlm_reply *ldlm_rep) { - struct md_object *next = mdt_object_child(info->mti_object); - const struct mdt_body *reqbody = info->mti_body; - struct lu_fid *child_fid = &info->mti_tmp_fid1; - struct mdt_body *repbody; - int rc; - ENTRY; - - if (reqbody->mbo_valid != OBD_MD_FLID) - RETURN(0); + struct lu_fid *child_fid = &info->mti_tmp_fid1; + int rc; + ENTRY; - LASSERT(!info->mti_cross_ref); + LASSERT(!info->mti_cross_ref); - /* Only got the fid of this obj by name */ - fid_zero(child_fid); - rc = mdo_lookup(info->mti_env, next, lname, child_fid, - &info->mti_spec); -#if 0 - /* XXX is raw_lookup possible as intent operation? */ - if (rc != 0) { - if (rc == -ENOENT) - mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG); - RETURN(rc); - } else - mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS); + /* Only got the fid of this obj by name */ + fid_zero(child_fid); + rc = mdo_lookup(info->mti_env, mdt_object_child(info->mti_object), + lname, child_fid, &info->mti_spec); + if (rc == 0) { + struct mdt_body *repbody; - repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY); -#endif - if (rc == 0) { - repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY); + repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY); repbody->mbo_fid1 = *child_fid; repbody->mbo_valid = OBD_MD_FLID; - } - RETURN(1); + mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_POS); + } else if (rc == -ENOENT) { + mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG); + } + + RETURN(rc); } /* @@ -1319,7 +1352,6 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, struct mdt_body *reqbody = NULL; struct mdt_object *parent = info->mti_object; struct mdt_object *child; - struct md_object *next = mdt_object_child(parent); struct lu_fid *child_fid = &info->mti_tmp_fid1; struct lu_name *lname = NULL; struct mdt_lock_handle *lhp = NULL; @@ -1334,7 +1366,8 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, LASSERT(ergo(is_resent, lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT)); - LASSERT(parent != NULL); + if (parent == NULL) + RETURN(-ENOENT); if (info->mti_cross_ref) { /* Only getattr on the child. Parent is on another node. */ @@ -1347,7 +1380,7 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, rc = mdt_check_resent_lock(info, child, lhc); if (rc < 0) { - RETURN(-EPROTO); + RETURN(rc); } else if (rc > 0) { mdt_lock_handle_init(lhc); mdt_lock_reg_init(lhc, LCK_PR); @@ -1423,10 +1456,15 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, } if (lu_name_is_valid(lname)) { - rc = mdt_raw_lookup(info, parent, lname, ldlm_rep); - if (rc != 0) { - if (rc > 0) - rc = 0; + /* Always allow to lookup ".." */ + if (unlikely(lname->ln_namelen == 2 && + lname->ln_name[0] == '.' && + lname->ln_name[1] == '.')) + info->mti_spec.sp_permitted = 1; + + if (info->mti_body->mbo_valid == OBD_MD_FLID) { + rc = mdt_raw_lookup(info, parent, lname, ldlm_rep); + RETURN(rc); } @@ -1443,8 +1481,8 @@ static int mdt_getattr_name_lock(struct mdt_thread_info *info, /* step 2: lookup child's fid by name */ fid_zero(child_fid); - rc = mdo_lookup(info->mti_env, next, lname, child_fid, - &info->mti_spec); + rc = mdo_lookup(info->mti_env, mdt_object_child(parent), lname, + child_fid, &info->mti_spec); if (rc == -ENOENT) mdt_set_disposition(info, ldlm_rep, DISP_LOOKUP_NEG); @@ -1969,6 +2007,7 @@ static int mdt_quotactl(struct tgt_session_info *tsi) int id, rc; struct mdt_device *mdt = mdt_exp2dev(exp); struct lu_device *qmt = mdt->mdt_qmt_dev; + struct lu_nodemap *nodemap = exp->exp_target_data.ted_nodemap; ENTRY; oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL); @@ -1989,9 +2028,11 @@ static int mdt_quotactl(struct tgt_session_info *tsi) /* deprecated, not used any more */ RETURN(-EOPNOTSUPP); /* master quotactl */ - case Q_GETINFO: case Q_SETINFO: case Q_SETQUOTA: + if (!nodemap_can_setquota(nodemap)) + RETURN(-EPERM); + case Q_GETINFO: case Q_GETQUOTA: if (qmt == NULL) RETURN(-EOPNOTSUPP); @@ -2030,6 +2071,13 @@ static int mdt_quotactl(struct tgt_session_info *tsi) } } + if (oqctl->qc_type == USRQUOTA) + id = nodemap_map_id(nodemap, NODEMAP_UID, + NODEMAP_CLIENT_TO_FS, id); + else if (oqctl->qc_type == GRPQUOTA) + id = nodemap_map_id(nodemap, NODEMAP_UID, + NODEMAP_CLIENT_TO_FS, id); + repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL); if (repoqc == NULL) RETURN(err_serious(-EFAULT)); @@ -2325,8 +2373,14 @@ int mdt_check_resent_lock(struct mdt_thread_info *info, lock = ldlm_handle2lock(&lhc->mlh_reg_lh); LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT); - LASSERTF(lock != NULL, "Invalid lock handle "LPX64"\n", - lhc->mlh_reg_lh.cookie); + if (lock == NULL) { + /* Lock is pinned by ldlm_handle_enqueue0() as it is + * a resend case, however, it could be already destroyed + * due to client eviction or a raced cancel RPC. */ + LDLM_DEBUG_NOLOCK("Invalid lock handle "LPX64"\n", + lhc->mlh_reg_lh.cookie); + RETURN(-ESTALE); + } if (!fid_res_name_eq(mdt_object_fid(mo), &lock->l_resource->lr_name)) { @@ -2434,8 +2488,8 @@ static int mdt_object_local_lock(struct mdt_thread_info *info, policy, res_id, dlmflags, info->mti_exp == NULL ? NULL : &info->mti_exp->exp_handle.h_cookie); - if (unlikely(rc)) - RETURN(rc); + if (unlikely(rc != 0)) + GOTO(out_unlock, rc); } /* @@ -2456,15 +2510,15 @@ static int mdt_object_local_lock(struct mdt_thread_info *info, res_id, LDLM_FL_LOCAL_ONLY | dlmflags, info->mti_exp == NULL ? NULL : &info->mti_exp->exp_handle.h_cookie); - if (rc) - mdt_object_unlock(info, o, lh, 1); - else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) && - lh->mlh_pdo_hash != 0 && - (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) { - OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15); - } +out_unlock: + if (rc != 0) + mdt_object_unlock(info, o, lh, 1); + else if (unlikely(OBD_FAIL_PRECHECK(OBD_FAIL_MDS_PDO_LOCK)) && + lh->mlh_pdo_hash != 0 && + (lh->mlh_reg_mode == LCK_PW || lh->mlh_reg_mode == LCK_EX)) + OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_PDO_LOCK, 15); - RETURN(rc); + RETURN(rc); } static int @@ -2815,6 +2869,7 @@ void mdt_thread_info_init(struct ptlrpc_request *req, info->mti_spec.no_create = 0; info->mti_spec.sp_rm_entry = 0; + info->mti_spec.sp_permitted = 0; info->mti_spec.u.sp_ea.eadata = NULL; info->mti_spec.u.sp_ea.eadatalen = 0; @@ -2881,7 +2936,8 @@ static int mdt_tgt_connect(struct tgt_session_info *tsi) if (OBD_FAIL_CHECK(OBD_FAIL_TGT_DELAY_CONDITIONAL) && cfs_fail_val == tsi2mdt_info(tsi)->mti_mdt->mdt_seq_site.ss_node_id) - schedule_timeout_and_set_state(TASK_UNINTERRUPTIBLE, HZ * 3); + schedule_timeout_and_set_state(TASK_UNINTERRUPTIBLE, + msecs_to_jiffies(3 * MSEC_PER_SEC)); rc = tgt_connect(tsi); if (rc != 0) @@ -3344,7 +3400,7 @@ static int mdt_intent_reint(enum mdt_it_code opcode, /* the open lock or the lock for cross-ref object should be * returned to the client */ - if (rc == -EREMOTE || mdt_get_disposition(rep, DISP_OPEN_LOCK)) { + if (rc == -MDT_EREMOTE_OPEN || mdt_get_disposition(rep, DISP_OPEN_LOCK)) { LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh)); rep->lock_policy_res2 = 0; rc = mdt_intent_lock_replace(info, lockp, lhc, flags); @@ -3439,17 +3495,16 @@ static int mdt_intent_code(long itcode) static int mdt_intent_opc(long itopc, struct mdt_thread_info *info, struct ldlm_lock **lockp, __u64 flags) { - struct req_capsule *pill; - struct mdt_it_flavor *flv; - int opc; - int rc; - ENTRY; - - opc = mdt_intent_code(itopc); - if (opc < 0) - RETURN(-EINVAL); + struct req_capsule *pill = info->mti_pill; + struct ptlrpc_request *req = mdt_info_req(info); + struct mdt_it_flavor *flv; + int opc; + int rc; + ENTRY; - pill = info->mti_pill; + opc = mdt_intent_code(itopc); + if (opc < 0) + RETURN(-EINVAL); if (opc == MDT_IT_QUOTA) { struct lu_device *qmt = info->mti_mdt->mdt_qmt_dev; @@ -3465,33 +3520,33 @@ static int mdt_intent_opc(long itopc, struct mdt_thread_info *info, RETURN(rc); } - flv = &mdt_it_flavor[opc]; - if (flv->it_fmt != NULL) - req_capsule_extend(pill, flv->it_fmt); + flv = &mdt_it_flavor[opc]; + if (flv->it_fmt != NULL) + req_capsule_extend(pill, flv->it_fmt); - rc = mdt_unpack_req_pack_rep(info, flv->it_flags); - if (rc == 0) { - struct ptlrpc_request *req = mdt_info_req(info); - if (flv->it_flags & MUTABOR && - exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY) - RETURN(-EROFS); - } - if (rc == 0 && flv->it_act != NULL) { + rc = mdt_unpack_req_pack_rep(info, flv->it_flags); + if (rc < 0) + RETURN(rc); + + if (flv->it_flags & MUTABOR && + exp_connect_flags(req->rq_export) & OBD_CONNECT_RDONLY) + RETURN(-EROFS); + + if (flv->it_act != NULL) { struct ldlm_reply *rep; /* execute policy */ rc = flv->it_act(opc, info, lockp, flags); /* Check whether the reply has been packed successfully. */ - if (mdt_info_req(info)->rq_repmsg != NULL) { + if (req->rq_repmsg != NULL) { rep = req_capsule_server_get(info->mti_pill, &RMF_DLM_REP); rep->lock_policy_res2 = ptlrpc_status_hton(rep->lock_policy_res2); } - } else { - rc = -EPROTO; } + RETURN(rc); } @@ -3988,7 +4043,7 @@ static int mdt_stack_init(const struct lu_env *env, struct mdt_device *mdt, if (!obd) { CERROR("Can not find obd %s (%s in config)\n", MDD_OBD_NAME, lustre_cfg_string(cfg, 0)); - GOTO(class_detach, rc = -EINVAL); + GOTO(lcfg_cleanup, rc = -EINVAL); } lustre_cfg_free(lcfg); @@ -4116,7 +4171,7 @@ static int mdt_quota_init(const struct lu_env *env, struct mdt_device *mdt, if (!obd) { CERROR("Can not find obd %s (%s in config)\n", qmtname, lustre_cfg_string(cfg, 0)); - GOTO(class_detach, rc = -EINVAL); + GOTO(lcfg_cleanup, rc = -EINVAL); } lustre_cfg_free(lcfg); @@ -4690,13 +4745,13 @@ static int mdt_process_config(const struct lu_env *env, } } - rc = class_process_proc_seq_param(PARAM_MDT, obd->obd_vars, - cfg, obd); + rc = class_process_proc_param(PARAM_MDT, obd->obd_vars, + cfg, obd); if (rc > 0 || rc == -ENOSYS) { /* is it an HSM var ? */ - rc = class_process_proc_seq_param(PARAM_HSM, - hsm_cdt_get_proc_vars(), - cfg, obd); + rc = class_process_proc_param(PARAM_HSM, + hsm_cdt_get_proc_vars(), + cfg, obd); if (rc > 0 || rc == -ENOSYS) /* we don't understand; pass it on */ rc = next->ld_ops->ldo_process_config(env, next, @@ -4985,90 +5040,6 @@ static int mdt_connect_internal(struct obd_export *exp, return 0; } -/* mds_connect copy */ -static int mdt_obd_connect(const struct lu_env *env, - struct obd_export **exp, struct obd_device *obd, - struct obd_uuid *cluuid, - struct obd_connect_data *data, - void *localdata) -{ - struct obd_export *lexp; - struct lustre_handle conn = { 0 }; - struct mdt_device *mdt; - int rc; - ENTRY; - - LASSERT(env != NULL); - if (!exp || !obd || !cluuid) - RETURN(-EINVAL); - - mdt = mdt_dev(obd->obd_lu_dev); - - /* - * first, check whether the stack is ready to handle requests - * XXX: probably not very appropriate method is used now - * at some point we should find a better one - */ - if (!test_bit(MDT_FL_SYNCED, &mdt->mdt_state) && data != NULL && - !(data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT)) { - rc = obd_get_info(env, mdt->mdt_child_exp, - sizeof(KEY_OSP_CONNECTED), - KEY_OSP_CONNECTED, NULL, NULL, NULL); - if (rc) - RETURN(-EAGAIN); - set_bit(MDT_FL_SYNCED, &mdt->mdt_state); - } - - rc = class_connect(&conn, obd, cluuid); - if (rc) - RETURN(rc); - - lexp = class_conn2export(&conn); - LASSERT(lexp != NULL); - - rc = mdt_connect_internal(lexp, mdt, data); - if (rc == 0) { - struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd; - - LASSERT(lcd); - memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid); - rc = tgt_client_new(env, lexp); - if (rc == 0) - mdt_export_stats_init(obd, lexp, localdata); - - /* For phase I, sync for cross-ref operation. */ - lexp->exp_keep_sync = 1; - } - - if (rc != 0) { - class_disconnect(lexp); - *exp = NULL; - } else { - *exp = lexp; - } - - RETURN(rc); -} - -static int mdt_obd_reconnect(const struct lu_env *env, - struct obd_export *exp, struct obd_device *obd, - struct obd_uuid *cluuid, - struct obd_connect_data *data, - void *localdata) -{ - int rc; - ENTRY; - - if (exp == NULL || obd == NULL || cluuid == NULL) - RETURN(-EINVAL); - - rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data); - if (rc == 0) - mdt_export_stats_init(obd, exp, localdata); - - RETURN(rc); -} - static int mdt_ctxt_add_dirty_flag(struct lu_env *env, struct mdt_thread_info *info, struct mdt_file_data *mfd) @@ -5096,25 +5067,26 @@ static int mdt_ctxt_add_dirty_flag(struct lu_env *env, static int mdt_export_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; + struct list_head closing_list; + 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; + struct mdt_file_data *mfd, *n; + int rc = 0; + ENTRY; + INIT_LIST_HEAD(&closing_list); spin_lock(&med->med_open_lock); - while (!cfs_list_empty(&med->med_open_head)) { - cfs_list_t *tmp = med->med_open_head.next; - mfd = cfs_list_entry(tmp, struct mdt_file_data, mfd_list); + 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); - cfs_list_move_tail(&mfd->mfd_list, &closing_list); + list_move_tail(&mfd->mfd_list, &closing_list); } spin_unlock(&med->med_open_lock); mdt = mdt_dev(obd->obd_lu_dev); @@ -5131,12 +5103,13 @@ static int mdt_export_cleanup(struct obd_export *exp) info->mti_mdt = mdt; info->mti_exp = exp; - if (!cfs_list_empty(&closing_list)) { - struct md_attr *ma = &info->mti_attr; + if (!list_empty(&closing_list)) { + struct md_attr *ma = &info->mti_attr; - /* Close any open files (which may also cause orphan unlinking). */ - cfs_list_for_each_entry_safe(mfd, n, &closing_list, mfd_list) { - cfs_list_del_init(&mfd->mfd_list); + /* 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); ma->ma_need = ma->ma_valid = 0; /* This file is being closed due to an eviction, it @@ -5182,6 +5155,7 @@ static int mdt_obd_disconnect(struct obd_export *exp) LASSERT(exp); class_export_get(exp); + nodemap_del_member(exp); rc = server_disconnect_export(exp); if (rc != 0) CDEBUG(D_IOCTL, "server disconnect error: rc = %d\n", rc); @@ -5191,14 +5165,110 @@ static int mdt_obd_disconnect(struct obd_export *exp) RETURN(rc); } +/* mds_connect copy */ +static int mdt_obd_connect(const struct lu_env *env, + struct obd_export **exp, struct obd_device *obd, + struct obd_uuid *cluuid, + struct obd_connect_data *data, + void *localdata) +{ + struct obd_export *lexp; + struct lustre_handle conn = { 0 }; + struct mdt_device *mdt; + int rc; + lnet_nid_t *client_nid = localdata; + ENTRY; + + LASSERT(env != NULL); + if (!exp || !obd || !cluuid) + RETURN(-EINVAL); + + mdt = mdt_dev(obd->obd_lu_dev); + + /* + * first, check whether the stack is ready to handle requests + * XXX: probably not very appropriate method is used now + * at some point we should find a better one + */ + if (!test_bit(MDT_FL_SYNCED, &mdt->mdt_state) && data != NULL && + !(data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT)) { + rc = obd_get_info(env, mdt->mdt_child_exp, + sizeof(KEY_OSP_CONNECTED), + KEY_OSP_CONNECTED, NULL, NULL, NULL); + if (rc) + RETURN(-EAGAIN); + set_bit(MDT_FL_SYNCED, &mdt->mdt_state); + } + + rc = class_connect(&conn, obd, cluuid); + if (rc) + RETURN(rc); + + lexp = class_conn2export(&conn); + LASSERT(lexp != NULL); + + rc = mdt_connect_internal(lexp, mdt, data); + if (rc == 0) { + struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd; + + LASSERT(lcd); + memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid); + rc = tgt_client_new(env, lexp); + if (rc == 0) { + rc = nodemap_add_member(*client_nid, lexp); + if (rc != 0 && rc != -EEXIST) + goto out; + + mdt_export_stats_init(obd, lexp, localdata); + } + + /* For phase I, sync for cross-ref operation. */ + spin_lock(&lexp->exp_lock); + lexp->exp_keep_sync = 1; + spin_unlock(&lexp->exp_lock); + } +out: + if (rc != 0) { + class_disconnect(lexp); + *exp = NULL; + } else { + *exp = lexp; + } + + RETURN(rc); +} + +static int mdt_obd_reconnect(const struct lu_env *env, + struct obd_export *exp, struct obd_device *obd, + struct obd_uuid *cluuid, + struct obd_connect_data *data, + void *localdata) +{ + lnet_nid_t *client_nid = localdata; + int rc; + ENTRY; + + if (exp == NULL || obd == NULL || cluuid == NULL) + RETURN(-EINVAL); + + rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data); + if (rc == 0) { + rc = nodemap_add_member(*client_nid, exp); + if (rc == 0 || rc == -EEXIST) + mdt_export_stats_init(obd, exp, localdata); + } + + RETURN(rc); +} + /* FIXME: Can we avoid using these two interfaces? */ static int mdt_init_export(struct obd_export *exp) { - struct mdt_export_data *med = &exp->exp_mdt_data; - int rc; - ENTRY; + struct mdt_export_data *med = &exp->exp_mdt_data; + int rc; + ENTRY; - CFS_INIT_LIST_HEAD(&med->med_open_head); + INIT_LIST_HEAD(&med->med_open_head); spin_lock_init(&med->med_open_lock); mutex_init(&med->med_idmap_mutex); med->med_idmap = NULL; @@ -5243,13 +5313,13 @@ static int mdt_destroy_export(struct obd_export *exp) &exp->exp_client_uuid))) RETURN(0); - ldlm_destroy_export(exp); - tgt_client_free(exp); + ldlm_destroy_export(exp); + tgt_client_free(exp); - LASSERT(cfs_list_empty(&exp->exp_outstanding_replies)); - LASSERT(cfs_list_empty(&exp->exp_mdt_data.med_open_head)); + LASSERT(list_empty(&exp->exp_outstanding_replies)); + LASSERT(list_empty(&exp->exp_mdt_data.med_open_head)); - RETURN(0); + RETURN(0); } /** The maximum depth that fid2path() will search. @@ -5936,9 +6006,6 @@ static int __init mdt_mod_init(void) GOTO(lu_fini, rc); rc = class_register_type(&mdt_obd_device_ops, NULL, true, NULL, -#ifndef HAVE_ONLY_PROCFS_SEQ - NULL, -#endif LUSTRE_MDT_NAME, &mdt_device_type); if (rc) GOTO(mds_fini, rc);