From 6c6ca1fbfb1b2be0e6a9675f9214f98e59bc8088 Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Tue, 29 Oct 2019 23:15:30 +0530 Subject: [PATCH] LU-12923 lustre: Replace CLASSERT() with BUILD_BUG_ON() This patch replaces all CLASSERT() with kernel defined BUILD_BUG_ON() Test-Parameters: trivial Signed-off-by: Arshad Hussain Change-Id: Ic21510ba4f1c99fa0ea6832d240d96ffc7622593 Reviewed-on: https://review.whamcloud.com/36725 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Shaun Tancheff Reviewed-by: Petros Koutoupis Reviewed-by: James Simmons Reviewed-by: Neil Brown --- lnet/klnds/gnilnd/gnilnd.c | 2 +- lnet/klnds/gnilnd/gnilnd_cb.c | 6 ++++-- lnet/klnds/gnilnd/gnilnd_conn.c | 2 +- lnet/klnds/o2iblnd/o2iblnd.c | 26 +++++++++++++------------- lnet/klnds/socklnd/socklnd.c | 4 ++-- lnet/klnds/socklnd/socklnd_cb.c | 2 +- lnet/klnds/socklnd/socklnd_proto.c | 4 ++-- lnet/lnet/acceptor.c | 4 ++-- lnet/lnet/net_fault.c | 8 ++++---- lnet/lnet/router_proc.c | 4 ++-- lnet/selftest/module.c | 14 ++++++++------ lustre/fid/fid_handler.c | 10 +++++----- lustre/llite/dir.c | 6 +++--- lustre/llite/super25.c | 3 ++- lustre/lod/lod_object.c | 2 +- lustre/mgs/mgs_nids.c | 2 +- lustre/obdclass/cl_lock.c | 2 +- lustre/obdclass/md_attrs.c | 8 ++++---- lustre/ofd/ofd_dev.c | 2 +- lustre/osd-ldiskfs/osd_handler.c | 9 +++++---- lustre/osd-ldiskfs/osd_iam_lfix.c | 2 +- lustre/osd-ldiskfs/osd_iam_lvar.c | 2 +- lustre/osd-zfs/osd_handler.c | 8 ++++---- lustre/osd-zfs/osd_object.c | 4 ++-- lustre/osd-zfs/osd_xattr.c | 4 ++-- lustre/ptlrpc/client.c | 3 ++- lustre/ptlrpc/lproc_ptlrpc.c | 2 +- lustre/ptlrpc/nodemap_handler.c | 2 +- lustre/ptlrpc/nodemap_lproc.c | 3 ++- lustre/ptlrpc/nodemap_storage.c | 4 ++-- lustre/ptlrpc/pers.c | 2 +- lustre/utils/create_iam.c | 2 +- 32 files changed, 83 insertions(+), 75 deletions(-) diff --git a/lnet/klnds/gnilnd/gnilnd.c b/lnet/klnds/gnilnd/gnilnd.c index cf1b263e..d1a73a7 100644 --- a/lnet/klnds/gnilnd/gnilnd.c +++ b/lnet/klnds/gnilnd/gnilnd.c @@ -272,7 +272,7 @@ kgnilnd_create_conn(kgn_conn_t **connp, kgn_device_t *dev) conn->gnc_next_tx = (int) GNILND_MAX_MSG_ID - 10; /* if this fails, we have conflicts and MAX_TX is too large */ - CLASSERT(GNILND_MAX_MSG_ID < GNILND_MSGID_CLOSE); + BUILD_BUG_ON(GNILND_MAX_MSG_ID >= GNILND_MSGID_CLOSE); /* get a new unique CQ id for this conn */ write_lock(&kgnilnd_data.kgn_peer_conn_lock); diff --git a/lnet/klnds/gnilnd/gnilnd_cb.c b/lnet/klnds/gnilnd/gnilnd_cb.c index 4e15f7c..c65dfa2 100644 --- a/lnet/klnds/gnilnd/gnilnd_cb.c +++ b/lnet/klnds/gnilnd/gnilnd_cb.c @@ -1150,8 +1150,10 @@ kgnilnd_unmap_buffer(kgn_tx_t *tx, int error) int hold_timeout = 0; /* code below relies on +1 relationship ... */ - CLASSERT(GNILND_BUF_PHYS_MAPPED == (GNILND_BUF_PHYS_UNMAPPED + 1)); - CLASSERT(GNILND_BUF_VIRT_MAPPED == (GNILND_BUF_VIRT_UNMAPPED + 1)); + BUILD_BUG_ON(GNILND_BUF_PHYS_MAPPED != + (GNILND_BUF_PHYS_UNMAPPED + 1)); + BUILD_BUG_ON(GNILND_BUF_VIRT_MAPPED != + (GNILND_BUF_VIRT_UNMAPPED + 1)); switch (tx->tx_buftype) { default: diff --git a/lnet/klnds/gnilnd/gnilnd_conn.c b/lnet/klnds/gnilnd/gnilnd_conn.c index a225780..9090f9e 100644 --- a/lnet/klnds/gnilnd/gnilnd_conn.c +++ b/lnet/klnds/gnilnd/gnilnd_conn.c @@ -733,7 +733,7 @@ kgnilnd_pack_connreq(kgn_connreq_t *connreq, kgn_conn_t *conn, int err = 0; /* ensure we haven't violated max datagram size */ - CLASSERT(sizeof(kgn_connreq_t) <= GNI_DATAGRAM_MAXSIZE); + BUILD_BUG_ON(sizeof(kgn_connreq_t) > GNI_DATAGRAM_MAXSIZE); /* no need to zero out, we do that when allocating dgram */ connreq->gncr_magic = GNILND_MSG_MAGIC; diff --git a/lnet/klnds/o2iblnd/o2iblnd.c b/lnet/klnds/o2iblnd/o2iblnd.c index 44820c0..945f0c8 100644 --- a/lnet/klnds/o2iblnd/o2iblnd.c +++ b/lnet/klnds/o2iblnd/o2iblnd.c @@ -256,8 +256,8 @@ int kiblnd_unpack_msg(struct kib_msg *msg, int nob) if (flip) { /* leave magic unflipped as a clue to peer_ni endianness */ msg->ibm_version = version; - CLASSERT (sizeof(msg->ibm_type) == 1); - CLASSERT (sizeof(msg->ibm_credits) == 1); + BUILD_BUG_ON(sizeof(msg->ibm_type) != 1); + BUILD_BUG_ON(sizeof(msg->ibm_credits) != 1); msg->ibm_nob = msg_nob; __swab64s(&msg->ibm_srcnid); __swab64s(&msg->ibm_srcstamp); @@ -1429,11 +1429,11 @@ kiblnd_map_tx_pool(struct kib_tx_pool *tpo) dev = net->ibn_dev; - /* pre-mapped messages are not bigger than 1 page */ - CLASSERT (IBLND_MSG_SIZE <= PAGE_SIZE); + /* pre-mapped messages are not bigger than 1 page */ + BUILD_BUG_ON(IBLND_MSG_SIZE > PAGE_SIZE); - /* No fancy arithmetic when we do the buffer calculations */ - CLASSERT (PAGE_SIZE % IBLND_MSG_SIZE == 0); + /* No fancy arithmetic when we do the buffer calculations */ + BUILD_BUG_ON(PAGE_SIZE % IBLND_MSG_SIZE != 0); tpo->tpo_hdev = kiblnd_current_hdev(dev); @@ -3373,13 +3373,13 @@ static int __init ko2iblnd_init(void) { int rc; - CLASSERT(sizeof(struct kib_msg) <= IBLND_MSG_SIZE); - CLASSERT(offsetof(struct kib_msg, - ibm_u.get.ibgm_rd.rd_frags[IBLND_MAX_RDMA_FRAGS]) <= - IBLND_MSG_SIZE); - CLASSERT(offsetof(struct kib_msg, - ibm_u.putack.ibpam_rd.rd_frags[IBLND_MAX_RDMA_FRAGS]) - <= IBLND_MSG_SIZE); + BUILD_BUG_ON(sizeof(struct kib_msg) > IBLND_MSG_SIZE); + BUILD_BUG_ON(offsetof(struct kib_msg, + ibm_u.get.ibgm_rd.rd_frags[IBLND_MAX_RDMA_FRAGS]) > + IBLND_MSG_SIZE); + BUILD_BUG_ON(offsetof(struct kib_msg, + ibm_u.putack.ibpam_rd.rd_frags[IBLND_MAX_RDMA_FRAGS]) > + IBLND_MSG_SIZE); rc = kiblnd_tunables_init(); if (rc != 0) diff --git a/lnet/klnds/socklnd/socklnd.c b/lnet/klnds/socklnd/socklnd.c index 6fd707c..d4eb06b 100644 --- a/lnet/klnds/socklnd/socklnd.c +++ b/lnet/klnds/socklnd/socklnd.c @@ -2825,8 +2825,8 @@ static int __init ksocklnd_init(void) int rc; /* check ksnr_connected/connecting field large enough */ - CLASSERT(SOCKLND_CONN_NTYPES <= 4); - CLASSERT(SOCKLND_CONN_ACK == SOCKLND_CONN_BULK_IN); + BUILD_BUG_ON(SOCKLND_CONN_NTYPES > 4); + BUILD_BUG_ON(SOCKLND_CONN_ACK != SOCKLND_CONN_BULK_IN); /* initialize the_ksocklnd */ the_ksocklnd.lnd_type = SOCKLND; diff --git a/lnet/klnds/socklnd/socklnd_cb.c b/lnet/klnds/socklnd/socklnd_cb.c index f7b39b7..2cda73c 100644 --- a/lnet/klnds/socklnd/socklnd_cb.c +++ b/lnet/klnds/socklnd/socklnd_cb.c @@ -1733,7 +1733,7 @@ ksocknal_parse_proto_version (struct ksock_hello_msg *hello) if (hello->kshm_magic == le32_to_cpu(LNET_PROTO_TCP_MAGIC)) { struct lnet_magicversion *hmv; - CLASSERT(sizeof(struct lnet_magicversion) == + BUILD_BUG_ON(sizeof(struct lnet_magicversion) != offsetof(struct ksock_hello_msg, kshm_src_nid)); hmv = (struct lnet_magicversion *)hello; diff --git a/lnet/klnds/socklnd/socklnd_proto.c b/lnet/klnds/socklnd/socklnd_proto.c index e0fd857..de34b51 100644 --- a/lnet/klnds/socklnd/socklnd_proto.c +++ b/lnet/klnds/socklnd/socklnd_proto.c @@ -457,8 +457,8 @@ ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello) int rc; int i; - CLASSERT(sizeof(struct lnet_magicversion) == - offsetof(struct lnet_hdr, src_nid)); + BUILD_BUG_ON(sizeof(struct lnet_magicversion) != + offsetof(struct lnet_hdr, src_nid)); LIBCFS_ALLOC(hdr, sizeof(*hdr)); if (hdr == NULL) { diff --git a/lnet/lnet/acceptor.c b/lnet/lnet/acceptor.c index 5be1dd8..232018b 100644 --- a/lnet/lnet/acceptor.c +++ b/lnet/lnet/acceptor.c @@ -159,7 +159,7 @@ lnet_connect(struct socket **sockp, lnet_nid_t peer_nid, int port; int fatal; - CLASSERT(sizeof(cr) <= 16); /* not too big to be on the stack */ + BUILD_BUG_ON(sizeof(cr) > 16); /* not too big to be on the stack */ for (port = LNET_ACCEPTOR_MAX_RESERVED_PORT; port >= LNET_ACCEPTOR_MIN_RESERVED_PORT; @@ -175,7 +175,7 @@ lnet_connect(struct socket **sockp, lnet_nid_t peer_nid, continue; } - CLASSERT(LNET_PROTO_ACCEPTOR_VERSION == 1); + BUILD_BUG_ON(LNET_PROTO_ACCEPTOR_VERSION != 1); cr.acr_magic = LNET_PROTO_ACCEPTOR_MAGIC; cr.acr_version = LNET_PROTO_ACCEPTOR_VERSION; diff --git a/lnet/lnet/net_fault.c b/lnet/lnet/net_fault.c index ce68063..3af39dc 100644 --- a/lnet/lnet/net_fault.c +++ b/lnet/lnet/net_fault.c @@ -1080,10 +1080,10 @@ lnet_fault_ctl(int opc, struct libcfs_ioctl_data *data) int lnet_fault_init(void) { - CLASSERT(LNET_PUT_BIT == 1 << LNET_MSG_PUT); - CLASSERT(LNET_ACK_BIT == 1 << LNET_MSG_ACK); - CLASSERT(LNET_GET_BIT == 1 << LNET_MSG_GET); - CLASSERT(LNET_REPLY_BIT == 1 << LNET_MSG_REPLY); + BUILD_BUG_ON(LNET_PUT_BIT != 1 << LNET_MSG_PUT); + BUILD_BUG_ON(LNET_ACK_BIT != 1 << LNET_MSG_ACK); + BUILD_BUG_ON(LNET_GET_BIT != 1 << LNET_MSG_GET); + BUILD_BUG_ON(LNET_REPLY_BIT != 1 << LNET_MSG_REPLY); mutex_init(&delay_dd.dd_mutex); spin_lock_init(&delay_dd.dd_lock); diff --git a/lnet/lnet/router_proc.c b/lnet/lnet/router_proc.c index 23ec36e..2a47ee6 100644 --- a/lnet/lnet/router_proc.c +++ b/lnet/lnet/router_proc.c @@ -148,7 +148,7 @@ proc_lnet_routes(struct ctl_table *table, int write, void __user *buffer, int ver; int off; - CLASSERT(sizeof(loff_t) >= 4); + BUILD_BUG_ON(sizeof(loff_t) < 4); off = LNET_PROC_HOFF_GET(*ppos); ver = LNET_PROC_VER_GET(*ppos); @@ -407,7 +407,7 @@ proc_lnet_peers(struct ctl_table *table, int write, void __user *buffer, if (*lenp == 0) return 0; - CLASSERT(LNET_PROC_HASH_BITS >= LNET_PEER_HASH_BITS); + BUILD_BUG_ON(LNET_PROC_HASH_BITS < LNET_PEER_HASH_BITS); if (cpt >= LNET_CPT_NUMBER) { *lenp = 0; diff --git a/lnet/selftest/module.c b/lnet/selftest/module.c index 5324957..a6a06d1 100644 --- a/lnet/selftest/module.c +++ b/lnet/selftest/module.c @@ -90,12 +90,14 @@ lnet_selftest_exit(void) void lnet_selftest_structure_assertion(void) { - CLASSERT(sizeof(struct srpc_msg) == 160); - CLASSERT(sizeof(struct srpc_test_reqst) == 70); - CLASSERT(offsetof(struct srpc_msg, msg_body.tes_reqst.tsr_concur) == 72); - CLASSERT(offsetof(struct srpc_msg, msg_body.tes_reqst.tsr_ndest) == 78); - CLASSERT(sizeof(struct srpc_stat_reply) == 136); - CLASSERT(sizeof(struct srpc_stat_reqst) == 28); + BUILD_BUG_ON(sizeof(struct srpc_msg) != 160); + BUILD_BUG_ON(sizeof(struct srpc_test_reqst) != 70); + BUILD_BUG_ON(offsetof(struct srpc_msg, msg_body.tes_reqst.tsr_concur) != + 72); + BUILD_BUG_ON(offsetof(struct srpc_msg, msg_body.tes_reqst.tsr_ndest) != + 78); + BUILD_BUG_ON(sizeof(struct srpc_stat_reply) != 136); + BUILD_BUG_ON(sizeof(struct srpc_stat_reqst) != 28); } static int __init diff --git a/lustre/fid/fid_handler.c b/lustre/fid/fid_handler.c index 12b708d..1d9b560 100644 --- a/lustre/fid/fid_handler.c +++ b/lustre/fid/fid_handler.c @@ -516,15 +516,15 @@ int seq_server_init(const struct lu_env *env, LASSERT(ss != NULL); LASSERT(ss->ss_lu != NULL); - /* A compile-time check for FIDs that used to be in lustre_idl.h - * but is moved here to remove CLASSERT/LASSERT in that header. + /* * Check all lu_fid fields are converted in fid_cpu_to_le() and friends - * and that there is no padding added by compiler to the struct. */ + * and that there is no padding added by compiler to the struct. + */ { struct lu_fid tst; - CLASSERT(sizeof(tst) == sizeof(tst.f_seq) + - sizeof(tst.f_oid) + sizeof(tst.f_ver)); + BUILD_BUG_ON(sizeof(tst) != sizeof(tst.f_seq) + + sizeof(tst.f_oid) + sizeof(tst.f_ver)); } seq->lss_cli = NULL; diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index ace18b5..328cf4c 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -1466,9 +1466,9 @@ lmv_out_free: int set_default = 0; - CLASSERT(sizeof(struct lov_user_md_v3) > - sizeof(struct lov_comp_md_v1)); - CLASSERT(sizeof(*lumv3) == sizeof(*lumv3p)); + BUILD_BUG_ON(sizeof(struct lov_user_md_v3) <= + sizeof(struct lov_comp_md_v1)); + BUILD_BUG_ON(sizeof(*lumv3) != sizeof(*lumv3p)); /* first try with v1 which is smaller than v3 */ if (copy_from_user(&lumv1, lumv1p, sizeof(lumv1))) RETURN(-EFAULT); diff --git a/lustre/llite/super25.c b/lustre/llite/super25.c index dce25a7..2a510ef 100644 --- a/lustre/llite/super25.c +++ b/lustre/llite/super25.c @@ -88,7 +88,8 @@ static int __init lustre_init(void) int i, rc; unsigned long lustre_inode_cache_flags; - CLASSERT(sizeof(LUSTRE_VOLATILE_HDR) == LUSTRE_VOLATILE_HDR_LEN + 1); + BUILD_BUG_ON(sizeof(LUSTRE_VOLATILE_HDR) != + LUSTRE_VOLATILE_HDR_LEN + 1); /* print an address of _any_ initialized kernel symbol from this * module, to allow debugging with gdb that doesn't support data diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index f25a490..25ae4b2 100644 --- a/lustre/lod/lod_object.c +++ b/lustre/lod/lod_object.c @@ -1505,7 +1505,7 @@ static int lod_xattr_get(const struct lu_env *env, struct dt_object *dt, RETURN(rc = rc > 0 ? -EINVAL : rc); if (buf->lb_buf == NULL || buf->lb_len == 0) { - CLASSERT(sizeof(*lmv1) <= sizeof(info->lti_key)); + BUILD_BUG_ON(sizeof(*lmv1) > sizeof(info->lti_key)); /* lti_buf is large enough for *lmv1 or a short * (<= sizeof(struct lmv_mds_md_v1)) foreign LMV diff --git a/lustre/mgs/mgs_nids.c b/lustre/mgs/mgs_nids.c index 2da7902..1e19589 100644 --- a/lustre/mgs/mgs_nids.c +++ b/lustre/mgs/mgs_nids.c @@ -427,7 +427,7 @@ static int mgs_ir_notify(void *arg) struct ldlm_res_id resid; char name[sizeof(fsdb->fsdb_name) + 16]; - CLASSERT(sizeof(name) < 40); /* name is too large to be on stack */ + BUILD_BUG_ON(sizeof(name) >= 40); /* name is too large to be on stack */ snprintf(name, sizeof(name) - 1, "mgs_%s_notify", fsdb->fsdb_name); complete(&fsdb->fsdb_notify_comp); diff --git a/lustre/obdclass/cl_lock.c b/lustre/obdclass/cl_lock.c index ba8126f..692ad18 100644 --- a/lustre/obdclass/cl_lock.c +++ b/lustre/obdclass/cl_lock.c @@ -247,7 +247,7 @@ const char *cl_lock_mode_name(const enum cl_lock_mode mode) [CLM_WRITE] = "W", [CLM_GROUP] = "G" }; - CLASSERT(CLM_MAX == ARRAY_SIZE(names)); + BUILD_BUG_ON(CLM_MAX != ARRAY_SIZE(names)); return names[mode]; } EXPORT_SYMBOL(cl_lock_mode_name); diff --git a/lustre/obdclass/md_attrs.c b/lustre/obdclass/md_attrs.c index d0ca4f1..fe8fca5 100644 --- a/lustre/obdclass/md_attrs.c +++ b/lustre/obdclass/md_attrs.c @@ -47,9 +47,9 @@ void lustre_lma_init(struct lustre_mdt_attrs *lma, const struct lu_fid *fid, /* If a field is added in struct lustre_mdt_attrs, zero it explicitly * and change the test below. */ - CLASSERT(sizeof(*lma) == - (offsetof(struct lustre_mdt_attrs, lma_self_fid) + - sizeof(lma->lma_self_fid))); + BUILD_BUG_ON(sizeof(*lma) != + (offsetof(struct lustre_mdt_attrs, lma_self_fid) + + sizeof(lma->lma_self_fid))); } EXPORT_SYMBOL(lustre_lma_init); @@ -71,7 +71,7 @@ EXPORT_SYMBOL(lustre_lma_swab); void lustre_loa_init(struct lustre_ost_attrs *loa, const struct lu_fid *fid, __u32 compat, __u32 incompat) { - CLASSERT(sizeof(*loa) == LMA_OLD_SIZE); + BUILD_BUG_ON(sizeof(*loa) != LMA_OLD_SIZE); memset(&loa->loa_parent_fid, 0, sizeof(*loa) - offsetof(typeof(*loa), loa_parent_fid)); diff --git a/lustre/ofd/ofd_dev.c b/lustre/ofd/ofd_dev.c index 30f6590..dcfeb85 100644 --- a/lustre/ofd/ofd_dev.c +++ b/lustre/ofd/ofd_dev.c @@ -1955,7 +1955,7 @@ static int ofd_punch_hdl(struct tgt_session_info *tsi) OBD_FAIL_TIMEOUT(OBD_FAIL_OST_PAUSE_PUNCH, cfs_fail_val); /* check that we do support OBD_CONNECT_TRUNCLOCK. */ - CLASSERT(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK); + BUILD_BUG_ON(!(OST_CONNECT_SUPPORTED & OBD_CONNECT_TRUNCLOCK)); if ((oa->o_valid & (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) != (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS)) diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 2edbbeb..5710374 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -2223,7 +2223,7 @@ int osd_statfs(const struct lu_env *env, struct dt_device *d, * * Reserve 0.78% of total space, at least 8MB for small filesystems. */ - CLASSERT(OSD_STATFS_RESERVED > LDISKFS_MAX_BLOCK_SIZE); + BUILD_BUG_ON(OSD_STATFS_RESERVED <= LDISKFS_MAX_BLOCK_SIZE); reserved = OSD_STATFS_RESERVED >> sb->s_blocksize_bits; if (likely(sfs->os_blocks >= reserved << OSD_STATFS_RESERVED_SHIFT)) reserved = sfs->os_blocks >> OSD_STATFS_RESERVED_SHIFT; @@ -3826,7 +3826,7 @@ static struct inode *osd_create_local_agent_inode(const struct lu_env *env, * debugging if we need to determine where this symlink came from. */ if (S_ISLNK(type)) { - CLASSERT(LDISKFS_N_BLOCKS * 4 >= FID_LEN + 1); + BUILD_BUG_ON(LDISKFS_N_BLOCKS * 4 < FID_LEN + 1); rc = snprintf((char *)LDISKFS_I(local)->i_data, LDISKFS_N_BLOCKS * 4, DFID, PFID(fid)); @@ -8183,10 +8183,11 @@ static int __init osd_init(void) struct kobject *kobj; int rc; - CLASSERT(BH_DXLock < sizeof(((struct buffer_head *)0)->b_state) * 8); + BUILD_BUG_ON(BH_DXLock >= + sizeof(((struct buffer_head *)0)->b_state) * 8); #if !defined(CONFIG_DEBUG_MUTEXES) && !defined(CONFIG_DEBUG_SPINLOCK) /* please, try to keep osd_thread_info smaller than a page */ - CLASSERT(sizeof(struct osd_thread_info) <= PAGE_SIZE); + BUILD_BUG_ON(sizeof(struct osd_thread_info) > PAGE_SIZE); #endif osd_oi_mod_init(); diff --git a/lustre/osd-ldiskfs/osd_iam_lfix.c b/lustre/osd-ldiskfs/osd_iam_lfix.c index 5d44a33..ef1906b 100644 --- a/lustre/osd-ldiskfs/osd_iam_lfix.c +++ b/lustre/osd-ldiskfs/osd_iam_lfix.c @@ -757,7 +757,7 @@ void iam_lfix_format_init(void) #define STORE_UNALIGNED(val, dst) \ ({ \ typeof(val) __val = (val); \ - CLASSERT(sizeof(val) == sizeof(*(dst))); \ + BUILD_BUG_ON(sizeof(val) != sizeof(*(dst))); \ memcpy(dst, &__val, sizeof(*(dst))); \ }) diff --git a/lustre/osd-ldiskfs/osd_iam_lvar.c b/lustre/osd-ldiskfs/osd_iam_lvar.c index 38943f3..031cd33 100644 --- a/lustre/osd-ldiskfs/osd_iam_lvar.c +++ b/lustre/osd-ldiskfs/osd_iam_lvar.c @@ -111,7 +111,7 @@ enum { static inline int getsize(const struct iam_leaf *leaf, int namelen, int recsize) { - CLASSERT(!(LVAR_PAD & (LVAR_PAD - 1))); + BUILD_BUG_ON((LVAR_PAD & (LVAR_PAD - 1))); return (offsetof(struct lvar_leaf_entry, vle_key) + namelen + recsize + LVAR_ROUND) & ~LVAR_ROUND; diff --git a/lustre/osd-zfs/osd_handler.c b/lustre/osd-zfs/osd_handler.c index 078eb34..4e23ba1 100644 --- a/lustre/osd-zfs/osd_handler.c +++ b/lustre/osd-zfs/osd_handler.c @@ -411,8 +411,8 @@ uint64_t osd_objs_count_estimate(uint64_t usedbytes, uint64_t usedobjs, * gradually disappears as the number of real dnodes grows. It also * avoids the need to check for divide-by-zero computing dn_per_block. */ - CLASSERT(OSD_DNODE_MIN_BLKSHIFT > 0); - CLASSERT(OSD_DNODE_EST_BLKSHIFT > 0); + BUILD_BUG_ON(OSD_DNODE_MIN_BLKSHIFT <= 0); + BUILD_BUG_ON(OSD_DNODE_EST_BLKSHIFT <= 0); est_usedblocks = ((OSD_DNODE_EST_COUNT << OSD_DNODE_EST_BLKSHIFT) + usedbytes) >> est_maxblockshift; @@ -513,7 +513,7 @@ static int osd_objset_statfs(struct osd_device *osd, struct obd_statfs *osfs) * Reserve 0.78% of total space, at least 16MB for small filesystems, * for internal files to be created/unlinked when space is tight. */ - CLASSERT(OSD_STATFS_RESERVED_SIZE > 0); + BUILD_BUG_ON(OSD_STATFS_RESERVED_SIZE <= 0); reserved = OSD_STATFS_RESERVED_SIZE >> bshift; if (likely(osfs->os_blocks >= reserved << OSD_STATFS_RESERVED_SHIFT)) reserved = osfs->os_blocks >> OSD_STATFS_RESERVED_SHIFT; @@ -585,7 +585,7 @@ static int osd_blk_insert_cost(struct osd_device *osd) /* nr_blkptrshift is the log2 of the number of block pointers that can * be stored in an indirect block */ - CLASSERT(DN_MAX_INDBLKSHIFT > SPA_BLKPTRSHIFT); + BUILD_BUG_ON(DN_MAX_INDBLKSHIFT <= SPA_BLKPTRSHIFT); nr_blkptrshift = DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT; /* max_blockshift / nr_blkptrshift is thus the maximum depth of the diff --git a/lustre/osd-zfs/osd_object.c b/lustre/osd-zfs/osd_object.c index ca0db0f..d2b2f03 100644 --- a/lustre/osd-zfs/osd_object.c +++ b/lustre/osd-zfs/osd_object.c @@ -455,7 +455,7 @@ static int osd_check_lma(const struct lu_env *env, struct osd_object *obj) const struct lu_fid *rfid = lu_object_fid(&obj->oo_dt.do_lu); ENTRY; - CLASSERT(sizeof(info->oti_buf) >= sizeof(*lma)); + BUILD_BUG_ON(sizeof(info->oti_buf) < sizeof(*lma)); lma = (struct lustre_mdt_attrs *)info->oti_buf; buf.lb_buf = lma; buf.lb_len = sizeof(info->oti_buf); @@ -1300,7 +1300,7 @@ static int osd_attr_set(const struct lu_env *env, struct dt_object *dt, if (la->la_flags & LUSTRE_LMA_FL_MASKS) { LASSERT(!obj->oo_pfid_in_lma); - CLASSERT(sizeof(info->oti_buf) >= sizeof(*lma)); + BUILD_BUG_ON(sizeof(info->oti_buf) < sizeof(*lma)); lma = (struct lustre_mdt_attrs *)&info->oti_buf; buf.lb_buf = lma; buf.lb_len = sizeof(info->oti_buf); diff --git a/lustre/osd-zfs/osd_xattr.c b/lustre/osd-zfs/osd_xattr.c index ab4d683..4683a17 100644 --- a/lustre/osd-zfs/osd_xattr.c +++ b/lustre/osd-zfs/osd_xattr.c @@ -240,7 +240,7 @@ static int osd_get_pfid_from_lma(const struct lu_env *env, int rc; ENTRY; - CLASSERT(sizeof(info->oti_buf) >= sizeof(*loa)); + BUILD_BUG_ON(sizeof(info->oti_buf) < sizeof(*loa)); rc = osd_xattr_get_internal(env, obj, &tbuf, XATTR_NAME_LMA, sizep); if (rc) @@ -777,7 +777,7 @@ static int osd_xattr_split_pfid(const struct lu_env *env, int rc; ENTRY; - CLASSERT(sizeof(info->oti_buf) >= sizeof(*loa)); + BUILD_BUG_ON(sizeof(info->oti_buf) < sizeof(*loa)); rc = osd_xattr_get_internal(env, obj, &buf, XATTR_NAME_LMA, &size); if (rc) RETURN(rc); diff --git a/lustre/ptlrpc/client.c b/lustre/ptlrpc/client.c index 94bae92..eccf0a8 100644 --- a/lustre/ptlrpc/client.c +++ b/lustre/ptlrpc/client.c @@ -3370,7 +3370,8 @@ void ptlrpc_init_xid(void) } /* Need to always be aligned to a power-of-two for mutli-bulk BRW */ - CLASSERT((PTLRPC_BULK_OPS_COUNT & (PTLRPC_BULK_OPS_COUNT - 1)) == 0); + BUILD_BUG_ON((PTLRPC_BULK_OPS_COUNT & (PTLRPC_BULK_OPS_COUNT - 1)) != + 0); xid &= PTLRPC_BULK_OPS_MASK; atomic64_set(&ptlrpc_last_xid, xid); } diff --git a/lustre/ptlrpc/lproc_ptlrpc.c b/lustre/ptlrpc/lproc_ptlrpc.c index 08039c2..266e1c1 100644 --- a/lustre/ptlrpc/lproc_ptlrpc.c +++ b/lustre/ptlrpc/lproc_ptlrpc.c @@ -517,7 +517,7 @@ void nrs_policy_get_info_locked(struct ptlrpc_nrs_policy *policy, LASSERT(info != NULL); assert_spin_locked(&policy->pol_nrs->nrs_lock); - CLASSERT(sizeof(info->pi_arg) == sizeof(policy->pol_arg)); + BUILD_BUG_ON(sizeof(info->pi_arg) != sizeof(policy->pol_arg)); memcpy(info->pi_name, policy->pol_desc->pd_name, NRS_POL_NAME_MAX); memcpy(info->pi_arg, policy->pol_arg, sizeof(policy->pol_arg)); diff --git a/lustre/ptlrpc/nodemap_handler.c b/lustre/ptlrpc/nodemap_handler.c index 0443c3b..6cea792 100644 --- a/lustre/ptlrpc/nodemap_handler.c +++ b/lustre/ptlrpc/nodemap_handler.c @@ -994,7 +994,7 @@ static int nodemap_validate_sepol(const char *sepol) unsigned char mode; unsigned short ver; - CLASSERT(sizeof(buf) == sizeof(((struct lu_nodemap *)0)->nm_sepol)); + BUILD_BUG_ON(sizeof(buf) != sizeof(((struct lu_nodemap *)0)->nm_sepol)); if (sepol == NULL) return -EINVAL; diff --git a/lustre/ptlrpc/nodemap_lproc.c b/lustre/ptlrpc/nodemap_lproc.c index 8167883..62a053f 100644 --- a/lustre/ptlrpc/nodemap_lproc.c +++ b/lustre/ptlrpc/nodemap_lproc.c @@ -286,7 +286,8 @@ nodemap_sepol_seq_write(struct file *file, char sepol[LUSTRE_NODEMAP_SEPOL_LENGTH + 1]; int rc = 0; - CLASSERT(sizeof(sepol) == sizeof(((struct lu_nodemap *)0)->nm_sepol)); + BUILD_BUG_ON(sizeof(sepol) != + sizeof(((struct lu_nodemap *)0)->nm_sepol)); if (count > 0) { if (count >= sizeof(sepol)) diff --git a/lustre/ptlrpc/nodemap_storage.c b/lustre/ptlrpc/nodemap_storage.c index 1b522a1..ea72c87 100644 --- a/lustre/ptlrpc/nodemap_storage.c +++ b/lustre/ptlrpc/nodemap_storage.c @@ -87,7 +87,7 @@ static void nodemap_cluster_key_init(struct nodemap_key *nk, unsigned int nm_id) static void nodemap_cluster_rec_init(union nodemap_rec *nr, const struct lu_nodemap *nodemap) { - CLASSERT(sizeof(nr->ncr.ncr_name) == sizeof(nodemap->nm_name)); + BUILD_BUG_ON(sizeof(nr->ncr.ncr_name) != sizeof(nodemap->nm_name)); strncpy(nr->ncr.ncr_name, nodemap->nm_name, sizeof(nr->ncr.ncr_name)); nr->ncr.ncr_squash_uid = cpu_to_le32(nodemap->nm_squash_uid); @@ -671,7 +671,7 @@ static int nodemap_process_keyrec(struct nodemap_config *config, ENTRY; - CLASSERT(sizeof(union nodemap_rec) == 32); + BUILD_BUG_ON(sizeof(union nodemap_rec) != 32); nodemap_id = le32_to_cpu(key->nk_nodemap_id); type = nodemap_get_key_type(key); diff --git a/lustre/ptlrpc/pers.c b/lustre/ptlrpc/pers.c index 51e17e2..e899d79 100644 --- a/lustre/ptlrpc/pers.c +++ b/lustre/ptlrpc/pers.c @@ -44,7 +44,7 @@ void ptlrpc_fill_bulk_md(struct lnet_md *md, struct ptlrpc_bulk_desc *desc, int mdidx) { - CLASSERT(PTLRPC_MAX_BRW_PAGES < LI_POISON); + BUILD_BUG_ON(PTLRPC_MAX_BRW_PAGES >= LI_POISON); LASSERT(mdidx < desc->bd_md_max_brw); LASSERT(desc->bd_iov_count <= PTLRPC_MAX_BRW_PAGES); diff --git a/lustre/utils/create_iam.c b/lustre/utils/create_iam.c index dc544d0..9d08bc0 100644 --- a/lustre/utils/create_iam.c +++ b/lustre/utils/create_iam.c @@ -115,7 +115,7 @@ enum { ({ \ typeof(val) __val = (val); \ \ - CLASSERT(sizeof(val) == sizeof(*(dst))); \ + BUILD_BUG_ON(sizeof(val) != sizeof(*(dst))); \ memcpy(dst, &__val, sizeof(*(dst))); \ }) -- 1.8.3.1