X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fmdt%2Fmdt_open.c;h=97918c48240074a1bdeeabe77ec77ae0a2df3b8e;hb=2bc5bcb7efa247fcd8cc65d013ffc9f6c33dd788;hp=fd54c2a252db09aa68f0fe649c0a8e03bbc83cb4;hpb=003df3c38fe74a092f75569793edd6ec5a387d5c;p=fs%2Flustre-release.git diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index fd54c2a..97918c4 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2013, Intel Corporation. + * Copyright (c) 2011, 2014, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -45,6 +45,7 @@ #include #include #include "mdt_internal.h" +#include /* we do nothing because we do not have refcount now */ static void mdt_mfd_get(void *mfdp) @@ -65,9 +66,9 @@ struct mdt_file_data *mdt_mfd_new(const struct mdt_export_data *med) OBD_ALLOC_PTR(mfd); if (mfd != NULL) { - CFS_INIT_LIST_HEAD(&mfd->mfd_handle.h_link); + INIT_LIST_HEAD(&mfd->mfd_handle.h_link); mfd->mfd_handle.h_owner = med; - CFS_INIT_LIST_HEAD(&mfd->mfd_list); + INIT_LIST_HEAD(&mfd->mfd_list); class_handle_hash(&mfd->mfd_handle, &mfd_handle_ops); } @@ -91,7 +92,7 @@ struct mdt_file_data *mdt_handle2mfd(struct mdt_export_data *med, mfd = class_handle2object(handle->cookie, med); /* during dw/setattr replay the mfd can be found by old handle */ if (mfd == NULL && is_replay_or_resent) { - cfs_list_for_each_entry(mfd, &med->med_open_head, mfd_list) { + list_for_each_entry(mfd, &med->med_open_head, mfd_list) { if (mfd->mfd_old_handle.cookie == handle->cookie) RETURN(mfd); } @@ -104,8 +105,8 @@ struct mdt_file_data *mdt_handle2mfd(struct mdt_export_data *med, /* free mfd */ void mdt_mfd_free(struct mdt_file_data *mfd) { - LASSERT(cfs_list_empty(&mfd->mfd_list)); - OBD_FREE_RCU(mfd, sizeof *mfd, &mfd->mfd_handle); + LASSERT(list_empty(&mfd->mfd_list)); + OBD_FREE_RCU(mfd, sizeof *mfd, &mfd->mfd_handle); } static int mdt_create_data(struct mdt_thread_info *info, @@ -123,9 +124,6 @@ static int mdt_create_data(struct mdt_thread_info *info, ma->ma_valid = 0; mutex_lock(&o->mot_lov_mutex); if (!(o->mot_flags & MOF_LOV_CREATED)) { - if (p != NULL && !fid_is_md_operative(mdt_object_fid(p))) - GOTO(unlock, rc = -EPERM); - rc = mdo_create_data(info->mti_env, p ? mdt_object_child(p) : NULL, mdt_object_child(o), spec, ma); @@ -135,7 +133,7 @@ static int mdt_create_data(struct mdt_thread_info *info, if (rc == 0 && ma->ma_valid & MA_LOV) o->mot_flags |= MOF_LOV_CREATED; } -unlock: + mutex_unlock(&o->mot_lov_mutex); RETURN(rc); } @@ -472,7 +470,7 @@ static int mdt_ioepoch_close(struct mdt_thread_info *info, struct mdt_object *o) * Apply obtained attributes for the 1st case, wipe out the on-disk SOM * cache otherwise. */ -int mdt_som_au_close(struct mdt_thread_info *info, struct mdt_object *o) +static int mdt_som_au_close(struct mdt_thread_info *info, struct mdt_object *o) { struct ptlrpc_request *req = mdt_info_req(info); __u64 ioepoch = 0; @@ -665,9 +663,9 @@ void mdt_mfd_set_mode(struct mdt_file_data *mfd, __u64 mode) /** * prep ma_lmm/ma_lmv for md_attr from reply */ -void mdt_prep_ma_buf_from_rep(struct mdt_thread_info *info, - struct mdt_object *obj, - struct md_attr *ma) +static void mdt_prep_ma_buf_from_rep(struct mdt_thread_info *info, + struct mdt_object *obj, + struct md_attr *ma) { LASSERT(ma->ma_lmv == NULL && ma->ma_lmm == NULL); if (S_ISDIR(obj->mot_header.loh_attr)) { @@ -757,8 +755,18 @@ static int mdt_mfd_open(struct mdt_thread_info *info, struct mdt_object *p, rc = mo_open(info->mti_env, mdt_object_child(o), created ? flags | MDS_OPEN_CREATED : flags); - if (rc) - GOTO(err_out, rc); + if (rc != 0) { + /* If we allow the client to chgrp (CFS_SETGRP_PERM), but the + * client does not know which suppgid should be sent to the MDS, + * or some other(s) changed the target file's GID after this RPC + * sent to the MDS with the suppgid as the original GID, then we + * give the client another chance to send the right suppgid. */ + if (rc == -EACCES && + allow_client_chgrp(info, lu_ucred(info->mti_env))) + mdt_set_disposition(info, rep, DISP_OPEN_DENY); + + GOTO(err_out, rc); + } mfd = mdt_mfd_new(med); if (mfd == NULL) @@ -802,7 +810,7 @@ static int mdt_mfd_open(struct mdt_thread_info *info, struct mdt_object *p, PFID(mdt_object_fid(mfd->mfd_object)), info->mti_rr.rr_handle->cookie); class_handle_unhash(&old_mfd->mfd_handle); - cfs_list_del_init(&old_mfd->mfd_list); + list_del_init(&old_mfd->mfd_list); spin_unlock(&med->med_open_lock); /* no attr update for that close */ la->la_valid = 0; @@ -830,12 +838,12 @@ static int mdt_mfd_open(struct mdt_thread_info *info, struct mdt_object *p, if (req->rq_export->exp_disconnected) { spin_lock(&med->med_open_lock); class_handle_unhash(&mfd->mfd_handle); - cfs_list_del_init(&mfd->mfd_list); + list_del_init(&mfd->mfd_list); spin_unlock(&med->med_open_lock); mdt_mfd_close(info, mfd); } else { spin_lock(&med->med_open_lock); - cfs_list_add(&mfd->mfd_list, &med->med_open_head); + list_add(&mfd->mfd_list, &med->med_open_head); spin_unlock(&med->med_open_lock); } @@ -854,21 +862,21 @@ err_out: return rc; } -int mdt_finish_open(struct mdt_thread_info *info, - struct mdt_object *p, struct mdt_object *o, - __u64 flags, int created, struct ldlm_reply *rep) +static int mdt_finish_open(struct mdt_thread_info *info, + struct mdt_object *p, struct mdt_object *o, + __u64 flags, int created, struct ldlm_reply *rep) { - struct ptlrpc_request *req = mdt_info_req(info); - struct obd_export *exp = req->rq_export; - struct mdt_export_data *med = &req->rq_export->exp_mdt_data; - struct md_attr *ma = &info->mti_attr; - struct lu_attr *la = &ma->ma_attr; - struct mdt_file_data *mfd; - struct mdt_body *repbody; - int rc = 0; - int isreg, isdir, islnk; - cfs_list_t *t; - ENTRY; + struct ptlrpc_request *req = mdt_info_req(info); + struct obd_export *exp = req->rq_export; + struct mdt_export_data *med = &req->rq_export->exp_mdt_data; + struct md_attr *ma = &info->mti_attr; + struct lu_attr *la = &ma->ma_attr; + struct mdt_file_data *mfd; + struct mdt_body *repbody; + int rc = 0; + int isreg, isdir, islnk; + struct list_head *t; + ENTRY; LASSERT(ma->ma_valid & MA_INODE); @@ -907,34 +915,9 @@ int mdt_finish_open(struct mdt_thread_info *info, } } #ifdef CONFIG_FS_POSIX_ACL - else if (exp_connect_flags(exp) & OBD_CONNECT_ACL) { - const struct lu_env *env = info->mti_env; - struct md_object *next = mdt_object_child(o); - struct lu_buf *buf = &info->mti_buf; - - 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) { - 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("got acl size: %d\n", rc); - } - } else { - repbody->mbo_aclsize = rc; - repbody->mbo_valid |= OBD_MD_FLACL; - rc = 0; - } - } - } + else if (exp_connect_flags(exp) & OBD_CONNECT_ACL) + rc = mdt_pack_acl2body(info, repbody, o, + exp->exp_target_data.ted_nodemap); #endif if (info->mti_mdt->mdt_lut.lut_mds_capa && @@ -994,11 +977,11 @@ int mdt_finish_open(struct mdt_thread_info *info, RETURN(-EAGAIN); } - mfd = NULL; - if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) { + mfd = NULL; + if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT) { spin_lock(&med->med_open_lock); - cfs_list_for_each(t, &med->med_open_head) { - mfd = cfs_list_entry(t, struct mdt_file_data, mfd_list); + list_for_each(t, &med->med_open_head) { + mfd = list_entry(t, struct mdt_file_data, mfd_list); if (mfd->mfd_xid == req->rq_xid) break; mfd = NULL; @@ -1028,9 +1011,6 @@ int mdt_finish_open(struct mdt_thread_info *info, RETURN(rc); } -extern void mdt_req_from_lcd(struct ptlrpc_request *req, - struct lsd_client_data *lcd); - void mdt_reconstruct_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) { @@ -1144,7 +1124,7 @@ out: LASSERT(ergo(rc < 0, lustre_msg_get_transno(req->rq_repmsg) == 0)); } -int mdt_open_by_fid(struct mdt_thread_info *info, struct ldlm_reply *rep) +static int mdt_open_by_fid(struct mdt_thread_info *info, struct ldlm_reply *rep) { __u64 flags = info->mti_spec.sp_cr_flags; struct mdt_reint_record *rr = &info->mti_rr; @@ -1246,29 +1226,30 @@ static int mdt_object_open_lock(struct mdt_thread_info *info, /* normal open holds read mode of open sem */ down_read(&obj->mot_open_sem); - if (open_flags & FMODE_WRITE) - lm = LCK_CW; - else if (open_flags & MDS_FMODE_EXEC) - lm = LCK_PR; - else - lm = LCK_CR; - if (open_flags & MDS_OPEN_LOCK) { + if (open_flags & FMODE_WRITE) + lm = LCK_CW; + else if (open_flags & MDS_FMODE_EXEC) + lm = LCK_PR; + else + lm = LCK_CR; + *ibits = MDS_INODELOCK_LOOKUP | MDS_INODELOCK_OPEN; - } else if (open_flags & (FMODE_WRITE | MDS_FMODE_EXEC) || - atomic_read(&obj->mot_lease_count) > 0) { - /* We need to flush conflicting locks or revoke a lease. - * In either case there is no need to acquire a layout - * lock since it won't be returned to the client. */ - try_layout = false; + } else if (atomic_read(&obj->mot_lease_count) > 0) { + if (open_flags & FMODE_WRITE) + lm = LCK_CW; + else + lm = LCK_CR; + + /* revoke lease */ *ibits = MDS_INODELOCK_OPEN; + try_layout = false; + lhc = &info->mti_lh[MDT_LH_LOCAL]; } - - CDEBUG(D_INODE, "normal open FID = "DFID", open_count = %d, " - "lm = %d\n", - PFID(mdt_object_fid(obj)), - atomic_read(&obj->mot_open_count), lm); + CDEBUG(D_INODE, "normal open:"DFID" lease count: %d, lm: %d\n", + PFID(mdt_object_fid(obj)), + atomic_read(&obj->mot_open_count), lm); } mdt_lock_reg_init(lhc, lm); @@ -1394,7 +1375,7 @@ static void mdt_object_open_unlock(struct mdt_thread_info *info, up_read(&obj->mot_open_sem); /* Cross-ref case, the lock should be returned to the client */ - if (ibits == 0 || rc == -EREMOTE) + if (ibits == 0 || rc == -MDT_EREMOTE_OPEN) RETURN_EXIT; if (!(open_flags & MDS_OPEN_LOCK) && !(ibits & MDS_INODELOCK_LAYOUT)) { @@ -1431,8 +1412,9 @@ static bool mdt_hsm_release_allow(const struct md_attr *ma) return true; } -int mdt_open_by_fid_lock(struct mdt_thread_info *info, struct ldlm_reply *rep, - struct mdt_lock_handle *lhc) +static int mdt_open_by_fid_lock(struct mdt_thread_info *info, + struct ldlm_reply *rep, + struct mdt_lock_handle *lhc) { const struct lu_env *env = info->mti_env; struct mdt_device *mdt = info->mti_mdt; @@ -1442,6 +1424,7 @@ int mdt_open_by_fid_lock(struct mdt_thread_info *info, struct ldlm_reply *rep, struct mdt_object *parent= NULL; struct mdt_object *o; int rc; + int object_locked = 0; __u64 ibits = 0; ENTRY; @@ -1460,9 +1443,9 @@ int mdt_open_by_fid_lock(struct mdt_thread_info *info, struct ldlm_reply *rep, ma->ma_need |= MA_PFID; } - o = mdt_object_find(env, mdt, rr->rr_fid2); - if (IS_ERR(o)) - RETURN(rc = PTR_ERR(o)); + o = mdt_object_find(env, mdt, rr->rr_fid2); + if (IS_ERR(o)) + GOTO(out_parent_put, rc = PTR_ERR(o)); if (mdt_object_remote(o)) { CDEBUG(D_INFO, "%s: "DFID" is on remote MDT.\n", @@ -1491,9 +1474,15 @@ int mdt_open_by_fid_lock(struct mdt_thread_info *info, struct ldlm_reply *rep, if (flags & MDS_OPEN_RELEASE && !mdt_hsm_release_allow(ma)) GOTO(out, rc = -EPERM); - rc = mdt_object_open_lock(info, o, lhc, &ibits); - if (rc) - GOTO(out_unlock, rc); + rc = mdt_check_resent_lock(info, o, lhc); + if (rc < 0) { + GOTO(out, rc); + } else if (rc > 0) { + rc = mdt_object_open_lock(info, o, lhc, &ibits); + object_locked = 1; + if (rc) + GOTO(out_unlock, rc); + } if (ma->ma_valid & MA_PFID) { parent = mdt_object_find(env, mdt, &ma->ma_pfid); @@ -1517,9 +1506,11 @@ int mdt_open_by_fid_lock(struct mdt_thread_info *info, struct ldlm_reply *rep, GOTO(out_unlock, rc); out_unlock: - mdt_object_open_unlock(info, o, lhc, ibits, rc); + if (object_locked) + mdt_object_open_unlock(info, o, lhc, ibits, rc); out: mdt_object_put(env, o); +out_parent_put: if (parent != NULL) mdt_object_put(env, parent); return rc; @@ -1563,13 +1554,6 @@ static int mdt_cross_open(struct mdt_thread_info *info, if (rc != 0) GOTO(out, rc); - /* Do not create lov object if the fid is opened - * under OBF */ - if (S_ISREG(ma->ma_attr.la_mode) && - !(ma->ma_valid & MA_LOV) && (flags & FMODE_WRITE) && - fid_is_obf(parent_fid)) - GOTO(out, rc = -EPERM); - rc = mdt_finish_open(info, NULL, o, flags, 0, rep); } else { /* @@ -1602,6 +1586,7 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) struct mdt_reint_record *rr = &info->mti_rr; int result, rc; int created = 0; + int object_locked = 0; __u32 msg_flags; ENTRY; @@ -1660,23 +1645,16 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) GOTO(out, result = -EFAULT); } CDEBUG(D_INFO, "No object(1), continue as regular open.\n"); - } else if ((!lu_name_is_valid(&rr->rr_name) && - (create_flags & MDS_OPEN_LOCK)) || - (create_flags & MDS_OPEN_BY_FID)) { + } else if (create_flags & (MDS_OPEN_BY_FID | MDS_OPEN_LOCK)) { + /* + * MDS_OPEN_LOCK is checked for backward compatibility with 2.1 + * client. + */ result = mdt_open_by_fid_lock(info, ldlm_rep, lhc); - /* If result is 0 then open by FID has found the file - * and there is nothing left for us to do here. More - * generally if it is anything other than -ENOENT or - * -EREMOTE then we return that now. If -ENOENT and - * MDS_OPEN_CREAT is set then we must create the file - * below. If -EREMOTE then we need to return a LOOKUP - * lock to the client, which we do below. Hence this - * odd looking condition. See LU-2523. */ - if (!(result == -ENOENT && (create_flags & MDS_OPEN_CREAT)) && - result != -EREMOTE) - GOTO(out, result); - - CDEBUG(D_INFO, "No object(2), continue as regular open.\n"); + if (result < 0) + CDEBUG(D_INFO, "no object for "DFID": %d\n", + PFID(rr->rr_fid2), result); + GOTO(out, result); } if (OBD_FAIL_CHECK(OBD_FAIL_MDS_OPEN_PACK)) @@ -1811,22 +1789,10 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) */ LASSERT(lhc != NULL); - if (lustre_handle_is_used(&lhc->mlh_reg_lh)) { - struct ldlm_lock *lock; - - LASSERT(msg_flags & MSG_RESENT); - - lock = ldlm_handle2lock(&lhc->mlh_reg_lh); - if (!lock) { - CERROR("Invalid lock handle "LPX64"\n", - lhc->mlh_reg_lh.cookie); - LBUG(); - } - LASSERT(fid_res_name_eq(mdt_object_fid(child), - &lock->l_resource->lr_name)); - LDLM_LOCK_PUT(lock); - rc = 0; - } else { + rc = mdt_check_resent_lock(info, child, lhc); + if (rc < 0) { + GOTO(out_child, result = rc); + } else if (rc > 0) { mdt_lock_handle_init(lhc); mdt_lock_reg_init(lhc, LCK_PR); @@ -1839,7 +1805,7 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) if (rc != 0) result = rc; else - result = -EREMOTE; + result = -MDT_EREMOTE_OPEN; GOTO(out_child, result); } else if (mdt_object_exists(child)) { /* We have to get attr & LOV EA & HSM for this @@ -1847,6 +1813,8 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) mdt_prep_ma_buf_from_rep(info, child, ma); ma->ma_need |= MA_HSM; result = mdt_attr_get_complex(info, child, ma); + if (result != 0) + GOTO(out_child, result); } else { /* Object does not exist. Likely FS corruption. */ CERROR("%s: name '"DNAME"' present, but FID " @@ -1856,9 +1824,12 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) } } - if (lustre_handle_is_used(&lhc->mlh_reg_lh)) { + rc = mdt_check_resent_lock(info, child, lhc); + if (rc < 0) { + GOTO(out_child, result = rc); + } else if (rc == 0) { /* the open lock might already be gotten in - * mdt_intent_fixup_resent */ + * ldlm_handle_enqueue() */ LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT); if (create_flags & MDS_OPEN_LOCK) mdt_set_disposition(info, ldlm_rep, DISP_OPEN_LOCK); @@ -1866,6 +1837,7 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) /* get openlock if this isn't replay and client requested it */ if (!req_is_replay(req)) { rc = mdt_object_open_lock(info, child, lhc, &ibits); + object_locked = 1; if (rc != 0) GOTO(out_child_unlock, result = rc); else if (create_flags & MDS_OPEN_LOCK) @@ -1906,7 +1878,8 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc) } EXIT; out_child_unlock: - mdt_object_open_unlock(info, child, lhc, ibits, result); + if (object_locked) + mdt_object_open_unlock(info, child, lhc, ibits, result); out_child: mdt_object_put(info->mti_env, child); out_parent: @@ -2245,10 +2218,10 @@ int mdt_mfd_close(struct mdt_thread_info *info, struct mdt_file_data *mfd) mdt_mfd_set_mode(mfd, ret == MDT_IOEPOCH_OPENED ? MDS_FMODE_EPOCH : MDS_FMODE_SOM); - LASSERT(mdt_info_req(info)); - med = &mdt_info_req(info)->rq_export->exp_mdt_data; + LASSERT(mdt_info_req(info)); + med = &mdt_info_req(info)->rq_export->exp_mdt_data; spin_lock(&med->med_open_lock); - cfs_list_add(&mfd->mfd_list, &med->med_open_head); + list_add(&mfd->mfd_list, &med->med_open_head); class_handle_hash_back(&mfd->mfd_handle); spin_unlock(&med->med_open_lock); @@ -2339,7 +2312,7 @@ int mdt_close(struct tgt_session_info *tsi) rc = -ESTALE; } else { class_handle_unhash(&mfd->mfd_handle); - cfs_list_del_init(&mfd->mfd_list); + list_del_init(&mfd->mfd_list); spin_unlock(&med->med_open_lock); /* Do not lose object before last unlink. */ @@ -2423,12 +2396,12 @@ int mdt_done_writing(struct tgt_session_info *tsi) } else rc = -ESTALE; GOTO(error_ucred, rc); - } + } - LASSERT(mfd->mfd_mode == MDS_FMODE_EPOCH || - mfd->mfd_mode == MDS_FMODE_TRUNC); - class_handle_unhash(&mfd->mfd_handle); - cfs_list_del_init(&mfd->mfd_list); + LASSERT(mfd->mfd_mode == MDS_FMODE_EPOCH || + mfd->mfd_mode == MDS_FMODE_TRUNC); + class_handle_unhash(&mfd->mfd_handle); + list_del_init(&mfd->mfd_list); spin_unlock(&med->med_open_lock); /* Set EPOCH CLOSE flag if not set by client. */