From 04b27bfadf72e46962e26991ee85c44596709f4f Mon Sep 17 00:00:00 2001 From: Dmitry Eremin Date: Mon, 4 Aug 2014 12:41:14 +0400 Subject: [PATCH] LU-5417 obdclass: fix comparison between signed and unsigned Make lu_buf->lb_len unsigned. Signed-off-by: Dmitry Eremin Change-Id: I769b0a21aabb5466096e5f3e1aba4e96bcf64a6b Reviewed-on: http://review.whamcloud.com/11281 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Fan Yong Reviewed-by: John L. Hammond Reviewed-by: Oleg Drokin --- lustre/include/lu_object.h | 12 ++++++------ lustre/lfsck/lfsck_layout.c | 33 +++++++++++++++++++-------------- lustre/lod/lod_object.c | 11 +++++++---- lustre/obdclass/lu_object.c | 39 ++++++++++++++++++++------------------- 4 files changed, 52 insertions(+), 43 deletions(-) diff --git a/lustre/include/lu_object.h b/lustre/include/lu_object.h index b104851..a66790a 100644 --- a/lustre/include/lu_object.h +++ b/lustre/include/lu_object.h @@ -1326,8 +1326,8 @@ static inline bool lu_name_is_valid(const struct lu_name *ln) * methods. */ struct lu_buf { - void *lb_buf; - ssize_t lb_len; + void *lb_buf; + size_t lb_len; }; #define DLUBUF "(%p %zu)" @@ -1366,11 +1366,11 @@ struct lu_object *lu_object_anon(const struct lu_env *env, extern struct lu_buf LU_BUF_NULL; void lu_buf_free(struct lu_buf *buf); -void lu_buf_alloc(struct lu_buf *buf, int size); -void lu_buf_realloc(struct lu_buf *buf, int size); +void lu_buf_alloc(struct lu_buf *buf, size_t size); +void lu_buf_realloc(struct lu_buf *buf, size_t size); -int lu_buf_check_and_grow(struct lu_buf *buf, int len); -struct lu_buf *lu_buf_check_and_alloc(struct lu_buf *buf, int len); +int lu_buf_check_and_grow(struct lu_buf *buf, size_t len); +struct lu_buf *lu_buf_check_and_alloc(struct lu_buf *buf, size_t len); /** @} lu */ #endif /* __LUSTRE_LU_OBJECT_H */ diff --git a/lustre/lfsck/lfsck_layout.c b/lustre/lfsck/lfsck_layout.c index cceebbd..ba861c0 100644 --- a/lustre/lfsck/lfsck_layout.c +++ b/lustre/lfsck/lfsck_layout.c @@ -2472,6 +2472,7 @@ static int lfsck_layout_recreate_lovea(const struct lu_env *env, struct lfsck_bookmark *bk = &lfsck->li_bookmark_ram; struct thandle *handle = NULL; size_t buflen = buf->lb_len; + size_t lovea_size; struct lov_mds_md_v1 *lmm; struct lov_ost_data_v1 *objs; struct lustre_handle lh = { 0 }; @@ -2510,8 +2511,9 @@ again: if (rc < 0) GOTO(unlock_layout, rc); - if (buf->lb_len < rc) { - lu_buf_realloc(buf, rc); + lovea_size = rc; + if (buf->lb_len < lovea_size) { + lu_buf_realloc(buf, lovea_size); buflen = buf->lb_len; if (buf->lb_buf == NULL) GOTO(unlock_layout, rc = -ENOMEM); @@ -2541,11 +2543,12 @@ again: LASSERT(rc != 0); goto again; } else if (rc == -ENODATA || rc == 0) { - rc = lov_mds_md_size(ea_off + 1, LOV_MAGIC_V1); + lovea_size = lov_mds_md_size(ea_off + 1, LOV_MAGIC_V1); /* If the declared is not big enough, re-try. */ - if (buf->lb_len < rc) + if (buf->lb_len < lovea_size) { + rc = lovea_size; goto again; - + } fl = LU_XATTR_CREATE; } else if (rc < 0) { GOTO(unlock_parent, rc); @@ -2553,15 +2556,16 @@ again: goto again; } else { fl = LU_XATTR_REPLACE; + lovea_size = rc; } if (fl == LU_XATTR_CREATE) { if (bk->lb_param & LPF_DRYRUN) GOTO(unlock_parent, rc = 1); - LASSERT(buf->lb_len >= rc); + LASSERT(buf->lb_len >= lovea_size); - buf->lb_len = rc; + buf->lb_len = lovea_size; rc = lfsck_layout_extend_lovea(env, lfsck, handle, parent, cfid, buf, fl, ost_idx, ea_off, false); @@ -2576,9 +2580,9 @@ again: if (bk->lb_param & LPF_DRYRUN) GOTO(unlock_parent, rc = 1); - LASSERT(buf->lb_len >= rc); + LASSERT(buf->lb_len >= lovea_size); - buf->lb_len = rc; + buf->lb_len = lovea_size; memset(lmm, 0, buf->lb_len); rc = lfsck_layout_extend_lovea(env, lfsck, handle, parent, cfid, buf, fl, ost_idx, ea_off, true); @@ -2612,12 +2616,13 @@ again: if (bk->lb_param & LPF_DRYRUN) GOTO(unlock_parent, rc = 1); - rc = lov_mds_md_size(ea_off + 1, magic); + lovea_size = lov_mds_md_size(ea_off + 1, magic); /* If the declared is not big enough, re-try. */ - if (buf->lb_len < rc) + if (buf->lb_len < lovea_size) { + rc = lovea_size; goto again; - - buf->lb_len = rc; + } + buf->lb_len = lovea_size; rc = lfsck_layout_extend_lovea(env, lfsck, handle, parent, cfid, buf, fl, ost_idx, ea_off, false); @@ -2626,7 +2631,7 @@ again: LASSERTF(rc > 0, "invalid rc = %d\n", rc); - buf->lb_len = rc; + buf->lb_len = lovea_size; for (i = 0; i < count; i++, objs++) { /* The MDT-object was created via lfsck_layout_recover_create() * by others before, and we fill the dummy layout EA. */ diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index a936f52..2094ae9 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); - size_t size; + size_t lmv1_size; int rc; ENTRY; @@ -721,8 +721,11 @@ int lod_load_lmv_shards(const struct lu_env *env, struct lod_object *lo, if (stripes < 1) RETURN(0); - size = lmv_mds_md_size(stripes, magic); - if (buf->lb_len < size) { + rc = lmv_mds_md_size(stripes, magic); + if (rc < 0) + RETURN(rc); + lmv1_size = rc; + if (buf->lb_len < lmv1_size) { struct lu_buf tbuf; if (!resize) @@ -731,7 +734,7 @@ int lod_load_lmv_shards(const struct lu_env *env, struct lod_object *lo, tbuf = *buf; buf->lb_buf = NULL; buf->lb_len = 0; - lu_buf_alloc(buf, size); + lu_buf_alloc(buf, lmv1_size); lmv1 = buf->lb_buf; if (lmv1 == NULL) RETURN(-ENOMEM); diff --git a/lustre/obdclass/lu_object.c b/lustre/obdclass/lu_object.c index d880ba4..567c4b4 100644 --- a/lustre/obdclass/lu_object.c +++ b/lustre/obdclass/lu_object.c @@ -352,7 +352,7 @@ int lu_site_purge(const struct lu_env *env, struct lu_site *s, int nr) int start; int count; int bnr; - int i; + unsigned int i; if (OBD_FAIL_CHECK(OBD_FAIL_OBD_NO_LRU)) RETURN(0); @@ -950,10 +950,10 @@ EXPORT_SYMBOL(lu_site_print); /** * Return desired hash table order. */ -static int lu_htable_order(struct lu_device *top) +static unsigned int lu_htable_order(struct lu_device *top) { - unsigned long cache_size; - int bits; + unsigned long cache_size; + unsigned int bits; /* * For ZFS based OSDs the cache should be disabled by default. This @@ -1094,15 +1094,16 @@ int lu_site_init(struct lu_site *s, struct lu_device *top) struct lu_site_bkt_data *bkt; cfs_hash_bd_t bd; char name[16]; - int bits; - int i; + unsigned int bits; + unsigned int i; ENTRY; memset(s, 0, sizeof *s); mutex_init(&s->ls_purge_mutex); bits = lu_htable_order(top); snprintf(name, 16, "lu_site_%s", top->ld_type->ldt_name); - for (bits = min(max(LU_SITE_BITS_MIN, bits), LU_SITE_BITS_MAX); + for (bits = clamp_t(typeof(bits), bits, + LU_SITE_BITS_MIN, LU_SITE_BITS_MAX); bits >= LU_SITE_BITS_MIN; bits--) { s->ls_obj_hash = cfs_hash_create(name, bits, bits, bits - LU_SITE_BKT_BITS, @@ -1429,8 +1430,8 @@ static unsigned key_set_version = 0; */ int lu_context_key_register(struct lu_context_key *key) { - int result; - int i; + int result; + unsigned int i; LASSERT(key->lct_init != NULL); LASSERT(key->lct_fini != NULL); @@ -1640,7 +1641,7 @@ EXPORT_SYMBOL(lu_context_key_revive); static void keys_fini(struct lu_context *ctx) { - int i; + unsigned int i; if (ctx->lc_value == NULL) return; @@ -1654,7 +1655,7 @@ static void keys_fini(struct lu_context *ctx) static int keys_fill(struct lu_context *ctx) { - int i; + unsigned int i; LINVRNT(ctx->lc_value != NULL); for (i = 0; i < ARRAY_SIZE(lu_keys); ++i) { @@ -1767,7 +1768,7 @@ EXPORT_SYMBOL(lu_context_enter); */ void lu_context_exit(struct lu_context *ctx) { - int i; + unsigned int i; LINVRNT(ctx->lc_state == LCS_ENTERED); ctx->lc_state = LCS_LEFT; @@ -1915,8 +1916,8 @@ typedef struct lu_site_stats{ static void lu_site_stats_get(cfs_hash_t *hs, lu_site_stats_t *stats, int populated) { - cfs_hash_bd_t bd; - int i; + cfs_hash_bd_t bd; + unsigned int i; cfs_hash_for_each_bucket(hs, &bd, i) { struct lu_site_bkt_data *bkt = cfs_hash_bd_extra_get(hs, &bd); @@ -2077,7 +2078,7 @@ int lu_debugging_setup(void) void lu_context_keys_dump(void) { - int i; + unsigned int i; for (i = 0; i < ARRAY_SIZE(lu_keys); ++i) { struct lu_context_key *key; @@ -2333,7 +2334,7 @@ void lu_buf_free(struct lu_buf *buf) } EXPORT_SYMBOL(lu_buf_free); -void lu_buf_alloc(struct lu_buf *buf, int size) +void lu_buf_alloc(struct lu_buf *buf, size_t size) { LASSERT(buf); LASSERT(buf->lb_buf == NULL); @@ -2344,14 +2345,14 @@ void lu_buf_alloc(struct lu_buf *buf, int size) } EXPORT_SYMBOL(lu_buf_alloc); -void lu_buf_realloc(struct lu_buf *buf, int size) +void lu_buf_realloc(struct lu_buf *buf, size_t size) { lu_buf_free(buf); lu_buf_alloc(buf, size); } EXPORT_SYMBOL(lu_buf_realloc); -struct lu_buf *lu_buf_check_and_alloc(struct lu_buf *buf, int len) +struct lu_buf *lu_buf_check_and_alloc(struct lu_buf *buf, size_t len) { if (buf->lb_buf == NULL && buf->lb_len == 0) lu_buf_alloc(buf, len); @@ -2369,7 +2370,7 @@ EXPORT_SYMBOL(lu_buf_check_and_alloc); * old buffer remains unchanged on error * \retval 0 or -ENOMEM */ -int lu_buf_check_and_grow(struct lu_buf *buf, int len) +int lu_buf_check_and_grow(struct lu_buf *buf, size_t len) { char *ptr; -- 1.8.3.1