From e8bafb17ed102626adc6ae0806279f95c8cdd2b3 Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Thu, 1 Mar 2018 10:02:09 -0600 Subject: [PATCH] LU-10750 mdd: declare changelogs only when enabled In the mdd layer, rename recording_changelog() to mdd_changelog_enabled() and add the changelog record type as a parameter. In mdd_changelog_enabled() test to see if the type is enabled in addition to checking is changelogs are generally enabled and only lookup the ucred if the other tests pass. Add a type parameter to mdd_declare_changelog_store() so that this information can be passed to mdd_declare_changelog_store(). In mdd_close() check if CLOSE changelogs are enabled before opening a transaction and declaring the record. Signed-off-by: John L. Hammond Change-Id: Idd7604de5e97bad72a802cb4b49dae4668b2644a Reviewed-on: https://review.whamcloud.com/31477 Tested-by: Jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Sebastien Buisson Reviewed-by: Quentin Bouget --- lustre/mdd/mdd_dir.c | 33 +++++++++++------- lustre/mdd/mdd_internal.h | 26 +++++++++----- lustre/mdd/mdd_object.c | 87 +++++++++++++++++++++++------------------------ 3 files changed, 79 insertions(+), 67 deletions(-) diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index 74988ec..acf1bd2 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -754,6 +754,7 @@ static int mdd_llog_record_calc_size(const struct lu_env *env, int mdd_declare_changelog_store(const struct lu_env *env, struct mdd_device *mdd, + enum changelog_rec_type type, const struct lu_name *tname, const struct lu_name *sname, struct thandle *handle) @@ -766,8 +767,7 @@ int mdd_declare_changelog_store(const struct lu_env *env, int reclen; int rc; - /* Not recording */ - if (!recording_changelog(env, mdd)) + if (!mdd_changelog_enabled(env, mdd, type)) return 0; reclen = mdd_llog_record_calc_size(env, tname, sname); @@ -1108,11 +1108,7 @@ int mdd_changelog_ns_store(const struct lu_env *env, int rc; ENTRY; - /* Not recording */ - if (!recording_changelog(env, mdd)) - RETURN(0); - - if ((mdd->mdd_cl.mc_mask & (1 << type)) == 0) + if (!mdd_changelog_enabled(env, mdd, type)) RETURN(0); LASSERT(tpfid != NULL); @@ -1478,7 +1474,8 @@ static int mdd_declare_link(const struct lu_env *env, if (rc != 0) return rc; - rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle); + rc = mdd_declare_changelog_store(env, mdd, CL_HARDLINK, name, NULL, + handle); return rc; } @@ -1753,7 +1750,8 @@ static int mdd_declare_unlink(const struct lu_env *env, struct mdd_device *mdd, return rc; /* FIXME: need changelog for remove entry */ - rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle); + rc = mdd_declare_changelog_store(env, mdd, CL_UNLINK, name, + NULL, handle); } return rc; @@ -2030,7 +2028,8 @@ static int mdd_create_data(const struct lu_env *env, if (rc) GOTO(stop, rc); - rc = mdd_declare_changelog_store(env, mdd, NULL, NULL, handle); + rc = mdd_declare_changelog_store(env, mdd, CL_LAYOUT, NULL, NULL, + handle); if (rc) GOTO(stop, rc); @@ -2340,6 +2339,7 @@ static int mdd_declare_create(const struct lu_env *env, struct mdd_device *mdd, GOTO(out, rc); } else { struct lu_attr *la = &mdd_env_info(env)->mti_la_for_fix; + enum changelog_rec_type type; rc = mdo_declare_index_insert(env, p, mdo2fid(c), attr->la_mode, name->ln_name, handle); @@ -2356,7 +2356,12 @@ static int mdd_declare_create(const struct lu_env *env, struct mdd_device *mdd, if (rc) return rc; - rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle); + type = S_ISDIR(attr->la_mode) ? CL_MKDIR : + S_ISREG(attr->la_mode) ? CL_CREATE : + S_ISLNK(attr->la_mode) ? CL_SOFTLINK : CL_MKNOD; + + rc = mdd_declare_changelog_store(env, mdd, type, name, NULL, + handle); if (rc) return rc; } @@ -2992,7 +2997,8 @@ static int mdd_declare_rename(const struct lu_env *env, return rc; } - rc = mdd_declare_changelog_store(env, mdd, tname, sname, handle); + rc = mdd_declare_changelog_store(env, mdd, CL_RENAME, tname, sname, + handle); if (rc) return rc; @@ -4163,7 +4169,8 @@ static int mdd_declare_migrate_update_name(const struct lu_env *env, if (rc != 0) return rc; - rc = mdd_declare_changelog_store(env, mdd, lname, NULL, handle); + rc = mdd_declare_changelog_store(env, mdd, CL_MIGRATE, lname, NULL, + handle); return rc; } diff --git a/lustre/mdd/mdd_internal.h b/lustre/mdd/mdd_internal.h index c7519e4..9af66f0 100644 --- a/lustre/mdd/mdd_internal.h +++ b/lustre/mdd/mdd_internal.h @@ -302,10 +302,11 @@ struct mdd_object *mdd_object_find(const struct lu_env *env, int mdd_readpage(const struct lu_env *env, struct md_object *obj, const struct lu_rdpg *rdpg); int mdd_declare_changelog_store(const struct lu_env *env, - struct mdd_device *mdd, - const struct lu_name *tname, - const struct lu_name *sname, - struct thandle *handle); + struct mdd_device *mdd, + enum changelog_rec_type type, + const struct lu_name *tname, + const struct lu_name *sname, + struct thandle *handle); void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid); void mdd_changelog_rec_ext_extra_flags(struct changelog_rec *rec, __u64 eflags); void mdd_changelog_rec_extra_uidgid(struct changelog_rec *rec, @@ -740,13 +741,20 @@ int mdo_destroy(const struct lu_env *env, struct mdd_object *o, return dt_destroy(env, next, handle); } -static inline int recording_changelog(const struct lu_env *env, - struct mdd_device *mdd) +static inline bool mdd_changelog_enabled(const struct lu_env *env, + struct mdd_device *mdd, + enum changelog_rec_type type) { - const struct lu_ucred *uc = lu_ucred_check(env); + const struct lu_ucred *uc; - return (mdd->mdd_cl.mc_flags & CLM_ON) && - (uc ? uc->uc_enable_audit : 1); + if ((mdd->mdd_cl.mc_flags & CLM_ON) && + (mdd->mdd_cl.mc_mask & (1 << type))) { + uc = lu_ucred_check(env); + + return uc != NULL ? uc->uc_enable_audit : true; + } else { + return false; + } } #endif diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index dca2cd5..8f9085c 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -394,7 +394,7 @@ static int mdd_xattr_get(const struct lu_env *env, const char *name) { struct mdd_object *mdd_obj = md2mdd_obj(obj); - struct md_device *md_dev = lu2md_dev(mdd2lu_dev(mdo2mdd(obj))); + struct mdd_device *mdd; int rc; ENTRY; @@ -425,28 +425,25 @@ static int mdd_xattr_get(const struct lu_env *env, rc = mdo_xattr_get(env, mdd_obj, buf, name); mdd_read_unlock(env, mdd_obj); + mdd = mdo2mdd(obj); + /* record only getting user xattrs and acls */ if (rc >= 0 && + mdd_changelog_enabled(env, mdd, CL_GETXATTR) && (has_prefix(name, XATTR_USER_PREFIX) || has_prefix(name, XATTR_NAME_POSIX_ACL_ACCESS) || has_prefix(name, XATTR_NAME_POSIX_ACL_DEFAULT))) { struct thandle *handle; - struct mdd_device *mdd = lu2mdd_dev(&md_dev->md_lu_dev); int rc2; - /* Not recording */ - if (!recording_changelog(env, mdd)) - RETURN(rc); - if (!(mdd->mdd_cl.mc_mask & (1 << CL_GETXATTR))) - RETURN(rc); - LASSERT(mdo2fid(mdd_obj) != NULL); handle = mdd_trans_create(env, mdd); if (IS_ERR(handle)) RETURN(PTR_ERR(handle)); - rc2 = mdd_declare_changelog_store(env, mdd, NULL, NULL, handle); + rc2 = mdd_declare_changelog_store(env, mdd, CL_GETXATTR, NULL, + NULL, handle); if (rc2) GOTO(stop, rc2); @@ -923,10 +920,7 @@ int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd, LASSERT(mdd_obj != NULL); LASSERT(handle != NULL); - /* Not recording */ - if (!recording_changelog(env, mdd)) - RETURN(0); - if ((mdd->mdd_cl.mc_mask & (1 << type)) == 0) + if (!mdd_changelog_enabled(env, mdd, type)) RETURN(0); if (mdd_is_volatile_obj(mdd_obj)) @@ -960,10 +954,7 @@ static int mdd_changelog_data_store_xattr(const struct lu_env *env, LASSERT(mdd_obj != NULL); LASSERT(handle != NULL); - /* Not recording */ - if (!recording_changelog(env, mdd)) - RETURN(0); - if ((mdd->mdd_cl.mc_mask & (1 << type)) == 0) + if (!mdd_changelog_enabled(env, mdd, type)) RETURN(0); if (mdd_is_volatile_obj(mdd_obj)) @@ -995,19 +986,18 @@ static int mdd_changelog(const struct lu_env *env, enum changelog_rec_type type, int rc; ENTRY; - /* Not recording */ - if (!recording_changelog(env, mdd)) - RETURN(0); - if (!(mdd->mdd_cl.mc_mask & (1 << type))) - RETURN(0); - LASSERT(fid != NULL); + /* We'll check this again below, but we check now before we + * start a transaction. */ + if (!mdd_changelog_enabled(env, mdd, type)) + RETURN(0); + handle = mdd_trans_create(env, mdd); if (IS_ERR(handle)) RETURN(PTR_ERR(handle)); - rc = mdd_declare_changelog_store(env, mdd, NULL, NULL, handle); + rc = mdd_declare_changelog_store(env, mdd, type, NULL, NULL, handle); if (rc) GOTO(stop, rc); @@ -1095,7 +1085,8 @@ static int mdd_declare_attr_set(const struct lu_env *env, } #endif - rc = mdd_declare_changelog_store(env, mdd, NULL, NULL, handle); + rc = mdd_declare_changelog_store(env, mdd, CL_SETXATTR, NULL, NULL, + handle); return rc; } @@ -1308,16 +1299,18 @@ static int mdd_declare_xattr_set(const struct lu_env *env, const char *name, int fl, struct thandle *handle) { - int rc; + enum changelog_rec_type type; + int rc; rc = mdo_declare_xattr_set(env, obj, buf, name, fl, handle); if (rc) return rc; - if (mdd_xattr_changelog_type(env, mdd, name) < 0) + type = mdd_xattr_changelog_type(env, mdd, name); + if (type < 0) return 0; /* no changelog to store */ - return mdd_declare_changelog_store(env, mdd, NULL, NULL, handle); + return mdd_declare_changelog_store(env, mdd, type, NULL, NULL, handle); } /* @@ -1880,16 +1873,18 @@ static int mdd_declare_xattr_del(const struct lu_env *env, const char *name, struct thandle *handle) { + enum changelog_rec_type type; int rc; rc = mdo_declare_xattr_del(env, obj, name, handle); if (rc) return rc; - if (mdd_xattr_changelog_type(env, mdd, name) < 0) + type = mdd_xattr_changelog_type(env, mdd, name); + if (type < 0) return 0; /* no changelog to store */ - return mdd_declare_changelog_store(env, mdd, NULL, NULL, handle); + return mdd_declare_changelog_store(env, mdd, type, NULL, NULL, handle); } /** @@ -2451,7 +2446,8 @@ static int mdd_declare_layout_change(const struct lu_env *env, if (rc) return rc; - return mdd_declare_changelog_store(env, mdd, NULL, NULL, handle); + return mdd_declare_changelog_store(env, mdd, CL_LAYOUT, NULL, NULL, + handle); } /* For PFL, this is used to instantiate necessary component objects. */ @@ -2528,7 +2524,7 @@ mdd_layout_update_rdonly(const struct lu_env *env, struct mdd_object *obj, GOTO(out, rc); /* record a changelog for data mover to consume */ - rc = mdd_declare_changelog_store(env, mdd, NULL, NULL, handle); + rc = mdd_declare_changelog_store(env, mdd, CL_FLRW, NULL, NULL, handle); if (rc) GOTO(out, rc); @@ -2668,7 +2664,8 @@ mdd_object_update_sync_pending(const struct lu_env *env, struct mdd_object *obj, GOTO(out, rc); /* record a changelog for the completion of resync */ - rc = mdd_declare_changelog_store(env, mdd, NULL, NULL, handle); + rc = mdd_declare_changelog_store(env, mdd, CL_RESYNC, NULL, NULL, + handle); if (rc) GOTO(out, rc); @@ -2883,7 +2880,7 @@ static int mdd_open(const struct lu_env *env, struct md_object *obj, struct mdd_object_user *mou = NULL; const struct lu_ucred *uc = lu_ucred(env); struct mdd_device *mdd = mdo2mdd(obj); - int type = CL_OPEN; + enum changelog_rec_type type = CL_OPEN; int rc = 0; mdd_write_lock(env, mdd_obj, MOR_TGT_CHILD); @@ -2900,10 +2897,7 @@ static int mdd_open(const struct lu_env *env, struct md_object *obj, else mdd_obj->mod_count++; - /* Not recording */ - if (!recording_changelog(env, mdd)) - GOTO(out, rc); - if (!(mdd->mdd_cl.mc_mask & (1 << type))) + if (!mdd_changelog_enabled(env, mdd, type)) GOTO(out, rc); find: @@ -3031,7 +3025,8 @@ again: if (rc) GOTO(stop, rc); - rc = mdd_declare_changelog_store(env, mdd, NULL, NULL, handle); + rc = mdd_declare_changelog_store(env, mdd, CL_CLOSE, NULL, NULL, + handle); if (rc) GOTO(stop, rc); @@ -3064,8 +3059,7 @@ cont: /* under mdd write lock */ /* If recording, see if we need to remove UID from list */ - if ((mdd->mdd_cl.mc_flags & CLM_ON) && - (mdd->mdd_cl.mc_mask & (1 << CL_OPEN))) { + if (mdd_changelog_enabled(env, mdd, CL_OPEN)) { struct mdd_object_user *mou; /* look for UID in list */ @@ -3121,14 +3115,17 @@ cont: out: mdd_write_unlock(env, mdd_obj); + if (rc != 0 || blocked || + !mdd_changelog_enabled(env, mdd, CL_CLOSE)) + GOTO(stop, rc); + /* Record CL_CLOSE in changelog only if file was opened in write mode, * or if CL_OPEN was recorded and it's last close by user. * Changelogs mask may change between open and close operations, but * this is not a big deal if we have a CL_CLOSE entry with no matching * CL_OPEN. Plus Changelogs mask may not change often. */ - if (!rc && !blocked && - ((!(mdd->mdd_cl.mc_mask & (1 << CL_OPEN)) && + if (((!(mdd->mdd_cl.mc_mask & (1 << CL_OPEN)) && (mode & (MDS_FMODE_WRITE | MDS_OPEN_APPEND | MDS_OPEN_TRUNC))) || ((mdd->mdd_cl.mc_mask & (1 << CL_OPEN)) && last_close_by_uid)) && !(ma->ma_valid & MA_FLAGS && ma->ma_attr_flags & MDS_RECOV_OPEN)) { @@ -3137,8 +3134,8 @@ out: if (IS_ERR(handle)) GOTO(stop, rc = PTR_ERR(handle)); - rc = mdd_declare_changelog_store(env, mdd, NULL, NULL, - handle); + rc = mdd_declare_changelog_store(env, mdd, CL_CLOSE, + NULL, NULL, handle); if (rc) GOTO(stop, rc); -- 1.8.3.1