From 3ef773db80fc346455c9939ad108f3f56990ee9c Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Sun, 2 Apr 2023 04:15:58 -0500 Subject: [PATCH] LU-16594 build: get_random_u32_below, get_acl with dentry Linux commit v6.1-13825-g3c202d14a9d7 prandom: remove prandom_u32_max() Use get_random_u32_below() and provide a replacement when get_random_u32_below is not available. Linux commit v6.1-rc1-2-g138060ba92b3 fs: pass dentry to set acl method Linux commit v6.1-rc1-4-g7420332a6ff4 fs: add new get acl method get_acl() and set_acl() have new signatures Test-Parameters: trivial HPE-bug-id: LUS-11556 Signed-off-by: Shaun Tancheff Change-Id: I1de02f86fd2719fc75de4f014f51d73736d83c33 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50193 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- contrib/scripts/spelling.txt | 1 + libcfs/libcfs/fail.c | 2 +- lnet/lnet/net_fault.c | 28 ++++++++++---------- lnet/lnet/router.c | 2 +- lustre/autoconf/lustre-core.m4 | 60 ++++++++++++++++++++++++++++++++++++++++++ lustre/llite/acl.c | 26 +++++++++++++----- lustre/llite/llite_internal.h | 21 ++++++++++----- lustre/lod/lod_qos.c | 4 +-- lustre/mgc/mgc_request.c | 2 +- lustre/obdclass/lu_tgt_descs.c | 4 +-- lustre/ptlrpc/nrs_delay.c | 4 +-- 11 files changed, 119 insertions(+), 35 deletions(-) diff --git a/contrib/scripts/spelling.txt b/contrib/scripts/spelling.txt index 5209c82..5cc1ad9 100644 --- a/contrib/scripts/spelling.txt +++ b/contrib/scripts/spelling.txt @@ -214,6 +214,7 @@ page_cache_release||put_page PAGE_CACHE_SHIFT||PAGE_SHIFT PAGE_CACHE_SIZE||PAGE_SIZE prandom_u32||get_random_u32 +prandom_u32_max||get_random_u32_below return seq_printf||seq_printf setup_timer||cfs_timer_setup = seq_printf||seq_printf diff --git a/libcfs/libcfs/fail.c b/libcfs/libcfs/fail.c index 00c4c2b..5623e3f 100644 --- a/libcfs/libcfs/fail.c +++ b/libcfs/libcfs/fail.c @@ -64,7 +64,7 @@ int __cfs_fail_check_set(u32 id, u32 value, int set) /* Fail 1/cfs_fail_val times */ if (cfs_fail_loc & CFS_FAIL_RAND) { - if (cfs_fail_val < 2 || prandom_u32_max(cfs_fail_val) > 0) + if (cfs_fail_val < 2 || get_random_u32_below(cfs_fail_val) > 0) return 0; } diff --git a/lnet/lnet/net_fault.c b/lnet/lnet/net_fault.c index 8b1f2f2..205b268 100644 --- a/lnet/lnet/net_fault.c +++ b/lnet/lnet/net_fault.c @@ -180,9 +180,9 @@ lnet_drop_rule_add(struct lnet_fault_attr *attr) if (attr->u.drop.da_interval != 0) { rule->dr_time_base = ktime_get_seconds() + attr->u.drop.da_interval; rule->dr_drop_time = ktime_get_seconds() + - prandom_u32_max(attr->u.drop.da_interval); + get_random_u32_below(attr->u.drop.da_interval); } else { - rule->dr_drop_at = prandom_u32_max(attr->u.drop.da_rate); + rule->dr_drop_at = get_random_u32_below(attr->u.drop.da_rate); } lnet_net_lock(LNET_LOCK_EX); @@ -287,10 +287,10 @@ lnet_drop_rule_reset(void) memset(&rule->dr_stat, 0, sizeof(rule->dr_stat)); if (attr->u.drop.da_rate != 0) { - rule->dr_drop_at = prandom_u32_max(attr->u.drop.da_rate); + rule->dr_drop_at = get_random_u32_below(attr->u.drop.da_rate); } else { rule->dr_drop_time = ktime_get_seconds() + - prandom_u32_max(attr->u.drop.da_interval); + get_random_u32_below(attr->u.drop.da_interval); rule->dr_time_base = ktime_get_seconds() + attr->u.drop.da_interval; } spin_unlock(&rule->dr_lock); @@ -309,7 +309,7 @@ lnet_fault_match_health(enum lnet_msg_hstatus *hstatus, __u32 mask) int i; /* assign a random failure */ - choice = prandom_u32_max(LNET_MSG_STATUS_END - LNET_MSG_STATUS_OK); + choice = get_random_u32_below(LNET_MSG_STATUS_END - LNET_MSG_STATUS_OK); if (choice == 0) choice++; @@ -377,7 +377,7 @@ drop_rule_match(struct lnet_drop_rule *rule, /* match this rule, check drop rate now */ spin_lock(&rule->dr_lock); if (attr->u.drop.da_random) { - int value = prandom_u32_max(attr->u.drop.da_interval); + int value = get_random_u32_below(attr->u.drop.da_interval); if (value >= (attr->u.drop.da_interval / 2)) drop = true; else @@ -392,7 +392,7 @@ drop_rule_match(struct lnet_drop_rule *rule, rule->dr_time_base = now; rule->dr_drop_time = rule->dr_time_base + - prandom_u32_max(attr->u.drop.da_interval); + get_random_u32_below(attr->u.drop.da_interval); rule->dr_time_base += attr->u.drop.da_interval; CDEBUG(D_NET, "Drop Rule %s->%s: next drop : %lld\n", @@ -408,7 +408,7 @@ drop_rule_match(struct lnet_drop_rule *rule, count = rule->dr_stat.fs_count; if (do_div(count, attr->u.drop.da_rate) == 0) { rule->dr_drop_at = rule->dr_stat.fs_count + - prandom_u32_max(attr->u.drop.da_rate); + get_random_u32_below(attr->u.drop.da_rate); CDEBUG(D_NET, "Drop Rule %s->%s: next drop: %lu\n", libcfs_nid2str(attr->fa_src), libcfs_nid2str(attr->fa_dst), rule->dr_drop_at); @@ -559,7 +559,7 @@ delay_rule_match(struct lnet_delay_rule *rule, struct lnet_nid *src, rule->dl_time_base = now; rule->dl_delay_time = rule->dl_time_base + - prandom_u32_max(attr->u.delay.la_interval); + get_random_u32_below(attr->u.delay.la_interval); rule->dl_time_base += attr->u.delay.la_interval; CDEBUG(D_NET, "Delay Rule %s->%s: next delay : %lld\n", @@ -576,7 +576,7 @@ delay_rule_match(struct lnet_delay_rule *rule, struct lnet_nid *src, count = rule->dl_stat.fs_count; if (do_div(count, attr->u.delay.la_rate) == 0) { rule->dl_delay_at = rule->dl_stat.fs_count + - prandom_u32_max(attr->u.delay.la_rate); + get_random_u32_below(attr->u.delay.la_rate); CDEBUG(D_NET, "Delay Rule %s->%s: next delay: %lu\n", libcfs_nid2str(attr->fa_src), libcfs_nid2str(attr->fa_dst), rule->dl_delay_at); @@ -866,9 +866,9 @@ lnet_delay_rule_add(struct lnet_fault_attr *attr) rule->dl_time_base = ktime_get_seconds() + attr->u.delay.la_interval; rule->dl_delay_time = ktime_get_seconds() + - prandom_u32_max(attr->u.delay.la_interval); + get_random_u32_below(attr->u.delay.la_interval); } else { - rule->dl_delay_at = prandom_u32_max(attr->u.delay.la_rate); + rule->dl_delay_at = get_random_u32_below(attr->u.delay.la_rate); } rule->dl_msg_send = -1; @@ -1012,10 +1012,10 @@ lnet_delay_rule_reset(void) memset(&rule->dl_stat, 0, sizeof(rule->dl_stat)); if (attr->u.delay.la_rate != 0) { - rule->dl_delay_at = prandom_u32_max(attr->u.delay.la_rate); + rule->dl_delay_at = get_random_u32_below(attr->u.delay.la_rate); } else { rule->dl_delay_time = ktime_get_seconds() + - prandom_u32_max(attr->u.delay.la_interval); + get_random_u32_below(attr->u.delay.la_interval); rule->dl_time_base = ktime_get_seconds() + attr->u.delay.la_interval; } diff --git a/lnet/lnet/router.c b/lnet/lnet/router.c index 8d4d5bd..2b916ef 100644 --- a/lnet/lnet/router.c +++ b/lnet/lnet/router.c @@ -584,7 +584,7 @@ lnet_add_route_to_rnet(struct lnet_remotenet *rnet, struct lnet_route *route) * different nodes are using the same list of routers, they end up * preferring different routers. */ - offset = prandom_u32_max(len + 1); + offset = get_random_u32_below(len + 1); list_for_each(e, &rnet->lrn_routes) { if (offset == 0) break; diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index 3f94c95..31f123b 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -3737,6 +3737,58 @@ AC_DEFUN([LC_HAVE_FILEMAP_GET_FOLIOS_CONTIG], [ ]) # LC_HAVE_FILEMAP_GET_FOLIOS_CONTIG # +# LC_HAVE_GET_RANDOM_U32_BELOW +# +# Linux commit v6.1-13825-g3c202d14a9d7 +# prandom: remove prandom_u32_max() +# +AC_DEFUN([LC_SRC_HAVE_GET_RANDOM_U32_BELOW], [ + LB2_LINUX_TEST_SRC([get_random_u32_below], [ + #include + ],[ + u32 rand32 = get_random_u32_below(99); + (void)rand32; + ],[-Werror]) +]) +AC_DEFUN([LC_HAVE_GET_RANDOM_U32_BELOW], [ + AC_MSG_CHECKING([if get_random_u32_below()is available]) + LB2_LINUX_TEST_RESULT([get_random_u32_below], [ + AC_DEFINE(HAVE_GET_RANDOM_U32_BELOW, 1, + [get_random_u32_below() is available]) + ],[ + AC_DEFINE([get_random_u32_below(v)], [prandom_u32_max(v)], + [get_random_u32_below() is not available]) + ]) +]) # LC_HAVE_GET_RANDOM_U32_BELOW + +# +# LC_HAVE_ACL_WITH_DENTRY +# +# Linux commit v6.1-rc1-2-g138060ba92b3 +# fs: pass dentry to set acl method +# Linux commit v6.1-rc1-4-g7420332a6ff4 +# fs: add new get acl method +# +AC_DEFUN([LC_SRC_HAVE_ACL_WITH_DENTRY], [ + LB2_LINUX_TEST_SRC([acl_with_dentry], [ + #include + ],[ + struct user_namespace *ns = NULL; + struct dentry *dentry = NULL; + + ((struct inode_operations *)1)->get_acl(ns, dentry, 0); + (void)ns; (void)dentry; + ],[-Werror]) +]) +AC_DEFUN([LC_HAVE_ACL_WITH_DENTRY], [ + AC_MSG_CHECKING([if 'get_acl' and 'set_acl' use dentry argument]) + LB2_LINUX_TEST_RESULT([acl_with_dentry], [ + AC_DEFINE(HAVE_ACL_WITH_DENTRY, 1, + ['get_acl' and 'set_acl' use dentry argument]) + ]) +]) # LC_HAVE_ACL_WITH_DENTRY + +# # LC_PROG_LINUX # # Lustre linux kernel checks @@ -3979,6 +4031,10 @@ AC_DEFUN([LC_PROG_LINUX_SRC], [ LC_SRC_NFS_FILLDIR_USE_CTX_RETURN_BOOL LC_SRC_HAVE_FILEMAP_GET_FOLIOS_CONTIG + # 6.2 + LC_SRC_HAVE_GET_RANDOM_U32_BELOW + LC_SRC_HAVE_ACL_WITH_DENTRY + # kernel patch to extend integrity interface LC_SRC_BIO_INTEGRITY_PREP_FN ]) @@ -4236,6 +4292,10 @@ AC_DEFUN([LC_PROG_LINUX_RESULTS], [ LC_NFS_FILLDIR_USE_CTX_RETURN_BOOL LC_HAVE_FILEMAP_GET_FOLIOS_CONTIG + # 6.2 + LC_HAVE_GET_RANDOM_U32_BELOW + LC_HAVE_ACL_WITH_DENTRY + # kernel patch to extend integrity interface LC_BIO_INTEGRITY_PREP_FN ]) diff --git a/lustre/llite/acl.c b/lustre/llite/acl.c index 7d6d5be..dda8f3b 100644 --- a/lustre/llite/acl.c +++ b/lustre/llite/acl.c @@ -38,12 +38,18 @@ #include "llite_internal.h" -struct posix_acl *ll_get_acl(struct inode *inode, int type -#ifdef HAVE_GET_ACL_RCU_ARG - , bool rcu -#endif /* HAVE_GET_ACL_RCU_ARG */ - ) +struct posix_acl *ll_get_acl( + #ifdef HAVE_ACL_WITH_DENTRY + struct user_namespace *ns, struct dentry *dentry, int type) + #elif defined HAVE_GET_ACL_RCU_ARG + struct inode *inode, int type, bool rcu) + #else + struct inode *inode, int type) + #endif /* HAVE_GET_ACL_RCU_ARG */ { +#ifdef HAVE_ACL_WITH_DENTRY + struct inode *inode = dentry->d_inode; +#endif struct ll_inode_info *lli = ll_i2info(inode); struct posix_acl *acl = NULL; ENTRY; @@ -62,9 +68,17 @@ struct posix_acl *ll_get_acl(struct inode *inode, int type } #ifdef HAVE_IOP_SET_ACL -int ll_set_acl(struct user_namespace *mnt_userns, struct inode *inode, +int ll_set_acl(struct user_namespace *mnt_userns, +#ifdef HAVE_ACL_WITH_DENTRY + struct dentry *dentry, +#else + struct inode *inode, +#endif struct posix_acl *acl, int type) { +#ifdef HAVE_ACL_WITH_DENTRY + struct inode *inode = dentry->d_inode; +#endif struct ll_sb_info *sbi = ll_i2sbi(inode); struct ptlrpc_request *req = NULL; const char *name = NULL; diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index 9b98b94..32023a4 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -1210,12 +1210,21 @@ int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat); int ll_getattr_dentry(struct dentry *de, struct kstat *stat, u32 request_mask, unsigned int flags, bool foreign); #ifdef CONFIG_LUSTRE_FS_POSIX_ACL -struct posix_acl *ll_get_acl(struct inode *inode, int type -#ifdef HAVE_GET_ACL_RCU_ARG - , bool rcu -#endif /* HAVE_GET_ACL_RCU_ARG */ - ); -int ll_set_acl(struct user_namespace *mnt_userns, struct inode *inode, +struct posix_acl *ll_get_acl( + #ifdef HAVE_ACL_WITH_DENTRY + struct user_namespace *, struct dentry *, int); + #elif defined HAVE_GET_ACL_RCU_ARG + struct inode *inode, int type, bool rcu); + #else + struct inode *inode, int type); + #endif /* HAVE_GET_ACL_RCU_ARG */ + +int ll_set_acl(struct user_namespace *mnt_userns, + #ifdef HAVE_ACL_WITH_DENTRY + struct dentry *dentry, + #else + struct inode *inode, + #endif struct posix_acl *acl, int type); #else /* !CONFIG_LUSTRE_FS_POSIX_ACL */ #define ll_get_acl NULL diff --git a/lustre/lod/lod_qos.c b/lustre/lod/lod_qos.c index ff61d67..b974cb9 100644 --- a/lustre/lod/lod_qos.c +++ b/lustre/lod/lod_qos.c @@ -769,7 +769,7 @@ static int lod_ost_alloc_rr(const struct lu_env *env, struct lod_object *lo, spin_lock(&lqr->lqr_alloc); if (--lqr->lqr_start_count <= 0) { atomic_set(&lqr->lqr_start_idx, - prandom_u32_max(osts->op_count)); + get_random_u32_below(osts->op_count)); lqr->lqr_start_count = (LOV_CREATE_RESEED_MIN / max(osts->op_count, 1U) + LOV_CREATE_RESEED_MULT) * max(osts->op_count, 1U); @@ -965,7 +965,7 @@ int lod_mdt_alloc_rr(const struct lu_env *env, struct lod_object *lo, spin_lock(&lqr->lqr_alloc); if (--lqr->lqr_start_count <= 0) { atomic_set(&lqr->lqr_start_idx, - prandom_u32_max(pool->op_count)); + get_random_u32_below(pool->op_count)); lqr->lqr_start_count = (LOV_CREATE_RESEED_MIN / max(pool->op_count, 1U) + LOV_CREATE_RESEED_MULT) * max(pool->op_count, 1U); diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index eb07035..3827305 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -659,7 +659,7 @@ static int mgc_requeue_thread(void *data) */ to = mgc_requeue_timeout_min == 0 ? 1 : mgc_requeue_timeout_min; to = cfs_time_seconds(mgc_requeue_timeout_min) + - prandom_u32_max(cfs_time_seconds(to)); + get_random_u32_below(cfs_time_seconds(to)); wait_event_idle_timeout(rq_waitq, rq_state & (RQ_STOP | RQ_PRECLEANUP), to); diff --git a/lustre/obdclass/lu_tgt_descs.c b/lustre/obdclass/lu_tgt_descs.c index 9a965fc..697ff5e 100644 --- a/lustre/obdclass/lu_tgt_descs.c +++ b/lustre/obdclass/lu_tgt_descs.c @@ -65,10 +65,10 @@ u64 lu_prandom_u64_max(u64 ep_ro) * 32 bits (truncated to the upper limit, if needed) */ if (ep_ro > 0xffffffffULL) - rand = (u64)prandom_u32_max((u32)(ep_ro >> 32)) << 32; + rand = (u64)get_random_u32_below((u32)(ep_ro >> 32)) << 32; if (rand == (ep_ro & 0xffffffff00000000ULL)) - rand |= prandom_u32_max((u32)ep_ro); + rand |= get_random_u32_below((u32)ep_ro); else rand |= get_random_u32(); #else diff --git a/lustre/ptlrpc/nrs_delay.c b/lustre/ptlrpc/nrs_delay.c index 33aef12..0f1459b 100644 --- a/lustre/ptlrpc/nrs_delay.c +++ b/lustre/ptlrpc/nrs_delay.c @@ -255,11 +255,11 @@ static int nrs_delay_req_add(struct ptlrpc_nrs_policy *policy, if (delay_data->delay_pct == 0 || /* Not delaying anything */ (delay_data->delay_pct != 100 && - delay_data->delay_pct < prandom_u32_max(100))) + delay_data->delay_pct < get_random_u32_below(100))) return 1; nrq->nr_u.delay.req_start_time = ktime_get_real_seconds() + - prandom_u32_max(delay_data->max_delay - delay_data->min_delay + 1) + + get_random_u32_below(delay_data->max_delay - delay_data->min_delay + 1) + delay_data->min_delay; return binheap_insert(delay_data->delay_binheap, &nrq->nr_node); -- 1.8.3.1