From: Mr NeilBrown Date: Mon, 27 Apr 2020 03:40:30 +0000 (+1000) Subject: LU-6142 lustre: use BIT() macro where appropriate X-Git-Tag: 2.13.54~31 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=ff09273feadc994c8c83118e9c4b33189bf04b6d LU-6142 lustre: use BIT() macro where appropriate When accessing a bit in a bitmap/mask/flags-word it can be more readable to use BIT(num) rather than "1 << num". This patch makes that change to various places in lustre Test-Parameters: trivial Signed-off-by: Mr NeilBrown Change-Id: I9f10e7e11e0f310c46c9b216f138799c62308279 Reviewed-on: https://review.whamcloud.com/38377 Reviewed-by: Olaf Faaland-LLNL Tested-by: jenkins Tested-by: Maloo Reviewed-by: Gian-Carlo DeFazio Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- diff --git a/lustre/ldlm/ldlm_extent.c b/lustre/ldlm/ldlm_extent.c index 369c28c..710a783 100644 --- a/lustre/ldlm/ldlm_extent.c +++ b/lustre/ldlm/ldlm_extent.c @@ -1050,7 +1050,7 @@ void ldlm_extent_add_lock(struct ldlm_resource *res, LASSERT(!interval_is_intree(&node->li_node)); idx = ldlm_mode_to_index(lock->l_granted_mode); - LASSERT(lock->l_granted_mode == 1 << idx); + LASSERT(lock->l_granted_mode == BIT(idx)); LASSERT(lock->l_granted_mode == res->lr_itree[idx].lit_mode); /* node extent initialize */ @@ -1106,7 +1106,7 @@ void ldlm_extent_unlink_lock(struct ldlm_lock *lock) return; idx = ldlm_mode_to_index(lock->l_granted_mode); - LASSERT(lock->l_granted_mode == 1 << idx); + LASSERT(lock->l_granted_mode == BIT(idx)); tree = &res->lr_itree[idx]; LASSERT(tree->lit_root != NULL); /* assure the tree is not null */ diff --git a/lustre/ldlm/ldlm_inodebits.c b/lustre/ldlm/ldlm_inodebits.c index 9193ba5..1723db4 100644 --- a/lustre/ldlm/ldlm_inodebits.c +++ b/lustre/ldlm/ldlm_inodebits.c @@ -102,7 +102,7 @@ restart: if (list_empty(head)) continue; - if (hint && !(hint->l_policy_data.l_inodebits.bits & (1 << i))) + if (hint && !(hint->l_policy_data.l_inodebits.bits & BIT(i))) continue; node = list_entry(head->next, struct ldlm_ibits_node, @@ -550,7 +550,7 @@ void ldlm_inodebits_add_lock(struct ldlm_resource *res, struct list_head *head, if (head == &res->lr_waiting) { for (i = 0; i < MDS_INODELOCK_NUMBITS; i++) { - if (lock->l_policy_data.l_inodebits.bits & (1 << i)) + if (lock->l_policy_data.l_inodebits.bits & BIT(i)) list_add_tail(&lock->l_ibits_node->lin_link[i], &res->lr_ibits_queues->liq_waiting[i]); } diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index 735fad3..a154d85 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -1341,7 +1341,7 @@ static bool ldlm_resource_extent_new(struct ldlm_resource *res) /* Initialize interval trees for each lock mode. */ for (idx = 0; idx < LCK_MODE_NUM; idx++) { res->lr_itree[idx].lit_size = 0; - res->lr_itree[idx].lit_mode = 1 << idx; + res->lr_itree[idx].lit_mode = BIT(idx); res->lr_itree[idx].lit_root = NULL; } return true; diff --git a/lustre/lfsck/lfsck_lib.c b/lustre/lfsck/lfsck_lib.c index bf69c6d..4895b3b 100644 --- a/lustre/lfsck/lfsck_lib.c +++ b/lustre/lfsck/lfsck_lib.c @@ -1787,7 +1787,7 @@ void lfsck_bits_dump(struct seq_file *m, int bits, const char *names[], seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n'); - for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) { + for (i = 0, flag = 1; bits != 0; i++, flag = BIT(i)) { if (flag & bits) { bits &= ~flag; if (names[i] != NULL) { @@ -3570,8 +3570,8 @@ int lfsck_query(const struct lu_env *env, struct dt_device *key, GOTO(out, rc = -ENOTSUPP); } - for (i = 0, type = 1 << i; i < LFSCK_TYPE_BITS; - i++, type = 1 << i) { + for (i = 0, type = BIT(i); i < LFSCK_TYPE_BITS; + i++, type = BIT(i)) { if (!(que->lu_types & type)) continue; @@ -3595,8 +3595,8 @@ again: if (!(que->lu_flags & LPF_WAIT)) GOTO(out, rc); - for (i = 0, type = 1 << i; i < LFSCK_TYPE_BITS; - i++, type = 1 << i) { + for (i = 0, type = BIT(i); i < LFSCK_TYPE_BITS; + i++, type = BIT(i)) { if (!(que->lu_types & type)) continue; diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index da83791..007f6cf 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -1043,7 +1043,7 @@ static int copy_and_ct_start(int cmd, struct obd_export *exp, count = 0; for (i = 0; i < sizeof(archive_mask) * 8; i++) { - if ((1 << i) & archive_mask) { + if (BIT(i) & archive_mask) { lk->lk_data[count] = i + 1; count++; } diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 86c5fc4..23aa55b 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -4543,24 +4543,24 @@ int ll_have_md_lock(struct inode *inode, __u64 *bits, enum ldlm_mode l_req_mode) flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING | LDLM_FL_TEST_LOCK; for (i = 0; i < MDS_INODELOCK_NUMBITS && *bits != 0; i++) { - policy.l_inodebits.bits = *bits & (1 << i); + policy.l_inodebits.bits = *bits & BIT(i); if (policy.l_inodebits.bits == 0) continue; - if (md_lock_match(ll_i2mdexp(inode), flags, fid, LDLM_IBITS, - &policy, mode, &lockh)) { - struct ldlm_lock *lock; - - lock = ldlm_handle2lock(&lockh); - if (lock) { - *bits &= - ~(lock->l_policy_data.l_inodebits.bits); - LDLM_LOCK_PUT(lock); - } else { - *bits &= ~policy.l_inodebits.bits; - } - } - } + if (md_lock_match(ll_i2mdexp(inode), flags, fid, LDLM_IBITS, + &policy, mode, &lockh)) { + struct ldlm_lock *lock; + + lock = ldlm_handle2lock(&lockh); + if (lock) { + *bits &= + ~(lock->l_policy_data.l_inodebits.bits); + LDLM_LOCK_PUT(lock); + } else { + *bits &= ~policy.l_inodebits.bits; + } + } + } RETURN(*bits == 0); } @@ -5023,7 +5023,7 @@ int ll_inode_permission(struct inode *inode, int mask) cred->fsuid = make_kuid(&init_user_ns, squash->rsi_uid); cred->fsgid = make_kgid(&init_user_ns, squash->rsi_gid); for (cap = 0; cap < sizeof(cfs_cap_t) * 8; cap++) { - if ((1 << cap) & CFS_CAP_FS_MASK) + if (BIT(cap) & CFS_CAP_FS_MASK) cap_lower(cred->cap_effective, cap); } old_cred = override_creds(cred); diff --git a/lustre/lov/lov_cl_internal.h b/lustre/lov/lov_cl_internal.h index 394eddb..f899c11 100644 --- a/lustre/lov/lov_cl_internal.h +++ b/lustre/lov/lov_cl_internal.h @@ -83,7 +83,7 @@ struct lovsub_device; struct lovsub_object; enum lov_device_flags { - LOV_DEV_INITIALIZED = 1 << 0 + LOV_DEV_INITIALIZED = BIT(0), }; /* diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index a1b113c..9562c8e 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -717,7 +717,7 @@ int mdd_changelog_write_header(const struct lu_env *env, ENTRY; - if (mdd->mdd_cl.mc_mask & (1 << CL_MARK)) { + if (mdd->mdd_cl.mc_mask & BIT(CL_MARK)) { mdd->mdd_cl.mc_starttime = ktime_get(); RETURN(0); } diff --git a/lustre/mdd/mdd_internal.h b/lustre/mdd/mdd_internal.h index 5080b83..220bed9 100644 --- a/lustre/mdd/mdd_internal.h +++ b/lustre/mdd/mdd_internal.h @@ -161,9 +161,9 @@ struct mdd_device { enum mod_flags { /* The dir object has been unlinked */ - DEAD_OBJ = 1 << 0, - ORPHAN_OBJ = 1 << 1, - VOLATILE_OBJ = 1 << 4, + DEAD_OBJ = BIT(0), + ORPHAN_OBJ = BIT(1), + VOLATILE_OBJ = BIT(4), }; struct mdd_object { @@ -785,7 +785,7 @@ static inline bool mdd_changelog_enabled(const struct lu_env *env, const struct lu_ucred *uc; if ((mdd->mdd_cl.mc_flags & CLM_ON) && - (mdd->mdd_cl.mc_mask & (1 << type))) { + (mdd->mdd_cl.mc_mask & BIT(type))) { uc = lu_ucred_check(env); return uc != NULL ? uc->uc_enable_audit : true; diff --git a/lustre/mdd/mdd_lproc.c b/lustre/mdd/mdd_lproc.c index 0b86322..392719e 100644 --- a/lustre/mdd/mdd_lproc.c +++ b/lustre/mdd/mdd_lproc.c @@ -90,7 +90,7 @@ static int mdd_changelog_mask_seq_show(struct seq_file *m, void *data) int i = 0; while (i < CL_LAST) { - if (mdd->mdd_cl.mc_mask & (1 << i)) + if (mdd->mdd_cl.mc_mask & BIT(i)) seq_printf(m, "%s ", changelog_type2str(i)); i++; } diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index d32da73..df5bea0 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -1069,11 +1069,11 @@ static int mdd_attr_set_changelog(const struct lu_env *env, struct mdd_device *mdd = mdo2mdd(obj); int bits, type = 0; - bits = (valid & LA_SIZE) ? 1 << CL_TRUNC : 0; - bits |= (valid & ~(LA_CTIME|LA_MTIME|LA_ATIME)) ? 1 << CL_SETATTR : 0; - bits |= (valid & LA_MTIME) ? 1 << CL_MTIME : 0; - bits |= (valid & LA_CTIME) ? 1 << CL_CTIME : 0; - bits |= (valid & LA_ATIME) ? 1 << CL_ATIME : 0; + bits = (valid & LA_SIZE) ? BIT(CL_TRUNC) : 0; + bits |= (valid & ~(LA_CTIME|LA_MTIME|LA_ATIME)) ? BIT(CL_SETATTR) : 0; + bits |= (valid & LA_MTIME) ? BIT(CL_MTIME) : 0; + bits |= (valid & LA_CTIME) ? BIT(CL_CTIME) : 0; + bits |= (valid & LA_ATIME) ? BIT(CL_ATIME) : 0; bits = bits & mdd->mdd_cl.mc_mask; /* This is an implementation limit rather than a protocol limit */ BUILD_BUG_ON(CL_LAST > sizeof(int) * 8); @@ -3138,7 +3138,7 @@ static int mdd_open(const struct lu_env *env, struct md_object *obj, rc = mdd_open_sanity_check(env, mdd_obj, attr, open_flags, spec->no_create); - if ((rc == -EACCES) && (mdd->mdd_cl.mc_mask & (1 << CL_DN_OPEN))) + if ((rc == -EACCES) && (mdd->mdd_cl.mc_mask & BIT(CL_DN_OPEN))) type = CL_DN_OPEN; else if (rc != 0) GOTO(out, rc); @@ -3376,10 +3376,10 @@ out: * 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 (((!(mdd->mdd_cl.mc_mask & (1 << CL_OPEN)) && + if (((!(mdd->mdd_cl.mc_mask & BIT(CL_OPEN)) && (open_flags & (MDS_FMODE_WRITE | MDS_OPEN_APPEND | MDS_OPEN_TRUNC))) || - ((mdd->mdd_cl.mc_mask & (1 << CL_OPEN)) && last_close_by_uid)) && + ((mdd->mdd_cl.mc_mask & BIT(CL_OPEN)) && last_close_by_uid)) && !(ma->ma_valid & MA_FLAGS && ma->ma_attr_flags & MDS_RECOV_OPEN)) { if (handle == NULL) { handle = mdd_trans_create(env, mdo2mdd(obj)); diff --git a/lustre/mdt/mdt_hsm_cdt_agent.c b/lustre/mdt/mdt_hsm_cdt_agent.c index bd0b1bf..1767e11 100644 --- a/lustre/mdt/mdt_hsm_cdt_agent.c +++ b/lustre/mdt/mdt_hsm_cdt_agent.c @@ -170,7 +170,7 @@ int mdt_hsm_agent_register_mask(struct mdt_thread_info *mti, nr_archives = 0; for (i = 0; i < sizeof(archive_mask) * 8; i++) { - if ((1 << i) & archive_mask) { + if (BIT(i) & archive_mask) { archive_id[nr_archives] = i + 1; nr_archives++; } @@ -325,9 +325,9 @@ int mdt_hsm_send_action_to_each_archive(struct mdt_thread_info *mti, list_for_each_entry(ha, &cdt->cdt_agents, ha_list) { for (i = 0; (i < ha->ha_archive_cnt); i++) { /* only send once for each archive_id */ - if ((1 << ha->ha_archive_id[i]) & archive_mask) + if (BIT(ha->ha_archive_id[i]) & archive_mask) continue; - archive_mask |= (1 << ha->ha_archive_id[i]); + archive_mask |= BIT(ha->ha_archive_id[i]); /* XXX: it could make sense to gather all * actions for the same archive_id like in diff --git a/lustre/mdt/mdt_internal.h b/lustre/mdt/mdt_internal.h index 6f7cedb..99320fc 100644 --- a/lustre/mdt/mdt_internal.h +++ b/lustre/mdt/mdt_internal.h @@ -377,7 +377,7 @@ struct mdt_reint_record { }; enum mdt_reint_flag { - MRF_OPEN_TRUNC = 1 << 0, + MRF_OPEN_TRUNC = BIT(0), }; /* diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index bcb222a..5f557d1 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -1667,7 +1667,7 @@ static struct mdt_object *mdt_orphan_open(struct mdt_thread_info *info, uc = lu_ucred(env); uc_cap_save = uc->uc_cap; - uc->uc_cap |= 1 << CFS_CAP_DAC_OVERRIDE; + uc->uc_cap |= BIT(CFS_CAP_DAC_OVERRIDE); rc = mdo_create(env, mdt_object_child(local_root), &lname, mdt_object_child(obj), spec, attr); uc->uc_cap = uc_cap_save; diff --git a/lustre/obdclass/scrub.c b/lustre/obdclass/scrub.c index 24cb640..0d8ad4b 100644 --- a/lustre/obdclass/scrub.c +++ b/lustre/obdclass/scrub.c @@ -375,7 +375,7 @@ static void scrub_bits_dump(struct seq_file *m, int bits, const char *names[], seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n'); - for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) { + for (i = 0, flag = 1; bits != 0; i++, flag = BIT(i)) { if (flag & bits) { bits &= ~flag; seq_printf(m, "%s%c", names[i], diff --git a/lustre/osc/lproc_osc.c b/lustre/osc/lproc_osc.c index b3eae69..3e0ef83 100644 --- a/lustre/osc/lproc_osc.c +++ b/lustre/osc/lproc_osc.c @@ -409,9 +409,9 @@ static int osc_checksum_type_seq_show(struct seq_file *m, void *v) return 0; for (i = 0; i < ARRAY_SIZE(cksum_name); i++) { - if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0) + if ((BIT(i) & obd->u.cli.cl_supp_cksum_types) == 0) continue; - if (obd->u.cli.cl_cksum_type == (1 << i)) + if (obd->u.cli.cl_cksum_type == BIT(i)) seq_printf(m, "[%s] ", cksum_name[i]); else seq_printf(m, "%s ", cksum_name[i]); diff --git a/lustre/osd-ldiskfs/osd_iam.h b/lustre/osd-ldiskfs/osd_iam.h index afeb8be..b4ee34d 100644 --- a/lustre/osd-ldiskfs/osd_iam.h +++ b/lustre/osd-ldiskfs/osd_iam.h @@ -584,11 +584,11 @@ enum iam_it_flags { /* * this iterator will move (iam_it_next() will be called on it) */ - IAM_IT_MOVE = (1 << 0), + IAM_IT_MOVE = BIT(0), /* * tree can be updated through this iterator. */ - IAM_IT_WRITE = (1 << 1) + IAM_IT_WRITE = BIT(1) }; /* diff --git a/lustre/ptlrpc/gss/gss_err.h b/lustre/ptlrpc/gss/gss_err.h index bcf8130..34cd9a4 100644 --- a/lustre/ptlrpc/gss/gss_err.h +++ b/lustre/ptlrpc/gss/gss_err.h @@ -172,11 +172,11 @@ typedef unsigned int OM_uint32; /* * Supplementary info bits: */ -#define GSS_S_CONTINUE_NEEDED (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 0)) -#define GSS_S_DUPLICATE_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 1)) -#define GSS_S_OLD_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 2)) -#define GSS_S_UNSEQ_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 3)) -#define GSS_S_GAP_TOKEN (1 << (GSS_C_SUPPLEMENTARY_OFFSET + 4)) +#define GSS_S_CONTINUE_NEEDED BIT(GSS_C_SUPPLEMENTARY_OFFSET + 0) +#define GSS_S_DUPLICATE_TOKEN BIT(GSS_C_SUPPLEMENTARY_OFFSET + 1) +#define GSS_S_OLD_TOKEN BIT(GSS_C_SUPPLEMENTARY_OFFSET + 2) +#define GSS_S_UNSEQ_TOKEN BIT(GSS_C_SUPPLEMENTARY_OFFSET + 3) +#define GSS_S_GAP_TOKEN BIT(GSS_C_SUPPLEMENTARY_OFFSET + 4) /* XXXX these are not part of the GSSAPI C bindings! (but should be) */ diff --git a/lustre/ptlrpc/layout.c b/lustre/ptlrpc/layout.c index ff13d5f..807ad87 100644 --- a/lustre/ptlrpc/layout.c +++ b/lustre/ptlrpc/layout.c @@ -878,20 +878,20 @@ struct req_msg_field { }; enum rmf_flags { - /** - * The field is a string, must be NUL-terminated. - */ - RMF_F_STRING = 1 << 0, - /** - * The field's buffer size need not match the declared \a rmf_size. - */ - RMF_F_NO_SIZE_CHECK = 1 << 1, - /** - * The field's buffer size must be a whole multiple of the declared \a - * rmf_size and the \a rmf_swabber function must work on the declared \a - * rmf_size worth of bytes. - */ - RMF_F_STRUCT_ARRAY = 1 << 2 + /** + * The field is a string, must be NUL-terminated. + */ + RMF_F_STRING = BIT(0), + /** + * The field's buffer size need not match the declared \a rmf_size. + */ + RMF_F_NO_SIZE_CHECK = BIT(1), + /** + * The field's buffer size must be a whole multiple of the declared \a + * rmf_size and the \a rmf_swabber function must work on the declared \a + * rmf_size worth of bytes. + */ + RMF_F_STRUCT_ARRAY = BIT(2), }; struct req_capsule; diff --git a/lustre/quota/qsd_config.c b/lustre/quota/qsd_config.c index ed3415e..6b18cb7 100644 --- a/lustre/quota/qsd_config.c +++ b/lustre/quota/qsd_config.c @@ -134,11 +134,11 @@ int qsd_config(char *valstr, char *fsname, int pool) } if (strchr(valstr, 'u')) - enabled |= 1 << USRQUOTA; + enabled |= BIT(USRQUOTA); if (strchr(valstr, 'g')) - enabled |= 1 << GRPQUOTA; + enabled |= BIT(GRPQUOTA); if (strchr(valstr, 'p')) - enabled |= 1 << PRJQUOTA; + enabled |= BIT(PRJQUOTA); mutex_lock(&qfs->qfs_mutex); if (qfs->qfs_enabled[pool - LQUOTA_FIRST_RES] == enabled) @@ -173,8 +173,8 @@ int qsd_config(char *valstr, char *fsname, int pool) qqi = qsd->qsd_type_array[type]; /* only trigger reintegration if this * type of quota is not enabled before */ - if ((old_enabled & 1 << type) || - !(enabled & 1 << type)) + if ((old_enabled & BIT(type)) || + !(enabled & BIT(type))) continue; if (qqi->qqi_acct_failed) { diff --git a/lustre/quota/qsd_internal.h b/lustre/quota/qsd_internal.h index 4747b61..4dc3418 100644 --- a/lustre/quota/qsd_internal.h +++ b/lustre/quota/qsd_internal.h @@ -281,7 +281,7 @@ static inline int qsd_type_enabled(struct qsd_instance *qsd, int type) pool = qsd->qsd_is_md ? LQUOTA_RES_MD : LQUOTA_RES_DT; enabled = qsd->qsd_fsinfo->qfs_enabled[pool - LQUOTA_FIRST_RES]; - return enabled & (1 << type); + return enabled & BIT(type); } /* helper function to set new qunit and compute associated qtune value */