From 2fbf36f5e3890d8b560b5682931999f229021b2d Mon Sep 17 00:00:00 2001 From: Dmitry Eremin Date: Mon, 4 Aug 2014 16:18:02 +0400 Subject: [PATCH] LU-5417 lod: fix comparison between signed and unsigned Make few members/variables related to size or indexes as unsigned. Fix incorrect comparison between signed and unsigned variables. Signed-off-by: Dmitry Eremin Change-Id: I1bb3dff189e5ad4f37c7696ffd51832af60bd8f1 Reviewed-on: http://review.whamcloud.com/11316 Tested-by: Jenkins Reviewed-by: John L. Hammond Reviewed-by: Fan Yong Tested-by: Maloo Reviewed-by: Oleg Drokin --- libcfs/include/libcfs/bitmap.h | 6 ++--- lustre/lfsck/lfsck_internal.h | 2 +- lustre/lod/lod_dev.c | 11 ++++++---- lustre/lod/lod_internal.h | 6 ++--- lustre/lod/lod_lov.c | 21 +++++++++--------- lustre/lod/lod_object.c | 35 +++++++++++++++-------------- lustre/lod/lod_pool.c | 14 +++++++----- lustre/lod/lod_qos.c | 50 +++++++++++++++++++++++------------------- lustre/lod/lproc_lod.c | 3 ++- 9 files changed, 81 insertions(+), 67 deletions(-) diff --git a/libcfs/include/libcfs/bitmap.h b/libcfs/include/libcfs/bitmap.h index 1ef4db7..c74726b 100644 --- a/libcfs/include/libcfs/bitmap.h +++ b/libcfs/include/libcfs/bitmap.h @@ -45,8 +45,8 @@ #endif typedef struct { - int size; - unsigned long data[0]; + unsigned int size; + unsigned long data[0]; } cfs_bitmap_t; #define CFS_BITMAP_SIZE(nbits) \ @@ -102,7 +102,7 @@ int cfs_bitmap_check_empty(cfs_bitmap_t *bitmap) static inline void cfs_bitmap_copy(cfs_bitmap_t *new, cfs_bitmap_t *old) { - int newsize; + size_t newsize; LASSERT(new->size >= old->size); newsize = new->size; diff --git a/lustre/lfsck/lfsck_internal.h b/lustre/lfsck/lfsck_internal.h index 36259fa..29a24d4 100644 --- a/lustre/lfsck/lfsck_internal.h +++ b/lustre/lfsck/lfsck_internal.h @@ -371,7 +371,7 @@ struct lfsck_tgt_descs { struct list_head ltd_orphan; /* number of registered TGTs */ - int ltd_tgtnr; + __u32 ltd_tgtnr; }; #define LTD_TGT(ltd, index) \ diff --git a/lustre/lod/lod_dev.c b/lustre/lod/lod_dev.c index 9ab7972..3a9fdee 100644 --- a/lustre/lod/lod_dev.c +++ b/lustre/lod/lod_dev.c @@ -142,7 +142,7 @@ static int lod_cleanup_desc_tgts(const struct lu_env *env, { struct lu_device *next; int rc = 0; - int i; + unsigned int i; lod_getref(ltd); if (ltd->ltd_tgts_size <= 0) { @@ -335,7 +335,8 @@ static int lod_recovery_complete(const struct lu_env *env, { struct lod_device *lod = lu2lod_dev(dev); struct lu_device *next = &lod->lod_child->dd_lu_dev; - int i, rc; + unsigned int i; + int rc; ENTRY; LASSERT(lod->lod_recovery_completed == 0); @@ -469,7 +470,8 @@ static int lod_sync(const struct lu_env *env, struct dt_device *dev) { struct lod_device *lod = dt2lod_dev(dev); struct lod_ost_desc *ost; - int rc = 0, i; + unsigned int i; + int rc = 0; ENTRY; lod_getref(&lod->lod_ost_descs); @@ -853,7 +855,8 @@ static int lod_obd_get_info(const struct lu_env *env, struct obd_export *exp, struct obd_device *obd = exp->exp_obd; struct lod_device *d; struct lod_ost_desc *ost; - int i, rc = 1; + unsigned int i; + int rc = 1; if (!obd->obd_set_up || obd->obd_stopping) RETURN(-EAGAIN); diff --git a/lustre/lod/lod_internal.h b/lustre/lod/lod_internal.h index 22d248c..ce1fd8b 100644 --- a/lustre/lod/lod_internal.h +++ b/lustre/lod/lod_internal.h @@ -136,7 +136,7 @@ struct lod_tgt_descs { /* Size of the lod_tgts array, granted to be a power of 2 */ __u32 ltd_tgts_size; /* number of registered TGTs */ - int ltd_tgtnr; + __u32 ltd_tgtnr; /* bitmap of TGTs available */ cfs_bitmap_t *ltd_tgt_bitmap; /* TGTs scheduled to be deleted */ @@ -270,7 +270,7 @@ struct lod_it { struct lod_thread_info { /* per-thread buffer for LOV EA */ void *lti_ea_store; - int lti_ea_store_size; + __u32 lti_ea_store_size; /* per-thread buffer for LMV EA */ struct lu_buf lti_buf; struct ost_id lti_ostid; @@ -431,7 +431,7 @@ int lod_verify_striping(struct lod_device *d, const struct lu_buf *buf, bool is_from_disk); int lod_generate_and_set_lovea(const struct lu_env *env, struct lod_object *mo, struct thandle *th); -int lod_ea_store_resize(struct lod_thread_info *info, int size); +int lod_ea_store_resize(struct lod_thread_info *info, size_t size); /* lod_pool.c */ int lod_ost_pool_add(struct ost_pool *op, __u32 idx, unsigned int min_count); int lod_ost_pool_remove(struct ost_pool *op, __u32 idx); diff --git a/lustre/lod/lod_lov.c b/lustre/lod/lod_lov.c index 80e96cd..924780c 100644 --- a/lustre/lod/lod_lov.c +++ b/lustre/lod/lod_lov.c @@ -67,7 +67,7 @@ void lod_putref(struct lod_device *lod, struct lod_tgt_descs *ltd) ltd->ltd_refcount--; if (ltd->ltd_refcount == 0 && ltd->ltd_death_row) { struct lod_tgt_desc *tgt_desc, *tmp; - int idx; + unsigned int idx; CFS_LIST_HEAD(kill); CDEBUG(D_CONFIG, "destroying %d ltd desc\n", @@ -394,7 +394,7 @@ static void __lod_del_device(const struct lu_env *env, struct lod_device *lod, int lod_fini_tgt(const struct lu_env *env, struct lod_device *lod, struct lod_tgt_descs *ltd, bool for_ost) { - int idx; + unsigned int idx; if (ltd->ltd_tgts_size <= 0) return 0; @@ -479,9 +479,9 @@ out: return(rc); } -int lod_ea_store_resize(struct lod_thread_info *info, int size) +int lod_ea_store_resize(struct lod_thread_info *info, size_t size) { - int round = size_roundup_power2(size); + __u32 round = size_roundup_power2(size); LASSERT(round <= lov_mds_md_size(LOV_MAX_STRIPE_COUNT, LOV_MAGIC_V3)); @@ -514,8 +514,8 @@ int lod_generate_and_set_lovea(const struct lu_env *env, struct lov_mds_md_v1 *lmm; struct lov_ost_data_v1 *objs; __u32 magic; - int i, rc, lmm_size; - int cplen = 0; + int i, rc; + size_t lmm_size; ENTRY; LASSERT(lo); @@ -548,7 +548,7 @@ int lod_generate_and_set_lovea(const struct lu_env *env, objs = &lmm->lmm_objects[0]; } else { struct lov_mds_md_v3 *v3 = (struct lov_mds_md_v3 *) lmm; - cplen = strlcpy(v3->lmm_pool_name, lo->ldo_pool, + size_t cplen = strlcpy(v3->lmm_pool_name, lo->ldo_pool, sizeof(v3->lmm_pool_name)); if (cplen >= sizeof(v3->lmm_pool_name)) RETURN(-E2BIG); @@ -688,7 +688,7 @@ int lod_store_def_striping(const struct lu_env *env, struct dt_object *dt, RETURN(rc); } -static int validate_lod_and_idx(struct lod_device *md, int idx) +static int validate_lod_and_idx(struct lod_device *md, __u32 idx) { if (unlikely(idx >= md->lod_ost_descs.ltd_tgts_size || !cfs_bitmap_check(md->lod_ost_bitmap, idx))) { @@ -725,7 +725,8 @@ int lod_initialize_objects(const struct lu_env *env, struct lod_object *lo, struct lu_device *nd; struct dt_object **stripe; int stripe_len; - int i, idx, rc = 0; + int i, rc = 0; + __u32 idx; ENTRY; LASSERT(lo != NULL); @@ -873,7 +874,7 @@ int lod_load_striping_locked(const struct lu_env *env, struct lod_object *lo) rc = lod_parse_striping(env, lo, buf); } else if (S_ISDIR(lu_object_attr(lod2lu_obj(lo)))) { rc = lod_get_lmv_ea(env, lo); - if (rc < sizeof(struct lmv_mds_md_v1)) + if (rc < (typeof(rc))sizeof(struct lmv_mds_md_v1)) GOTO(out, rc = rc > 0 ? -EINVAL : rc); buf->lb_buf = info->lti_ea_store; diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index 2ea9025..e3ad890 100644 --- a/lustre/lod/lod_object.c +++ b/lustre/lod/lod_object.c @@ -705,7 +705,7 @@ int lod_load_lmv_shards(const struct lu_env *env, struct lod_object *lo, const struct dt_it_ops *iops; __u32 stripes; __u32 magic = le32_to_cpu(lmv1->lmv_magic); - int size; + size_t size; int rc; ENTRY; @@ -1217,10 +1217,10 @@ static int lod_xattr_get(const struct lu_env *env, struct dt_object *dt, struct lmv_mds_md_v1 *lmv1; int rc1 = 0; - if (rc > sizeof(*lmv1)) + if (rc > (typeof(rc))sizeof(*lmv1)) RETURN(rc); - if (rc < sizeof(*lmv1)) + if (rc < (typeof(rc))sizeof(*lmv1)) RETURN(rc = rc > 0 ? -EINVAL : rc); if (buf->lb_buf == NULL || buf->lb_len == 0) { @@ -1373,7 +1373,7 @@ int lod_parse_dir_striping(const struct lu_env *env, struct lod_object *lo, union lmv_mds_md *lmm = buf->lb_buf; struct lmv_mds_md_v1 *lmv1 = &lmm->lmv_md_v1; struct lu_fid *fid = &info->lti_fid; - int i; + unsigned int i; int rc = 0; ENTRY; @@ -1457,11 +1457,11 @@ static int lod_prep_md_striped_create(const struct lu_env *env, struct lmv_mds_md_v1 *lmm; struct lmv_mds_md_v1 *slave_lmm = NULL; struct dt_insert_rec *rec = &info->lti_dt_rec; - int stripe_count; + __u32 stripe_count; int *idx_array; int rc = 0; - int i; - int j; + __u32 i; + __u32 j; ENTRY; /* The lum has been verifed in lod_verify_md_striping */ @@ -1507,10 +1507,10 @@ static int lod_prep_md_striped_create(const struct lu_env *env, for (j = 0; j < lod->lod_remote_mdt_count; j++, idx = (idx + 1) % (lod->lod_remote_mdt_count + 1)) { bool already_allocated = false; - int k; + __u32 k; - CDEBUG(D_INFO, "try idx %d, mdt cnt %d," - " allocated %d, last allocated %d\n", idx, + CDEBUG(D_INFO, "try idx %d, mdt cnt %u," + " allocated %u, last allocated %d\n", idx, lod->lod_remote_mdt_count, i, idx_array[i - 1]); /* Find next available target */ @@ -1553,13 +1553,13 @@ static int lod_prep_md_striped_create(const struct lu_env *env, /* Can not allocate more stripes */ if (j == lod->lod_remote_mdt_count) { - CDEBUG(D_INFO, "%s: require stripes %d only get %d\n", + CDEBUG(D_INFO, "%s: require stripes %u only get %d\n", lod2obd(lod)->obd_name, stripe_count, i - 1); break; } - CDEBUG(D_INFO, "idx %d, mdt cnt %d," - " allocated %d, last allocated %d\n", idx, + CDEBUG(D_INFO, "idx %d, mdt cnt %u," + " allocated %u, last allocated %d\n", idx, lod->lod_remote_mdt_count, i, idx_array[i - 1]); next: @@ -1672,7 +1672,7 @@ next: if (rc != 0) GOTO(out_put, rc); - snprintf(stripe_name, sizeof(info->lti_key), DFID":%d", + snprintf(stripe_name, sizeof(info->lti_key), DFID":%u", PFID(lu_object_fid(&dto->do_lu)), i); sname = lod_name_get(env, stripe_name, strlen(stripe_name)); @@ -2458,7 +2458,7 @@ static int lod_cache_parent_lov_striping(const struct lu_env *env, if (rc < 0) GOTO(unlock, rc); - if (rc < sizeof(struct lov_user_md)) { + if (rc < (typeof(rc))sizeof(struct lov_user_md)) { /* don't lookup for non-existing or invalid striping */ lp->ldo_def_striping_set = 0; lp->ldo_striping_cached = 1; @@ -2521,7 +2521,7 @@ static int lod_cache_parent_lmv_striping(const struct lu_env *env, if (rc < 0) GOTO(unlock, rc); - if (rc < sizeof(struct lmv_user_md)) { + if (rc < (typeof(rc))sizeof(struct lmv_user_md)) { /* don't lookup for non-existing or invalid striping */ lp->ldo_dir_def_striping_set = 0; lp->ldo_dir_striping_cached = 1; @@ -3026,7 +3026,8 @@ static int lod_object_destroy(const struct lu_env *env, struct lod_object *lo = lod_dt_obj(dt); struct lod_thread_info *info = lod_env_info(env); char *stripe_name = info->lti_key; - int rc, i; + unsigned int i; + int rc; ENTRY; /* destroy sub-stripe of master object */ diff --git a/lustre/lod/lod_pool.c b/lustre/lod/lod_pool.c index aad13f4..3bebbfe 100644 --- a/lustre/lod/lod_pool.c +++ b/lustre/lod/lod_pool.c @@ -227,8 +227,8 @@ cfs_hash_ops_t pool_hash_operations = { #define POOL_IT_MAGIC 0xB001CEA0 struct lod_pool_iterator { - int lpi_magic; /* POOL_IT_MAGIC */ - int lpi_idx; /* from 0 to pool_tgt_size - 1 */ + unsigned int lpi_magic; /* POOL_IT_MAGIC */ + unsigned int lpi_idx; /* from 0 to pool_tgt_size - 1 */ struct pool_desc *lpi_pool; }; @@ -429,7 +429,7 @@ static struct file_operations pool_proc_operations = { */ void lod_dump_pool(int level, struct pool_desc *pool) { - int i; + unsigned int i; pool_getref(pool); @@ -535,7 +535,8 @@ int lod_ost_pool_extend(struct ost_pool *op, unsigned int min_count) */ int lod_ost_pool_add(struct ost_pool *op, __u32 idx, unsigned int min_count) { - int rc = 0, i; + unsigned int i; + int rc = 0; ENTRY; down_write(&op->op_rw_sem); @@ -574,7 +575,7 @@ out: */ int lod_ost_pool_remove(struct ost_pool *op, __u32 idx) { - int i; + unsigned int i; ENTRY; down_write(&op->op_rw_sem); @@ -877,7 +878,8 @@ out: */ int lod_check_index_in_pool(__u32 idx, struct pool_desc *pool) { - int i, rc; + unsigned int i; + int rc; ENTRY; pool_getref(pool); diff --git a/lustre/lod/lod_qos.c b/lustre/lod/lod_qos.c index ba70a97..f63c710 100644 --- a/lustre/lod/lod_qos.c +++ b/lustre/lod/lod_qos.c @@ -202,7 +202,8 @@ static void lod_qos_statfs_update(const struct lu_env *env, { struct obd_device *obd = lod2obd(lod); struct ost_pool *osts = &(lod->lod_pool_info); - int i, idx, rc = 0; + unsigned int i; + int idx, rc = 0; __u64 max_age, avail; ENTRY; @@ -241,7 +242,8 @@ static int lod_qos_calc_ppo(struct lod_device *lod) struct lod_qos_oss *oss; __u64 ba_max, ba_min, temp; __u32 num_active; - int rc, i, prio_wide; + unsigned int i; + int rc, prio_wide; time_t now, age; ENTRY; @@ -372,7 +374,7 @@ static int lod_qos_used(struct lod_device *lod, struct ost_pool *osts, { struct lod_tgt_desc *ost; struct lod_qos_oss *oss; - int j; + unsigned int j; ENTRY; ost = OST_TGT(lod,index); @@ -452,7 +454,8 @@ static int lod_qos_calc_rr(struct lod_device *lod, struct ost_pool *src_pool, struct lod_qos_oss *oss; struct lod_tgt_desc *ost; unsigned placed, real_count; - int i, rc; + unsigned int i; + int rc; ENTRY; if (!lqr->lqr_dirty) { @@ -553,7 +556,7 @@ static int lod_qos_calc_rr(struct lod_device *lod, struct ost_pool *src_pool, */ static struct dt_object *lod_qos_declare_object_on(const struct lu_env *env, struct lod_device *d, - int ost_idx, + __u32 ost_idx, struct thandle *th) { struct lod_tgt_desc *ost; @@ -564,7 +567,6 @@ static struct dt_object *lod_qos_declare_object_on(const struct lu_env *env, ENTRY; LASSERT(d); - LASSERT(ost_idx >= 0); LASSERT(ost_idx < d->lod_osts_size); ost = OST_TGT(d,ost_idx); LASSERT(ost); @@ -602,7 +604,7 @@ out: RETURN(dt); } -static int min_stripe_count(int stripe_cnt, int flags) +static int min_stripe_count(__u32 stripe_cnt, int flags) { return (flags & LOV_USES_DEFAULT_STRIPE ? stripe_cnt - (stripe_cnt / 4) : stripe_cnt); @@ -624,7 +626,8 @@ static int inline lod_qos_dev_is_full(struct obd_statfs *msfs) return (msfs->os_bavail < used); } -static inline int lod_qos_ost_in_use_clear(const struct lu_env *env, int stripes) +static inline int lod_qos_ost_in_use_clear(const struct lu_env *env, + __u32 stripes) { struct lod_thread_info *info = lod_env_info(env); @@ -647,11 +650,11 @@ static inline void lod_qos_ost_in_use(const struct lu_env *env, int idx, int ost osts[idx] = ost; } -static int lod_qos_is_ost_used(const struct lu_env *env, int ost, int stripes) +static int lod_qos_is_ost_used(const struct lu_env *env, int ost, __u32 stripes) { struct lod_thread_info *info = lod_env_info(env); int *osts = info->lti_ea_store; - int j; + __u32 j; for (j = 0; j < stripes; j++) { if (osts[j] == ost) @@ -671,13 +674,13 @@ static int lod_alloc_rr(const struct lu_env *env, struct lod_object *lo, struct ost_pool *osts; struct lod_qos_rr *lqr; struct dt_object *o; - unsigned array_idx; - int i, rc; - int ost_start_idx_temp; + unsigned int i, array_idx; + int rc; + __u32 ost_start_idx_temp; int speed = 0; - int stripe_idx = 0; - int stripe_cnt = lo->ldo_stripenr; - int stripe_cnt_min = min_stripe_count(stripe_cnt, flags); + __u32 stripe_idx = 0; + __u32 stripe_cnt = lo->ldo_stripenr; + __u32 stripe_cnt_min = min_stripe_count(stripe_cnt, flags); __u32 ost_idx; ENTRY; @@ -836,8 +839,9 @@ static int lod_alloc_specific(const struct lu_env *env, struct lod_object *lo, struct lod_device *m = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev); struct obd_statfs *sfs = &lod_env_info(env)->lti_osfs; struct dt_object *o; - unsigned ost_idx, array_idx, ost_count; - int i, rc, stripe_num = 0; + __u32 ost_idx; + unsigned int i, array_idx, ost_count; + int rc, stripe_num = 0; int speed = 0; struct pool_desc *pool = NULL; struct ost_pool *osts; @@ -987,9 +991,11 @@ static int lod_alloc_qos(const struct lu_env *env, struct lod_object *lo, struct lod_tgt_desc *ost; struct dt_object *o; __u64 total_weight = 0; - int nfound, good_osts, i, rc = 0; - int stripe_cnt = lo->ldo_stripenr; - int stripe_cnt_min; + unsigned int i; + int rc = 0; + __u32 nfound, good_osts; + __u32 stripe_cnt = lo->ldo_stripenr; + __u32 stripe_cnt_min; struct pool_desc *pool = NULL; struct ost_pool *osts; ENTRY; @@ -1107,7 +1113,7 @@ static int lod_alloc_qos(const struct lu_env *env, struct lod_object *lo, /* On average, this will hit larger-weighted osts more often. 0-weight osts will always get used last (only when rand=0) */ for (i = 0; i < osts->op_count; i++) { - int idx = osts->op_array[i]; + __u32 idx = osts->op_array[i]; if (!cfs_bitmap_check(m->lod_ost_bitmap, idx)) continue; diff --git a/lustre/lod/lproc_lod.c b/lustre/lod/lproc_lod.c index b2318bb..ec67275 100644 --- a/lustre/lod/lproc_lod.c +++ b/lustre/lod/lproc_lod.c @@ -296,7 +296,8 @@ lod_qos_maxage_seq_write(struct file *file, const char *buffer, struct lu_device *next; struct lustre_cfg *lcfg; char str[32]; - int val, rc, i; + unsigned int i; + int val, rc; LASSERT(dev != NULL); lod = lu2lod_dev(dev->obd_lu_dev); -- 1.8.3.1