Whamcloud - gitweb
LU-5577 obdclass: (*dt_index_page_build_t) arg nob to size_t 82/12382/2
authorDmitry Eremin <dmitry.eremin@intel.com>
Fri, 10 Oct 2014 16:55:00 +0000 (20:55 +0400)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 18 Dec 2014 00:16:42 +0000 (00:16 +0000)
Change the type accordant usage and check for correct input.

Signed-off-by: Dmitry Eremin <dmitry.eremin@intel.com>
Change-Id: Ic80025e95eddbc9fb51efd83c54573e5f310bb0b
Reviewed-on: http://review.whamcloud.com/12382
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/include/dt_object.h
lustre/mdd/mdd_object.c
lustre/obdclass/dt_object.c

index 90f8cb5..a54157e 100644 (file)
@@ -2069,7 +2069,7 @@ int dt_record_read(const struct lu_env *env, struct dt_object *dt,
 int dt_record_write(const struct lu_env *env, struct dt_object *dt,
                     const struct lu_buf *buf, loff_t *pos, struct thandle *th);
 typedef int (*dt_index_page_build_t)(const struct lu_env *env,
-                                    union lu_page *lp, int nob,
+                                    union lu_page *lp, size_t nob,
                                     const struct dt_it_ops *iops,
                                     struct dt_it *it, __u32 attr, void *arg);
 int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
index 6504da2..f1d78f1 100644 (file)
@@ -1850,7 +1850,7 @@ static int mdd_readpage_sanity_check(const struct lu_env *env,
 }
 
 static int mdd_dir_page_build(const struct lu_env *env, union lu_page *lp,
-                             int nob, const struct dt_it_ops *iops,
+                             size_t nob, const struct dt_it_ops *iops,
                              struct dt_it *it, __u32 attr, void *arg)
 {
        struct lu_dirpage       *dp = &lp->lp_dir;
@@ -1862,6 +1862,9 @@ static int mdd_dir_page_build(const struct lu_env *env, union lu_page *lp,
        struct lu_fid            fid;
        int                      first = 1;
 
+       if (nob < sizeof(*dp))
+               return -EINVAL;
+
         memset(area, 0, sizeof (*dp));
         area += sizeof (*dp);
         nob  -= sizeof (*dp);
@@ -1869,7 +1872,7 @@ static int mdd_dir_page_build(const struct lu_env *env, union lu_page *lp,
         ent  = area;
         do {
                 int    len;
-                int    recsize;
+               size_t recsize;
 
                 len = iops->key_size(env, it);
 
index 460cbeb..83cf4fb 100644 (file)
@@ -666,15 +666,19 @@ static inline const struct dt_index_features *dt_index_feat_select(__u64 seq,
  * \param arg  - is a pointer to the idx_info structure
  */
 static int dt_index_page_build(const struct lu_env *env, union lu_page *lp,
-                              int nob, const struct dt_it_ops *iops,
+                              size_t nob, const struct dt_it_ops *iops,
                               struct dt_it *it, __u32 attr, void *arg)
 {
        struct idx_info         *ii = (struct idx_info *)arg;
        struct lu_idxpage       *lip = &lp->lp_idx;
        char                    *entry;
-       int                      rc, size;
+       size_t                   size;
+       int                      rc;
        ENTRY;
 
+       if (nob < LIP_HDR_SIZE)
+               return -EINVAL;
+
        /* initialize the header of the new container */
        memset(lip, 0, LIP_HDR_SIZE);
        lip->lip_magic = LIP_MAGIC;
@@ -786,7 +790,7 @@ int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
 {
        struct dt_it            *it;
        const struct dt_it_ops  *iops;
-       unsigned int             pageidx, nob, nlupgs = 0;
+       size_t                   pageidx, nob, nlupgs = 0;
        int                      rc;
        ENTRY;
 
@@ -794,7 +798,7 @@ int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
        LASSERT(obj->do_index_ops != NULL);
 
        nob = rdpg->rp_count;
-       if (nob <= 0)
+       if (nob == 0)
                RETURN(-EFAULT);
 
        /* Iterate through index and fill containers from @rdpg */
@@ -841,7 +845,7 @@ int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
 
                /* fill lu pages */
                for (i = 0; i < LU_PAGE_COUNT; i++, lp++, nob -= LU_PAGE_SIZE) {
-                       rc = filler(env, lp, min_t(int, nob, LU_PAGE_SIZE),
+                       rc = filler(env, lp, min_t(size_t, nob, LU_PAGE_SIZE),
                                    iops, it, rdpg->rp_attrs, arg);
                        if (rc < 0)
                                break;
@@ -859,7 +863,7 @@ out:
        iops->fini(env, it);
 
        if (rc >= 0)
-               rc = min_t(unsigned int, nlupgs * LU_PAGE_SIZE, rdpg->rp_count);
+               rc = min_t(size_t, nlupgs * LU_PAGE_SIZE, rdpg->rp_count);
 
        RETURN(rc);
 }