Whamcloud - gitweb
LU-9679 modules: convert MIN/MAX to kernel style
[fs/lustre-release.git] / lustre / lod / lod_object.c
index f25a490..e11f474 100644 (file)
@@ -871,8 +871,8 @@ int lod_load_lmv_shards(const struct lu_env *env, struct lod_object *lo,
                                goto next;
                }
 
-               len = snprintf(name, sizeof(name),
-                              DFID":", PFID(&ent->lde_fid));
+               len = scnprintf(name, sizeof(name),
+                               DFID":", PFID(&ent->lde_fid));
                /* The ent->lde_name is composed of ${FID}:${index} */
                if (ent->lde_namelen < len + 1 ||
                    memcmp(ent->lde_name, name, len) != 0) {
@@ -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
@@ -2973,6 +2973,8 @@ bool lod_last_non_stale_mirror(__u16 mirror_id, struct lod_object *lo)
  * the '$field' can only be 'flags' now. The xattr value is binary
  * lov_comp_md_v1 which contains the component ID(s) and the value of
  * the field to be modified.
+ * Please update allowed_lustre_lov macro if $field groks more values
+ * in the future.
  *
  * \param[in] env      execution environment
  * \param[in] dt       dt_object to be modified
@@ -2998,6 +3000,9 @@ static int lod_declare_layout_set(const struct lu_env *env,
        bool    changed = false;
        ENTRY;
 
+       /* Please update allowed_lustre_lov macro if op
+        * groks more values in the future
+        */
        if (strcmp(op, "set.flags") != 0) {
                CDEBUG(D_LAYOUT, "%s: operation (%s) not supported.\n",
                       lod2obd(d)->obd_name, op);
@@ -3449,7 +3454,7 @@ static int lod_declare_layout_merge(const struct lu_env *env,
                        lcme->lcme_id = cpu_to_le32(id);
                }
 
-               id = MAX(le32_to_cpu(lcme->lcme_id), id);
+               id = max(le32_to_cpu(lcme->lcme_id), id);
        }
 
        mirror_id = mirror_id_of(id) + 1;
@@ -3581,9 +3586,8 @@ static int lod_declare_xattr_set(const struct lu_env *env,
                        strcmp(name, XATTR_LUSTRE_LOV) == 0);
                rc = lod_declare_layout_split(env, dt, buf, th);
        } else if (S_ISREG(mode) &&
-                  strlen(name) > strlen(XATTR_LUSTRE_LOV) + 1 &&
-                  strncmp(name, XATTR_LUSTRE_LOV,
-                          strlen(XATTR_LUSTRE_LOV)) == 0) {
+                  strlen(name) >= sizeof(XATTR_LUSTRE_LOV) + 3 &&
+                  allowed_lustre_lov(name)) {
                /*
                 * this is a request to modify object's striping.
                 * add/set/del component(s).
@@ -3593,15 +3597,15 @@ static int lod_declare_xattr_set(const struct lu_env *env,
 
                rc = lod_declare_modify_layout(env, dt, name, buf, th);
        } else if (strncmp(name, XATTR_NAME_LMV, strlen(XATTR_NAME_LMV)) == 0 &&
-                  strlen(name) > strlen(XATTR_NAME_LMV) + 1) {
-               const char *op = name + strlen(XATTR_NAME_LMV) + 1;
+                  strlen(name) > strlen(XATTR_NAME_LMV)) {
+               const char *op = name + strlen(XATTR_NAME_LMV);
 
                rc = -ENOTSUPP;
-               if (strcmp(op, "add") == 0)
+               if (strcmp(op, ".add") == 0)
                        rc = lod_dir_declare_layout_add(env, dt, buf, th);
-               else if (strcmp(op, "del") == 0)
+               else if (strcmp(op, ".del") == 0)
                        rc = lod_dir_declare_layout_delete(env, dt, buf, th);
-               else if (strcmp(op, "set") == 0)
+               else if (strcmp(op, ".set") == 0)
                        rc = lod_sub_declare_xattr_set(env, next, buf,
                                                       XATTR_NAME_LMV, fl, th);
 
@@ -4483,7 +4487,7 @@ static int lod_layout_del_prep_layout(const struct lu_env *env,
                        lu_object_put(env, &obj->do_lu);
                        lod_comp->llc_stripe[j] = NULL;
                }
-               OBD_FREE(lod_comp->llc_stripe, sizeof(struct dt_object *) *
+               OBD_FREE(lod_comp->llc_stripe, sizeof(*lod_comp->llc_stripe) *
                                        lod_comp->llc_stripes_allocated);
                lod_comp->llc_stripe = NULL;
                OBD_FREE(lod_comp->llc_ost_indices,
@@ -4615,23 +4619,23 @@ static int lod_xattr_set(const struct lu_env *env,
                RETURN(rc);
        } else if (S_ISDIR(dt->do_lu.lo_header->loh_attr) &&
                   strncmp(name, XATTR_NAME_LMV, strlen(XATTR_NAME_LMV)) == 0 &&
-                  strlen(name) > strlen(XATTR_NAME_LMV) + 1) {
-               const char *op = name + strlen(XATTR_NAME_LMV) + 1;
+                  strlen(name) > strlen(XATTR_NAME_LMV)) {
+               const char *op = name + strlen(XATTR_NAME_LMV);
 
                rc = -ENOTSUPP;
                /*
                 * XATTR_NAME_LMV".add" is never called, but only declared,
                 * because lod_xattr_set_lmv() will do the addition.
                 */
-               if (strcmp(op, "del") == 0)
+               if (strcmp(op, ".del") == 0)
                        rc = lod_dir_layout_delete(env, dt, buf, th);
-               else if (strcmp(op, "set") == 0)
+               else if (strcmp(op, ".set") == 0)
                        rc = lod_sub_xattr_set(env, next, buf, XATTR_NAME_LMV,
                                               fl, th);
 
                RETURN(rc);
        } else if (S_ISDIR(dt->do_lu.lo_header->loh_attr) &&
-           strcmp(name, XATTR_NAME_LOV) == 0) {
+                  strcmp(name, XATTR_NAME_LOV) == 0) {
                struct lod_default_striping *lds = lod_lds_buf_get(env);
                struct lov_user_md_v1 *v1 = buf->lb_buf;
                char pool[LOV_MAXPOOLNAME + 1];
@@ -4693,9 +4697,9 @@ static int lod_xattr_set(const struct lu_env *env,
                                                      th);
                RETURN(rc);
        } else if (S_ISREG(dt->do_lu.lo_header->loh_attr) &&
-                  (!strcmp(name, XATTR_NAME_LOV) ||
-                   !strncmp(name, XATTR_LUSTRE_LOV,
-                            strlen(XATTR_LUSTRE_LOV)))) {
+                  (strcmp(name, XATTR_NAME_LOV) == 0 ||
+                   strcmp(name, XATTR_LUSTRE_LOV) == 0 ||
+                   allowed_lustre_lov(name))) {
                /* in case of lov EA swap, just set it
                 * if not, it is a replay so check striping match what we
                 * already have during req replay, declare_xattr_set()