Whamcloud - gitweb
LU-5417 obdclass: fix comparison between signed and unsigned
[fs/lustre-release.git] / lustre / lod / lod_object.c
index fb43a8d..2094ae9 100644 (file)
@@ -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                   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);
@@ -1149,16 +1152,16 @@ static int lod_attr_set(const struct lu_env *env,
         */
        LASSERT(lo->ldo_stripe);
        for (i = 0; i < lo->ldo_stripenr; i++) {
-               if (likely(lo->ldo_stripe[i] != NULL)) {
-                       if (dt_object_exists(lo->ldo_stripe[i]) == 0)
-                               continue;
-
-                       rc = dt_attr_set(env, lo->ldo_stripe[i], attr,
-                                        handle, capa);
-                       if (rc != 0) {
-                               CERROR("failed declaration: %d\n", rc);
-                               break;
-                       }
+               if (unlikely(lo->ldo_stripe[i] == NULL))
+                       continue;
+               if (S_ISDIR(dt->do_lu.lo_header->loh_attr) &&
+                   (dt_object_exists(lo->ldo_stripe[i]) == 0))
+                       continue;
+
+               rc = dt_attr_set(env, lo->ldo_stripe[i], attr, handle, capa);
+               if (rc != 0) {
+                       CERROR("failed declaration: %d\n", rc);
+                       break;
                }
        }
 
@@ -1217,10 +1220,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 +1376,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;
 
@@ -1456,11 +1459,12 @@ static int lod_prep_md_striped_create(const struct lu_env *env,
        struct lu_buf           slave_lmv_buf;
        struct lmv_mds_md_v1    *lmm;
        struct lmv_mds_md_v1    *slave_lmm = NULL;
-       int                     stripe_count;
+       struct dt_insert_rec    *rec = &info->lti_dt_rec;
+       __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 */
@@ -1506,10 +1510,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 */
@@ -1552,13 +1556,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:
@@ -1600,6 +1604,7 @@ next:
        if (!dt_try_as_dir(env, dt_object_child(dt)))
                GOTO(out_put, rc = -EINVAL);
 
+       rec->rec_type = S_IFDIR;
        for (i = 0; i < lo->ldo_stripenr; i++) {
                struct dt_object        *dto            = stripe[i];
                char                    *stripe_name    = info->lti_key;
@@ -1614,16 +1619,16 @@ next:
                if (!dt_try_as_dir(env, dto))
                        GOTO(out_put, rc = -EINVAL);
 
-               rc = dt_declare_insert(env, dto,
-                    (const struct dt_rec *)lu_object_fid(&dto->do_lu),
-                    (const struct dt_key *)dot, th);
+               rec->rec_fid = lu_object_fid(&dto->do_lu);
+               rc = dt_declare_insert(env, dto, (const struct dt_rec *)rec,
+                                      (const struct dt_key *)dot, th);
                if (rc != 0)
                        GOTO(out_put, rc);
 
                /* master stripe FID will be put to .. */
-               rc = dt_declare_insert(env, dto,
-                    (const struct dt_rec *)lu_object_fid(&dt->do_lu),
-                    (const struct dt_key *)dotdot, th);
+               rec->rec_fid = lu_object_fid(&dt->do_lu);
+               rc = dt_declare_insert(env, dto, (const struct dt_rec *)rec,
+                                      (const struct dt_key *)dotdot, th);
                if (rc != 0)
                        GOTO(out_put, rc);
 
@@ -1670,7 +1675,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));
@@ -1689,9 +1694,10 @@ next:
                if (rc != 0)
                        GOTO(out_put, rc);
 
+               rec->rec_fid = lu_object_fid(&dto->do_lu);
                rc = dt_declare_insert(env, dt_object_child(dt),
-                    (const struct dt_rec *)lu_object_fid(&dto->do_lu),
-                    (const struct dt_key *)stripe_name, th);
+                                      (const struct dt_rec *)rec,
+                                      (const struct dt_key *)stripe_name, th);
                if (rc != 0)
                        GOTO(out_put, rc);
 
@@ -2055,6 +2061,7 @@ static int lod_xattr_set_lmv(const struct lu_env *env, struct dt_object *dt,
        struct lu_buf           slave_lmv_buf;
        struct lmv_mds_md_v1    *lmm;
        struct lmv_mds_md_v1    *slave_lmm = NULL;
+       struct dt_insert_rec    *rec = &info->lti_dt_rec;
        int                     i;
        int                     rc;
        ENTRY;
@@ -2087,6 +2094,7 @@ static int lod_xattr_set_lmv(const struct lu_env *env, struct dt_object *dt,
        slave_lmv_buf.lb_buf = slave_lmm;
        slave_lmv_buf.lb_len = sizeof(*slave_lmm);
 
+       rec->rec_type = S_IFDIR;
        for (i = 0; i < lo->ldo_stripenr; i++) {
                struct dt_object        *dto;
                char                    *stripe_name    = info->lti_key;
@@ -2101,15 +2109,15 @@ static int lod_xattr_set_lmv(const struct lu_env *env, struct dt_object *dt,
                if (rc != 0)
                        RETURN(rc);
 
-               rc = dt_insert(env, dto,
-                             (const struct dt_rec *)lu_object_fid(&dto->do_lu),
-                             (const struct dt_key *)dot, th, capa, 0);
+               rec->rec_fid = lu_object_fid(&dto->do_lu);
+               rc = dt_insert(env, dto, (const struct dt_rec *)rec,
+                              (const struct dt_key *)dot, th, capa, 0);
                if (rc != 0)
                        RETURN(rc);
 
-               rc = dt_insert(env, dto,
-                             (struct dt_rec *)lu_object_fid(&dt->do_lu),
-                             (const struct dt_key *)dotdot, th, capa, 0);
+               rec->rec_fid = lu_object_fid(&dt->do_lu);
+               rc = dt_insert(env, dto, (struct dt_rec *)rec,
+                              (const struct dt_key *)dotdot, th, capa, 0);
                if (rc != 0)
                        RETURN(rc);
 
@@ -2172,9 +2180,10 @@ static int lod_xattr_set_lmv(const struct lu_env *env, struct dt_object *dt,
                if (rc != 0)
                        GOTO(out, rc);
 
+               rec->rec_fid = lu_object_fid(&dto->do_lu);
                rc = dt_insert(env, dt_object_child(dt),
-                    (const struct dt_rec *)lu_object_fid(&dto->do_lu),
-                    (const struct dt_key *)stripe_name, th, capa, 0);
+                              (const struct dt_rec *)rec,
+                              (const struct dt_key *)stripe_name, th, capa, 0);
                if (rc != 0)
                        GOTO(out, rc);
 
@@ -2452,7 +2461,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;
@@ -2515,7 +2524,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;
@@ -3020,7 +3029,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 */
@@ -3319,7 +3329,7 @@ static int lod_object_init(const struct lu_env *env, struct lu_object *lo,
        struct lu_object        *cobj;
        struct lod_tgt_descs    *ltd    = NULL;
        struct lod_tgt_desc     *tgt;
-       mdsno_t                  idx    = 0;
+       u32                      idx    = 0;
        int                      type   = LU_SEQ_RANGE_ANY;
        int                      rc;
        ENTRY;