From 1ef38b1258f1c6a26b24e1e1ff2b854b43db8f25 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 Lustre-change: https://review.whamcloud.com/50193 Lustre-commit: 3ef773db80fc346455c9939ad108f3f56990ee9c Test-Parameters: trivial HPE-bug-id: LUS-11556 Signed-off-by: Shaun Tancheff Change-Id: I1de02f86fd2719fc75de4f014f51d73736d83c33 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/51734 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- 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/file.c | 23 +++++++++++----- 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, 116 insertions(+), 35 deletions(-) diff --git a/contrib/scripts/spelling.txt b/contrib/scripts/spelling.txt index 4765eaa..22e1097 100644 --- a/contrib/scripts/spelling.txt +++ b/contrib/scripts/spelling.txt @@ -199,6 +199,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 SETSTRIPE||LFS setstripe setup_timer||cfs_timer_setup diff --git a/libcfs/libcfs/fail.c b/libcfs/libcfs/fail.c index 0478f4a..f1574a2 100644 --- a/libcfs/libcfs/fail.c +++ b/libcfs/libcfs/fail.c @@ -58,7 +58,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 eca096e..43f7f9a 100644 --- a/lnet/lnet/net_fault.c +++ b/lnet/lnet/net_fault.c @@ -175,9 +175,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); @@ -282,10 +282,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); @@ -304,7 +304,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++; @@ -370,7 +370,7 @@ drop_rule_match(struct lnet_drop_rule *rule, lnet_nid_t src, /* 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 @@ -385,7 +385,7 @@ drop_rule_match(struct lnet_drop_rule *rule, lnet_nid_t src, 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", @@ -401,7 +401,7 @@ drop_rule_match(struct lnet_drop_rule *rule, lnet_nid_t src, 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); @@ -553,7 +553,7 @@ delay_rule_match(struct lnet_delay_rule *rule, lnet_nid_t 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", @@ -570,7 +570,7 @@ delay_rule_match(struct lnet_delay_rule *rule, lnet_nid_t 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); @@ -862,9 +862,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; @@ -1008,10 +1008,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 8ab85fa..53e98b3 100644 --- a/lnet/lnet/router.c +++ b/lnet/lnet/router.c @@ -629,7 +629,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 0955981..d509683 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -3438,6 +3438,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 @@ -3653,6 +3705,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 ]) @@ -3893,6 +3949,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/file.c b/lustre/llite/file.c index 62a71e2..114b407 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -5855,12 +5855,18 @@ out: return rc; } -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; @@ -5880,7 +5886,12 @@ struct posix_acl *ll_get_acl(struct inode *inode, int type #ifdef HAVE_IOP_SET_ACL #ifdef CONFIG_LUSTRE_FS_POSIX_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) { struct ll_sb_info *sbi = ll_i2sbi(inode); diff --git a/lustre/llite/llite_internal.h b/lustre/llite/llite_internal.h index c412b1f..6849434 100644 --- a/lustre/llite/llite_internal.h +++ b/lustre/llite/llite_internal.h @@ -1262,14 +1262,23 @@ int ll_getattr(struct vfsmount *mnt, struct dentry *de, struct kstat *stat); #endif /* HAVE_USER_NAMESPACE_ARG */ int ll_getattr_dentry(struct dentry *de, struct kstat *stat, u32 request_mask, unsigned int flags); -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 *, struct 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_IOP_SET_ACL #ifdef CONFIG_LUSTRE_FS_POSIX_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); #else /* !CONFIG_LUSTRE_FS_POSIX_ACL */ #define ll_set_acl NULL diff --git a/lustre/lod/lod_qos.c b/lustre/lod/lod_qos.c index 4995a36..4e628dd 100644 --- a/lustre/lod/lod_qos.c +++ b/lustre/lod/lod_qos.c @@ -783,7 +783,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); @@ -977,7 +977,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 2a669a0..260d8e6 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -650,7 +650,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 709ed58..5bd9d3a 100644 --- a/lustre/obdclass/lu_tgt_descs.c +++ b/lustre/obdclass/lu_tgt_descs.c @@ -66,10 +66,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 7222c09..c6174f8 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 cfs_binheap_insert(delay_data->delay_binheap, &nrq->nr_node); -- 1.8.3.1