From 52a5981be4df863088168b3ea41fac9e29ddf060 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Wed, 13 Nov 2019 19:49:23 -0700 Subject: [PATCH] LU-12967 tgt: clean up sync_on_cancel references Clean up the use of "sync_on_cancel" in the code, since the tunable parameter is named "sync_lock_cancel" and using the same name in the code makes it easier to find the related parts. Rename constants to be more consistent: NEVER_SYNC_ON_CANCEL -> SYNC_LOCK_CANCEL_NEVER BLOCKING_SYNC_ON_CANCEL -> SYNC_LOCK_CANCEL_BLOCKING ALWAYS_SYNC_ON_CANCEL -> SYNC_LOCK_CANCEL_ALWAYS Initialize sync_lock_cancel_states[] with designated initializers so that the state names always match the declared values. Use ARRAY_SIZE() instead of needing NUM_SYNC_ON_CANCEL_STATES. Test-Parameters: trivial Signed-off-by: Andreas Dilger Change-Id: If7c6015420a5c3266a13798fd8b96539323ebbe5 Reviewed-on: https://review.whamcloud.com/36754 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Arshad Hussain Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/include/obd.h | 9 ++++----- lustre/mdt/mdt_handler.c | 8 ++++---- lustre/mdt/mdt_internal.h | 2 +- lustre/ofd/ofd_internal.h | 6 +++--- lustre/target/tgt_handler.c | 4 ++-- lustre/target/tgt_main.c | 20 +++++++++++--------- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lustre/include/obd.h b/lustre/include/obd.h index e560a8c..c84980b 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -136,11 +136,10 @@ struct timeout_item { #define OSC_DEFAULT_RESENDS 10 /* possible values for lut_sync_lock_cancel */ -enum { - NEVER_SYNC_ON_CANCEL = 0, - BLOCKING_SYNC_ON_CANCEL = 1, - ALWAYS_SYNC_ON_CANCEL = 2, - NUM_SYNC_ON_CANCEL_STATES +enum tgt_sync_lock_cancel { + SYNC_LOCK_CANCEL_NEVER = 0, + SYNC_LOCK_CANCEL_BLOCKING = 1, + SYNC_LOCK_CANCEL_ALWAYS = 2, }; /* diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 50191b3..9213c45 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -6153,14 +6153,14 @@ static int mdt_export_cleanup(struct obd_export *exp) static inline void mdt_enable_slc(struct mdt_device *mdt) { - if (mdt->mdt_lut.lut_sync_lock_cancel == NEVER_SYNC_ON_CANCEL) - mdt->mdt_lut.lut_sync_lock_cancel = BLOCKING_SYNC_ON_CANCEL; + if (mdt->mdt_lut.lut_sync_lock_cancel == SYNC_LOCK_CANCEL_NEVER) + mdt->mdt_lut.lut_sync_lock_cancel = SYNC_LOCK_CANCEL_BLOCKING; } static inline void mdt_disable_slc(struct mdt_device *mdt) { - if (mdt->mdt_lut.lut_sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL) - mdt->mdt_lut.lut_sync_lock_cancel = NEVER_SYNC_ON_CANCEL; + if (mdt->mdt_lut.lut_sync_lock_cancel == SYNC_LOCK_CANCEL_BLOCKING) + mdt->mdt_lut.lut_sync_lock_cancel = SYNC_LOCK_CANCEL_NEVER; } static int mdt_obd_disconnect(struct obd_export *exp) diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 1e1d6da..6083c9b 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -1213,7 +1213,7 @@ static inline void mdt_fid_unlock(struct lustre_handle *lh, enum ldlm_mode mode) static inline bool mdt_slc_is_enabled(struct mdt_device *mdt) { - return mdt->mdt_lut.lut_sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL; + return mdt->mdt_lut.lut_sync_lock_cancel == SYNC_LOCK_CANCEL_BLOCKING; } extern mdl_mode_t mdt_mdl_lock_modes[]; diff --git a/lustre/ofd/ofd_internal.h b/lustre/ofd/ofd_internal.h index 7a9a152..779aea5 100644 --- a/lustre/ofd/ofd_internal.h +++ b/lustre/ofd/ofd_internal.h @@ -456,9 +456,9 @@ static inline struct ofd_thread_info *tsi2ofd_info(struct tgt_session_info *tsi) static inline void ofd_slc_set(struct ofd_device *ofd) { if (ofd->ofd_sync_journal == 1) - ofd->ofd_lut.lut_sync_lock_cancel = NEVER_SYNC_ON_CANCEL; - else if (ofd->ofd_lut.lut_sync_lock_cancel == NEVER_SYNC_ON_CANCEL) - ofd->ofd_lut.lut_sync_lock_cancel = ALWAYS_SYNC_ON_CANCEL; + ofd->ofd_lut.lut_sync_lock_cancel = SYNC_LOCK_CANCEL_NEVER; + else if (ofd->ofd_lut.lut_sync_lock_cancel == SYNC_LOCK_CANCEL_NEVER) + ofd->ofd_lut.lut_sync_lock_cancel = SYNC_LOCK_CANCEL_ALWAYS; } static inline int ofd_validate_seq(struct obd_export *exp, __u64 seq) diff --git a/lustre/target/tgt_handler.c b/lustre/target/tgt_handler.c index 4a6443e..bc3f7eb 100644 --- a/lustre/target/tgt_handler.c +++ b/lustre/target/tgt_handler.c @@ -1280,8 +1280,8 @@ static int tgt_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc, if (flag == LDLM_CB_CANCELING && (lock->l_granted_mode & (LCK_EX | LCK_PW | LCK_GROUP)) && - (tgt->lut_sync_lock_cancel == ALWAYS_SYNC_ON_CANCEL || - (tgt->lut_sync_lock_cancel == BLOCKING_SYNC_ON_CANCEL && + (tgt->lut_sync_lock_cancel == SYNC_LOCK_CANCEL_ALWAYS || + (tgt->lut_sync_lock_cancel == SYNC_LOCK_CANCEL_BLOCKING && ldlm_is_cbpending(lock))) && ((exp_connect_flags(lock->l_export) & OBD_CONNECT_MDS_MDS) || lock->l_resource->lr_type == LDLM_EXTENT)) { diff --git a/lustre/target/tgt_main.c b/lustre/target/tgt_main.c index ef02f05..ce15894 100644 --- a/lustre/target/tgt_main.c +++ b/lustre/target/tgt_main.c @@ -39,9 +39,11 @@ /* This must be longer than the longest string below */ #define SYNC_STATES_MAXLEN 16 -static char *sync_on_cancel_states[] = {"never", - "blocking", - "always" }; +static char *sync_lock_cancel_states[] = { + [SYNC_LOCK_CANCEL_NEVER] = "never", + [SYNC_LOCK_CANCEL_BLOCKING] = "blocking", + [SYNC_LOCK_CANCEL_ALWAYS] = "always", +}; /** * Show policy for handling dirty data under a lock being cancelled. @@ -61,7 +63,7 @@ ssize_t sync_lock_cancel_show(struct kobject *kobj, struct lu_target *tgt = obd->u.obt.obt_lut; return sprintf(buf, "%s\n", - sync_on_cancel_states[tgt->lut_sync_lock_cancel]); + sync_lock_cancel_states[tgt->lut_sync_lock_cancel]); } EXPORT_SYMBOL(sync_lock_cancel_show); @@ -93,14 +95,14 @@ ssize_t sync_lock_cancel_store(struct kobject *kobj, struct attribute *attr, obd_kset.kobj); struct lu_target *tgt = obd->u.obt.obt_lut; int val = -1; - int i; + enum tgt_sync_lock_cancel slc; if (count == 0 || count >= SYNC_STATES_MAXLEN) return -EINVAL; - for (i = 0 ; i < NUM_SYNC_ON_CANCEL_STATES; i++) { - if (strcmp(buffer, sync_on_cancel_states[i]) == 0) { - val = i; + for (slc = 0; slc < ARRAY_SIZE(sync_lock_cancel_states); slc++) { + if (strcmp(buffer, sync_lock_cancel_states[slc]) == 0) { + val = slc; break; } } @@ -416,7 +418,7 @@ int tgt_init(const struct lu_env *env, struct lu_target *lut, sptlrpc_rule_set_init(&lut->lut_sptlrpc_rset); spin_lock_init(&lut->lut_flags_lock); - lut->lut_sync_lock_cancel = NEVER_SYNC_ON_CANCEL; + lut->lut_sync_lock_cancel = SYNC_LOCK_CANCEL_NEVER; spin_lock_init(&lut->lut_slc_locks_guard); INIT_LIST_HEAD(&lut->lut_slc_locks); -- 1.8.3.1