From: Andreas Dilger Date: Thu, 14 Nov 2019 02:49:23 +0000 (-0700) Subject: LU-12967 tgt: clean up sync_on_cancel references X-Git-Tag: 2.12.4-RC1~34 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=1e43d3c4fc8432bebacfa7a8a320163e3b15448d;p=fs%2Flustre-release.git 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. Lustre-change: https://review.whamcloud.com/36754 Lustre-commit: 52a5981be4df863088168b3ea41fac9e29ddf060 Test-Parameters: trivial Signed-off-by: Andreas Dilger Change-Id: If7c6015420a5c3266a13798fd8b96539323ebbe5 Reviewed-by: Arshad Hussain Reviewed-by: James Simmons Signed-off-by: Minh Diep Reviewed-on: https://review.whamcloud.com/37038 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/obd.h b/lustre/include/obd.h index d2ca015..e86cac4 100644 --- a/lustre/include/obd.h +++ b/lustre/include/obd.h @@ -137,11 +137,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 1eb098a..3693d5b 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -6037,14 +6037,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 d4b2d80..4ac9674 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -1171,7 +1171,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 b7b87e3..e4733ac 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 75b5cec..4c1b930 100644 --- a/lustre/target/tgt_handler.c +++ b/lustre/target/tgt_handler.c @@ -1276,8 +1276,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);