From 4c4c327b25f3414f20a9ae600e7311f1aa3a866d Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Wed, 4 Dec 2019 12:26:46 +1100 Subject: [PATCH 1/1] LU-9679 modules: convert MIN/MAX to kernel style The linux kernel provides a variety of min/max style macros which ensure type correctness - not risking signed vs unsigned comparisons etc. min_t and max_t can be given a type, but if the type of the args is identicatl min/max can be used. We also have min3() and max3() to compare three values of identical type, and clamp_t() to restrict a value to a given range (min(max(...)). Use these as appropriate throughout the lustre/lnet kernel code. The variables (rlength and mlength) have their type changed from int to unsigned int as this makes more sense in the context, and allows min() to be used. Similarly the return type of kiblnd_rd_frag_size() is changed from __u32 to unsigned int as the return value is *only* used in a min3() comparison with another unsigned it. Signed-off-by: Mr NeilBrown Change-Id: I9f0cdd23b78d2f9dd04ba58e9b9c7df8d1ee3ca1 Reviewed-on: https://review.whamcloud.com/37456 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Yang Sheng Reviewed-by: James Simmons Reviewed-by: Shaun Tancheff Reviewed-by: Oleg Drokin --- contrib/scripts/spelling.txt | 2 ++ libcfs/include/libcfs/libcfs_private.h | 8 -------- lnet/klnds/gnilnd/gnilnd.c | 10 +++++----- lnet/klnds/gnilnd/gnilnd_cb.c | 2 +- lnet/klnds/gnilnd/gnilnd_conn.c | 4 ++-- lnet/klnds/o2iblnd/o2iblnd.h | 2 +- lnet/klnds/o2iblnd/o2iblnd_cb.c | 5 +++-- lnet/klnds/socklnd/socklnd.c | 7 ++++--- lnet/klnds/socklnd/socklnd_cb.c | 24 ++++++++++++------------ lnet/lnet/lib-move.c | 32 ++++++++++++++++---------------- lnet/lnet/peer.c | 4 ++-- lnet/lnet/router_proc.c | 3 ++- lnet/selftest/conrpc.h | 3 ++- lnet/selftest/rpc.c | 4 ++-- lustre/lod/lod_object.c | 2 +- lustre/lov/lov_io.c | 4 ++-- lustre/mdc/mdc_locks.c | 8 ++++---- lustre/mdc/mdc_request.c | 10 ++++++---- lustre/mdd/mdd_dir.c | 3 ++- lustre/mdd/mdd_object.c | 3 ++- lustre/mdd/mdd_permission.c | 10 ++++++---- lustre/mdt/mdt_handler.c | 5 +++-- lustre/mgs/mgs_handler.c | 3 ++- lustre/obdclass/lu_object.c | 3 ++- lustre/ofd/ofd_objects.c | 5 +++-- lustre/osc/osc_request.c | 2 +- lustre/osd-zfs/osd_internal.h | 6 ++++-- 27 files changed, 92 insertions(+), 82 deletions(-) diff --git a/contrib/scripts/spelling.txt b/contrib/scripts/spelling.txt index 595d8d2..a1bcb78 100644 --- a/contrib/scripts/spelling.txt +++ b/contrib/scripts/spelling.txt @@ -144,6 +144,8 @@ LPROC_SEQ_FOPS_WR_ONLY||LUSTRE_WO_ATTR LPU64||%llu LPX64i||%llx LPX64||%#llx +\bMAX\(||max_t +\bMIN\(||min_t mktemp||mkstemp page_cache_get||get_page PAGE_CACHE_MASK||PAGE_MASK diff --git a/libcfs/include/libcfs/libcfs_private.h b/libcfs/include/libcfs/libcfs_private.h index e0fcdbe..27db6b7 100644 --- a/libcfs/include/libcfs/libcfs_private.h +++ b/libcfs/include/libcfs/libcfs_private.h @@ -351,14 +351,6 @@ do { \ /* logical equivalence */ #define equi(a, b) (!!(a) == !!(b)) -/* what used to be in portals_lib.h */ -#ifndef MIN -# define MIN(a,b) (((a)<(b)) ? (a): (b)) -#endif -#ifndef MAX -# define MAX(a,b) (((a)>(b)) ? (a): (b)) -#endif - #define MKSTR(ptr) ((ptr))? (ptr) : "" static inline size_t cfs_size_round4(size_t val) diff --git a/lnet/klnds/gnilnd/gnilnd.c b/lnet/klnds/gnilnd/gnilnd.c index bcbc0ac..8b5bc2e 100644 --- a/lnet/klnds/gnilnd/gnilnd.c +++ b/lnet/klnds/gnilnd/gnilnd.c @@ -291,8 +291,8 @@ kgnilnd_create_conn(kgn_conn_t **connp, kgn_device_t *dev) * check context */ conn->gnc_device = dev; - conn->gnc_timeout = MAX(*kgnilnd_tunables.kgn_timeout, - GNILND_MIN_TIMEOUT); + conn->gnc_timeout = max(*kgnilnd_tunables.kgn_timeout, + GNILND_MIN_TIMEOUT); kgnilnd_update_reaper_timeout(conn->gnc_timeout); /* this is the ep_handle for doing SMSG & BTE */ @@ -879,7 +879,7 @@ kgnilnd_set_conn_params(kgn_dgram_t *dgram) /* set timeout vals in conn early so we can use them for the NAK */ /* use max of the requested and our timeout, peer will do the same */ - conn->gnc_timeout = MAX(conn->gnc_timeout, connreq->gncr_timeout); + conn->gnc_timeout = max(conn->gnc_timeout, connreq->gncr_timeout); /* only ep_bind really mucks around with the CQ */ /* only ep bind if we are not connecting to ourself and the dstnid is not a wildcard. this check @@ -1261,8 +1261,8 @@ kgnilnd_peer_increase_reconnect_locked(kgn_peer_t *peer) current_to += *kgnilnd_tunables.kgn_min_reconnect_interval / 2; } - current_to = MIN(current_to, - *kgnilnd_tunables.kgn_max_reconnect_interval); + current_to = min(current_to, + *kgnilnd_tunables.kgn_max_reconnect_interval); peer->gnp_reconnect_interval = current_to; CDEBUG(D_NET, "peer %s can reconnect at %lu interval %lu\n", diff --git a/lnet/klnds/gnilnd/gnilnd_cb.c b/lnet/klnds/gnilnd/gnilnd_cb.c index 93cae3d..4cff9ed 100644 --- a/lnet/klnds/gnilnd/gnilnd_cb.c +++ b/lnet/klnds/gnilnd/gnilnd_cb.c @@ -2800,7 +2800,7 @@ kgnilnd_check_peer_timeouts_locked(kgn_peer_t *peer, struct list_head *todie, peer, libcfs_nid2str(peer->gnp_nid), peer->gnp_reconnect_interval); - timeout = cfs_time_seconds(MAX(*kgnilnd_tunables.kgn_timeout, + timeout = cfs_time_seconds(max(*kgnilnd_tunables.kgn_timeout, GNILND_MIN_TIMEOUT)); conn = kgnilnd_find_conn_locked(peer); diff --git a/lnet/klnds/gnilnd/gnilnd_conn.c b/lnet/klnds/gnilnd/gnilnd_conn.c index 9fa539c..541c7ef 100644 --- a/lnet/klnds/gnilnd/gnilnd_conn.c +++ b/lnet/klnds/gnilnd/gnilnd_conn.c @@ -517,8 +517,8 @@ kgnilnd_release_mbox(kgn_conn_t *conn, int purgatory_hold) fma_blk->gnm_hndl.qword1, fma_blk->gnm_hndl.qword2); fma_blk->gnm_held_mboxs++; - fma_blk->gnm_max_timeout = MAX(fma_blk->gnm_max_timeout, - conn->gnc_timeout); + fma_blk->gnm_max_timeout = max_t(long, fma_blk->gnm_max_timeout, + conn->gnc_timeout); } else { CDEBUG(D_NET, "conn %p smsg %p fmablk %p release SMSG mbox %d " "hndl %#llx.%#llx\n", diff --git a/lnet/klnds/o2iblnd/o2iblnd.h b/lnet/klnds/o2iblnd/o2iblnd.h index 9eb4578..12c770d 100644 --- a/lnet/klnds/o2iblnd/o2iblnd.h +++ b/lnet/klnds/o2iblnd/o2iblnd.h @@ -1060,7 +1060,7 @@ kiblnd_rd_frag_addr(struct kib_rdma_desc *rd, int index) return rd->rd_frags[index].rf_addr; } -static inline __u32 +static inline int kiblnd_rd_frag_size(struct kib_rdma_desc *rd, int index) { return rd->rd_frags[index].rf_nob; diff --git a/lnet/klnds/o2iblnd/o2iblnd_cb.c b/lnet/klnds/o2iblnd/o2iblnd_cb.c index 82c4509..a370ed5 100644 --- a/lnet/klnds/o2iblnd/o2iblnd_cb.c +++ b/lnet/klnds/o2iblnd/o2iblnd_cb.c @@ -1229,8 +1229,9 @@ kiblnd_init_rdma(struct kib_conn *conn, struct kib_tx *tx, int type, break; } - sge_nob = MIN(MIN(kiblnd_rd_frag_size(srcrd, srcidx), - kiblnd_rd_frag_size(dstrd, dstidx)), resid); + sge_nob = min3(kiblnd_rd_frag_size(srcrd, srcidx), + kiblnd_rd_frag_size(dstrd, dstidx), + resid); sge = &tx->tx_sge[tx->tx_nsge]; sge->addr = kiblnd_rd_frag_addr(srcrd, srcidx); diff --git a/lnet/klnds/socklnd/socklnd.c b/lnet/klnds/socklnd/socklnd.c index 364fb54..17115c1 100644 --- a/lnet/klnds/socklnd/socklnd.c +++ b/lnet/klnds/socklnd/socklnd.c @@ -748,9 +748,10 @@ ksocknal_select_ips(struct ksock_peer_ni *peer_ni, __u32 *peerips, int n_peerips LASSERT(net->ksnn_ninterfaces <= LNET_INTERFACES_NUM); /* Only match interfaces for additional connections - * if I have > 1 interface */ - n_ips = (net->ksnn_ninterfaces < 2) ? 0 : - MIN(n_peerips, net->ksnn_ninterfaces); + * if I have > 1 interface + */ + n_ips = (net->ksnn_ninterfaces < 2) ? 0 : + min(n_peerips, net->ksnn_ninterfaces); for (i = 0; peer_ni->ksnp_n_passive_ips < n_ips; i++) { /* ^ yes really... */ diff --git a/lnet/klnds/socklnd/socklnd_cb.c b/lnet/klnds/socklnd/socklnd_cb.c index 88000c9..134aaff 100644 --- a/lnet/klnds/socklnd/socklnd_cb.c +++ b/lnet/klnds/socklnd/socklnd_cb.c @@ -1145,22 +1145,22 @@ ksocknal_new_packet(struct ksock_conn *conn, int nob_to_skip) /* Set up to skip as much as possible now. If there's more left * (ran out of iov entries) we'll get called again */ - conn->ksnc_rx_state = SOCKNAL_RX_SLOP; - conn->ksnc_rx_nob_left = nob_to_skip; + conn->ksnc_rx_state = SOCKNAL_RX_SLOP; + conn->ksnc_rx_nob_left = nob_to_skip; conn->ksnc_rx_iov = (struct kvec *)&conn->ksnc_rx_iov_space; - skipped = 0; - niov = 0; + skipped = 0; + niov = 0; - do { - nob = MIN (nob_to_skip, sizeof (ksocknal_slop_buffer)); + do { + nob = min_t(int, nob_to_skip, sizeof(ksocknal_slop_buffer)); - conn->ksnc_rx_iov[niov].iov_base = ksocknal_slop_buffer; - conn->ksnc_rx_iov[niov].iov_len = nob; - niov++; - skipped += nob; - nob_to_skip -=nob; + conn->ksnc_rx_iov[niov].iov_base = ksocknal_slop_buffer; + conn->ksnc_rx_iov[niov].iov_len = nob; + niov++; + skipped += nob; + nob_to_skip -= nob; - } while (nob_to_skip != 0 && /* mustn't overflow conn's rx iov */ + } while (nob_to_skip != 0 && /* mustn't overflow conn's rx iov */ niov < sizeof(conn->ksnc_rx_iov_space) / sizeof(struct kvec)); conn->ksnc_rx_niov = niov; diff --git a/lnet/lnet/lib-move.c b/lnet/lnet/lib-move.c index 0bebc01..c36a886 100644 --- a/lnet/lnet/lib-move.c +++ b/lnet/lnet/lib-move.c @@ -279,7 +279,7 @@ lnet_copy_iov2iov(unsigned int ndiov, struct kvec *diov, unsigned int doffset, unsigned int nob) { /* NB diov, siov are READ-ONLY */ - unsigned int this_nob; + unsigned int this_nob; if (nob == 0) return; @@ -305,9 +305,9 @@ lnet_copy_iov2iov(unsigned int ndiov, struct kvec *diov, unsigned int doffset, do { LASSERT(ndiov > 0); LASSERT(nsiov > 0); - this_nob = MIN(diov->iov_len - doffset, - siov->iov_len - soffset); - this_nob = MIN(this_nob, nob); + this_nob = min3((unsigned int)diov->iov_len - doffset, + (unsigned int)siov->iov_len - soffset, + nob); memcpy((char *)diov->iov_base + doffset, (char *)siov->iov_base + soffset, this_nob); @@ -427,9 +427,9 @@ lnet_copy_kiov2kiov(unsigned int ndiov, lnet_kiov_t *diov, unsigned int doffset, do { LASSERT(ndiov > 0); LASSERT(nsiov > 0); - this_nob = MIN(diov->kiov_len - doffset, - siov->kiov_len - soffset); - this_nob = MIN(this_nob, nob); + this_nob = min3(diov->kiov_len - doffset, + siov->kiov_len - soffset, + nob); if (daddr == NULL) daddr = ((char *)kmap(diov->kiov_page)) + @@ -508,9 +508,9 @@ lnet_copy_kiov2iov (unsigned int niov, struct kvec *iov, unsigned int iovoffset, do { LASSERT(niov > 0); LASSERT(nkiov > 0); - this_nob = MIN(iov->iov_len - iovoffset, - kiov->kiov_len - kiovoffset); - this_nob = MIN(this_nob, nob); + this_nob = min3((unsigned int)iov->iov_len - iovoffset, + (unsigned int)kiov->kiov_len - kiovoffset, + nob); if (addr == NULL) addr = ((char *)kmap(kiov->kiov_page)) + @@ -578,9 +578,9 @@ lnet_copy_iov2kiov(unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffse do { LASSERT(nkiov > 0); LASSERT(niov > 0); - this_nob = MIN(kiov->kiov_len - kiovoffset, - iov->iov_len - iovoffset); - this_nob = MIN(this_nob, nob); + this_nob = min3((unsigned int)kiov->kiov_len - kiovoffset, + (unsigned int)iov->iov_len - iovoffset, + nob); if (addr == NULL) addr = ((char *)kmap(kiov->kiov_page)) + @@ -3994,8 +3994,8 @@ lnet_parse_reply(struct lnet_ni *ni, struct lnet_msg *msg) struct lnet_hdr *hdr = &msg->msg_hdr; struct lnet_process_id src = {0}; struct lnet_libmd *md; - int rlength; - int mlength; + unsigned int rlength; + unsigned int mlength; int cpt; cpt = lnet_cpt_of_cookie(hdr->msg.reply.dst_wmd.wh_object_cookie); @@ -4024,7 +4024,7 @@ lnet_parse_reply(struct lnet_ni *ni, struct lnet_msg *msg) LASSERT(md->md_offset == 0); rlength = hdr->payload_length; - mlength = MIN(rlength, (int)md->md_length); + mlength = min(rlength, md->md_length); if (mlength < rlength && (md->md_options & LNET_MD_TRUNCATE) == 0) { diff --git a/lnet/lnet/peer.c b/lnet/lnet/peer.c index 6336410..4e6a3e5 100644 --- a/lnet/lnet/peer.c +++ b/lnet/lnet/peer.c @@ -2583,7 +2583,7 @@ static int lnet_peer_merge_data(struct lnet_peer *lp, lp->lp_state &= ~LNET_PEER_ROUTER_ENABLED; spin_unlock(&lp->lp_lock); - nnis = MAX(lp->lp_nnis, pbuf->pb_info.pi_nnis); + nnis = max_t(int, lp->lp_nnis, pbuf->pb_info.pi_nnis); LIBCFS_ALLOC(curnis, nnis * sizeof(*curnis)); LIBCFS_ALLOC(addnis, nnis * sizeof(*addnis)); LIBCFS_ALLOC(delnis, nnis * sizeof(*delnis)); @@ -2977,7 +2977,7 @@ __must_hold(&lp->lp_lock) pnid = lnet_peer_select_nid(lp); lnet_net_unlock(cpt); - nnis = MAX(lp->lp_data_nnis, LNET_INTERFACES_MIN); + nnis = max(lp->lp_data_nnis, LNET_INTERFACES_MIN); rc = lnet_send_ping(pnid, &lp->lp_ping_mdh, nnis, lp, the_lnet.ln_dc_eqh, false); diff --git a/lnet/lnet/router_proc.c b/lnet/lnet/router_proc.c index 126fe1e..617beec 100644 --- a/lnet/lnet/router_proc.c +++ b/lnet/lnet/router_proc.c @@ -36,7 +36,8 @@ */ #define LNET_PROC_CPT_BITS (LNET_CPT_BITS + 1) /* change version, 16 bits or 8 bits */ -#define LNET_PROC_VER_BITS MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8) +#define LNET_PROC_VER_BITS \ + clamp_t(int, LNET_LOFFT_BITS / 4, 8, 16) #define LNET_PROC_HASH_BITS LNET_PEER_HASH_BITS /* diff --git a/lnet/selftest/conrpc.h b/lnet/selftest/conrpc.h index 6eaeaa7..bdceea6 100644 --- a/lnet/selftest/conrpc.h +++ b/lnet/selftest/conrpc.h @@ -49,7 +49,8 @@ #define LST_TRANS_TIMEOUT 30 #define LST_TRANS_MIN_TIMEOUT 3 -#define LST_VALIDATE_TIMEOUT(t) MIN(MAX(t, LST_TRANS_MIN_TIMEOUT), LST_TRANS_TIMEOUT) +#define LST_VALIDATE_TIMEOUT(t) \ + clamp_t(int, t, LST_TRANS_MIN_TIMEOUT, LST_TRANS_TIMEOUT) #define LST_PING_INTERVAL 8 diff --git a/lnet/selftest/rpc.c b/lnet/selftest/rpc.c index 6a2ba3a..47a89fa 100644 --- a/lnet/selftest/rpc.c +++ b/lnet/selftest/rpc.c @@ -553,7 +553,7 @@ srpc_add_buffer(struct swi_workitem *wi) LASSERT(scd->scd_buf_posting > 0); scd->scd_buf_posting--; scd->scd_buf_total++; - scd->scd_buf_low = MAX(2, scd->scd_buf_total / 4); + scd->scd_buf_low = max(2, scd->scd_buf_total / 4); } if (rc != 0) { @@ -1512,7 +1512,7 @@ srpc_lnet_ev_handler(struct lnet_event *ev) if (scd->scd_buf_err == 0 && /* adding buffer is enabled */ scd->scd_buf_adjust == 0 && scd->scd_buf_nposted < scd->scd_buf_low) { - scd->scd_buf_adjust = MAX(scd->scd_buf_total / 2, + scd->scd_buf_adjust = max(scd->scd_buf_total / 2, SFW_TEST_WI_MIN); swi_schedule_workitem(&scd->scd_buf_wi); } diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index 0d6b06a..e11f474 100644 --- a/lustre/lod/lod_object.c +++ b/lustre/lod/lod_object.c @@ -3454,7 +3454,7 @@ static int lod_declare_layout_merge(const struct lu_env *env, lcme->lcme_id = cpu_to_le32(id); } - id = MAX(le32_to_cpu(lcme->lcme_id), id); + id = max(le32_to_cpu(lcme->lcme_id), id); } mirror_id = mirror_id_of(id) + 1; diff --git a/lustre/lov/lov_io.c b/lustre/lov/lov_io.c index 36c83d4..e699603 100644 --- a/lustre/lov/lov_io.c +++ b/lustre/lov/lov_io.c @@ -257,8 +257,8 @@ static int lov_io_mirror_write_intent(struct lov_io *lio, if (!lu_extent_is_overlapped(ext, lle->lle_extent)) continue; - ext->e_start = MIN(ext->e_start, lle->lle_extent->e_start); - ext->e_end = MAX(ext->e_end, lle->lle_extent->e_end); + ext->e_start = min(ext->e_start, lle->lle_extent->e_start); + ext->e_end = max(ext->e_end, lle->lle_extent->e_end); ++count; } if (count == 0) { diff --git a/lustre/mdc/mdc_locks.c b/lustre/mdc/mdc_locks.c index 81bfebc..574d09b 100644 --- a/lustre/mdc/mdc_locks.c +++ b/lustre/mdc/mdc_locks.c @@ -926,8 +926,8 @@ static int mdc_enqueue_base(struct obd_export *exp, generation = obddev->u.cli.cl_import->imp_generation; if (!it || (it->it_op & (IT_OPEN | IT_CREAT))) - acl_bufsize = MIN(imp->imp_connect_data.ocd_max_easize, - XATTR_SIZE_MAX); + acl_bufsize = min_t(__u32, imp->imp_connect_data.ocd_max_easize, + XATTR_SIZE_MAX); else acl_bufsize = LUSTRE_POSIX_ACL_MAX_SIZE_OLD; @@ -1039,8 +1039,8 @@ resend: acl_bufsize == LUSTRE_POSIX_ACL_MAX_SIZE_OLD) { mdc_clear_replay_flag(req, -ERANGE); ptlrpc_req_finished(req); - acl_bufsize = MIN(imp->imp_connect_data.ocd_max_easize, - XATTR_SIZE_MAX); + acl_bufsize = min_t(__u32, imp->imp_connect_data.ocd_max_easize, + XATTR_SIZE_MAX); goto resend; } diff --git a/lustre/mdc/mdc_request.c b/lustre/mdc/mdc_request.c index b1ccedf..4e503fe 100644 --- a/lustre/mdc/mdc_request.c +++ b/lustre/mdc/mdc_request.c @@ -238,8 +238,9 @@ again: rc = mdc_getattr_common(exp, req); if (rc) { if (rc == -ERANGE) { - acl_bufsize = MIN(imp->imp_connect_data.ocd_max_easize, - XATTR_SIZE_MAX); + acl_bufsize = min_t(__u32, + imp->imp_connect_data.ocd_max_easize, + XATTR_SIZE_MAX); mdc_reset_acl_req(req); goto again; } @@ -293,8 +294,9 @@ again: rc = mdc_getattr_common(exp, req); if (rc) { if (rc == -ERANGE) { - acl_bufsize = MIN(imp->imp_connect_data.ocd_max_easize, - XATTR_SIZE_MAX); + acl_bufsize = min_t(__u32, + imp->imp_connect_data.ocd_max_easize, + XATTR_SIZE_MAX); mdc_reset_acl_req(req); goto again; } diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index 89f7f74..9247abb 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -2585,7 +2585,8 @@ int mdd_create(const struct lu_env *env, struct md_object *pobj, GOTO(out_free, rc = PTR_ERR(handle)); lu_buf_check_and_alloc(&info->mti_xattr_buf, - MIN(mdd->mdd_dt_conf.ddp_max_ea_size, XATTR_SIZE_MAX)); + min_t(unsigned int, mdd->mdd_dt_conf.ddp_max_ea_size, + XATTR_SIZE_MAX)); acl_buf = info->mti_xattr_buf; def_acl_buf.lb_buf = info->mti_key; def_acl_buf.lb_len = sizeof(info->mti_key); diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index 21eae5d..bfc4ae6 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -1443,7 +1443,8 @@ static int mdd_hsm_update_locked(const struct lu_env *env, /* Read HSM attrs from disk */ current_buf = lu_buf_check_and_alloc(&info->mti_xattr_buf, - MIN(mdd_obj2mdd_dev(mdd_obj)->mdd_dt_conf.ddp_max_ea_size, + min_t(unsigned int, + mdd_obj2mdd_dev(mdd_obj)->mdd_dt_conf.ddp_max_ea_size, XATTR_SIZE_MAX)); rc = mdo_xattr_get(env, mdd_obj, current_buf, XATTR_NAME_HSM); rc = lustre_buf2hsm(current_buf->lb_buf, rc, current_mh); diff --git a/lustre/mdd/mdd_permission.c b/lustre/mdd/mdd_permission.c index 2b03de1..0857889 100644 --- a/lustre/mdd/mdd_permission.c +++ b/lustre/mdd/mdd_permission.c @@ -62,8 +62,9 @@ int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode, ENTRY; lu_buf_check_and_alloc(&mdd_env_info(env)->mti_xattr_buf, - MIN(mdd_obj2mdd_dev(o)->mdd_dt_conf.ddp_max_ea_size, - XATTR_SIZE_MAX)); + min_t(unsigned int, + mdd_obj2mdd_dev(o)->mdd_dt_conf.ddp_max_ea_size, + XATTR_SIZE_MAX)); buf = mdd_env_info(env)->mti_xattr_buf; if (buf.lb_buf == NULL) RETURN(-ENOMEM); @@ -217,8 +218,9 @@ static int mdd_check_acl(const struct lu_env *env, struct mdd_object *obj, ENTRY; lu_buf_check_and_alloc(&mdd_env_info(env)->mti_xattr_buf, - MIN(mdd_obj2mdd_dev(obj)->mdd_dt_conf.ddp_max_ea_size, - XATTR_SIZE_MAX)); + min_t(unsigned int, + mdd_obj2mdd_dev(obj)->mdd_dt_conf.ddp_max_ea_size, + XATTR_SIZE_MAX)); buf = mdd_env_info(env)->mti_xattr_buf; if (buf.lb_buf == NULL) RETURN(-ENOMEM); diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 3b6918b..b2b29fd 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -598,8 +598,9 @@ again: buf->lb_buf != info->mti_big_acl) { if (info->mti_big_acl == NULL) { info->mti_big_aclsize = - MIN(mdt->mdt_max_ea_size, - XATTR_SIZE_MAX); + min_t(unsigned int, + mdt->mdt_max_ea_size, + XATTR_SIZE_MAX); OBD_ALLOC_LARGE(info->mti_big_acl, info->mti_big_aclsize); if (info->mti_big_acl == NULL) { diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 6487d72..e5603d5 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -820,7 +820,8 @@ static int mgs_iocontrol_nodemap(const struct lu_env *env, nid = libcfs_str2nid(nidstr); nodemap_test_nid(nid, name_buf, sizeof(name_buf)); rc = copy_to_user(data->ioc_pbuf1, name_buf, - MIN(data->ioc_plen1, sizeof(name_buf))); + min_t(size_t, data->ioc_plen1, + sizeof(name_buf))); if (rc != 0) GOTO(out_lcfg, rc = -EFAULT); break; diff --git a/lustre/obdclass/lu_object.c b/lustre/obdclass/lu_object.c index 9f97180..7ebe04e 100644 --- a/lustre/obdclass/lu_object.c +++ b/lustre/obdclass/lu_object.c @@ -738,7 +738,8 @@ static void lu_object_limit(const struct lu_env *env, return; lu_site_purge_objects(env, dev->ld_site, - MIN(size - nr, LU_CACHE_NR_MAX_ADJUST), 0); + min_t(__u64, size - nr, LU_CACHE_NR_MAX_ADJUST), + 0); } /** diff --git a/lustre/ofd/ofd_objects.c b/lustre/ofd/ofd_objects.c index 8579158..d7ca9f3 100644 --- a/lustre/ofd/ofd_objects.c +++ b/lustre/ofd/ofd_objects.c @@ -621,8 +621,9 @@ int ofd_object_ff_update(const struct lu_env *env, struct ofd_object *fo, ff->ff_layout_version = oa->o_layout_version; ff->ff_range = 0; } else if (oa->o_layout_version > ff->ff_layout_version) { - ff->ff_range = MAX(ff->ff_range, - oa->o_layout_version - ff->ff_layout_version); + ff->ff_range = max_t(__u32, ff->ff_range, + oa->o_layout_version - + ff->ff_layout_version); } } diff --git a/lustre/osc/osc_request.c b/lustre/osc/osc_request.c index a33641d..cf3136e 100644 --- a/lustre/osc/osc_request.c +++ b/lustre/osc/osc_request.c @@ -2214,7 +2214,7 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli, mem_tight |= ext->oe_memalloc; grant += ext->oe_grants; page_count += ext->oe_nr_pages; - layout_version = MAX(layout_version, ext->oe_layout_version); + layout_version = max(layout_version, ext->oe_layout_version); if (obj == NULL) obj = ext->oe_obj; } diff --git a/lustre/osd-zfs/osd_internal.h b/lustre/osd-zfs/osd_internal.h index dd2316a..dde36de 100644 --- a/lustre/osd-zfs/osd_internal.h +++ b/lustre/osd-zfs/osd_internal.h @@ -856,7 +856,8 @@ osd_dmu_object_alloc(objset_t *os, dmu_object_type_t objtype, int blocksize, int dnodesize, dmu_tx_t *tx) { if (dnodesize == 0) - dnodesize = MAX(dmu_objset_dnodesize(os), DNODE_MIN_SIZE); + dnodesize = max_t(int, dmu_objset_dnodesize(os), + DNODE_MIN_SIZE); return dmu_object_alloc_dnsize(os, objtype, blocksize, DMU_OT_SA, DN_BONUS_SIZE(dnodesize), dnodesize, tx); @@ -868,7 +869,8 @@ osd_zap_create_flags(objset_t *os, int normflags, zap_flags_t flags, int indirect_blockshift, int dnodesize, dmu_tx_t *tx) { if (dnodesize == 0) - dnodesize = MAX(dmu_objset_dnodesize(os), DNODE_MIN_SIZE); + dnodesize = max_t(int, dmu_objset_dnodesize(os), + DNODE_MIN_SIZE); return zap_create_flags_dnsize(os, normflags, flags, ot, leaf_blockshift, indirect_blockshift, -- 1.8.3.1