From: Lai Siyao Date: Thu, 4 Jul 2013 09:36:08 +0000 (+0800) Subject: LU-36 mdd: cache lu_attr to avoid duplicate fetch X-Git-Tag: 2.5.52~12 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=c330a759c70b8328a0821d6f314d61f39e1efe8c LU-36 mdd: cache lu_attr to avoid duplicate fetch - we called mdd_la_get for so many times in MDD, it's not good for performance of high contention pdir operations. - mdd_attr_check is not strictly correct under pdir operations, there is still chance to decrease ctime because we don't have exclusive lock on parent while checking ctime - mdd_attr_check_set_internal and mdd_attr_check_set_internal_locked can be merged into one function: mdd_update_time, because set cmtime is the only use-case of them. Change-Id: I59500835473ae6d42aa9bd2dcf9be644b7b7ec16 Signed-off-by: Liang Zhen Signed-off-by: Lai Siyao Reviewed-on: http://review.whamcloud.com/6897 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Alex Zhuravlev Reviewed-by: Mike Pershin Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/lustre_eacl.h b/lustre/include/lustre_eacl.h index 84b2624..28d0c59 100644 --- a/lustre/include/lustre_eacl.h +++ b/lustre/include/lustre_eacl.h @@ -75,9 +75,10 @@ struct lu_ucred; struct lu_attr; struct lustre_idmap_table; -extern int lustre_posix_acl_permission(struct lu_ucred *mu, struct lu_attr *la, - int want, posix_acl_xattr_entry *entry, - int count); +extern int lustre_posix_acl_permission(struct lu_ucred *mu, + const struct lu_attr *la, int want, + posix_acl_xattr_entry *entry, + int count); extern int lustre_posix_acl_chmod_masq(posix_acl_xattr_entry *entry, __u32 mode, int count); extern int lustre_posix_acl_create_masq(posix_acl_xattr_entry *entry, diff --git a/lustre/mdd/mdd_compat.c b/lustre/mdd/mdd_compat.c index fedc877..7b50624 100644 --- a/lustre/mdd/mdd_compat.c +++ b/lustre/mdd/mdd_compat.c @@ -136,7 +136,7 @@ static int mdd_convert_object(const struct lu_env *env, const struct lu_name *name) { struct mdd_object *o; - struct lu_attr *la = &mdd_env_info(env)->mti_la; + struct lu_attr *la = MDD_ENV_VAR(env, cattr); int rc; ENTRY; diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index c4d0271..37ece1f 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -60,7 +60,8 @@ static struct lu_name lname_dotdot = { /* Get FID from name and parent */ static int __mdd_lookup(const struct lu_env *env, struct md_object *pobj, - const struct lu_name *lname, struct lu_fid* fid, int mask) + const struct lu_attr *pattr, const struct lu_name *lname, + struct lu_fid* fid, int mask) { const char *name = lname->ln_name; const struct dt_key *key = (const struct dt_key *)name; @@ -84,7 +85,7 @@ __mdd_lookup(const struct lu_env *env, struct md_object *pobj, if (unlikely(lname->ln_namelen > m->mdd_dt_conf.ddp_max_name_len)) RETURN(-ENAMETOOLONG); - rc = mdd_permission_internal_locked(env, mdd_obj, NULL, mask, + rc = mdd_permission_internal_locked(env, mdd_obj, pattr, mask, MOR_TGT_PARENT); if (rc) RETURN(rc); @@ -106,19 +107,27 @@ __mdd_lookup(const struct lu_env *env, struct md_object *pobj, } int mdd_lookup(const struct lu_env *env, - struct md_object *pobj, const struct lu_name *lname, - struct lu_fid* fid, struct md_op_spec *spec) + struct md_object *pobj, const struct lu_name *lname, + struct lu_fid *fid, struct md_op_spec *spec) { + struct lu_attr *pattr = MDD_ENV_VAR(env, pattr); int rc; ENTRY; - rc = __mdd_lookup(env, pobj, lname, fid, MAY_EXEC); + + rc = mdd_la_get(env, md2mdd_obj(pobj), pattr, BYPASS_CAPA); + if (rc != 0) + RETURN(rc); + + rc = __mdd_lookup(env, pobj, pattr, lname, fid, MAY_EXEC); RETURN(rc); } -int mdd_parent_fid(const struct lu_env *env, struct mdd_object *obj, - struct lu_fid *fid) +static inline int mdd_parent_fid(const struct lu_env *env, + struct mdd_object *obj, + const struct lu_attr *attr, + struct lu_fid *fid) { - return __mdd_lookup(env, &obj->mod_obj, &lname_dotdot, fid, 0); + return __mdd_lookup(env, &obj->mod_obj, attr, &lname_dotdot, fid, 0); } /* @@ -141,10 +150,11 @@ int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid) * otherwise: values < 0, errors. */ static int mdd_is_parent(const struct lu_env *env, - struct mdd_device *mdd, - struct mdd_object *p1, - const struct lu_fid *lf, - struct lu_fid *pf) + struct mdd_device *mdd, + struct mdd_object *p1, + const struct lu_attr *attr, + const struct lu_fid *lf, + struct lu_fid *pf) { struct mdd_object *parent = NULL; struct lu_fid *pfid; @@ -159,11 +169,11 @@ static int mdd_is_parent(const struct lu_env *env, RETURN(0); for(;;) { - /* this is done recursively, bypass capa for each obj */ - mdd_set_capainfo(env, 4, p1, BYPASS_CAPA); - rc = mdd_parent_fid(env, p1, pfid); - if (rc) - GOTO(out, rc); + /* this is done recursively, bypass capa for each obj */ + mdd_set_capainfo(env, 4, p1, BYPASS_CAPA); + rc = mdd_parent_fid(env, p1, attr, pfid); + if (rc) + GOTO(out, rc); if (mdd_is_root(mdd, pfid)) GOTO(out, rc = 0); if (lu_fid_eq(pfid, lf)) @@ -201,25 +211,30 @@ out: * returns < 0: if error */ int mdd_is_subdir(const struct lu_env *env, struct md_object *mo, - const struct lu_fid *fid, struct lu_fid *sfid) + const struct lu_fid *fid, struct lu_fid *sfid) { - struct mdd_device *mdd = mdo2mdd(mo); - int rc; - ENTRY; + struct mdd_device *mdd = mdo2mdd(mo); + struct lu_attr *attr = MDD_ENV_VAR(env, cattr); + int rc; + ENTRY; - if (!S_ISDIR(mdd_object_type(md2mdd_obj(mo)))) - RETURN(0); + if (!S_ISDIR(mdd_object_type(md2mdd_obj(mo)))) + RETURN(0); - rc = mdd_is_parent(env, mdd, md2mdd_obj(mo), fid, sfid); - if (rc == 0) { - /* found root */ - fid_zero(sfid); - } else if (rc == 1) { - /* found @fid is parent */ - *sfid = *fid; - rc = 0; - } - RETURN(rc); + rc = mdd_la_get(env, md2mdd_obj(mo), attr, BYPASS_CAPA); + if (rc != 0) + RETURN(rc); + + rc = mdd_is_parent(env, mdd, md2mdd_obj(mo), attr, fid, sfid); + if (rc == 0) { + /* found root */ + fid_zero(sfid); + } else if (rc == 1) { + /* found @fid is parent */ + *sfid = *fid; + rc = 0; + } + RETURN(rc); } /* @@ -271,79 +286,79 @@ static int mdd_dir_is_empty(const struct lu_env *env, RETURN(result); } -static int __mdd_may_link(const struct lu_env *env, struct mdd_object *obj) +static int __mdd_may_link(const struct lu_env *env, struct mdd_object *obj, + const struct lu_attr *la) { - struct mdd_device *m = mdd_obj2mdd_dev(obj); - struct lu_attr *la = &mdd_env_info(env)->mti_la; - int rc; - ENTRY; + struct mdd_device *m = mdd_obj2mdd_dev(obj); + ENTRY; - rc = mdd_la_get(env, obj, la, BYPASS_CAPA); - if (rc) - RETURN(rc); + LASSERT(la != NULL); - /* - * Subdir count limitation can be broken through. - */ - if (la->la_nlink >= m->mdd_dt_conf.ddp_max_nlink && - !S_ISDIR(la->la_mode)) - RETURN(-EMLINK); - else - RETURN(0); + if (!S_ISDIR(la->la_mode)) + RETURN(0); + + /* + * Subdir count limitation can be broken through. + */ + if (la->la_nlink >= m->mdd_dt_conf.ddp_max_nlink) + RETURN(-EMLINK); + else + RETURN(0); } /* * Check whether it may create the cobj under the pobj. * cobj maybe NULL */ -int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj, - struct mdd_object *cobj, int check_perm, int check_nlink) +int mdd_may_create(const struct lu_env *env, + struct mdd_object *pobj, const struct lu_attr *pattr, + struct mdd_object *cobj, int check_perm, int check_nlink) { - int rc = 0; - ENTRY; + int rc = 0; + ENTRY; if (cobj && mdd_object_exists(cobj)) - RETURN(-EEXIST); + RETURN(-EEXIST); - if (mdd_is_dead_obj(pobj)) - RETURN(-ENOENT); + if (mdd_is_dead_obj(pobj)) + RETURN(-ENOENT); - if (check_perm) - rc = mdd_permission_internal_locked(env, pobj, NULL, - MAY_WRITE | MAY_EXEC, - MOR_TGT_PARENT); - if (!rc && check_nlink) - rc = __mdd_may_link(env, pobj); + if (check_perm) + rc = mdd_permission_internal_locked(env, pobj, pattr, + MAY_WRITE | MAY_EXEC, + MOR_TGT_PARENT); + if (!rc && check_nlink) + rc = __mdd_may_link(env, pobj, pattr); - RETURN(rc); + RETURN(rc); } /* * Check whether can unlink from the pobj in the case of "cobj == NULL". */ int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj, - const struct lu_attr *attr) + const struct lu_attr *pattr, const struct lu_attr *attr) { - int rc; - ENTRY; + int rc; + ENTRY; - if (mdd_is_dead_obj(pobj)) - RETURN(-ENOENT); + if (mdd_is_dead_obj(pobj)) + RETURN(-ENOENT); if ((attr->la_valid & LA_FLAGS) && (attr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL))) - RETURN(-EPERM); + RETURN(-EPERM); - rc = mdd_permission_internal_locked(env, pobj, NULL, - MAY_WRITE | MAY_EXEC, - MOR_TGT_PARENT); - if (rc) - RETURN(rc); + rc = mdd_permission_internal_locked(env, pobj, pattr, + MAY_WRITE | MAY_EXEC, + MOR_TGT_PARENT); + if (rc) + RETURN(rc); - if (mdd_is_append(pobj)) - RETURN(-EPERM); + if (mdd_is_append(pobj)) + RETURN(-EPERM); - RETURN(rc); + RETURN(rc); } /* @@ -352,34 +367,30 @@ int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj, */ static inline int mdd_is_sticky(const struct lu_env *env, struct mdd_object *pobj, - struct mdd_object *cobj) + const struct lu_attr *pattr, + struct mdd_object *cobj, + const struct lu_attr *cattr) { - struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la; struct lu_ucred *uc = lu_ucred_assert(env); - int rc; - - if (pobj) { - rc = mdd_la_get(env, pobj, tmp_la, BYPASS_CAPA); - if (rc) - return rc; - if (!(tmp_la->la_mode & S_ISVTX) || - (tmp_la->la_uid == uc->uc_fsuid)) + if (pobj != NULL) { + LASSERT(pattr != NULL); + if (!(pattr->la_mode & S_ISVTX) || + (pattr->la_uid == uc->uc_fsuid)) return 0; } - rc = mdd_la_get(env, cobj, tmp_la, BYPASS_CAPA); - if (rc) - return rc; - - if (tmp_la->la_uid == uc->uc_fsuid) + LASSERT(cattr != NULL); + if (cattr->la_uid == uc->uc_fsuid) return 0; return !md_capable(uc, CFS_CAP_FOWNER); } static int mdd_may_delete_entry(const struct lu_env *env, - struct mdd_object *pobj, int check_perm) + struct mdd_object *pobj, + const struct lu_attr *pattr, + int check_perm) { ENTRY; @@ -392,7 +403,7 @@ static int mdd_may_delete_entry(const struct lu_env *env, if (check_perm) { int rc; - rc = mdd_permission_internal_locked(env, pobj, NULL, + rc = mdd_permission_internal_locked(env, pobj, pattr, MAY_WRITE | MAY_EXEC, MOR_TGT_PARENT); if (rc) @@ -409,67 +420,70 @@ static int mdd_may_delete_entry(const struct lu_env *env, * Check whether it may delete the cobj from the pobj. * pobj maybe NULL */ -int mdd_may_delete(const struct lu_env *env, struct mdd_object *pobj, - struct mdd_object *cobj, struct lu_attr *cattr, - struct lu_attr *src_attr, int check_perm, int check_empty) +int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj, + const struct lu_attr *tpattr, struct mdd_object *tobj, + const struct lu_attr *tattr, const struct lu_attr *cattr, + int check_perm, int check_empty) { - int rc = 0; - ENTRY; + int rc = 0; + ENTRY; - if (pobj) { - rc = mdd_may_delete_entry(env, pobj, check_perm); + if (tpobj) { + LASSERT(tpattr != NULL); + rc = mdd_may_delete_entry(env, tpobj, tpattr, check_perm); if (rc != 0) RETURN(rc); } - if (cobj == NULL) + if (tobj == NULL) RETURN(0); - if (!mdd_object_exists(cobj)) - RETURN(-ENOENT); - - if (mdd_is_dead_obj(cobj)) - RETURN(-ESTALE); + if (!mdd_object_exists(tobj)) + RETURN(-ENOENT); + if (mdd_is_dead_obj(tobj)) + RETURN(-ESTALE); - if (mdd_is_sticky(env, pobj, cobj)) - RETURN(-EPERM); + if (mdd_is_sticky(env, tpobj, tpattr, tobj, tattr)) + RETURN(-EPERM); - if (mdd_is_immutable(cobj) || mdd_is_append(cobj)) - RETURN(-EPERM); + if (mdd_is_immutable(tobj) || mdd_is_append(tobj)) + RETURN(-EPERM); - if ((cattr->la_valid & LA_FLAGS) && - (cattr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL))) - RETURN(-EPERM); + if ((tattr->la_valid & LA_FLAGS) && + (tattr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL))) + RETURN(-EPERM); /* additional check the rename case */ - if (src_attr) { - if (S_ISDIR(src_attr->la_mode)) { - struct mdd_device *mdd = mdo2mdd(&cobj->mod_obj); + if (cattr) { + if (S_ISDIR(cattr->la_mode)) { + struct mdd_device *mdd = mdo2mdd(&tobj->mod_obj); - if (!S_ISDIR(cattr->la_mode)) + if (!S_ISDIR(tattr->la_mode)) RETURN(-ENOTDIR); - if (lu_fid_eq(mdo2fid(cobj), &mdd->mdd_root_fid)) + if (lu_fid_eq(mdo2fid(tobj), &mdd->mdd_root_fid)) RETURN(-EBUSY); - } else if (S_ISDIR(cattr->la_mode)) + } else if (S_ISDIR(tattr->la_mode)) RETURN(-EISDIR); } - if (S_ISDIR(cattr->la_mode) && check_empty) - rc = mdd_dir_is_empty(env, cobj); + if (S_ISDIR(tattr->la_mode) && check_empty) + rc = mdd_dir_is_empty(env, tobj); - RETURN(rc); + RETURN(rc); } /* * tgt maybe NULL * has mdd_write_lock on src already, but not on tgt yet */ -int mdd_link_sanity_check(const struct lu_env *env, - struct mdd_object *tgt_obj, - const struct lu_name *lname, - struct mdd_object *src_obj) +static int mdd_link_sanity_check(const struct lu_env *env, + struct mdd_object *tgt_obj, + const struct lu_attr *tattr, + const struct lu_name *lname, + struct mdd_object *src_obj, + const struct lu_attr *cattr) { struct mdd_device *m = mdd_obj2mdd_dev(src_obj); int rc = 0; @@ -491,16 +505,16 @@ int mdd_link_sanity_check(const struct lu_env *env, if (S_ISDIR(mdd_object_type(src_obj))) RETURN(-EPERM); - LASSERT(src_obj != tgt_obj); - if (tgt_obj) { - rc = mdd_may_create(env, tgt_obj, NULL, 1, 0); - if (rc) - RETURN(rc); - } + LASSERT(src_obj != tgt_obj); + if (tgt_obj) { + rc = mdd_may_create(env, tgt_obj, tattr, NULL, 1, 0); + if (rc) + RETURN(rc); + } - rc = __mdd_may_link(env, src_obj); + rc = __mdd_may_link(env, src_obj, cattr); - RETURN(rc); + RETURN(rc); } static int __mdd_index_delete_only(const struct lu_env *env, struct mdd_object *pobj, @@ -1209,11 +1223,21 @@ static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj, struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix; struct mdd_object *mdd_tobj = md2mdd_obj(tgt_obj); struct mdd_object *mdd_sobj = md2mdd_obj(src_obj); + struct lu_attr *cattr = MDD_ENV_VAR(env, cattr); + struct lu_attr *tattr = MDD_ENV_VAR(env, tattr); struct mdd_device *mdd = mdo2mdd(src_obj); struct thandle *handle; struct linkea_data *ldata = &mdd_env_info(env)->mti_link_data; - int rc; - ENTRY; + int rc; + ENTRY; + + rc = mdd_la_get(env, mdd_sobj, cattr, BYPASS_CAPA); + if (rc != 0) + RETURN(rc); + + rc = mdd_la_get(env, mdd_tobj, tattr, BYPASS_CAPA); + if (rc != 0) + RETURN(rc); handle = mdd_trans_create(env, mdd); if (IS_ERR(handle)) @@ -1233,10 +1257,11 @@ static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj, if (rc) GOTO(stop, rc); - mdd_write_lock(env, mdd_sobj, MOR_TGT_CHILD); - rc = mdd_link_sanity_check(env, mdd_tobj, lname, mdd_sobj); - if (rc) - GOTO(out_unlock, rc); + mdd_write_lock(env, mdd_sobj, MOR_TGT_CHILD); + rc = mdd_link_sanity_check(env, mdd_tobj, tattr, lname, mdd_sobj, + cattr); + if (rc) + GOTO(out_unlock, rc); rc = mdo_ref_add(env, mdd_sobj, handle); if (rc) @@ -1251,13 +1276,13 @@ static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj, GOTO(out_unlock, rc); } - la->la_valid = LA_CTIME | LA_MTIME; - rc = mdd_attr_check_set_internal(env, mdd_tobj, la, handle, 0); - if (rc) - GOTO(out_unlock, rc); + la->la_valid = LA_CTIME | LA_MTIME; + rc = mdd_update_time(env, mdd_tobj, tattr, la, handle); + if (rc) + GOTO(out_unlock, rc); - la->la_valid = LA_CTIME; - rc = mdd_attr_check_set_internal(env, mdd_sobj, la, handle, 0); + la->la_valid = LA_CTIME; + rc = mdd_update_time(env, mdd_sobj, cattr, la, handle); if (rc == 0) { rc = mdd_linkea_prepare(env, mdd_sobj, NULL, NULL, mdo2fid(mdd_tobj), lname, 0, 0, @@ -1341,14 +1366,16 @@ int mdd_finish_unlink(const struct lu_env *env, * has mdd_write_lock on cobj already, but not on pobj yet */ int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj, - struct mdd_object *cobj, struct lu_attr *cattr) + const struct lu_attr *pattr, + struct mdd_object *cobj, + const struct lu_attr *cattr) { - int rc; - ENTRY; + int rc; + ENTRY; - rc = mdd_may_delete(env, pobj, cobj, cattr, NULL, 1, 1); + rc = mdd_may_delete(env, pobj, pattr, cobj, cattr, NULL, 1, 1); - RETURN(rc); + RETURN(rc); } static int mdd_declare_unlink(const struct lu_env *env, struct mdd_device *mdd, @@ -1452,8 +1479,9 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj, struct md_attr *ma, int no_name) { const char *name = lname->ln_name; - struct lu_attr *cattr = &mdd_env_info(env)->mti_cattr; - struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix; + struct lu_attr *pattr = MDD_ENV_VAR(env, pattr); + struct lu_attr *cattr = MDD_ENV_VAR(env, cattr); + struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix; struct mdd_object *mdd_pobj = md2mdd_obj(pobj); struct mdd_object *mdd_cobj = NULL; struct mdd_device *mdd = mdo2mdd(pobj); @@ -1466,11 +1494,12 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj, mdd_cobj = md2mdd_obj(cobj); if (mdd_object_exists(mdd_cobj) == 0) RETURN(-ENOENT); - /* currently it is assume, it could only delete - * name entry of remote directory */ - is_dir = 1; } + rc = mdd_la_get(env, mdd_pobj, pattr, BYPASS_CAPA); + if (rc) + RETURN(rc); + handle = mdd_trans_create(env, mdd); if (IS_ERR(handle)) RETURN(PTR_ERR(handle)); @@ -1488,16 +1517,14 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj, mdd_write_lock(env, mdd_cobj, MOR_TGT_CHILD); /* fetch cattr */ - rc = mdd_la_get(env, mdd_cobj, cattr, - mdd_object_capa(env, mdd_cobj)); + rc = mdd_la_get(env, mdd_cobj, cattr, BYPASS_CAPA); if (rc) GOTO(cleanup, rc); is_dir = S_ISDIR(cattr->la_mode); - } - rc = mdd_unlink_sanity_check(env, mdd_pobj, mdd_cobj, cattr); + rc = mdd_unlink_sanity_check(env, mdd_pobj, pattr, mdd_cobj, cattr); if (rc) GOTO(cleanup, rc); @@ -1523,8 +1550,7 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj, mdo_ref_del(env, mdd_cobj, handle); /* fetch updated nlink */ - rc = mdd_la_get(env, mdd_cobj, cattr, - mdd_object_capa(env, mdd_cobj)); + rc = mdd_la_get(env, mdd_cobj, cattr, BYPASS_CAPA); if (rc) GOTO(cleanup, rc); } @@ -1533,7 +1559,7 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj, la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime; la->la_valid = LA_CTIME | LA_MTIME; - rc = mdd_attr_check_set_internal(env, mdd_pobj, la, handle, 0); + rc = mdd_update_time(env, mdd_pobj, pattr, la, handle); if (rc) GOTO(cleanup, rc); @@ -1545,7 +1571,7 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj, /* update ctime of an unlinked file only if it is still * opened or a link still exists */ la->la_valid = LA_CTIME; - rc = mdd_attr_check_set_internal(env, mdd_cobj, la, handle, 0); + rc = mdd_update_time(env, mdd_cobj, cattr, la, handle); if (rc) GOTO(cleanup, rc); } @@ -1557,8 +1583,7 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj, /* fetch updated nlink */ if (rc == 0) - rc = mdd_la_get(env, mdd_cobj, cattr, - mdd_object_capa(env, mdd_cobj)); + rc = mdd_la_get(env, mdd_cobj, cattr, BYPASS_CAPA); if (!is_dir) /* old files may not have link ea; ignore errors */ @@ -1606,28 +1631,27 @@ static int mdd_cd_sanity_check(const struct lu_env *env, RETURN(-ENOENT); RETURN(0); - } static int mdd_create_data(const struct lu_env *env, struct md_object *pobj, struct md_object *cobj, const struct md_op_spec *spec, struct md_attr *ma) { - struct mdd_device *mdd = mdo2mdd(cobj); - struct mdd_object *mdd_pobj = md2mdd_obj(pobj); - struct mdd_object *son = md2mdd_obj(cobj); - struct thandle *handle; + struct mdd_device *mdd = mdo2mdd(cobj); + struct mdd_object *mdd_pobj = md2mdd_obj(pobj); + struct mdd_object *son = md2mdd_obj(cobj); + struct thandle *handle; const struct lu_buf *buf; - struct lu_attr *attr = &mdd_env_info(env)->mti_cattr; - int rc; - ENTRY; + struct lu_attr *attr = MDD_ENV_VAR(env, cattr); + int rc; + ENTRY; - rc = mdd_cd_sanity_check(env, son); - if (rc) - RETURN(rc); + rc = mdd_cd_sanity_check(env, son); + if (rc) + RETURN(rc); - if (!md_should_create(spec->sp_cr_flags)) - RETURN(0); + if (!md_should_create(spec->sp_cr_flags)) + RETURN(0); /* * there are following use cases for this function: @@ -1635,7 +1659,7 @@ static int mdd_create_data(const struct lu_env *env, struct md_object *pobj, * striping can be specified or not * 2) CMD? */ - rc = mdd_la_get(env, son, attr, mdd_object_capa(env, son)); + rc = mdd_la_get(env, son, attr, BYPASS_CAPA); if (rc) RETURN(rc); @@ -1768,7 +1792,7 @@ static int mdd_object_initialize(const struct lu_env *env, /* has not lock on pobj yet */ static int mdd_create_sanity_check(const struct lu_env *env, struct md_object *pobj, - struct lu_attr *pattr, + const struct lu_attr *pattr, const struct lu_name *lname, struct lu_attr *cattr, struct md_op_spec *spec) @@ -1795,20 +1819,21 @@ static int mdd_create_sanity_check(const struct lu_env *env, * _index_insert also, for avoiding rolling back if exists * _index_insert. */ - rc = __mdd_lookup(env, pobj, lname, fid, MAY_WRITE | MAY_EXEC); + rc = __mdd_lookup(env, pobj, pattr, lname, fid, + MAY_WRITE | MAY_EXEC); if (rc != -ENOENT) RETURN(rc ? : -EEXIST); } else { - /* - * Check WRITE permission for the parent. - * EXEC permission have been checked - * when lookup before create already. - */ + /* + * Check WRITE permission for the parent. + * EXEC permission have been checked + * when lookup before create already. + */ rc = mdd_permission_internal_locked(env, obj, pattr, MAY_WRITE, MOR_TGT_PARENT); - if (rc) - RETURN(rc); - } + if (rc) + RETURN(rc); + } /* sgid check */ if (pattr->la_mode & S_ISGID) { @@ -2041,10 +2066,10 @@ static int mdd_create(const struct lu_env *env, struct md_object *pobj, if (rc != 0) RETURN(rc); - /* Sanity checks before big job. */ + /* Sanity checks before big job. */ rc = mdd_create_sanity_check(env, pobj, pattr, lname, attr, spec); - if (rc) - RETURN(rc); + if (rc) + RETURN(rc); if (OBD_FAIL_CHECK(OBD_FAIL_MDS_DQACQ_NET)) GOTO(out_free, rc = -EINPROGRESS); @@ -2178,7 +2203,7 @@ static int mdd_create(const struct lu_env *env, struct md_object *pobj, /* update parent directory mtime/ctime */ *la = *attr; la->la_valid = LA_CTIME | LA_MTIME; - rc = mdd_attr_check_set_internal(env, mdd_pobj, la, handle, 0); + rc = mdd_update_time(env, mdd_pobj, pattr, la, handle); if (rc) GOTO(cleanup, rc); @@ -2252,6 +2277,7 @@ enum rename_order { static int mdd_rename_order(const struct lu_env *env, struct mdd_device *mdd, struct mdd_object *src_pobj, + const struct lu_attr *pattr, struct mdd_object *tgt_pobj) { /* order of locking, 1 - tgt-src, 0 - src-tgt*/ @@ -2267,7 +2293,8 @@ static int mdd_rename_order(const struct lu_env *env, } else if (lu_fid_eq(&mdd->mdd_root_fid, mdo2fid(tgt_pobj))) { rc = MDD_RN_TGTSRC; } else { - rc = mdd_is_parent(env, mdd, src_pobj, mdo2fid(tgt_pobj), NULL); + rc = mdd_is_parent(env, mdd, src_pobj, pattr, mdo2fid(tgt_pobj), + NULL); if (rc == -EREMOTE) rc = 0; @@ -2283,11 +2310,13 @@ static int mdd_rename_order(const struct lu_env *env, /* has not mdd_write{read}_lock on any obj yet. */ static int mdd_rename_sanity_check(const struct lu_env *env, struct mdd_object *src_pobj, + const struct lu_attr *pattr, struct mdd_object *tgt_pobj, + const struct lu_attr *tpattr, struct mdd_object *sobj, + const struct lu_attr *cattr, struct mdd_object *tobj, - struct lu_attr *so_attr, - struct lu_attr *tg_attr) + const struct lu_attr *tattr) { int rc = 0; ENTRY; @@ -2297,7 +2326,7 @@ static int mdd_rename_sanity_check(const struct lu_env *env, * before mdd_rename and enable MDS_PERM_BYPASS. */ LASSERT(sobj); - rc = mdd_may_delete(env, src_pobj, sobj, so_attr, NULL, 1, 0); + rc = mdd_may_delete(env, src_pobj, pattr, sobj, cattr, NULL, 1, 0); if (rc) RETURN(rc); @@ -2307,15 +2336,14 @@ static int mdd_rename_sanity_check(const struct lu_env *env, * MDS_PERM_BYPASS). * So check may_create, but not check may_unlink. */ if (!tobj) - rc = mdd_may_create(env, tgt_pobj, NULL, + rc = mdd_may_create(env, tgt_pobj, tpattr, NULL, (src_pobj != tgt_pobj), 0); else - rc = mdd_may_delete(env, tgt_pobj, tobj, tg_attr, so_attr, + rc = mdd_may_delete(env, tgt_pobj, tpattr, tobj, tattr, cattr, (src_pobj != tgt_pobj), 1); - if (!rc && !tobj && (src_pobj != tgt_pobj) && - S_ISDIR(so_attr->la_mode)) - rc = __mdd_may_link(env, tgt_pobj); + if (!rc && !tobj && (src_pobj != tgt_pobj) && S_ISDIR(cattr->la_mode)) + rc = __mdd_may_link(env, tgt_pobj, tpattr); RETURN(rc); } @@ -2371,7 +2399,6 @@ static int mdd_declare_rename(const struct lu_env *env, rc = mdo_declare_ref_add(env, mdd_tpobj, handle); if (rc) return rc; - } la->la_valid = LA_CTIME | LA_MTIME; @@ -2455,13 +2482,15 @@ static int mdd_rename(const struct lu_env *env, const char *sname = lsname->ln_name; const char *tname = ltname->ln_name; struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix; - struct lu_attr *so_attr = &mdd_env_info(env)->mti_cattr; - struct lu_attr *tg_attr = &mdd_env_info(env)->mti_pattr; struct mdd_object *mdd_spobj = md2mdd_obj(src_pobj); /* source parent */ struct mdd_object *mdd_tpobj = md2mdd_obj(tgt_pobj); struct mdd_device *mdd = mdo2mdd(src_pobj); struct mdd_object *mdd_sobj = NULL; /* source object */ struct mdd_object *mdd_tobj = NULL; + struct lu_attr *cattr = MDD_ENV_VAR(env, cattr); + struct lu_attr *pattr = MDD_ENV_VAR(env, pattr); + struct lu_attr *tattr = MDD_ENV_VAR(env, tattr); + struct lu_attr *tpattr = MDD_ENV_VAR(env, tpattr); struct thandle *handle; struct linkea_data *ldata = &mdd_env_info(env)->mti_link_data; const struct lu_fid *tpobj_fid = mdo2fid(mdd_tpobj); @@ -2473,25 +2502,31 @@ static int mdd_rename(const struct lu_env *env, int rc, rc2; ENTRY; - if (tobj) - mdd_tobj = md2mdd_obj(tobj); + if (tobj) + mdd_tobj = md2mdd_obj(tobj); + + mdd_sobj = mdd_object_find(env, mdd, lf); - mdd_sobj = mdd_object_find(env, mdd, lf); + rc = mdd_la_get(env, mdd_sobj, cattr, BYPASS_CAPA); + if (rc) + GOTO(out_pending, rc); - rc = mdd_la_get(env, mdd_sobj, so_attr, - mdd_object_capa(env, mdd_sobj)); + rc = mdd_la_get(env, mdd_spobj, pattr, BYPASS_CAPA); if (rc) GOTO(out_pending, rc); if (mdd_tobj) { - rc = mdd_la_get(env, mdd_tobj, tg_attr, - mdd_object_capa(env, mdd_tobj)); + rc = mdd_la_get(env, mdd_tobj, tattr, BYPASS_CAPA); if (rc) GOTO(out_pending, rc); } - rc = mdd_rename_sanity_check(env, mdd_spobj, mdd_tpobj, mdd_sobj, - mdd_tobj, so_attr, tg_attr); + rc = mdd_la_get(env, mdd_tpobj, tpattr, BYPASS_CAPA); + if (rc) + GOTO(out_pending, rc); + + rc = mdd_rename_sanity_check(env, mdd_spobj, pattr, mdd_tpobj, tpattr, + mdd_sobj, cattr, mdd_tobj, tattr); if (rc) GOTO(out_pending, rc); @@ -2512,11 +2547,11 @@ static int mdd_rename(const struct lu_env *env, GOTO(stop, rc); /* FIXME: Should consider tobj and sobj too in rename_lock. */ - rc = mdd_rename_order(env, mdd, mdd_spobj, mdd_tpobj); - if (rc < 0) - GOTO(cleanup_unlocked, rc); + rc = mdd_rename_order(env, mdd, mdd_spobj, pattr, mdd_tpobj); + if (rc < 0) + GOTO(cleanup_unlocked, rc); - is_dir = S_ISDIR(so_attr->la_mode); + is_dir = S_ISDIR(cattr->la_mode); /* Remove source name from source directory */ rc = __mdd_index_delete(env, mdd_spobj, sname, is_dir, handle, @@ -2562,12 +2597,12 @@ static int mdd_rename(const struct lu_env *env, la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime; /* XXX: mdd_sobj must be local one if it is NOT NULL. */ - if (mdd_sobj) { - la->la_valid = LA_CTIME; - rc = mdd_attr_check_set_internal(env, mdd_sobj, la, handle, 0); - if (rc) - GOTO(fixup_tpobj, rc); - } + if (mdd_sobj) { + la->la_valid = LA_CTIME; + rc = mdd_update_time(env, mdd_sobj, cattr, la, handle); + if (rc) + GOTO(fixup_tpobj, rc); + } /* Remove old target object * For tobj is remote case cmm layer has processed @@ -2586,13 +2621,12 @@ static int mdd_rename(const struct lu_env *env, mdo_ref_del(env, mdd_tobj, handle); /* Remove dot reference. */ - if (S_ISDIR(tg_attr->la_mode)) + if (S_ISDIR(tattr->la_mode)) mdo_ref_del(env, mdd_tobj, handle); tobj_ref = 1; /* fetch updated nlink */ - rc = mdd_la_get(env, mdd_tobj, tg_attr, - mdd_object_capa(env, mdd_tobj)); + rc = mdd_la_get(env, mdd_tobj, tattr, BYPASS_CAPA); if (rc != 0) { CERROR("%s: Failed to get nlink for tobj " DFID": rc = %d\n", @@ -2602,7 +2636,7 @@ static int mdd_rename(const struct lu_env *env, } la->la_valid = LA_CTIME; - rc = mdd_attr_check_set_internal(env, mdd_tobj, la, handle, 0); + rc = mdd_update_time(env, mdd_tobj, tattr, la, handle); if (rc != 0) { CERROR("%s: Failed to set ctime for tobj " DFID": rc = %d\n", @@ -2612,7 +2646,7 @@ static int mdd_rename(const struct lu_env *env, } /* XXX: this transfer to ma will be removed with LOD/OSP */ - ma->ma_attr = *tg_attr; + ma->ma_attr = *tattr; ma->ma_valid |= MA_INODE; rc = mdd_finish_unlink(env, mdd_tobj, ma, handle); if (rc != 0) { @@ -2624,8 +2658,7 @@ static int mdd_rename(const struct lu_env *env, } /* fetch updated nlink */ - rc = mdd_la_get(env, mdd_tobj, tg_attr, - mdd_object_capa(env, mdd_tobj)); + rc = mdd_la_get(env, mdd_tobj, tattr, BYPASS_CAPA); if (rc != 0) { CERROR("%s: Failed to get nlink for tobj " DFID": rc = %d\n", @@ -2634,26 +2667,25 @@ static int mdd_rename(const struct lu_env *env, GOTO(fixup_tpobj, rc); } /* XXX: this transfer to ma will be removed with LOD/OSP */ - ma->ma_attr = *tg_attr; + ma->ma_attr = *tattr; ma->ma_valid |= MA_INODE; - if (tg_attr->la_nlink == 0) { + if (tattr->la_nlink == 0) { cl_flags |= CLF_RENAME_LAST; if (mdd_hsm_archive_exists(env, mdd_tobj, ma)) cl_flags |= CLF_RENAME_LAST_EXISTS; } } - la->la_valid = LA_CTIME | LA_MTIME; - rc = mdd_attr_check_set_internal(env, mdd_spobj, la, handle, 0); - if (rc) - GOTO(fixup_tpobj, rc); + la->la_valid = LA_CTIME | LA_MTIME; + rc = mdd_update_time(env, mdd_spobj, pattr, la, handle); + if (rc) + GOTO(fixup_tpobj, rc); - if (mdd_spobj != mdd_tpobj) { - la->la_valid = LA_CTIME | LA_MTIME; - rc = mdd_attr_check_set_internal(env, mdd_tpobj, la, - handle, 0); - } + if (mdd_spobj != mdd_tpobj) { + la->la_valid = LA_CTIME | LA_MTIME; + rc = mdd_update_time(env, mdd_tpobj, tpattr, la, handle); + } if (rc == 0 && mdd_sobj) { mdd_write_lock(env, mdd_sobj, MOR_SRC_CHILD); diff --git a/lustre/mdd/mdd_internal.h b/lustre/mdd/mdd_internal.h index 4f5d0a6..daa1dcb 100644 --- a/lustre/mdd/mdd_internal.h +++ b/lustre/mdd/mdd_internal.h @@ -122,39 +122,44 @@ struct mdd_object { __u64 mod_cltime; unsigned long mod_flags; #ifdef CONFIG_LOCKDEP - /* "dep_map" name is assumed by lockdep.h macros. */ - struct lockdep_map dep_map; + /* "dep_map" name is assumed by lockdep.h macros. */ + struct lockdep_map dep_map; #endif }; struct mdd_thread_info { - struct lu_fid mti_fid; - struct lu_fid mti_fid2; /* used for be & cpu converting */ - struct lu_attr mti_la; - struct lu_attr mti_la_for_fix; + struct lu_fid mti_fid; + struct lu_fid mti_fid2; /* used for be & cpu converting */ + /** + * only be used by MDD interfaces, can be passed into local MDD APIs. + */ struct lu_attr mti_pattr; struct lu_attr mti_cattr; - struct md_attr mti_ma; - struct obd_info mti_oi; + struct lu_attr mti_tpattr; + struct lu_attr mti_tattr; + /** used to set c/mtime */ + struct lu_attr mti_la_for_fix; + struct md_attr mti_ma; + struct obd_info mti_oi; /* mti_ent and mti_key must be conjoint, - * then mti_ent::lde_name will be mti_key. */ + * then mti_ent::lde_name will be mti_key. */ struct lu_dirent mti_ent; char mti_key[NAME_MAX + 16]; - struct obd_trans_info mti_oti; - struct lu_buf mti_buf[4]; - struct lu_buf mti_big_buf; /* biggish persistent buf */ + struct obd_trans_info mti_oti; + struct lu_buf mti_buf[4]; + struct lu_buf mti_big_buf; /* biggish persistent buf */ struct lu_buf mti_link_buf; /* buf for link ea */ - struct lu_name mti_name; + struct lu_name mti_name; struct lu_name mti_name2; - struct obdo mti_oa; - char mti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE]; - struct dt_allocation_hint mti_hint; - struct lov_mds_md *mti_max_lmm; - int mti_max_lmm_size; - struct llog_cookie *mti_max_cookie; - int mti_max_cookie_size; - struct dt_object_format mti_dof; - struct obd_quotactl mti_oqctl; + struct obdo mti_oa; + char mti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE]; + struct dt_allocation_hint mti_hint; + struct lov_mds_md *mti_max_lmm; + int mti_max_lmm_size; + struct llog_cookie *mti_max_cookie; + int mti_max_cookie_size; + struct dt_object_format mti_dof; + struct obd_quotactl mti_oqctl; struct linkea_data mti_link_data; }; @@ -217,11 +222,9 @@ int mdd_attr_set_internal(const struct lu_env *env, const struct lu_attr *attr, struct thandle *handle, int needacl); -int mdd_attr_check_set_internal(const struct lu_env *env, - struct mdd_object *obj, - struct lu_attr *attr, - struct thandle *handle, - int needacl); +int mdd_update_time(const struct lu_env *env, struct mdd_object *obj, + const struct lu_attr *oattr, struct lu_attr *attr, + struct thandle *handle); int mdd_declare_object_kill(const struct lu_env *env, struct mdd_object *obj, struct md_attr *ma, struct thandle *handle); int mdd_object_kill(const struct lu_env *env, struct mdd_object *obj, @@ -232,11 +235,6 @@ int mdd_object_create_internal(const struct lu_env *env, struct mdd_object *p, struct mdd_object *c, struct lu_attr *attr, struct thandle *handle, const struct md_op_spec *spec); -int mdd_attr_check_set_internal_locked(const struct lu_env *env, - struct mdd_object *obj, - struct lu_attr *attr, - struct thandle *handle, - int needacl); int mdd_lmm_get_locked(const struct lu_env *env, struct mdd_object *mdd_obj, struct md_attr *ma); @@ -255,24 +253,24 @@ void *mdd_pdo_write_lock(const struct lu_env *env, struct mdd_object *obj, void mdd_pdo_write_unlock(const struct lu_env *env, struct mdd_object *obj, void *dlh); /* mdd_dir.c */ -int mdd_parent_fid(const struct lu_env *env, struct mdd_object *obj, - struct lu_fid *fid); int mdd_is_subdir(const struct lu_env *env, struct md_object *mo, const struct lu_fid *fid, struct lu_fid *sfid); int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj, - struct mdd_object *cobj, int check_perm, int check_nlink); + const struct lu_attr *pattr, struct mdd_object *cobj, + int check_perm, int check_nlink); int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj, - const struct lu_attr *attr); -int mdd_may_delete(const struct lu_env *env, struct mdd_object *pobj, - struct mdd_object *cobj, struct lu_attr *cattr, - struct lu_attr *src_attr, int check_perm, int check_empty); + const struct lu_attr *pattr, const struct lu_attr *attr); +int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj, + const struct lu_attr *tpattr, struct mdd_object *tobj, + const struct lu_attr *tattr, const struct lu_attr *cattr, + int check_perm, int check_empty); int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj, - struct mdd_object *cobj, struct lu_attr *cattr); + const struct lu_attr *pattr, + struct mdd_object *cobj, + const struct lu_attr *cattr); int mdd_finish_unlink(const struct lu_env *env, struct mdd_object *obj, struct md_attr *ma, struct thandle *th); -int mdd_link_sanity_check(const struct lu_env *env, struct mdd_object *tgt_obj, - const struct lu_name *lname, struct mdd_object *src_obj); int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid); int mdd_lookup(const struct lu_env *env, struct md_object *pobj, const struct lu_name *lname, @@ -321,6 +319,8 @@ int mdd_lovobj_unlink(const struct lu_env *env, struct mdd_device *mdd, struct mdd_thread_info *mdd_env_info(const struct lu_env *env); +#define MDD_ENV_VAR(env, var) (&mdd_env_info(env)->mti_##var) + const struct lu_name *mdd_name_get_const(const struct lu_env *env, const void *area, ssize_t len); struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len); @@ -345,7 +345,6 @@ int mdd_procfs_init(struct mdd_device *mdd, const char *name); int mdd_procfs_fini(struct mdd_device *mdd); /* mdd_object.c */ -int mdd_get_flags(const struct lu_env *env, struct mdd_object *obj); struct lu_buf *mdd_buf_alloc(const struct lu_env *env, ssize_t len); int mdd_buf_grow(const struct lu_env *env, ssize_t len); void mdd_buf_put(struct lu_buf *buf); @@ -355,7 +354,7 @@ int mdd_link_buf_grow(const struct lu_env *env, ssize_t len); extern const struct md_dir_operations mdd_dir_ops; extern const struct md_object_operations mdd_obj_ops; -int accmode(const struct lu_env *env, struct lu_attr *la, int flags); +int accmode(const struct lu_env *env, const struct lu_attr *la, int flags); extern struct lu_context_key mdd_thread_key; extern const struct lu_device_operations mdd_lu_ops; @@ -428,11 +427,11 @@ int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode, int __mdd_declare_acl_init(const struct lu_env *env, struct mdd_object *obj, int is_dir, struct thandle *handle); int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj, - const struct lu_buf *buf, int fl); + struct lu_attr *attr, const struct lu_buf *buf, int fl); int __mdd_fix_mode_acl(const struct lu_env *env, struct lu_buf *buf, __u32 *mode); int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj, - struct lu_attr *la, int mask, int role); + const struct lu_attr *la, int mask, int role); int mdd_permission(const struct lu_env *env, struct md_object *pobj, struct md_object *cobj, struct md_attr *ma, int mask); @@ -597,18 +596,19 @@ enum { }; static inline int mdd_permission_internal(const struct lu_env *env, - struct mdd_object *obj, - struct lu_attr *la, int mask) + struct mdd_object *obj, + const struct lu_attr *la, int mask) { - return __mdd_permission_internal(env, obj, la, mask, -1); + return __mdd_permission_internal(env, obj, la, mask, -1); } static inline int mdd_permission_internal_locked(const struct lu_env *env, - struct mdd_object *obj, - struct lu_attr *la, int mask, - enum mdd_object_role role) + struct mdd_object *obj, + const struct lu_attr *la, + int mask, + enum mdd_object_role role) { - return __mdd_permission_internal(env, obj, la, mask, role); + return __mdd_permission_internal(env, obj, la, mask, role); } static inline int mdo_data_get(const struct lu_env *env, diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index 12a8166..69d4c30 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -84,6 +84,7 @@ int mdd_la_get(const struct lu_env *env, struct mdd_object *obj, mdd_obj_dev_name(obj), PFID(mdd_object_fid(obj))); return -ENOENT; } + return mdo_attr_get(env, obj, la, capa); } @@ -184,10 +185,18 @@ static int mdd_object_init(const struct lu_env *env, struct lu_object *o, static int mdd_object_start(const struct lu_env *env, struct lu_object *o) { - if (lu_object_exists(o)) - return mdd_get_flags(env, lu2mdd_obj(o)); - else - return 0; + int rc = 0; + + if (lu_object_exists(o)) { + struct mdd_object *mdd_obj = lu2mdd_obj(o); + struct lu_attr *attr = MDD_ENV_VAR(env, cattr); + + rc = mdd_la_get(env, mdd_obj, attr, BYPASS_CAPA); + if (rc == 0) + mdd_flags_xlate(mdd_obj, attr->la_flags); + } + + return rc; } static void mdd_object_free(const struct lu_env *env, struct lu_object *o) @@ -222,20 +231,6 @@ struct mdd_object *mdd_object_find(const struct lu_env *env, return md2mdd_obj(md_object_find_slice(env, &d->mdd_md_dev, f)); } -/* Returns the full path to this fid, as of changelog record recno. */ -int mdd_get_flags(const struct lu_env *env, struct mdd_object *obj) -{ - struct lu_attr *la = &mdd_env_info(env)->mti_la; - int rc; - - ENTRY; - rc = mdd_la_get(env, obj, la, BYPASS_CAPA); - if (rc == 0) { - mdd_flags_xlate(obj, la->la_flags); - } - RETURN(rc); -} - /* * No permission check is needed. */ @@ -386,31 +381,6 @@ int mdd_object_create_internal(const struct lu_env *env, struct mdd_object *p, RETURN(rc); } -/** - * Make sure the ctime is increased only. - */ -static inline int mdd_attr_check(const struct lu_env *env, - struct mdd_object *obj, - struct lu_attr *attr) -{ - struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la; - int rc; - ENTRY; - - if (attr->la_valid & LA_CTIME) { - rc = mdd_la_get(env, obj, tmp_la, BYPASS_CAPA); - if (rc) - RETURN(rc); - - if (attr->la_ctime < tmp_la->la_ctime) - attr->la_valid &= ~(LA_MTIME | LA_CTIME); - else if (attr->la_valid == LA_CTIME && - attr->la_ctime == tmp_la->la_ctime) - attr->la_valid &= ~LA_CTIME; - } - RETURN(0); -} - int mdd_attr_set_internal(const struct lu_env *env, struct mdd_object *obj, const struct lu_attr *attr, struct thandle *handle, int needacl) @@ -426,20 +396,29 @@ int mdd_attr_set_internal(const struct lu_env *env, struct mdd_object *obj, RETURN(rc); } -int mdd_attr_check_set_internal(const struct lu_env *env, - struct mdd_object *obj, struct lu_attr *attr, - struct thandle *handle, int needacl) +int mdd_update_time(const struct lu_env *env, struct mdd_object *obj, + const struct lu_attr *oattr, struct lu_attr *attr, + struct thandle *handle) { - int rc; - ENTRY; - - rc = mdd_attr_check(env, obj, attr); - if (rc) - RETURN(rc); + int rc = 0; + ENTRY; - if (attr->la_valid) - rc = mdd_attr_set_internal(env, obj, attr, handle, needacl); - RETURN(rc); + LASSERT(attr->la_valid & LA_CTIME); + LASSERT(oattr != NULL); + + /* Make sure the ctime is increased only, however, it's not strictly + * reliable at here because there is not guarantee to hold lock on + * object, so we just bypass some unnecessary cmtime setting first + * and OSD has to check it again. */ + if (attr->la_ctime < oattr->la_ctime) + attr->la_valid &= ~(LA_MTIME | LA_CTIME); + else if (attr->la_valid == LA_CTIME && + attr->la_ctime == oattr->la_ctime) + attr->la_valid &= ~LA_CTIME; + + if (attr->la_valid != 0) + rc = mdd_attr_set_internal(env, obj, attr, handle, 0); + RETURN(rc); } /* @@ -450,23 +429,25 @@ int mdd_attr_check_set_internal(const struct lu_env *env, * This API is ported from mds_fix_attr but remove some unnecesssary stuff. */ static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj, - struct lu_attr *la, const unsigned long flags) + const struct lu_attr *oattr, struct lu_attr *la, + const unsigned long flags) { - struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la; struct lu_ucred *uc; - int rc; - ENTRY; + int rc = 0; + ENTRY; - if (!la->la_valid) - RETURN(0); + if (!la->la_valid) + RETURN(0); - /* Do not permit change file type */ - if (la->la_valid & LA_TYPE) - RETURN(-EPERM); + /* Do not permit change file type */ + if (la->la_valid & LA_TYPE) + RETURN(-EPERM); + + /* They should not be processed by setattr */ + if (la->la_valid & (LA_NLINK | LA_RDEV | LA_BLKSIZE)) + RETURN(-EPERM); - /* They should not be processed by setattr */ - if (la->la_valid & (LA_NLINK | LA_RDEV | LA_BLKSIZE)) - RETURN(-EPERM); + LASSERT(oattr != NULL); /* export destroy does not have ->le_ses, but we may want * to drop LUSTRE_SOM_FL. */ @@ -474,36 +455,33 @@ static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj, if (uc == NULL) RETURN(0); - rc = mdd_la_get(env, obj, tmp_la, BYPASS_CAPA); - if (rc) - RETURN(rc); - - if (la->la_valid == LA_CTIME) { + if (la->la_valid == LA_CTIME) { if (!(flags & MDS_PERM_BYPASS)) - /* This is only for set ctime when rename's source is - * on remote MDS. */ - rc = mdd_may_delete(env, NULL, obj, tmp_la, NULL, 1, 0); - if (rc == 0 && la->la_ctime <= tmp_la->la_ctime) - la->la_valid &= ~LA_CTIME; - RETURN(rc); - } + /* This is only for set ctime when rename's source is + * on remote MDS. */ + rc = mdd_may_delete(env, NULL, NULL, obj, oattr, NULL, + 1, 0); + if (rc == 0 && la->la_ctime <= oattr->la_ctime) + la->la_valid &= ~LA_CTIME; + RETURN(rc); + } - if (la->la_valid == LA_ATIME) { - /* This is atime only set for read atime update on close. */ - if (la->la_atime >= tmp_la->la_atime && - la->la_atime < (tmp_la->la_atime + - mdd_obj2mdd_dev(obj)->mdd_atime_diff)) - la->la_valid &= ~LA_ATIME; - RETURN(0); - } + if (la->la_valid == LA_ATIME) { + /* This is atime only set for read atime update on close. */ + if (la->la_atime >= oattr->la_atime && + la->la_atime < (oattr->la_atime + + mdd_obj2mdd_dev(obj)->mdd_atime_diff)) + la->la_valid &= ~LA_ATIME; + RETURN(0); + } - /* Check if flags change. */ - if (la->la_valid & LA_FLAGS) { - unsigned int oldflags = 0; - unsigned int newflags = la->la_flags & - (LUSTRE_IMMUTABLE_FL | LUSTRE_APPEND_FL); + /* Check if flags change. */ + if (la->la_valid & LA_FLAGS) { + unsigned int oldflags = 0; + unsigned int newflags = la->la_flags & + (LUSTRE_IMMUTABLE_FL | LUSTRE_APPEND_FL); - if ((uc->uc_fsuid != tmp_la->la_uid) && + if ((uc->uc_fsuid != oattr->la_uid) && !md_capable(uc, CFS_CAP_FOWNER)) RETURN(-EPERM); @@ -517,159 +495,159 @@ static int mdd_fix_attr(const struct lu_env *env, struct mdd_object *obj, !md_capable(uc, CFS_CAP_LINUX_IMMUTABLE)) RETURN(-EPERM); - if (!S_ISDIR(tmp_la->la_mode)) - la->la_flags &= ~LUSTRE_DIRSYNC_FL; - } + if (!S_ISDIR(oattr->la_mode)) + la->la_flags &= ~LUSTRE_DIRSYNC_FL; + } - if ((mdd_is_immutable(obj) || mdd_is_append(obj)) && - (la->la_valid & ~LA_FLAGS) && + if ((mdd_is_immutable(obj) || mdd_is_append(obj)) && + (la->la_valid & ~LA_FLAGS) && !(flags & MDS_PERM_BYPASS)) - RETURN(-EPERM); + RETURN(-EPERM); /* Check for setting the obj time. */ if ((la->la_valid & (LA_MTIME | LA_ATIME | LA_CTIME)) && !(la->la_valid & ~(LA_MTIME | LA_ATIME | LA_CTIME))) { - if ((uc->uc_fsuid != tmp_la->la_uid) && + if ((uc->uc_fsuid != oattr->la_uid) && !md_capable(uc, CFS_CAP_FOWNER)) { - rc = mdd_permission_internal(env, obj, tmp_la, + rc = mdd_permission_internal(env, obj, oattr, MAY_WRITE); if (rc) RETURN(rc); } } - if (la->la_valid & LA_KILL_SUID) { - la->la_valid &= ~LA_KILL_SUID; - if ((tmp_la->la_mode & S_ISUID) && - !(la->la_valid & LA_MODE)) { - la->la_mode = tmp_la->la_mode; - la->la_valid |= LA_MODE; - } - la->la_mode &= ~S_ISUID; - } + if (la->la_valid & LA_KILL_SUID) { + la->la_valid &= ~LA_KILL_SUID; + if ((oattr->la_mode & S_ISUID) && + !(la->la_valid & LA_MODE)) { + la->la_mode = oattr->la_mode; + la->la_valid |= LA_MODE; + } + la->la_mode &= ~S_ISUID; + } - if (la->la_valid & LA_KILL_SGID) { - la->la_valid &= ~LA_KILL_SGID; - if (((tmp_la->la_mode & (S_ISGID | S_IXGRP)) == - (S_ISGID | S_IXGRP)) && - !(la->la_valid & LA_MODE)) { - la->la_mode = tmp_la->la_mode; - la->la_valid |= LA_MODE; - } - la->la_mode &= ~S_ISGID; - } + if (la->la_valid & LA_KILL_SGID) { + la->la_valid &= ~LA_KILL_SGID; + if (((oattr->la_mode & (S_ISGID | S_IXGRP)) == + (S_ISGID | S_IXGRP)) && + !(la->la_valid & LA_MODE)) { + la->la_mode = oattr->la_mode; + la->la_valid |= LA_MODE; + } + la->la_mode &= ~S_ISGID; + } - /* Make sure a caller can chmod. */ - if (la->la_valid & LA_MODE) { + /* Make sure a caller can chmod. */ + if (la->la_valid & LA_MODE) { if (!(flags & MDS_PERM_BYPASS) && - (uc->uc_fsuid != tmp_la->la_uid) && + (uc->uc_fsuid != oattr->la_uid) && !md_capable(uc, CFS_CAP_FOWNER)) RETURN(-EPERM); if (la->la_mode == (umode_t) -1) - la->la_mode = tmp_la->la_mode; + la->la_mode = oattr->la_mode; else la->la_mode = (la->la_mode & S_IALLUGO) | - (tmp_la->la_mode & ~S_IALLUGO); + (oattr->la_mode & ~S_IALLUGO); /* Also check the setgid bit! */ if (!lustre_in_group_p(uc, (la->la_valid & LA_GID) ? - la->la_gid : tmp_la->la_gid) && + la->la_gid : oattr->la_gid) && !md_capable(uc, CFS_CAP_FSETID)) la->la_mode &= ~S_ISGID; } else { - la->la_mode = tmp_la->la_mode; + la->la_mode = oattr->la_mode; } - /* Make sure a caller can chown. */ - if (la->la_valid & LA_UID) { - if (la->la_uid == (uid_t) -1) - la->la_uid = tmp_la->la_uid; - if (((uc->uc_fsuid != tmp_la->la_uid) || - (la->la_uid != tmp_la->la_uid)) && + /* Make sure a caller can chown. */ + if (la->la_valid & LA_UID) { + if (la->la_uid == (uid_t) -1) + la->la_uid = oattr->la_uid; + if (((uc->uc_fsuid != oattr->la_uid) || + (la->la_uid != oattr->la_uid)) && !md_capable(uc, CFS_CAP_CHOWN)) RETURN(-EPERM); - /* If the user or group of a non-directory has been - * changed by a non-root user, remove the setuid bit. - * 19981026 David C Niemi - * - * Changed this to apply to all users, including root, - * to avoid some races. This is the behavior we had in - * 2.0. The check for non-root was definitely wrong - * for 2.2 anyway, as it should have been using - * CAP_FSETID rather than fsuid -- 19990830 SD. */ - if (((tmp_la->la_mode & S_ISUID) == S_ISUID) && - !S_ISDIR(tmp_la->la_mode)) { - la->la_mode &= ~S_ISUID; - la->la_valid |= LA_MODE; - } - } + /* If the user or group of a non-directory has been + * changed by a non-root user, remove the setuid bit. + * 19981026 David C Niemi + * + * Changed this to apply to all users, including root, + * to avoid some races. This is the behavior we had in + * 2.0. The check for non-root was definitely wrong + * for 2.2 anyway, as it should have been using + * CAP_FSETID rather than fsuid -- 19990830 SD. */ + if (((oattr->la_mode & S_ISUID) == S_ISUID) && + !S_ISDIR(oattr->la_mode)) { + la->la_mode &= ~S_ISUID; + la->la_valid |= LA_MODE; + } + } - /* Make sure caller can chgrp. */ - if (la->la_valid & LA_GID) { - if (la->la_gid == (gid_t) -1) - la->la_gid = tmp_la->la_gid; - if (((uc->uc_fsuid != tmp_la->la_uid) || - ((la->la_gid != tmp_la->la_gid) && + /* Make sure caller can chgrp. */ + if (la->la_valid & LA_GID) { + if (la->la_gid == (gid_t) -1) + la->la_gid = oattr->la_gid; + if (((uc->uc_fsuid != oattr->la_uid) || + ((la->la_gid != oattr->la_gid) && !lustre_in_group_p(uc, la->la_gid))) && !md_capable(uc, CFS_CAP_CHOWN)) RETURN(-EPERM); - /* Likewise, if the user or group of a non-directory - * has been changed by a non-root user, remove the - * setgid bit UNLESS there is no group execute bit - * (this would be a file marked for mandatory - * locking). 19981026 David C Niemi - * - * Removed the fsuid check (see the comment above) -- - * 19990830 SD. */ - if (((tmp_la->la_mode & (S_ISGID | S_IXGRP)) == - (S_ISGID | S_IXGRP)) && !S_ISDIR(tmp_la->la_mode)) { - la->la_mode &= ~S_ISGID; - la->la_valid |= LA_MODE; - } - } + /* Likewise, if the user or group of a non-directory + * has been changed by a non-root user, remove the + * setgid bit UNLESS there is no group execute bit + * (this would be a file marked for mandatory + * locking). 19981026 David C Niemi + * + * Removed the fsuid check (see the comment above) -- + * 19990830 SD. */ + if (((oattr->la_mode & (S_ISGID | S_IXGRP)) == + (S_ISGID | S_IXGRP)) && !S_ISDIR(oattr->la_mode)) { + la->la_mode &= ~S_ISGID; + la->la_valid |= LA_MODE; + } + } - /* For both Size-on-MDS case and truncate case, - * "la->la_valid & (LA_SIZE | LA_BLOCKS)" are ture. + /* For both Size-on-MDS case and truncate case, + * "la->la_valid & (LA_SIZE | LA_BLOCKS)" are ture. * We distinguish them by "flags & MDS_SOM". - * For SOM case, it is true, the MAY_WRITE perm has been checked - * when open, no need check again. For truncate case, it is false, - * the MAY_WRITE perm should be checked here. */ + * For SOM case, it is true, the MAY_WRITE perm has been checked + * when open, no need check again. For truncate case, it is false, + * the MAY_WRITE perm should be checked here. */ if (flags & MDS_SOM) { - /* For the "Size-on-MDS" setattr update, merge coming - * attributes with the set in the inode. BUG 10641 */ - if ((la->la_valid & LA_ATIME) && - (la->la_atime <= tmp_la->la_atime)) - la->la_valid &= ~LA_ATIME; - - /* OST attributes do not have a priority over MDS attributes, - * so drop times if ctime is equal. */ - if ((la->la_valid & LA_CTIME) && - (la->la_ctime <= tmp_la->la_ctime)) - la->la_valid &= ~(LA_MTIME | LA_CTIME); - } else { - if (la->la_valid & (LA_SIZE | LA_BLOCKS)) { + /* For the "Size-on-MDS" setattr update, merge coming + * attributes with the set in the inode. BUG 10641 */ + if ((la->la_valid & LA_ATIME) && + (la->la_atime <= oattr->la_atime)) + la->la_valid &= ~LA_ATIME; + + /* OST attributes do not have a priority over MDS attributes, + * so drop times if ctime is equal. */ + if ((la->la_valid & LA_CTIME) && + (la->la_ctime <= oattr->la_ctime)) + la->la_valid &= ~(LA_MTIME | LA_CTIME); + } else { + if (la->la_valid & (LA_SIZE | LA_BLOCKS)) { if (!((flags & MDS_OWNEROVERRIDE) && - (uc->uc_fsuid == tmp_la->la_uid)) && + (uc->uc_fsuid == oattr->la_uid)) && !(flags & MDS_PERM_BYPASS)) { rc = mdd_permission_internal(env, obj, - tmp_la, MAY_WRITE); + oattr, MAY_WRITE); if (rc != 0) RETURN(rc); } - } - if (la->la_valid & LA_CTIME) { - /* The pure setattr, it has the priority over what is - * already set, do not drop it if ctime is equal. */ - if (la->la_ctime < tmp_la->la_ctime) - la->la_valid &= ~(LA_ATIME | LA_MTIME | - LA_CTIME); - } - } + } + if (la->la_valid & LA_CTIME) { + /* The pure setattr, it has the priority over what is + * already set, do not drop it if ctime is equal. */ + if (la->la_ctime < oattr->la_ctime) + la->la_valid &= ~(LA_ATIME | LA_MTIME | + LA_CTIME); + } + } - RETURN(0); + RETURN(0); } /** Store a data change changelog record @@ -829,35 +807,63 @@ static int mdd_declare_attr_set(const struct lu_env *env, return rc; } -static inline bool permission_is_reduced(const struct lu_attr *old, +/* + * LU-3671 + * + * permission changes may require sync operation, to mitigate performance + * impact, only do this for dir and when permission is reduced. + * + * For regular files, version is updated with permission change (see VBR), async + * permission won't cause any issue, while missing permission change on + * directory may affect accessibility of other objects after recovery. + */ +static inline bool permission_needs_sync(const struct lu_attr *old, const struct lu_attr *new) { - return ((new->la_mode & old->la_mode) & S_IRWXUGO) != - (old->la_mode & S_IRWXUGO); + if (!S_ISDIR(old->la_mode)) + return false; + + if (new->la_valid & (LA_UID | LA_GID)) + return true; + + if (new->la_valid & LA_MODE && + new->la_mode & (S_ISUID | S_ISGID | S_ISVTX)) + return true; + + if ((new->la_valid & LA_MODE) && + ((new->la_mode & old->la_mode) & S_IRWXUGO) != + (old->la_mode & S_IRWXUGO)) + return true; + + return false; } /* set attr and LOV EA at once, return updated attr */ int mdd_attr_set(const struct lu_env *env, struct md_object *obj, const struct md_attr *ma) { - struct mdd_object *mdd_obj = md2mdd_obj(obj); - struct mdd_device *mdd = mdo2mdd(obj); - struct thandle *handle; - struct lu_attr *la_copy = &mdd_env_info(env)->mti_la_for_fix; + struct mdd_object *mdd_obj = md2mdd_obj(obj); + struct mdd_device *mdd = mdo2mdd(obj); + struct thandle *handle; + struct lu_attr *la_copy = &mdd_env_info(env)->mti_la_for_fix; + struct lu_attr *attr = MDD_ENV_VAR(env, cattr); const struct lu_attr *la = &ma->ma_attr; - bool sync_perm = false; int rc; - ENTRY; + ENTRY; /* we do not use ->attr_set() for LOV/SOM/HSM EA any more */ LASSERT((ma->ma_valid & MA_LOV) == 0); LASSERT((ma->ma_valid & MA_HSM) == 0); LASSERT((ma->ma_valid & MA_SOM) == 0); - *la_copy = ma->ma_attr; - rc = mdd_fix_attr(env, mdd_obj, la_copy, ma->ma_attr_flags); + rc = mdd_la_get(env, mdd_obj, attr, BYPASS_CAPA); if (rc) - RETURN(rc); + RETURN(rc); + + *la_copy = ma->ma_attr; + rc = mdd_fix_attr(env, mdd_obj, attr, la_copy, ma->ma_attr_flags); + if (rc) + RETURN(rc); /* setattr on "close" only change atime, or do nothing */ if (la->la_valid == LA_ATIME && la_copy->la_valid == 0) @@ -875,38 +881,8 @@ int mdd_attr_set(const struct lu_env *env, struct md_object *obj, if (rc) GOTO(stop, rc); - /* - * LU-3671 - * - * permission changes may require sync operation, to mitigate - * performance impact, only do this for dir and when permission is - * reduced. - * - * For regular files, version is updated with permission change - * (see VBR), async permission won't cause any issue, while missing - * permission change on directory may affect accessibility of other - * objects. - */ - if (S_ISDIR(mdd_object_type(mdd_obj))) { - if (la->la_valid & (LA_UID | LA_GID)) { - sync_perm = true; - } else if (la->la_valid & LA_MODE && - la->la_mode & (S_ISUID | S_ISGID | S_ISVTX)) { - sync_perm = true; - } else if (la->la_valid & LA_MODE) { - struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la; - - rc = mdd_la_get(env, mdd_obj, tmp_la, BYPASS_CAPA); - if (rc) - GOTO(stop, rc); - - if (permission_is_reduced(tmp_la, la)) - sync_perm = true; - } - } - - if (sync_perm) - handle->th_sync |= !!mdd->mdd_sync_permission; + if (mdd->mdd_sync_permission && permission_needs_sync(attr, la)) + handle->th_sync = 1; if (la->la_valid & (LA_MTIME | LA_CTIME)) CDEBUG(D_INODE, "setting mtime "LPU64", ctime "LPU64"\n", @@ -929,25 +905,19 @@ stop: } static int mdd_xattr_sanity_check(const struct lu_env *env, - struct mdd_object *obj) + struct mdd_object *obj, + const struct lu_attr *attr) { - struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la; struct lu_ucred *uc = lu_ucred_assert(env); - int rc; ENTRY; if (mdd_is_immutable(obj) || mdd_is_append(obj)) RETURN(-EPERM); - rc = mdd_la_get(env, obj, tmp_la, BYPASS_CAPA); - if (rc) - RETURN(rc); - - if ((uc->uc_fsuid != tmp_la->la_uid) && - !md_capable(uc, CFS_CAP_FOWNER)) + if ((uc->uc_fsuid != attr->la_uid) && !md_capable(uc, CFS_CAP_FOWNER)) RETURN(-EPERM); - RETURN(rc); + RETURN(0); } static int mdd_declare_xattr_set(const struct lu_env *env, @@ -1056,17 +1026,22 @@ static int mdd_xattr_set(const struct lu_env *env, struct md_object *obj, int fl) { struct mdd_object *mdd_obj = md2mdd_obj(obj); + struct lu_attr *attr = MDD_ENV_VAR(env, cattr); struct mdd_device *mdd = mdo2mdd(obj); struct thandle *handle; int rc; - ENTRY; + ENTRY; + + rc = mdd_la_get(env, mdd_obj, attr, BYPASS_CAPA); + if (rc) + RETURN(rc); if (!strcmp(name, XATTR_NAME_ACL_ACCESS)) { - rc = mdd_acl_set(env, mdd_obj, buf, fl); + rc = mdd_acl_set(env, mdd_obj, attr, buf, fl); RETURN(rc); } - rc = mdd_xattr_sanity_check(env, mdd_obj); + rc = mdd_xattr_sanity_check(env, mdd_obj, attr); if (rc) RETURN(rc); @@ -1142,15 +1117,20 @@ static int mdd_declare_xattr_del(const struct lu_env *env, int mdd_xattr_del(const struct lu_env *env, struct md_object *obj, const char *name) { - struct mdd_object *mdd_obj = md2mdd_obj(obj); - struct mdd_device *mdd = mdo2mdd(obj); - struct thandle *handle; - int rc; - ENTRY; + struct mdd_object *mdd_obj = md2mdd_obj(obj); + struct lu_attr *attr = MDD_ENV_VAR(env, cattr); + struct mdd_device *mdd = mdo2mdd(obj); + struct thandle *handle; + int rc; + ENTRY; - rc = mdd_xattr_sanity_check(env, mdd_obj); - if (rc) - RETURN(rc); + rc = mdd_la_get(env, mdd_obj, attr, BYPASS_CAPA); + if (rc) + RETURN(rc); + + rc = mdd_xattr_sanity_check(env, mdd_obj, attr); + if (rc) + RETURN(rc); handle = mdd_trans_create(env, mdd); if (IS_ERR(handle)) @@ -1279,12 +1259,11 @@ static int mdd_xattr_hsm_replace(const struct lu_env *env, */ static int mdd_layout_swap_allowed(const struct lu_env *env, struct mdd_object *o1, - struct mdd_object *o2) + const struct lu_attr *attr1, + struct mdd_object *o2, + const struct lu_attr *attr2) { const struct lu_fid *fid1, *fid2; - __u32 uid, gid; - struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la; - int rc; ENTRY; fid1 = mdo2fid(o1); @@ -1294,19 +1273,8 @@ static int mdd_layout_swap_allowed(const struct lu_env *env, (mdd_object_type(o1) != mdd_object_type(o2))) RETURN(-EPERM); - tmp_la->la_valid = 0; - rc = mdd_la_get(env, o1, tmp_la, BYPASS_CAPA); - if (rc) - RETURN(rc); - uid = tmp_la->la_uid; - gid = tmp_la->la_gid; - - tmp_la->la_valid = 0; - rc = mdd_la_get(env, o2, tmp_la, BYPASS_CAPA); - if (rc) - RETURN(rc); - - if ((uid != tmp_la->la_uid) || (gid != tmp_la->la_gid)) + if ((attr1->la_uid != attr2->la_uid) || + (attr1->la_gid != attr2->la_gid)) RETURN(-EPERM); RETURN(0); @@ -1321,6 +1289,8 @@ static int mdd_swap_layouts(const struct lu_env *env, struct md_object *obj1, struct mdd_thread_info *info = mdd_env_info(env); struct mdd_object *fst_o = md2mdd_obj(obj1); struct mdd_object *snd_o = md2mdd_obj(obj2); + struct lu_attr *fst_la = MDD_ENV_VAR(env, cattr); + struct lu_attr *snd_la = MDD_ENV_VAR(env, tattr); struct mdd_device *mdd = mdo2mdd(obj1); struct lov_mds_md *fst_lmm, *snd_lmm; struct lu_buf *fst_buf = &info->mti_buf[0]; @@ -1347,8 +1317,16 @@ static int mdd_swap_layouts(const struct lu_env *env, struct md_object *obj1, if (rc < 0) swap(fst_o, snd_o); + rc = mdd_la_get(env, fst_o, fst_la, BYPASS_CAPA); + if (rc != 0) + RETURN(rc); + + rc = mdd_la_get(env, snd_o, snd_la, BYPASS_CAPA); + if (rc != 0) + RETURN(rc); + /* check if layout swapping is allowed */ - rc = mdd_layout_swap_allowed(env, fst_o, snd_o); + rc = mdd_layout_swap_allowed(env, fst_o, fst_la, snd_o, snd_la); if (rc != 0) RETURN(rc); @@ -1576,7 +1554,7 @@ void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent, /* * do NOT or the MAY_*'s, you'll get the weakest */ -int accmode(const struct lu_env *env, struct lu_attr *la, int flags) +int accmode(const struct lu_env *env, const struct lu_attr *la, int flags) { int res = 0; @@ -1602,45 +1580,41 @@ int accmode(const struct lu_env *env, struct lu_attr *la, int flags) } static int mdd_open_sanity_check(const struct lu_env *env, - struct mdd_object *obj, int flag) + struct mdd_object *obj, + const struct lu_attr *attr, int flag) { - struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la; - int mode, rc; - ENTRY; - - /* EEXIST check */ - if (mdd_is_dead_obj(obj)) - RETURN(-ENOENT); + int mode, rc; + ENTRY; - rc = mdd_la_get(env, obj, tmp_la, BYPASS_CAPA); - if (rc) - RETURN(rc); + /* EEXIST check */ + if (mdd_is_dead_obj(obj)) + RETURN(-ENOENT); - if (S_ISLNK(tmp_la->la_mode)) - RETURN(-ELOOP); + if (S_ISLNK(attr->la_mode)) + RETURN(-ELOOP); - mode = accmode(env, tmp_la, flag); + mode = accmode(env, attr, flag); - if (S_ISDIR(tmp_la->la_mode) && (mode & MAY_WRITE)) - RETURN(-EISDIR); + if (S_ISDIR(attr->la_mode) && (mode & MAY_WRITE)) + RETURN(-EISDIR); - if (!(flag & MDS_OPEN_CREATED)) { - rc = mdd_permission_internal(env, obj, tmp_la, mode); - if (rc) - RETURN(rc); - } + if (!(flag & MDS_OPEN_CREATED)) { + rc = mdd_permission_internal(env, obj, attr, mode); + if (rc) + RETURN(rc); + } - if (S_ISFIFO(tmp_la->la_mode) || S_ISSOCK(tmp_la->la_mode) || - S_ISBLK(tmp_la->la_mode) || S_ISCHR(tmp_la->la_mode)) - flag &= ~MDS_OPEN_TRUNC; + if (S_ISFIFO(attr->la_mode) || S_ISSOCK(attr->la_mode) || + S_ISBLK(attr->la_mode) || S_ISCHR(attr->la_mode)) + flag &= ~MDS_OPEN_TRUNC; - /* For writing append-only file must open it with append mode. */ - if (mdd_is_append(obj)) { - if ((flag & FMODE_WRITE) && !(flag & MDS_OPEN_APPEND)) - RETURN(-EPERM); - if (flag & MDS_OPEN_TRUNC) - RETURN(-EPERM); - } + /* For writing append-only file must open it with append mode. */ + if (mdd_is_append(obj)) { + if ((flag & FMODE_WRITE) && !(flag & MDS_OPEN_APPEND)) + RETURN(-EPERM); + if (flag & MDS_OPEN_TRUNC) + RETURN(-EPERM); + } #if 0 /* @@ -1651,29 +1625,34 @@ static int mdd_open_sanity_check(const struct lu_env *env, if (uc && ((uc->uc_valid == UCRED_OLD) || (uc->uc_valid == UCRED_NEW)) && - (uc->uc_fsuid != tmp_la->la_uid) && + (uc->uc_fsuid != attr->la_uid) && !md_capable(uc, CFS_CAP_FOWNER)) RETURN(-EPERM); } #endif - RETURN(0); + RETURN(0); } static int mdd_open(const struct lu_env *env, struct md_object *obj, - int flags) + int flags) { - struct mdd_object *mdd_obj = md2mdd_obj(obj); - int rc = 0; + struct mdd_object *mdd_obj = md2mdd_obj(obj); + struct lu_attr *attr = MDD_ENV_VAR(env, cattr); + int rc = 0; - mdd_write_lock(env, mdd_obj, MOR_TGT_CHILD); + mdd_write_lock(env, mdd_obj, MOR_TGT_CHILD); - rc = mdd_open_sanity_check(env, mdd_obj, flags); - if (rc == 0) - mdd_obj->mod_count++; + rc = mdd_la_get(env, mdd_obj, attr, BYPASS_CAPA); + if (rc) + RETURN(rc); - mdd_write_unlock(env, mdd_obj); - return rc; + rc = mdd_open_sanity_check(env, mdd_obj, attr, flags); + if (rc == 0) + mdd_obj->mod_count++; + + mdd_write_unlock(env, mdd_obj); + return rc; } int mdd_declare_object_kill(const struct lu_env *env, struct mdd_object *obj, diff --git a/lustre/mdd/mdd_permission.c b/lustre/mdd/mdd_permission.c index f52d617..da184e8 100644 --- a/lustre/mdd/mdd_permission.c +++ b/lustre/mdd/mdd_permission.c @@ -93,10 +93,9 @@ int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode, } int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj, - const struct lu_buf *buf, int fl) + struct lu_attr *la, const struct lu_buf *buf, int fl) { struct mdd_device *mdd = mdd_obj2mdd_dev(obj); - struct lu_attr *la = &mdd_env_info(env)->mti_la; struct thandle *handle; posix_acl_xattr_header *head; posix_acl_xattr_entry *entry; @@ -105,10 +104,6 @@ int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj, mode_t mode; ENTRY; - rc = mdd_la_get(env, obj, la, BYPASS_CAPA); - if (rc) - RETURN(rc); - head = (posix_acl_xattr_header *)(buf->lb_buf); entry = head->a_entries; entry_count = (buf->lb_len - sizeof(head->a_version)) / @@ -208,7 +203,7 @@ int __mdd_fix_mode_acl(const struct lu_env *env, struct lu_buf *buf, * Hold read_lock for obj. */ static int mdd_check_acl(const struct lu_env *env, struct mdd_object *obj, - struct lu_attr *la, int mask) + const struct lu_attr *la, int mask) { #ifdef CONFIG_FS_POSIX_ACL struct lu_ucred *uc = lu_ucred_assert(env); @@ -241,7 +236,7 @@ static int mdd_check_acl(const struct lu_env *env, struct mdd_object *obj, } int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj, - struct lu_attr *la, int mask, int role) + const struct lu_attr *la, int mask, int role) { struct lu_ucred *uc = lu_ucred(env); __u32 mode; @@ -265,12 +260,7 @@ int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj, if ((mask & MAY_WRITE) && mdd_is_immutable(obj)) RETURN(-EACCES); - if (la == NULL) { - la = &mdd_env_info(env)->mti_la; - rc = mdd_la_get(env, obj, la, BYPASS_CAPA); - if (rc) - RETURN(rc); - } + LASSERT(la != NULL); mode = la->la_mode; if (uc->uc_fsuid == la->la_uid) { @@ -313,29 +303,38 @@ int mdd_permission(const struct lu_env *env, struct md_object *pobj, struct md_object *cobj, struct md_attr *ma, int mask) { - struct mdd_object *mdd_pobj, *mdd_cobj; + struct mdd_object *mdd_pobj = NULL; + struct mdd_object *mdd_cobj; struct lu_ucred *uc = NULL; - struct lu_attr *la = &mdd_env_info(env)->mti_cattr; - int check_create, check_link; - int check_unlink; - int check_rename_src, check_rename_tar; - int check_vtx_part, check_vtx_full; - int check_rgetfacl; - int rc = 0; - ENTRY; + struct lu_attr *pattr = NULL; + struct lu_attr *cattr = MDD_ENV_VAR(env, cattr); + int check_create, check_link; + int check_unlink; + int check_rename_src, check_rename_tar; + int check_vtx_part, check_vtx_full; + int check_rgetfacl; + int rc = 0; + ENTRY; - LASSERT(cobj); - mdd_cobj = md2mdd_obj(cobj); + LASSERT(cobj); + if (pobj != NULL) { + mdd_pobj = md2mdd_obj(pobj); + pattr = MDD_ENV_VAR(env, pattr); + rc = mdd_la_get(env, mdd_pobj, pattr, BYPASS_CAPA); + if (rc) + RETURN(rc); + } - rc = mdd_la_get(env, mdd_cobj, la, BYPASS_CAPA); + mdd_cobj = md2mdd_obj(cobj); + rc = mdd_la_get(env, mdd_cobj, cattr, BYPASS_CAPA); if (rc) RETURN(rc); - /* For cross_open case, the "mask" is open flags, - * so convert it to permission mask first. - * XXX: MDS_OPEN_CROSS must be NOT equal to permission mask MAY_*. */ + /* For cross_open case, the "mask" is open flags, + * so convert it to permission mask first. + * XXX: MDS_OPEN_CROSS must be NOT equal to permission mask MAY_*. */ if (unlikely(mask & MDS_OPEN_CROSS)) - mask = accmode(env, la, mask & ~MDS_OPEN_CROSS); + mask = accmode(env, cattr, mask & ~MDS_OPEN_CROSS); check_create = mask & MAY_CREATE; check_link = mask & MAY_LINK; @@ -352,32 +351,25 @@ int mdd_permission(const struct lu_env *env, MAY_VTX_PART | MAY_VTX_FULL | MAY_RGETFACL); - rc = mdd_permission_internal_locked(env, mdd_cobj, NULL, mask, - MOR_TGT_CHILD); + rc = mdd_permission_internal_locked(env, mdd_cobj, cattr, mask, + MOR_TGT_CHILD); - if (!rc && (check_create || check_link)) - rc = mdd_may_create(env, mdd_cobj, NULL, 1, check_link); + if (!rc && (check_create || check_link)) + rc = mdd_may_create(env, mdd_pobj, pattr, mdd_cobj, 1, + check_link); if (!rc && check_unlink) - rc = mdd_may_unlink(env, mdd_cobj, la); + rc = mdd_may_unlink(env, mdd_pobj, pattr, cattr); - if (!rc && (check_rename_src || check_rename_tar)) { - LASSERT(pobj); - mdd_pobj = md2mdd_obj(pobj); - rc = mdd_may_delete(env, mdd_pobj, mdd_cobj, la, NULL, 1, - check_rename_tar); - } + if (!rc && (check_rename_src || check_rename_tar)) + rc = mdd_may_delete(env, mdd_pobj, pattr, mdd_cobj, cattr, NULL, + 1, check_rename_tar); if (!rc && (check_vtx_part || check_vtx_full)) { uc = lu_ucred_assert(env); - if (likely(!la)) { - la = &mdd_env_info(env)->mti_la; - rc = mdd_la_get(env, mdd_cobj, la, BYPASS_CAPA); - if (rc) - RETURN(rc); - } - if (!(la->la_mode & S_ISVTX) || (la->la_uid == uc->uc_fsuid) || + if (!(cattr->la_mode & S_ISVTX) || + (cattr->la_uid == uc->uc_fsuid) || (check_vtx_full && (ma->ma_attr.la_valid & LA_UID) && (ma->ma_attr.la_uid == uc->uc_fsuid))) { ma->ma_attr_flags |= MDS_VTX_BYPASS; @@ -392,7 +384,7 @@ int mdd_permission(const struct lu_env *env, if (likely(!uc)) uc = lu_ucred_assert(env); - if (la->la_uid != uc->uc_fsuid && + if (cattr->la_uid != uc->uc_fsuid && !md_capable(uc, CFS_CAP_FOWNER)) rc = -EPERM; } diff --git a/lustre/obdclass/acl.c b/lustre/obdclass/acl.c index b16289c..e7b986c 100644 --- a/lustre/obdclass/acl.c +++ b/lustre/obdclass/acl.c @@ -100,7 +100,7 @@ static inline void lustre_posix_acl_cpu_to_le(posix_acl_xattr_entry *d, /* * Check permission based on POSIX ACL. */ -int lustre_posix_acl_permission(struct lu_ucred *mu, struct lu_attr *la, +int lustre_posix_acl_permission(struct lu_ucred *mu, const struct lu_attr *la, int want, posix_acl_xattr_entry *entry, int count) {